#!/usr/bin/make -f
# -*- makefile -*-

#export DH_VERBOSE=1
export PYBUILD_NAME=epr
export PYBUILD_DISABLE=test
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

include /usr/share/dpkg/pkg-info.mk
BUILD_DATE="$(date --utc --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +%Y-%m-%d)"
SPHINXOPTS := -D today=\"$(BUILD_DATE)\"
SPHINXOPTS += -D html_last_updated_fmt=\"$(BUILD_DATE)\"

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
export CFLAGS ?= -O0
endif

%:
	dh $@ --buildsystem=pybuild

execute_after_dh_auto_build-indep:
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	cd doc && \
	env PYTHONPATH=$(CURDIR) http_proxy='http://127.0.0.1:9/' https_proxy='https://127.0.0.1:9/' \
	sphinx-build -N -E -T $(SPHINXOPTS) -b html . $(CURDIR)/.pybuild/docs/html
	$(RM) -r $(CURDIR)/.pybuild/docs/html/.doctrees
	$(RM) -r $(CURDIR)/.pybuild/docs/html/_downloads
else
	mkdir -p  $(CURDIR)/.pybuild/docs/html
endif

override_dh_python3:
	dh_python3 -N python-epr-doc

override_dh_installchangelogs:
	dh_installchangelogs -k doc/NEWS.rst

override_dh_compress:
	dh_compress -X.txt -X.rst -X.html -X.py
