#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1

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

export BUILD_DATE=$(shell LC_ALL=C date -u "+%B %d, %Y" -d @"$(SOURCE_DATE_EPOCH)")

# Prevent setuptools/distribute from accessing the internet.
export http_proxy = http://127.0.9.1:9

# This has to be exported to make some magic below work.
export DH_OPTIONS
export PYBUILD_NAME=radon

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

override_dh_auto_build:
	mkdir -p debian/python-radon-doc/usr/share/doc/python-radon-doc/html/_static/
	ln -s /usr/share/javascript/mathjax/MathJax.js debian/python-radon-doc/usr/share/doc/python-radon-doc/html/_static/MathJax.js
	python3 setup.py build
	make -C docs/ html SPHINXBUILD="/usr/share/sphinx/scripts/python3/sphinx-build" SPHINXOPTS="-j 4 -D today=\"$(BUILD_DATE)\""
	find . -name objects.inv -delete

override_dh_auto_install:
	mkdir -p debian/python-radon-doc/usr/share/doc/python-radon-doc/html/_static/
	ln -s /usr/share/javascript/mathjax/MathJax.js debian/python-radon-doc/usr/share/doc/python-radon-doc/html/_static/MathJax.js
	python3 setup.py install --root=$(CURDIR)/debian/radon/ --install-layout=deb
	rst2man debian/radon.rst > debian/radon.1
	dh_installman -pradon debian/radon.1
	find . -name objects.inv -delete

override_dh_auto_test:
	# uses autopkgtest due to avoid adding extra build deps
	true

override_dh_auto_clean:
	python3 setup.py clean -a
	find . -path '*/__pycache__/*' -delete
	find . -type d -name '__pycache__' -empty -delete
	${RM} -r docs/_build/ radon.egg-info .pytest_cache
