# This is a template for all makefiles.

#Set the list of files to be deleted by clean (Targets can also be specified).:
CLEAN_TARGETS += $(ALL_LIBRARIES) cms310 small_aod aliceesd stl_example.root stltest foreign

# Set the list of target to make while testing.  By default, mytest is the
# only target added.  If the name of the target is changed in the rules then
# the name should be changed accordingly in this list.

TEST_TARGETS += atlasaod aliceesd teststl stltest2 foreign
ifeq ($(FAST),)
# Takes >1GB of RAM when building; disable for quick builds:
TEST_TARGETS += cms310
endif

# Search for Rules.mk in roottest/scripts
# Algorithm:  Find the current working directory and remove everything after
#  '*roottest/'.  Append the path for Rules.mk from within roottest, which 
#  should be 'scripts/Rules.mk'.  The roottest path is saved in the
#  ROOTTEST_HOME variable for use by the SUBDIRECTORIES variable and is 
#  exported to eliminate the overhead of findding the path again during 
#  recursive calls of gmake.
# Since all makefiles should be under roottest or one of its
#  subdirectories and all recursions of gmake are called by 
#    'cd [DIR]; gmake ...'
#  this algorithm should not fail in finding /roottest/ in the
#  current working directory.  
# Issues:  This algorithm will fail if a makefile is called from outside the 
#  roottest folder, as in executing 'gmake -f ~/roottest/Makefile' from 
#  the home directory.

ifeq ($(strip $(ROOTTEST_HOME)),)
   export ROOTTEST_HOME := $(shell git rev-parse --show-toplevel)/roottest/
   ifeq ($(strip $(ROOTTEST_HOME)),)
      export ROOTTEST_HOME := $(shell expr $(CURDIR) : '\(.*/roottest/\)')
   endif
   ifeq ($(strip $(ROOTTEST_HOME)),)
      $(error The head of roottest was not found.  Set ROOTTEST_HOME)
   endif
endif

include $(ROOTTEST_HOME)/scripts/Rules.mk
include $(ROOTTEST_HOME)/scripts/Reflex.mk


# The name of this target should be changed according to the test being run.  Any name changes
#  should also be reflected in the TEST_TARGETS variable above.

mytest:
	$(CMDECHO) echo mytest > /dev/null


# Outputs a message if the FAIL variable is null

testWithFailure:
ifeq ($(FAIL),)
	$(WarnFailTest)
endif


# Remember that sometest.log can be made automatically from
#  from runsometest.C
# This target attempts to create a log file (which should be the output of running the test), and
#  compares its output with a prebuilt reference file.  The reference file should be copied from
#  the log files produced during what is considered a successful run of the test.  The testWithDiff
#  files should be renamed according to the test being run.
# By default the TestDiff variable is set to compare the .log and .ref files
# To run a diff and ignore whitespacing use $(TestDiffW)

testWithDiff: testWithDiff.log testWithDiff.ref
	$(TestDiff)


atlasaod.log: runatlasaod.C
	$(CMDECHO) $(CALLROOTEXE) -q -b -l $< 2>&1 | $(RemoveLeadingDirs) | grep -v -e 'unused class rule' -e 'no dictionary for class pair' > $@ 

ifeq ($(ARCH)$(FAIL),win32)
atlasaod:
	$(WarnFailTest)
else
atlasaod: atlasaod.log
	$(TestDiff)
endif

cms310.log: runcms310.C
	$(CMDECHO) ulimit -n 1024 ; $(CALLROOTEXE) -q -b -l $< 2>&1 | $(RemoveLeadingDirs) | grep -v 'WARNING: IO rule for class' | grep -v -e 'unused class rule' -e 'no dictionary for class pair' > $@ 

ifeq ($(ARCH)$(FAIL),win32)
aliceesd:
	$(WarnFailTest)

cms310:
	$(WarnFailTest)
else
aliceesd: aliceesd.log
	$(TestDiff)

cms310: cms310.log
	$(TestDiff)

endif

aliceesd.log: runaliceesd.C
	$(CMDECHO) ulimit -n 1024 ; $(CALLROOTEXE) -q -b -l $< 2>&1 | $(RemoveLeadingDirs)  | grep -v -e 'unused class rule' -e 'no dictionary for class pair' > $@

stl_makeproject_test.$(DllSuf): stl_makeproject_test_cling.$(ObjSuf)  $(ROOTCORELIBS) $(ROOTCINT) $(ROOTV)
	$(BuildFromObj)

stl_example.log: create_makeproject_examples.C | stl_makeproject_test.$(DllSuf)
	$(CMDECHO) ulimit -n 1024 ; $(CALLROOTEXE) -q -b -l $< 2>&1 | $(RemoveLeadingDirs)  | grep -v -e 'unused class rule' -e 'no dictionary for class pair' > $@

stl_example: stl_example.log
	$(TestDiff)

stl_example.root: stl_example.log

stltest.log: runstltest.C stl_example.root
	$(CMDECHO) ulimit -n 1024 ; $(CALLROOTEXE) -q -b -l $< 2>&1 | $(RemoveLeadingDirs) | grep -v 'WARNING: IO rule for class' | grep -v -e 'unused class rule' -e 'no dictionary for class pair' > $@

stltest2.log: runstltest2.C stltest.log | stl_example.root 
	$(CMDECHO) ulimit -n 1024 ; $(CALLROOTEXE) -q -b -l $< 2>&1 | $(RemoveLeadingDirs) | grep -v 'WARNING: IO rule for class' | grep -v -e 'unused class rule' -e 'no dictionary for class pair' > $@

foreign.log: runforeign.C
	$(CMDECHO) ulimit -n 1024 ; $(CALLROOTEXE) -q -b -l $< 2>&1 | $(RemoveLeadingDirs) | grep -v 'WARNING: IO rule for class' | grep -v -e 'unused class rule' -e 'no dictionary for class pair' > $@

teststl: stltest.log
	$(TestDiff)

stltest2: stltest2.log
	$(TestDiff)

foreign: foreign.log
	$(TestDiff)

