#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+bindnow

PACKAGE = $(shell dh_listpackages)
TMP     = $(CURDIR)/debian/$(PACKAGE)

ARCHLIB := $(shell perl -MConfig -e 'print $$Config{vendorarch}')

%:
	dh $@

override_dh_auto_install:
	dh_auto_install
	mv $(TMP)/usr/bin/primes.pl $(TMP)/usr/bin/primes
	mkdir -p $(TMP)/usr/share/man/man1
	PERL5LIB=$(TMP)/$(ARCHLIB) help2man -n 'Display all primes' --no-info --no-discard-stderr $(TMP)/usr/bin/primes | gzip -9 > $(TMP)/usr/share/man/man1/primes.1.gz
	PERL5LIB=$(TMP)/$(ARCHLIB) help2man -n 'Print prime factors' --no-info --no-discard-stderr $(TMP)/usr/bin/factor.pl | gzip -9 > $(TMP)/usr/share/man/man1/factor.pl.1.gz
	find $(TMP)/usr/bin -type f -print0 | \
		 xargs -r0 sed -i -e '1s|^#!/usr/bin/env perl|#!/usr/bin/perl|'

override_dh_installexamples:
	dh_installexamples
	find $(TMP)/usr/share/doc/$(PACKAGE)/examples -type f -name "*.pl" -print0 | \
		xargs -r0 sed -i -e '1s|^#!/usr/bin/env perl|#!/usr/bin/perl|'
