#!/usr/bin/make -f
#export DH_VERBOSE=1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND  = -Wall -Wextra
export DPKG_GENSYMBOLS_CHECK_LEVEL = 4

# To tun the test suite kernel needs some module
KCAPI_RNG ?= $(shell grep CONFIG_CRYPTO_USER_API_RNG /boot/config-$(shell uname -r) | cut -f2 -d=)

%:
	dh $@

#  --enable-kcapi-test     Compile kcapi test program
#  --enable-kcapi-speed    Compile kcapi-speed test program
#  --enable-kcapi-rngapp   Compile rng read application
#  --enable-kcapi-encapp   Compile enc application
#  --enable-kcapi-dgstapp  Compile dgst application

kcapi_tools = \
 --enable-kcapi-hasher \
 --enable-kcapi-rngapp \
 --enable-kcapi-encapp \
 --enable-kcapi-dgstapp

override_dh_auto_configure:
	dh_auto_configure -- $(kcapi_tools)

override_dh_auto_build-indep:
	dh_auto_build -- html
	dh_auto_build -- man

override_dh_auto_install-indep:
	dh_auto_install -- install-html

override_dh_install-indep:
	find $(CURDIR)/debian/tmp -name "*.la" -delete
	dh_install

# No tests needed for docs
override_dh_auto_test-indep:

override_dh_auto_build-arch:
	dh_auto_build

override_dh_auto_install-arch:
	dh_auto_install -- install-man

override_dh_install-arch:
	find $(CURDIR)/debian/tmp -name "*.la" -delete
	dh_install

override_dh_auto_test-arch:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
ifeq ($(KCAPI_RNG), m)
	# required to be run within 'test' subdir:
	(cd test ; ENABLE_FUZZ_TEST=1 NO_32BIT_TEST=1 ./test-invocation.sh)
endif
endif

override_dh_strip-arch:
	dh_strip
	# Recompute .hmac after install
	mkdir -p debian/libkcapi1/usr/bin
	cp debian/kcapi-tools/usr/bin/kcapi-hasher debian/libkcapi1/usr/bin
	dh_auto_build -- install-exec-hook DESTDIR=$(CURDIR)/debian/kcapi-tools
	dh_auto_build -- install-exec-hook DESTDIR=$(CURDIR)/debian/libkcapi1
	rm -rf debian/libkcapi1/usr/bin debian/libkcapi1/usr/libexec

get-orig-source:
	uscan --verbose --force-download --rename
