#!/usr/bin/make -f

HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)

#export DH_VERBOSE=1
export PYBUILD_NAME=wand

export PYBUILD_TEST_ARGS='-k not pdf and not test_artifacts'
export PYBUILD_DISABLE_pypy=test

# Disable tests in i386 and armhf to prevent FTBFS with reproducible builds
ifneq (,$(filter $(HOST_ARCH),armhf i386))
	export PYBUILD_TEST_ARGS='-k not pdf and not test_artifacts and not test_limits'
endif

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

execute_after_dh_auto_build:
ifeq (,$(filter nodoc,$(DEB_BUILD_PROFILES)))
	$(MAKE) -C $(CURDIR)/docs html
	find $(CURDIR)/docs/_build/html -mindepth 2 -maxdepth 2 -type f | xargs sed -i 's;https://cdnjs.*HTMLorMML;../_static/mathjax.js;g'
	find $(CURDIR)/docs/_build/html -maxdepth 1 -type f | xargs sed -i 's;https://cdnjs.*HTMLorMML;_static/mathjax.js;g'
endif

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_PROFILES)))
	dh_auto_test
endif

execute_after_dh_auto_clean:
	$(MAKE) -C $(CURDIR)/docs clean
