#!/usr/bin/make -f
#
# Invoke each target with `./debian/rules <target>'.  All targets should be
# invoked with the package root as the current directory.

VERSION:=$(shell dpkg-parsechangelog | perl -ne 'print $$1 $$2 if /^Version: (.*?)-(.*)$$/')

# The name of the package
P = dhelp

R = debian/tmp

# Builds the binary package.
build:
	$(checkdir)
	./configure --prefix=/usr
	make

# Undoes the effect of `make -f rules build'.
clean:
	$(checkdir)
	[ ! -f Makefile ] || make distclean
	dh_clean

# Makes a binary package.
binary-indep: checkroot build
	$(checkdir)

binary-arch: checkroot build
	$(checkdir)
	dh_installdirs
	$(MAKE) DESTDIR=$(R) install
# put version into dhelp script
	perl -i -pe "s/__VERSION__/$(shell dpkg-parsechangelog | perl -ne 'print $$1 if /^Version: (.*)$$/')/" $(R)/usr/bin/dhelp
	mkdir -p $(R)/usr/share/doc/$(P)
	cp doc/* $(R)/usr/share/doc/$(P)
	cp debian/dhelp $(R)/usr/share/doc/$(P)/.dhelp
	mkdir -p $(R)/usr/lib/cgi-bin
	cp dsearch $(R)/usr/lib/cgi-bin

	dh_installdebconf
	dh_fixperms
	dh_shlibdeps
	dh_strip
	dh_installman man/dhelp.1 man/dhelp_parse.8
	dh_installchangelogs
	dh_installcron
	dh_installdocs CREDITS debian/THANKS
	dh_installmenu

	dh_compress -X .dhelp
	dh_installdeb 
	dh_gencontrol
	dh_md5sums
	dh_builddeb

define checkdir
	test -f debian/rules
endef

# Below here is fairly generic really

binary:		binary-indep binary-arch

source diff:
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

checkroot:
	$(checkdir)
	test root = "`whoami`"

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


