diff --git a/build_web.sh b/build_web.sh index 74c689d..03c5976 100755 --- a/build_web.sh +++ b/build_web.sh @@ -29,37 +29,57 @@ fi echo "=== Step 1: Compiling raylib for web ===" -# Compile raylib source files -emcc -c "$RAYLIB_DIR/src/rcore.c" $RAYLIB_CFLAGS -o "$RAYLIB_BUILD/rcore.o" -emcc -c "$RAYLIB_DIR/src/rshapes.c" $RAYLIB_CFLAGS -o "$RAYLIB_BUILD/rshapes.o" -emcc -c "$RAYLIB_DIR/src/rtextures.c" $RAYLIB_CFLAGS -o "$RAYLIB_BUILD/rtextures.o" -emcc -c "$RAYLIB_DIR/src/rtext.c" $RAYLIB_CFLAGS -o "$RAYLIB_BUILD/rtext.o" -emcc -c "$RAYLIB_DIR/src/rmodels.c" $RAYLIB_CFLAGS -o "$RAYLIB_BUILD/rmodels.o" -emcc -c "$RAYLIB_DIR/src/raudio.c" $RAYLIB_CFLAGS -o "$RAYLIB_BUILD/raudio.o" +# raylib rarely changes; skip the (slow) rebuild if the archive already exists. +# Delete "$RAYLIB_BUILD/libraylib.a" to force a clean raylib rebuild. +if [ ! -f "$RAYLIB_BUILD/libraylib.a" ]; then + # Compile raylib source files + emcc -c "$RAYLIB_DIR/src/rcore.c" $RAYLIB_CFLAGS -o "$RAYLIB_BUILD/rcore.o" + emcc -c "$RAYLIB_DIR/src/rshapes.c" $RAYLIB_CFLAGS -o "$RAYLIB_BUILD/rshapes.o" + emcc -c "$RAYLIB_DIR/src/rtextures.c" $RAYLIB_CFLAGS -o "$RAYLIB_BUILD/rtextures.o" + emcc -c "$RAYLIB_DIR/src/rtext.c" $RAYLIB_CFLAGS -o "$RAYLIB_BUILD/rtext.o" + emcc -c "$RAYLIB_DIR/src/rmodels.c" $RAYLIB_CFLAGS -o "$RAYLIB_BUILD/rmodels.o" + emcc -c "$RAYLIB_DIR/src/raudio.c" $RAYLIB_CFLAGS -o "$RAYLIB_BUILD/raudio.o" -# Create static library -cd "$RAYLIB_BUILD" -emar rcs libraylib.a rcore.o rshapes.o rtextures.o rtext.o rmodels.o raudio.o + # Create static library + cd "$RAYLIB_BUILD" + emar rcs libraylib.a rcore.o rshapes.o rtextures.o rtext.o rmodels.o raudio.o + cd "$SCRIPT_DIR" +else + echo "libraylib.a found, skipping raylib rebuild" +fi + +# Compile the application modules (web version — no subprocess support). +# platform_web.c provides stub implementations for spawn/error functions. +# Keep this list in sync with rspektrum.make (use platform_web instead of +# platform_linux for the web target). +echo "=== Step 2: Compiling spectrogram modules for web ===" cd "$SCRIPT_DIR" -# Compile spectrogram (web version — no subprocess support) -# platform_web.c provides stub implementations for spawn/error functions -echo "=== Step 2: Compiling spectrogram + platform for web ===" -cd "$SCRIPT_DIR" +APP_MODULES="spectrogram fft stft audio render ui utils primitives platform_web" -# Compile platform_web.o (handles fork/execvp stubs for web) -emcc -c -Os -Wall -DPLATFORM_WEB "$SRC_DIR/platform_web.c" -o "$RAYLIB_BUILD/platform_web.o" +APP_OPT="-Os" +if [ "$BUILD_TYPE" = "debug" ]; then + APP_OPT="-g -O0" +fi -# Compile spectrogram -emcc -c -Os -Wall -DPLATFORM_WEB "$SRC_DIR/spectrogram.c" \ - -I"$RAYLIB_DIR/src" \ - -I"$RAYLIB_DIR/src/external" \ - -I"$RAYLIB_DIR/src/external/glfw/include" \ - -Iinclude \ - -o "$RAYLIB_BUILD/spectrogram.o" +APP_INCLUDES="-I$RAYLIB_DIR/src -I$RAYLIB_DIR/src/external -I$RAYLIB_DIR/src/external/glfw/include -Iinclude" + +# NOTE: do NOT pass -DPLATFORM_WEB to the app modules. Our code selects web +# behavior by linking platform_web.c (not via the macro), and PLATFORM_WEB is +# also an enumerator in platform.h — defining it as a macro breaks that enum. +# (raylib itself is built with -DPLATFORM_WEB above; it needs the macro.) +OBJECTS="" +for m in $APP_MODULES; do + echo " CC $m.c" + emcc -c $APP_OPT -Wall $APP_INCLUDES \ + "$SRC_DIR/$m.c" -o "$RAYLIB_BUILD/$m.o" + OBJECTS="$OBJECTS $RAYLIB_BUILD/$m.o" +done # Linker flags -LDFLAGS="-s USE_GLFW=3 -s ASYNCIFY -s TOTAL_MEMORY=67108864 -s FORCE_FILESYSTEM=1 --preload-file resources@resources --preload-file fonts/DejaVuSansMono.ttf@fonts/DejaVuSansMono.ttf --shell-file $SCRIPT_DIR/web_shell.html -s NO_EXIT_RUNTIME=1" +# The font lives at resources/fonts/DejaVuSansMono.ttf and is loaded relative to +# the resources dir at runtime, so the resources@resources preload covers it. +LDFLAGS="-s USE_GLFW=3 -s ASYNCIFY -s TOTAL_MEMORY=67108864 -s FORCE_FILESYSTEM=1 --preload-file resources@resources --shell-file $SCRIPT_DIR/web_shell.html -s NO_EXIT_RUNTIME=1" if [ "$BUILD_TYPE" = "debug" ]; then LDFLAGS="$LDFLAGS -g -O0 -s ASSERTIONS=1" @@ -69,13 +89,11 @@ fi # Compile and link emcc -o "$OUTPUT" \ - "$RAYLIB_BUILD/platform_web.o" \ - "$RAYLIB_BUILD/spectrogram.o" \ + $OBJECTS \ -I"$RAYLIB_DIR/src" \ -I"$RAYLIB_DIR/src/external" \ -I"$RAYLIB_DIR/src/external/glfw/include" \ -Iinclude \ - -DPLATFORM_WEB \ "$RAYLIB_BUILD/libraylib.a" \ $LDFLAGS diff --git a/src/platform_web.c b/src/platform_web.c index 32bd3f3..242bb78 100644 --- a/src/platform_web.c +++ b/src/platform_web.c @@ -10,6 +10,7 @@ #include #include #include +#include /* ENOSYS */ /* ── Helpers ─────────────────────────────────────────────────────────── */