CXXFLAGS=-O3 $(shell pkg-config --cflags gecode gecode-minimodel gecode-search)
LDFLAGS=$(shell pkg-config --libs gecode gecode-minimodel gecode-search)
EXAMPLES=$(patsubst %.cc,%,$(wildcard *.cc))
SUPPORT=support/example support/options
SUPPORT_OBJS=$(addsuffix .o,$(SUPPORT))

all: $(EXAMPLES)

$(addsuffix .o,$(EXAMPLES)):
	g++ $(CXXFLAGS) $(patsubst %.o,%.cc,$@) -c

$(addsuffix .o,$(SUPPORT)):
	g++ $(CXXFLAGS) $(patsubst %.o,%.cc,$@) -c -o $@

clean:
	rm -f $(EXAMPLES)
	rm -f *.o support/*.o

.PHONY: all clean

.SECONDEXPANSION:
$(EXAMPLES): $(SUPPORT_OBJS) $$@.o
	g++ $(LDFLAGS) $@.o $(SUPPORT_OBJS) -o $@
