# Adrian Pop, adrpo@ida.liu.se, 2006-02-01
# Makefile for compilation of OMC using OMDev-mingw
# OMDev-mingw: http://www.ida.liu.se/~adrpo/omc/omdev/

top_builddir = ../../..
builddir_build=$(top_builddir)/build
builddir_bin=$(top_builddir)/build/bin
builddir_lib=$(top_builddir)/build/lib/omc
builddir_inc=$(top_builddir)/build/include/omc

RUNTIME_STATIC_LINKING_COMMAND="-DRUNTIME_STATIC_LINKING=ON"
BOOST_STATIC_LINKING_COMMAND="-DBOOST_STATIC_LINKING=ON"
BOOST_REALPATHS_COMMAND="-DUSE_BOOST_REALPATHS=ON"
PARALLEL_OUTPUT_COMMAND="-DUSE_PARALLEL_OUTPUT=ON"
RUNTIME_PROFILING_COMMAND="-DRUNTIME_PROFILING=ON"
SCOREP_COMMAND="-DUSE_SCOREP=ON"
SUNDIALS_LAPACK_COMMAND="-DSUNDIALS_LAPACK=ON"
CMAKE_COMMANDS=CC="scorep --user --nocompiler --thread=pthread gcc" CXX="scorep --user --nocompiler --thread=pthread g++"
CMAKE_ARGS=$(patsubst CMAKE_%, -D%, $(filter CMAKE_%, $(MAKEFLAGS)))

runtimeCpp: clean
ifneq ("$(RUNTIME_STATIC_LINKING)","true")
	$(eval RUNTIME_STATIC_LINKING_COMMAND=)
endif
ifneq ("$(BOOST_STATIC_LINKING)","true")
	$(eval BOOST_STATIC_LINKING_COMMAND=)
endif
ifneq ("$(BOOST_REALPATHS)","true")
	$(eval BOOST_REALPATHS_COMMAND=)
endif
ifneq ("$(USE_PARALLEL_OUTPUT)","true")
	$(eval PARALLEL_OUTPUT_COMMAND=)
endif
ifneq ("$(RUNTIME_PROFILING)","true")
	$(eval RUNTIME_PROFILING_COMMAND=)
endif
ifneq ("$(USE_SCOREP)","true") #If ScoreP ist used, the analyzation mode is automatically turned on
	$(eval CMAKE_COMMANDS=)
	$(eval SCOREP_COMMAND=)
else
	$(eval RUNTIME_STATIC_LINKING_COMMAND="-DRUNTIME_STATIC_LINKING=ON")
endif
ifneq ("$(USE_SUNDIALS_LAPACK)","true")
	$(eval SUNDIALS_LAPACK_COMMAND=)
endif
	cd ./Build && echo "change to Build" && $(CMAKE_COMMANDS) cmake $(RUNTIME_STATIC_LINKING_COMMAND) $(BOOST_STATIC_LINKING_COMMAND) $(BOOST_REALPATHS_COMMAND) $(PARALLEL_OUTPUT_COMMAND) $(RUNTIME_PROFILING_COMMAND) $(SCOREP_COMMAND) $(SUNDIALS_LAPACK_COMMAND) -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX:PATH="$(builddir_build)" $(CMAKE_ARGS)  ../
	$(MAKE) -C Build VERBOSE=1 

install: runtimeCpp
	(cd Build; $(MAKE) install)

clean:
	rm -R -f Build
	mkdir Build
