summaryrefslogtreecommitdiff
path: root/bnf/Makefile
blob: 4a3b34546580ee87112e07f56b40e92bc1e83838 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

.SUFFIXES:

CXXFLAGS := -std=c++11 -x c++ -I . -g

OBJS := main.o rust.tab.o rust.lex.o

RUSTSRC := /home/tpg/Source/rust/rustc-nightly/src/

TSTFILES := ../samples/1.rs
TSTFILES += $(addprefix $(RUSTSRC), libcore/lib.rs libstd/lib.rs)

BIN := ./test.bin


all: $(BIN)

clean:
	rm $(BIN) $(OBJS)

test: $(BIN) $(TSTFILES)
	$(foreach f,$(TSTFILES), $(DBG) ./test.bin "$f" &&) true


.PHONY: rust_tests
RUST_TESTS_DIR := $(RUSTSRC)test/
rust_tests: $(patsubst $(RUST_TESTS_DIR)%.rs,output/rust/%.txt,$(sort $(wildcard $(RUST_TESTS_DIR)run-pass/*.rs)))

output/rust/%.txt: $(RUST_TESTS_DIR)%.rs $(BIN)
	@mkdir -p $(dir $@)
	$(BIN) $< > $@ 2>&1

$(BIN): $(OBJS)
	g++ -std=c++11 $(OBJS) -o $@ -g

%.o: %.cpp
	g++ $(CXXFLAGS) $< -c -o $@ -MMD -MP -MF $@.dep
%.o: .gen/%.cpp
	g++ $(CXXFLAGS) $< -c -o $@ -MMD -MP -MF $@.dep

.gen/rust.tab.cpp: .gen/.rust.y
	@mkdir -p $(dir $@)
	@echo [BISON] $@
	@bison -o $@ $< -d --verbose
# HACK: Bison emits duplicate entries in the union, remove those
	@mv $(@:%.cpp=%.hpp) $(@:%.cpp=%.hpp.OLD)
	@awk '{ if($$0 ~ /yacc.c:1909/) { ignore = 1; print $$0; } else if( ignore == 1 ) { trigger = $$0; ignore = 2; } else if( ignore == 2 ) { if($$0 == trigger) { ignore = 0 } }  if( ignore > 0 ) { } else { print $$0; }  }' < ${@:%.cpp=%.hpp.OLD} > $(@:%.cpp=%.hpp)
.gen/rust.tab.hpp: .gen/rust.tab.cpp

.gen/.rust.y: Makefile rust.y rust_expr.y.h rust_expr.y_tree.h rust_tts.y.h
	@mkdir -p $(dir $@)
	cat rust.y > $@
	cpp -P rust_expr.y.h >> $@
	cpp -P rust_tts.y.h >> $@


.gen/rust.lex.cpp: rust.lex
	@mkdir -p $(dir $@)
	flex -o $@ $<


main.cpp: .gen/rust.tab.hpp

-include $(OBJS:%=%.dep)