################################################################################ 
#
# makefile for HepPID examples
# These examples are used to verify particle numbering translations.
#
# use: gmake [INCDIR= ] [CXX= ] [LIBNAME= ] all
#      gmake [INCDIR= ] [CXX= ] [LIBNAME= ] run
#
# Options:  
#      [HEPPDT_BASE= ]
#      [HerwigLIB= ]
#      [IsajetLIB= ]
#      [PythiaLIB= ]
#
################################################################################ 

  HEPPDT_BASE= /usr
  CXX = g++
  LIBNAME = $(HEPPDT_BASE)/lib/libHepPID.a
  HerwigLIB = $(HERWIG_DIR)/lib/libherwig.a $(HERWIG_DIR)/lib/libherdum.a $(HERWIG_DIR)/lib/timel.o
  IsajetLIB = $(ISAJET_DIR)/libisajet.a
  PythiaLIB = $(PYLIB)/pydata.o $(PYLIB)/libpythia.a $(PYLIB)/libpydum.a
  INCDIR    = -I$(HEPPDT_BASE)/include
  LIBS = -Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 

################################################################################ 

ifndef DEBUG
    DEBUG = none
    DFLG =
    SFX =
else
    DFLG = $(DEBUG)
    SFX = _g
endif

ifdef HERWIG_DIR
    INCDIR += -I$(HERWIG_DIR)/src
endif

ifdef PYTHIA_DIR
    INCDIR += -I$(PYTHIA_DIR)/src/inc
endif

ifeq "$(CXX)" "g++"
    F77 = g77
    FFLAGS = $(DFLG) -fno-second-underscore $(INCDIR)
else
    F77 = f77
    FFLAGS = $(DFLG) $(INCDIR)
endif

################################################################################ 

AR=ar
ARFLG = -urs

CXXFLAGS = $(DFLG) -O -ansi -pedantic -Wall -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection $(INCDIR)

#------------------------------------------

all: examListHerwig examListIsajet examListPythia

examListPythia: examListPythia.o examListPythiaInterface.o
	$(CXX) $(CXXFLAGS) -o $@ \
		examListPythia.o examListPythiaInterface.o \
		$(PythiaLIB) \
		$(LIBNAME) $(LIBS) -lg2c
	rm -f examListPythia.lpt

examListHerwig: examListHerwig.o examListHerwigInterface.o
	$(CXX) $(CXXFLAGS) -o $@ \
		examListHerwig.o examListHerwigInterface.o \
		$(HerwigLIB) \
		$(LIBNAME) $(LIBS) -lg2c

examListIsajet: examListIsajet.o examListIsajetInterface.o
	$(CXX) $(CXXFLAGS) -o $@ \
		examListIsajet.o examListIsajetInterface.o \
		$(IsajetLIB) \
		$(LIBNAME) $(LIBS) -lg2c
	rm -f examListIsajet.lpt

cleanobjs:
	rm -f *.o

clean:
	rm -f *.o
	rm -f examListPythia examListHerwig examListIsajet
	rm -f *.out *.log *.lpt
	rm -f fort.*


#------------------------------------------

.PHONY:  clean cleanobjs

.SUFFIXES :             # cancel implicit rules
.SUFFIXES : .o .cc .cpp .F .inc .h .hh

%.o: %.cc
	$(CXX) $(CXXFLAGS) -c $<

%_g.o: %.cc
	$(CXX) $(CXXFLAGS) -c -o $@ $<

%.o: %.cpp
	$(CXX) $(CXXFLAGS) -c $<

%_g.o: %.cpp
	$(CXX) $(CXXFLAGS) -c -o $@ $<

%.o: %.F
	$(F77) $(FFLAGS) -c -o $@ $<
	
%_g.o: %.F
	$(F77) $(FFLAGS) -c -o $@ $<
 
