#!/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

ifeq ($(DEB_HOST_ARCH_CPU),s390x)
OPENMPI=no
else
OPENMPI=yes
endif

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

%:
	dh $@ --parallel --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
ifeq ($(OPENMPI),yes)
	dh_auto_configure -Bbuild-openmpi -- $(CONFIGURE) --with-mpi-include=/usr/lib/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 -Bbuild-mpich -- -k
ifeq ($(OPENMPI),yes)
	-dh_auto_test -Bbuild-openmpi -- -C src/modules/mpi -k
endif

override_dh_strip:
	dh_strip -Xlibeztrace-autostart-
