opt		=	-O2

xml_h		=	
xml_lib		=	-lxmltok -lxmlparse
xml_exp		=	-lexpat

root_fe		=	$(shell awk 'BEGIN {n=0} /^ *\#define USE_ROOT_FE/ {n++} END {print n}' reader.h)
ifeq ($(root_fe),1)
root_h		=	$(shell root-config --cflags)
root_lib	=	$(shell root-config --glibs)
endif

all:	clean fat-reader rmo

tcalfit.o:
	c++ tcalfit.cxx -c $(opt)

reader.o:
	c++ reader.cxx -c $(opt) $(root_h) $(xml_h) || \
	( sed 's-xmlparse-expat-' reader.cxx > foo.cxx && mv foo.cxx reader.cxx && c++ reader.cxx -c $(opt) $(root_h) $(xml_h) )

fat-reader:	tcalfit.o reader.o
	c++ fat-reader.cxx -o fat-reader $(opt) $(root_lib) $(xml_lib) tcalfit.o reader.o && strip fat-reader || \
	c++ fat-reader.cxx -o fat-reader $(opt) $(root_lib) $(xml_exp) tcalfit.o reader.o && strip fat-reader

jj-reader:	clean tcalfit.o
	c++ jj-reader.cxx -o jj-reader $(opt) tcalfit.o && strip jj-reader

clean:
	rm *.o *~ jj-reader fat-reader >& /dev/null || true

rmo:
	rm *.o >& /dev/null || true
