#!/usr/bin/make -f
# -*- makefile -*-

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

export OMPI_MCA_rmaps_base_oversubscribe=true
export OMPI_MCA_plm_rsh_agent=/bin/false
export LIBS=-lscalapack-$(ARCH_DEFAULT_MPI_IMPL)
# The gold linker is currently broken on mips64el. See #851736.
# Switch to bfd as a temporary workaround.
ifneq ($(filter $(DEB_BUILD_ARCH), mips64el),)
	export DEB_LDFLAGS_MAINT_APPEND=-Wl,--as-needed -Wl,-fuse-ld=bfd
else
	export DEB_LDFLAGS_MAINT_APPEND=-Wl,--as-needed
endif

export DEB_FCFLAGS_MAINT_APPEND = -fallow-argument-mismatch
export CXX=mpicxx

export TEST_FLAGS?=500 150 16

ifneq (,$(filter $(DEB_HOST_ARCH), mips mipsel powerpc))
	export TEST_FLAGS=200 12 2
endif

ifneq (,$(filter $(DEB_HOST_ARCH), mipsel powerpc))
        export MPIEXEC=mpiexec -n 1
endif

ifeq (,$(filter custom,$(DEB_BUILD_OPTIONS)))
BUILD_FLAGS=--disable-sse --disable-sse-assembly --disable-avx --disable-avx2 --disable-avx512
endif

# the current upstream version (2019.11.001) FTBFS when make is run in
# parallel, so force parallel to off via --max-parallel=1
%:
	dh $@ --max-parallel=1 --builddir=build

override_dh_auto_configure:
	dh_auto_configure -- --disable-silent-rules ${BUILD_FLAGS}

override_dh_auto_test:
	@echo "Running tests with matrix size ${TEST_FLAGS% *}"
	(cd build; $(MAKE) -j1 check || cat test-suite.log)
	build/elpa2_print_kernels
	# error out in case of test suite failures
	if grep ^FAIL build/test-suite.log; then exit 1; fi
