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

FC      = [[[PLT:ACTIVE:FC]]]
FFLAGS  = [[[PLT:ACTIVE:FFLAGS]]]

LD      = [[[PLT:ACTIVE:LD]]]
LDFLAGS = [[[PLT:ACTIVE:LDFLAGS]]]

OASIS_BASE_DIR = [[[PLT:ACTIVE:ECEARTH_SRC_DIR]]]/oasis3-mct/ecconf
OASIS_MOD_DIR  = $(OASIS_BASE_DIR)/build/lib/psmile.MPI1
OASIS_INC_DIR  = $(OASIS_BASE_DIR)/lib/psmile/include
OASIS_LIB_DIR  = $(OASIS_BASE_DIR)/lib
OASIS_LIBS     = -lpsmile.MPI1 -lmct -lmpeu -lscrip

MPI_BASE_DIR            := [[[PLT:ACTIVE:MPI_BASE_DIR]]]
ifneq ($(strip $(MPI_BASE_DIR)),)
MPI_INC_DIR             := $(MPI_BASE_DIR)$(addprefix /,[[[PLT:ACTIVE:MPI_INC_SUBDIR]]])
MPI_LIB_DIR             := $(MPI_BASE_DIR)$(addprefix /,[[[PLT:ACTIVE:MPI_LIB_SUBDIR]]])
endif
MPI_LIBS                := [[[PLT:ACTIVE:MPI_LIBS_WITHOUT_L]]]

ifneq ($(strip [[[PLT:ACTIVE:NETCDF_BASE_DIR]]]),)
NETCDF_LIB_DIR          := [[[PLT:ACTIVE:NETCDF_BASE_DIR]]]/[[[PLT:ACTIVE:NETCDF_LIB_SUBDIR]]]
NETCDF_INC_DIR          := [[[PLT:ACTIVE:NETCDF_BASE_DIR]]]/[[[PLT:ACTIVE:NETCDF_INC_SUBDIR]]]
endif
NETCDF_LIBS             := [[[PLT:ACTIVE:NETCDF_LIBS_WITHOUT_L]]]

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) \
	    $(addprefix -L,$(NETCDF_LIB_DIR))  $(addprefix -l,$(NETCDF_LIBS))  \
	    $(addprefix -L,$(MPI_LIB_DIR))     $(addprefix -l,$(MPI_LIBS))


%.o: %.F90
	$(FC) $(FFLAGS) -c -I$(OASIS_MOD_DIR) $(addprefix -I,$(NETCDF_INC_DIR)) $(addprefix -I,$(MPI_INC_DIR)) $<

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