#!/usr/bin/make -f
#
# debian/rules for getpath
#

SHELL	= /bin/bash

pkg	= getpath
tmp	= $(shell pwd)/debian/tmp

build:	$(checkdir)
	make
	touch build

clean:	checkroot
	make distclean || echo "\nWARNING -- ignoring 'make clean' error\n"
	rm -f build debian/files debian/substvars
	rm -rf $(tmp)

binary:	build checkroot
	#
	# dir structure
	-rm -rf $(tmp)
	install -o root -g root -m 755 -d $(tmp)
	install -o root -g root -m 755 -d $(tmp)/{DEBIAN,etc,usr}
	install -o root -g root -m 755 -d $(tmp)/usr/{bin,share}
	install -o root -g root -m 755 -d $(tmp)/usr/share/{doc,man}
	install -o root -g root -m 755 -d $(tmp)/usr/share/doc/$(pkg)
	install -o root -g root -m 755 -d $(tmp)/usr/share/man/man8
	#
	# binary
	install -o root -g root -m 755 -s getpath	$(tmp)/usr/bin/getpath
	#
	# documentation
	install -o root -g root -m 644 getpath.8	$(tmp)/usr/share/man/man8/getpath.8
	gzip -9f $(tmp)/usr/share/man/man8/getpath.8
	install -o root -g root -m 644 debian/changelog	$(tmp)/usr/share/doc/$(pkg)/changelog.Debian
	install -o root -g root -m 644 README*		$(tmp)/usr/share/doc/$(pkg)
	gzip -9f $(tmp)/usr/share/doc/$(pkg)/*
	install -o root -g root -m 644 debian/copyright	$(tmp)/usr/share/doc/$(pkg)
	#
	# configuration
	#install -o root -g root -m 644 getpath.conf	$(tmp)/etc/getpath.conf.new
	install -o root -g root -m 644 getpath.conf	$(tmp)/etc/getpath.conf
	#
	# debian
	install -o root -g root -m 644 debian/templates	$(tmp)/DEBIAN/templates
	install -o root -g root -m 755 debian/config	$(tmp)/DEBIAN/config
	#install -o root -g root -m 755 debian/preinst	$(tmp)/DEBIAN/preinst
	install -o root -g root -m 755 debian/postinst	$(tmp)/DEBIAN/postinst
	install -o root -g root -m 755 debian/prerm	$(tmp)/DEBIAN/prerm
	install -o root -g root -m 755 debian/postrm	$(tmp)/DEBIAN/postrm
	install -o root -g root -m 644 debian/conffiles	$(tmp)/DEBIAN/conffiles
	dpkg-gencontrol -isp -p$(pkg) -P$(tmp)
	dpkg --build $(tmp) ..
	rm -rf $(tmp)

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

.PHONY: binary clean checkroot
