#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

include /usr/share/dpkg/default.mk

%:
	dh $@

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

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

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

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	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
endif
