-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathMakefile
464 lines (381 loc) · 10.2 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
COMMONFLAGS := -W -Wall -W -Werror -MMD -MP -O -g -Wno-missing-field-initializers
CFLAGS := -std=gnu99 $(COMMONFLAGS) -Wno-missing-field-initializers
CXXFLAGS := -std=c++11 $(COMMONFLAGS)
uname := $(shell uname)
ifneq (,$(findstring arm,$(shell uname -m)))
ARCH := arm
else
ARCH := x86
endif
ELI := out/eli
ELC := out/elc
8CC := out/8cc
8CC_SRCS := \
8cc/buffer.c \
8cc/cpp.c \
8cc/debug.c \
8cc/dict.c \
8cc/encoding.c \
8cc/error.c \
8cc/file.c \
8cc/gen.c \
8cc/lex.c \
8cc/main.c \
8cc/map.c \
8cc/parse.c \
8cc/path.c \
8cc/set.c \
8cc/vector.c
LLC := llvm-build/bin/llc
BINS := $(8CC) $(ELI) $(ELC) out/dump_ir out/befunge out/bfopt out/tm tinycc/tcc
LIB_IR_SRCS := ir/ir.c ir/table.c
LIB_IR := $(LIB_IR_SRCS:ir/%.c=out/%.o)
ELC_EIR := out/elc.c.eir.c.gcc.exe
all: build
@echo ''
@echo 'Now you have tools such as out/8cc and out/elc'
@echo ''
@echo 'Use following targets to build/run tests for backend xxx:'
@echo ''
@echo '- `make build-xxx`: Compile all tests to xxx backend'
@echo ' (e.g., out/lisp.c.eir.xxx will be built from test/lisp.c)'
@echo '- `make test-xxx` or `make xxx`: Run tests for xxx backend'
@echo ' (e.g., out/lisp.c.eir.xxx.out.diff will be output)'
@echo '- `make test-xxx-full`: Run target/xxx.c on ELVM'
@echo ' (this checks if the target xxx can self-host)'
@echo '- `make test`: Build and run all tests'
@echo ' (WARNING: will take a lot of time/disk)'
@echo ''
out/git_submodule.stamp: .git/index
git submodule update --init
touch $@
$(8CC_SRCS) Whitespace/whitespace.c tinycc/configure: out/git_submodule.stamp
Whitespace/whitespace.out: Whitespace/whitespace.c
$(MAKE) -C Whitespace 'MAX_SOURCE_SIZE:=16777216' 'MAX_BYTECODE_SIZE:=16777216' 'MAX_N_LABEL:=1048576' 'HEAP_SIZE:=16777224'
out/befunge: tools/befunge.cc
$(CXX) $(CXXFLAGS) $< -o $@
out/bfopt: tools/bfopt.cc
$(CXX) $(CXXFLAGS) $< -o $@
out/tm: tools/tm.cc
$(CXX) $(CXXFLAGS) $< -o $@
tinycc/tcc: tinycc/config.h
$(MAKE) -C tinycc tcc libtcc1.a
tinycc/config.h: tinycc/configure
cd tinycc && ./configure
out/elc.c.eir.c.gcc.exe: out/elc.c.eir.c
$(CC) -o $@ $<
CSRCS := $(LIB_IR_SRCS) ir/dump_ir.c ir/eli.c
COBJS := $(addprefix out/,$(notdir $(CSRCS:.c=.o)))
$(COBJS): out/%.o: ir/%.c
$(CC) -c -I. $(CFLAGS) $< -o $@
ELC_SRCS := \
elc.c \
util.c \
arm.c \
bef.c \
bf.c \
c.c \
cl.c \
cpp.c \
cr.c \
cs.c \
el.c \
forth.c \
fs.c \
go.c \
i.c \
java.c \
js.c \
php.c \
piet.c \
pietasm.c \
pl.c \
py.c \
ps.c \
rb.c \
sed.c \
sh.c \
sqlite3.c \
swift.c \
tex.c \
tf.c \
tm.c \
unl.c \
vim.c \
ws.c \
x86.c \
ELC_SRCS := $(addprefix target/,$(ELC_SRCS))
COBJS := $(addprefix out/,$(notdir $(ELC_SRCS:.c=.o)))
$(COBJS): out/%.o: target/%.c
$(CC) -c -I. $(CFLAGS) $< -o $@
out/dump_ir: $(LIB_IR) out/dump_ir.o
$(CC) $(CFLAGS) -DTEST $^ -o $@
$(ELI): $(LIB_IR) out/eli.o
$(CC) $(CFLAGS) $^ -o $@
$(ELC): $(LIB_IR) $(ELC_SRCS:target/%.c=out/%.o)
$(CC) $(CFLAGS) $^ -o $@
$(8CC): $(8CC_SRCS)
$(MAKE) -C 8cc && cp 8cc/8cc $@
# Stage tests
$(shell mkdir -p out)
TEST_RESULTS :=
SRCS := $(sort $(wildcard test/*.eir))
DSTS := $(SRCS:test/%.eir=out/%.eir)
OUT.eir := $(DSTS)
$(DSTS): out/%.eir: test/%.eir
cp $< [email protected] && mv [email protected] $@
SRCS := $(wildcard test/*.eir.rb)
DSTS := $(SRCS:test/%.eir.rb=out/%.eir)
OUT.eir += $(DSTS)
$(DSTS): out/%.eir: test/%.eir.rb
ruby $< > [email protected] && mv [email protected] $@
SRCS := $(sort $(wildcard test/*.c))
DSTS := $(SRCS:test/%.c=out/%.c)
$(DSTS): out/%.c: test/%.c
cp $< [email protected] && mv [email protected] $@
OUT.c := $(SRCS:test/%.c=out/%.c)
out/8cc.c: $(8CC_SRCS)
cp 8cc/*.h 8cc/*.inc 8cc/include/*.h out
cat $(8CC_SRCS) > [email protected] && mv [email protected] $@
OUT.c += out/8cc.c
out/elc.c: $(ELC_SRCS) $(LIB_IR_SRCS)
cat $^ > [email protected] && mv [email protected] $@
OUT.c += out/elc.c
out/dump_ir.c: ir/dump_ir.c $(LIB_IR_SRCS)
cat $^ > [email protected] && mv [email protected] $@
OUT.c += out/dump_ir.c
out/eli.c: ir/eli.c $(LIB_IR_SRCS)
cat $^ > [email protected] && mv [email protected] $@
OUT.c += out/eli.c
# Build tests
TEST_INS := $(wildcard test/*.in)
include clear_vars.mk
SRCS := $(OUT.c)
EXT := exe
CMD = $(CC) -std=gnu99 -DNOFILE -include libc/_builtin.h -I. $2 -o $1
OUT.c.exe := $(SRCS:%=%.$(EXT))
include build.mk
include clear_vars.mk
SRCS := $(filter-out out/8cc.c.exe,$(OUT.c.exe))
EXT := out
DEPS := $(TEST_INS) runtest.sh
CMD = ./runtest.sh $1 $2
include build.mk
include clear_vars.mk
SRCS := out/8cc.c.exe
EXT := out
DEPS := $(TEST_INS)
# TODO: Hacky!
sharp := \#
CMD = $2 -S -o $1.S.tmp - < test/8cc.in.c && sed 's/ *$(sharp).*//' $1.S.tmp > $1.S && (echo === test/8cc.in === && cat $1.S && echo) > $1.tmp && mv $1.tmp $1
include build.mk
include clear_vars.mk
SRCS := $(OUT.c)
# 8cc doesn't support function call with structs.
SRCS := $(filter-out out/024pass_struct.c out/025ret_struct.c,$(SRCS))
EXT := eir
CMD = $(8CC) -S -I. -Ilibc -Iout -o $1.tmp $2 && mv $1.tmp $1
DEPS := $(wildcard libc/*.h)
OUT.eir += $(SRCS:%=%.$(EXT))
include build.mk
include clear_vars.mk
SRCS := $(OUT.eir)
EXT := out
DEPS := $(TEST_INS) runtest.sh
CMD = ./runtest.sh $1 $(ELI) $2
OUT.eir.out := $(SRCS:%=%.$(EXT))
include build.mk
include clear_vars.mk
OUT.c.exe.out := $(OUT.c.exe:%=%.out)
OUT.c.eir.out := $(filter $(OUT.eir:%=%.out),$(OUT.c.exe.out:%.c.exe.out=%.c.eir.out))
EXPECT := c.exe.out
ACTUAL := c.eir.out
include diff.mk
ifdef LLVM
include clear_vars.mk
SRCS := $(OUT.c)
EXT := ll
CMD = llvm-build/bin/clang -g -std=c99 -m32 -target elvm-unknown-linux-gnu -emit-llvm -S -include libc/_builtin.h -I. -Ilibc -Iout -o $1.tmp $2 && mv $1.tmp $1
DEPS := $(wildcard libc/*.h)
OUT.c.ll := $(SRCS:%=%.$(EXT))
include build.mk
$(LLC): llc
@
llc:
ninja -C llvm-build bin/llc
include clear_vars.mk
SRCS := $(OUT.c.ll)
EXT := eir
CMD = $(LLC) -march=elvm -asm-verbose $2 -o $1.tmp && cat libc/crt.eir $1.tmp > $1.tmp2 && rm $1.tmp && mv $1.tmp2 $1
DEPS := $(LLC) libc/crt.eir
OUT.c.ll.eir := $(SRCS:%=%.$(EXT))
include build.mk
include clear_vars.mk
SRCS := $(OUT.c.ll.eir)
EXT := out
DEPS := $(TEST_INS) runtest.sh
CMD = ./runtest.sh $1 $(ELI) $2
OUT.c.ll.eir.out := $(SRCS:%=%.$(EXT))
include build.mk
include clear_vars.mk
EXPECT := c.exe.out
ACTUAL := c.ll.eir.out
include diff.mk
endif
build: $(TEST_RESULTS)
# They are tests for compiler, not useful for backends.
OUT.eir:=$(filter-out out/0%.c.eir,$(OUT.eir))
# Targets
TARGET := rb
RUNNER := ruby
include target.mk
TARGET := py
RUNNER := python
include target.mk
ifdef TF
TARGET := tf
RUNNER := python
include target.mk
endif
TARGET := js
RUNNER := nodejs
include target.mk
TARGET := php
RUNNER := php
include target.mk
TARGET := el
RUNNER := emacs --no-site-file --script
include target.mk
TARGET := vim
RUNNER := tools/runvim.sh
TOOL := vim
include target.mk
TARGET := tex
RUNNER := tools/runtex.sh
TOOL := tex
include target.mk
TARGET := cl
RUNNER := sbcl --script
include target.mk
TARGET := sh
RUNNER := bash
ifndef FULL
TEST_FILTER := out/fizzbuzz_fast.c.eir.sh out/8cc.c.eir.sh out/eli.c.eir.sh out/dump_ir.c.eir.sh
endif
include target.mk
TARGET := sed
RUNNER := sed -n -f
# Sed backend is so slow.
ifndef FULL
TEST_FILTER := out/24_cmp.c.eir.sed out/24_cmp2.c.eir.sed out/24_muldiv.c.eir.sed out/bitops.c.eir.sed out/copy_struct.c.eir.sed out/eof.c.eir.sed out/fizzbuzz.c.eir.sed out/fizzbuzz_fast.c.eir.sed out/global_struct_ref.c.eir.sed out/lisp.c.eir.sed out/printf.c.eir.sed out/qsort.c.eir.sed out/8cc.c.eir.sed out/elc.c.eir.sed out/dump_ir.c.eir.sed out/eli.c.eir.sed
endif
# Only GNU sed can output NUL.
ifeq ($(findstring GNU,$(shell sed --version)),)
TEST_FILTER += out/04getc.eir.sed
endif
include target.mk
TARGET := java
RUNNER := tools/runjava.sh
TOOL := javac
include target.mk
$(OUT.eir.java.out): tools/runjava.sh
TARGET := swift
RUNNER := tools/runswift.sh
TOOL := swiftc
include target.mk
$(OUT.eir.swift.out): tools/runswift.sh
TARGET := cr
RUNNER := tools/runcr.sh
TOOL := crystal
include target.mk
$(OUT.eir.crystal.out): tools/runcr.sh
TARGET := cs
RUNNER := tools/runcs.sh
CAN_BUILD := $(if $(or $(shell which dotnet),$(and $(shell which mono),$(shell which gmcs))),1,0)
include target.mk
$(OUT.eir.cs.out): tools/runcs.sh
TARGET := c
RUNNER := tools/runc.sh
include target.mk
$(OUT.eir.c.out): tools/runc.sh
TARGET := cpp
RUNNER := tools/runcpp.sh
TOOL := g++-6
include target.mk
$(OUT.eir.cpp.out): tools/runcpp.sh
ifeq ($(uname),Linux)
TARGET := $(ARCH)
RUNNER :=
include target.mk
endif
TARGET := i
RUNNER := tools/runi.sh
TOOL := ick
# INTERCAL backend is 16bit.
TEST_FILTER := $(addsuffix .i,$(filter out/24_%.eir,$(OUT.eir))) out/eof.c.eir.i out/neg.c.eir.i
include target.mk
$(OUT.eir.i.out): tools/runi.sh
TARGET := ws
RUNNER := tools/runws.sh
TEST_FILTER := out/eli.c.eir.ws
include target.mk
$(OUT.eir.ws.out): tools/runws.sh Whitespace/whitespace.out
TARGET := bef
RUNNER := out/befunge
include target.mk
TARGET := bf
RUNNER := tools/runbf.sh
ifndef FULL
TEST_FILTER := out/eli.c.eir.bf out/dump_ir.c.eir.bf
endif
include target.mk
$(OUT.eir.bf.out): tools/runbf.sh
ifdef PIETASM
TARGET := pietasm
RUNNER := tools/runpietasm.sh
include target.mk
$(OUT.eir.piet.out): tools/runpietasm.sh
endif
ifdef PIET
TARGET := piet
RUNNER := tools/runpiet.sh
# Piet backend is 16bit.
TEST_FILTER := $(addsuffix .piet,$(filter out/24_%.c.eir,$(OUT.eir))) out/eof.c.eir.piet out/neg.c.eir.piet
include target.mk
$(OUT.eir.piet.out): tools/runpiet.sh
endif
TARGET := unl
RUNNER := tools/rununl.sh
ifndef FULL
TEST_FILTER := out/eli.c.eir.unl out/dump_ir.c.eir.unl
endif
include target.mk
$(OUT.eir.unl.out): tools/rununl.sh
TARGET := tm
RUNNER := out/tm
TEST_FILTER := out/24_cmp.c.eir.tm out/24_cmp2.c.eir.tm out/24_muldiv.c.eir.tm out/bitops.c.eir.tm out/copy_struct.c.eir.tm out/eof.c.eir.tm out/fizzbuzz.c.eir.tm out/fizzbuzz_fast.c.eir.tm out/global_struct_ref.c.eir.tm out/lisp.c.eir.tm out/printf.c.eir.tm out/qsort.c.eir.tm out/8cc.c.eir.tm out/elc.c.eir.tm out/dump_ir.c.eir.tm out/eli.c.eir.tm
include target.mk
TARGET := forth
RUNNER := gforth --dictionary-size 16M
include target.mk
TARGET := fs
RUNNER := tools/runfs.sh
CAN_BUILD := $(if $(or $(shell which dotnet),$(and $(shell which mono),$(shell which fsharpc))),1,0)
include target.mk
$(OUT.eir.fs.out): tools/runfs.sh
TARGET := pl
RUNNER := perl
include target.mk
TARGET := go
RUNNER := go run
include target.mk
TARGET := sqlite3
RUNNER := tools/runsqlite3.sh
TOOL := sqlite3
include target.mk
TARGET := ps
RUNNER := gsnd -q -dBATCH --
include target.mk
test: $(TEST_RESULTS)
.SUFFIXES:
-include */*.d