#GNU Makefile to build plasma_state 
#
#05/05/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

EQFILE = tftr_nbline.cdf
OBJDIR = $(OBJ)/obj/ps_nbline_driver

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

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 $(OBJDIR)/rng_container.o $(OBJ)/test/ps_nbline_driver

chktest:
	(cd $(OBJ)/test; $(TSTLNK) $(EQFILE) || ln -s $(srcdir)/$(EQFILE) $(EQFILE))

$(OBJ)/test/ps_nbline_driver: $(OBJDIR)/ps_nbline_driver.o 
ifeq ("${USEFC}","Y")
	$(FC) $(LDFLAGS) -o $@ $< $(OBJDIR)/rng_container.o $(LDLIBS) $(LUSRLIB) $(NETCDF) $(LAPACK) $(BLAS) $(XFLIB) $(XLIBS) $(EDITLIBS) $(CLIBS)
else
	$(CXX) $(LDFLAGS) -o $@ $< $(F_MAIN) $(OBJDIR)/rng_container.o $(LDLIBS) $(LUSRLIB) $(NETCDF) $(LAPACK) $(BLAS) $(XFLIB) $(XLIBS) $(EDITLIBS) $(FORTLIBS)
endif



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

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

realclean: clean


