
CFLAGS  = -O3 -W -Wall -fomit-frame-pointer -march=native -mtune=native -DNDEBUG -fprefetch-loop-arrays
FILES   = $(wildcard src/*.coffee)
TARGETS = cpp/TextMiningCompiler cpp/TextMiningApp
TARGETS_COFFEE = $(FILES:.coffee=.js)

all: $(TARGETS)

coffee: $(TARGETS_COFFEE)

check: $(TARGETS) dict/words.out dict/words.bin
	bash -c 'time (cat test/en_400.txt | ./cpp/TextMiningApp dict/words.out > cpp.txt)'
	bash -c 'time (cat test/en_400.txt | ./ref/TextMiningApp dict/words.bin > ref.txt)'
	diff ref.txt cpp.txt

%.out: %.txt
	bash -c 'time ./cpp/TextMiningCompiler $< $@'

%.bin: %.txt
	bash -c 'time ./ref/TextMiningCompiler $< $@'

%.js: %.coffee
	coffeescript/bin/coffee -c $<

cpp/TextMiningCompiler: src/compiler.cc
	g++ $(CFLAGS) -o $@ $<
	cp cpp/TextMiningCompiler .

cpp/TextMiningApp: src/app.cc
	g++ $(CFLAGS) -o $@ $<
	cp cpp/TextMiningApp .

clean:
	rm -f $(TARGETS) $(TARGETS_COFFEE)
	rm -f TextMiningApp TextMiningCompiler
	rm -f dict/*.json
	rm -f dict/*.bin
	rm -f dict/*.out
	rm -f cpp.txt ref.txt
