#GNU Makefile to build Library libmds_sub.a 
#
#04/22/00 C. Ludescher
#

ifneq ($(MAKELEVEL),0)
# if OBJ was defined for main Makefile one level down
ifeq ("${OBJ}",".")
	override OBJ=..
endif
endif

# define system dependent flags, etc.
-include ../share/Make.local
include ../share/Make.flags


ifdef DEBUG
	F90FLAGS = $(DF90FLAGS)
	FFLAGS = $(DFFLAGS)
endif

ARC = $(OBJ)/lib/libmds_sub.a
OBJDIR = $(OBJ)/obj/mds_sub


#=============================================================
 # f90 modules
#public Module names
Mnams = mds_readnode.mod

# source file names
Mobjs = mds_readnode.o

ifeq ($(MODUP),Y)
 MODS0=$(foreach m,$(Mnams),$(shell  echo $(m) | tr 'a-z' 'A-Z'))
 MODULES=$(foreach m,$(MODS0),$(subst .MOD,.$(MODEXT),$(m)))
else
 MODULES = $(foreach m,$(Mnams),$(subst .mod,.$(MODEXT),$(m)))
endif 

# fortran archive members
F  = $(subst .f,.o, $(wildcard *.f)) $(subst .for,.o, $(wildcard *.for)) $(subst .F,.o, $(wildcard *.F))
F90 = $(subst .f90,.o, $(wildcard *.f90)) $(subst .F90,.o, $(wildcard *.F90))
FALL = $(F) $(F90)

MEM = $(foreach file,$(FALL),$(ARC)($(file)))


.PHONY: clean realclean checkdir all

libs: FORCE $(ARC)
 
all:  libs 
	@echo done  

$(OLDLIB): timestamp.inf
	@echo "--- DETECTED uflib.a source update"
	@echo "--- Re-Making $(ARC)"
	@$(MAKE) libs

FORCE:
	@test -d $(OBJ)/lib || mkdir -p $(OBJ)/lib
	@test -d $(OBJ)/obj/mds_sub || mkdir -p $(OBJ)/obj/mds_sub
	@test -d $(OBJ)/mod || mkdir -p $(OBJ)/mod

 
$(ARC): $(MODS) $(MEM)
	@$(RANLIB) $@ > /dev/null



# compile f77
$(ARC)(%.o): %.f
	$(FC) $(FFLAGS) $(MODFLAGS) -I./ $(INCFLAGS) $(OUT)  $(OBJDIR)/$*.o $<
	$(make_ar)

$(ARC)(%.o): %.for
	$(FC) $(FFLAGS) $(MODFLAGS) -I./ $(INCFLAGS) $(OUT)  $(OBJDIR)/$*.o $<
	$(make_ar)

# pre-process/compile fortran 77 code
$(ARC)(%.o): %.F
	$(F_proc)
	$(make_ar)

$(ARC)(%.o): %.f90
	$(FC90) $(FFLAGS) $(MODFLAGS) -I./ $(INCFLAGS) $(OUT) $(OBJDIR)/$*.o $<
	$(make_ar)
#
#---------------------------------------------------
exec:
	@echo 

clean: 
	@rm -f $(OBJDIR)/*

realclean: clean
	@rm -f $(ARC)



install:
	@test -d $(LIBDIR) || mkdir -p $(LIBDIR)
	@if test -f $(ARC); then \
	  umask 133; cp $(ARC) $(LIBDIR)/; \
	else test -f $(LIBDIR)/libmds_sub.a || echo ">>> can not find $(ARC)";fi;  

uninstall:
	rm -f $(LIBDIR)/libmds_sub.a
