include ../make.inc
include make.inc

TAUOLA        :=  $(shell cd .. && pwd)
ROOTLIB       :=  $(shell root-config --glibs)
ROOTINC       :=  $(shell root-config --cflags)
ROOTLIBPATH   :=  $(shell root-config --libdir)
PYTHIA_LIBS    = -L$(PYTHIALOCATION)/lib/archive -lpythia8 -llhapdfdummy -lhepmcinterface
MC_TESTER_LIBS = -L$(MCTESTERLOCATION)/lib -lHEPEvent -lHepMCEvent -lMCTester
HEPMC_LIBS     = -L$(HEPMCLOCATION)/lib -lHepMC
TAUOLA_LIBS    = -L../lib -lTauolaCxxInterface -lTauolaFortran

all:
	@make taumain_stand_alone_example.exe
ifneq ($(PYTHIALOCATION), )
	@make single_tau_gun_example.exe
	@make taummk_pythia_example.exe
ifneq ($(MCTESTERLOCATION), )
	@make taumain_pythia_example.exe
endif
endif
	@echo "##################################################################"
	@echo " Examples compiled successfully. Available examples:"
	@if test -e taumain_stand_alone_example.exe; then \
	echo " ./taumain_stand_alone_example.exe"; fi
	@if test -e single_tau_gun_example.exe; then \
	echo " ./single_tau_gun_example.exe"; fi
	@if test -e taummk_pythia_example.exe; then \
	echo " ./taummk_pythia_example.exe"; fi
	@if test -e taumain_pythia_example.exe; then \
	echo " ./taumain_pythia_example.exe"; fi
	@echo "##################################################################"


# Universal example (all paths presents)
%.o: %.c
	$(CC) $(CFLAGS) -I../include -I$(PYTHIALOCATION)/include -I$(MCTESTERLOCATION)/include \
	-I$(HEPMCLOCATION)/include $(ROOTINC) -c $<

# Universal example (all paths presents) - linking procedure
%.exe: %.o
	$(CC) -o $@ $(LDFLAGS) $< $(ROOTLIB) \
	$(PYTHIA_LIBS) $(MC_TESTER_LIBS) $(HEPMC_LIBS) $(TAUOLA_LIBS) \
	-Wl,-rpath,$(PREFIX)/lib \
	-Wl,-rpath,$(TAUOLA)/lib \
	-Wl,-rpath,$(ROOTLIBPATH) \
	-Wl,-rpath,$(HEPMCLOCATION)/lib \
	-Wl,-rpath,$(PYTHIALOCATION)/lib \
	-Wl,-rpath,$(MCTESTERLOCATION)/lib

# Version for tau gun example - HepMC & Pythia8 required
single_tau_gun_example.exe: single_tau_gun_example.c
	$(CC) $(CFLAGS) -I../include -I$(HEPMCLOCATION)/include \
	-I$(PYTHIALOCATION)/include -c $<
	$(CC) -o $@ $(LDFLAGS) $(<:.c=.o) $(HEPMC_LIBS) $(TAUOLA_LIBS) $(PYTHIA_LIBS) \
	-Wl,-rpath,$(PREFIX)/lib \
	-Wl,-rpath,$(TAUOLA)/lib \
	-Wl,-rpath,$(HEPMCLOCATION)/lib \
	-Wl,-rpath,$(PYTHIALOCATION)/lib

# Version for taummk example - HepMC & Pythia8 required
taummk_pythia_example.exe: taummk_pythia_example.c
	$(CC) $(CFLAGS) -I../include -I$(HEPMCLOCATION)/include \
	-I$(PYTHIALOCATION)/include -c $<
	$(CC) -o $@ $(LDFLAGS) $(<:.c=.o) $(HEPMC_LIBS) $(TAUOLA_LIBS) $(PYTHIA_LIBS) \
	-Wl,-rpath,$(PREFIX)/lib \
	-Wl,-rpath,$(TAUOLA)/lib \
	-Wl,-rpath,$(HEPMCLOCATION)/lib \
	-Wl,-rpath,$(PYTHIALOCATION)/lib

# Version for standalone example - only HepMC required
taumain_stand_alone_example.exe: taumain_stand_alone_example.c
	$(CC) $(CFLAGS) -I../include -I$(HEPMCLOCATION)/include -c $<
	$(CC) -o $@ $(LDFLAGS) $(<:.c=.o) $(HEPMC_LIBS) $(TAUOLA_LIBS) \
	-Wl,-rpath,$(PREFIX)/lib \
	-Wl,-rpath,$(TAUOLA)/lib \
	-Wl,-rpath,$(HEPMCLOCATION)/lib

clean:
	rm -f *.o *.a *~ *.exe

Clean: clean
	rm -rf config.log config.status autom4te.cache configure.paths.sh
	rm -f make.inc

make.inc:
	@echo ""
	@echo "Please execute ./configure first!"
	@echo ""
	@false

../make.inc:
	@echo ""
	@echo "Please compile the interface first!"
	@echo ""
	@false
