#GNU Makefile to build Library libsigsub.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
	FFLAGS = $(DFFLAGS)
endif


ARC = $(OBJ)/lib/libsigsub.a
OBJDIR = $(OBJ)/obj/sigsub
MDIR = $(OBJ)/mod

#=============================================================
# f90 modules
Mnams = adas_bms_splines.mod adas_mod.mod csigma_mod.mod expint1.mod sigtabl_mod.mod
Mobjs = adas_bms_splines.o adas_mod.o csigma_mod.o de1mod.o sigtabl_mod.o
MODS = $(foreach file,$(Mobjs),$(ARC)($(file)))
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
FALL  = $(subst .f,.o, $(wildcard *.f)) $(subst .for,.o, $(wildcard *.for)) $(subst .F,.o, $(wildcard *.F)) $(subst .F90,.o, $(wildcard *.F90)) $(subst .f90,.o, $(wildcard *.f90))
MEM = $(foreach file,$(FALL),$(ARC)($(file)))


.PHONY: clean realclean checkdir all exec

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

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

FORCE:
	@test -d $(OBJ)/lib || mkdir -p $(OBJ)/lib
	@test -d $(OBJ)/mod || mkdir -p $(OBJ)/mod
	@test -d $(OBJ)/obj/sigsub || mkdir -p $(OBJ)/obj/sigsub
	@if test ! -f $(LIBDIR)/libaladdinsub.a; then \
        if test -f ../aladdinsub/Makefile; then \
        (cd ../aladdinsub; $(MAKE) libs); fi; fi

 
# compile 
$(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)

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

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

# pre-process/compile fortran 90 code
$(ARC)(%.o): %.F90
	$(F90_proc)
	$(make_ar)

$(ARC): $(MODS) $(MEM)
	@$(RANLIB) $@ > /dev/null
#
#---------------------------------------------------
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)/libsigsub.a || echo ">>> can not find $(ARC)";fi
	$(foreach file,$(MODULES),$(shell cp $(MDIR)/$(file) $(MODDIR)/))

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