-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
212 lines (162 loc) · 9.44 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
SHELL = bash
.SHELLFLAGS = -o pipefail -c
.PHONY : help
help : Makefile ## Display this help
@sed -nE 's/^([[:alnum:]-]+)[[:space:]]*:[^#]*##[[:space:]]*(.*)$$/\1: \2/p' $<
HOST_SCHEME_FLAGS := --r7rs
HOST_SCHEME_COMPILED_DIR := ./compiled/
HOST_SCHEME_COMPILE_MODULE = guild compile $(HOST_SCHEME_FLAGS)
HOST_SCHEME_RUN_PROGRAM = guile $(HOST_SCHEME_FLAGS) --no-auto-compile
COMPILER_SOURCES = $(wildcard *.scm)
COMPILER_BINARIES := $(COMPILER_SOURCES:%.scm=$(HOST_SCHEME_COMPILED_DIR)%.go)
RUN_COMPILER = $(HOST_SCHEME_RUN_PROGRAM) -L . -C $(HOST_SCHEME_COMPILED_DIR) driver.scm
.PHONY : compile
compile : $(COMPILER_BINARIES) ## Compiles a scheme file from standard input and outputs WAT to standard output
$(RUN_COMPILER) $<
.PHONY : generate-runtime
generate-runtime : runtime/scheme-base.wat ## Generates the runtime library WAT
runtime/generate-scheme-base-wat.scm : values.scm
runtime/scheme-base.wat : runtime/generate-scheme-base-wat.scm
$(HOST_SCHEME_RUN_PROGRAM) -L . $< | wat-desugar - > [email protected] \
&& mv -f [email protected] $@
.PHONY : generate-runtime-test
generate-runtime-test : runtime/test/scheme-base.wast ## Generates the runtime library test script
runtime/test/ :
mkdir -p runtime/test
runtime/generate-scheme-base-wast.scm : values.scm
runtime/test/scheme-base.wast : runtime/generate-scheme-base-wast.scm | runtime/test/
$(HOST_SCHEME_RUN_PROGRAM) -L . $< > [email protected] \
&& mv -f [email protected] $@
.PHONY : test-runtime
test-runtime : runtime/test/test-runtime.log ## Executes tests for the runtime library
runtime/test/test-runtime.log : runtime/test/test-runtime.json | runtime/test/
spectest-interp $< | tee [email protected] \
&& mv -f [email protected] $@
runtime/test/test-runtime.json : runtime/test/test-runtime.wast | runtime/test/
wast2json $< -o $@
runtime/test/test-runtime.wast : runtime/scheme-base.wat \
runtime/register-scheme-base.wast \
runtime/test/scheme-base.wast \
| runtime/test/
cat $^ > $@
.PHONY : compile-compiler
compile-compiler : $(COMPILER_BINARIES) ## Compiles the compiler with host scheme
$(HOST_SCHEME_COMPILED_DIR) :
mkdir -p $@
COMPILER_DEPENDENCIES = $(HOST_SCHEME_COMPILED_DIR)module-dependencies.mk
$(COMPILER_DEPENDENCIES) : $(COMPILER_SOURCES) tools/scheme-dependencies.scm | $(HOST_SCHEME_COMPILED_DIR)
$(HOST_SCHEME_RUN_PROGRAM) tools/scheme-dependencies.scm $(COMPILER_SOURCES) \
| sed -e 's|\([^[:space:]]*\)\.scm|$(HOST_SCHEME_COMPILED_DIR)\1\.go|g' \
| tee [email protected] && mv -f [email protected] $@
include $(COMPILER_DEPENDENCIES)
$(COMPILER_BINARIES) : $(HOST_SCHEME_COMPILED_DIR)%.go : %.scm | $(HOST_SCHEME_COMPILED_DIR)
GUILE_LOAD_COMPILED_PATH=$(HOST_SCHEME_COMPILED_DIR) $(HOST_SCHEME_COMPILE_MODULE) -o $@ $<
TEST_COMPILER_DIR := test-compiler/
COMPILER_TEST_PROGRAMS := $(wildcard $(TEST_COMPILER_DIR)test/*.scm)
COMPILER_TEST_HOST_TARGETS := $(COMPILER_TEST_PROGRAMS:$(TEST_COMPILER_DIR)test/%.scm=$(TEST_COMPILER_DIR)%-host)
COMPILER_TEST_HOST_LOGS := $(COMPILER_TEST_PROGRAMS:$(TEST_COMPILER_DIR)test/%.scm=$(TEST_COMPILER_DIR)host-log/%.log)
RUN_COMPILER_TEST_HOST = $(HOST_SCHEME_RUN_PROGRAM) -L .. -L ../lib
$(TEST_COMPILER_DIR)build/ \
$(TEST_COMPILER_DIR)log/ \
$(TEST_COMPILER_DIR)host-log/ \
$(TEST_COMPILER_DIR)wast-log/ \
$(TEST_COMPILER_DIR)wat :
mkdir -p $@
.PHONY : test-compiler-host $(COMPILER_TEST_HOST_TARGETS)
test-compiler-host : $(COMPILER_TEST_HOST_LOGS) ## Executes the compiler integration tests on the host scheme
$(COMPILER_TEST_HOST_TARGETS) : $(TEST_COMPILER_DIR)%-host : $(TEST_COMPILER_DIR)host-log/%.log
$(COMPILER_TEST_HOST_LOGS) : $(TEST_COMPILER_DIR)host-log/%.log : $(TEST_COMPILER_DIR)%.scm \
$(TEST_COMPILER_DIR)test/%.scm \
$(TEST_COMPILER_DIR)/lib/compiler-test.scm \
| $(TEST_COMPILER_DIR)host-log/
cd $(TEST_COMPILER_DIR)host-log ; \
rm -f $(notdir $(@:%.log=%.fail.log)) ; \
$(RUN_COMPILER_TEST_HOST) ../test/$(notdir $<) || \
(mv -f $(notdir $@) $(notdir $(@:%.log=%.fail.log)) && cat $(notdir $(@:%.log=%.fail.log)))
COMPILER_TEST_WAST_TARGETS := $(COMPILER_TEST_PROGRAMS:$(TEST_COMPILER_DIR)test/%.scm=$(TEST_COMPILER_DIR)%-wast)
COMPILER_TEST_WAST_TESTS := $(COMPILER_TEST_PROGRAMS:$(TEST_COMPILER_DIR)test/%.scm=$(TEST_COMPILER_DIR)build/%-test.wast)
COMPILER_TEST_WAST_LOGS := $(COMPILER_TEST_PROGRAMS:$(TEST_COMPILER_DIR)test/%.scm=$(TEST_COMPILER_DIR)wast-log/%.log)
COMPILER_TEST_WAST_COMPILER := $(TEST_COMPILER_DIR)lib/compiler-test-to-wast.scm
COMPILER_TEST_TO_WAST := $(HOST_SCHEME_RUN_PROGRAM) -L . -C $(HOST_SCHEME_COMPILED_DIR) $(COMPILER_TEST_WAST_COMPILER)
COMPILER_TEST_SCM_MODULES := $(wildcard $(TEST_COMPILER_DIR)*.scm)
COMPILER_TEST_WAT_MODULES := $(COMPILER_TEST_SCM_MODULES:$(TEST_COMPILER_DIR)%.scm=$(TEST_COMPILER_DIR)wat/%.wat)
.PHONY : test-compiler-wast $(COMPILER_TEST_WAST_TARGETS)
test-compiler-wast : $(COMPILER_TEST_WAST_LOGS) $(COMPILER_TEST_WAT_MODULES) ## Compiles the compiler tests to WAST scripts and executes them
$(COMPILER_TEST_WAST_TARGETS) : $(TEST_COMPILER_DIR)%-wast : $(TEST_COMPILER_DIR)wast-log/%.log
$(COMPILER_TEST_WAST_LOGS) : $(TEST_COMPILER_DIR)wast-log/%.log : $(TEST_COMPILER_DIR)build/%-test.json \
| $(TEST_COMPILER_DIR)wast-log/
spectest-interp $< | tee [email protected] \
&& mv -f [email protected] $@
$(TEST_COMPILER_DIR)build/%-test.json : $(TEST_COMPILER_DIR)build/test-prelude.wast \
$(TEST_COMPILER_DIR)build/%.wat \
$(TEST_COMPILER_DIR)build/%-test.wast \
| $(TEST_COMPILER_DIR)build/
cat $^ | wast2json - -o [email protected] \
&& mv -f [email protected] $@
$(COMPILER_TEST_WAST_TESTS) : $(TEST_COMPILER_DIR)lib/compiler-test-to-wast.scm
$(COMPILER_TEST_WAST_TESTS) : $(TEST_COMPILER_DIR)build/%-test.wast : $(TEST_COMPILER_DIR)test/%.scm \
| $(TEST_COMPILER_DIR)build/
$(COMPILER_TEST_TO_WAST) < $< > [email protected] \
&& mv -f [email protected] $@
$(COMPILER_TEST_WAT_MODULES) : $(TEST_COMPILER_DIR)wat/%.wat : $(TEST_COMPILER_DIR)build/%.wat \
| $(TEST_COMPILER_DIR)wat
wat-desugar $< -o $@
COMPILER_TEST_DIRECT_TESTS := $(wildcard $(TEST_COMPILER_DIR)wast/*.wast)
COMPILER_TEST_DIRECT_TARGETS := $(COMPILER_TEST_DIRECT_TESTS:%.wast=%)
COMPILER_TEST_DIRECT_LOGS := $(COMPILER_TEST_DIRECT_TARGETS:$(TEST_COMPILER_DIR)wast/%=$(TEST_COMPILER_DIR)log/%.log)
.PHONY : test-compiler-direct
test-compiler-direct : $(COMPILER_TEST_DIRECT_LOGS) ## Executes integration tests for the compiler
$(COMPILER_TEST_DIRECT_TARGETS) : $(TEST_COMPILER_DIR)wast/% : $(TEST_COMPILER_DIR)log/%.log
$(TEST_COMPILER_DIR)log/%.log : $(TEST_COMPILER_DIR)build/%.json | $(TEST_COMPILER_DIR)log/
spectest-interp $< | tee [email protected] \
&& mv -f [email protected] $@
$(TEST_COMPILER_DIR)build/%.json : $(TEST_COMPILER_DIR)build/test-prelude.wast \
$(TEST_COMPILER_DIR)build/%.wat \
$(TEST_COMPILER_DIR)wast/%.wast \
| $(TEST_COMPILER_DIR)build/
cat $^ | wast2json - -o [email protected] \
&& mv -f [email protected] $@
$(TEST_COMPILER_DIR)build/test-prelude.wast : runtime/scheme-base.wat \
runtime/register-scheme-base.wast \
| $(TEST_COMPILER_DIR)build/
cat $^ > $@
$(TEST_COMPILER_DIR)build/%.wat : $(TEST_COMPILER_DIR)%.scm $(COMPILER_BINARIES) | $(TEST_COMPILER_DIR)build/
$(RUN_COMPILER) < $< > [email protected] \
&& mv -f [email protected] $@
.PRECIOUS : $(TEST_COMPILER_DIR)build/%.json $(TEST_COMPILER_DIR)build/%.wast $(TEST_COMPILER_DIR)build/%.wat
TEST_UNIT_DIR := test-unit/
UNIT_TEST_PROGRAMS := $(wildcard $(TEST_UNIT_DIR)*.scm)
UNIT_TEST_BINARIES := $(UNIT_TEST_PROGRAMS:$(TEST_UNIT_DIR)%.scm=$(TEST_UNIT_DIR)compiled/%.go)
UNIT_TEST_TARGETS := $(UNIT_TEST_PROGRAMS:.scm=)
UNIT_TEST_LOGS := $(UNIT_TEST_PROGRAMS:$(TEST_UNIT_DIR)%.scm=$(TEST_UNIT_DIR)log/%.log)
RUN_UNIT_TEST := $(HOST_SCHEME_RUN_PROGRAM) -C $(TEST_UNIT_DIR)compiled -C $(HOST_SCHEME_COMPILED_DIR)
.PHONY : test-unit $(UNIT_TEST_TARGETS)
test-unit : $(UNIT_TEST_LOGS) ## Executes the unit tests for the compiler
$(UNIT_TEST_TARGETS) : $(TEST_UNIT_DIR)% : $(TEST_UNIT_DIR)log/%.log
$(TEST_UNIT_DIR)log $(TEST_UNIT_DIR)compiled :
mkdir -p $@
$(UNIT_TEST_BINARIES) : $(TEST_UNIT_DIR)compiled/%.go : $(TEST_UNIT_DIR)%.scm | $(TEST_UNIT_DIR)compiled
$(HOST_SCHEME_COMPILE_MODULE) -L . -o $@ $<
$(UNIT_TEST_LOGS) : $(TEST_UNIT_DIR)log/%.log : $(TEST_UNIT_DIR)%.scm | $(TEST_UNIT_DIR)log
$(RUN_UNIT_TEST) $< > [email protected] \
&& mv -f [email protected] $@
$(UNIT_TEST_LOGS) : $(UNIT_TEST_BINARIES)
$(UNIT_TEST_BINARIES) : $(COMPILER_BINARIES)
.PHONY : test
test : test-runtime test-unit test-compiler-host test-compiler-wast test-compiler-direct ## Executes all tests
.PHONY : clean
clean : clean-test clean-compiler ## Removes test outputs and forces compiler re-compilation
.PHONY : clean-compiler
clean-compiler : ## Forces compiler re-compilation
-rm -rf $(HOST_SCHEME_COMPILED_DIR)
.PHONY : clean-test
clean-test : ## Removes test build artefacts and results
-rm -rf \
runtime/test \
runtime/scheme-base.wat \
$(TEST_UNIT_DIR)log \
$(TEST_UNIT_DIR)compiled \
$(TEST_COMPILER_DIR)build \
$(TEST_COMPILER_DIR)log \
$(TEST_COMPILER_DIR)host-log \
$(TEST_COMPILER_DIR)wast-log