#########################################################################
#									#
#                    Top level SPFLAME Makefile                         #
#									#
#########################################################################

SPFLAME = ${HOME}/src/spflame/shipping-1.1

#########################################################################
# machine dependencies
#
include Makefile_host
#
#########################################################################


#########################################################################
# all targets
#########################################################################

help:
	@echo "-----------------------------------"
	@echo "SPFLAME Makefile for ${UNAME}"
	@echo "Targets are:"
	@echo "              spflame"
	@echo "              prep_routines"
	@echo "              converter"
	@echo "              clean"
	@echo "              archive"
	@echo "              tools"
	@echo "-----------------------------------"

clean:
	(cd misc_modules; ${MAKE} SPFLAME=${SPFLAME} clean)
	(cd model;        ${MAKE} SPFLAME=${SPFLAME} clean)
	(cd diagnostics;  ${MAKE} SPFLAME=${SPFLAME} clean)
	(cd mpp;          ${MAKE} SPFLAME=${SPFLAME} clean)
	(cd prep;         ${MAKE} SPFLAME=${SPFLAME} clean)
	(cd cv_cdf;       ${MAKE} SPFLAME=${SPFLAME} clean)
	(cd misc_tools;   ${MAKE} SPFLAME=${SPFLAME} clean)
	@echo "------------------------------------"
	@echo "Cleaning everything up in spflame"
	@echo "------------------------------------"
	rm -f *.o *.f *~ *.mod V* *.vo *.L

spflame: 
	@echo "-----------------------------------"
	@echo "Making SPFLAME object for ${UNAME}"
	@echo "-----------------------------------"
	(cd misc_modules; ${MAKE} SPFLAME=${SPFLAME} all)
	(cd model       ; ${MAKE} SPFLAME=${SPFLAME} all)
	(cd diagnostics ; ${MAKE} SPFLAME=${SPFLAME} all)
	(cd mpp         ; ${MAKE} SPFLAME=${SPFLAME} all)
	test -d ${SPFLAME}/bin || mkdir ${SPFLAME}/bin
	$(LINKER) misc_modules/*.o model/*.o \
                  diagnostics/*.o  mpp/*.o \
          ${F90_OPTS} -o ${SPFLAME}/bin/spflame.x \
          $(ALL_LIBS_PATHS) $(LIBS)

prep_routines: 
	@echo "--------------------------------"
	@echo "Making prep routines for ${UNAME}"
	@echo "--------------------------------"
	test -d ${SPFLAME}/bin || mkdir ${SPFLAME}/bin
	(cd misc_modules; ${MAKE} SPFLAME=${SPFLAME} all)
	(cd prep        ; ${MAKE} SPFLAME=${SPFLAME} all)


converter:
	@echo "--------------------------------"
	@echo "Making converters for ${UNAME}"
	@echo "--------------------------------"
	test -d ${SPFLAME}/bin || mkdir ${SPFLAME}/bin
	(cd misc_modules; ${MAKE} SPFLAME=${SPFLAME} all)
	(cd cv_cdf      ; ${MAKE} SPFLAME=${SPFLAME} all)

tools:
	@echo "--------------------------------"
	@echo "Making tools for ${UNAME}"
	@echo "--------------------------------"
	test -d ${SPFLAME}/bin || mkdir ${SPFLAME}/bin
	(cd misc_modules; ${MAKE} SPFLAME=${SPFLAME} all)
	(cd misc_tools  ; ${MAKE} SPFLAME=${SPFLAME} all)


archive:
	@echo "--------------------------------"
	@echo "Making SPFLAME archive for ${UNAME}"
	@echo "--------------------------------"
	tar cvf spflame.tar  Makefile README.first \
                configure/ include/ misc_tools/ \
                misc_modules/ model/ diagnostics/ mpp/ \
                prep/ cv_cdf/ doc/*


test_dens: 
	@echo "-----------------------------------------"
	@echo "Making test density module for ${UNAME}"
	@echo "-----------------------------------------"
	(cd misc_modules; ${MAKE} SPFLAME=${SPFLAME} all)
	(cd model       ; ${MAKE} SPFLAME=${SPFLAME} test_dens)
	(cd bin; ./test_dens.x)

test_co2: 
	@echo "-----------------------------------------"
	@echo "Making test co2 module for ${UNAME}"
	@echo "-----------------------------------------"
	(cd misc_modules; ${MAKE} SPFLAME=${SPFLAME} all)
	(cd model       ; ${MAKE} SPFLAME=${SPFLAME} test_co2)
	(cd bin; ./test_co2.x)

test_tmngr: 
	@echo "-----------------------------------------"
	@echo "Making test time manager module for ${UNAME}"
	@echo "-----------------------------------------"
	(cd misc_modules;  ${MAKE} SPFLAME=${SPFLAME} test_tmngr)
	(cd bin; ./test_tmngr.x)

