#!/usr/bin/make -f
# Made with the aid of debmake, by Christoph Lameter,
# based on the sample debian/rules file for GNU hello by Ian Jackson.

package=crafty

build:
	$(checkdir)
	make
	touch build

clean:
	$(checkdir)
	-rm -f build
	-make clean
	-rm -f `find . -name "*~"`
	-rm -rf debian/tmp debian/files* core debian/substvars
	-rm -f game* log* position* books.bin book.bin

binary-indep: checkroot 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: checkroot build
	$(checkdir)
	-rm -rf debian/tmp
	install -d debian/tmp
	cd debian/tmp && install -d `cat ../dirs`
	install -s crafty debian/tmp/usr/games
	cp debian/craftywatch debian/tmp/usr/games
	chmod 755 debian/tmp/usr/games/craftywatch
#	Build the opening books.
	echo "book create debian/medtosmall.txt 60" \
	     | debian/tmp/usr/games/crafty
	echo "books create debian/start.pgn 60" \
	     | debian/tmp/usr/games/crafty
#	When you create the books above, you also create these extra files.
	-rm -f /usr/lib/games/crafty/position.bin
	-rm -f /usr/lib/games/crafty/position.lrn
	-rm -f /usr/lib/games/crafty/book.lrn
	cp books.bin debian/tmp/usr/lib/games/crafty
	cp book.bin debian/tmp/usr/lib/games/crafty
	chmod 644 debian/tmp/usr/lib/games/crafty/books.bin
	chmod 644 debian/tmp/usr/lib/games/crafty/book.bin
	cp debian/crafty.doc debian/tmp/usr/doc/crafty
	cp debian/crafty.faq debian/tmp/usr/doc/crafty
	cp debian/read.me debian/tmp/usr/doc/crafty
	chmod 644 debian/tmp/usr/doc/crafty/crafty.doc
	chmod 644 debian/tmp/usr/doc/crafty/crafty.faq
	chmod 644 debian/tmp/usr/doc/crafty/read.me
#	debstd gzips the next two.
#	gzip -9 debian/tmp/usr/doc/crafty/crafty.doc
#	gzip -9 debian/tmp/usr/doc/crafty/crafty.faq
	gzip -9 debian/tmp/usr/doc/crafty/read.me
	ln -sf ../man7/undocumented.7.gz debian/tmp/usr/man/man6/crafty.6.gz
	ln -sf ../man7/undocumented.7.gz \
               debian/tmp/usr/man/man6/craftywatch.6.gz
	cp debian/craftyrc debian/tmp/etc
# Must have debmake installed for this to work. Otherwise please copy
# /usr/bin/debstd into the debian directory and change debstd to debian/debstd
	debstd 
	dpkg-gencontrol
	chown -R root.root debian/tmp
	chmod -R go=rX debian/tmp
	dpkg --build debian/tmp ..

define checkdir
	test -f debian/rules
endef

binary: binary-indep binary-arch

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

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