# =================================================================================================
# Compiles and creates (Fortran) executables CIOVELAP_OD of Newton-X package
# =================================================================================================
HERE := $(shell pwd)
# -------------------------------------------------------------------------------------------------
# .SILENT:
# -------------------------------------------------------------------------------------------------
# Fortran language compiler
FCMPLR = gfortran
# Fortran language compiler flags
FFLAGS = -static -fopenmp -fbacktrace -O3 -frecursive
# Non-library flags (-L)
LDFLAGS = -llapack -lblas -lgomp
# Library flags (-l)
LDLIBS = -llapack -lblas -lgomp 
# libs's objects
LIB = 
# initcond's objects
OBJ = OBJ_ciood
# initcond's executables
EXE = EXE_ciood
# =================================================================================================
#                       initializes user-defined macros and implicit rules
# =================================================================================================

# 'cioverlap' program:
OBL_cioverlap  =  
OBJ_cioverlap  = mod_cioverlap.o cioverlap.o routines.o

# -------------------------------------------------------------------------------------------------

MAIN_cioverlap = $(addprefix $(LIB)/,$(OBL_cioverlap))  $(addprefix $(OBJ)/,$(OBJ_cioverlap))

# -------------------------------------------------------------------------------------------------
#             sets up implicit rules for generating .o files from .f90, .f & .c files
# -------------------------------------------------------------------------------------------------
$(OBJ)/%.mod: %.f90
	$(FCMPLR) $(FFLAGS) -c $< ; mv $(notdir $@) $@; chmod 700 $@
	mv $*.o $(OBJ)/.; chmod 700 $(OBJ)/$*.o
$(OBJ)/%.o: %.f90
	$(FCMPLR) $(FFLAGS) -c $< ; mv $(notdir $@) $@; chmod 700 $@
$(OBJ)/%.o: %.f
	$(FCMPLR) $(FFLAGS) -c $<; mv $(notdir $@) $@; chmod 700 $@
$(OBJ)/%.o: %.c
	$(CCMPLR) $(CFLAGS) -c $<; mv $(notdir $@) $@; chmod 700 $@
# =================================================================================================
#                         makes ALL executables 
# =================================================================================================
PROGs  =  cioverlap
 all: dir
	make $(PROGs); 
	echo CIOVERLAP_OD:
	echo - Executables are ready to be used
	echo - Executables are:
	echo $(PROGs)
	echo - Executables were located at:
	echo '  '$(HERE)/$(EXE)
# =================================================================================================
#	               makes the $(OBJ) folder in case it doesn't exist
# =================================================================================================
dir:
	-test ! -d $(OBJ) && mkdir $(OBJ)
	-test ! -d $(EXE) && mkdir $(EXE)
	clear
# =================================================================================================
#                          links & compiles the different ch3i_qct
# =================================================================================================
cioverlap: $(MAIN_cioverlap)
	$(FCMPLR) -o $(addprefix $(EXE)/,$@) $(FFLAGS) $(MAIN_cioverlap) $(LDLIBS)
#-----------------------------------------------------------------------------------------------

