#!/usr/bin/make -f

UPSTREAM_GIT := https://github.com/rohe/pysaml2.git
include /usr/share/openstack-pkg-tools/pkgos.make

LAST_CHANGE = $(shell dpkg-parsechangelog -S Date)
BUILD_DATE  = $(shell LC_ALL=C date -u "+%B %d, %Y" -d "$(LAST_CHANGE)")

#export http_proxy=127.0.0.1:9
#export https_proxy=127.0.0.1:9

%:
	dh $@ --buildsystem=python_distutils --with python3,sphinxdoc

override_dh_auto_clean:
	rm -rf build
	find . -iname '*.pyc' -delete
	for i in $$(find . -type d -iname __pycache__) ; do rm -rf $$i ; done

override_dh_auto_build:
	echo "Do nothing..."

override_dh_auto_install:
	pkgos-dh_auto_install --no-py2
	for i in `ls $(CURDIR)/debian/python*-pysaml2/usr/bin/*.py` ; do \
		DEST_FILE=`echo $$i | sed s/\\.py\\$$//` ; \
		mv $$i $$DEST_FILE ; \
	done
	sed -i 's| #!/usr/bin/env python|#!/usr/bin/env python3|' $(CURDIR)/debian/python3-pysaml2/usr/bin/mdexport

override_dh_python3:
	dh_python3 --shebang=/usr/bin/python3

override_dh_auto_test:
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	set -e ; for pyvers in $(PYTHON3S) ; do \
		PYTHONPATH=$(CURDIR)/src:. python$$pyvers -m pytest tests ; \
	done
endif


override_dh_sphinxdoc:
	python3 -m sphinx -D today="$(BUILD_DATE)" -b html doc debian/python-pysaml2-doc/usr/share/doc/python-pysaml2-doc/html
	dh_sphinxdoc
