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

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


# Get the supported Python versions
PY2VERS = $(shell pyversions -r -v)
PY3VERS = $(shell py3versions -r -v)

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


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


build-python%:
	python$* setup.py build
	python$*-dbg setup.py build


override_dh_auto_build: $(PY3VERS:%=build-python%)
	dh_auto_build


install-python%:
	python$* setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb
	python$*-dbg setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb


override_dh_auto_install: $(PY3VERS:%=install-python%)
	dh_auto_install


override_dh_install:
	# Install everything excluding the *_d.so debug extensions to python-numexpr
	dh_install -X"*_d.so" "debian/tmp/usr/lib/python2*" -p python-numexpr
	dh_install -X"*dmu.so" -X"*dm.so" "debian/tmp/usr/lib/python3*" -p python3-numexpr

	# Install the debug extensions to python-numexpr-dbg
	dh_install "debian/tmp/usr/lib/python2*/*-packages/numexpr/*_d.so" -p python-numexpr-dbg
	dh_install "debian/tmp/usr/lib/python3*/*-packages/numexpr/*.cpython-??dm*.so" -p python3-numexpr-dbg

	# Continue with regular dh_install
	dh_install
	dh_numpy
	dh_numpy3


override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))

	set -e -x;\
	for py in $(PY2VERS) $(PY3VERS); do \
		cd $(CURDIR)/build/lib.*-$$py;\
		env PYTHONPATH=. python$$py numexpr/tests/test_numexpr.py -v;\
		cd $(CURDIR)/build/lib.*-$$py-pydebug;\
		env PYTHONPATH=. python$$py-dbg numexpr/tests/test_numexpr.py -v;\
	done

endif


override_dh_installchangelogs:
	dh_installchangelogs -k RELEASE_NOTES.txt


.PHONY: override_dh_auto_build override_dh_auto_install override_dh_install \
        override_dh_auto_test override_dh_installchangelogs

