#!/usr/bin/make -f

export OMPI_MCA_orte_rsh_agent=/bin/false                #workaround to start MPI-applications in chroot
export NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))

disable_auto_test_archs_mpi = hurd-i386 mips mipsel s390 s390x

%:
	dh $@ --parallel

override_dh_auto_clean:
	cd src; make clean-all
	dh_clean

override_dh_auto_build:
	cd src; $(MAKE) -j$(NUMJOBS) yes-all; $(MAKE) -j$(NUMJOBS) no-lib; $(MAKE) -j$(NUMJOBS) mpi
	mv src/lmp_mpi src/lammps

override_dh_auto_test:
	mkdir test; cp examples/crack/* test/
	cd test; ./../src/lammps < in.crack
	rm -rf test
ifeq (,$(filter $(DEB_HOST_ARCH),$(disable_auto_test_archs_mpi)))
	mkdir test; cp examples/crack/* test/
	cd test; mpirun -np 2 ./../src/lammps < in.crack
	rm -rf test
endif

override_dh_fixperms-indep:
	dh_fixperms -i
	find $(CURDIR)/debian/lammps-doc/usr/share/doc/lammps-doc/examples/USER/ -type f -print -exec chmod 644 {} \; 
	find $(CURDIR)/debian/lammps-doc/usr/share/doc/lammps-doc/examples/vashishta/ -type f -print -exec chmod 644 {} \; 
	find $(CURDIR)/debian/lammps-doc/usr/share/doc/lammps-doc/ -type f -print0 | xargs -0 sed -i 's/https:\/\/cdn\.mathjax\.org\/mathjax\/latest\/MathJax.js?config=TeX-AMS-MML_HTMLorMML/\/usr\/share\/javascript\/mathjax\/config\/TeX-AMS-MML_HTMLorMML\.js/g'
