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

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

DEB_BUILD_ARCH=$(shell dpkg-architecture -qDEB_BUILD_ARCH)

ifeq ($(DEB_BUILD_ARCH), i386)
    export FFTW3_ALIGN=-D__FFTW3_UNALIGNED
else
    export FFTW3_ALIGN=
endif

export LIB_SCALAPACK=-lscalapack-$(ARCH_DEFAULT_MPI_IMPL)
export LIB_BLACS=-lblacsCinit-$(ARCH_DEFAULT_MPI_IMPL) -lblacs-$(ARCH_DEFAULT_MPI_IMPL)
export OMPI_MCA_orte_rsh_agent=/bin/false

PLATFORM=Linux
ARCH=`uname -m`
FORT_C_NAME=gfortran

%:
	dh $@ 

override_dh_auto_clean:
	(cd arch; ln -fs $(PLATFORM)-generic-$(FORT_C_NAME).popt $(PLATFORM)-$(ARCH)-$(FORT_C_NAME).popt)
	(cd makefiles; $(MAKE) ARCH=$(PLATFORM)-$(ARCH)-$(FORT_C_NAME) VERSION=popt distclean)
	(cd web/manual; rm -rf CP2K_INPUT; rm -f *.html *.xml)
	rm -f arch/$(PLATFORM)-$(ARCH)-$(FORT_C_NAME).*
	rm -rf LAST* TEST*
	dh_auto_clean

override_dh_auto_build:
	(cd arch; ln -fs $(PLATFORM)-generic-$(FORT_C_NAME).popt $(PLATFORM)-$(ARCH)-$(FORT_C_NAME).popt)
	(cd makefiles; $(MAKE) ARCH=$(PLATFORM)-$(ARCH)-$(FORT_C_NAME) VERSION=popt all)
	(cd web/manual; $(CURDIR)/exe/*/cp2k.popt --xml)
	(cd web/manual; saxonb-xslt -o index.html -ext:on cp2k_input.xml cp2k_input.xsl)
	(cd web/manual; saxonb-xslt -o index_javascript.html -ext:on cp2k_input.xml cp2k_input_javascript.xsl)

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	ln -nfs testresults LAST-$(PLATFORM)-$(ARCH)-$(FORT_C_NAME)-popt
	-(cd tools; ARCH=$(PLATFORM)-$(ARCH)-$(FORT_C_NAME) ./do_regtest -quick \
		-config ../debian/regtest.config                                \
		-restrictdir ATOM/regtest-2                                     \
		-restrictdir DFTB/regtest-nonscc                                \
		-restrictdir FE/regtest-2                                       \
		-restrictdir Fist/regtest-2                                     \
		-restrictdir MC/regtest                                         \
		-restrictdir NEB/regtest-3                                      \
		-restrictdir QMMM/QS/regtest-2-erf                              \
		-restrictdir QMMM/SE/regtest_2                                  \
		-restrictdir QS/regtest-gapw-2                                  \
		-restrictdir QS/regtest-gpw-1                                   \
		-restrictdir QS/regtest-hfx-periodic                            \
		-restrictdir QS/regtest-hfx-stress                              \
		-restrictdir QS/regtest-linearscaling                           \
		-restrictdir QS/regtest-nmr-2                                   \
		-restrictdir QS/regtest-libxc                                   \
		-restrictdir QS/regtest-ot-refine                               \
		-restrictdir SE/regtest-4 )
endif
