#!/usr/bin/make -f
# Build rules for pmake (1.39)
# Based on Ian Jackson's sample rules file for GNU hello
# Copyright 1994,1995 by Ian Jackson.
# Copyright 1997,1998 by James Troup.
# Copyright 1999 by Edward Brocklesby.
# 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.)

ARCH=$(shell dpkg --print-gnu-build-architecture)
CFLAGS="-O2  -g -Wall -D__COPYRIGHT\(x\)= -D__RCSID\(x\)= \
	-I. -DMACHINE=\\\"debian\\\" -DMACHINE_ARCH=\\\"${ARCH}\\\" \
	-D_GNU_SOURCE"

build:
	$(checkdir)
	$(MAKE) -f Makefile.boot CFLAGS=$(CFLAGS)
	touch build

clean:
	$(checkdir)
	$(MAKE) -f Makefile.boot clean
	-rm -rf build *~ debian/tmp debian/*~ debian/files* debian/substvar*

binary-indep:   checkroot build
	$(checkdir)

binary-arch:    checkroot build
	$(checkdir)
	-rm -rf debian/tmp/
	install -d -m 755 debian/tmp/DEBIAN/
	install -m 644 debian/control debian/tmp/DEBIAN/

	install -d -m 755 debian/tmp/usr/bin/
	install -s -m 755 bmake debian/tmp/usr/bin/pmake
	install -m 755 mkdep debian/tmp/usr/bin/

	install -d -m 755 debian/tmp/usr/share/man/man1/
	install -m 644 make.1 debian/tmp/usr/share/man/man1/pmake.1
	install -m 644 mkdep.1 debian/tmp/usr/share/man/man1/
	gzip -9v debian/tmp/usr/share/man/man1/*

	install -d -m 755 debian/tmp/usr/share/mk/
	for file in mk/*; \
	do \
	  install -m 644 $$file debian/tmp/usr/share/$$file; \
	done

	install -d -m 755 debian/tmp/usr/share/doc/pmake/
	groff -Tascii -ms PSD.doc/tutorial.ms > \
	      debian/tmp/usr/share/doc/pmake/tutorial.asc
	groff -Tps -ms PSD.doc/tutorial.ms > \
	      debian/tmp/usr/share/doc/pmake/tutorial.ps
	cp debian/changelog debian/tmp/usr/share/doc/pmake/changelog.Debian
	gzip -9v debian/tmp/usr/share/doc/pmake/*
	install -m 644 debian/copyright  debian/tmp/usr/share/doc/pmake/

	-install -m 755 debian/preinst debian/tmp/DEBIAN/preinst
	-install -m 755 debian/postinst debian/tmp/DEBIAN/postinst
	-install -m 755 debian/prerm debian/tmp/DEBIAN/prerm
	-install -m 755 debian/postrm debian/tmp/DEBIAN/postrm

	dpkg-shlibdeps debian/tmp/usr/bin/pmake
	dpkg-gencontrol -isp
	chown -R root.root debian/tmp/
	chmod -R go=rX debian/tmp/
	dpkg --build debian/tmp/ ..

define checkdir
	test -f make.c -a -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
