#!/usr/bin/make -f
# debian/rules for tree-puzzle using dh
# Andreas Tille <tille@debian.org>, GPL

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

pkg:=tree-puzzle
ppkg:=tree-ppuzzle

ifneq (,$(filter $(DEB_BUILD_ARCH),i386))
export DEB_CFLAGS_MAINT_APPEND += -ffloat-store
endif

%:
	dh $@ --no-parallel

override_dh_compress:
	dh_compress --exclude=.pdf --exclude .phy --exclude trees --exclude .b

override_dh_auto_build-arch:
	dh_auto_build -a

override_dh_auto_build-indep:
	echo "Nothing to build just for the docs"

override_dh_install-arch:
	dh_install -a
	# The binary has to be renamed because of the generic name
	mv `pwd`/debian/tmp/usr/bin/puzzle `pwd`/debian/$(pkg)/usr/bin/$(pkg)
	mv `pwd`/debian/tmp/usr/bin/ppuzzle `pwd`/debian/$(ppkg)/usr/bin/$(ppkg)

override_dh_installexamples:
	rm -f tests/*.log tests/*.trs
ifneq (,$(filter $(DEB_BUILD_ARCH),i386))
	# Does not generate deterministic output on i386.
	rm -f tests/qp-tn-nucl.nucl*
endif
	dh_installexamples

override_dh_fixperms:
	dh_fixperms
	find debian \( \
		       -name "*.3trees" -o \
	               -name "*.a" -o \
	               -name "*.b" -o \
	               -name "*.ctrees" -o \
	               -name "*.n" -o \
	               -name "*.nucl" -o \
	               -name "*.phy" -o \
	               -name "*.trees" -o \
	               -name "check-*-bin" -o \
	               -name "check-*-clock" -o \
	               -name "check-*-nucl" -o \
	               -name "check-*-prot" -o\
	               -name "*bin.bin" -o \
	               -name "*nucl.nucl" -o \
	               -name "*prot.prot" \
	            \) \
		-exec chmod -x \{\} \;
	find debian \( -name "Makefile*" -o -name build-puzzle -o -name build-remark \)  -delete

override_dh_missing-indep:
	dh_missing --list-missing
