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

# The name of the package
P = dhelp

R = debian/tmp

DIRECTORIES = \
        $(R) \
        $(R)/DEBIAN \
        $(R)/usr \
        $(R)/usr/bin \
        $(R)/usr/share/doc/$(P) \
        $(R)/usr/lib/cgi-bin \
        $(R)/usr/share/man/man1 \
        $(R)/usr/share/man/man8 \
        $(R)/usr/share/man/de/man1 \
	$(R)/usr/sbin \
        $(R)/var/lib/dhelp

$(DIRECTORIES):
	install -d -g root -o root -m 755 $@
	chmod g-s $@

# Builds the binary package.
build:
	$(checkdir)
	touch build

# Clean $(DIRECTORIES)
clean-dir:
	$(checkdir)
	rm -rf $(R)

# Undoes the effect of `make -f rules build'.
clean: clean-dir
	$(checkdir)
	[ ! -f Makefile ] || make clean
	rm -f debian/files* debian/substvars core debian/*~ *~ doc/*~ build
	make -C fsstnd clean
	rm -f debian/post*.debhelper debian/pre*.debhelper

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


binary-arch: $(DIRECTORIES) checkroot build
	$(checkdir)

	make
	cp dhelp_parse $(R)/usr/sbin	
	cp dhelp dhelp_fsstnd dh_dhelp $(R)/usr/bin
	cp doc/* debian/THANKS $(R)/usr/share/doc/$(P)
	cp debian/dhelp $(R)/usr/share/doc/$(P)/.dhelp
	cp debian/{changelog,README.debian,copyright} $(R)/usr/share/doc/$(P)
	gzip -9 $(R)/usr/share/doc/$(P)/{changelog,README.debian,copyright}
	cp dsearch $(R)/usr/lib/cgi-bin
	cp man/{dhelp.1,dh_dhelp.1} $(R)/usr/share/man/man1/
	cp man/dhelp_parse.8 $(R)/usr/share/man/man8/
	cp man/de/dhelp.1 $(R)/usr/share/man/de/man1/
	gzip $(R)/usr/share/man/man1/* $(R)/usr/share/man/man8/* 
	gzip $(R)/usr/share/man/de/man1/*


# old fsstnd support
	make -C fsstnd
	cp fsstnd/dhelp_parse_fsstnd $(R)/usr/sbin

	dh_shlibdeps
	dh_strip
	dh_installcron
	dh_installmenu
	dh_installdeb 
	dh_md5sums

	dpkg-gencontrol
	chown -R root.root debian/tmp
	chown www-data.www-data $(R)/var/lib/dhelp
	chmod -R g-ws debian/tmp

	dpkg --build debian/tmp ..

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: binary binary-arch binary-indep clean checkroot


