-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathGNUmakefile
400 lines (336 loc) · 10.3 KB
/
GNUmakefile
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
export PATH := .:$(PATH)
$(shell mkdir -p config)
export OL_HOME=libraries
# don't spam "Entering/Leaving directory"
MAKEFLAGS += --no-print-directory
# default target
all: release
# detect external features
-include configure.mk
.PHONY: all release debug check slim config recompile install uninstall clean android
.PHONY: describe
describe: all
./vm --version
./ol --version
echo "(print (syscall 63))"|./vm repl
# default toolchain(s)
CC ?= gcc
LD ?= ld
# win32 cross-compile
MGCC32 ?= i686-w64-mingw32-gcc
MGCC64?=x86_64-w64-mingw32-gcc
# ansi colors
ifeq ($(MAKE_TERMOUT),)
red=
green=
done=
else
red=\033[1;31m
green=\033[1;32m
done=\033[0m
endif
# check submodules
# ----------------
ifeq ($(shell ls -A libraries/OpenGL),)
$(warning $(red)Submodules not loaded. Run 'git submodule update --init --recursive' once.$(done))
endif
# cleanup while insuccessfull builds
# ----------------------------------
$(shell [ -s tmp/repl.c ] || rm -rf tmp/repl.c)
# source code dependencies and flags
# ----------------------------------
include dependencies.mk
# autogenerations
# ----------------------------------
includes/ol/vm.h: src/olvm.c
sed -e '/\/\/ <!--/,/\/\/ -->/d' $^ >$@
# note: use 2>/dev/null in "shell command" to avoid
# make call optimization and really run shell.
tmp/repl.c: olvm repl
# vim
ifneq ($(shell command -v xxd 2>/dev/null),)
xxd --include repl >tmp/repl.c
else
# coreutils
ifneq ($(shell command -v od 2>/dev/null),)
od -An -vtx1 repl| tr -d '\n'| sed \
-e 's/^ /0x/' -e 's/ /,0x/g' \
-e 's/^/unsigned char repl[] = {/' \
-e 's/$$/};/'> $@
else
# olvm
echo '(display "unsigned char repl[] = {") (lfor-each (lambda (x) (display x) (display ",")) (file->bytestream "repl")) (display "0};")'| ./olvm repl> tmp/repl.c
endif
endif
doc/olvm.md: src/olvm.c extensions/ffi.c
cat src/olvm.c extensions/ffi.c| tools/makedoc >doc/olvm.md
# compiler flags
# ----------------------------------
## os independent flags
CFLAGS += -std=gnu99 -fno-exceptions
CFLAGS += -DHAVE_SOCKETS=$(if $(HAVE_SOCKETS),$(HAVE_SOCKETS),0)
CFLAGS += -DHAVE_DLOPEN=$(if $(HAVE_DLOPEN),$(HAVE_DLOPEN),0)
CFLAGS += -DHAVE_SECCOMP=$(if $(HAVE_SECCOMP),$(HAVE_SECCOMP),0)
ifneq ($(HAVE_MEMFD_CREATE),)
CFLAGS += -DHAVE_MEMFD_CREATE=$(HAVE_MEMFD_CREATE)
endif
ifneq ($(HAVE_SENDFILE),)
CFLAGS += -DHAVE_SENDFILE=$(HAVE_SENDFILE)
endif
# builtin "sin", "cos", "sqrt", etc. functions support
# can be disabled using "-DOLVM_BUILTIN_FMATH=0"
ifneq ($(OLVM_BUILTIN_FMATH),0)
CFLAGS += -lm
# CFLAGS += -ffast-math -mfpmath=387
else
CFLAGS += -DOLVM_BUILTIN_FMATH=0
endif
# 32-bit linux fseek and ftell needs:
CFLAGS += -D_FILE_OFFSET_BITS=64
# -D_LARGEFILE_SOURCE
# ----------------------------------
## debug/release flags
CFLAGS_CHECK := -O0 -g3 -Wall -DWARN_ALL
CFLAGS_DEBUG := -O0 -g3 -Wall
CFLAGS_DEBUG += -DCAR_CHECK=1 -DCDR_CHECK=1 -DNTRACE
CFLAGS_RELEASE := $(if $(RPM_OPT_FLAGS), $(RPM_OPT_FLAGS), -O2 -DNDEBUG)
CFLAGS_RELEASE += -Wno-unused-result -g0
CFLAGS_TRACE := -O0 -g3 -Wall
CFLAGS_TRACE += -DCAR_CHECK=1 -DCDR_CHECK=1
VERSION ?= $(shell echo `git describe --tags \`git rev-list --tags --max-count=1\``-`git rev-list HEAD --count`-`git log --pretty=format:'%h' -n 1`)
# ------------------------------------------------------
## os dependent flags
UNAME ?= $(shell uname -s)
# Linux
ifeq ($(UNAME),Linux)
ifeq ($(CC), tcc)
L := $(if $(HAVE_DLOPEN), -ldl)
else
L := $(if $(HAVE_DLOPEN), -ldl) \
-Xlinker --export-dynamic
endif
# Debian i586 fix
ifeq ($(CC),gcc)
CFLAGS += -I/usr/include/$(shell gcc -print-multiarch)
endif
endif #Linux
# BSD
ifeq ($(UNAME),FreeBSD)
L := $(if $(HAVE_DLOPEN), -lc) \
-Xlinker --export-dynamic
LD := ld.bfd
endif
ifeq ($(UNAME),NetBSD)
L := $(if $(HAVE_DLOPEN), -lc) \
-Xlinker --export-dynamic
endif
ifeq ($(UNAME),OpenBSD)
L := $(if $(HAVE_DLOPEN), -lc) \
-Xlinker --export-dynamic
endif
ifeq ($(UNAME),Darwin)
CFLAGS += -DSYSCALL_SYSINFO=0
PREFIX ?= /usr/local
endif
# -----------------------------------------------
## 'clean/install' part
clean:
rm -f boot.fasl
rm -f ./vm ./ol ./olvm ./libol.so
rm -f tmp/*
rm -f includes/ol/vm.h
-include extras/setup.mk
# -----------------------------------------------
## builds
debug: CFLAGS += $(CFLAGS_DEBUG)
debug: vm ol olvm libol.so
trace: CFLAGS += $(CFLAGS_TRACE)
trace: vm ol olvm libol.so
release: CFLAGS += $(CFLAGS_RELEASE)
release: vm ol olvm libol.so
# new one special hardened target
paranoid: CFLAGS += $(CFLAGS_RELEASE)
paranoid: CFLAGS += -DCAR_CHECK=1 -DCDR_CHECK=1
paranoid: vm ol olvm libol.so
perf: CFLAGS += -O2 -g3 -DNDEBUG -Wall
perf: vm ol olvm libol.so
slim:
HAVE_SOCKETS=0 HAVE_DLOPEN=0 HAVE_SANDBOX=1 \
$(MAKE) -B release olvm
minimal: CFLAGS += -DOLVM_FFI=0 -DHAVE_SOCKETS=1 -DHAVE_DLOPEN=0 -DHAVE_SANDBOX=0
minimal: release
# ffi test build
ffi: CFLAGS += $(CFLAGS_TRACE)
ffi: src/olvm.c extensions/ffi.c tests/ffi.c
$(CC) src/olvm.c -o $@ \
extensions/ffi.c -Iincludes \
tests/ffi.c \
$(CFLAGS) $(L)
@echo Ok.
ffi32: CFLAGS += $(CFLAGS_TRACE) -m32
ffi32: src/olvm.c extensions/ffi.c tests/ffi.c
$(CC) src/olvm.c -o $@ \
extensions/ffi.c -Iincludes \
tests/ffi.c \
$(CFLAGS) $(L)
@echo Ok.
## android build
NDK_ROOT ?=/opt/android/ndk
android: jni/*.c tmp/repl.c
$(NDK_ROOT)/ndk-build
# ol
vm:
$(CC) src/olvm.c -o $@ \
extensions/ffi.c -Iincludes \
$(CFLAGS) -DPREFIX=\"$(PREFIX)\" $(L)
@echo Ok.
vm.asm: CFLAGS += $(CFLAGS_RELEASE)
vm.asm:
$(CC) src/olvm.c -o $@ \
-DHAVE_DLOPEN=0 -Iincludes \
$(CFLAGS) -DPREFIX=\"$(PREFIX)\" $(L) \
-S -fverbose-asm
@echo Ok.
ol:
$(CC) src/olvm.c -o $@ \
extensions/ffi.c -Iincludes \
$(CFLAGS) -DPREFIX=\"$(PREFIX)\" $(L) \
tmp/repl.c -DREPL=repl
@echo Ok.
olp: CFLAGS += $(CFLAGS_RELEASE)
olp: tmp/pvenv.tar
$(CC) src/olvm.c -o $@ \
extensions/ffi.c -Iincludes \
-DOLVM_TARVENV=1 -DOLVM_TARVFOLDERS=1 \
$(CFLAGS) -DPREFIX=\"$(PREFIX)\" $(L) \
tmp/repl.c -DREPL=repl
objcopy --add-section .tar=tmp/pvenv.tar \
--set-section-flags .tar=noload,readonly \
$@ $@
libol.so:
$(CC) src/olvm.c -o $@ \
extensions/ffi.c -Iincludes \
$(CFLAGS) -DPREFIX=\"$(PREFIX)\" $(L) \
tmp/repl.c -DREPL=repl \
-DOLVM_NOMAIN -shared -fPIC
@echo Ok.
# real name of
olvm: vm
cp $< $@
strip $@
#strip $@ -R .eh_frame
#strip $@ -R .eh_frame_hdr
# selfexec feature test
selfexec: ol
objcopy --add-section .lisp=selfexec.lisp \
--set-section-flags .lisp=noload,readonly $^ $@
# windows
# You can debug ol.exe using "winedbg --gdb ol.exe"
# require mingw-w64-i686-dev (+ gcc-mingw-w64-i686) or/and mingw-w64-x86-64-dev (+ gcc-mingw-w64-x86-64)
ol%.exe: MINGWCFLAGS += -std=gnu99 -fno-exceptions
ol%.exe: MINGWCFLAGS += $(CFLAGS_RELEASE)
ol%.exe: src/olvm.c extensions/ffi.c tmp/repl.c
$(MGCC) \
$^ -o $@ \
-DREPL=repl \
-DHAVE_DLOPEN=1 -DHAS_SOCKES=1 -DOLVM_FFI=1 \
-DOLVM_TARVENV=1 \
-Iincludes/win32 -Iincludes \
$(MINGWCFLAGS) -lws2_32
#wine tools/cv2pdb.exe $@
ol32.exe: MGCC:=$(MGCC32)
ol64.exe: MGCC:=$(MGCC64)
ol.exe: MINGWCFLAGS += -DOLVM_TARVENV=1 # enable TARVENV definitely
ol.exe: ol64.exe tmp/pvenv.tar # by default 64-bit exe
cat $< >$@
#wine tools/cv2pdb.exe ol.exe
x86_64-w64-mingw32-strip $@
cat tmp/pvenv.tar >>$@
# compiling the Ol language
recompile: boot.fasl
boot.fasl: vm repl src/*.scm lang/*.scm libraries/otus/*.scm libraries/owl/*.scm libraries/scheme/*.scm
@vm repl --version="$(VERSION)" --home=.:libraries \
src/ol.scm
@if diff boot.fasl repl>/dev/null;then\
echo '$(green) `___` $(done)' ;\
echo '$(green) (o,o) $(done)' ;\
echo '$(green) \) ) $(done)' ;\
echo '$(green)___"_"___$(done)' ;\
echo '$(green)Build Ok.$(done)' ;\
else \
echo `stat -c%s repl` -\> `stat -c%s $@` ;\
cp -b $@ repl ;$(MAKE) $@ ;\
fi
# compiling infix math notation
libraries/owl/math/infix.scm: tools/make-math-infix.scm vm
./vm repl tools/make-math-infix.scm >$@
# additional targets (like packaging, tests, etc.)
MAKEFILE_MAIN=1
-include extras/wasm.mk
-include tests/Makefile
-include tests/rosettacode/Makefile
-include config/Makefile
-include debian/Makefile
# documentation samples check
check: check-reference
check-reference: release
check-reference: $(wildcard doc/reference/*.md)
@echo "Testing reference samples:"
@./ol tools/check-reference.lisp $(filter %.md,$^) && echo $(ok) || echo $(failed)
# win32 extensions
-include extensions/win32/Makefile
# -------------------------------------------------------------
# pvenv
define PVENV_ADD
cat '{}'| $$olvm $$repl <(echo '(write (read))') >$$library;\
tar -rf $$tar0 '$$library' \
--absolute-names \
--transform 's|.*|{}|' \
--owner=OL/2.6 \
--group=*
endef
define PVENV_ADD_RAW
tar -rf $$tar0 \
--absolute-names '{}' \
--owner=OL/2.6 \
--group=*
endef
tmp/pvenv.tar: $(wildcard libraries/*/*.scm)\
$(wildcard libraries/*/*/*.scm)\
$(wildcard libraries/*/*/*/*.scm)\
$(wildcard libraries/*/*.lisp)\
$(wildcard libraries/*/*/*.lisp)\
$(wildcard libraries/*/*/*/*.lisp)
@$(MAKE) olvm
tar -cf $@ -T /dev/null
`# macOS wants the template to be at the end` ;\
`# so use the same template under all os` ;\
export library=`mktemp /tmp/scm.XXXXXXXXX` ;\
export olvm=${abspath ./olvm} ;\
export repl=${abspath ./repl} ;\
`# OpenGL tarfolder` ;\
export tar0=${abspath ./tmp/OpenGL.tar} ;\
tar -cf $$tar0 -T /dev/null ;\
cd libraries/OpenGL ;\
find * -name "*.scm" -exec bash -c "echo '{}'; $(PVENV_ADD)" \;;\
cd ../.. ;\
`# lib/gtk-3 tarfolder` ;\
export tar0=${abspath ./tmp/gtk-3.tar} ;\
tar -cf $$tar0 -T /dev/null ;\
cd libraries/lib/gtk-3 ;\
find * -name "*.scm" -exec bash -c "echo '{}'; $(PVENV_ADD)" \;;\
cd ../../.. ;\
export tar0=${abspath $@} ;\
cd libraries ;\
find . -name "*.scm" -exec bash -c "echo '{}'; $(PVENV_ADD)" \;;\
find . -name "*.lisp" -exec bash -c "echo '{}'; $(PVENV_ADD_RAW)" \;;\
for name in "http/server"; do \
eval `echo $(PVENV_ADD_RAW) |sed "s|{}|$$name|g"` ;\
done ;\
cd .. ;\
rm -f $$library ;\
`# Final integration of all TAR subfolders` \
tar -vf $$tar0 --wildcards --delete './OpenGL/*' ;\
tar -rf $$tar0 tmp/OpenGL.tar --transform 's|.*|./OpenGL/|' ;\
tar -vf $$tar0 --wildcards --delete './lib/gtk-3/*' ;\
tar -rf $$tar0 tmp/gtk-3.tar --transform 's|.*|./lib/gtk-3/|'