#!/usr/bin/make -f

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

export DEB_BUILD_HARDENING=1

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

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

%:
	dh $@  --with autotools-dev,autoreconf

override_dh_auto_configure:
	dh_auto_configure -- --libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH)

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
	(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:
	for i in otfaux otfcompress otfconfig otfinfo otfmerge otfprofile otfshrink ; do \
		$(HELP2MAN) -n $$i ./tools/$$i/$$i > debian/$$i.1 ; \
	done
	$(HELP2MAN) -n otfprint ./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
