This repository has been archived by the owner on Sep 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathmkfile
432 lines (333 loc) · 11.6 KB
/
mkfile
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
##############################################################################
#
# Quick C-- Interpreter
#
# This mkfile is used to build qc--interp, the Quick C-- Interpreter.
#
# IMPORTANT BUILD TARGETS ::
#
# all : builds qc--interp
# update : builds qc--interp and copies binary to $BINDIR
# depend : updates dependencies for proper compilation
# gc : builds experimental garb. collecting interp client gc_client
# exn : builds experimental exn. dispatching interp client exn_client
# clean : cleans object files (*.o)
# clobber : cleans all binaries, object files, and source code that can
# be regenerated from .NW files
#
# IMPORTANT DOCUMENTATION TARGETS ::
#
# doc.dvi : builds main documentation file for entire interpreter;
# includes formalization, module interfaces and implementations
#
# client.dvi : builds DVI doc. of client.nw, the included interp. client
# runtime.dvi : builds DVI doc. of runtime.nw, the C-- runtime system
#
NAME = qc--interp
LIBNAME = lib$NAME.a
VERSION = `date +%Y%m%d`
# ------------------------------------------------------------------
# paths
# ------------------------------------------------------------------
TOP = ..
BINDIR = $TOP/bin
LIBDIR = $TOP/lib
QCC = $TOP/bin/qc--
MODE = user
# change to MODE=developer to turn on Toolkit features
# LCC_INSTALLDIR : directory where lcc binary and liblcc.a are installed
LCC_INSTALLDIR = /usr/local/lcc
# LCC_SRCDIR : directory containing include/ subdirectory with lcc header files
LCC_SRCDIR = /home/nr/lcc/lcc-4.2
# ------------------------------------------------------------------
# main targets
# ------------------------------------------------------------------
INTERP = evaluating
all:V: $NAME $LIBNAME libinclude gc exn prs
all.opt:V: all
update:V: $BINDIR/$NAME $LIBDIR/$LIBNAME libinclude gc exn prs
update.opt:V: update
install:V: all $install_bin $install_lib
cp $NAME $install_bin/$NAME
cp $LIBNAME $install_lib/$LIBNAME
(cd libinclude ; mk $MKFLAGS install)
install.opt:V: install
libinclude:V:
(cd libinclude ; mk all)
test:VQ:
(cd test; mk $MKFLAGS test)
clean:V:
rm -f *.o *.cmm.qs $NAME DEPEND
rm -f *.cmm-x86-linux.c-- *.cmm-sparc-solaris.c--
(cd clients; mk clean)
clean.opt:V: clean
clobber:V: clean
rm -f *.blg *.log *.dvi *.inc *.toc *.aux
rm -f $NWTEXFILES
rm -f prof.out core *~
rm -f $NAME $LIBNAME
rm -f *.m *.i decode.fetch bytecode.sled
rm -f $INTERPHDRS $INTERPSRCS cmmfloat-*.c
rm -f underflowhandler.c-- underflowhandler.qs
rm -f $CLIENTHDRS $CLIENTSRCS
rm -f inspect.lua inspect.clua
rm -f mkfile.bak
rm -f booted-interp booted-interp.opt
(cd clients ; mk clobber)
(cd libinclude ; mk clobber)
# cleani does _not_ remove mclib.o or the CII *.o (which don't change often)
cleani:V:
rm -f $INTERPOBJS client.o
(cd clients ; mk clean)
# ------------------------------------------------------------------
# rules and tools
# ------------------------------------------------------------------
<mkfile.$MODE
<$TOP/config/config.mk
B=""
<$TOP/config/c.mk
<$TOP/config/lua.mk
<$TOP/config/noweb.mk
<$TOP/config/man.mk
LIBS = -lm $LUALIBS
INCLUDES = -I./include -I./include/cii -I. $LUAINCLUDES
CFLAGS = -g -ansi -pedantic -Wall -Wno-long-long $INCLUDES
NOTANGLEOPTS = -L
# ------------------------------------------------------------------
# important file sets
# ------------------------------------------------------------------
NWFILES = `echo *.nw`
INTERPHDRS = activation.h \
assemblyunit.h \
ccall.h \
cmmfloat.h \
controlflow.h \
disasm.h \
encoding.h \
fe_prs.h \
interp.h \
intervals.h \
label.h \
lualink.h \
machine.h \
operator.h \
runtime.h \
span.h \
stack.h \
table.h \
thread.h \
types.h \
uid.h \
underflowhandler.h \
util.h \
value.h
GENHDRS = encode.h
EXTSRCS = arena.c \
assert.c \
atom.c \
except.c \
fmt.c \
mclib.c \
mem.c \
mp.c \
xp.c
INTERPSRCS = activation.c \
assemblyunit.c \
ccall.c \
cmmfloat-$config_float_impl.c \
controlflow.c \
encoding.c \
fe_prs.c \
intervals.c \
label.c \
lualink.c \
operator.c \
runtime.c \
span.c \
stack.c \
table.c \
thread.c \
uid.c \
underflowhandler.c \
util.c \
value.c
GENSRCS = interp-dec.c \
disasm-dec.c \
encode.c
INTERPOBJS = ${INTERPSRCS:%.c=%.o} ${GENSRCS:%.c=%.o}
CORESRCS = $EXTSRCS $INTERPSRCS $GENSRCS
COREHDRS = $INTERPHDRS $GENHDRS
COREOBJS = ${CORESRCS:%.c=%.o}
CLIENTHDRS = client.h
CLIENTSRCS = client.c
CLIENTOBJS = ${CLIENTSRCS:%.c=%.o}
HDRS = $COREHDRS $CLIENTHDRS inspect.clua
SRCS = $CORESRCS $CLIENTSRCS
code:V: $SRCS $HDRS
# ------------------------------------------------------------------
# copy files to their official directories
# ------------------------------------------------------------------
$BINDIR/$NAME: $NAME
cp $prereq $target
$LIBDIR/$LIBNAME: $LIBNAME
cp $prereq $target
# ------------------------------------------------------------------
# binaries
# ------------------------------------------------------------------
interp:V: $NAME
gc:V: clients/gc_client
exn:V: clients/exn_client
prs:V: clients/prs_client
float:V: cmmfloat-$config_float_impl.o
$NAME: $COREOBJS client.o
$CC $CFLAGS -o $target $COREOBJS client.o $LIBS
# $LIBNAME: $COREOBJS $LIBLUA $LIBLUALIB
$LIBNAME: $COREOBJS
clients/%: libinclude $LIBDIR/$LIBNAME
(cd clients ; mk $stem)
### alternately built binaries (for sparc, lcc, etc.)
atac-interp:VQ:
mk interp $MKFLAGS MODE=$MODE NOTANGLEOPTS= CC='atac gcc'
## bootstrapped binary
LCC = $LCC_INSTALLDIR/lcc
LCC_INC = -I$LCC_SRCDIR/include/x86/linux $INCLUDES
LCC_LIBS = -L$LCC_INSTALLDIR -llcc
#### need to capture LCC_ARGS based on config
LCC_COMMON_ARGS = -target=c-- -Wf-c--segLIT=data ${LCC_INC:%=-Wp%}
%.cmm-sparc-solaris.c--:D: %.c
$LCC -S $LCC_COMMON_ARGS -Wf-c--=sparc/solaris -o $target $prereq
%.cmm-x86-linux.c--:D: %.c
$LCC -S $LCC_COMMON_ARGS -Wf-c--=x86/linux -o $target $prereq
BOOTED_CORESRCS = ${CORESRCS:%.c=%.cmm-$config_arch.c--}
BOOTED_CLIENTSRCS = ${CLIENTSRCS:%.c=%.cmm-$config_arch.c--}
BOOTED_COREOBJS = ${BOOTED_CORESRCS:%.c--=%.o}
BOOTEDBC_COREOBJS = ${BOOTED_CORESRCS:%.c--=%.qs}
booted-cmm:V: $BOOTED_CORESRCS $BOOTED_CLIENTSRCS
'^'cmmfloat-(iec60559|solaris|none)'\.c$':RD: cmmfloat.nw
notangle -L -R$target $prereq > $target
%.cmm-$config_arch.o:D: %.cmm-$config_arch.c--
$QCC -c -o $target $prereq
%.cmm-$config_arch.qs:D: %.cmm-$config_arch.c--
$QCC -interp -stop .qs -o $target $prereq
boot:V: booted-interp.opt
booted-interp.opt:D: $QCC $BOOTED_COREOBJS $BOOTED_CLIENTSRCS
$QCC -globals -o $target $BOOTED_COREOBJS $BOOTED_CLIENTSRCS $LCC_LIBS $LIBS
# cannot actually run booted-interp because of missing imports from libraries;
# if actually interested in this, someone could write a version of client.c
# that registers with the interpreter all functions imported from the libraries
# in $LCC_LIBS and $LIBS
#
booted-interp:D: $QCC $BOOTEDBC_COREOBJS $BOOTED_CLIENTSRCS
$QCC -interp -globals -o $target $BOOTEDBC_COREOBJS $BOOTED_CLIENTSRCS
# ------------------------------------------------------------------
# dependency recalculation
# ------------------------------------------------------------------
DEPEND = -MM
depend:V: DEPEND
(cd libinclude; mk depend)
(cd clients; mk depend)
DEPEND:D: DEPEND.raw
sed 's@gc\.o:@clients/gc.o:@;s@exn\.o:@clients/exn.o:@' $prereq > $target
DEPEND.raw:D: $SRCS $HDRS
$CC $DEPEND $INCLUDES $SRCS > $target
# ------------------------------------------------------------------
# documentation-related files
# ------------------------------------------------------------------
NWTEXFILES = ${NWFILES:%.nw=%.tex}
NWINCFILES = ${NWFILES:%.nw=%.inc}
# INTERFACES should be in a sensible order so the print-out makes sense
INTERFACES = cmmfloat.nw \
util.nw \
types.nw \
value.nw \
stack.nw \
lualink.nw \
table.nw \
intervals.nw \
uid.nw \
activation.nw \
controlflow.nw \
label.nw \
thread.nw \
assemblyunit.nw \
encoding.nw \
operator.nw \
ccall.nw \
span.nw \
disasm.nw \
inspect.nw \
runtime.nw \
fe_prs.nw \
interfaces:V: interfaces.dvi
interfaces.tex: interfaces.nw
$NOWEAVE -delay -autodefs c -index $prereq > $target
interfaces.dvi: ${INTERFACES:%.nw=%.inc}
doc.tex: doc.nw
$NOWEAVE -delay -autodefs c -index $prereq > $target
doc.dvi: $NWINCFILES
### some old documentation files
design.tex: design.inc
echo "\input{design.inc}" > $target
state.tex: state.inc
echo "\input{state.inc}" > $target
# ------------------------------------------------------------------
# source code targets
# ------------------------------------------------------------------
bytecode.sled:D: interp.nw
$NOTANGLE $NOTANGLEOPTS -R$target $prereq | $CPIF $target
decode.fetch:D: interp.nw
$NOTANGLE $NOTANGLEOPTS -R$target $prereq | $CPIF $target
machine.h:D: interp.nw
$NOTANGLE $NOTANGLEOPTS -R$target.${MACHINE-x86} $prereq | $CPIF $target
'(([^/]*/)*)(.*)\.h$':RD: '\1\3.nw'
$NOTANGLE $NOTANGLEOPTS -R$stem3.h $prereq | $CPIF $target
#'(([^/]*/)*)(.*)\.c$':RD: '\1\3.nw'
# $NOTANGLE $NOTANGLEOPTS -R$stem3.c $prereq | $CPIF $target
%.m:D: %.nw
$NOTANGLE -R$target $prereq | $CPIF $target
inspect.lua:D: inspect.nw
$NOTANGLE -R$target $prereq > $target
inspect.clua:D: inspect.lua
sed -e 's/\\/\\\\/g' \
-e 's/"/\\"/g' \
-e 's/^/"/' \
-e 's/$/\\n"/' $prereq > $target
# sed -e 's/\\/\\\\/g' \
# -e 's/"/\\"/g' \
# -e 'i \' \
# -e '\"\\' \
# -e 's/$/\\n"/' $prereq > $target
# ------------------------------------------------------------------
# intermediate code targets
# ------------------------------------------------------------------
#
# for development and debugging only
'(([^/]*/)*)(.*)\.i$':RD: '\1\3.c' $HDRS
$CC -P -E $INCLUDES $stem3.c > $target
# ------------------------------------------------------------------
# operator generator targets (experimental, and not currently used)
# ------------------------------------------------------------------
opgen: opgen.icn
icont -o $target $prereq
%.icn:D: %.nw
$NOTANGLE -L'#line %-1L "%F"%N' -R$target $prereq > $target
optest:V: opgen
echo "v1:f32 v2:f32 feq32 -- v1 == v2 : bool" | ./opgen
%-ops.c:D: %.ops opgen
./opgen $stem.ops > $target
# ------------------------------------------------------------------
# underflow handler
# ------------------------------------------------------------------
underflowhandler.c--:D: underflowhandler.nw
notangle -L -R$target $prereq > $target
underflowhandler.qs: underflowhandler.c--
$QCC -interp -S underflowhandler.c--
underflowhandler.c: underflowhandler.qs
echo -n "char* Cmm_underflow_handler=\"" > underflowhandler.c; sed -e 's/$/\\n\\/' -e 's/"/\\"/g' underflowhandler.qs >> underflowhandler.c; echo '";' >> underflowhandler.c
#
# -- end of mkfile --
#
#
# [dependencies]
<DEPEND
<$TOP/config/install.mk