#!/usr/bin/make -f

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

%:
	dh $@

override_dh_auto_build:
	dh_auto_build
	docbook-to-man debian/checkinstall.sgml > debian/checkinstall.8
	docbook-to-man debian/installwatch.sgml > debian/installwatch.1

override_dh_auto_clean:
	$(MAKE) clean
	rm -f debian/checkinstall.8
	rm -f debian/installwatch.1

TMPDIR=$(CURDIR)/debian/tmp
override_dh_auto_install:
	# We override all paths: we want the binary in bin instead of
	# sbin, the configuration file in etc, the locales in the
	# standard directory, and the installwatch library in a subdir
	# of usr/lib
	$(MAKE) install PREFIX=$(TMPDIR)/usr LCDIR=$(TMPDIR)/usr/share/locale \
		CONFDIR=$(TMPDIR)/etc BINDIR=$(TMPDIR)/usr/bin \
		LIBDIR=$(TMPDIR)/usr/lib/checkinstall
	# Delete the checkinstallrc-dist file from etc
	rm -f $(TMPDIR)/etc/checkinstallrc-dist
	
	# installwatch's documentation
	mkdir -p $(TMPDIR)/usr/share/doc/checkinstall
	gzip -9c installwatch/CHANGELOG \
		> $(TMPDIR)/usr/share/doc/checkinstall/installwatch.changelog.gz
	gzip -9c debian/changelog.installwatch.old \
		> $(TMPDIR)/usr/share/doc/checkinstall/installwatch.changelog.Debian.gz
	cp installwatch/BUGS \
		$(TMPDIR)/usr/share/doc/checkinstall/BUGS.installwatch
	cp installwatch/README \
		$(TMPDIR)/usr/share/doc/checkinstall/README.installwatch
	cp installwatch/TODO \
		$(TMPDIR)/usr/share/doc/checkinstall/TODO.installwatch
	
	# Modifications to the programs/config are applied here
	
	# Enable installwatch to find the shared library
	sed -i -e 's|$(TMPDIR)||' $(TMPDIR)/usr/bin/installwatch
	sed -i -e 's|PREFIX/lib|PREFIX/lib/checkinstall|' \
		$(TMPDIR)/usr/bin/installwatch
	
override_dh_installman:
	dh_installman debian/installwatch.1 debian/checkinstall.8

override_dh_install:
	dh_install --sourcedir=$(TMPDIR)

