#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

SPHINXBUILD="/usr/share/sphinx/scripts/python3/sphinx-build"

# Build documentation for readthedocs
export READTHEDOCS=True
# Do not build for Travis
export TRAVIS_CI=False

%:
	dh $@ --buildsystem=pybuild

execute_after_dh_auto_clean:
	$(MAKE) distclean
	rm -rf html

execute_after_dh_auto_build:
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	# Link mathjax in _static
	ln -s /usr/share/javascript/mathjax \
		documentation/source/_static/mathjax
	env PYTHONPATH=$(shell pybuild --print {build_dir} --interpreter python3) BREATHE_GIT_TAG=v$(DEB_VERSION_UPSTREAM) \
		$(MAKE) SPHINXBUILD=$(SPHINXBUILD) DOXYGEN=/usr/bin/doxygen SPHINXOPTS="-v -E"
	mv documentation/build/html html
	# Hotfix for build path in documentation
	sed -i -e 's@$(CURDIR)/@@g' html/*.html
endif

override_dh_auto_test:
	# We test breathe by building the documention. The documentation has already
	# been built for the default Python 3 version, so we do not need to do this
	# again.

override_dh_installdocs:
	# Do not copy mathjax to the binary package
	dh_installdocs -X_static/mathjax

override_dh_sphinxdoc:
	# dh_link creates the link for mathjax after dh_sphinxdoc, so ignore
	# MathJax.js
	dh_sphinxdoc -XMathJax.js

