-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMakefile
144 lines (104 loc) · 3.51 KB
/
Makefile
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
CXXFLAGS := -O -g -std=gnu++11 -Wall -W -Werror
CFLAGS := -I. -fno-builtin -m32
CFLAGS += -Wall -W -Werror -Wno-unused-function
CLANGFLAGS := $(CFLAGS) -Wno-incompatible-library-redeclaration
BFS_SRCS :=
BFS_ASMS := $(wildcard test/*.bfs)
BFS_ASMS_STAGED := $(BFS_ASMS:test/%.bfs=out/%.bfs)
BFS_SRCS += $(BFS_ASMS_STAGED)
BFS_RBS := $(wildcard test/*.bfs.rb)
BFS_RBS_STAGED := $(BFS_RBS:test/%.bfs.rb=out/%.bfs)
BFS_SRCS += $(BFS_RBS_STAGED)
BFS_CS := $(wildcard test/*.c)
ifndef BFS24
BFS_CS := $(filter-out test/24_%.c, $(BFS_CS))
endif
BFS_CS_STAGED := $(BFS_CS:test/%.c=out/%.bfs)
TEST_EXES := $(BFS_CS:test/%.c=out/%.exe)
TEST_RES := $(TEST_EXES:%.exe=%.res)
TEST_OKS := $(TEST_EXES:%.exe=%.ok1)
#BFS_CS := $(wildcard test/*.c)
#BFS_ASMS := $(BFS_CS:test/%.c=out/%.s)
#BFS_OBJS := $(BFS_CS:test/%.c=out/%.o)
#BFS_CS_STAGED := $(BFS_OBJS:%.o=%.bfs)
BFS_SRCS += $(BFS_CS_STAGED)
BFS_BFS := $(BFS_SRCS:%.bfs=%.bf)
BFS_SIMS := $(BFS_SRCS:%.bfs=%.sim)
BFS_OUTS := $(BFS_SRCS:%.bfs=%.out)
BFS_OKS := $(BFS_SRCS:%.bfs=%.ok2)
# Very slow.
BFS_OKS_RUN := $(BFS_OKS)
BFS_OKS_RUN := $(filter-out out/fizzbuzz.ok2, $(BFS_OKS_RUN))
RUBY_DEPS := $(wildcard bf*.rb) common.rb Makefile
LISP_BFS := out/lisp.bfs
LISP_BF := out/lisp.bf
8CC_C := out/8cc.c
8CC_BFS := out/8cc.bfs
ALL := $(BFS_BFS) $(BFS_SIMS) $(BFS_OKS_RUN)
ALL += $(BFS_OBJS) $(BFS_ASMS)
ALL += 8cc/8cc
ALL += $(TEST_OKS)
ALL += $(LISP_BFS)
ALL += out/bfopt $(LISP_BF)
$(shell mkdir -p out)
all: $(ALL)
define run-diff
@if diff -uN $1 $2 > [email protected]; then \
echo PASS: "$*.bfs($3)"; \
mv [email protected] $@; \
else \
echo FAIL: "$*.bfs($3)"; \
cat [email protected]; \
fi
endef
$(BFS_ASMS_STAGED): out/%.bfs: test/%.bfs
cp $< [email protected] && mv [email protected] $@
$(BFS_RBS_STAGED): out/%.bfs: test/%.bfs.rb
ruby $< > [email protected] && mv [email protected] $@
$(BFS_CS_STAGED): out/%.bfs: test/%.c 8cc/8cc libf.h
8cc/8cc -S -o [email protected] $< && mv [email protected] $@
$(BFS_BFS): %.bf: %.bfs $(RUBY_DEPS)
./bfcore.rb $< > [email protected] && mv [email protected] $@
$(BFS_SIMS): %.sim: %.bfs $(RUBY_DEPS) run.sh
./run.sh ./bfsim.rb -q $< > [email protected] && mv [email protected] $@
$(BFS_OUTS): %.out: %.bf run.sh out/bfopt
./run.sh out/bfopt $< > [email protected] && mv [email protected] $@
$(BFS_OKS): %.ok2: %.sim %.out
$(call run-diff,$*.sim,$*.out,sim:bf)
$(TEST_EXES): out/%.exe: test/%.c libf.h
$(CC) -fno-builtin -g -o $@ $<
$(TEST_RES): %.res: %.exe run.sh
./run.sh $< $*.bfs > [email protected] && mv [email protected] $@
$(TEST_OKS): %.ok1: %.res %.sim
$(call run-diff,$*.res,$*.sim,gcc:8cc)
$(LISP_BFS): lisp.c 8cc/8cc libf.h
8cc/8cc -S -o [email protected] $< && mv [email protected] $@
$(LISP_BF): $(LISP_BFS)
./bfcore.rb $< > [email protected] && mv [email protected] $@
$(8CC_C): 8cc/8cc merge_8cc.sh
./merge_8cc.sh > [email protected] && mv [email protected] $@
$(8CC_BFS): out/8cc.c 8cc/8cc libf.h
8cc/8cc -S -o [email protected] $< && mv [email protected] $@
out/8cc.bf out/8cc.2.bf out/8cc.3.bf: out/8cc%.bf: out/8cc%.bfs
BFS24=1 ./bfcore.rb $< > [email protected] && mv [email protected] $@
out/8cc.bf.c out/8cc.2.bf.c: out/8cc%.bf.c: out/8cc%.bf out/bfopt
out/bfopt -c $< [email protected] && mv [email protected] $@
out/8cc.bf.tcc.o out/8cc.2.bf.tcc.o: out/8cc%.bf.tcc.o: out/8cc%.bf.c
tcc -c $< -o $@
out/8cc.bf.tcc.exe out/8cc.2.bf.tcc.exe: out/8cc%.bf.tcc.exe: out/8cc%.bf.tcc.o
$(CC) $< -o $@
out/8cc.2.bfs: out/8cc.bf.tcc.exe $(8CC_C)
$< < out/8cc.c > [email protected] && mv [email protected] $@
out/8cc.3.bfs: out/8cc.2.bf.tcc.exe $(8CC_C)
$< < out/8cc.c > [email protected] && mv [email protected] $@
out/bfopt: bfopt.cc
$(CXX) $(CXXFLAGS) $< -o $@
.PHONY: all
.SUFFIXES:
8cc/8cc: $(wildcard 8cc/*.c 8cc/*.h) 8cc/README.md
$(MAKE) -C 8cc
8cc/README.md:
rm -fr 8cc.tmp
git clone https://github.com/shinh/8cc.git 8cc.tmp
cd 8cc.tmp && git checkout bfs
mv 8cc.tmp 8cc