#
# $Id: GNUmakefile,v 1.74 2002/12/10 00:58:32 vince Exp $
#
PBOXLIB_HOME = ..

TOP = $(PBOXLIB_HOME)
#
# Where libraries and include files will be installed.
#
INSTALL_ROOT = $(TOP)
#
# Variables settable by users.
#
PRECISION     = DOUBLE
PROFILE       = TRUE
PROFILE       = FALSE
COMP          = mpKCC
COMP          = KCC
COMP          = g++
DEBUG         = FALSE
DEBUG         = TRUE
DIM           = 2
DIM           = 3
USE_MPI       = TRUE
USE_MPI       = FALSE
USE_ARRAYVIEW = TRUE
USE_ARRAYVIEW = FALSE

#
# Base name of the executable.
#
EBASE = hyperclaw
#
# Here's where we decide which of the problems to build.
#
# PROB_DIR is the name of a subdirectory of the directory
# containing this GNUmakefile.  It contains the problem-specific
# Fortran code for the problem type that you wish to run.
#
# Currently supported:
#
#   bubble
#
PROB_DIR = bubble

ifeq ($(PROB_DIR), explosion)
  DEFINES += -DBL_SYNC_RANTABLES
endif

ifeq ($(PROB_DIR), gravslab)
  DEFINES += -DBL_ADD_GRAVITY
endif

#CXXFLAGS += -fprm c -ieee
#CXXFLAGS += -ieee
#CXXFLAGS += -fprm c

include $(TOP)/mk/Make.defs ./Make.package

############################################### arrayview
ifeq (USE_ARRAYVIEW, TRUE)
  DEFINES += -DBL_USE_ARRAYVIEW
  #ARRAYVIEWDIR = $(VINCEDIR)/ArrayView
  ARRAYVIEWDIR = .
  INCLUDE_LOCATIONS += $(ARRAYVIEWDIR)
  #LIBRARY_LOCATIONS += $(ARRAYVIEWDIR)
  #LIBRARIES += -larrayview$(DIM)d.$(machineSuffix)
endif

BUILD_INPLACE := FALSE
BUILD_INPLACE := TRUE

ifeq ($(BUILD_INPLACE), TRUE)
  include $(TOP)/amrlib/Make.package
  include $(TOP)/bndrylib/Make.package
  include $(TOP)/BoxLib/Make.package

  INCLUDE_LOCATIONS += ./$(PROB_DIR)
  INCLUDE_LOCATIONS += .
  INCLUDE_LOCATIONS += $(TOP)/amrlib
  INCLUDE_LOCATIONS += $(TOP)/bndrylib
  INCLUDE_LOCATIONS += $(TOP)/BoxLib
  INCLUDE_LOCATIONS += $(TOP)
else
  INCLUDE_LOCATIONS += . ./$(PROB_DIR) $(TOP)/include
  LIBRARY_LOCATIONS += $(TOP)/lib/$(machineSuffix)
  LIBRARIES += -lamr$(DIM)d -lbndry$(DIM)d -lbox$(DIM)d
endif

ifeq ($(MACHINE), OSF1)
#
# Some additional stuff for our preferred development/debugging environment.
#
  ifeq ($(PRECISION), DOUBLE)
    FFLAGS += -real_size 64
  endif
  FDEBF += -C
   FDEBF += -warn argument_checking
  FDEBF += -warn declarations
  ifneq ($(FC), f90)
    FDEBF += -warn truncated_source
    FDEBF += -warn unused
  endif
endif

SOURCE_DIRS = ./$(PROB_DIR) .
ifeq ($(BUILD_INPLACE), TRUE)
  SOURCE_DIRS += $(TOP)/amrlib $(TOP)/bndrylib $(TOP)/BoxLib
  ifeq ($(PROB_DIR),  hyperchem)
    DEFINES += -DBL_USE_CHEM
    SOURCE_DIRS += $(TOP)/HeatTransfer/ChemKinDriver
    include $(TOP)/HeatTransfer/ChemKinDriver/Make.package
    INCLUDE_LOCATIONS += $(TOP)/HeatTransfer/ChemKinDriver
  endif
endif

vpath %.cpp $(SOURCE_DIRS)
vpath %.H   $(SOURCE_DIRS)
vpath %.h   $(SOURCE_DIRS)
vpath %.F   $(SOURCE_DIRS)
vpath %.f   $(SOURCE_DIRS)

