#!/usr/bin/make -f
#
# Invoke each target with `./debian/rules <target>'.  All targets should be
# invoked with the package root as the current directory.
#
# Marco Budde (Budde@tu-harburg.de)

# The name of the package
P = heise-register

R = debian/tmp

DIRECTORIES = \
        $(R) \
        $(R)/DEBIAN \
        $(R)/usr \
        $(R)/usr/share/doc/$(P) \
        $(R)/usr/lib \
        $(R)/usr/lib/cgi-bin \
        $(R)/var \
        $(R)/var/lib \
        $(R)/var/lib/$(P) 

$(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)
	rm -f debian/files* debian/substvars core debian/*~ *~ build
	rm -f debian/*.debhelper

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

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

	cp *.cti $(R)/var/lib/$(P)
	cp heise.html $(R)/usr/share/doc/$(P)
	cp heise.pl $(R)/usr/lib/cgi-bin/heise-search

	cp debian/changelog $(R)/usr/share/doc/$(P)/changelog.Debian
	cp debian/{copyright,README.debian} $(R)/usr/share/doc/$(P)
	gzip -9 $(R)/usr/share/doc/$(P)/{changelog.Debian,README.debian}

	dh_dhelp

	dh_installdeb 
	dh_md5sums

	dpkg-gencontrol
	chown -R root.root debian/tmp
	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
