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

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

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 TEST_FLAGS?=2000 750 8

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

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- --disable-silent-rules

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	@echo "Running tests with matrix size ${ELPA_TEST_SCALE}"
	$(MAKE) -j1 check || cat test-suite.log
	grep Total.time *.log
	grep -A1 ^Matrix.size *.log
	./elpa2_print_kernels
	# error out in case of test suite failures
	if grep ^FAIL test-suite.log; then exit 1; fi
endif
