#!/usr/bin/make -f

#export DH_VERBOSE=1
export PYBUILD_NAME=pyregion
export HTTP_PROXY=127.0.0.1:9
export DEB_BUILD_MAINT_OPTIONS=hardening=+bindnow

LAST_CHANGE = $(shell dpkg-parsechangelog -S Date)
BUILD_DATE  = $(shell LC_ALL=C date -u "+%B %d, %Y" -d "$(LAST_CHANGE)")
SPHINXOPTS := -D today="$(BUILD_DATE)" -D html_last_updated_fmt="$(BUILD_DATE)" -D html_show_copyright=0

%:
	dh $@ --with python2,python3 --buildsystem=pybuild

override_dh_auto_install:
	rm -f build/html/_static/jquery.js
	rm -f build/html/_static/unserscore.js
	sed -i "s#https.*modernizr\.#/usr/share/javascript/modernizr/modernizr\.#" build/html/*.html
	rm -rf build/html/plot_directive
	sed -i "s#_images#examples#g" build/html/examples.html
	rm -f build/html/_images/demo_region*
	sed -i "s#_images/\(region_draw\|demo\)#figures/\1#g" build/html/getting_started.html
	rm -f build/html/_images/region_draw*
	rm -f build/html/_images/demo_filter_mask.png
	dh_auto_install
	dh_numpy

override_dh_auto_clean:
	dh_auto_clean
	rm -rf .cache
	rm -rf api
	rm -rf pyregion/_region_filter.c

override_dh_auto_test:
	python setup.py test
	python3 setup.py test

override_dh_auto_build:
	cython pyregion/_region_filter.pyx
	dh_auto_build
	PYTHONPATH=$$(echo build/lib.* | tr " " :) sphinx-build $(SPHINXOPTS) -N -bhtml docs/ build/html
