#!/usr/bin/make -f
BUILDDIR = $(CURDIR)/debian/build

%:
	dh $@ --buildsystem=cmake --builddirectory=$(BUILDDIR) --parallel

export OMPI_MCA_plm_rsh_agent=/bin/false		#workaround to start MPI-applications in chroot
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# fewer/no debug info to fix FTBFS on archs with few address space
ifeq (32,$(DEB_HOST_ARCH_BITS))
  export DEB_CFLAGS_MAINT_APPEND = -g1
  export DEB_CXXFLAGS_MAINT_APPEND = -g1
endif
ifneq (,$(filter $(DEB_HOST_ARCH), mips mipsel))
  export DEB_CFLAGS_MAINT_APPEND = -g0
  export DEB_CXXFLAGS_MAINT_APPEND = -g0
endif

disable_auto_test_archs_simpl = armel armhf i386 mips mipsel mips64el
disable_auto_test_archs_mpi = armel armhf hurd-i386 i386 mips mipsel mips64el s390 s390x powerpc

override_dh_auto_test:
ifeq (,$(filter $(DEB_HOST_ARCH),$(disable_auto_test_archs_mpi)))
	mkdir test
	cp -r examples/LIGGGHTS/Tutorials_public/heatTransfer_1/* test/
	cd test; mpirun -np 2 --oversubscribe $(BUILDDIR)/src/liggghts < in.heatGran
	rm -rf test
endif
ifeq (,$(filter $(DEB_HOST_ARCH),$(disable_auto_test_archs_simpl)))
	mkdir test
	cp -r  examples/LIGGGHTS/Tutorials_public/heatTransfer_1/* test/
	cd test; $(BUILDDIR)/src/liggghts < in.heatGran
	rm -rf test
endif

override_dh_installexamples:
	dh_installexamples
	find $(CURDIR)/debian/ -name ".gitignore" | xargs rm -f
