#!/usr/bin/make -f
############################ -*- Mode: Makefile -*- ###########################
## rules ---
## Author           : Manoj Srivastava ( srivasta@tiamat.datasync.com )
## Created On       : Sat Dec 28 18:16:05 1996
## Created On Node  : tiamat.datasync.com
## Last Modified By : Manoj Srivastava
## Last Modified On : Tue Apr  7 01:29:23 1998
## Last Machine Used: tiamat.datasync.com
## Update Count     : 60
## Status           : Unknown, Use with caution!
## HISTORY          :
## Description      :
##
###############################################################################

FILES_TO_CLEAN = debian/files angband debian/buildinfo debian/substvars
STAMPS_TO_CLEAN = stamp-binary
DIRS_TO_CLEAN  = debian/tmp
thisdir=$(shell pwd)

install_file= /usr/bin/install -p -o root -g root -m 644
install_program= /usr/bin/install -p -o root -g root -m 755
make_directory= /usr/bin/install -p -d -o root -g root -m 755

package = $(shell grep Source debian/control | sed 's/^Source: //')
DOCDIR := debian/tmp/usr/doc/$(package)

LIBDIR:= var/lib/games/angband/info
STATICDIR:= usr/lib/games/angband/info

TMPLIBDIR:= debian/tmp/$(LIBDIR)
TMPSTATICDIR:= debian/tmp/$(STATICDIR)

all build: stamp-build
stamp-build:

clean:
	$(checkdir)
	rm -f  $(FILES_TO_CLEAN) $(STAMPS_TO_CLEAN)
	rm -rf $(DIRS_TO_CLEAN)
	rm -f core `find . \( -name '*.orig' -o -name '*.rej' -o \
	  -name '*~' -o -name '*.bak' -o -name '#*#' -o \
	  -name '.*.orig' -o -name '.*.rej' -o -name '.SUMS' -o \
	  -size 0 \) -print` TAGS

binary:		binary-indep binary-arch

binary-indep:	stamp-binary
	$(checkdir)

binary-arch:

stamp-binary:
	@test root = "`whoami`" || (echo need root priviledges; exit 1)
	$(checkdir)
	-rm -rf                 debian/tmp
	$(make_directory)       $(DOCDIR)
	$(make_directory)       $(TMPLIBDIR)
	$(make_directory)       $(TMPSTATICDIR)
	$(make_directory)       debian/tmp/DEBIAN
	$(make_directory)       debian/tmp/usr/lib/menu
	(cd Help-Info;          tar cf - *) | (cd $(TMPSTATICDIR); tar xf -)
	(cd $(TMPLIBDIR);                                                 \
            for file in         ../../../../../$(STATICDIR)/*;            \
              do                                                          \
                                ln -s /$(STATICDIR)/`basename $$file` . ; \
              done; );
	$(install_file)         debian/changelog     $(DOCDIR)/changelog
	$(install_file)         debian/README.debian $(DOCDIR)/
	gzip -9fqr              $(DOCDIR)
# Make sure the copyright file is not compressed
	$(install_file)         debian/copyright     $(DOCDIR)/
	(cd Help-Page;          tar cf - *) | (cd $(DOCDIR); tar xf -)
	gzip -9fq               $(DOCDIR)/angfaq*.txt
	$(install_file)         debian/menuentry \
	                         debian/tmp/usr/lib/menu/$(package)
	$(install_program)      debian/postinst \
                                debian/tmp/DEBIAN/postinst
	$(install_program)      debian/postrm \
                                debian/tmp/DEBIAN/postrm
	dpkg-gencontrol
	chown -R root.root      debian/tmp/
	chmod -R go=rX          debian/tmp/
	dpkg --build            debian/tmp ..

define checkdir
	test -f Help-Info/artifact.spo -a -f debian/rules
endef

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

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