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

#export DH_VERBOSE = 1

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

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

# testsuite wants non-ASCII with python3
export LC_ALL=C.UTF-8
export PYBUILD_NAME=flask-migrate

%:
	dh $@ --buildsystem=pybuild

override_dh_auto_configure:
	dh_auto_configure
	chmod a-x src/flask_migrate/templates/flask/README
	chmod a-x src/flask_migrate/templates/flask/env.py
	chmod a-x src/flask_migrate/templates/flask/script.py.mako
	chmod a-x src/flask_migrate/templates/flask-multidb/README
	chmod a-x src/flask_migrate/templates/flask-multidb/script.py.mako
	chmod a-x src/flask_migrate/templates/flask-multidb/env.py

override_dh_auto_test:
	PYBUILD_SYSTEM=custom PYBUILD_TEST_ARGS="PYTHONPATH=$(CURDIR)/src {interpreter} -m unittest discover -v" dh_auto_test

override_dh_sphinxdoc:
ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=src python3 -m sphinx -b html $(SPHINXOPTS) docs/ debian/flask-migrate-doc/usr/share/doc/flask-migrate-doc/html
	dh_sphinxdoc
endif
