#!/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:
	# Work around the broken insane build system
	touch bts2.tth sam2p_version.h stdafx.h
	dh_auto_configure -- --enable-gif --enable-lzw
	rm bts2.tth sam2p_version.h stdafx.h

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' \
		< debian/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
