#!/usr/bin/make -f

package = base-files
docdir = debian/tmp/usr/doc/$(package)

build:
	$(checkdir)
	touch build

clean:
	$(checkdir)
	-rm -f build
	-rm -f `find . -name "*~"`
	-rm -rf debian/tmp debian/files* core debian/substvars

binary-arch: checkroot build
	$(checkdir)

binary-indep: checkroot build
	$(checkdir)
	-rm -rf debian/tmp
	install -d debian/tmp/DEBIAN $(docdir)
	cd debian/tmp && install -d usr/share/$(package)
	install -p -m 644 debian/copyright debian/changelog $(docdir)
	cd debian && install -m 755 preinst postinst tmp/DEBIAN
	cd debian && install -m 644 conffiles tmp/DEBIAN
	cd debian/tmp && install -d `cat ../directory-list`
	# cd debian/tmp && ln -s /var/spool usr/spool
	# cd debian/tmp && ln -s /var/tmp   usr/tmp
	# cd debian/tmp && ln -s /var/log   usr/adm
	# cd debian/tmp && ln -s log        var/adm
	cd debian/tmp && chown root.src     usr/src
	cd debian/tmp && chown root.mail    var/spool/mail
	cd debian/tmp && chown root.adm     var/log
	cd debian/tmp && chown root.staff   var/local
	# cd debian/tmp && chown root.staff   var/local/usr
	cd debian/tmp && chown root.floppy  floppy
	cd debian/tmp && chown root.disk    boot
	cd debian/tmp && chown root.staff   home
	cd debian/tmp && chown root.cdrom   cdrom
	cd debian/tmp && chmod 755  `find . -type d`
	cd debian/tmp && chmod 1777 `cat ../1777-dirs`
	cd debian/tmp && chmod 2775 `cat ../2775-dirs`
	install -p -m 644 root/dot.profile root/dot.bashrc \
		debian/tmp/usr/share/base-files
	install -p -m 644 licenses/* debian/tmp/usr/share/common-licenses
	ln -s ../../share/common-licenses/GPL \
		debian/tmp/usr/doc/copyright/GPL
	ln -s ../../share/common-licenses/LGPL \
		debian/tmp/usr/doc/copyright/LGPL
	ln -s ../../share/common-licenses/BSD \
		debian/tmp/usr/doc/copyright/BSD
	ln -s ../../share/common-licenses/Artistic \
		debian/tmp/usr/doc/copyright/Artistic 
	# install -p -m 755 bin/edit  debian/tmp/bin
	install -p -m 644 etc/* debian/tmp/etc
	install -p -m 644 debian/README $(docdir)
	gzip -9 $(docdir)/changelog
	dpkg-gencontrol
	dpkg --build debian/tmp ..

define checkdir
	test -f debian/rules
endef

binary: binary-indep binary-arch

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

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