#!/usr/bin/make -f
# This rules file was adapted from the
#   Sample debian.rules file - for GNU Hello (1.3).
#   Copyright 1994,1995 by Ian Jackson.
#   I hereby give you perpetual unlimited permission to copy,
#   modify and relicense this file, provided that you do not remove
#   my name from the file itself.  (I assert my moral right of
#   paternity under the Copyright, Designs and Patents Act 1988.)
#   This file may have to be extensively modified

package = $(shell sed -n -e 's/Package: *\([a-z]\)/\1/p' debian/control)
man	:= usr/man/man6
doc	:= usr/doc/$(package)
binpath := usr/games
bin	:= fortune

build:
	$(checkdir)
	make CFLAGS="-O2 -g -Wall" && touch build

clean:
	$(checkdir)
	-rm -f build
	-make clean
	-find . -name "*~"|xargs -r rm -f
	-rm -rf debian/tmp debian/files* core debian/substvars

binary-indep:	build
	$(checkdir)
# There are no architecture-independent files to be uploaded
# generated by this package.  If there were any they would be
# made here.

binary-arch:	build
	$(checkdir)
	-rm -rf debian/tmp
	install -d debian/tmp
	cd debian/tmp && install -d DEBIAN $(binpath) $(doc) $(man)
	install -m 755 fortune debian/tmp/$(binpath)
	dpkg-shlibdeps $(bin)
	strip debian/tmp/$(binpath)/$(bin)
	cp debian/changelog debian/tmp/$(doc)
	gzip -9f debian/tmp/$(doc)/*
	cp debian/copyright debian/tmp/$(doc)
	install -m 644 debian/fortune.6 debian/tmp/$(man)
	cd debian/tmp && gzip -9f $(man)/$(bin).6
	cd debian/tmp &&\
	  md5sum `find * -name DEBIAN -prune -o -type f -print`\
	   > DEBIAN/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

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