#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

DEB_HOST_MULTIARCH  ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

include /usr/share/mpi-default-dev/debian_defaults

ifeq ($(ARCH_DEFAULT_MPI_IMPL),openmpi)
OPENMPI=yes
else
OPENMPI=no
endif

CONFIGURE_ENV=
CONFIGURE=--with-litl=/usr --with-gtg=/usr --with-starpu=/usr

%:
	dh $@ --parallel --with autoreconf

override_dh_auto_configure:
	$(CONFIGURE_ENV) dh_auto_configure -Bbuild-mpich -- $(CONFIGURE) --with-mpi-include=/usr/include/mpich --with-mpi-module-name=mpich --with-mpi-event-id=4
ifeq ($(OPENMPI),yes)
	$(CONFIGURE_ENV) dh_auto_configure -Bbuild-openmpi -- $(CONFIGURE) --with-mpi-include=/usr/lib/$(DEB_HOST_MULTIARCH)/openmpi/include --with-mpi-module-name=openmpi --with-mpi-event-id=10
endif

override_dh_auto_build:
	dh_auto_build -Bbuild-mpich
ifeq ($(OPENMPI),yes)
	dh_auto_build -Bbuild-openmpi -- -C src/modules/mpi
endif

override_dh_auto_clean:
	dh_auto_clean -Bbuild-mpich
ifeq ($(OPENMPI),yes)
	dh_auto_clean -Bbuild-openmpi
endif
	rm -f test/automake/testcommon.h

override_dh_auto_install:
	dh_auto_install -Bbuild-mpich
ifeq ($(OPENMPI),yes)
	dh_auto_install -Bbuild-openmpi -- -C src/modules/mpi
endif

override_dh_auto_test:
	-dh_auto_test --no-parallel -Bbuild-mpich -- -k
ifeq ($(OPENMPI),yes)
	-dh_auto_test --no-parallel -Bbuild-openmpi -- -C src/modules/mpi -k
endif
