# to use this makefile you must run in the commandline:
# module reset
# module load python3/3.10.10-01 prgenv/intel intel/2021.4.0 hpcx-openmpi/2.9.0 hdf5-parallel/1.12.2 netcdf4-parallel/4.9.1 

# Added -ffree-line-length-512 flag to compute Fortran code on
# other systems

#
# Include file for OASIS3 Makefile for a Linux system using 
# Gnu compilers with OpenMPI 4
#
###############################################################################
#
# CHAN  : communication technique used in OASIS3 (MPI1/MPI2/NONE)
CHAN        = MPI1
#
# Paths for libraries, object files and binaries
#
# COUPLE : path for oasis3-mct main directory
curr_path = $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
COUPLE      = $(curr_path)../..
#
# ARCHDIR : directory created when compiling
ARCHDIR     = $(COUPLE)/generated
#
# MPI library
MPIDIR      := 
MPIBIN      := $(MPIDIR)/bin
MPI_INCLUDE :=
MPILIB      :=
MPIRUN      = mpirun
#
# NETCDF library
NETCDF_INCLUDE = ${NETCDF4_PARALLEL_DIR}/include
NETCDF_LIBRARY = -L${NETCDF4_PARALLEL_DIR}/lib -lnetcdff -lnetcdf
#
# Compiling and other commands
MAKE        = gmake
F90         = mpifort $(addprefix -I, $(MPI_INCLUDE))
F           = $(F90)
f90         = $(F90)
f           = $(F90)
CC          = mpicc
LD          = mpifort $(MPILIB)
DYNOPT      = -fPIC
LDDYNOPT    = -shared
AR          = ar
ARFLAGS     = -cruv
#
# CPP keys and compiler options
# 
#CPPDEF    = -Duse_comm_$(CHAN) -D__VERBOSE -DTREAT_OVERLAY
CPPDEF      = -Duse_libMPI -Duse_comm_$(CHAN) -Duse_netCDF -DTREAT_OVERLAY
#
# 
#F90FLAGS_1 := -r8 -O3 -xAVX -mtune=skylake -ip -fp-model precise -traceback -extend-source 132
#F90FLAGS_1 += "-132"
F90FLAGS_1  = -r8 -traceback -g -fp-model precise -fp-speculation=safe -O2 -xHost
f90FLAGS_1  = $(F90FLAGS_1)
FFLAGS_1    = $(F90FLAGS_1)
fFLAGS_1    = $(F90FLAGS_1)
CCFLAGS_1   = 
#LDFLAGS     =  -O2
LDFLAGS     =  
#

###################
#
# Additional definitions that should not be changed
#
FLIBS            = $(NETCDF_LIBRARY)
# BINDIR         : directory for executables
BINDIR           = $(ARCHDIR)/bin
# LIBBUILD       : contains a directory for each library
LIBBUILD         = $(ARCHDIR)/build/lib
# LIBBUILDSHARED : contains a directory for each shared library
LIBBUILDSHARED   = $(ARCHDIR)/build-shared/lib
# INCPSMILE      : includes all *o and *mod for each library
INCPSMILE        = -I$(ARCHDIR)/include

F90FLAGS  = $(F90FLAGS_1) $(INCPSMILE) $(CPPDEF) -I$(NETCDF_INCLUDE)
f90FLAGS  = $(f90FLAGS_1) $(INCPSMILE) $(CPPDEF) -I$(NETCDF_INCLUDE)
FFLAGS    = $(FFLAGS_1) $(INCPSMILE) $(CPPDEF) -I$(NETCDF_INCLUDE)
fFLAGS    = $(fFLAGS_1) $(INCPSMILE) $(CPPDEF) -I$(NETCDF_INCLUDE)
CCFLAGS   = $(CCFLAGS_1) $(INCPSMILE) $(CPPDEF) -I$(NETCDF_INCLUDE) 
#
#############################################################################
