#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk
include /usr/share/dpkg/architecture.mk

export PYBUILD_NAME=pycryptodome
export VERBOSE=1

CMAKE_CFLAGS   = ${CFLAGS}   ${CPPFLAGS}
CMAKE_CXXFLAGS = ${CXXFLAGS} ${CPPFLAGS}

%:
	dh $@ --with python3,sphinxdoc --buildsystem=pybuild

override_dh_auto_test:
	for PY3VER in $(shell py3versions -sv); do \
		PYBUILD_SYSTEM=custom \
			PYBUILD_TEST_ARGS="python$$PY3VER -m Cryptodome.SelfTest {build_dir}/" dh_auto_test; \
	done
	cd src/test && PYTHON=python3 CFLAGS="${CMAKE_CFLAGS}" CXXFLAGS="${CMAKE_CXXFLAGS}" cmake -DDEB_HOST_ARCH=${DEB_HOST_ARCH} ./ && $(MAKE)

execute_before_dh_auto_build:
	touch .separate_namespace

execute_after_dh_auto_build:
	PYTHONPATH=. python3 -m sphinx -N -bhtml Doc/ build/html # HTML generator
	PYTHONPATH=. python3 -m sphinx -N -bman Doc/ build/man # Manpage generator

# Do this until it becomes clearer where documentation should live post Python 2
override_dh_installdocs:
	dh_installdocs -p python3-pycryptodome
	dh_installdocs --doc-main-package=python-pycryptodome-doc -p python-pycryptodome-doc

execute_after_dh_auto_clean:
	if [ -f src/test/Makefile ] ; then \
		$(MAKE) -C src/test clean ; \
	fi

override_dh_clean:
	dh_clean --exclude=Doc/LEGAL/copy/LICENSE.orig