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

export OMPI_MCA_plm_rsh_agent=/bin/false                #workaround to start MPI-applications in chroot

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

%:
	dh $@ --with python3,sphinxdoc --sourcedirectory=cmake --builddirectory=$(BUILDDIR)

override_dh_auto_configure:
	dh_auto_configure -- \
		-DBUILD_LIB=ON -DBUILD_SHARED_LIBS=ON \
		-DCMAKE_SKIP_INSTALL_RPATH=TRUE \
		-DPKG_ASPHERE=ON \
		-DPKG_BODY=ON \
		-DPKG_CLASS2=ON \
		-DPKG_COLLOID=ON \
		-DPKG_COMPRESS=ON \
		-DPKG_CORESHELL=ON \
		-DPKG_DIPOLE=ON \
		-DPKG_GPU=ON \
		-DPKG_GRANULAR=ON \
		-DPKG_KIM=ON \
		-DPKG_KSPACE=ON \
		-DPKG_MANYBODY=ON \
		-DPKG_MC=ON \
		-DPKG_MISC=ON \
		-DPKG_MOLECULE=ON \
		-DPKG_MPIIO=ON \
		-DPKG_OPT=ON \
		-DPKG_PERI=ON \
		-DPKG_POEMS=ON \
		-DPKG_PYTHON=ON \
		-DPKG_QEQ=ON \
		-DPKG_REPLICA=ON \
		-DPKG_RIGID=ON \
		-DPKG_SHOCK=ON \
		-DPKG_SNAP=ON \
		-DPKG_SRD=ON \
		-DPKG_USER-ATC=ON \
		-DPKG_USER-AWPMD=ON \
		-DPKG_USER-BOCS=ON \
		-DPKG_USER-CGDNA=ON \
		-DPKG_USER-CGSDK=ON \
		-DPKG_USER-DIFFRACTION=ON \
		-DPKG_USER-DPD=ON \
		-DPKG_USER-DRUDE=ON \
		-DPKG_USER-EFF=ON \
		-DPKG_USER-FEP=ON \
		-DPKG_USER-H5MD=ON \
		-DPKG_USER-LB=ON \
		-DPKG_USER-MANIFOLD=ON \
		-DPKG_USER-MEAMC=ON \
		-DPKG_USER-MESO=ON \
		-DPKG_USER-MGPT=ON \
		-DPKG_USER-MISC=ON \
		-DPKG_USER-MOFFF=ON \
		-DPKG_USER-MOLFILE=ON \
		-DPKG_USER-NETCDF=ON \
		-DPKG_USER-OMP=ON \
		-DPKG_USER-PHONON=ON \
		-DPKG_USER-QTB=ON \
		-DPKG_USER-REAXC=OFF \
		-DPKG_USER-SMD=ON \
		-DPKG_USER-SMTBQ=ON \
		-DPKG_USER-SPH=ON \
		-DPKG_USER-TALLY=ON \
		-DPKG_USER-UEF=ON \
		-DPKG_USER-VTK=ON \
		-DPKG_VORONOI=ON

override_dh_auto_build-indep:
	cd doc; $(MAKE) html; $(MAKE) pdf

override_dh_auto_clean:
	dh_auto_clean
	rm -rf $(BUILDDIR)

override_dh_install:
	dh_install -X.gitignore

override_dh_installexamples:
	dh_installexamples -X.gitignore

override_dh_fixperms-indep:
	dh_fixperms -i
	find $(CURDIR)/debian/lammps-examples/usr/share/lammps/examples/ -type f -a -not -name *.sh -print -exec chmod 644 {} \;
	find $(CURDIR)/debian/lammps-doc/usr/share/doc/lammps/ -type f -print0 \
	    | xargs -0 sed -i 's|https://cdn\.mathjax\.org/mathjax/latest|/usr/share/javascript/mathjax|g; s|https://cdnjs.cloudflare.com/ajax/libs/mathjax/.*/latest.js|/usr/share/javascript/mathjax/unpacked/latest.js|g'

override_dh_auto_test-arch:
ifeq (,$(filter $(DEB_HOST_ARCH),$(disable_auto_test_archs_simpl)))
	mkdir test; cp examples/crack/* test/
	cd test; $(BUILDDIR)/lmp < in.crack
	rm -rf test
endif
ifeq (,$(filter $(DEB_HOST_ARCH),$(disable_auto_test_archs_mpi)))
	mkdir test; cp examples/crack/* test/
	cd test; mpirun -np 2 --allow-run-as-root --oversubscribe $(BUILDDIR)/lmp < in.crack
	rm -rf test
endif

# dwz reports: .../liblammps.so.0: elf_update failed
override_dh_dwz:
	dh_dwz -Xliblammps.so.0
