#
# $Id: GNUmakefile,v 1.39 2003/03/17 20:21:46 marc Exp $
#
PBOXLIB_HOME = ..

TOP = $(PBOXLIB_HOME)
#
# Variables for the user to set ...
#
PRECISION = DOUBLE
DEBUG	  = TRUE
DEBUG	  = FALSE
PROFILE   = FALSE
DIM       = 2
DIM       = 3
USE_THREADS=TRUE
USE_THREADS=FALSE
USE_MPI=TRUE
USE_MPI=FALSE
AIXLARGEMEM=TRUE
AIXLARGEMEM=FALSE

COMP      = mpKCC
COMP      = KCC
COMP      = g++

USE_ARRAYVIEW = FALSE

# See below (set TRUE if this derive has a corresponding Fort file)
BL_HAS_FORT = TRUE

#
# By default we build AmrDerive.
#
# Easiest way to use this is to set it on the command line, say
#
#   gmake EBASE=AmrDeriveIntegrate DEBUG=FALSE
#
#EBASE = AmrDeriveAvgPlots
#EBASE = AmrDeriveMatLab
#EBASE = AmrDeriveBinTrac
#EBASE = AmrDerivePeriodicFab
#EBASE = AmrDeriveTestFlush
#EBASE = AmrDerive
#EBASE = AmrDeriveDist
#EBASE = AmrDeriveTBR
#EBASE = AmrDerive
#EBASE = AmrDeriveStoch
#EBASE = AmrDeriveQuench
#EBASE = AmrDeriveSumRho
#EBASE = AmrDeriveTecplot
#EBASE = AmrDerive_VtoRTZavg
#EBASE = AmrDerive_Vfluct
#EBASE = AmrDerive_IntScale
#EBASE = AmrDeriveYAvg
EBASE = AmrDeriveTurbfile
#EBASE = AmrDerive2Chombo
#EBASE = AmrDeriveIntegrate
#EBASE = AmrDeriveYIntegrals

PBOXLIB_HOME = ..
ifeq ($(EBASE), AmrDerive2Chombo)
  XTRALIBS += -lhdf5 -lz
endif
ifeq ($(EBASE), AmrDeriveTecplot)
  LIBRARY_LOCATIONS += /usr/local/Tecplot/lib
  #LIBRARY_LOCATIONS += ${HOME}/Local/TEC90/lib/mesa
  XTRALIBS += -ltec
  #Joe Grcar (1/13/03): use only the following and comment out the others
  #XTRALIBS += /usr/tec92/lib/tecio.a
endif
include $(TOP)/mk/Make.defs

ifeq ($(PROFILE), FALSE)
ifeq ($(DEBUG), TRUE)
USE_ARRAYVIEW = TRUE
USE_ARRAYVIEW = FALSE
endif
endif


HERE = .

#ifeq ($(MACHINE), OSF1)
#INCLUDE_LOCATIONS += /usr/include/X11 /usr/include/Xm /usr/include/X11/Xaw
#endif
#
#ifeq ($(MACHINE), T3E)
#ifeq ($(WHICHT3E), NERSC)
#INCLUDE_LOCATIONS += /opt/ctl/cvt/3.1.0.0/include/X11
#INCLUDE_LOCATIONS += /opt/ctl/cvt/3.1.0.0/include/Xm
#INCLUDE_LOCATIONS += /opt/ctl/cvt/3.1.0.0/include/X11/Xaw
#LIBRARY_LOCATIONS += /opt/ctl/cvt/ctv/lib
#endif
#endif

#DEFINES           += -DBL_DERIVE_IAMR
DEFINES           += -DBL_DERIVE_HCHEM

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

BUILD_INPLACE := FALSE
BUILD_INPLACE := TRUE

#ifeq ($(MACHINE), OSF1)
#LIBRARIES += -lXm -lXt -lX11
#endif
#
#ifeq ($(MACHINE), T3E)
#ifeq ($(WHICHT3E), NERSC)
#LIBRARIES += -lXm -lSM -lICE -lXt -lX11
#endif
#endif

CEXE_sources += $(EBASE).cpp
ifeq ($(EBASE), AmrDeriveQuench)
  CHEMDIR = $(TOP)/HeatTransfer/ChemKinDriver
endif

include ./Make.package
ifeq (${BL_HAS_FORT}, TRUE)
FEXE_sources += ${EBASE}_F.F
endif

DEFINES += -DBL_PARALLEL_IO
ifeq ($(COMP),KCC)
  ifeq ($(KCC_VERSION),3.3)
    CXXFLAGS += --diag_suppress 837
    CXXOPTF  += -Olimit 2400
    #CXXFLAGS += -fprm n -fptm u
  endif
endif

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

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

ifeq ($(USE_ARRAYVIEW),TRUE)
DEFINES += -DBL_USE_ARRAYVIEW
DEFINES += -DBL_ARRAYVIEW_TAGBOX
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
#
# For Running 3rd Only
#
3RD = 1
3RD =
ifdef 3RD
LDFLAGS += --link_command_prefix 3rd
LDFLAGS += -non_shared -v
endif

ifeq ($(BUILD_INPLACE), TRUE)
  PATHDIRS = . $(TOP)/pAmrvis $(TOP)/amrlib $(TOP)/bndrylib $(TOP)/BoxLib
else
  PATHDIRS = . $(TOP)/pAmrvis
endif
ifeq ($(EBASE), AmrDeriveQuench)
  INCLUDE_LOCATIONS += $(CHEMDIR)
  PATHDIRS += $(CHEMDIR)
endif
ifeq ($(EBASE), AmrDerive2Chombo)
  INCLUDE_LOCATIONS += ../../HDF/include
  cEXE_sources += chomboHDF5.c
  cEXE_headers += chomboHDF5.h
  FEXE_sources += AmrDerive2Chombo_F.F FILCC_$(DIM)D.F
  FEXE_headers += AmrDerive2Chombo_F.H
  LIBRARY_LOCATIONS += ../../HDF/lib
  INCLUDE_LOCATIONS += $(TOP)/amrlib
  include $(TOP)/bndrylib/Make.package
endif
#
# Note: If you need to link to Tecplot libs, you will need to link
#         the Tecplot lib/include sutff to this location
#
ifeq ($(EBASE), AmrDeriveTecplot)
  INCLUDE_LOCATIONS += /usr/local/TEC90/include
  #INCLUDE_LOCATIONS += ${HOME}/Local/TEC90/include
  #Joe Grcar (1/13/03): use only the following and comment out the others
  #INCLUDE_LOCATIONS += /usr/tec92/include
endif

ifeq ($(BUILD_INPLACE), TRUE)
  vpath %.f   $(PATHDIRS)
  vpath %.F   $(PATHDIRS)
  vpath %.h   $(PATHDIRS)
  vpath %.H   $(PATHDIRS)
  vpath %.cpp $(PATHDIRS)
else
  vpath %.f   $(PATHDIRS)
  vpath %.F   $(PATHDIRS)
  vpath %.h   $(PATHDIRS)
  vpath %.H   $(PATHDIRS)
  vpath %.cpp $(PATHDIRS)
  vpath %.a   $(LIBRARY_LOCATIONS)
endif

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 in an appropriate 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 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
#
# 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 $^)

include $(TOP)/mk/Make.rules
