-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmake.sh
executable file
·84 lines (59 loc) · 2.31 KB
/
make.sh
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
#!/bin/bash
# ------------------------------------------------------------------------------
set -e
root="${BASH_SOURCE[0]}";
if [ -h "${root}" ]; then
while [ -h "${root}" ]; do root=`readlink "${root}"`; done
fi
root=$(cd `dirname "${root}"` && pwd)
# ------------------------------------------------------------------------------
TEMPLATEFILE=${TEMPLATEFILE:-"${root}/src/template/lua5.1.5.template.js"}
FRAGMENTDIR=${FRAGMENTDIR:-"${root}/src/js"}
GENERATEDDIR=${GENERATEDDIR:-"${root}/src/generated"}
OUTDIR=${OUTDIR:-"${root}/src/min"}
OUTFILE=${OUTFILE:-"${OUTDIR}/lua5.1.5.min.js"}
LUASRCDIR=${LUASRCDIR:-"${root}/lib/lua-5.1.5/src"}
LUAJS=${LUAJS:-"${GENERATEDDIR}/lua5.1.5.js"}
# ------------------------------------------------------------------------------
if [ "${1}" == "--run-emscripten" ]; then
echo "Building ${LUAJS} with emscripten..."
EMCC=${EMCC:-$(which emcc || true)}
EMCC=${EMCC:-${HOME}/projects/emscripten/emcc}
if [ ! -x ${EMCC} ]; then
echo "Emscripten's emcc not found." >&2
echo "See README for installation instructions." >&2
exit 1
fi
EMCCFLAGS=${EMCCFLAGS:-'-O2'}
cd ${LUASRCDIR}
exported_functions=$(
grep 'LUA.*_API' lua.h lauxlib.h lualib.h \
| sed -e 's/.*[ (*]\(lua[LIa-z_]\+\).*(.*/\1/g' \
| sed -e "s/\(.*\)/'_\1',/g" \
| sed ':a;N;$!ba;s/\n/ /g' \
)
# TODO: Would it be enough? Need better tests.
reserved_function_pointers=$(wc -w <<<$exported_functions)
mkdir -p "${GENERATEDDIR}"
"${EMCC}" \
${EMCCFLAGS} \
-s EXPORTED_FUNCTIONS="[${exported_functions}]" \
-s RESERVED_FUNCTION_POINTERS="${reserved_function_pointers}" \
-o "${LUAJS}" \
lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c lmem.c \
lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c ltm.c lundump.c \
lvm.c lzio.c lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c loslib.c \
ltablib.c lstrlib.c loadlib.c linit.c
else
echo "Skipping generation of lua.js (use --run-emscripten to do it)..."
fi
# ------------------------------------------------------------------------------
echo "Generating ${OUTFILE}..."
mkdir -p "${OUTDIR}"
${root}/bin/generator \
"${OUTFILE}" \
"${TEMPLATEFILE}" \
"${LUAJS}" \
"${FRAGMENTDIR}"/*.js
# ------------------------------------------------------------------------------
echo "OK"