#-
#- $Id: AA_make 105 2007-07-26 09:46:30Z mafoipsl $
#-
MAKE_NAM = $(MAKE)
ifneq ($(MAKE_NAM),$(M_K))
 @$(error You must invoke this Makefile with the $(M_K) command)
endif
USER_DIR = $(shell /bin/pwd)
MAKE_DIR = '??'
ifneq ($(USER_DIR),$(MAKE_DIR))
 @$(error You must invoke this Makefile from its directory)
endif
#-
#-Q- sxdkrz F_O = $(F_D) $(F_P) -C vsafe -size_t64 -I $(MODDIR)
#-Q- eshpux F_O = $(F_D) $(F_P) -C vsafe -I $(MODDIR)
#---------------------------------------------------------------------
#- Create "libioipsl"
#---------------------------------------------------------------------

.PRECIOUS : $(MODEL_LIB)
SXMODEL_LIB = $(MODEL_LIB)
ifeq ($(L_X),1)
SXMODEL_LIB = $(LIBDIR)/libsxioipsl.a
.PRECIOUS : $(SXMODEL_LIB)
endif

MODS1 = defprec.f90   \
        errioipsl.f90 \
        stringop.f90  \
        mathelp.f90   \
        getincom.f90  \
        calendar.f90  \
        fliocom.f90   \
        flincom.f90   \
        histcom.f90   \
        restcom.f90   \
        ioipsl.f90
OBJSMODS1 = $(MODS1:.f90=.o)

all: $(MODEL_LIB)($(OBJSMODS1))
	@echo IOIPSL is OK

$(MODEL_LIB)(%.o): %.f90
	$(F_C) $(F_O) -I$(NCDF_INC) $*.f90
	$(A_C) $(MODEL_LIB) $*.o
ifeq ($(L_X),1)
	$(A_X) $(SXMODEL_LIB) $*.o
endif
#-Q- sgi6 	mv $(shell echo $* | tr '[:lower:]' '[:upper:]').mod $(MODDIR)
ifeq ($(M_M),1)
	mv $*.mod $(MODDIR)
endif
	$(RM) $*.o

clean:
	$(RM) $(MODEL_LIB)
ifeq ($(L_X),1)
	$(RM) $(SXMODEL_LIB)
endif
	$(RM) *.*~ Makefile~ core *.o *.mod i.*.L *.L i.*.f90
	$(RM) $(MODDIR)/*.mod $(MODDIR)/*.M *.M

#- Specific dependencies

$(MODEL_LIB)(errioipsl.o):   \
  $(MODEL_LIB)(defprec.o)

$(MODEL_LIB)(stringop.o):    \
  $(MODEL_LIB)(defprec.o)

$(MODEL_LIB)(mathelp.o):     \
  $(MODEL_LIB)(errioipsl.o)  \
  $(MODEL_LIB)(stringop.o)

$(MODEL_LIB)(getincom.o):    \
  $(MODEL_LIB)(stringop.o)

$(MODEL_LIB)(calendar.o):    \
  $(MODEL_LIB)(errioipsl.o)  \
  $(MODEL_LIB)(stringop.o)

$(MODEL_LIB)(fliocom.o):     \
  $(MODEL_LIB)(defprec.o)    \
  $(MODEL_LIB)(errioipsl.o)  \
  $(MODEL_LIB)(stringop.o)   \
  $(MODEL_LIB)(calendar.o)

$(MODEL_LIB)(flincom.o):     \
  $(MODEL_LIB)(errioipsl.o)  \
  $(MODEL_LIB)(stringop.o)   \
  $(MODEL_LIB)(calendar.o)

$(MODEL_LIB)(histcom.o):     \
  $(MODEL_LIB)(errioipsl.o)  \
  $(MODEL_LIB)(stringop.o)   \
  $(MODEL_LIB)(mathelp.o)    \
  $(MODEL_LIB)(calendar.o)   \
  $(MODEL_LIB)(fliocom.o)

$(MODEL_LIB)(restcom.o):     \
  $(MODEL_LIB)(errioipsl.o)  \
  $(MODEL_LIB)(stringop.o)   \
  $(MODEL_LIB)(mathelp.o)    \
  $(MODEL_LIB)(calendar.o)   \
  $(MODEL_LIB)(fliocom.o)

$(MODEL_LIB)(ioipsl.o):      \
  $(MODEL_LIB)(getincom.o)   \
  $(MODEL_LIB)(fliocom.o)    \
  $(MODEL_LIB)(flincom.o)    \
  $(MODEL_LIB)(histcom.o)    \
  $(MODEL_LIB)(restcom.o)

