forked from samirose/sicp-compiler-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
130 lines (108 loc) · 3.42 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
SHELL = /bin/bash
.SHELLFLAGS = -o pipefail -c
LIBDIR := lib/
LIBS := \
lists \
pattern-match \
scheme-syntax \
scheme-r7rs-syntax \
lexical-env \
wasm-syntax \
wasm-module-definitions \
compiled-program \
compilation-error \
expression-compiler \
module-compiler
LIBDIRS = $(addprefix $(LIBDIR),$(LIBS))
COMPILED_COMPILER := compiled/driver_sps.dep compiled/driver_sps.zo
SCHEME := plt-r6rs
SCHEME_COMPILE_PROGRAM := plt-r6rs ++path ${LIBDIR} --compile
SCHEME_COMPILE_LIBRARY := plt-r6rs --install --collections ${LIBDIR}
SCHEME_RUN_PROGRAM := plt-r6rs ++path ${LIBDIR}
$(COMPILED_COMPILER) &: $(LIBDIRS) driver.sps
rm -f $(COMPILED_COMPILER)
$(SCHEME_COMPILE_PROGRAM) driver.sps
$(LIBDIR)% : %.sls
rm -rf $@
$(SCHEME_COMPILE_LIBRARY) $<
touch $@
RUN_DRIVER = $(SCHEME_RUN_PROGRAM) driver.sps
lib/wasm-module-definitions : \
lib/lists \
lib/wasm-syntax
lib/compiled-program : \
lib/wasm-module-definitions
lib/scheme-r7rs-syntax: \
lib/pattern-match \
lib/compilation-error
lib/scheme-syntax: \
lib/pattern-match \
lib/compilation-error
lib/lexical-env: \
lib/lists
lib/expression-compiler : \
lib/lists \
lib/scheme-syntax \
lib/lexical-env \
lib/compiled-program \
lib/compilation-error \
lib/wasm-syntax \
lib/wasm-module-definitions
lib/module-compiler : \
lib/lists \
lib/scheme-syntax \
lib/scheme-r7rs-syntax \
lib/compilation-error \
lib/lexical-env \
lib/compiled-program \
lib/wasm-syntax \
lib/pattern-match \
lib/expression-compiler
.PHONY : compile
compile : $(COMPILED_COMPILER)
$(RUN_DRIVER) $<
TEST_COMPILER_DIR := test-compiler
COMPILER_TEST_PROGRAMS = $(wildcard $(TEST_COMPILER_DIR)/*.scm)
COMPILER_TEST_LOGS = $(patsubst $(TEST_COMPILER_DIR)/%.scm,$(TEST_COMPILER_DIR)/log/%.log,$(COMPILER_TEST_PROGRAMS))
.PHONY : test-compiler-dirs test-compiler
test-compiler : test-compiler-dirs $(COMPILER_TEST_LOGS)
test-compiler-dirs : $(TEST_COMPILER_DIR)/build $(TEST_COMPILER_DIR)/log
$(TEST_COMPILER_DIR)/build :
mkdir -p $@
$(TEST_COMPILER_DIR)/log :
mkdir -p $@
$(TEST_COMPILER_DIR)/log/%.log : $(TEST_COMPILER_DIR)/build/%.json
spectest-interp $< | tee [email protected] \
&& mv -f [email protected] $@
$(TEST_COMPILER_DIR)/build/%.json : $(TEST_COMPILER_DIR)/build/%.wast
wast2json $< -o $@
$(TEST_COMPILER_DIR)/build/%.wast : $(TEST_COMPILER_DIR)/build/%.wat $(TEST_COMPILER_DIR)/%.wast
cat $^ > $@
$(TEST_COMPILER_DIR)/build/%.wat : $(TEST_COMPILER_DIR)/%.scm $(COMPILED_COMPILER) $(TEST_COMPILER_DIR)/build
$(RUN_DRIVER) < $< > $@
.PRECIOUS : $(TEST_COMPILER_DIR)/build/%.json $(TEST_COMPILER_DIR)/build/%.wast $(TEST_COMPILER_DIR)/build/%.wat
TEST_UNIT_DIR := test-unit
UNIT_TEST_LIBS = lib/assert
UNIT_TEST_PROGRAMS = $(wildcard $(TEST_UNIT_DIR)/*.sps)
UNIT_TEST_LOGS = $(patsubst $(TEST_UNIT_DIR)/%.sps,$(TEST_UNIT_DIR)/log/%.log,$(UNIT_TEST_PROGRAMS))
.PHONY : test-unit-dirs test-unit
test-unit : test-unit-dirs $(UNIT_TEST_LOGS)
test-unit-dirs : $(TEST_UNIT_DIR)/log
$(TEST_UNIT_DIR)/log :
mkdir -p $@
$(UNIT_TEST_LOGS) : $(TEST_UNIT_DIR)/log/%.log : $(TEST_UNIT_DIR)/%.sps $(LIBDIRS) $(UNIT_TEST_LIBS)
$(SCHEME_RUN_PROGRAM) $< > [email protected] \
&& mv -f [email protected] $@
.PHONY : test
test : test-unit test-compiler
.PHONY : cleanall
cleanall : cleantest cleancompiler cleanlibs
.PHONY : cleancompiler
cleancompiler :
-rm -rf $(COMPILED_COMPILER)
.PHONY : cleanlibs
cleanlibs :
-rm -rf $(LIBDIRS)
.PHONY : cleantest
cleantest :
-rm -rf $(TEST_UNIT_DIR)/log $(TEST_COMPILER_DIR)/build $(TEST_COMPILER_DIR)/log $(UNIT_TEST_LIBS)