# This makefile will make all of the ROOT classes in the current directory
# It finds all dependancies for each file, compiles the classes, calls
# rootcint to make the dictionary file, compiles that, and links 
# the class and dictionary object files together


ROOTCFLAGS    = $(shell root-config --cflags)
ROOTLIBS      = $(shell root-config --new --libs)
ROOTGLIBS     = $(shell root-config --glibs)

# Linux with egcs
CXX           = g++
CXXFLAGS      = -O2 -Wall -fPIC $(ROOTCFLAGS)
LD            = g++
LDFLAGS       =  $(ROOTLIBS) $(ROOTGLIBS) -L/home/rainman/rfliller/ROOT
SOFLAGS       = -shared 


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

SRCS := $(wildcard *.cxx)
OBJS := $(patsubst %.cxx,%.o,$(SRCS))
DEPS := $(patsubst %.cxx,%.d,$(SRCS))
PROGRAMS := libBug.so libOnMe.so dummy

all:            $(PROGRAMS)


clean:
		@rm -f core *.o *.d 

#  Calculate Dependancies
%.d :%.cxx
	$(CXX) -M $(CXXFLAGS) $< | sed s/\\.o/.d/ > $@

# Dependancies for object files
%.o: %.cxx
	$(CXX) $(CXXFLAGS) -c $<

#Dependancies for so files

libBug.so: bug.o bugDict.o
	$(LD) $(SOFLAGS) -Wl,-soname,$@ $(LDFLAGS) $^ -o $@

libOnMe.so: onme.o onmeDict.o
	$(LD) $(SOFLAGS) -Wl,-soname,$@ $(LDFLAGS) -L\. -lBug $^ -o $@

dummy: dummy.o
	$(LD) $(LDFLAGS) -L\. -lBug -lOnMe $^ -o $@

# Dendancies of Dictionary files
%Dict.cxx: %.h  %LinkDef.h 
	@echo "Generating dictionary $@..."
	$(ROOTSYS)/bin/rootcint -f $@ -c $^


depend: $(DEPS)
	@echo "Dependancies are now up to date"

