#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
DEB_UPSTREAM_VERSION = $(shell dpkg-parsechangelog -S version | cut -d - -f 1 | cut -d : -f 2)

%:
	dh $@ --with bash-completion

override_dh_auto_build:
	+$(MAKE) doc
	dh_auto_build  -- prefix=/usr libdir=/usr/lib/$(DEB_HOST_MULTIARCH) sysconfdir=/etc bashcompdir=/usr/share/bash-completion/completions NORPATH=1

override_dh_auto_install:
	dh_auto_install -- prefix=/usr libdir=/usr/lib/$(DEB_HOST_MULTIARCH) sysconfdir=/etc bashcompdir=/usr/share/bash-completion/completions NORPATH=1

override_dh_install:
	mkdir -p debian/tmp/usr/share/pmdk/
	cp utils/pmdk.magic debian/tmp/usr/share/pmdk/
	dh_install

override_dh_installexamples:
	dh_installexamples --exclude=.gitignore --exclude=.vcxproj

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# Use fake pmem; we really want tmpfs if possible.
	# No non-pmem dir, as real syncs there are slow.
	echo "PMEM_FS_DIR=/tmp" > src/test/testconfig.sh
	# Use cache flushes instead of msync().
	echo "PMEM_FS_DIR_FORCE_PMEM=1" >> src/test/testconfig.sh
	# Don't try static libs.
	echo "TEST_BUILD=\"debug nondebug\"" >> src/test/testconfig.sh
	# Display execution time of each test
	echo "TM=1" >> src/test/testconfig.sh
	# Kill a legitimately failing test (kernel bug on tmpfs).
	rm -f src/test/obj_pool/TEST34
	+$(MAKE) check
endif
