#!/usr/bin/make -f
export DH_VERBOSE=1
export PYBUILD_NAME=m2crypto
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

export PYBUILD_AFTER_BUILD=cp {build_dir}/M2Crypto/_m2crypto.so M2Crypto/
# bindings needed inplace for tests and docs

export http_proxy=
export https_proxy=
# override settings from pybuild, unset them is needed for tests

%:
ifneq (,$(filter nodoc,$(DEB_BUILD_PROFILES)))
	dh $@ --with python2 --buildsystem=pybuild
else
	dh $@ --with python2,sphinxdoc --buildsystem=pybuild
endif

override_dh_auto_test:
	PYBUILD_SYSTEM=custom PYBUILD_TEST_ARGS="{interpreter} -Wd -m pytest --ignore tests/test_ssl.py -v -rs" dh_auto_test

override_dh_auto_install:
	dh_auto_install
ifeq (,$(filter nodoc, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=. http_proxy='127.0.0.1:9' sphinx-build -N doc debian/m2crypto-doc/usr/share/doc/m2crypto-doc/html
endif

override_dh_installdocs:
ifeq (,$(filter nodoc, $(DEB_BUILD_OPTIONS)))
	rst2html -r 5 README.rst .pybuild/README.html
	LC_LANG=C.UTF-8 links -dump .pybuild/README.html > .pybuild/README
endif
	dh_installdocs -A .pybuild/README