-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Makefile
348 lines (302 loc) · 13.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
# Cyclone Scheme
# Copyright (c) 2014-2020, Justin Ethier
# All rights reserved.
include Makefile.config
# Commands
#
# Set up Cyclone here to build the compiler itself using a system-installed
# compiler (EG: from bootstrap or an earlier cyclone version). Everything
# else can then be built using our local binary.
CYCLONE_SYSTEM = cyclone -I . -CLNK '-L.'
CYCLONE_LOCAL = ./cyclone -I . -I libs -COPT '-Iinclude' -CLNK '-L.'
CCOMP = $(CC) $(CFLAGS)
FORMAT_CMD = indent -linux -l80 -i2 -nut
# Libraries
CYC_RT_LIB = libcyclone.a
CYC_BN_LIB = libcyclonebn.a
CYC_BN_LIB_SUBDIR = third-party/libtommath-1.2.0
CYC_LIBS = $(CYC_RT_LIB) $(CYC_BN_LIB)
# Directories
BOOTSTRAP_DIR = ../cyclone-bootstrap
SCHEME_DIR = scheme
EXAMPLE_DIR = examples
HEADER_DIR = include/cyclone
TEST_DIR = tests
# Source files
SLDFILES = $(wildcard $(SCHEME_DIR)/*.sld) \
$(wildcard srfi/*.sld) \
$(wildcard libs/cyclone/*.sld) \
$(wildcard $(SCHEME_DIR)/cyclone/*.sld)
COBJECTS = $(SLDFILES:.sld=.o)
HEADERS = $(HEADER_DIR)/runtime.h $(HEADER_DIR)/types.h
TEST_SRC = $(TEST_DIR)/unit-tests.scm \
$(TEST_DIR)/base.scm \
$(TEST_DIR)/test.scm \
$(TEST_DIR)/threading.scm \
$(TEST_DIR)/c-compiler-options.scm \
$(TEST_DIR)/test-shared-queue.scm \
$(TEST_DIR)/macro-hygiene.scm \
$(TEST_DIR)/match-tests.scm \
$(TEST_DIR)/srfi-28-tests.scm \
$(TEST_DIR)/srfi-60-tests.scm \
$(TEST_DIR)/srfi-121-tests.scm \
$(TEST_DIR)/srfi-128-162-tests.scm \
$(TEST_DIR)/srfi-143-tests.scm
TESTS = $(basename $(TEST_SRC))
# Primary rules (of interest to an end user)
all : cyclone icyc libs
test : libs $(TESTS)
icyc -p "(cond-expand (linux (begin (define-syntax foo (syntax-rules () ((foo) 123))) (foo))))"
example :
cd $(EXAMPLE_DIR) ; $(MAKE)
cd $(EXAMPLE_DIR)/call-scm-from-c ; $(MAKE)
clean :
rm -rf test.txt a.out *.so *.o *.a *.out tags cyclone icyc scheme/*.o scheme/*.so scheme/*.c scheme/*.meta srfi/*.c srfi/*.meta srfi/*.o srfi/*.so scheme/cyclone/*.o scheme/cyclone/*.so scheme/cyclone/*.c scheme/cyclone/*.meta libs/cyclone/*.o libs/cyclone/*.so libs/cyclone/*.c libs/cyclone/*.meta cyclone.c dispatch.c icyc.c generate-c.c generate-c
cd $(EXAMPLE_DIR) ; $(MAKE) clean
rm -rf html tests/*.o tests/*.c
rm -f tests/srfi-28-tests
rm -f tests/srfi-60-tests
rm -f tests/srfi-121-tests
rm -f tests/srfi-143-tests
rm -f tests/macro-hygiene
rm -f tests/match-tests
cd $(CYC_BN_LIB_SUBDIR) ; $(MAKE) clean
install : libs install-libs install-includes install-bin
$(MKDIR) $(DESTDIR)$(DATADIR)
$(MKDIR) $(DESTDIR)$(DATADIR)/scheme/cyclone
$(MKDIR) $(DESTDIR)$(DATADIR)/cyclone
$(MKDIR) $(DESTDIR)$(DATADIR)/srfi
$(MKDIR) $(DESTDIR)$(DATADIR)/srfi/list-queues
$(MKDIR) $(DESTDIR)$(DATADIR)/srfi/sets
$(MKDIR) $(DESTDIR)$(DATADIR)/srfi/sorting
$(INSTALL) -m0644 scheme/*.sld $(DESTDIR)$(DATADIR)/scheme
$(INSTALL) -m0644 scheme/*.o $(DESTDIR)$(DATADIR)/scheme
$(INSTALL) -m0755 scheme/*.so $(DESTDIR)$(DATADIR)/scheme
$(INSTALL) -m0644 scheme/cyclone/*.sld $(DESTDIR)$(DATADIR)/scheme/cyclone
$(INSTALL) -m0644 scheme/cyclone/*.scm $(DESTDIR)$(DATADIR)/scheme/cyclone
$(INSTALL) -m0644 libs/cyclone/test.meta $(DESTDIR)$(DATADIR)/cyclone
$(INSTALL) -m0644 libs/cyclone/match.meta $(DESTDIR)$(DATADIR)/cyclone
$(INSTALL) -m0644 libs/cyclone/foreign.meta $(DESTDIR)$(DATADIR)/cyclone
$(INSTALL) -m0644 scheme/cyclone/*.o $(DESTDIR)$(DATADIR)/scheme/cyclone
$(INSTALL) -m0755 scheme/cyclone/*.so $(DESTDIR)$(DATADIR)/scheme/cyclone
$(INSTALL) -m0644 libs/cyclone/*.sld $(DESTDIR)$(DATADIR)/cyclone
$(INSTALL) -m0644 libs/cyclone/*.scm $(DESTDIR)$(DATADIR)/cyclone
$(INSTALL) -m0644 libs/cyclone/*.o $(DESTDIR)$(DATADIR)/cyclone
$(INSTALL) -m0755 libs/cyclone/*.so $(DESTDIR)$(DATADIR)/cyclone
$(INSTALL) -m0644 srfi/*.sld $(DESTDIR)$(DATADIR)/srfi
$(INSTALL) -m0644 srfi/*.o $(DESTDIR)$(DATADIR)/srfi
$(INSTALL) -m0755 srfi/*.so $(DESTDIR)$(DATADIR)/srfi
$(INSTALL) -m0644 srfi/*.meta $(DESTDIR)$(DATADIR)/srfi
$(INSTALL) -m0644 srfi/list-queues/*.scm $(DESTDIR)$(DATADIR)/srfi/list-queues
$(INSTALL) -m0644 srfi/sets/*.scm $(DESTDIR)$(DATADIR)/srfi/sets
$(INSTALL) -m0644 srfi/sorting/*.scm $(DESTDIR)$(DATADIR)/srfi/sorting
uninstall :
$(RM) $(DESTDIR)$(BINDIR)/cyclone
$(RM) $(DESTDIR)$(BINDIR)/icyc
$(RM) $(DESTDIR)$(LIBDIR)/$(CYC_RT_LIB)
$(RM) $(DESTDIR)$(LIBDIR)/$(CYC_BN_LIB)
$(RM) $(DESTDIR)$(INCDIR)/*.*
$(RMDIR) $(DESTDIR)$(INCDIR)
$(RM) $(DESTDIR)$(DATADIR)/scheme/cyclone/*.*
$(RMDIR) $(DESTDIR)$(DATADIR)/scheme/cyclone
$(RM) $(DESTDIR)$(DATADIR)/cyclone/*.*
$(RMDIR) $(DESTDIR)$(DATADIR)/cyclone
$(RM) $(DESTDIR)$(DATADIR)/srfi/list-queues/*.*
$(RMDIR) $(DESTDIR)$(DATADIR)/srfi/list-queues
$(RM) $(DESTDIR)$(DATADIR)/srfi/sets/*.*
$(RMDIR) $(DESTDIR)$(DATADIR)/srfi/sets
$(RM) $(DESTDIR)$(DATADIR)/srfi/sorting/*.*
$(RMDIR) $(DESTDIR)$(DATADIR)/srfi/sorting
$(RM) $(DESTDIR)$(DATADIR)/srfi/*.*
$(RMDIR) $(DESTDIR)$(DATADIR)/srfi
$(RM) $(DESTDIR)$(DATADIR)/scheme/*.*
$(RMDIR) $(DESTDIR)$(DATADIR)/scheme
$(RMDIR) $(DESTDIR)$(DATADIR)
# Dev rules (of interest to people hacking on Cyclone's core)
tags :
ctags -R *
format : gc.c runtime.c ffi.c hashset.c mstreams.c ck-polyfill.c ck-polyfill.h $(HEADER_DIR)/*.h
$(FORMAT_CMD) $(HEADER_DIR)/*.h
$(FORMAT_CMD) ck-polyfill.c
$(FORMAT_CMD) ck-polyfill.h
$(FORMAT_CMD) ffi.c
$(FORMAT_CMD) gc.c
$(FORMAT_CMD) hashset.c
$(FORMAT_CMD) mstreams.c
$(FORMAT_CMD) runtime.c
test-format :
./scripts/check-c-formatting.sh hashset.c
# This is a test directive used to test changes to a SLD file
# EG: make sld SLDPATH=scheme/cyclone SLD=macros
sld :
cyclone $(SLDPATH)/$(SLD).sld && sudo cp $(SLDPATH)/$(SLD).c /usr/local/share/cyclone/$(SLDPATH)/ && sudo cp $(SLDPATH)/$(SLD).sld /usr/local/share/cyclone/$(SLDPATH)/ && sudo cp $(SLDPATH)/$(SLD).o /usr/local/share/cyclone/$(SLDPATH)/ && cyclone cyclone.scm && cyclone icyc.scm && sudo $(MAKE) install-bin
debug :
sudo ls; cyclone scheme/cyclone/cgen.sld && sudo cp scheme/cyclone/cgen.* /usr/local/share/cyclone/scheme/cyclone/ && cyclone cyclone.scm && sudo $(MAKE) install-includes && sudo $(MAKE) install-libs && ./cyclone generate-c.scm
doc :
doxygen Doxyfile
api-doc :
./scripts/generate-doc-index.sh && mv api-index.scm docs/api/
# Helper rules (of interest to people hacking on this makefile)
.PHONY: clean full bench bootstrap tags format test-format debug test doc api-doc
$(TESTS) : %: %.scm cyclone libs
$(CYCLONE_LOCAL) -I . $<
./$@
rm -rf $@
$(EXAMPLES) : %: %.scm cyclone libs
$(CYCLONE_LOCAL) $<
game-of-life :
cd $(EXAMPLE_DIR)/game-of-life ; $(MAKE)
hello-library/hello :
cd $(EXAMPLE_DIR)/hello-library ; $(MAKE)
libs : $(COBJECTS)
$(COBJECTS) : %.o: %.sld cyclone
$(CYCLONE_LOCAL) $<
cyclone : cyclone.scm $(CYC_RT_LIB) $(CYC_BN_LIB)
$(CYCLONE_SYSTEM) cyclone.scm
icyc : icyc.scm $(CYC_RT_LIB) $(CYC_BN_LIB) cyclone libs
$(CYCLONE_LOCAL) $<
$(CYC_RT_LIB) : $(CFILES) $(HEADERS) $(CYC_BN_LIB)
$(CYC_BN_LIB) : $(CYC_BN_LIB_SUBDIR)/*.c
cd $(CYC_BN_LIB_SUBDIR) ; $(MAKE) LIBNAME=$(CYC_BN_LIB) && cp $(CYC_BN_LIB) ../..
hashset.o : hashset.c $(HEADERS)
$(CCOMP) -c $< -o $@
gc.o : gc.c $(HEADERS)
$(CCOMP) -std=gnu99 -c $< -o $@
ffi.o : ffi.c $(HEADERS)
$(CCOMP) -c $< -o $@
mstreams.o : mstreams.c $(HEADERS)
$(CCOMP) -c \
-DCYC_HAVE_OPEN_MEMSTREAM=$(CYC_PLATFORM_HAS_MEMSTREAM) \
-DCYC_HAVE_FMEMOPEN=$(CYC_PLATFORM_HAS_FMEMOPEN) \
$< -o $@
ifdef CYC_PTHREAD_SET_STACK_SIZE
DEF_PTHREAD_SET_STACK_SIZE=-DCYC_PTHREAD_SET_STACK_SIZE=$(CYC_PTHREAD_SET_STACK_SIZE)
else
DEF_PTHREAD_SET_STACK_SIZE=
endif
runtime.o : runtime.c $(HEADERS)
$(CCOMP) -c \
$(DEF_PTHREAD_SET_STACK_SIZE) \
-DCYC_INSTALL_DIR=\"$(PREFIX)\" \
-DCYC_INSTALL_LIB=\"$(LIBDIR)\" \
-DCYC_INSTALL_BIN=\"$(BINDIR)\" \
-DCYC_INSTALL_INC=\"$(INCDIR)\" \
-DCYC_INSTALL_SLD=\"$(DATADIR)\" \
-DCYC_CC_PROG=\"$(CC_PROG)\" \
-DCYC_CC_EXEC=\"$(CC_EXEC)\" \
-DCYC_CC_LIB=\"$(CC_LIB)\" \
-DCYC_CC_SO=\"$(CC_SO)\" \
-DCYC_PLATFORM=\"$(PLATFORM)\" \
$< -o $@
libcyclone.a : runtime.o gc.o ffi.o mstreams.o hashset.o
$(CREATE_LIBRARY_COMMAND) $(CREATE_LIBRARY_FLAGS) $@ $&
$(RANLIB_COMMAND)
# Instructions from: http://www.adp-gmbh.ch/cpp/gcc/create_lib.html
# Note compiler will have to link to this, eg:
#Linking against static library
#gcc -static main.c -L. -lmean -o statically_linked
#Note: the first three letters (the lib) must not be specified, as well as the suffix (.a)
full :
$(MAKE) clean ; $(MAKE) && $(MAKE) test && $(MAKE) bootstrap && cd ../cyclone-bootstrap && $(MAKE) clean && ./install.sh
bench :
cd ../r7rs-benchmarks && rm results.Cyclone && ./bench cyclone all && grep Elapsed results.Cyclone >out.txt ; grep Elapsed results.Cyclone |wc ; grep -i -e error -e limit -e crash results.Cyclone ; grep Elapsed results.Cyclone | cut -d" " -f 3 ; true
bootstrap : icyc libs
mkdir -p $(BOOTSTRAP_DIR)/libs/cyclone
mkdir -p $(BOOTSTRAP_DIR)/scheme/cyclone
mkdir -p $(BOOTSTRAP_DIR)/srfi
mkdir -p $(BOOTSTRAP_DIR)/$(HEADER_DIR)
cp $(HEADER_DIR)/types.h $(BOOTSTRAP_DIR)/include/cyclone
cp $(HEADER_DIR)/runtime-main.h $(BOOTSTRAP_DIR)/include/cyclone
cp $(HEADER_DIR)/runtime.h $(BOOTSTRAP_DIR)/include/cyclone
cp $(HEADER_DIR)/ck_ht_hash.h $(BOOTSTRAP_DIR)/include/cyclone
cp $(HEADER_DIR)/hashset.h $(BOOTSTRAP_DIR)/include/cyclone
cp $(HEADER_DIR)/bignum.h $(BOOTSTRAP_DIR)/include/cyclone
cp scheme/*.sld $(BOOTSTRAP_DIR)/scheme
cp libs/cyclone/*.sld $(BOOTSTRAP_DIR)/libs/cyclone
cp scheme/cyclone/*.sld $(BOOTSTRAP_DIR)/scheme/cyclone
cp libs/cyclone/*.c $(BOOTSTRAP_DIR)/libs/cyclone
cp srfi/*.sld $(BOOTSTRAP_DIR)/srfi
cp srfi/*.scm $(BOOTSTRAP_DIR)/srfi
cp runtime.c $(BOOTSTRAP_DIR)
cp ffi.c $(BOOTSTRAP_DIR)
cp mstreams.c $(BOOTSTRAP_DIR)
cp hashset.c $(BOOTSTRAP_DIR)
cp gc.c $(BOOTSTRAP_DIR)
cp scheme/base.c $(BOOTSTRAP_DIR)/scheme
cp scheme/case-lambda.c $(BOOTSTRAP_DIR)/scheme
cp scheme/cxr.c $(BOOTSTRAP_DIR)/scheme
cp scheme/read.c $(BOOTSTRAP_DIR)/scheme
cp scheme/write.c $(BOOTSTRAP_DIR)/scheme
cp scheme/char.c $(BOOTSTRAP_DIR)/scheme
cp scheme/complex.c $(BOOTSTRAP_DIR)/scheme
cp scheme/eval.c $(BOOTSTRAP_DIR)/scheme
cp scheme/repl.c $(BOOTSTRAP_DIR)/scheme
cp scheme/file.c $(BOOTSTRAP_DIR)/scheme
cp scheme/inexact.c $(BOOTSTRAP_DIR)/scheme
cp scheme/lazy.c $(BOOTSTRAP_DIR)/scheme
cp scheme/load.c $(BOOTSTRAP_DIR)/scheme
cp scheme/process-context.c $(BOOTSTRAP_DIR)/scheme
cp scheme/time.c $(BOOTSTRAP_DIR)/scheme
cp scheme/cyclone/common.c $(BOOTSTRAP_DIR)/scheme/cyclone
cp icyc.scm $(BOOTSTRAP_DIR)
cp icyc.c $(BOOTSTRAP_DIR)
cp tests/unit-tests.scm $(BOOTSTRAP_DIR)/tests
cp tests/base.scm $(BOOTSTRAP_DIR)/tests
cp tests/threading.scm $(BOOTSTRAP_DIR)/tests
cp scheme/cyclone/ast.c $(BOOTSTRAP_DIR)/scheme/cyclone
cp scheme/cyclone/cps-optimizations.c $(BOOTSTRAP_DIR)/scheme/cyclone
cp scheme/cyclone/cps-opt-local-var-redux.scm $(BOOTSTRAP_DIR)/scheme/cyclone
cp scheme/cyclone/cps-opt-analyze-call-graph.scm $(BOOTSTRAP_DIR)/scheme/cyclone
cp scheme/cyclone/cps-opt-memoize-pure-fncs.scm $(BOOTSTRAP_DIR)/scheme/cyclone
cp scheme/cyclone/pass-validate-syntax.scm $(BOOTSTRAP_DIR)/scheme/cyclone
cp scheme/cyclone/hashset.c $(BOOTSTRAP_DIR)/scheme/cyclone
cp scheme/cyclone/libraries.c $(BOOTSTRAP_DIR)/scheme/cyclone
cp scheme/cyclone/macros.c $(BOOTSTRAP_DIR)/scheme/cyclone
cp libs/cyclone/match.c $(BOOTSTRAP_DIR)/cyclone
cp libs/cyclone/match.meta $(BOOTSTRAP_DIR)/cyclone
cp libs/cyclone/foreign.meta $(BOOTSTRAP_DIR)/cyclone
cp scheme/cyclone/pretty-print.c $(BOOTSTRAP_DIR)/scheme/cyclone
cp scheme/cyclone/primitives.c $(BOOTSTRAP_DIR)/scheme/cyclone
cp scheme/cyclone/transforms.c $(BOOTSTRAP_DIR)/scheme/cyclone
cp scheme/cyclone/cgen.c $(BOOTSTRAP_DIR)/scheme/cyclone
cp scheme/cyclone/util.c $(BOOTSTRAP_DIR)/scheme/cyclone
cp libs/cyclone/test.c $(BOOTSTRAP_DIR)/cyclone
cp libs/cyclone/test.meta $(BOOTSTRAP_DIR)/cyclone
cp libs/cyclone/test.scm $(BOOTSTRAP_DIR)/cyclone
cp srfi/1.c $(BOOTSTRAP_DIR)/srfi
cp srfi/2.c $(BOOTSTRAP_DIR)/srfi
cp srfi/2.meta $(BOOTSTRAP_DIR)/srfi
cp srfi/18.c $(BOOTSTRAP_DIR)/srfi
cp srfi/27.c $(BOOTSTRAP_DIR)/srfi
cp srfi/28.c $(BOOTSTRAP_DIR)/srfi
cp srfi/60.c $(BOOTSTRAP_DIR)/srfi
cp srfi/69.c $(BOOTSTRAP_DIR)/srfi
cp srfi/106.c $(BOOTSTRAP_DIR)/srfi
cp srfi/111.c $(BOOTSTRAP_DIR)/srfi
cp srfi/113.c $(BOOTSTRAP_DIR)/srfi
cp srfi/117.c $(BOOTSTRAP_DIR)/srfi
cp srfi/121.c $(BOOTSTRAP_DIR)/srfi
cp srfi/128.c $(BOOTSTRAP_DIR)/srfi
cp srfi/128.meta $(BOOTSTRAP_DIR)/srfi
cp srfi/132.c $(BOOTSTRAP_DIR)/srfi
cp srfi/133.c $(BOOTSTRAP_DIR)/srfi
cp srfi/143.c $(BOOTSTRAP_DIR)/srfi
cp srfi/list-queues/*.scm $(BOOTSTRAP_DIR)/srfi/list-queues
cp srfi/sets/*.scm $(BOOTSTRAP_DIR)/srfi/sets
cp srfi/sorting/*.scm $(BOOTSTRAP_DIR)/srfi/sorting
cp cyclone.c $(BOOTSTRAP_DIR)/cyclone.c
cp Makefile.config $(BOOTSTRAP_DIR)/Makefile.config
install-includes : $(HEADER_DIR)/*.h
$(MKDIR) $(DESTDIR)$(INCDIR)
$(INSTALL) -m0644 $(HEADER_DIR)/*.h $(DESTDIR)$(INCDIR)/
install-libs : $(CYC_LIBS)
$(MKDIR) $(DESTDIR)$(LIBDIR)
$(INSTALL) -m0644 $(CYC_RT_LIB) $(DESTDIR)$(LIBDIR)/
$(INSTALL) -m0644 $(CYC_BN_LIB) $(DESTDIR)$(LIBDIR)/
install-bin : cyclone icyc
$(MKDIR) $(DESTDIR)$(BINDIR)
$(INSTALL) -m0755 cyclone $(DESTDIR)$(BINDIR)/
$(INSTALL) -m0755 icyc $(DESTDIR)$(BINDIR)/
# TODO: is this linking in local lcyclone or the system one????
test-lib: test-lib.c
$(CCOMP) -g test-lib.c -o test-lib -L . $(LIBS)