# If you are using this Makefile standalone and fastjet-config is not
# in your path, edit this line to specify the full path
FASTJETCONFIG=fastjet-config
PREFIX=`$(FASTJETCONFIG) --prefix`
CXX=g++
CXXFLAGS= -O3 -Wall -g
install_script = $(SHELL) ../utils/install-sh
check_script = ../utils/check.sh

# global contrib-wide Makefile include may override some of the above
# variables (leading "-" means don't give an error if you can't find
# the file)
-include ../.Makefile.inc

#------------------------------------------------------------------------
# things that are specific to this contrib
NAME=GenericSubtractor
SRCS=GenericSubtractor.cc
NOINST_SRCS=ExampleShapes.cc
EXAMPLES=example example_with_components
INSTALLED_HEADERS=GenericSubtractor.hh ShapeWithPartition.hh ShapeWithComponents.hh
#------------------------------------------------------------------------

CXXFLAGS += $(shell ${FASTJETCONFIG} --cxxflags)
LDFLAGS  +=-lm $(shell ${FASTJETCONFIG} --libs)

OBJS          = $(SRCS:.cc=.o)
NOINST_OBJS   = $(NOINST_SRCS:.cc=.o)
EXAMPLES_SRCS = $(EXAMPLES:=.cc)

install_HEADER  = $(install_script) -c -m 644
install_LIB     = $(install_script) -c -m 644
install_DIR     = $(install_script) -d

.PHONY: clean install examples $(EXAMPLES)

# compilation of the code (default target)
all: lib$(NAME).a

lib$(NAME).a: $(OBJS) 
	ar cru lib$(NAME).a $(OBJS)
	ranlib lib$(NAME).a

# building the examples
examples: $(EXAMPLES)

# the following construct allows to build each of the examples listed
# in $EXAMPLES automatically
$(EXAMPLES): % : %.o all $(NOINST_OBJS)
	$(CXX) -o $@ $< $(NOINST_OBJS) -L. -l$(NAME) $(LDFLAGS)

# check that everything went fine
check: examples
	@for prog in $(EXAMPLES); do\
	  $(check_script) $${prog} ../data/Pythia-Zp2jets-lhc-pileup-1ev.dat || exit 1;\
	done
	@echo "All tests successful"

# cleaning the directory
clean:
	rm -f *~ *.o

distclean: clean
	rm -f lib$(NAME).a $(EXAMPLES)

# install things in PREFIX/...
install: all
	$(install_DIR) $(PREFIX)/include/fastjet/contrib
	for header in $(INSTALLED_HEADERS); do\
	  $(install_HEADER) $$header $(PREFIX)/include/fastjet/contrib/;\
	done
	$(install_DIR) $(PREFIX)/lib
	$(install_LIB) lib$(NAME).a $(PREFIX)/lib

depend:
	makedepend -Y --   -- $(SRCS) $(EXAMPLES_SRCS)
# DO NOT DELETE

ExampleShapes.o: ExampleShapes.hh ShapeWithPartition.hh
GenericSubtractor.o: GenericSubtractor.hh ShapeWithComponents.hh
GenericSubtractor.o: SimpleGhostRescaler.hh ShapeWithPartition.hh
example.o: ExampleShapes.hh ShapeWithPartition.hh GenericSubtractor.hh
example.o: ShapeWithComponents.hh
example_with_components.o: ShapeWithComponents.hh ExampleShapes.hh
example_with_components.o: ShapeWithPartition.hh GenericSubtractor.hh
