#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

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

BUILD_ARGS = prefix=/usr libdir=/usr/lib/$(DEB_HOST_MULTIARCH) sysconfdir=/etc bashcompdir=/usr/share/bash-completion/completions NORPATH=1 BUILD_EXAMPLES=n BUILD_BENCHMARKS=n

%:
	dh $@ --with bash-completion

execute_after_dh_auto_clean:
	rm -rf src/test/unittest/__pycache__
	find . -name ".pyc" -delete
	find . -name "*.so*" -delete
	find . -name "*.a" -delete
	find . -name "*.static-nondebug" -delete
	find . -name "*.static-debug" -delete
	rm -f doc/*/*.gz

override_dh_auto_build:
	+$(MAKE) doc
	for x in `grep -l _LOG_LEVEL doc/lib*/lib*.7`; do \
		ed -s <debian/man-debug.ed $$x; done
	dh_auto_build  -- $(BUILD_ARGS)

override_dh_auto_install:
	dh_auto_install -- $(BUILD_ARGS)

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

override_dh_missing:
	dh_missing --list-missing --exclude=usr/share/man --exclude=usr/lib/$(DEB_HOST_MULTIARCH)/pmdk_debug/ --exclude=usr/share/bash-completion/completions/pmempool

override_dh_auto_test:
	cp debian/testconfig.* src/test/
	# Still fails/times out on weird setups (a 33GB fallocate).
	rm -f src/test/obj_pool/TEST34
	# binutils regression #964457
	rm -rf src/test/scope/TESTS.py
ifeq ($(DEB_HOST_ARCH),ppc64el)
	# https://github.com/pmem/pmdk/issues/5458
	rm -f src/test/obj_ctl_arenas/TEST3 src/test/pmem2_future/TESTS.py
endif
ifneq (,$(filter $(DEB_HOST_ARCH),amd64 arm64))
	+$(MAKE) check pycheck $(BUILD_ARGS)
else
	-$(MAKE) check pycheck $(BUILD_ARGS)
endif
