The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/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=vendor PREFIX=$(ddir)/usr 
	$(MAKE) OPTIMIZE="-O2 -g -Wall"
	#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 $(ddir) debian/files* core debian/substvars

binary-indep: checkroot build
	$(checkdir)
	perl -MConfig -le 'print "perl:Depends=perlapi-$Config{version}"' >>debian/substvers

binary-arch: checkroot build
	$(checkdir)
	
	-rm -rf $(ddir)
	$(INSTALL) -d $(ddir)/DEBIAN
	$(INSTALL) -d $(ddir)/usr/share/doc/$(package)
	export BUILDROOTPREFIX=${ddir}; make  pure_install 
# these scripts are not part of the distribution, but we need them for
# postinst [use sort -u to give me an error if this is ever ambiguous]
	set -vx; d=$$(find $(ddir)/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 $(ddir); 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 $(ddir)/usr/lib/perl5 -name perllocal.pod)
	find $(ddir)/usr/share/man -type f | xargs gzip -9
	# remove packlist files
	find $(ddir) -type f -name .packlist | xargs -r rm -f
#	find $(ddir) -type d -empty | xargs -r rmdir -p --no-fail-on-non-empty
	$(INSTALL) -m 644 README $(ddir)/usr/share/doc/$(package)
	$(INSTALL) -m 644 TODO $(ddir)/usr/share/doc/$(package)
	$(INSTALL) -m 644 debian/README.debian $(ddir)/usr/share/doc/$(package)
	$(INSTALL) -m 644 debian/changelog $(ddir)/usr/share/doc/$(package)/changelog.Debian
	$(INSTALL) -m 644 Changes $(ddir)/usr/share/doc/$(package)/changelog

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

	chmod 755 $(ddir)/usr/bin/*

# Install menu entry
	  $(INSTALL) -d  $(ddir)/usr/lib/menu
	  cp debian/$(package)-menu  $(ddir)/usr/lib/menu/$(package)

# copy dpkg scripts
	for f in postinst postrm preinst prerm; do \
		cp debian/$$f $(ddir)/DEBIAN; \
		chmod +x $(ddir)/DEBIAN/$$f; \
	done

#	debstd Changes README TODO 
	dpkg-shlibdeps $$(find blib -name '*.so')
	dpkg-gencontrol
	chown -R root.root $(ddir)
	chmod -R go=rX $(ddir)
# fix up some rather odd permissions issues
	find $(ddir)/usr/lib $(ddir)/usr/share/man -type f | xargs chmod 644
# clean up any extra symbols
	find $(ddir)/usr/lib -name '*.so' | xargs strip --strip-unneeded -R .comment -R .note
	dpkg --build $(ddir) ..

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