
CC = $(CXX)
CFLAGS = -MMD -O6 -Wall -ffast-math -finline-functions -fomit-frame-pointer -fstrict-aliasing $(GCCFLAGS)
LDFLAGS = -Wall -O6 $(GCCLDFLAGS)
#
# debugging
#
# CFLAGS = -g -O -MMD -Wall -ffast-math -fstrict-aliasing $(GCCFLAGS)
# LDFLAGS = -g -Wall
#
# profiling
#
# CFLAGS = -g -pg -O6 -MMD -Wall -ffast-math -fno-default-inline -fno-inline $(GCCFLAGS)
# CFLAGS = -g -pg -O -MMD -Wall -ffast-math $(GCCFLAGS)
# LDFLAGS = -g -pg

CXXFLAGS = $(CFLAGS) -Wno-deprecated

TARGETS = gibbs-pcfg hastings-pcfg # gibbs-test hastings-test
SOURCES = gammavariate.c gibbs-pcfg.cc hastings-pcfg.cc mt19937ar.c
OBJECTS = $(patsubst %.l,%.o,$(patsubst %.c,%.o,$(SOURCES:%.cc=%.o)))

top: $(TARGETS)

.PHONY: run-test
run-test: gibbs.trace hastings.trace

.PHONY: gibbs.trace
gibbs.trace: gibbs-pcfg testengger.lt testeng.yld
	gibbs-pcfg -d 500 -a 1 -S 0 -F gibbs.trace testengger.lt < testger.yld

.PHONY: hastings.trace
hastings.trace: hastings-pcfg testengger.lt testeng.yld
	hastings-pcfg -d 100 -T 10 -m 50 -F hastings.trace testengger.lt < testger.yld


gibbs-pcfg: gibbs-pcfg.o gammavariate.o mt19937ar.o
	$(CXX) $(LDFLAGS) $^ -o $@

hastings-pcfg: hastings-pcfg.o mt19937ar.o
	$(CXX) $(LDFLAGS) $^ -o $@


gammavariate.o: gammavariate.c
	gcc -c $(CFLAGS) $< -o $@

matinv.o: matinv.c
	gcc -c $(CFLAGS) $< -o $@

mt19937ar.o: mt19937ar.c
	gcc -c $(CFLAGS) $< -o $@

main: main.o sym.o
	$(CXX) $(LDFLAGS) $^ -o $@

.PHONY: 
clean: 
	rm -fr *.o *.d *~ core read-tree.cc *.trace

.PHONY: real-clean
real-clean: clean 
	rm -fr $(TARGETS)

# this command tells GNU make to look for dependencies in *.d files
-include $(patsubst %.l,%.d,$(patsubst %.c,%.d,$(SOURCES:%.cc=%.d)))
