#! /usr/bin/make -f

ifeq (,$(filter terse,$(DEB_BUILD_OPTIONS)))
export DH_VERBOSE = 1
export PYBUILD_VERBOSE=1
else
export DH_QUIET = 1
endif

export PYBUILD_DESTDIR=debian/python3-pytools/
# Disable some tests as they expect siphash13 not available in Debian
export PYBUILD_TEST_ARGS=-k 'not test_attrs_hashing and not test_class_hashing and not test_dataclass_hashing and not test_datetime_hashing and not test_hash_function'

BUILD_DATE=$(shell LC_ALL=C date -u "+%B %d, %Y" -d "@$(SOURCE_DATE_EPOCH)")
SPHINXOPTS:=-D today=\"$(BUILD_DATE)\"
SPHINXOPTS+=-D html_last_updated_fmt=\"$(BUILD_DATE)\"

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

override_dh_auto_clean:
	dh_auto_clean
	-rm -rf doc/_build

override_dh_installdocs:
# Don't build documentation when required not to do it
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
# Documentation requires pytools module to analyse existing types
	SPHINXOPTS="$(SPHINXOPTS)" pybuild --build -i python3 -s custom --build-args 'make -C {dir}/doc html'
	sed -i 's#https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js#file:///usr/share/nodejs/mathjax-full/es5/tex-mml-chtml.js#' doc/_build/html/index.html
	sed -i 's#https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js#file:///usr/share/nodejs/mathjax-full/es5/tex-mml-chtml.js#' doc/_build/html/convergence.html
	sed -i 's#https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js#file:///usr/share/nodejs/mathjax-full/es5/tex-mml-chtml.js#' doc/_build/html/graph.html
	dh_installdocs
endif

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	dh_auto_test --buildsystem pybuild -- --test-pytest
endif

