#GNU Makefile to build update_state 
#
#12/15/08 C. Ludescher-Furth : created


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

OBJDIR = $(OBJ)/obj/update_state

LDLIBS = -L$(OBJ)/lib -lplasma_state -lps_xplasma2 -lplasma_state_kernel \
	-L$(PSPLINE_HOME)/lib -lpspline \
	$(LLOC) -lxplasma2 \
	-lnscrunch -lfluxav \
	-lr8bloat -lezcdf -lsmlib\
	-lcomput -llsode -llsode_linpack \
	-lportlib

srcdir  = $(shell pwd)
testdir = $(shell cd $(OBJ)/test; pwd)


.PHONY: clean realclean checkdirs all exec


libs: FORCE  
 
all:  libs exec 
	@echo done  


FORCE: chkdirs

chkdirs:
	@test -d $(OBJ)/test || mkdir -p $(OBJ)/test
	@test -d $(OBJDIR)   || mkdir -p $(OBJDIR)


#
#---------------------------------------------------
#
# Build Test Programs
#=====================
# pre-pocess / compile .F

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

$(OBJDIR)/%.o: %.F90
	$(F90_proc)

exec: chkdirs chktest $(OBJ)/test/update_state

chktest:

$(OBJ)/test/update_state: $(OBJDIR)/update_state.o 
ifeq ("${USEFC}","Y")
	$(FC) $(LDFLAGS) -o $@ $< $(LDLIBS) $(NETCDF) $(LAPACK) 
else
	$(CXX) $(LDFLAGS) -o $@ $< $(F_MAIN) $(LDLIBS) $(NETCDF) $(LAPACK) $(FORTLIBS)
endif



#-------------------------------------------------------------------------
install:
	@test -d $(BINDIR) || mkdir -p $(BINDIR)
	umask 022; cp $(OBJ)/test/update_state $(BINDIR)/

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

realclean: clean


