#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1

# see FEATURE AREAS in dpkg-buildflags(1)
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

DPKG_EXPORT_BUILDFLAGS	 = yes
include /usr/share/dpkg/buildflags.mk

# Upstream does not use CPPFLAGS
CFLAGS	+= $(CPPFLAGS)

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

get_package_version	 = $(shell dpkg-query -W -f '$${Version}' $1)

%:
	dh $@ --sourcedirectory=src --with autoreconf

.PHONY: override_dh_auto_configure
override_dh_auto_configure:
	dh_auto_configure --sourcedirectory=src -- \
		--with-static-lib=yes \
		--with-shared-lib=yes \
		--with-shlib \
		--with-perf-events \
		--with-pfm-incdir=/usr/include \
		--with-pfm-libdir=/usr/lib/$(DEB_HOST_MULTIARCH) \
		CC=$(CC)
	# for reproducibility
	sed -r -i '/^[CF]FLAGS/s/-fdebug-prefix-map=\S*\s*//' \
		src/ctests/Makefile.target \
		src/ftests/Makefile.target \
		src/testlib/Makefile.target \
		src/components/Makefile_comp_tests.target

.PHONY: override_dh_auto_test
override_dh_auto_test:
	-dh_auto_test

.PHONY: override_dh_auto_install
override_dh_auto_install:
	dh_auto_install --sourcedirectory=src -- install-all

.PHONY: override_dh_makeshlibs
override_dh_makeshlibs:
	dh_makeshlibs -a -- -c4

.PHONY: override_dh_shlibdeps
override_dh_shlibdeps:
	dh_shlibdeps -a -- --warnings=7

.PHONY: override_dh_install
override_dh_install:
	dh_install --list-missing

.PHONY: override_dh_installchangelogs
override_dh_installchangelogs:
	dh_installchangelogs RELEASENOTES.txt

.PHONY: override_dh_compress
override_dh_compress:
	dh_compress -X.c -X.h -X.F -XMakefile

.PHONY: override_dh_gencontrol
override_dh_gencontrol:
	dh_gencontrol -- \
		-V'libpfm4:MinVersion=$(call get_package_version,libpfm4-dev)'
