#!/usr/bin/make -f
# derived from: 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
#
# the debian-boot team

package	:= boot-floppies

prefix	:= debian/tmp
docdir	:= $(prefix)/usr/share/doc/$(package)
install_file	:= install -o root -g root -m 644 -p
install_script	:= install -o root -g root -m 755 -p
install_program	:= install -o root -g root -m 755 -p --strip
make_dir	:= install -d -o root -g root -m 755

arch	:= $(shell dpkg --print-architecture)
version	:= $(shell LC_ALL=C dpkg-parsechangelog | sed -n 's/^Version: *//p')
dist	:= $(shell LC_ALL=C dpkg-parsechangelog | sed -n 's/^Distribution: *//p')


build:
	$(checkdir)
	$(MAKE) localfiles
	$(MAKE) check
	$(MAKE) release
	touch build

release/bf-archive-install.sh:	debian/bf-archive-install.sh
	sed 's/%arch%/$(arch)/g; s/%dist%/$(dist)/g; s/%version%/$(version)/g;' $^ > $@
	chmod a+x $@

clean:
	$(checkdir)
	-$(MAKE) -i distclean
	dh_clean
	rm -f build
	find . -name '.#*' | xargs rm -f

binary-indep:	checkroot
	$(checkdir)
	dh_clean -k

	$(make_dir) $(prefix)/usr/src/$(package)
	tar --exclude $(prefix) --exclude CVS --exclude .cvsignore -cf - . \
	    | tar -C $(prefix)/usr/src/$(package) -xf -
	cd $(prefix)/usr/src/$(package) && ./debian/rules clean
	chown -R root.root $(prefix)/usr/src/$(package)
	chmod -R go-w,a+X,a-s $(prefix)/usr/src/$(package)
	cd $(prefix)/usr/src && \
	    GZIP=-9 tar -czf $(package).tar.gz --remove-files $(package)
	rm -rf $(prefix)/usr/src/$(package)

	dh_installdocs -i README
	dh_installchangelogs -i
	dh_compress -i
	dh_fixperms -i

	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

binary-arch:	checkroot build
	$(checkdir)
	(cd release/ ; for i in * ; do \
		cp -p $$i ../../ ; \
		dpkg-distaddfile -f../debian/files $$i byhand - ; \
	done ) 

define checkdir
	test -f rootdisk.sh -a -f debian/rules
endef

# Below here is fairly generic really

binary:		binary-indep binary-arch

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

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