#! /usr/bin/make -f
#
# Last updated: Thu Apr 26 22:00:00 CDT 1995 by david.
#
# 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 `diff' target assumes that you have the original
# source package available, unpacked, in ../$(p)-$(v).orig, or that you have
# the previous revision of the ``Debianized'' source package and context diff
# in the parent directory.

include Version.mk
v = $(VERSION)
vm = $(VMAJOR)
arch = $(shell dpkg --print-architecture)
ifeq ($(arch),i386)
archx = i486
else
archx = $(arch)
endif

build:
# Builds the binary package.
	make ARCH=$(arch) clean
	make ARCH=$(arch)
	touch build

clean:
# Undoes the effect of `make -f debian.rules build'.
	make ARCH=$(arch) clean
	rm -f build
	rm -rf debian/tmp debian/files

binary-indep:   checkroot build
        $(checkdir)

binary-arch:    checkroot build
	$(checkdir)
	rm -rf debian/tmp
	install -d -m 755 debian/tmp
	chmod g-s debian/tmp
	install -d -m 755 debian/tmp/sbin
	install -s -m 755 util/ldconfig debian/tmp/sbin/ldconfig.new
	install -d -m 755 debian/tmp/usr/man/man8
	install -m 644 man/ldconfig.8 debian/tmp/usr/man/man8/ldconfig.8
	gzip -9 debian/tmp/usr/man/man*/*
	install -d -m 755 debian/tmp/usr/doc/ldconfig
	install -m 644 debian/copyright debian/tmp/usr/doc/ldconfig/copyright
	install -m 644 README debian/tmp/usr/doc/ldconfig/README
	gzip -9f debian/tmp/usr/doc/ldconfig/README
	install -m 644 debian/changelog debian/tmp/usr/doc/ldconfig/changelog
	gzip -9f debian/tmp/usr/doc/ldconfig/changelog
	install -d -m 755 debian/tmp/DEBIAN
	sed -e 's/VERSION/$(v)/g' -e 's/VMAJOR/$(vm)/g' debian/postinst \
		> debian/tmp/DEBIAN/postinst
	chmod 755 debian/tmp/DEBIAN/postinst

	dpkg-gencontrol
	chmod -R g-w debian/tmp
	chown -R root.root debian/tmp
	dpkg --build debian/tmp ..

binary: binary-indep binary-arch

checkroot:
	test root = "`whoami`"

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