This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathemscripten-javascriptify.py
More file actions
executable file
·90 lines (71 loc) · 2.29 KB
/
emscripten-javascriptify.py
File metadata and controls
executable file
·90 lines (71 loc) · 2.29 KB
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
#!/usr/bin/env python
# This script runs the command that converts the LLVM bitcode files
# produced by the emscripten compiler to JavaScript.
import sys
import os
import subprocess
# Compiler settings
# -----------------
#
# These should generally match the settings in config/emscripten-settings.gypi
settings = {
'ALLOW_MEMORY_GROWTH': 1,
'ASSERTIONS': 1,
'DEMANGLE_SUPPORT': 1,
'EMTERPRETIFY': 1,
'EMTERPRETIFY_ASYNC': 1,
'LINKABLE': 1,
'RESERVED_FUNCTION_POINTERS': 1024,
'TOTAL_MEMORY': 67108864,
'WARN_ON_UNDEFINED_SYMBOLS': 1,
}
# Get the build type and the compiler command
# -------------------------------------------
env_verbose = os.getenv('V', '0')
env_emcc = os.getenv('EMCC', 'emcc')
env_build_type = os.getenv('BUILDTYPE', 'Debug')
env_cflags = os.getenv('CFLAGS', [])
if env_build_type == 'Release':
optimisation_flags = ['-Os', '-g0']
else:
optimisation_flags = ['-O2', '-g3']
# Separate out separate elements of command line
emcc = env_emcc.split()
cflags = env_cflags.split()
# Process command line options
# ----------------------------
#
# Each option absorbs all subsequent arguments up to the next option.
# Options are identified by the fact they start with "--".
option = None
options = {}
for arg in sys.argv[1:]:
if arg.startswith('--'):
option = arg[2:]
options[option] = []
else:
if option is None:
print('ERROR: unrecognized option \'{}\''.format(arg))
sys.exit(1)
options[option].append(arg)
# Special handling for "--whitelist"
if options.has_key('whitelist'):
settings['EMTERPRETIFY_WHITELIST'] = '@{}'.format(options['whitelist'][0])
# Construct emcc command line
# ---------------------------
command = emcc + ["--emrun"] + optimisation_flags + cflags
for input in options['input']:
command.append(input)
command += ['-o', options['output'][0]]
for setting in sorted(settings.keys()):
command += ['-s', '{}={}'.format(setting, settings[setting])]
for option in ['pre-js', 'shell-file', 'js-library']:
if options.has_key(option):
for value in options[option]:
command += ['--' + option, value]
# Run emcc
# --------
if env_verbose.strip() is not '0':
print(" ".join(command))
emcc_result = subprocess.call(command)
sys.exit(emcc_result)