#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# Enable hardening build flags
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

subst_pdlapi = -Vpdlapi:Provides="`perl -Mblib -MPDL::Config::Debian -e 'print \"pdlapi-$$PDL::Config::Debian::pdl_core_version\n\"'`"

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

TEMPLATES=$(wildcard debian/*.in)

templates:
	for TEMPLATE in $(TEMPLATES) ; do \
	    sed -e 's,@vendorarch@,$(vendorarch),g' $$TEMPLATE > `echo $$TEMPLATE | sed 's/.in$$//'` ; \
	done

%:
	dh $@

override_dh_clean:
	dh_clean t/callext.o t/callext.so Graphics/TriD/OpenGL/tmp*.h-out \
	         Perldl2/pdl2.pod debian/dh_pdl.1

override_dh_auto_configure: templates
	dh_auto_configure -- F77CONF=debian/f77conf.pl \
	                     PDLCONF=debian/perldl.conf

override_dh_auto_build:
	LD_RUN_PATH="" dh_auto_build

	mkdir -p blib/lib/PDL/Config
	perl -Mblib debian/write_config_debian.pl > blib/lib/PDL/Config/Debian.pm

	pod2man debian/dh_pdl > debian/dh_pdl.1

override_dh_auto_test:
	@echo "BEGIN test verbose"
	TEST_VERBOSE=1 LC_ALL=C dh_auto_test
	@echo "END test verbose"

override_dh_auto_install:
	dh_auto_install --destdir=$(CURDIR)/debian/pdl --max-parallel=1

	(cd debian/pdl; while read f ; do rm -f "$$f" ; done < ../pdl.remove)

	# create placeholder in usr/share/perl5/PDL
	echo > $(CURDIR)/debian/pdl/usr/share/perl5/PDL/.placeholder

	# Strip RPATH
	chrpath --delete debian/*/$(vendorarch)/auto/PDL/Minuit/Minuit.so
	chrpath --delete debian/*/$(vendorarch)/auto/PDL/Slatec/Slatec.so

override_dh_missing:
	dh_missing --list-missing

override_dh_shlibdeps:
	dh_shlibdeps -X OpenGLQ.so

override_dh_gencontrol:
	dh_gencontrol -- $(subst_pdlapi)
