#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

UPSTREAM_DATE = $(shell awk '/^= .* [0-9-]*$$/ { print $$NF; exit }' ChangeLog)

%:
	dh $@ --buildsystem=cmake

CONFIG_H = include/mbedtls/config.h

override_dh_auto_clean:
	dh_auto_clean
	[ ! -e $(CONFIG_H).bak ] || mv $(CONFIG_H).bak $(CONFIG_H)

override_dh_auto_configure:
	cp $(CONFIG_H) $(CONFIG_H).bak
	scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
	scripts/config.pl set MBEDTLS_HAVEGE_C
	scripts/config.pl set MBEDTLS_MD2_C
	scripts/config.pl set MBEDTLS_MD4_C
	scripts/config.pl set MBEDTLS_THREADING_C
	scripts/config.pl set MBEDTLS_THREADING_PTHREAD
	dh_auto_configure -- \
	 -DLIB_INSTALL_DIR="lib/$(DEB_HOST_MULTIARCH)" \
	 -DUSE_STATIC_MBEDTLS_LIBRARY=ON \
	 -DUSE_SHARED_MBEDTLS_LIBRARY=ON \
	 -DENABLE_PROGRAMS=OFF

override_dh_auto_build-indep:
	dh_auto_build -- apidoc

# Use faketime to prevent testsuite timebombing in the future
override_dh_auto_test-arch:
	faketime '$(UPSTREAM_DATE)' dh_auto_test

override_dh_auto_test-indep:
override_dh_auto_install-indep:

override_dh_installdocs:
	dh_installdocs -X.md5
