#!/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)

doc-package	:= install-doc
doc-prefix	:= debian/$(doc-package)
doc-docdir	:= $(doc-prefix)/usr/share/doc/$(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-arch:	checkroot build
	$(checkdir)

#	 build the by-hand materials for dists/<dist>/main/disks-<arch>/...
	(cd release/ ; for i in * ; do \
		cp -p $$i ../../ ; \
		dpkg-distaddfile -f../debian/files $$i byhand - ; \
	done )

#	 build the install-doc package
	rm -rf $(doc-prefix)
	$(make_dir) $(doc-docdir)
	$(MAKE) -C documentation DESTDIR=$(shell pwd)/$(doc-docdir) install
	dh_installdocs -p $(doc-package) README-CVS
	dh_installchangelogs -p $(doc-package)
	dh_compress -p $(doc-package)
	dh_fixperms -p $(doc-package)

	dh_installdeb -p $(doc-package)
	dh_gencontrol -p $(doc-package)
	dh_md5sums -p $(doc-package)
	dh_builddeb -p $(doc-package)


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

# Below here is fairly generic really

binary:	binary-arch

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

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