#!/bin/bash
# Build the Render Pipeline Visualizer for the web using Emscripten
set -e

# Source emsdk if not already in PATH
if ! command -v emcc &> /dev/null; then
    source ~/emsdk/emsdk_env.sh
fi

BUILD_DIR="build-web"
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"

emcmake cmake .. \
    -DCMAKE_BUILD_TYPE=Release \
    -DSDL_SHARED=OFF \
    -DSDL_STATIC=ON \
    -DSDL_TEST=OFF \
    -DSDL_X11=OFF \
    -DSDL_WAYLAND=OFF

emmake make -j$(nproc)

echo ""
echo "Build complete! Files are in $BUILD_DIR/"
echo "To test locally: cd $BUILD_DIR && python3 -m http.server 8080"
echo "Then open http://localhost:8080/sdl3_flecs_template.html"
