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

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

PY2VERS := $(shell pyversions -s)
PY3VERS := $(shell py3versions -s)

%:
	dh $@ --with sphinxdoc,python2,python3

override_dh_auto_test:
ifeq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),)
	#set -e ; \
	for python in $(PY2VERS) $(PY3VERS); do \
		$$python mpmath/tests/runtests.py -strict -py -local ; \
	done
endif

override_dh_auto_build:
	set -e ; \
	for python in $(PY2VERS) $(PY3VERS); do \
		$$python setup.py build; \
	done

	( cd doc ; PYTHONPATH=../build/lib/ python build.py )
	
override_dh_auto_clean:
	set -e ; \
	for python in $(PY2VERS) $(PY3VERS); do \
		$$python setup.py clean; \
	done
	find . -name '*\.py[co]' -delete
	dh_clean

override_dh_auto_install:
	set -e ; \
	for python in $(PY2VERS); do \
		$$python setup.py install --root=debian/python-mpmath --install-layout=deb; \
	done
	set -e ; \
	for python in $(PY3VERS); do \
		$$python setup.py install --root=debian/python3-mpmath --install-layout=deb; \
	done

	# remove files not compatible with Python 2
	find debian/python-mpmath -name "exec_py3.py" -delete
	find debian/python-mpmath -name "extratest_gamma.py" -delete
	find debian/python-mpmath -name "torture.py" -delete

	# remove files not compatible with Python 3.x
	find debian/python3-mpmath -name "exec_py2.py" -delete

	# move generated documentation under subdir to keep doc/ dir clean
	cp -arp doc/build/* $(CURDIR)/debian/python-mpmath-doc/usr/share/doc/python-mpmath-doc/html/
	cp -arp doc/source/* $(CURDIR)/debian/python-mpmath-doc/usr/share/doc/python-mpmath-doc/txt/

override_dh_installchangelogs:
	dh_installchangelogs    CHANGES

override_dh_installexamples:
	dh_installexamples      -ppython-mpmath-doc demo/*

override_dh_compress:
	dh_compress             -X.py -X.js -Xobjects.inv -X.txt
