forked from woodrush/lambda-8cc
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
332 lines (249 loc) · 10.1 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
LAMBDA8CC=lambda-8cc.lam
LAMBDA8CCZIP=out/lambda-8cc.lam
LAMBDA8CCLAZY=lambda-8cc.lazy
# Binary lambda calculus interpreter
UNIPP=./bin/uni++
# Tools
ASC2BIN=./bin/asc2bin
LAM2BIN=./bin/lam2bin
# Toolkit
LAMBDATOOLS=./build/lambda-calculus-devkit
# ELVM
8CC=./bin/8cc
ELC=./bin/elc
8CCLAM=./build/8cc.lam
ELCLAM=./build/elc.lam
# Other
SBCL=sbcl
LAZYK=./bin/lazyk
BLCAIT=./bin/blc-ait
BCL2SKI=./bin/bcl2ski
LATEX=latex
DVIPDFMX=dvipdfmx
target_latex=out/lambda-8cc.tex
target_pdf=lambda-8cc.pdf
# Input C file
INPUT=input.c
# lambda-8cc compilation options
OPT_C_TO_LAM ='(\\f.(f (\\x.\\y.x) (\\x.\\y.\\z.\\a.\\b.y) (\\x.x)))'
OPT_C_TO_BLC ='(\\f.(f (\\x.\\y.x) (\\x.\\y.\\z.\\a.\\b.z) (\\x.x)))'
OPT_C_TO_LAZY ='(\\f.(f (\\x.\\y.x) (\\x.\\y.\\z.\\a.\\b.a) (\\x.x)))'
OPT_C_TO_S ='(\\f.(f (\\x.\\y.x) (\\x.\\y.\\z.\\a.\\b.b) (\\x.x)))'
OPT_S_TO_X86 ='(\\f.(f (\\x.\\y.y) (\\x.\\y.\\z.\\a.\\b.x) (\\x.x)))'
OPT_S_TO_LAM ='(\\f.(f (\\x.\\y.y) (\\x.\\y.\\z.\\a.\\b.y) (\\x.x)))'
OPT_S_TO_BLC ='(\\f.(f (\\x.\\y.y) (\\x.\\y.\\z.\\a.\\b.z) (\\x.x)))'
OPT_S_TO_LAZY ='(\\f.(f (\\x.\\y.y) (\\x.\\y.\\z.\\a.\\b.a) (\\x.x)))'
all: a.out
a.s: $(INPUT) $(LAMBDA8CCZIP) $(LAM2BIN) $(ASC2BIN) $(UNIPP)
( ( cat $(LAMBDA8CCZIP); printf $(OPT_C_TO_S) ) | $(LAM2BIN) | $(ASC2BIN); cat $< ) | $(UNIPP) -o > [email protected]
mv [email protected] $@
a.out: a.s $(LAMBDA8CCZIP) $(LAM2BIN) $(ASC2BIN) $(UNIPP)
( ( cat $(LAMBDA8CCZIP); printf $(OPT_S_TO_X86) ) | $(LAM2BIN) | $(ASC2BIN); cat $< ) | $(UNIPP) -o > [email protected]
mv [email protected] $@
chmod 755 $@
a.out-onepass: $(INPUT) $(LAMBDA8CCZIP) $(LAM2BIN) $(ASC2BIN) $(UNIPP)
( cat $(LAMBDA8CCZIP) | $(LAM2BIN) | $(ASC2BIN); cat $< ) | $(UNIPP) -o > a.out
chmod 755 a.out
$(INPUT): examples/hello.c
cp examples/hello.c $@
tools: $(LAM2BIN) $(ASC2BIN) $(UNIPP)
test: test-compile
pdf: $(target_pdf)
build: $(LAMBDA8CC)
#================================================================
# Build the PDF
#================================================================
.PRECIOUS: $(target_latex)
$(target_latex):./src/lambda-8cc.cl ./tools/main.tex ./tools/make-latex.sh
mkdir -p ./out
./tools/make-latex.sh
mv lambda-8cc.tex out
.PHONY: pdf
$(target_pdf): $(target_latex) $(LAMBDA8CC)
cp ./tools/main.tex out
cd out; $(LATEX) main.tex
cd out; $(DVIPDFMX) main.dvi -o $@
mv out/$@ .
#================================================================
# Other output languages
#================================================================
a.lam: a.s $(LAMBDA8CC) $(LAM2BIN) $(ASC2BIN) $(UNIPP)
( ( cat $(LAMBDA8CC); printf $(OPT_S_TO_LAM) ) | $(LAM2BIN) | $(ASC2BIN); cat $< ) | $(UNIPP) -o > [email protected]
mv [email protected] $@
a.blc: a.s $(LAMBDA8CC) $(LAM2BIN) $(ASC2BIN) $(UNIPP)
( ( cat $(LAMBDA8CC); printf $(OPT_S_TO_BLC) ) | $(LAM2BIN) | $(ASC2BIN); cat $< ) | $(UNIPP) -o > [email protected]
mv [email protected] $@
a.lazy: a.s $(LAMBDA8CC) $(LAM2BIN) $(ASC2BIN) $(UNIPP)
( ( cat $(LAMBDA8CC); printf $(OPT_S_TO_LAZY) ) | $(LAM2BIN) | $(ASC2BIN); cat $< ) | $(UNIPP) -o > [email protected]
mv [email protected] $@
lam-onepass: $(INPUT) $(LAMBDA8CC) $(LAM2BIN) $(ASC2BIN) $(UNIPP)
( ( cat $(LAMBDA8CC); printf $(OPT_C_TO_LAM) ) | $(LAM2BIN) | $(ASC2BIN); cat $< ) | $(UNIPP) -o > a.lam.tmp
mv a.lam.tmp a.lam
blc-onepass: $(INPUT) $(LAMBDA8CC) $(LAM2BIN) $(ASC2BIN) $(UNIPP)
( ( cat $(LAMBDA8CC); printf $(OPT_C_TO_BLC) ) | $(LAM2BIN) | $(ASC2BIN); cat $< ) | $(UNIPP) -o > a.blc.tmp
mv a.blc.tmp a.blc
lazy-onepass: $(INPUT) $(LAMBDA8CC) $(LAM2BIN) $(ASC2BIN) $(UNIPP)
( ( cat $(LAMBDA8CC); printf $(OPT_C_TO_LAZY) ) | $(LAM2BIN) | $(ASC2BIN); cat $< ) | $(UNIPP) -o > a.lazy.tmp
mv a.lazy.tmp a.lazy
run-a.lam: $(LAM2BIN) $(ASC2BIN) $(UNIPP)
cat a.lam | $(LAM2BIN) | $(ASC2BIN) | $(UNIPP) -o
run-a.blc: $(ASC2BIN) $(UNIPP)
cat a.blc | $(ASC2BIN) | $(UNIPP) -o
run-a.lazy: $(LAZYK)
$(LAZYK) -u a.lazy
#================================================================
# Compilation test
#================================================================
out/test.c:
printf 'int main(void){return 0;}' > $@
out/test.s: out/test.c $(LAMBDA8CC) $(LAM2BIN) $(ASC2BIN) $(UNIPP)
mkdir -p out
( ( cat $(LAMBDA8CC); printf $(OPT_C_TO_S) ) | $(LAM2BIN) | $(ASC2BIN); cat $< ) | $(UNIPP) -o > [email protected]
mv [email protected] $@
out/test.bin: out/test.s $(LAMBDA8CC) $(LAM2BIN) $(ASC2BIN) $(UNIPP)
( ( cat $(LAMBDA8CC); printf $(OPT_S_TO_X86) ) | $(LAM2BIN) | $(ASC2BIN); cat $< ) | $(UNIPP) -o > [email protected]
mv [email protected] $@
out/test-8cc.s: out/test.c $(8CC)
$(8CC) -S -o $@ $<
out/test-8cc.bin: out/test-8cc.s $(ELC)
$(ELC) -x86 $< > $@
test-compile: out/test.bin out/test-8cc.bin
diff $^ || exit 1
echo "test-compile passed."
#================================================================
# Self-hosting test
#================================================================
out/8cc-self.s: build/8cc.c $(LAMBDA8CC) $(LAM2BIN) $(ASC2BIN) $(UNIPP)
( ( cat $(LAMBDA8CC); printf $(OPT_C_TO_S) ) | $(LAM2BIN) | $(ASC2BIN); cat $< ) | $(UNIPP) -o > [email protected]
mv [email protected] $@
out/elc-self.s: build/elc.c $(LAMBDA8CC) $(LAM2BIN) $(ASC2BIN) $(UNIPP)
( ( cat $(LAMBDA8CC); printf $(OPT_C_TO_S) ) | $(LAM2BIN) | $(ASC2BIN); cat $< ) | $(UNIPP) -o > [email protected]
mv [email protected] $@
out/8cc-self.lam: out/8cc-self.s $(LAMBDA8CC) $(LAM2BIN) $(ASC2BIN) $(UNIPP)
( ( cat $(LAMBDA8CC); printf $(OPT_S_TO_LAM) ) | $(LAM2BIN) | $(ASC2BIN); cat $< ) | $(UNIPP) -o > [email protected]
mv [email protected] $@
out/elc-self.lam: out/elc-self.s $(LAMBDA8CC) $(LAM2BIN) $(ASC2BIN) $(UNIPP)
( ( cat $(LAMBDA8CC); printf $(OPT_S_TO_LAM) ) | $(LAM2BIN) | $(ASC2BIN); cat $< ) | $(UNIPP) -o > [email protected]
mv [email protected] $@
out/lambda-8cc-self.lam: out/lambda-8cc-main.lam out/8cc-self.lam out/elc-self.lam
( printf '('; cat $^; printf ')'; ) > $@
test-self-host: out/lambda-8cc-self.lam build/8cc.eir build/elc.eir $(8CCLAM) $(ELCLAM)
diff out/8cc-self.s build/8cc.eir || exit 1
diff out/elc-self.s build/elc.eir || exit 1
diff out/8cc-self.lam $(8CCLAM) || exit 1
diff out/elc-self.lam $(ELCLAM) || exit 1
diff out/lambda-8cc-self.lam $(LAMBDA8CC) || exit 1
#================================================================
# Test for building build/lambda-8cc-main.lam using LambdaLisp
#================================================================
build/lambdalisp/bin/lambdalisp.blc:
mkdir -p build
cd build; git clone https://github.com/woodrush/lambdalisp
out/lambda-8cc-main-src.cl: src/lambdacraft.cl src/blc-numbers.cl src/usage.cl src/lambda-8cc.cl
cat $^ > $@
out/lambda-8cc-main-lambdaisp.lam: out/lambda-8cc-main-src.cl build/lambdalisp/bin/lambdalisp.blc $(ASC2BIN) $(UNIPP)
( cat build/lambdalisp/bin/lambdalisp.blc | $(ASC2BIN); cat $< ) | $(UNIPP) -o > [email protected]
cat [email protected] | sed -e '1s/> //' > $@
test-lambda-8cc-main-lambdaisp: out/lambda-8cc-main-lambdaisp.lam build/lambda-8cc-main.lam
diff $^ || exit 1
#================================================================
# Build lambda-8cc.lam
#================================================================
src/usage.cl: src/usage.txt src/compile-usage.sh
cd src; ./compile-usage.sh > usage.cl.tmp
mv src/usage.cl.tmp $@
build/lambda-8cc-main.lam: src/usage.cl $(wildcard src/*.cl)
mkdir -p build
cd src; $(SBCL) --script lambda-8cc.cl > ../[email protected]
mv [email protected] $@
$(LAMBDA8CC): build/lambda-8cc-main.lam $(8CCLAM) $(ELCLAM)
( printf '('; cat $^; printf ')'; ) > $@
out/lambda-8cc.blc: $(LAMBDA8CC) $(LAM2BIN)
cat $(LAMBDA8CC) | $(LAM2BIN) > [email protected]
mv [email protected] $@
bin/lambda-8cc.lam.zip: $(LAMBDA8CC)
zip $@ $<
bin/lambda-8cc.blc.zip: out/lambda-8cc.blc
zip $@ $<
$(LAMBDA8CCZIP):
cd out; unzip ../bin/lambda-8cc.lam.zip
#================================================================
# Build lambda-8cc.lazy (WIP)
#================================================================
build/lambda-8cc-lazy.cl: src/usage.cl $(wildcard src/*.cl)
mkdir -p build
( echo '(defparameter compile-lazyk t)'; cat src/lambda-8cc.cl ) > build/lambda-8cc-lazy.cl
build/lambda-8cc-main.lazy: build/lambda-8cc-lazy.cl $(BLCAIT) $(BCL2SKI)
cd src; $(SBCL) --script ../build/lambda-8cc-lazy.cl > ../build/lambda-8cc-main-lazy.lam
$(BLCAIT) bcl build/lambda-8cc-main-lazy.lam | $(BCL2SKI) > [email protected]
mv [email protected] $@
$(8CCLAM).lazy: build/8cc.eir $(ELC)
$(ELC) -lazy $< > $@
$(ELCLAM).lazy: build/elc.eir $(ELC)
$(ELC) -lazy $< > $@
$(LAMBDA8CCLAZY): build/lambda-8cc-main.lazy $(8CCLAM).lazy $(ELCLAM).lazy
( printf '``'; cat $^; ) > $@
#================================================================
# Build 8cc.lam and elc.lam
#================================================================
elvm/Makefile:
git submodule update --init --remote
.PHONY: 8cc
8cc: $(8CC)
$(8CC): elvm/Makefile
cd elvm && make out/8cc && cp out/8cc ../bin
.PHONY: elc
elc: $(ELC)
$(ELC): elvm/Makefile
cd elvm && make out/elc && cp out/elc ../bin
build/8cc.c: elvm/Makefile
mkdir -p out
cd elvm && make out/8cc.c && tools/merge_c.rb out/8cc.c > ../build/8cc.c
build/elc.c: elvm/Makefile
mkdir -p out
cd elvm && make out/elc.c && tools/merge_c.rb out/elc.c > ../build/elc.c
build/8cc.eir: build/8cc.c $(8CC)
$(8CC) -S -o $@ $<
build/elc.eir: build/elc.c $(8CC)
$(8CC) -S -o $@ $<
$(8CCLAM): build/8cc.eir $(ELC)
$(ELC) -lam $< > $@
$(ELCLAM): build/elc.eir $(ELC)
$(ELC) -lam $< > $@
#================================================================
# Build the lambda calculus interpreters and tools
#================================================================
$(LAMBDATOOLS):
mkdir -p build
cd build; git clone https://github.com/woodrush/lambda-calculus-devkit
.PHONY: uni++
uni++: $(UNIPP)
$(UNIPP): $(LAMBDATOOLS)
mkdir -p bin
cd $(LAMBDATOOLS) && make uni++ && mv bin/uni++ ../../bin
.PHONY: asc2bin
asc2bin: $(ASC2BIN)
$(ASC2BIN): $(LAMBDATOOLS)
mkdir -p bin
cd $(LAMBDATOOLS) && make asc2bin && mv bin/asc2bin ../../bin
.PHONY: lam2bin
lam2bin: $(LAM2BIN)
$(LAM2BIN): $(LAMBDATOOLS)
mkdir -p bin
cd $(LAMBDATOOLS) && make lam2bin && mv bin/lam2bin ../../bin
.PHONY: lazyk
lazyk: $(LAZYK)
$(LAZYK): $(LAMBDATOOLS)
mkdir -p bin
cd $(LAMBDATOOLS) && make lazyk && mv bin/lazyk ../../bin
.PHONY: blc-ait
blc-ait: $(BLCAIT)
$(BLCAIT): $(LAMBDATOOLS)
mkdir -p bin
cd $(LAMBDATOOLS) && make blc-ait && mv bin/blc-ait ../../bin
.PHONY: bcl2ski
bcl2ski: $(BCL2SKI)
$(BCL2SKI): $(LAMBDATOOLS)
mkdir -p bin
cd $(LAMBDATOOLS) && make bcl2ski && mv bin/bcl2ski ../../bin