-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMakefile
528 lines (486 loc) · 14.3 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
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
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
ifndef MAKEFILE_MAIN
$(error Use toplevel Makefile, please.)
else
.PHONY: check tests
.PHONY: testing-binaries
.PHONY: testing-embed testing-internal check-ffi
.PHONY: regression-tests
.SILENT: regression-tests
FAILED := $(shell mktemp -u /tmp/failed.XXXXXXXXX)
# win32 tests:
# apt install gcc-mingw-w64-i686 gcc-mingw-w64-x86-64
# note: use 2>/dev/null in "shell command" to avoid
# make call optimization and really run shell.
ifeq ($(shell command -v $(MGCC32) 2>/dev/null),)
HAVE_MINGW32 ?= 0
else
HAVE_MINGW32 ?= 1
endif
ifeq ($(shell command -v $(MGCC64) 2>/dev/null),)
HAVE_MINGW64 ?= 0
else
HAVE_MINGW64 ?= 1
endif
# dpkg --add-architecture i386 && apt-get update
# apt install wine32
# note: if you need to disable com ports under wine, then navigate to
# HKLM\Software\Wine and create a new empty String named 'com33' (or smth)
ifeq ($(shell command -v wine 2>/dev/null),)
HAVE_WINE ?= 0
else
HAVE_WINE ?= 1
endif
# wine is not required under WSL
ifdef WSL_DISTRO_NAME
WINE ?=
else # disable any wine logging
WINE ?= WINEDEBUG=-all wine cmd /c
endif
# notifications:
ok:="$(green) ok $(done)"
fail:="$(red)fail$(done)"
MACHINE ?= $(shell uname -m)
# special case, test 64- and 32-bit both
# (maximal testings under main development platform)
ifeq ($(UNAME)-$(MACHINE),Linux-x86_64)
HAS_64CDEFS ?= $(call exists,-m64,sys/cdefs.h,exit)
ifeq ($(HAS_64CDEFS),1)
DEV_MACHINE ?= 1
endif
# sudo apt-get install gcc-multilib
HAS_32CDEFS ?= $(call exists,-m32,sys/cdefs.h,exit)
ifeq ($(HAS_32CDEFS),1)
DEV_MACHINE ?= 1
endif
else
DEV_MACHINE ?= 0
HAS_64CDEFS ?= 0
HAS_32CDEFS ?= 0
endif
# -------------
# win
define winbuild
$(CC) src/olvm.c -o $1 \
-DHAVE_DLOPEN=1 -DHAS_SOCKES=1 -DOLVM_FFI=1 \
-Iincludes/win32 -Iincludes \
extensions/ffi.c \
-std=gnu99 -fno-exceptions -lws2_32 \
$2
endef
ifeq ($(HAVE_MINGW32),1)
tmp/vm32d.exe: CC=$(MGCC32)
tmp/vm32d.exe: src/olvm.c
$(call winbuild,$@,$(CFLAGS_DEBUG))
tmp/vm32r.exe: CC=$(MGCC32)
tmp/vm32r.exe: src/olvm.c
$(call winbuild,$@,$(CFLAGS_RELEASE))
endif
ifeq ($(HAVE_MINGW64),1)
tmp/vm64d.exe: CC=$(MGCC64)
tmp/vm64d.exe: src/olvm.c
$(call winbuild,$@,$(CFLAGS_DEBUG))
tmp/vm64r.exe: CC=$(MGCC64)
tmp/vm64r.exe: src/olvm.c
$(call winbuild,$@,$(CFLAGS_RELEASE))
endif
# # -=( test )=----------------------------------------
# test32: $(wildcard tests/*.scm)
# @echo "-- test32 ----------"
# @rm -f $(FAILED)
# @$(CC) src/olvm.c $(CFLAGS) tests/vm.c -Iincludes -DOLVM_NOMAIN -o vm32d $(L) -m32
# @./vm32d
# @$(CC) src/olvm.c $(CFLAGS) tests/ffi.c -Iincludes \
# -DOLVM_FFI=1 -Iincludes extensions/ffi.c -o ffi32 $(L) -m32
# @for F in $^ ;do \
# printf "Testing $$F ... " ;\
# if OL_HOME=`pwd`/libraries ./ffi32 repl $$F >/dev/null; then\
# echo "Ok." ;\
# else \
# echo "\033[0;31mFailed!\033[0m" ;\
# touch $(FAILED) ;\
# fi ;\
# done
# @if [ -e $(FAILED) ] ;then rm -f $(FAILED); exit 1 ;fi
# test64: $(wildcard tests/*.scm)
# @echo "-- test64 ----------"
# @rm -f $(FAILED)
# @$(CC) src/olvm.c $(CFLAGS) tests/vm.c -Iincludes -DOLVM_NOMAIN -o vm64d $(L) -m64
# @./vm64d
# @$(CC) src/olvm.c $(CFLAGS) tests/ffi.c -Iincludes \
# -DOLVM_FFI=1 -Iincludes extensions/ffi.c -o ffi64 $(L) -m64
# @for F in $^ ;do \
# printf "Testing $$F ... " ;\
# if OL_HOME=`pwd`/libraries ./ffi64 repl $$F >/dev/null; then\
# echo "Ok." ;\
# else \
# echo "\033[0;31mFailed!\033[0m" ;\
# touch $(FAILED) ;\
# fi ;\
# done
# @if [ -e $(FAILED) ] ;then rm -f $(FAILED); exit 1 ;fi
# test: test64
# @echo "passed!"
# -=( ffi )=----------------------------------------
test-ffi:
$(CC) src/olvm.c $(CFLAGS) tests/ffi.c -Iincludes \
-DOLVM_FFI=1 -Iincludes extensions/ffi.c -o $(ffi)$(affix)$(bits) $(L) \
-fsigned-char # for ffi tests we should use char as signed by default
@printf "Testing $(ffi)$(affix)$(bits) ... "
@if $(ffi)$(affix)$(bits) repl <tests/ffi.scm | diff - tests/ffi.scm.ok >/dev/null; then\
echo $(ok);\
else \
echo $(fail) ;\
touch $(FAILED);\
fi
ffi=tmp/ffi
test-ffi-debug: CFLAGS += $(CFLAGS_DEBUG)
test-ffi-debug: affix=d
test-ffi-debug: test-ffi
test-ffi-release: CFLAGS += $(CFLAGS_RELEASE)
test-ffi-release: affix=r
test-ffi-release: test-ffi
ifeq ($(HAS_32CDEFS),1) # x86_64
test-ffi-debug-32: CFLAGS += -m32
test-ffi-debug-32: bits=32
test-ffi-debug-32: test-ffi-debug
test-ffi-release-32: CFLAGS += -m32
test-ffi-release-32: bits=32
test-ffi-release-32: test-ffi-release
endif
ifeq ($(HAS_64CDEFS),1) # x86_64
test-ffi-debug-64: CFLAGS += -m64
test-ffi-debug-64: bits=64
test-ffi-debug-64: test-ffi-debug
test-ffi-release-64: CFLAGS += -m64
test-ffi-release-64: bits=64
test-ffi-release-64: test-ffi-release
endif
# -=( vmi )=---------------------------------------
test-vmi:
$(CC) src/olvm.c $(CFLAGS) tests/vm.c -Iincludes -DOLVM_NOMAIN -o $(vmi)$(affix)$(bits) $(L)
@echo "$(vmi)$(affix)$(bits):"
@$(vmi)$(affix)$(bits)
vmi=tmp/vmi
test-vmi-debug: CFLAGS += $(CFLAGS_DEBUG)
test-vmi-debug: affix=d
test-vmi-debug: test-vmi
test-vmi-release: CFLAGS += $(CFLAGS_RELEASE)
test-vmi-release: affix=r
test-vmi-release: test-vmi
ifeq ($(HAS_32CDEFS),1) # x86_64
test-vmi-debug-32: CFLAGS += -m32
test-vmi-debug-32: bits=32
test-vmi-debug-32: test-vmi-debug
test-vmi-release-32: CFLAGS += -m32
test-vmi-release-32: bits=32
test-vmi-release-32: test-vmi-release
endif
ifeq ($(HAS_64CDEFS),1) # x86_64
test-vmi-debug-64: CFLAGS += -m64
test-vmi-debug-64: bits=64
test-vmi-debug-64: test-vmi-debug
test-vmi-release-64: CFLAGS += -m64
test-vmi-release-64: bits=64
test-vmi-release-64: test-vmi-release
endif
# -=( vm )=----------------------------------------
# binaries
vm-debug:
$(CC) src/olvm.c $(CFLAGS) \
-DOLVM_FFI=1 -Iincludes extensions/ffi.c -o $(vm)d$(bits) $(L) $(CFLAGS_DEBUG)
vm-release:
$(CC) src/olvm.c $(CFLAGS) \
-DOLVM_FFI=1 -Iincludes extensions/ffi.c -o $(vm)r$(bits) $(L) $(CFLAGS_RELEASE)
vm=tmp/vm
# vm-debug: CFLAGS += $(CFLAGS_DEBUG)
# vm-debug: affix=d
# vm-debug: vm-debug
# vm-release: CFLAGS += $(CFLAGS_RELEASE)
# vm-release: affix=r
# vm-release: vm-release
ifeq ($(HAS_32CDEFS),1) # x86_64
vm-debug-32: CFLAGS += -m32
vm-debug-32: bits=32
vm-debug-32: vm-debug
vm-release-32: CFLAGS += -m32
vm-release-32: bits=32
vm-release-32: vm-release
endif
ifeq ($(HAS_64CDEFS),1) # x86_64
vm-debug-64: CFLAGS += -m64
vm-debug-64: bits=64
vm-debug-64: vm-debug
vm-release-64: CFLAGS += -m64
vm-release-64: bits=64
vm-release-64: vm-release
endif
# -- binaries ---------------------
testing-binaries: includes/ol/vm.h
@printf "Building test binaries:"
ifeq ($(DEV_MACHINE),1) # main development platform, special case
@printf "\n"
ifeq ($(HAS_32CDEFS),1)
@printf " linux 32-bit debug and release versions... "
$(MAKE) vm-debug-32
$(MAKE) vm-release-32
@echo $(ok)
endif
ifeq ($(HAS_64CDEFS),1)
@printf " linux 64-bit debug and release versions... "
$(MAKE) vm-debug-64
$(MAKE) vm-release-64
@echo $(ok)
endif
ifeq ($(HAVE_MINGW32),1)
@printf " mingw 32-bit debug and release versions... "
$(MAKE) $(vm)32d.exe
$(MAKE) $(vm)32r.exe
@echo $(ok)
endif
ifeq ($(HAVE_MINGW64),1)
@printf " mingw 64-bit debug and release versions... "
$(MAKE) $(vm)64d.exe
$(MAKE) $(vm)64r.exe
@echo $(ok)
endif
else # regular case
@printf " (debug and release versions both)... "
$(MAKE) vm-debug
$(MAKE) vm-release
endif
@echo "built."
@printf "\n"
# -- embed --------------------------------------------------------
testing-embed: tests/embed.c src/olvm.c includes/ol/ol.h tmp/repl.c
@echo "embed testing"
@echo "----------------------------------------"
@echo "tests/embed.c"
ifeq ($(DEV_MACHINE),1) # main development platform, special case
ifeq ($(HAS_32CDEFS),1)
@echo " debug-32:"
$(CC) tests/embed.c src/olvm.c tmp/repl.c $(CFLAGS) $(L) -DOLVM_NOMAIN \
-DOLVM_FFI=1 extensions/ffi.c -o tmp/embed32d \
-Iincludes -lm $(CFLAGS_DEBUG) -m32 -Wno-unused-function
@if tmp/embed32d >/dev/null; then\
echo $(ok) ;\
else \
echo $(fail) ;\
touch $(FAILED) ;\
fi
@echo " release-32:"
$(CC) tests/embed.c src/olvm.c tmp/repl.c $(CFLAGS) $(L) -DOLVM_NOMAIN \
-DOLVM_FFI=1 extensions/ffi.c -o tmp/embed32r \
-Iincludes -lm $(CFLAGS_RELEASE) -m32 -Wno-unused-function
@if tmp/embed32r >/dev/null; then\
echo $(ok) ;\
else \
echo $(fail) ;\
touch $(FAILED) ;\
fi
endif
ifeq ($(HAS_64CDEFS),1)
@echo " debug-64:"
$(CC) tests/embed.c src/olvm.c tmp/repl.c $(CFLAGS) $(L) -DOLVM_NOMAIN \
-DOLVM_FFI=1 extensions/ffi.c -o tmp/embed64d \
-Iincludes -lm $(CFLAGS_DEBUG) -m64 -Wno-unused-function
@if tmp/embed64d >/dev/null; then\
echo $(ok) ;\
else \
echo $(fail) ;\
touch $(FAILED) ;\
fi
@echo " release-64:"
$(CC) tests/embed.c src/olvm.c tmp/repl.c $(CFLAGS) $(L) -DOLVM_NOMAIN \
-DOLVM_FFI=1 extensions/ffi.c -o tmp/embed64r \
-Iincludes -lm $(CFLAGS_RELEASE) -m64 -Wno-unused-function
@if tmp/embed64r >/dev/null; then\
echo $(ok) ;\
else \
echo $(fail) ;\
touch $(FAILED) ;\
fi
endif
else # regular case
@echo " debug:"
$(CC) tests/embed.c src/olvm.c tmp/repl.c $(CFLAGS) $(L) -DOLVM_NOMAIN \
-DOLVM_FFI=1 extensions/ffi.c -o tmp/embedd \
-Iincludes -lm $(CFLAGS_DEBUG) -Wno-unused-function
@if tmp/embedd >/dev/null; then\
echo $(ok) ;\
else \
echo $(fail) ;\
touch $(FAILED) ;\
fi
@echo " release:"
$(CC) tests/embed.c src/olvm.c tmp/repl.c $(CFLAGS) $(L) -DOLVM_NOMAIN \
-DOLVM_FFI=1 extensions/ffi.c -o tmp/embedr \
-Iincludes -lm $(CFLAGS_RELEASE) -Wno-unused-function
@if tmp/embedr >/dev/null; then\
echo $(ok) ;\
else \
echo $(fail) ;\
touch $(FAILED) ;\
fi
endif
@echo "."
# -- internal -------------------------------------
testing-internal:
@echo "Internal vm testing"
@echo "----------------------------------------"
ifeq ($(DEV_MACHINE),1) # main development platform, special case
ifeq ($(HAS_32CDEFS),1)
$(MAKE) test-vmi-debug-32
$(MAKE) test-vmi-release-32
endif
ifeq ($(HAS_64CDEFS),1)
$(MAKE) test-vmi-debug-64
$(MAKE) test-vmi-release-64
endif
else # regular case
$(MAKE) test-vmi-debug
$(MAKE) test-vmi-release
endif
@echo " "
# -- ffi ------------------------------------------
check-ffi:
@echo "ffi testing"
@echo "----------------------------------------"
ifeq ($(DEV_MACHINE),1) # main development platform, special case
ifeq ($(HAS_32CDEFS),1)
$(MAKE) test-ffi-debug-32
$(MAKE) test-ffi-release-32
endif
ifeq ($(HAS_64CDEFS),1)
$(MAKE) test-ffi-debug-64
$(MAKE) test-ffi-release-64
endif
else # regular case
$(MAKE) test-ffi-debug
$(MAKE) test-ffi-release
endif
@echo " "
# -- scm ------------------------------------------
define scmtestok
@if ([ -f $1 ]); then\
if ([ -f $^.in ] && $3 $1 repl --home=libraries $^ <$^.in 2>&1 || $3 $1 repl --home=libraries $^ 2>&1) | diff $4 - $^.ok >/dev/null; then\
printf \|$(ok) ;\
else \
printf \|$(fail);\
touch $(FAILED);\
fi;\
fi
endef
%.scm.ok: %.scm
ifeq ($(DEV_MACHINE),1) # main development platform, special case
ifeq ($(HAS_32CDEFS),1)
$(call scmtestok,$(vm)d32,debug-32)
$(call scmtestok,$(vm)r32,release-32)
endif
ifeq ($(HAS_64CDEFS),1)
$(call scmtestok,$(vm)d64,debug-64)
$(call scmtestok,$(vm)r64,release-64)
endif
ifeq ($(HAVE_MINGW32)$(HAVE_WINE),11)
$(call scmtestok,$(vm)32d.exe,win-debug-32,$(WINE),--strip-trailing-cr)
$(call scmtestok,$(vm)32r.exe,win-release-32,$(WINE),--strip-trailing-cr)
endif
ifeq ($(HAVE_MINGW64)$(HAVE_WINE),11)
$(call scmtestok,$(vm)64d.exe,win-debug-64,$(WINE),--strip-trailing-cr)
$(call scmtestok,$(vm)64r.exe,win-release-64,$(WINE),--strip-trailing-cr)
endif
else # default case
$(call scmtestok,$(vm)d,debug)
$(call scmtestok,$(vm)r,release)
endif
@printf "|\n"
# -- bin ------------------------------------------
define bintestok
@if ([ -f $1 ]); then\
if ([ -f $^.in ] && $3 $1 $^ --home=libraries <$^.in || $3 $1 $^ --home=libraries) | diff $4 - $^.ok >/dev/null; then\
printf \|$(ok) ;\
else \
printf \|$(fail);\
touch $(FAILED);\
fi;\
fi
endef
%.bin.ok: %.bin
ifeq ($(DEV_MACHINE),1) # main development platform, special case
ifeq ($(HAS_32CDEFS),1)
$(call bintestok,$(vm)d32,debug-32)
$(call bintestok,$(vm)r32,release-32)
endif
ifeq ($(HAS_64CDEFS),1)
$(call bintestok,$(vm)d64,debug-64)
$(call bintestok,$(vm)r64,release-64)
endif
ifeq ($(HAVE_MINGW32)$(HAVE_WINE),11)
$(call bintestok,$(vm)32d.exe,win-debug-32,$(WINE),--strip-trailing-cr)
$(call bintestok,$(vm)32r.exe,win-release-32,$(WINE),--strip-trailing-cr)
endif
ifeq ($(HAVE_MINGW64)$(HAVE_WINE),11)
$(call bintestok,$(vm)64d.exe,win-debug-64,$(WINE),--strip-trailing-cr)
$(call bintestok,$(vm)64r.exe,win-release-64,$(WINE),--strip-trailing-cr)
endif
else # default case
$(call bintestok,$(vm)d,debug)
$(call bintestok,$(vm)r,release)
endif
@printf "|\n"
# -------------------------------------------------
# -=( tests )=-------------------------------------
check: tests
tests: testing-binaries
@rm -f $(FAILED)
$(MAKE) testing-internal
$(MAKE) check-ffi
$(MAKE) testing-embed
$(MAKE) regression-tests
define table-header
set -e
: header line 1
printf "%-$1s " " Test"
if [ "$(DEV_MACHINE)" = "1" ]; \
then \
: main development platform, special case;\
case "`expr $(HAS_32CDEFS) + $(HAS_64CDEFS) `" in \
1) printf "| Linux ";;\
2) printf "| Linux ";;\
esac ;\
case "`expr \( $(HAVE_MINGW32) + $(HAVE_MINGW64) \) \* $(HAVE_WINE)`" in \
1) printf "| Windows ";;\
2) printf "| Windows ";;\
esac ;\
else \
: regular platform ;\
printf "| %-7s " `uname` ;\
fi
printf "|\n"
: header line 1
printf "%-$1s " `uname`
if [ "$(DEV_MACHINE)" = "1" ]; \
then \
: main development platform, special case;\
if [ "$(HAS_32CDEFS)" = "1" ]; then printf "|32-d|32-r"; fi ;\
if [ "$(HAS_64CDEFS)" = "1" ]; then printf "|64-d|64-r"; fi ;\
if [ "$(HAVE_MINGW32)$(HAVE_WINE)" = "11" ]; then printf "|32-d|32-r"; fi ;\
if [ "$(HAVE_MINGW64)$(HAVE_WINE)" = "11" ]; then printf "|64-d|64-r"; fi ;\
else \
: regular platform ;\
printf "|dbg.|rel." ;\
fi
printf "|\n"
endef
regression-tests: $(filter-out tests/ffi.scm, $(wildcard tests/*.scm)) $(wildcard tests/*.bin)
echo " "
echo "regression tests"
echo "----------------"
$(eval F1LEN=$(shell for F in $^; do echo $${#F}; done |sort -n| tail -1))
$(call table-header, $(F1LEN))
for F in $^; do \
printf "%-$(F1LEN)s " "$$F" ;\
$(MAKE) -s -B $$F.ok ;\
done
if [ -e $(FAILED) ] ;then rm -f $(FAILED); exit 1 ;fi
echo "$(green)passed!$(done)"
endif