#!/usr/bin/make -f

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
DEB_HOST_ARCH_CPU=$(shell dpkg-architecture -qDEB_HOST_ARCH_CPU)
DEB_HOST_ARCH_OS=$(shell dpkg-architecture -qDEB_HOST_ARCH_OS)
export DEB_BUILD_HARDENING=1
export DEB_BUILD_HARDENING_PIE=0

NO_PPTRACE=

ifneq ($(DEB_HOST_ARCH_OS),linux)
NO_PPTRACE=--without-pptrace
endif
ifneq ($(DEB_HOST_ARCH_CPU),armel)
ifneq ($(DEB_HOST_ARCH_CPU),armhf)
ifneq ($(DEB_HOST_ARCH_CPU),amd64)
NO_PPTRACE=--without-pptrace
endif
endif
endif

CONFIGURE=$(NO_PPTRACE) --with-mpi-include=/usr/include/mpi --with-litl=/usr --with-gtg=/usr --libdir=/usr/lib/$(DEB_HOST_MULTIARCH)

%:
	dh $@  --with autoreconf

override_dh_auto_configure:
	dh_auto_configure -Bbuild-mpich -- $(CONFIGURE) --with-mpi-include=/usr/include/mpich --with-mpi-module-name=mpich --with-mpi-event-id=4
	dh_auto_configure -Bbuild-openmpi -- $(CONFIGURE) --with-mpi-include=/usr/lib/openmpi/include --with-mpi-module-name=openmpi --with-mpi-event-id=10

override_dh_auto_build:
	dh_auto_build -Bbuild-mpich
	dh_auto_build -Bbuild-openmpi -- -C src/modules/mpi

override_dh_auto_clean:
	dh_auto_clean -Bbuild-mpich
	dh_auto_clean -Bbuild-openmpi

override_dh_auto_install:
	dh_auto_install -Bbuild-mpich
	dh_auto_install -Bbuild-openmpi -- -C src/modules/mpi

override_dh_auto_test:
	-dh_auto_test
