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

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

CONFIGURE=$(NO_PPTRACE) --with-cuda=/usr --with-cupti=/usr --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

override_dh_auto_build:
	dh_auto_build -Bbuild-mpich -- -C src/modules/cuda

override_dh_auto_clean:
	dh_auto_clean -Bbuild-mpich -- -C src/modules/cuda
	rm -f test/automake/testcommon.h

override_dh_auto_install:
	dh_auto_install --destdir=debian/tmp -Bbuild-mpich -- -C src/modules/cuda

override_dh_auto_test:
	-dh_auto_test -Bbuild-mpich -- -C src/modules/cuda -k

override_dh_strip:
	dh_strip -Xlibeztrace-autostart-
