## Makefile, static linking. Pythia8 is fetched and built
## automatically.
## On macOS the executable is linked with an rpath to libpythia8.dylib.
## Setting DYLD_LIBRARY_PATH is normally not necessary.

PYTHIAVER := $(shell ./installer.py -v)
PYTHIA8HOME := pythia$(PYTHIAVER)/
CXX := g++
CXXFLAGS := -O3 -I$(PYTHIA8HOME)/include -I$(PYTHIA8HOME)/include/Pythia8/ -std=c++14
LDFLAGS  := -L$(PYTHIA8HOME)/lib/ -L$(PYTHIA8HOME)/lib -Wl,-rpath,$(PWD)/$(PYTHIA8HOME)/lib
XMLDOC   := $(PYTHIA8HOME)/share/Pythia8/xmldoc

.PHONY: install_pythia8

all: install_pythia8 pythia8.exe

version:
	@echo $(PYTHIAVER)

install_pythia8:
	./installer.py

clean:
	@chmod -R u+w pythia$(PYTHIAVER) 2>/dev/null || echo "no pythia$(PYTHIAVER)"
	rm -rf $(EXES) test.slha .pythia*.tgz* pythia*.tgz* pythia8.exe events.lhe
	@rm -rf pythia$(PYTHIAVER) || /bin/rm -rf pythia$(PYTHIAVER)

pythia8.exe: install_pythia8 pythia8.cc
	echo $(XMLDOC) > xml.doc
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ pythia8.cc -lpythia8 -ldl

run:
	./pythia8.exe -f ../../../inputFiles/slha/simplyGluino.slha -n 10 -c ../../etc/pythia8.cfg -x $(XMLDOC)

help:
	./pythia8.exe -h

particles:
	## used to create mappings of pythia8 particle names to pdg ids
	## the user shouldnt have to do this
	./parseXml.py

upload_particles: particles
	## only needed if the particle names have changed
	cp pythia8particles.py ../../smodels/tools/
	
protect:
	./installer.py -p

remove_protection:
	./installer.py -r

test: all run
