set -euo pipefail RELEASE=0 if [ "${1:-}" = "debug" ] then shift echo "Starting a debug build..." else RELEASE=1 echo "Starting a release build..." fi MAIN_C="src/main/demo.c" CFLAGS="" CFLAGS+=" -std=c99 -Wall -Werror -Wno-unused -Wno-missing-braces -Wno-tautological-compare -Wno-parentheses" CC="emcc" OUTFILE="main.html" CFLAGS+=" -DNO_EXECINFO" # telling our own code not to #include CFLAGS+=" -s DEFAULT_TO_CXX=0 " # no C++ plz CFLAGS+=" -s USE_SDL=2 " CFLAGS+=" --preload-file data --preload-file actor --preload-file anim" # Fixes: `ccall` is a library symbol and not included by default # ...as of my upgrade to emcc 6.0.3 # See also: # * https://github.com/emscripten-core/emscripten/issues/17839 # * https://github.com/emscripten-core/emscripten/issues/17831 CFLAGS+=" -s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=\$ccall " # Fixes: emscripten_force_exit cannot actually shut down the runtime, as the build does not have EXIT_RUNTIME set # ...as of my upgrade to emcc 6.0.3 CFLAGS+=" -s EXIT_RUNTIME=1 " # Use IDBFS for save files CFLAGS+=" -l idbfs.js " CFLAGS+=" --post-js setup_fs.js " CFLAGS+=" -s ALLOW_MEMORY_GROWTH=1" if [ "$RELEASE" = 1 ] then CFLAGS+=" -O2" else CFLAGS+=" -O0 -g" fi "$CC" $CFLAGS src/*.c "$MAIN_C" -o "$OUTFILE" $@ ########################################################################## # Building www directory WWW_SRC_DIR="www-src" WWW_DIR="www" # We've already got a modified version of emcc's main.html in $WWW_SRC_DIR, # so get rid of the unmodified version generated by emcc just now: EMCC_FILES=$(echo main.{html,html.map}) echo "Removing files: $EMCC_FILES" rm -f $EMCC_FILES # Remove old $WWW_DIR, make fresh one echo "Resetting $WWW_DIR/" rm -rf "$WWW_DIR" cp -r "$WWW_SRC_DIR" "$WWW_DIR" # Move files generated by emcc into $WWW_DIR for f in main.{js,html.mem,data,wasm} do echo "Moving $f into $WWW_DIR/" test -f "$f" || { echo "...never mind, doesn't exist" continue } mv "$f" "$WWW_DIR"/ done