# --------------------------------------------------------------
# GNUmakefile for creating exampleR06: Using the Geant4
# hit mechanism with ROOT.
# Note that as of 30-Oct-2000, it has only been tested with
# ROOT 2.25/03, Geant 4.2.0ref2, on a Linux Redhat 6.2 system.
# --------------------------------------------------------------

# Note: To adapt this example for working code, you not only have to
# edit the name of the main program, but you also have to edit the
# ROOT class definitions and implementions below.
name := exampleR06
G4TARGET := $(name)
G4EXLIB := true

ifndef G4INSTALL
  G4INSTALL = ../../..
endif

.PHONY: all
all: lib bin

include $(G4INSTALL)/config/architecture.gmk

ROOTCFLAGS = `root-config --cflags`
CPPFLAGS += $(ROOTCFLAGS)
LDFLAGS += `root-config --nonew --libs`

# Before we compile, use rootcint to create the dictionary files for
# our ROOT classes.  This example will create src/ExR05Dictionary.cc
# and src/ExR05Dictionary.h.
$(G4TARGET).cc: src/ExR05Dictionary.cc
src/ExR05Dictionary.cc: include/ExR05RootEvent.hh include/ExR05RootHit.hh
	@echo "Generating dictionary ExR05Dictionary..."
	@rootcint -f src/ExR05Dictionary.cc -c $(ROOTCFLAGS) -I./include ExR05RootEvent.hh ExR05RootHit.hh

# Standard G4 compilation:
include $(G4INSTALL)/config/binmake.gmk

# After G4 programs have compiled, create the ROOT shared library.
RootShared = ./ExR05.so
RootObjs = $(G4TMPDIR)/ExR05RootEvent.o $(G4TMPDIR)/ExR05RootHit.o $(G4TMPDIR)/ExR05Dictionary.o
bin: $(RootShared)
$(RootShared): $(RootObjs)
	@echo "Making ROOT shared library..."
	@$(CXX) -shared -O $(RootObjs) -o $@
	@echo "$@ done"

# For cleaning the ROOT files, add a command to the standard G4 "make clean":
clean: clean_root
clean_root:
	@echo "Deleting old dictionaries, shared libraries, output files, documentation and analysis classes..."
	@rm -f *.so src/*Dictionary.* *MakeClass* *.root

# This is not part of the G4 application.  It's included so you can
# type "make analysis" to compile the script in analysis.C.
analysis: analysis.C $(RootShared)
	@echo "Compiling analysis program..."
	g++ $< `root-config --cflags --libs` -Iinclude $(RootShared) -o $@

