################################################################################
# Makefile for building a HepMC PYTHIA8 example
#
# Lynn Garren garren@fnal.gov
#
# main31 and main32 have been copied from PYTHIA 8.157
# you must source either config.csh or config.sh first
#
# ./main31.exe
# ./main32.exe main32.cmnd hepmcout32.dat
#
################################################################################ Define directory paths 
#    You may have to change PYTHIA8_HOME and/or other variables
#
  HepMCdir      = /usr
  HEPMCLOCATION = $(HepMCdir)
  HepMClib      = -lHepMC
  Pythia_LIB	= -lpythia8 -lLHAPDF -lhepmcinterface

################################################################################ Compiler options
#
  CXX           = g++
  INCLUDES 	= -I/usr/include/pythia8
  CXXFLAGS      =  -march=x86-64-v3 -O3 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection -mpclmul -Wp,-D_GLIBCXX_ASSERTIONS -g -ffile-prefix-map=/startdir/src=/usr/src/debug/hepmc2 -flto=auto -falign-functions=32 -O -ansi -pedantic -Wall -D_GNU_SOURCE -O2 -g -DNDEBUG -Wshadow -fbounds-check $(INCLUDES)
ifeq "$(CXX)" "g++"
   FLAGS 	= $(DFLG) -fno-second-underscore $(INCDIR)
else
  FLAGS 	= $(DFLG) $(INCDIR)
endif

  LINK_LIBS     = -Wl,-O1 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now          -Wl,-z,pack-relative-relocs -flto=auto -falign-functions=32 

UNAME = $(shell uname)
ifneq "$(UNAME)" "Darwin"
  LINK_LIBS     += -Wl,-rpath -Wl,$(HepMCdir)/lib
endif

  HDRS          = $(HepMCdir)/include/HepMC/*.h *.h
  EXAMPLES	=  main31.exe main32.exe

###############################################################################
#
.SUFFIXES:      .o .cc .exe

all:	$(EXAMPLES)

main31.exe: main31.o
	$(CXX) $(CXXFLAGS) -o $@ main31.o \
	$(Pythia_LIB) \
	$(HepMClib)

main32.exe: main32.o
	$(CXX) $(CXXFLAGS) -o $@ main32.o \
	$(Pythia_LIB) \
	$(HepMClib)

###############################################################################
#
.cc.o:         $(HDRS) $<
	$(CXX) $(CXXFLAGS) -c $< -o $@

###############################################################################
# gmake clean       removes all garbage from HepMC directories.
# gmake distclean       removes all compiled libraries, executables, +garbage
#
clean:
	rm -f *.o

distclean: 
	$(MAKE) clean --no-print-directory
	rm -f $(EXAMPLES)
	rm -f *.dat
