#!/usr/bin/make -f
%:
	dh $@ --with python3

# Which MPI implementation?
# set ARCH_DEFAULT_MPI_IMPL
include /usr/share/mpi-default-dev/debian_defaults

export OMPI_MCA_orte_rsh_agent=/bin/false                #workaround to start MPI-applications in chroot
export DEB_CPPFLAGS_MAINT_APPEND := -I/usr/include/$(ARCH_DEFAULT_MPI_IMPL) -DOMPI_SKIP_MPICXX=1 -DMPICH_SKIP_MPICXX=1
export DEB_LDFLAGS_MAINT_APPEND := -Wl,--as-needed

CONFIGURE_FLAGS = --enable-python --with-swig=yes --with-hdf5=/usr/lib/$(DEB_HOST_MULTIARCH)/hdf5/$(ARCH_DEFAULT_MPI_IMPL) --with-hdf5-bin=/usr/bin

PY3VERS=$(shell py3versions -vr)
PY3DEF=$(shell py3versions -dv)

override_dh_auto_clean:
	[ ! -f doc/html.dox/Makefile ] || make -C doc/html.dox maintainer-clean-local
	dh_auto_clean
	rm -fr build.* debian/tmp.*
	[ ! -f doc/dox/examples.dox.orig ] || mv doc/dox/examples.dox.orig doc/dox/examples.dox

my_configure_common:
	cp doc/dox/examples.dox doc/dox/examples.dox.orig

my_configure_python%: pyver=$(patsubst my_configure_python%,%,$@)
my_configure_python%: my_configure_common
	PYTHON=/usr/bin/python$(pyver) dh_auto_configure -Bbuild.python$(pyver) -- $(CONFIGURE_FLAGS)

override_dh_auto_configure: $(foreach pyver,$(PY3VERS), my_configure_python$(pyver))

my_build_python%: pyver=$(patsubst my_build_python%,%,$@)
my_build_python%:
	dh_auto_build -Bbuild.python$(pyver)

override_dh_auto_build-arch: $(foreach pyver,$(PY3VERS), my_build_python$(pyver))

override_dh_auto_build-indep:
	dh_auto_build -Bbuild.python$(PY3DEF)/doc/html.dox -- html-local

my_install_python%: pyver=$(patsubst my_install_python%,%,$@)
my_install_python%:
	#dh_auto_install -Bbuild.python$(pyver) --destdir=$(CURDIR)/debian/tmp/python$(pyver)
	dh_auto_install -Bbuild.python$(pyver)
	#mv debian/tmp/python$(pyver)/usr/lib/python3 debian/tmp/python$(pyver)/usr/lib/python$(pyver)

override_dh_auto_install-arch: $(foreach pyver,$(PY3VERS), my_install_python$(pyver))
	find debian/tmp/usr/lib/python* \( -name \*.py[co] -o -name \*.la \) -delete
	rm -rf debian/tmp/usr/bin/test* \
	       debian/tmp/usr/bin/usescases \
	       debian/tmp/usr/bin/unittests

override_dh_auto_install-indep:
	dh_auto_install -Bbuild.python$(PY3DEF)/doc/html.dox

override_dh_install:
	dh_install
	rm -f debian/libmedc-dev/usr/include/*import*

my_test_python%: pyver=$(patsubst my_test_python%,%,$@)
my_test_python%:
	MPIEXEC="mpiexec --allow-run-as-root --oversubscribe -np " dh_auto_test -Bbuild.python$(pyver)/tests/python --max-parallel=1

override_dh_auto_test-arch: $(foreach pyver,$(PY3VERS), my_test_python$(pyver))

override_dh_auto_test-indep:
