# -*- Mode: Makefile; Modified: "Thu 09 Mar 2000 11:53:42 by dave"; -*- 
### This is the top-level GNUMakefile.  It requires GNU make. It builds some or
### all of the libraries and applications directories, depending on the targets
### specified.
###
### User-definable variables are in UPPER case.
### Internal variables are in lower case.
###
### The default target is "all".
###
### The main CONFIGURATION variables are:
###   DEBUG = {TRUE,FALSE} compile with debugging (TRUE) or optimization (FALSE)
###   DIM = {2,3} number of dimensions to build the code with (i.e. CH_SPACEDIM macro)
###   PRECISION = {DOUBLE,FLOAT} floating point data type to build with
###   PROFILE = {TRUE,FALSE} profiling is enabled (TRUE) or disabled (FALSE)
###   MPI = {TRUE,FALSE} build serial code (FALSE) or parallel code with MPI (TRUE)
###   CXX = C++ compiler (the serial C++ compiler when $MPI=TRUE)
###   MPICXX = C++ compiler to use when $MPI=TRUE
###            (in which case CXX is the serial compiler used by MPICXX)
###   FC = Fortran compiler
###
### Other variables that can be set on the gmake command line:
###   CXXFLAGS = options to pass to the C++ compiler
###   CPPFLAGS = options to pass to the C preprocessor (all source code passes through CPP)
###   FFLAGS = options to pass to the Fortran compiler
###   LDFLAGS = options to pass to the loader
###   LIBFLAGS = options to pass to the loader to specify libraries
###
###  For each of the above, there is another variable `XTRA*', which instead of
###  replacing the default value of the variable, adds onto the end of it.  
###  I.e: XTRACXXFLAGS XTRACPPFLAGS XTRAFFLAGS XTRALDFLAGS XTRALIBFLAGS
###
###
### If you dont like the default values, you can reset then on the command line
###  or in the file "mk/Make.defs.local".  Be aware that if you reset compiler-
###  related variables in "mk/Make.defs.local", you should also `include' the
###  appropriate compiler definitions files (usually named `Make.defs.<compiler>'.
###
### Usage:
###   target:    purpose:
###   -------    ----------
###   all        build all libraries and tests for this configuration
###   usage      list the available targets and variables
###   lib        build only the libraries for the specified configuration
###   test       build only the test programs (will also build necessary libraries)
###   util       build only the utility programs (will also build necessary libraries)
###   run        run the test programs
###   doc        build the documentation directories (config vars are ignored)
###   clean      delete files for the specified configuration
###   realclean  delete everything that wasn't in the original distribution
###   dist       build a tar file of the whole dir. tree (does a "realclean" first)
###   dist-noclean same as "dist" except doesn't do a "realclean" first
###   <library-name> build only this library and its dependencies
###   <test-name> build only this test and its dependencies
###
### Usage notes:
###   Target `realclean' will give warning messages.
###
###   Setting $(CHOMBO_HOME) on the command line or in an environment variable
###   to a value different from the current directory may produce unexpected
###   results.
###
##################################################################################

# Execute commands using `csh' instead of the default `sh'.
SHELL = /bin/csh -f

#
# This variable specifies where we are.  Lower-level make files will need an
# absolute path so we use 'pwd' rather than "."
#
CHOMBO_HOME = $(shell pwd)
export CHOMBO_HOME

##
## Default values of configuration variables.
##
include $(CHOMBO_HOME)/mk/Make.defs.defaults


##
## These variables define all the subdirectories that can be built.
## The `lib_names' variable is used by the makefiles in the application directories.
##[NOTE: if you change lib_names, also change the lib/* dependencies below.]
lib_names    = BoxTools 
lib_targets  = $(lib_names)



##
## These variables are needed by the `dist' targets
##
pkg_id := Chombo.1.0
date   := $(shell date)
today  := $(addprefix $(word 3,$(date)),$(addsuffix $(word 6,$(date)),$(word 2,$(date))))

.PHONY: usage all lib test util doc tags clean realclean dist dist-noclean doc++ \
	   $(lib_names) $(test_targets) $(lib_targets) $(util_targets) \
	   run-tests run util/GNUcpp include

# The next 5 targets are included for convenience.
lib: $(lib_targets) 


# This target builds an emacs TAGS file for all the lib,test sources.
#[Note: etags is very fast so just do it always.]
TAGS tags:
	etags {src,util,test}/*/*.{H,cpp} -l fortran {src,util,test}/*/*.ChF

# This target removes all non-essential files from the Chombo directory tree
realclean:
	find . \( -name \*.hdf5 -o -name d -o -name p -o -name \*~ -o -name f -o -name o -o -name \*.ex -o -name \*.a -o -name \*_F.H  -o -name core -o -name .#\* \) -print -exec $(RM) -r {} \;
	cd include; find . -name "*.H" -exec $(RM) {} \;

##
## These targets are used by lower-level makefiles to build libraries in 
## other directories ($lib_names variables)
##
BoxTools:         src/BoxTools

# These targets do the real work.
util/GNUcpp:
	@$(MAKE) --no-print-directory --directory=$(CHOMBO_HOME)/util/$(@F) util

$(lib_targets): util/GNUcpp
	$(make-Lib)


##
## Macro definitions used by targets.
##
define make-Lib
$(MAKE) --no-print-directory --directory=$(CHOMBO_HOME)/src/$(@F) lib
endef


