#!/usr/bin/make -f

PACKAGE = $(shell dh_listpackages)
TMP     = $(CURDIR)/debian/$(PACKAGE)
MAN3    = $(TMP)/usr/share/man/man3

%:
	dh $@

override_dh_install:
	dh_install
	sed -i '1s|^#!/usr/bin/env perl|#!/usr/bin/perl|' $(TMP)/usr/share/perl5/PDF/Table.pm

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

execute_before_dh_installman:
	# Documentation reorganisation seems to have lead to manpages mismatch.
	# PDF::Table.3pm is mostly empty at this point and the manual page has
	# to be forcefully regenerated using Table.pod, per upstream notice.
	chmod 0666 $(MAN3)/PDF::Table.3pm
	pod2man --section 3pm $(CURDIR)/lib/PDF/Table.pod \
	> $(MAN3)/PDF::Table.3pm
	chmod 0444 $(MAN3)/PDF::Table.3pm
