#!/usr/bin/make -f
# PDL debian build rules
# Made with the aid of debmake, by Christoph Lameter,
# based on the sample debian/rules file for GNU hello by Ian Jackson.
 
package=pdl

ddir=`pwd`/debian/tmp
arch = $(shell dpkg --print-architecture)

INSTALL=/usr/bin/install

build:
	$(checkdir)
	HOME=`pwd`/debian perl Makefile.PL INSTALLDIRS=perl PREFIX=$(ddir)/usr
#	    INSTALLPRIVLIB=${ddir}/usr/lib/perl5
	make
	#make test	## disabled until doesn't require X
#	make doctest   dont make the docs do it in postinst
	touch build

clean:
	$(checkdir)
	touch deleteme
	(find . -type f | sed 's}^\./}}' | egrep -v ^debian; cat MANIFEST MANIFEST) | sort | uniq -u | xargs rm 
	-rm -rf blib
	-rm -f `find . -name "*~"`
	-rm -rf debian/tmp debian/files* core debian/substvars

binary-indep: checkroot build
	$(checkdir)
# There are no architecture-independent files to be uploaded
# generated by this package.  If there were any they would be
# made here.

binary-arch: checkroot build
	$(checkdir)
	
	-rm -rf debian/tmp
	$(INSTALL) -d debian/tmp/DEBIAN
	$(INSTALL) -d debian/tmp/usr/share/doc/$(package)
	export BUILDROOTPREFIX=${ddir}; make  pure_install 
# these scripts are not part of the distribution, but we need them for
# postinst
	set -vx; d=`find debian/tmp/usr -type d -name PDL | sed 's}/auto/}/}' | sort -u`/Doc && mkdir -p $$d; cp Doc/scantree.pl Doc/mkhtmldoc.pl $$d/.
	set -vx; (d=/`cd debian/tmp; find usr -type d -name PDL | sed 's}/auto/}/}' | sort -u`/Doc; cat debian/postinst.base; q='>/dev/null 2>&1'; echo perl $$d/scantree.pl $$q; echo perl $$d/mkhtmldoc.pl $$q) > debian/postinst
	rm -f `find debian/tmp/usr/lib/perl5 -name perllocal.pod`
	find debian/tmp/usr/share/man -type f | xargs gzip -9
	# remove packlist files
	find `pwd`/debian/tmp -type f -name .packlist | xargs -r rm -f
#	find `pwd`/debian/tmp -type d -empty | xargs -r rmdir -p --no-fail-on-non-empty
	$(INSTALL) -m 644 README   debian/tmp/usr/share/doc/$(package)
	$(INSTALL) -m 644 TODO     debian/tmp/usr/share/doc/$(package)
	$(INSTALL) -m 644 debian/README.debian     debian/tmp/usr/share/doc/$(package)
	$(INSTALL) -m 644 debian/changelog   debian/tmp/usr/share/doc/$(package)/changelog.Debian
	$(INSTALL) -m 644 Changes     debian/tmp/usr/share/doc/$(package)/changelog

	-cd debian/tmp/usr/share/doc/$(package);  gzip -9v README TODO  README.debian changelog changelog.Debian
	cp debian/copyright debian/tmp/usr/share/doc/$(package)/copyright

	chmod 755 debian/tmp/usr/bin/*

# Install menu entry

	  $(INSTALL) -d  debian/tmp/usr/lib/menu
	  cp debian/$(package)-menu  debian/tmp/usr/lib/menu/$(package)

# copy postinst and postrm

	cp debian/postinst debian/tmp/DEBIAN
	cp debian/postrm debian/tmp/DEBIAN
	cp debian/preinst debian/tmp/DEBIAN

	chmod +x debian/tmp/DEBIAN/postinst debian/tmp/DEBIAN/postrm debian/tmp/DEBIAN/preinst

#	debstd Changes README TODO 
	dpkg-shlibdeps `ls blib/arch/auto/PDL/*/*.so`
	dpkg-gencontrol
	chown -R root.root debian/tmp
	chmod -R go=rX debian/tmp
# fix up some rather odd permissions issues
	find debian/tmp/usr/lib debian/tmp/usr/share/man -type f | xargs chmod 644
# clean up any extra symbols
	find debian/tmp/usr/lib -name '*.so' | xargs strip --strip-unneeded -R .comment -R .note
	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




