#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie

DEBPKGNAME     := $(shell dpkg-parsechangelog | awk '/^Source:/ {print $$2}')

%:
	dh $@

override_dh_auto_install:
	dh_auto_install
	# Avoid name spacing conflict with htop and consequently also rename gtop
	mv debian/$(DEBPKGNAME)/usr/bin/gtop debian/$(DEBPKGNAME)/usr/bin/pfgtop
	mv debian/$(DEBPKGNAME)/usr/bin/htop debian/$(DEBPKGNAME)/usr/bin/pfhtop

override_dh_installman:
	dh_installman
	mv debian/$(DEBPKGNAME)/usr/share/man/man1/gtop.1 debian/$(DEBPKGNAME)/usr/share/man/man1/pfgtop.1
	mv debian/$(DEBPKGNAME)/usr/share/man/man1/htop.1 debian/$(DEBPKGNAME)/usr/share/man/man1/pfhtop.1

override_dh_installexamples:
	dh_installexamples
	sed -i \
	    -e 's:^\([gh]top\) :pf\1 :' \
	    debian/$(DEBPKGNAME)/usr/share/doc/$(DEBPKGNAME)/examples/test.sh

override_dh_auto_test:
	dh_auto_test
	export PATH=$(CURDIR)/src/Fortran/:$(PATH) ; \
	echo $${PATH} ; \
	cd data ; \
	. ./test.sh | \
	    sed -e '/^MA/s/\(N_SCORE=[68].5\)0*/\1/' \
	        -e '/^DT  */d' > test.build ; \
	grep -v '^DT  *' test.out > test.compare ; \
	diff -u test.compare test.build || true
