#!/usr/bin/make -f

export PYBUILD_NAME=scipy

include /usr/share/dpkg/architecture.mk

unexport LDFLAGS
export FFLAGS="-fPIC"
export ATLAS=None
export PATH := $(CURDIR)/debian/extra_bin:$(PATH)
export SCIPY_USE_PYTHRAN=0

PY3VERS:= $(shell py3versions -v -r debian/control)
PY3_DEFAULT:= $(shell py3versions -dv)
TMPDIR := $(CURDIR)/build/tmp
BASE=$(shell pwd)/debian

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
  export NPY_NUM_BUILD_JOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
endif

export SCIPY_USE_PYTHRAN = $(shell if dpkg-query -s python3-pythran >/dev/null 2>/dev/null; then echo 1; else echo 0; fi )

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

override_dh_auto_clean:
	rm -rf build
	-rm -rf doc/source/fontList*
	-rm -rf doc/build
	dh_clean

execute_before_dh_installdocs-indep:
	(export MPLCONFIGDIR=. ; \
	PYLIBPATH=`pybuild --print build_dir -p$(PY3_DEFAULT) | awk '{print $$3}'`; \
	echo "building docs using PYLIBPATH=$$PYLIBPATH"; \
	PYTHONPATH=$$PYLIBPATH make -C doc html PYTHONPATH=$$PYLIBPATH PYVER=3)

override_dh_auto_test:
	echo "Build-time tests will be run after the installation dir is installed"

execute_after_dh_auto_install:
	for py in $(PY3VERS); do \
	  PYLIBPATH=`pybuild --print build_dir -p$$py | awk '{print $$3}'`; \
	  (cd /tmp; PYTHONPATH=$$PYLIBPATH python$$py -c "import scipy; scipy.test()" ); \
	done

execute_after_dh_install:
	dh_numpy3
