aboutsummaryrefslogtreecommitdiff
path: root/emcc
diff options
context:
space:
mode:
Diffstat (limited to 'emcc')
-rwxr-xr-xemcc22
1 files changed, 22 insertions, 0 deletions
diff --git a/emcc b/emcc
index 8fb93f78..249ba398 100755
--- a/emcc
+++ b/emcc
@@ -181,6 +181,11 @@ Options that are modified or new in %s include:
will be run). Note that this by itself
will not minify the code (closure does
that)
+ --embed-file <filename> A file to embed inside the generated
+ JavaScript. The compiled code will be able
+ to access the file in the current directory
+ with the same basename as given here (that is,
+ just the filename, without a path to it).
--shell-file <path> The path name to a skeleton HTML file used
when generating HTML output. The shell file
used needs to have this token inside it:
@@ -311,6 +316,7 @@ try:
closure = None
js_transform = None
compress_whitespace = None
+ embed_files = []
shell_path = shared.path_from_root('src', 'shell.html')
def check_bad_eq(arg):
@@ -344,6 +350,11 @@ try:
compress_whitespace = int(newargs[i+1])
newargs[i] = ''
newargs[i+1] = ''
+ elif newargs[i].startswith('--embed-file'):
+ check_bad_eq(newargs[i])
+ embed_files.append(newargs[i+1])
+ newargs[i] = ''
+ newargs[i+1] = ''
elif newargs[i] == '-MF': # clang cannot handle this, so we fake it
f = open(newargs[i+1], 'w')
f.write('\n')
@@ -662,6 +673,17 @@ try:
final = shared.Building.emscripten(final, append_ext=False)
if DEBUG: save_intermediate('original')
+ # Embed files
+ if len(embed_files) > 0:
+ if DEBUG: print >> sys.stderr, 'emcc: embedding files'
+ src = open(final).read().replace(
+ '// {{PRE_RUN_ADDITIONS}}',
+ '\n'.join(map(lambda embed_file: "FS.createDataFile('/', '%s', %s, true, false);" % (os.path.basename(embed_file), str(map(ord, open(embed_file, 'rb').read()))), embed_files))
+ )
+ final += '.ef.js'
+ open(final, 'w').write(src)
+ if DEBUG: save_intermediate('embedded_files')
+
# Apply a source code transformation, if requested
if js_transform:
shutil.copyfile(final, final + '.tr.js')