#!/usr/bin/make -f

BUILDDIR = build
DESTDIR = debian/nest
DISTRIBUTION = $(shell lsb_release -sc)
PACKAGEVERSION = nest-master
INSTALLDIR = \/$(BUILDDIR)\/$(PACKAGEVERSION)\/$(DESTDIR)

CMAKE_FLAGS = -DCMAKE_INSTALL_PREFIX:PATH=$(DESTDIR)/usr -Dwith-python=ON -DCMAKE_INSTALL_LIBDIR:PATH=lib
CMAKE_FLAGS += -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER=gcc
CMAKE_FLAGS += -Dwith-mpi=ON
CMAKE_FLAGS += -Dwith-openmp=ON
CMAKE_FLAGS += -Dwith-gsl=ON -Dwith-ltdl=ON -Dwith-readline=ON

%:
	LC_ALL=en_US.UTF-8 dh ${@} --with python3 --builddirectory=$(BUILDDIR)
	#dh $@

override_dh_auto_clean:
	dh_clean
	rm -rf $BUILDDIR
override_dh_auto_test:
override_dh_installdirs:
override_dh_installdocs:
override_dh_installinfo:
override_dh_shlibdeps:
override_dh_auto_configure:
override_dh_auto_build:
override_dh_auto_install:
    # This is a little bit tricky
    # @todo Check if this really is problem or only in building the packages
	sed -i 's/site-packages/dist-packages/g' ./cmake/ProcessOptions.cmake
	sed -i 's/NEST_INSTALL_PREFIX \"\/\"/\"\/usr\/"/g' ./sli/slistartup.cc
	cmake $(CMAKE_FLAGS) .
	make
	make install

	# Now changing nest_vars.sh setting the correct paths
	sed -i 's/\/build\/\(.*\)nest\(.*\)\/debian\/nest//g' $(DESTDIR)/usr/bin/nest_vars.sh
