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

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

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

OS            = LINUX
CXX           = g++
CXXFLAGS      = -O3 -Wall -Wno-trigraphs -fPIC
LOCALINCLUDE  = .
ROOTINCLUDE   = $(ROOTSYS)/include
INCLUDES      = -I$(LOCALINCLUDE) -I$(ROOTINCLUDE)
LD            = g++
LDFLAGS       =
SOFLAGS       = -O -shared

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

# some definitions: headers (used to generate *Dict* stuff), sources, objects,...
OBJS =
OBJS += TBNMR.o TlibBNMRDict.o

SHLIB = libBNMR.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

TlibBNMRDict.cpp: TBNMR.h TBNMRLinkDef.h
	@echo "Generating dictionary $@..."
	rootcint -f $@ -c -p -I$(ROOTINCLUDE) $^

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