-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathMakefile
122 lines (97 loc) · 3.3 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
# Run this on a docker container
tmp ?= /tmp/bbg
# tests without pre stuff involved
.PHONY: all
all: test1 test2 selfhost
# run all tests
.PHONY: test
test: $(tmp) test1 test2 selfhost test0 compare-test testlib
$(tmp):
mkdir -p $(tmp)
# make p compiler (a rich binary)
$(tmp)/p: src/*/* internal/*/* lib/*/* $(tmp)
rm -rf pre/internal pre/*.go
cp *.go pre/
cp -ar internal pre/
find pre -name '*.go' | xargs sed -e 's#github.com/DQNEO/babygo/lib/ast#go/ast#' -e 's#github.com/DQNEO/babygo/lib/token#go/token#' -e 's#github.com/DQNEO/babygo/lib/parser#go/parser#' -e 's#babygo/internal#babygo/pre/internal#g' -i
go build -o $@ ./pre
# babygo 1gen compiler (a rich binary)
$(tmp)/b: *.go lib/*/* src/*/* $(tmp)
go build -o $@ .
# babygo 2gen compiler (a thin binary) by p compiler
$(tmp)/pb: $(tmp)/p *.go src/*/* lib/*/*
[email protected] $< build -x -o $@ ./
# babygo 2gen compiler (a thin binary) by babygo 1gen compiler compiling babygo
$(tmp)/bb: $(tmp)/b
[email protected] $< build -x -o $@ ./
# babygo 3gen compiler (a thin binary) by babygo 2gen compiler compiling babygo
$(tmp)/bbb: $(tmp)/bb
[email protected] $< build -x -o $@ ./
# test binary made by p
$(tmp)/pt: $(tmp)/p t/*.go src/*/* lib/*/*
[email protected] $< build -x -o $@ ./t
# test binary made by babygo 1 gen compiler
$(tmp)/bt: $(tmp)/b t/*.go
[email protected] $< build -x -o $@ ./t
# test binary made by pb
$(tmp)/pbt: $(tmp)/pb t/*.go
[email protected] $< build -x -o $@ ./t
# test binary made by bb
$(tmp)/bbt: $(tmp)/bb t/*.go
[email protected] $< build -x -o $@ ./t
# make test expectations
t/expected.txt: t/*.go lib/*/*
export FOO=bar; go run t/*.go myargs > t/expected.txt
# test the test binary made by p compiler
.PHONY: test0
test0: $(tmp)/pt t/expected.txt
./test.sh $< $(tmp)
@echo "[PASS] test by p"
# test the test binary made by babygo 1gen compiler
.PHONY: test1
test1: $(tmp)/bt t/expected.txt
./test.sh $< $(tmp)
@echo "[PASS] test by b"
# test the test binary made by babygo 2gen compiler
.PHONY: test2
test2: $(tmp)/bbt t/expected.txt
./test.sh $< $(tmp)
@echo "[PASS] test by bb"
# do selfhost check by comparing 2gen and 3gen asm files
.PHONY: selfhost
selfhost: $(tmp)/bb $(tmp)/bbb
cat $(tmp)/bb.d/*.s > $(tmp)/bb.d/all
cat $(tmp)/bbb.d/*.s > $(tmp)/bbb.d/all
diff $(tmp)/bb.d/all $(tmp)/bbb.d/all >/dev/null
@echo "[PASS] selfhost"
# compare output of test0 and test1
.PHONY: compare-test
compare-test: $(tmp)/pt $(tmp)/bt $(tmp)/bbt $(tmp)/pbt
cat $(tmp)/pt.d/*.s > $(tmp)/pt.d/all
cat $(tmp)/bt.d/*.s > $(tmp)/bt.d/all
cat $(tmp)/pbt.d/*.s > $(tmp)/pbt.d/all
cat $(tmp)/bbt.d/*.s > $(tmp)/bbt.d/all
diff -u $(tmp)/pt.d/all $(tmp)/bt.d/all >/dev/null
diff -u $(tmp)/bt.d/all $(tmp)/pbt.d/all >/dev/null
diff -u $(tmp)/bt.d/all $(tmp)/bbt.d/all >/dev/null
@echo "[PASS] compare-test"
# Library's test by go test
.PHONY: testlib
testlib: lib/*/*
go test ./lib/...
.PHONY: fmt
fmt:
gofmt -w *.go t/*.go pre/*.go src/*/*.go lib/*/*.go
.PHONY: clean
clean:
rm -f ./tmp/*
rm -fr $(tmp) ./.shared/*
# to learn the official Go's assembly
.PHONY: example
example:
make example/example.s example/min.s
example/example.s: example
# -N: disable optimizations, -S: print assembly listing -l: no inline
go tool compile -N -S -l example/example.go > example/example.s
example/min.s: example
go tool compile -N -S -l example/min.go > example/min.s