#!/usr/bin/make -f

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

export LDFLAGS=-Wl,--as-needed

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- --enable-gif --enable-lzw

override_dh_auto_build:
	xsltproc --nonet -o debian/ \
	    /usr/share/xml/docbook/stylesheet/docbook-xsl-ns/manpages/docbook.xsl \
	    debian/sam2p_pdf_scale.1.xml
	# (the generated file debian/sam2p_pdf_scale.1 is cleaned by
	# dh_clean(1), cf. debian/clean)
	dh_auto_build

override_dh_auto_install:
	dh_auto_install -- prefix=$(CURDIR)/debian/sam2p/usr

override_dh_install:
	dh_install
	perl -0777 -p -e 's{.*?http://www.inf.bme.hu/~pts/Magic.Perl.Header\s*$$}{#!/usr/bin/perl -w}ms' \
		< sam2p_pdf_scale.pl > debian/sam2p/usr/bin/sam2p_pdf_scale

override_dh_installchangelogs:
	dh_installchangelogs debian/changelog.upstream

override_dh_installexamples:
	dh_installexamples
	# Removing a duplicate file (the other name, sam2p_fishg.job, is the
	# correct one, cf. its content)
	rm $(CURDIR)/debian/sam2p/usr/share/doc/sam2p/examples/sam2p_fisht.job

override_dh_auto_test:

override_dh_auto_clean:
	# Work around the annoying configure removal by make clean
	ln configure configure.bak
	dh_auto_clean
	mv configure.bak configure
