#!/usr/bin/make -f

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

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND =-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:
	# Manually clean, since make clean depends on two files, Makehelp and
	# Makedep, which are not provided but generated by configure, making
	# the clean impossible at the beginning.
	# Remove generated auxiliary makefiles
	rm -f Makedep Makehelp
	# Remove existing files directly listed in the make clean target
	rm -f *.o *.tth *.tmp.pin *.tmp.i *.tmp.ps0 *.tmp.h
	# Remove existing files indirectly listed in the make clean target, as
	# the $(ALL) variable defined in the Makedep auxiliary makefile
	rm -f sam2p_version.h ps_tiny sam2p
	# Remove generated files I found listed nowhere in the makefile
	rm -f config.h config.log config.status
