#!/usr/bin/make -f

# 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_DIR)/debconf.changelog

# Build architecture-independent files here.
binary-indep:
binary-indep: build
	dh_testdir
	dh_testroot
	dh_clean -k

	#$(MAKE) prefix=`pwd`/$(DEBIAN_DIR)/debconf-utils install-utils
	#$(MAKE) prefix=`pwd`/$(DEBIAN_DIR)/debconf-i18n install-i18n
	$(MAKE) prefix=`pwd`/$(DEBIAN_DIR)/debconf install-rest

	# Link doc dirs where appropriate.
	#for p in debconf-utils debconf-i18n debconf-english; do \
	#	dh_link -p $$p usr/share/doc/debconf usr/share/doc/$$p; \
	#done

	# Don't modify postrm, I purge differently than normal packages
	# using me
	dh_installdebconf -n
	
	#dh_installdocs
	dh_installdirs etc/apt/apt.conf.d/
	#mkdir -p $(DEBIAN_DIR)/debconf/etc/apt/apt.conf.d/
	cp $(DEBIAN_DIR)/apt.conf $(DEBIAN_DIR)/debconf/etc/apt/apt.conf.d/70debconf
	#dh_installman doc/man/gen/dpkg-*configure.8 \
		doc/man/gen/debconf-show.1 doc/man/gen/debconf-copydb.1 \
		doc/man/gen/debconf.1 doc/man/gen/debconf-communicate.1 \
		doc/man/gen/debconf-set-selections.1
	#dh_installman -p debconf-i18n doc/man/gen/dpkg-*.*.8 \
		doc/man/gen/debconf-show*.*.1 doc/man/gen/debconf-copydb*.*.1 \
		doc/man/gen/debconf.*.1 doc/man/gen/debconf-communicate.*.1 \
		doc/man/gen/debconf-set-selections.*.1
	#dh_installman -p debconf-doc doc/man/confmodule*.3 doc/man/debconf*.7 \
		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 | grep -v debconf-copydb | grep -v debconf-set-selections | grep -v debconf-communicate`
	#dh_installexamples -pdebconf-doc samples/*
	
	# Changelog reduction hack for debconf. Only include top 100 entries.
	#perl -ne '$$c++ if /^debconf /; last if $$c > 100 ; print $$_' \
	#	< $(DEBIAN_DIR)/changelog > $(DEBIAN_DIR)/debconf.changelog
	#echo "Install debconf-doc and see /usr/share/doc/debconf-doc/changelog.gz" >> $(DEBIAN_DIR)/debconf.changelog
	#echo "for the remainder of this changelog." >> $(DEBIAN_DIR)/debconf.changelog

	# emdebian-related deletions
	rm -rf $(DEBIAN_DIR)/debconf/usr/share/perl5/Debconf/FrontEnd/Kde*
	rm -rf $(DEBIAN_DIR)/debconf/usr/share/perl5/Debconf/Element/Kde*
	rm -rf $(DEBIAN_DIR)/debconf/usr/share/perl5/Debconf/Element/Gnome*
	rm -rf $(DEBIAN_DIR)/debconf/usr/share/pixmaps

	#dh_python
	#dh_installchangelogs
	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
