#
# Makefile to build the coupling libraries - libgetm_esmf.a libgetm_oasis.a
#

include ../Rules.make

LIB_ESMF	= $(LIBDIR)/libgetm_esmf${buildtype}.a
LIB_OASIS	= $(LIBDIR)/libgetm_oasis${buildtype}.a
LIB		= $(LIB_ESMF) $(LIB_OASIS)

SRC	=
ifeq ($(GETM_ESMF),true)
SRC	+= getm_esmf.F90 getm_nuopc.F90
endif
ifeq ($(GETM_OASIS),true)
SRC	+= getm_oasis.F90
endif

MOD   =
ifeq ($(GETM_ESMF),true)
MOD   += ${LIB_ESMF}(getm_esmf.o)
endif
ifeq ($(GETM_NUOPC),true)
MOD   += ${LIB_ESMF}(getm_nuopc.o)
endif
ifeq ($(GETM_OASIS),true)
MOD   += ${LIB_OASIS}(getm_oasis.o)
endif

OBJ   =

all: modules objects

modules: $(MOD)

objects: $(OBJ)

ifeq ($(GETM_NUOPC),true)
# this target builds your model and your NUOPC cap
nuopc: getm_nuopc.o $(GETMDIR)/include/getm_nuopc.mk
	mv $(GETMDIR)/src/coupling/getm_nuopc.o $(LIBDIR)/

# this target installs your NUOPC-compliant model to DESTDIR
nuopcinstall:

.PRECIOUS: getm_nuopc.o
.PHONY: $(GETMDIR)/include/getm_nuopc.mk
$(GETMDIR)/include/getm_nuopc.mk: $(MODDIR)/getm_nuopc.mk
	ln -snf $(MODDIR)/getm_nuopc.mk $(GETMDIR)/include/

.PHONY: $(MODDIR)/getm_nuopc.mk
$(MODDIR)/getm_nuopc.mk:
	@echo "# ESMF self-describing build dependency makefile fragment" > $@
	@echo >> $@
	@echo "# ESMF_DEP_FRONT: name of module file, header file or shared object (without extension)" >> $@
	@echo "# ESMF_DEP_INCPATH: absolute path to module or header file" >> $@
	@echo "# ESMF_DEP_CMPL_OBJS: object files that need to be considered as compile dependencies (with absolute path, space-separated)" >> $@
	@echo "# ESMF_DEP_LINK_OBJS: object files that need to be considered as link dependencies (with absolute path, space-separated)" >> $@
	@echo "# ESMF_DEP_SHRD_PATH: list of absolute paths to find shared libraries during link-time (and during run-time unless overridden by LD_LIBRARY_PATH)" >> $@
	@echo "# ESMF_DEP_SHRD_LIBS: list of shared libraries that need to be specified during link-time, and must be available during run-time (with absolute path)" >> $@
	@echo >> $@
	@echo "ESMF_DEP_FRONT     = getm_nuopc"                   >> $@
	@echo "ESMF_DEP_INCPATH   = $(MODDIR)"                    >> $@
	@echo "ESMF_DEP_CMPL_OBJS = $(LIBDIR)/getm_nuopc.o"       >> $@
	@echo "ESMF_DEP_LINK_OBJS = $(LIBDIR)/libgetm_all.a"      >> $@
	@echo "ESMF_DEP_SHRD_PATH = "                             >> $@
	@echo "ESMF_DEP_SHRD_LIBS = "                             >> $@
endif


doc: $(SRC)
	$(PROTEX) $(SRC) > $(DOCDIR)/coupling.tex
	touch doc

clean:
	$(RM) ${LIB} $(MODDIR)/{getm_esmf,getm_nuopc,getm_oasis}.{m.mod}

realclean: clean
	$(RM) *.o doc

distclean: realclean

#-----------------------------------------------------------------------
# Copyright (C) 2001 - Hans Burchard and Karsten Bolding (BBH)         !
#-----------------------------------------------------------------------