all: $(executable)

ifeq ($(MACHINE),T3E)
#
# We don't explicity set the path of the mpi directory on the T3E.
#
  $(executable): $(filter-out -lmpi, $(LIBRARIES))
else
  $(executable): $(LIBRARIES)
endif

ifneq ($(BUILD_INPLACE), TRUE)
#
# Build and install all libraries needed by HyperCLaw in proper order.
#
libs:
	cd $(TOP)/BoxLib; $(MAKE) PRECISION=$(PRECISION) PROFILE=$(PROFILE) COMP=$(COMP) DEBUG=$(DEBUG) DIM=$(DIM) USE_MPI=$(USE_MPI) install
	cd $(TOP)/bndrylib;  $(MAKE) PRECISION=$(PRECISION) PROFILE=$(PROFILE) COMP=$(COMP) DEBUG=$(DEBUG) DIM=$(DIM) USE_MPI=$(USE_MPI) install
	cd $(TOP)/amrlib;    $(MAKE) PRECISION=$(PRECISION) PROFILE=$(PROFILE) COMP=$(COMP) DEBUG=$(DEBUG) DIM=$(DIM) USE_MPI=$(USE_MPI) install
#
# Cleanup needed libraries.
#
cleanlibs:
	cd $(TOP)/BoxLib; $(MAKE) PRECISION=$(PRECISION) PROFILE=$(PROFILE) COMP=$(COMP) DEBUG=$(DEBUG) DIM=$(DIM) USE_MPI=$(USE_MPI) clean
	cd $(TOP)/bndrylib;  $(MAKE) PRECISION=$(PRECISION) PROFILE=$(PROFILE) COMP=$(COMP) DEBUG=$(DEBUG) DIM=$(DIM) USE_MPI=$(USE_MPI) clean
	cd $(TOP)/amrlib;    $(MAKE) PRECISION=$(PRECISION) PROFILE=$(PROFILE) COMP=$(COMP) DEBUG=$(DEBUG) DIM=$(DIM) USE_MPI=$(USE_MPI) clean
endif
#
# Temp stuff for doing html docs.
#
_docHeaders := $(sort $(wildcard *.H))

_htmlDir := html
#
# This will make the HTML files in the directory html provided
# any of the relevant .H files have changed more recently than the
# directory itself.
#
html: $(_docHeaders)
	-if `doc++ -h > /dev/null` ; then                                 \
		$(RM) -r $(_htmlDir);                                     \
		mkdir -p $(_htmlDir);                                     \
		doc++ -f -j -B Banner.html -d $(_htmlDir) $(_docHeaders); \
	fi

HyperCLaw.tex: $(_docHeaders)
	-if `doc++ -h > /dev/null` ; then                                    \
	    doc++ -f -t -j -o HyperCLaw.tex -ep docxx_squish $(_docHeaders); \
	    sed '/[\]usepackage[{]docxx[}]/d' < HyperCLaw.tex > .junk;       \
	    mv .junk HyperCLaw.tex;                                          \
	fi

HyperCLaw.dvi: HyperCLaw.tex
	latex HyperCLaw.tex; latex HyperCLaw.tex

HyperCLaw.ps: HyperCLaw.dvi
	dvips HyperCLaw.dvi -o HyperCLaw.ps

#
# Create MS-IDE dsp file to build this project
#
DspOlevel = 1
DspFileRoot = $(EBASE)$(DIM)d
ifeq ($(DEBUG), TRUE)
  DspFileRoot := $(join $(DspFileRoot),.DEBUG)
  DspOlevel := 0
endif
dsp: $(DspFileRoot).dsp
.dspDepends: $(FEXE_sources) $(FEXE_headers) $(fEXE_sources) $(CEXE_headers) $(CEXE_sources) $(INCLUDE_LOCATIONS)
	@echo $^ > .dspDepends

$(DspFileRoot).dsp: .dspDepends
	@(echo Building DSP file = $(DspFileRoot).dsp;\
	$(TOP)/scripts/dsp.mak -p $(DspFileRoot) -t $(TOP) -d $(DIM) -o $(DspFileRoot).dsp -O $(DspOlevel) -f $^)

.PHONY: dsp .dspDepends

include $(TOP)/mk/Make.rules
