#!/usr/bin/make -f
# 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=xjig
CXX=c++ -g -Wall
INSTALL = install
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL += -s
endif
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CXX += -O0
else
	CXX += -O2
endif



build:
	$(checkdir)
	xmkmf # djh
	make depend # djh
	cp xjig.man xjig.6
	if [ -x configure ]; then ./configure --prefix=/usr; fi
	make CXX="$(CXX)"

	touch build

clean:
	$(checkdir)
	-rm -f build
	-rm -f xjig xjig.6
	[ ! -f Makefile ] || $(MAKE) clean
	-rm `find . -name "*~"`
	-rm -rf debian/tmp debian/files* core debian/substvars

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/DEBIAN debian/tmp/usr/share/doc/xjig debian/tmp/usr/share/man/man6
	if [ -x configure ]; then \
	  make install CXX="$(CXX)" prefix=`pwd`/debian/tmp/usr ;\
	else \
	  make install CXX="$(CXX)" DESTDIR=`pwd`/debian/tmp; \
	fi
	mkdir -p debian/tmp/usr/lib/games/xjig
	cp tina.gif debian/tmp/usr/lib/games/xjig
	cp README* debian/README.debian debian/tmp/usr/share/doc/xjig
	cp debian/changelog debian/tmp/usr/share/doc/xjig/changelog.Debian
	mkdir -p debian/tmp/usr/share/menu
	cp debian/menu debian/tmp/usr/share/menu/xjig
	gzip -9v debian/tmp/usr/share/doc/xjig/*
	cp debian/copyright debian/tmp/usr/share/doc/xjig
	cp xjig.6 debian/tmp/usr/share/man/man6
	cp xjig-random.man debian/tmp/usr/share/man/man6/xjig-random.6
	gzip -9v debian/tmp/usr/share/man/man6/*
	mkdir -p debian/tmp/usr/games
	chmod a+rx xjig-random
	cp xjig-random debian/tmp/usr/games
	$(INSTALL) debian/tmp/usr/bin/xjig debian/tmp/usr/games/.
	rm -rf debian/tmp/usr/bin
	install -m 755 debian/prerm debian/postinst debian/postrm debian/tmp/DEBIAN
	dpkg-shlibdeps debian/tmp/usr/games/xjig
	dpkg-gencontrol -isp
	chown -R root.root debian/tmp
	chmod -R go=rX 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
