#
# General Makefile defintions to allow CMFGEN etc to
# be compiled and linked.
#
# NOTE WELL: 
#      FG are options for f90 files in fixed format
#      FFREE are options for f90 files in free format.
#      FD are options for f90 files in fixed format with debug.
#      FFREED are options for f90 files in free format with debug.
#      The debug commands are generally not defined, and are not used
#         unless you manually edit the Makefiles.
#
# Installation directory for CMFGEN
# Site dependent.

# Define options for the ar command. On UBUNTU systems this might be Uruv

AR_OPTION = ruv

HOST :=$(shell hostname)

HOST=crc
COMPILER=gcc
DEBUG=nodebug

COMPILE_OPT=$(HOST)_$(COMPILER)_$(DEBUG)

ifeq ($(HOST),crc)
INSTALL_DIR=$(HOME)/cur_cmf/
endif

ifeq ($(DEBUG),nodebug)
 MOD_DIR=$(INSTALL_DIR)mod/
 LIB_DIR=$(INSTALL_DIR)lib/
 EXE_DIR=$(INSTALL_DIR)exe/
endif

ifeq ($(DEBUG),debug)
 MOD_DIR=$(INSTALL_DIR)mod_dbg/
 LIB_DIR=$(INSTALL_DIR)lib_dbg/
 EXE_DIR=$(INSTALL_DIR)exe_dbg/
endif

ifeq ($(COMPILE_OPT),crc_gcc_nodebug)
 F90 = gfortran -fopenmp -m64 
 F90nomp = gfortran -m64
 FG  = -O -ffixed-line-length-0 -fno-backslash -fd-lines-as-comments -fbacktrace -ffpe-trap=invalid -I$(MOD_DIR) 
 FD  = -g -O0  -ffixed-line-length-0 -fbounds-check -fno-backslash -fd-lines-as-comments   -fbacktrace -I$(MOD_DIR) 
 FFREE  = -O -fno-backslash -I$(MOD_DIR) -J$(MOD_DIR)
 FFRED  = -g -fno-backslash -O0 -I$(MOD_DIR) -J$(MOD_DIR)
 BLAS=
 LAPACK= -lmkl_blas95_lp64 -lmkl_lapack95_lp64 \
             -Wl,--no-as-needed -lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl
 X11LIB=-L/usr/X11R6/lib -lX11
 PGLIB=-L$(PGPLOT_DIR) -lpgplot
endif

ifeq ($(COMPILE_OPT),crc_gcc_debug)
 F90 = gfortran -fopenmp -m64
 F90nomp = gfortran -m64
 FG  = -g -O0  -ffixed-line-length-0 -fbounds-check -fno-backslash -fd-lines-as-comments   -fbacktrace -I$(MOD_DIR) 
 FD  = -g -O0  -ffixed-line-length-0 -fbounds-check -fno-backslash -fd-lines-as-comments   -fbacktrace -I$(MOD_DIR) 
 FFREE  = -g -fno-backslash -O0 -I$(MOD_DIR) -J$(MOD_DIR)
 FFRED  = -g -fno-backslash -O0 -I$(MOD_DIR) -J$(MOD_DIR)
 BLAS=
 LAPACK= -lmkl_blas95_lp64 -lmkl_lapack95_lp64 \
              -Wl,--no-as-needed -lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl
 X11LIB=-L/usr/X11R6/lib -lX11
 PGLIB=-L$(PGPLOT_DIR) -lpgplot
endif

ifeq ($(COMPILE_OPT),crc_intel_nodebug)
 F90 = /ihome/crc/install/intel/2020.4/compilers_and_libraries/linux/bin/intel64/ifort -qopenmp  -mkl -pg -traceback -nb
 F90nomp = /ihome/crc/install/intel/2020.4/compilers_and_libraries/linux/bin/intel64/ifort -mkl -pg -traceback   -nbs
 FG  = -traceback  -extend_source -O2 -I$(MOD_DIR)
 FD  = -g -O0  -fpe0 -check bounds  -extend_source  -traceback  -I$(MOD_DIR)
 FFREE  = -O2 -nbs -traceback -check bounds -extend_source -I$(MOD_DIR)
 FFRED  = -g -fpe0 -nbs -traceback -O0 -I$(MOD_DIR) -check bounds  -extend_source -traceback
 BLAS=
 LAPACK= -lmkl_blas95_lp64 -lmkl_lapack95_lp64 \
-Wl,--no-as-needed -lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl
 X11LIB=-L/usr/X11R6/lib -lX11
 PGLIB=-L$(PGPLOT_DIR) -lpgplot
endif

ifeq ($(COMPILE_OPT),crc_intel_debug)
 F90 = /ihome/crc/install/intel/2020.4/compilers_and_libraries/linux/bin/intel64/ifort -qopenmp  -mkl -pg -traceback -nb
 F90nomp = /ihome/crc/install/intel/2020.4/compilers_and_libraries/linux/bin/intel64/ifort -mkl -pg -traceback   -nbs
 FG  = -g -O0  -fpe0 -check bounds  -extend_source  -traceback  -I$(MOD_DIR)
 FD  = -g -O0  -fpe0 -check bounds  -extend_source  -traceback  -I$(MOD_DIR)
 FFREE  = -g -fpe0 -nbs -traceback -O0 -I$(MOD_DIR) -check bounds  -extend_source -traceback
 FFRED  = -g -fpe0 -nbs -traceback -O0 -I$(MOD_DIR) -check bounds  -extend_source -traceback
 BLAS=
 LAPACK= -lmkl_blas95_lp64 -lmkl_lapack95_lp64 \
-Wl,--no-as-needed -lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl
 X11LIB=-L/usr/X11R6/lib -lX11
 PGLIB=-L$(PGPLOT_DIR) -lpgplot
endif

