#! /usr/bin/make -f
#
# 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
# Copyright 1996 by Kevin Dalley.

# To make the binary distribution package, the ``Debianized'' source package
# and the context diff to the original package, type `./debian.rules dist'.
# Make sure that `debian.rules' is executable before the final distribution
# is made.
#
# Invoke each target with `./debian.rules <target>'.  All targets should be
# invoked with the package root as the current directory.
#
# The `binary' target must be run as root, as it needs to install files with
# specific ownerships.

# The name of the package (for example, `emacs').
package = dejagnu

CC = gcc
CFLAGS = -O2 -Wall # sane warning options vary between programs
LDFLAGS = # none


build:
	$(checkdir)
	./configure --prefix=/usr
	$(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
	  libexecdir=/usr/lib/locate localstatedir=/var/lib/locate all
#	$(MAKE)
	touch build

clean:
	$(checkdir)
	-rm -f build
	-$(MAKE) -i distclean
	-rm -rf *~ debian/tmp debian/*~ debian/files*
	rm -f config.cache doc/config.log testsuite/config.log \
		testsuite/.tmp testsuite/dbg.log testsuite/runtest.log \
		testsuite/runtest.sum testsuite/setval.tmp \
		testsuite/testrun.log testsuite/testrun.sum \
		example/testrun.sum

binary-indep:	checkroot build
	$(checkdir)
	-rm -rf debian/tmp
	install -d debian/tmp debian/tmp/DEBIAN
	install -d debian/tmp/usr/doc/$(package)
	install -d -g root -m 755 -o root debian/tmp/etc/$(package)
	install debian/{postinst,preinst} debian/tmp/DEBIAN/.
	cd $(package); $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" \
	  LDFLAGS="$(LDFLAGS)" \
	  prefix=`pwd`/debian/tmp/usr install
	chmod 0644 debian/tmp/usr/share/dejagnu/runtest.exp
	cd $(package); $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" \
	  LDFLAGS="$(LDFLAGS)" \
	  pkgdatadir=debian/tmp/usr/doc/$(package) install-doc
#	gzip -9v debian/tmp/usr/info/*
#	gzip -9v debian/tmp/usr/man/man1/*
	install -d debian/tmp/usr/doc/$(package)/html/stylesheet-images
	install -m 0644 doc/overview.rtf debian/tmp/usr/doc/$(package)
	install -m 0644 doc/overview.ps debian/tmp/usr/doc/$(package)
	install -m 0644 doc/overview.pdf debian/tmp/usr/doc/$(package)
	install -m 0644 doc/html/*.html debian/tmp/usr/doc/$(package)/html/
	install -m 0644 debian/copyright debian/tmp/usr/doc/$(package)
	install -m 0644 debian/changelog debian/tmp/usr/doc/$(package)/changelog.Debian
	gzip -9v debian/tmp/usr/doc/$(package)/changelog.Debian
	install -m 0644 ChangeLog debian/tmp/usr/doc/$(package)
	gzip -9v debian/tmp/usr/doc/$(package)/ChangeLog
	ln -s ChangeLog.gz debian/tmp/usr/doc/$(package)/changelog.gz
	install -g root -m 644 -o root debian/site.exp \
		debian/tmp/etc/$(package)/site.exp
	cd debian/tmp/usr/lib/$(package); ln -fs /etc/$(package)/site.exp .
#	install -d debian/tmp/usr/doc/$(package)/examples
	-cd example; $(MAKE) -i distclean
#	(cd example; tar cf - . ) | \
#		(cd debian/tmp/usr/doc/$(package)/examples; tar xf -)
#	install debian/tmp/usr/doc/$(package)/examples
	dpkg-gencontrol
#	chown -R root.root debian/tmp
#	chmod -R g-ws debian/tmp
	dpkg --build debian/tmp ..

binary-arch:

define checkdir
	test -f runtest.exp -a -f debian/rules
endef
# Below here is fairly generic really

binary:		binary-indep

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
