#!/usr/bin/make -f

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


# skip tests on these arches
ARCH_NO_TEST_LIST = sh4

empty :=
space := $(empty)$(empty)

# run tests, or not
RUNTEST=yes
ifneq (,$(findstring $(space)$(DEB_HOST_ARCH)$(space), $(space)$(ARCH_NO_TEST_LIST)$(space)))
  RUNTEST=no
endif
ifeq (nocheck,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
  RUNTEST=no
endif

# skip MPI tests on these arches
ARCH_NO_MPI_TEST_LIST = hurd-i386 m68k

# run MPI tests, or not
RUN_MPI_TEST=yes
ifneq (,$(findstring $(space)$(DEB_HOST_ARCH)$(space), $(space)$(ARCH_NO_MPI_TEST_LIST)$(space)))
  RUN_MPI_TEST=no
endif


%:
	dh $@

override_dh_auto_clean:
	cp -f debian/Makefile.seq.inc Makefile.inc
	dh_auto_clean
	rm -rf lib Makefile.inc libmumps_seq libmumps_scotch libmumps_ptscotch

override_dh_auto_build-arch:
	mkdir lib
	cp -f debian/Makefile.ptscotch.inc Makefile.inc
	$(MAKE) MUMPS_MPI=$(ARCH_DEFAULT_MPI_IMPL) PLAT="_ptscotch" all
	cp -a lib libmumps_ptscotch
	$(MAKE) clean
	rm -f Makefile.inc
	cp -f debian/Makefile.scotch.inc Makefile.inc
	$(MAKE) MUMPS_MPI=$(ARCH_DEFAULT_MPI_IMPL) PLAT="_scotch" all
	cp -a lib libmumps_scotch
	cp -af libseq/lib* libmumps_scotch
	$(MAKE) clean
	rm -f Makefile.inc
	cp -f debian/Makefile.seq.inc Makefile.inc
	$(MAKE) MUMPS_MPI=$(ARCH_DEFAULT_MPI_IMPL) PLAT="_seq" all
	cp -a lib libmumps_seq
	cp -af libseq/lib* libmumps_seq
	$(MAKE) clean
	rm -f Makefile.inc
	cp -f debian/Makefile.par.inc Makefile.inc
	$(MAKE) MUMPS_MPI=$(ARCH_DEFAULT_MPI_IMPL) all

ifeq (yes,$(findstring yes,$(RUNTEST)))
override_dh_auto_test:
	LD_LIBRARY_PATH=$(CURDIR)/lib:$(LD_LIBRARY_PATH) ./debian/tests/mumps-examples-serial
ifeq (yes,$(findstring yes,$(RUN_MPI_TEST)))
	LD_LIBRARY_PATH=$(CURDIR)/lib:$(LD_LIBRARY_PATH) ./debian/tests/mumps-examples-mpi
endif
endif
