#!/usr/bin/make -f

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

# This is the debhelper compatibility version to use.
export DH_COMPAT=3

# Ensure that builds are self-hosting, which means I have to use the .pm
# files in this package, not any that may be on the system.
export PERL5LIB=.

build: build-stamp
build-stamp:
	dh_testdir
	$(MAKE)
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	$(MAKE) clean
	dh_clean debian/debconf.changelog
	# Just so non-debian folks will know where to find it.
	ln -sf ../debian/copyright doc/COPYRIGHT

# Build architecture-independent files here.
binary-indep:
binary-indep: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs etc/apt/apt.conf.d

	$(MAKE) prefix=`pwd`/debian/debconf-utils install-utils
	$(MAKE) prefix=`pwd`/debian/debconf install-rest

	install -m 0644 debian/apt.conf \
		debian/debconf/etc/apt/apt.conf.d/70debconf

	# Don't modify postrm, I purge differently than normal packages
	# using me
	PATH=.:$(PATH) dh_installdebconf -n
	
	dh_installdocs 
	dh_installman doc/man/gen/dpkg-*.8 doc/man/gen/debconf-show*.1
	dh_installman -p debconf-doc doc/man/confmodule*.3 doc/man/debconf*.8 \
		doc/man/debconf.conf*.5 doc/man/gen/Debconf::Client::ConfModule*
	dh_installman -p debconf-utils `find doc/man/gen/debconf-* | grep -v debconf-show`
	dh_installexamples -pdebconf-doc samples/*
	
	# Changelog reduction hack for debconf. Only include top 5 entries.
	perl -ne '$$c++ if /^debconf /; last if $$c > 5 ; print $$_' \
		< debian/changelog > debian/debconf.changelog
	echo "See /usr/share/doc/debconf-doc/changelog.gz for the" >> debian/debconf.changelog
	echo "remainder of this changelog." >> debian/debconf.changelog

	dh_installchangelogs
	dh_link
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-arch:
# Nothing to do

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary
