# Taken from oasis3-mct master branch: make.linux_gnu_openmpi4
curr_path = $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
include  $(curr_path)/../../../oasis3-mct/util/make_dir/make.inc

executable = ../../bin/amip-forcing

OASIS_BASE_DIR = ../../../oasis3-mct
OASIS_MOD_DIR  = $(OASIS_BASE_DIR)/generated/build/lib/psmile.MPI1
OASIS_INC_DIR  = $(OASIS_BASE_DIR)/generated/lib/psmile/include
OASIS_LIB_DIR  = $(OASIS_BASE_DIR)/generated/lib
OASIS_LIBS     = -lpsmile.MPI1 -lmct -lmpeu -lscrip

VPATH = cplng

cplng_srcs = \
    cplng_data_mod.F90 \
    cplng_init_mod.F90 \
    cplng_config_mod.F90 \
    cplng_exchange_mod.F90 \
    cplng_finalize_mod.F90 \
    cplng_mod.F90

amipforc_srcs = amip_forcing_mod.F90 amip_forcing.F90

$(executable): config_mod.o $(cplng_srcs:.F90=.o) $(amipforc_srcs:.F90=.o)
	$(LD) $(LDFLAGS) -o $@ $^ -L$(OASIS_LIB_DIR) $(OASIS_LIBS) \
	    $(NETCDF_LIBRARY) $(MPILIB)


%.o: %.F90
	$(F90) $(FFLAGS) -c -I$(OASIS_MOD_DIR) $(addprefix -I,$(NETCDF_INCLUDE)) $(addprefix -I,$(MPI_INCLUDE)) $<

.PHONY: clean
clean:
	@rm -f *.o *.mod

# Compiling OASIS3-MCT and pyOASIS
oasis: pyoasis

pyoasis:
	(cd $(OASIS_BASE_DIR)/util/make_dir ; $(MAKE) pyoasis -f TopMakefileOasis3; )

realclean: clean remove
remove:
	(cd $(OASIS_BASE_DIR)/util/make_dir ; $(MAKE) realclean -f TopMakefileOasis3)