#! /bin/bash # First figure out whether we are linking or not. We can tell by '-E', '-S', or '-c'. echo '' echo cc.sh "$@" echo '' linking=1 outfile=a.out # Dear, getopts doesn't cut it for cc linking=1 outfile='a.out' last='' args=("$@") # Go through arguments, capture the -o and remove it, while trying to # figure whether we are linking. skip=0 nargs=() for i in "${!args[@]}"; do # printf "arg[$i] = '%s'\\n" ${args[i]} if [ $skip == 1 ]; then skip=0 else skip=0 case ${args[i]} in -o) outfile=${args[$[$i + 1]]} skip=1 ;; -E|-S|-c) linking=0 nargs+=(${args[i]}); ;; *) nargs+=(${args[i]}); ;; esac fi done # When we are not generating an executable, we're done if [ 0 == $linking ]; then exec emcc -sEXIT_RUNTIME=1 "$@" fi args=(${nargs[@]}) wasmfile="$outfile.wasm" jsfile="$outfile.js" workerjsfile="$outfile.worker.js" args+=("-sFORCE_FILESYSTEM=1" "-o" "$outfile.js" "-lnodefs.js") rm -f $wasmfile $jsfile echo emcc ${args[@]} emcc ${args[@]} # if emcc failed, we're done, too. if [ 0 != $? ]; then exit $?; fi # Check that that outfile is produced if [ ! -f "$wasmfile" ]; then echo === emcc failed to generate "$wasmfile" exit 1 fi if [ ! -f "$jsfile" ]; then echo === emcc failed to generate "$jsfile" exit 1 fi ## Build the shell script cat > "$outfile" <\$temp/$(basename $outfile).js < { console.log(line); for (i = 0; i < line.length; i++) tty_have_input(line.charCodeAt(i)); tty_have_input(10); }); rl.on('close', () => { console.log("<>"); }); var tty_obuf = ""; function tyo(c) { process.stdout.write(String.fromCharCode(c)); } function whostate(s) { //console.log("whostate " + s); } Module || (Module = { arguments: [\$arguments], preRun: function () { //FS.mkdir("/tmp"); //FS.mkdir("/usr"); //FS.mkdir("/usr/joe"); function mkdir(path) { console.log('mkdir ' + path); FS.mkdir(path); } var i; var home = "$HOME"; for(i=1;i>"$outfile" <>\$temp/$(basename $outfile).js <> "$outfile" echo UUEND >> "$outfile" # transfer foo.js cat >>"$outfile" <\$temp/$(basename $outfile).worker.js <> "$outfile" echo UUEND >> "$outfile" # transfer foo.wasm cat >>"$outfile" <\$temp/$(basename $outfile).wasm <> "$outfile" echo UUEND >> "$outfile" cat >>"$outfile" <