forked from dyne/Zenroom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
291 lines (247 loc) · 11.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
# Zenroom (GNU Makefile build system)
#
# (c) Copyright 2017-2018 Dyne.org foundation
# designed, written and maintained by Denis Roio <jaromil@dyne.org>
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License version
# 3 as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see
# <http://www.gnu.org/licenses/>.
pwd := $(shell pwd)
mil := ${pwd}/build/milagro
extras := ${pwd}/docs/demo
# default
gcc := gcc
ar := ar
ranlib := ranlib
cflags_protection := -fstack-protector-all -D_FORTIFY_SOURCE=2 -fno-strict-overflow
cflags := -O2 ${cflags_protection}
musl := ${pwd}/build/musl
platform := posix
luasrc := ${pwd}/lib/lua53/src
# milagro settings
rsa_bits := ""
ecc_curves := ED25519,NIST256,GOLDILOCKS,BN254CX,FP256BN
milagro_cmake_flags := -DBUILD_SHARED_LIBS=OFF -DBUILD_PYTHON=OFF -DBUILD_DOXYGEN=OFF -DAMCL_CHUNK=32 -DAMCL_CURVE=${ecc_curves} -DAMCL_RSA=${rsa_bits} -DCMAKE_SHARED_LIBRARY_LINK_FLAGS=""
test-exec := ${pwd}/src/zenroom-shared -c ${pwd}/test/decode-test.conf
patches:
./build/apply-patches
embed-lua:
@echo "Embedding all files in src/lua"
if ! [ -r build/luac ]; then ${gcc} -I${luasrc} -o build/luac ${luasrc}/luac.c ${luasrc}/liblua.a -lm; fi
./build/embed-lualibs
@echo "File generated: src/lualibs_detected.c"
@echo "Must commit to git if modified, see git diff."
# TODO: improve flags according to
# https://github.com/kripken/emscripten/blob/master/src/settings.js
js: gcc=${EMSCRIPTEN}/emcc
js: ar=${EMSCRIPTEN}/emar
js: cflags := --memory-init-file 0 -O2 -D'ARCH=\"JS\"'
js: ldflags := -s "EXPORTED_FUNCTIONS='[\"_zenroom_exec\"]'" -s "EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\",\"cwrap\"]'" -s ALLOW_MEMORY_GROWTH=1 -s USE_SDL=0
js: patches lua53 milagro-js
CC=${gcc} CFLAGS="${cflags}" LDFLAGS="${ldflags}" make -C src js
wasm: gcc=${EMSCRIPTEN}/emcc
wasm: ar=${EMSCRIPTEN}/emar
wasm: cflags := -O2 -D'ARCH=\"WASM\"'
wasm: ldflags := -s WASM=1 -s "EXPORTED_FUNCTIONS='[\"_zenroom_exec\"]'" -s "EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\",\"cwrap\"]'" -s MODULARIZE=1
wasm: patches lua53 milagro-js
CC=${gcc} CFLAGS="${cflags}" LDFLAGS="${ldflags}" make -C src js
demo: gcc=${EMSCRIPTEN}/emcc
demo: ar=${EMSCRIPTEN}/emar
demo: cflags := -O2 -D'ARCH=\"WASM\"'
demo: ldflags := -s WASM=1 -s "EXPORTED_FUNCTIONS='[\"_zenroom_exec\"]'" -s "EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\",\"cwrap\"]'" -s ASSERTIONS=1 --shell-file ${extras}/shell_minimal.html -s NO_EXIT_RUNTIME=1 -s USE_SDL=0 -s USE_PTHREADS=0
demo: patches lua53 milagro-js
CC=${gcc} CFLAGS="${cflags}" LDFLAGS="${ldflags}" make -C src demo
html: gcc=${EMSCRIPTEN}/emcc
html: ar=${EMSCRIPTEN}/emar
html: cflags := -O2 -D'ARCH=\"JS\"'
html: ldflags := -sEXPORTED_FUNCTIONS='["_main","_zenroom_exec"]'
html: patches lua53 milagro-js
CC=${gcc} CFLAGS="${cflags}" LDFLAGS="${ldflags}" make -C src html
win: gcc=x86_64-w64-mingw32-gcc
win: ar=x86_64-w64-mingw32-ar
win: ranlib=x86_64-w64-mingw32-ranlib
win: cflags += -D'ARCH=\"WIN\"' -std=c99
win: platform = posix
win: patches lua53 milagro-win
CC=${gcc} CFLAGS="${cflags}" make -C src win
static: gcc := musl-gcc
static: cflags := -Os -static -Wall -std=gnu99 ${cflags_protection} -D'ARCH=\"MUSL\"' -D__MUSL__
static: ldflags := -static
static: patches lua53 milagro
CC=${gcc} CFLAGS="${cflags}" LDFLAGS="${ldflags}" make -C src static
system-static: cflags := -Os -static -Wall -std=gnu99 ${cflags_protection} -D'ARCH=\"UNIX\"' -D__MUSL__
system-static: ldflags := -static
system-static: patches lua53 milagro
CC=${gcc} CFLAGS="${cflags}" LDFLAGS="${ldflags}" make -C src system-static
shared: gcc := gcc
shared: cflags := -O2 -fPIC ${cflags_protection} -D'ARCH=\"LINUX\"'
shared: ldflags := -lm
shared: platform := linux
shared: patches lua53 milagro
CC=${gcc} CFLAGS="${cflags}" make -C src shared
osx: gcc := gcc
osx: cflags := -O2 -fPIC ${cflags_protection} -D'ARCH=\"OSX\"'
osx: ldflags := -lm
osx: platform := macosx
osx: patches lua53 milagro
CC=${gcc} CFLAGS="${cflags}" make -C src shared
ios-armv7: ARCH := armv7
ios-armv7: OS := iphoneos
ios-armv7: gcc := $(shell xcrun --sdk iphoneos -f gcc 2>/dev/null)
ios-armv7: ar := $(shell xcrun --sdk iphoneos -f ar 2>/dev/null)
ios-armv7: ld := $(shell xcrun --sdk iphoneos -f ld 2>/dev/null)
ios-armv7: ranlib := $(shell xcrun --sdk iphoneos -f ranlib 2>/dev/null)
ios-armv7: SDK := $(shell xcrun --sdk iphoneos --show-sdk-path 2>/dev/null)
ios-armv7: cflags := -O2 -fPIC ${cflags_protection} -D'ARCH=\"OSX\"' -isysroot ${SDK} -arch ${ARCH} -D NO_SYSTEM
ios-armv7: ldflags := -lm
ios-armv7: platform := ios
ios-armv7: patches lua53 milagro
CC=${gcc} CFLAGS="${cflags}" make -C src library
${AR} rcs zenroom-armv7.a `find . -name \*.o`
ios-arm64: ARCH := arm64
ios-arm64: OS := iphoneos
ios-arm64: gcc := $(shell xcrun --sdk iphoneos -f gcc 2>/dev/null)
ios-arm64: ar := $(shell xcrun --sdk iphoneos -f ar 2>/dev/null)
ios-arm64: ld := $(shell xcrun --sdk iphoneos -f ld 2>/dev/null)
ios-arm64: ranlib := $(shell xcrun --sdk iphoneos -f ranlib 2>/dev/null)
ios-arm64: SDK := $(shell xcrun --sdk iphoneos --show-sdk-path 2>/dev/null)
ios-arm64: cflags := -O2 -fPIC ${cflags_protection} -D'ARCH=\"OSX\"' -isysroot ${SDK} -arch ${ARCH} -D NO_SYSTEM
ios-arm64: ldflags := -lm
ios-arm64: platform := ios
ios-arm64: patches lua53 milagro
CC=${gcc} CFLAGS="${cflags}" make -C src library
${AR} rcs zenroom-arm64.a `find . -name \*.o`
ios-sim: ARCH := x86_64
ios-sim: OS := iphonesimulator
ios-sim: gcc := $(shell xcrun --sdk iphonesimulator -f gcc 2>/dev/null)
ios-sim: ar := $(shell xcrun --sdk iphonesimulator -f ar 2>/dev/null)
ios-sim: ld := $(shell xcrun --sdk iphonesimulator -f ld 2>/dev/null)
ios-sim: ranlib := $(shell xcrun --sdk iphonesimulator -f ranlib 2>/dev/null)
ios-sim: SDK := $(shell xcrun --sdk iphonesimulator --show-sdk-path 2>/dev/null)
ios-sim: cflags := -O2 -fPIC ${cflags_protection} -D'ARCH=\"OSX\"' -isysroot ${SDK} -arch ${ARCH} -D NO_SYSTEM
ios-sim: ldflags := -lm
ios-sim: platform := ios
ios-sim: patches lua53 milagro
CC=${gcc} CFLAGS="${cflags}" make -C src library
${AR} rcs zenroom-x86_64.a `find . -name \*.o`
ios-fat:
lipo -create zenroom-x86_64.a zenroom-arm64.a zenroom-armv7.a -output zenroom.a
android: gcc := $(CC)
android: ar := $(AR)
android: ranlib := $(RANLIB)
android: ld := $(ld)
android: cflags := ${cflags} -std=c99 -shared -DLUA_USE_DLOPEN
android: patches lua53 luazen milagro
LDFLAGS="--sysroot=/tmp/ndk-arch-21/sysroot" CC=${gcc} CFLAGS="${cflags}" make -C src android
debug: gcc := gcc
debug: cflags := -O0 -ggdb -D'ARCH=\"LINUX\"' ${cflags_protection}
debug: patches lua53 milagro
CC=${gcc} CFLAGS="${cflags}" make -C src shared
lua53:
CC=${gcc} CFLAGS="${cflags} \
-DLUA_COMPAT_5_3 -DLUA_COMPAT_MODULE" \
LDFLAGS="${ldflags}" AR="${ar}" RANLIB=${ranlib} \
make -C ${pwd}/lib/lua53/src ${platform}
milagro:
@echo "-- Building milagro (POSIX)"
if ! [ -r ${pwd}/lib/milagro-crypto-c/CMakeCache.txt ]; then cd ${pwd}/lib/milagro-crypto-c && CC=${gcc} cmake . -DCMAKE_C_FLAGS="${cflags}" ${milagro_cmake_flags}; fi
if ! [ -r ${pwd}/lib/milagro-crypto-c/lib/libamcl_core.a ]; then CC=${gcc} CFLAGS="${cflags}" make -C ${pwd}/lib/milagro-crypto-c; fi
milagro-win:
@echo "-- Building milagro (Windows)"
sed -i 's/project (AMCL)/project (AMCL C)/' ${pwd}/lib/milagro-crypto-c/CMakeLists.txt
if ! [ -r ${pwd}/lib/milagro-crypto-c/CMakeCache.txt ]; then cd ${pwd}/lib/milagro-crypto-c && CC=${gcc} cmake . -DCMAKE_C_FLAGS="${cflags}" -DCMAKE_SYSTEM_NAME="Windows" ${milagro_cmake_flags} ; fi
if ! [ -r ${pwd}/lib/milagro-crypto-c/lib/libamcl_core.a ]; then CC=${gcc} CFLAGS="${cflags}" make -C ${pwd}/lib/milagro-crypto-c; fi
milagro-js:
@echo "-- Building milagro (JS Emscripten)"
sed -i 's/project (AMCL)/project (AMCL C)/' ${pwd}/lib/milagro-crypto-c/CMakeLists.txt
if ! [ -r ${pwd}/lib/milagro-crypto-c/CMakeCache.txt ]; then cd ${pwd}/lib/milagro-crypto-c && CC=${gcc} cmake . -DCMAKE_C_FLAGS="${cflags}" -DCMAKE_SYSTEM_NAME="Javascript" ${milagro_cmake_flags} ; fi
if ! [ -r ${pwd}/lib/milagro-crypto-c/lib/libamcl_core.a ]; then CC=${gcc} CFLAGS="${cflags}" make -C ${pwd}/lib/milagro-crypto-c; fi
#-DCMAKE_TOOLCHAIN_FILE="${pwd}/lib/milagro-crypto-c/resources/cmake/emscripten-cross.cmake"
check-milagro: milagro
CC=${gcc} CFLAGS="${cflags}" make -C ${pwd}/lib/milagro-crypto-c test
## tests that require too much memory
himem-tests = \
@${1} test/sort.lua && \
${1} test/literals.lua && \
${1} test/calls.lua && \
${1} test/pm.lua && \
${1} test/nextvar.lua && \
${1} test/constructs.lua && \
${1} test/cjson-test.lua
## GC tests break memory management with umm
# in particular steps (2)
# ${1} test/gc.lua && \
lowmem-tests = \
@${1} test/vararg.lua && \
${1} test/utf8.lua && \
${1} test/tpack.lua && \
${1} test/strings.lua && \
${1} test/math.lua && \
${1} test/goto.lua && \
${1} test/events.lua && \
${1} test/coroutine.lua && \
${1} test/code.lua && \
${1} test/closure.lua && \
${1} test/locals.lua && \
${1} test/schema.lua && \
${1} test/octet.lua && \
${1} test/ecdh.lua
check-shared: test-exec-lowmem := ${pwd}/src/zenroom-shared -c umm
check-shared: test-exec := ${pwd}/src/zenroom-shared
check-shared:
$(call lowmem-tests,${test-exec-lowmem})
$(call himem-tests,${test-exec})
./test/octet-json.sh ${test-exec}
@echo "----------------"
@echo "All tests passed for SHARED binary build"
@echo "----------------"
check-static: test-exec := ${pwd}/src/zenroom-static
check-static: test-exec-lowmem := ${pwd}/src/zenroom-static -c umm
check-static:
$(call lowmem-tests,${test-exec-lowmem})
$(call himem-tests,${test-exec})
./test/octet-json.sh ${test-exec}
@echo "----------------"
@echo "All tests passed for SHARED binary build"
@echo "----------------"
check-js: test-exec := nodejs ${pwd}/test/zenroom_exec.js ${pwd}/src/zenroom.js
check-js:
$(call lowmem-tests,${test-exec})
$(call himem-tests,${test-exec})
@echo "----------------"
@echo "All tests passed for SHARED binary build"
@echo "----------------"
check-debug: test-exec-lowmem := valgrind --max-stackframe=2064480 ${pwd}/src/zenroom-shared -c umm
check-debug: test-exec := valgrind --max-stackframe=2064480 ${pwd}/src/zenroom-shared
check-debug:
$(call lowmem-tests,${test-exec-lowmem})
$(call himem-tests,${test-exec})
./test/octet-json.sh ${test-exec}
@echo "----------------"
@echo "All tests passed for SHARED binary build"
@echo "----------------"
check-osx: test-exec-lowmem := ${pwd}/src/zenroom-shared -c umm
check-osx: test-exec := ${pwd}/src/zenroom-shared
check-osx:
$(call lowmem-tests,${test-exec-lowmem})
$(call himem-tests,${test-exec})
@echo "----------------"
@echo "All tests passed for OSX binary build"
@echo "----------------"
clean:
make clean -C ${pwd}/lib/lua53/src
make clean -C ${pwd}/lib/milagro-crypto-c && \
rm -f ${pwd}/lib/milagro-crypto-c/CMakeCache.txt
make clean -C src
rm -f ${extras}/index.*
distclean:
rm -rf ${musl}