#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

include /usr/share/dpkg/architecture.mk
include /usr/share/mpi-default-dev/debian_defaults

FAILED=debian/failed

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

OMPT_ARCHS = amd64 arm64 i386 ppc64el riscv64

CONFIGURE_ENV=
CONFIGURE=-DCMAKE_INSTALL_INCLUDEDIR=/usr/include/$(DEB_HOST_MULTIARCH)

CONFIGURE_ENV+=CUPTI_ROOT=/usr
CONFIGURE+=-DEZTRACE_ENABLE_CUDA=ON

#export NVCCFLAGS = "-ccbin clang-5.0"
#export NVCCFLAGS = "-ccbin gcc-7"
export NVCCFLAGS = "--compiler-options -std=c++03 --compiler-options -D__GNUC__=7"

ifeq (,$(filter $(DEB_HOST_ARCH),amd64 arm64 mips64el ppc64el s390x alpha ia64 sparc64 kfreebsd-amd64 ppc64 riscv64))
CONFIGURE+=-DEZTRACE_ENABLE_PNETCDF=OFF
endif

%:
	dh $@

override_dh_auto_configure:
	$(CONFIGURE_ENV) dh_auto_configure -Bbuild-mpich -- $(CONFIGURE) \
		-DEZTRACE_ENABLE_CUDA=ON \
		-DEZTRACE_ENABLE_MPI=OFF \
		-DEZTRACE_ENABLE_STARPU=OFF \
		-DEZTRACE_ENABLE_OPENMP=OFF \
		-DEZTRACE_ENABLE_POSIXIO=OFF \
		-DEZTRACE_ENABLE_PTHREAD=OFF \
		-DEZTRACE_ENABLE_MEMORY=OFF \
		-DEZTRACE_ENABLE_OMPT=OFF \
		-DEZTRACE_ENABLE_PNETCDF=OFF \
		-DEZTRACE_ENABLE_NETCDF=OFF \
		-DEZTRACE_ENABLE_IOTRACER=OFF \
		$(CONFIGURE)

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

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

override_dh_auto_test:
	@echo 'blhc: ignore-line-regexp: ([0-9]*:\ )?.*src/modules/omp/bin/eztrace_cc\ .*'
	@echo 'blhc: ignore-line-regexp: ([0-9]*:\ )?\[eztrace_cc\].*'
	@echo 'blhc: ignore-line-regexp: ([0-9]*:\ )?cc\ -o\ test_task.*'
	@echo 'blhc: ignore-line-regexp: ([0-9]*:\ )?cc\ -o\ starpu_.*'
	@echo 'blhc: ignore-line-regexp: ([0-9]*:\ )?cc\ -o\ .*\ -pthread'
	@echo 'blhc: ignore-line-regexp: ([0-9]*:\ )?cc.*\ memory.c.*\ -o\ memory'
	@echo 'blhc: ignore-line-regexp: ([0-9]*:\ )?cc\ -o\ foo\ foo.c.*'
	@echo 'blhc: ignore-line-regexp: ([0-9]*:\ )?g\+\+\ -o\ vector\ vector.cxx'
	@echo 'blhc: ignore-line-regexp: ([0-9]*:\ )?.*/cc\ .*\ -c\ .*/test/.*.c'
	-verbose=1 dh_auto_test --no-parallel -Bbuild-mpich -- -C src/modules/cuda -k ARGS\+=--extra-verbose

override_dh_dwz:
	:
