#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# This is the debhelper compatability version to use.
export DH_COMPAT=4

include /usr/share/dpatch/dpatch.make

# shared library versions, option 1
#version=2.0.5
#major=2
# option 2, assuming the library is created as src/.libs/libfoo.so.2.0.5 or so
version=`ls libavc1394/.libs/lib*.so.* | \
 awk '{if (match($$0,/[0-9]+\.[0-9]+\.[0-9]+$$/)) print substr($$0,RSTART)}'`
major=`ls libavc1394/.libs/lib*.so.* | \
 awk '{if (match($$0,/\.so\.[0-9]+$$/)) print substr($$0,RSTART+4)}'`

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Make sure we use the latest autotools helpers.
	if test -f config.sub; then \
		mv config.sub config.sub.debsave; \
	fi
	if test -f config.guess; then \
		mv config.guess config.guess.debsave; \
	fi
	ln -sf /usr/share/misc/config.sub .
	ln -sf /usr/share/misc/config.guess .

	./configure --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info

	touch configure-stamp

build: build-stamp
build-stamp: patch-stamp configure-stamp
	dh_testdir

	$(MAKE)

	touch build-stamp

clean: unpatch
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	-$(MAKE) distclean

	if test -L config.sub -a -e config.sub.debsave; then \
		rm config.sub && mv config.sub.debsave config.sub; \
	fi
	if test -L config.guess -a -e config.guess.debsave; then \
		rm config.guess && mv config.guess.debsave config.guess; \
	fi
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	$(MAKE) install DESTDIR=$(CURDIR)/debian/libavc1394-dev


# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_movefiles --sourcedir=debian/libavc1394-dev -plibavc1394-$(major)

	# Act on _all_ packages. Docs in -dev will be removed later on, but
	# we want dh_installdocs to create the /usr/doc postinst.
	dh_installdocs 
	dh_installchangelogs -plibavc1394-$(major) ChangeLog

	rm -rf debian/libavc1394-dev/usr/share/doc/libavc1394-dev
	ln -s libavc1394-$(major) \
		debian/libavc1394-dev/usr/share/doc/libavc1394-dev \

	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs -V 'libavc1394-0 (>= 0.5.3)'
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure patch unpatch
