#---------------------------------------------------
# get compilation flags from root-config

ROOTCFLAGS    = $(shell $(ROOTSYS)/bin/root-config --cflags)

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

OS            = LINUX
CXX           = g++-4.4.0
CXXFLAGS      = -O3 -Wall -fopenmp -Wno-trigraphs -fPIC
MUSRFITINCLUDE = ../../../include
#MUSRFITINCLUDE = /home/l_wojek/rep/analysis/musrfit/src/include
LOCALINCLUDE  = ../include
ROOTINCLUDE   = $(ROOTSYS)/include
INCLUDES      = -I$(LOCALINCLUDE) -I$(MUSRFITINCLUDE) -I$(ROOTINCLUDE)
LD            = g++-4.4.0
LDFLAGS       = -O3
SOFLAGS       = -O3 -shared -fopenmp -lfftw3_threads -lfftw3 -lm -lpthread

# the output from the root-config script:
CXXFLAGS      += $(ROOTCFLAGS)
LDFLAGS       +=

# some definitions: headers (used to generate *Dict* stuff), sources, objects,...
OBJS =
OBJS += TTrimSPDataHandler.o
OBJS += TBofZCalc.o
OBJS += TPofBCalc.o
OBJS += TPofTCalc.o
OBJS += TFitPofBStartupHandler.o TFitPofBStartupHandlerDict.o
OBJS += TLondon1D.o TLondon1DDict.o
OBJS += TSkewedGss.o TSkewedGssDict.o

SHLIB = libTFitPofB.so

# make the shared lib:
#
all:  $(SHLIB)

$(SHLIB): $(OBJS)
	@echo "---> Building shared library $(SHLIB) ..."
	/bin/rm -f $(SHLIB)
	$(LD) $(OBJS) $(SOFLAGS) -o $(SHLIB)
	@echo "done"

# clean up: remove all object file (and core files)
# semicolon needed to tell make there is no source
# for this target!
#
clean:; 	@rm -f $(OBJS) *Dict* core*
	@echo "---> removing $(OBJS)"

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

# Generate the ROOT CINT dictionary

TLondon1DDict.cpp: ../include/TLondon1D.h ../include/TLondon1DLinkDef.h
	@echo "Generating dictionary $@..."
	rootcint -f $@ -c -p -I$(MUSRFITINCLUDE) $^

TSkewedGssDict.cpp: ../include/TSkewedGss.h ../include/TSkewedGssLinkDef.h
	@echo "Generating dictionary $@..."
	rootcint -f $@ -c -p -I$(MUSRFITINCLUDE) $^

TFitPofBStartupHandlerDict.cpp: ../include/TFitPofBStartupHandler.h ../include/TFitPofBStartupHandlerLinkDef.h
	@echo "Generating dictionary $@..."
	rootcint -f $@ -c -p $^

install: all
	@echo "Installing shared lib: libTFitPofB.so"
ifeq ($(OS),LINUX)
	cp -pv $(SHLIB) $(ROOTSYS)/lib
	cp -pv $(LOCALINCLUDE)/*.h $(ROOTSYS)/include
endif
