#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

VERSION:=$(shell dpkg-parsechangelog | grep ^Version: | cut -d ' ' -f 2 | sed -e 's/+dfsg.*//')

HELP2MAN=help2man -N --version-string=$(VERSION)

%:
	dh $@  --with autoreconf

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	dh_auto_test
	mkdir tmp
	cd tmp ; ../tests/hello/otf_hello
	cd tmp ; ../tests/progress/otf_progress hello_world.otf
	rm -fr tmp
endif

override_dh_auto_install:
	dh_auto_install
	ln -s libopen-trace-format.so debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libotf.so
	ln -s libopen-trace-format.a debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libotf.a
	mv debian/tmp/usr/bin/otfinfo debian/tmp/usr/bin/otfinfo-trace
	(cd debian/tmp/usr/include ; ln -s open-trace-format/* .)

override_dh_install:
	dh_install
	rm -f debian/otf-trace/usr/bin/otfconfig

override_dh_installman:
	$(HELP2MAN) -n "Append snapshots and statistics to an OTF trace" ./tools/otfaux/otfaux > debian/otfaux.1
	$(HELP2MAN) -n "Compression program for single OTF files" ./tools/otfcompress/otfcompress > debian/otfcompress.1
	$(HELP2MAN) -n "Show parameters of the OTF configuration" ./tools/otfconfig/otfconfig > debian/otfconfig.1
	$(HELP2MAN) -n "Program to get basic information of an OTF trace" ./tools/otfinfo/otfinfo > debian/otfinfo-trace.1
	$(HELP2MAN) -n "Change the number of streams for an OTF trace" ./tools/otfmerge/otfmerge > debian/otfmerge.1
	$(HELP2MAN) -n "Generate a profile of an OTF trace" ./tools/otfprofile/otfprofile > debian/otfprofile.1
	$(HELP2MAN) -n "Create a new OTF trace that only includes specified processes" ./tools/otfshrink/otfshrink > debian/otfshrink.1
	$(HELP2MAN) -n "Convert an OTF trace into a human readable, long version" ./tools/otfdump/otfprint > debian/otfprint.1
	ln -sf otfprofile.1 debian/otfprofile-mpi.1
	ln -sf otfmerge.1 debian/otfmerge-mpi.1
	ln -sf otfcompress.1 debian/otfdecompress.1
	dh_installman
	rm -f debian/otf-trace/usr/share/man/man1/otfconfig.1*

override_dh_auto_clean:
	dh_auto_clean
	rm -f debian/*.1
