2025-11-27 15:30:10 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
# Build wxWidgets with wxUniversal for WebAssembly
|
|
|
|
|
# This builds the GUI-enabled wxWidgets needed for KiCad
|
2025-11-28 16:42:35 +01:00
|
|
|
#
|
|
|
|
|
# Prerequisites:
|
|
|
|
|
# - Emscripten SDK installed and activated
|
|
|
|
|
# - autoconf (for regenerating configure from configure.in)
|
|
|
|
|
#
|
|
|
|
|
# To regenerate Makefile.in from bakefiles (after modifying files.bkl):
|
|
|
|
|
# cd wxwidgets/build/bakefiles
|
|
|
|
|
# docker run --rm -v "$(pwd)/../..":"$(pwd)/../.." -w "$(pwd)" \
|
|
|
|
|
# ghcr.io/vslavik/bakefile:0.2 bakefile_gen
|
|
|
|
|
#
|
|
|
|
|
# Usage:
|
|
|
|
|
# ./build-wxuniversal-wasm.sh # Build (incremental)
|
|
|
|
|
# ./build-wxuniversal-wasm.sh --clean # Clean build
|
2025-11-27 15:30:10 +01:00
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
|
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
|
|
|
|
BUILD_DIR="$PROJECT_ROOT/build-wasm/wxwidgets-universal"
|
|
|
|
|
WX_SOURCE="$PROJECT_ROOT/wxwidgets"
|
|
|
|
|
|
|
|
|
|
echo "=== Building wxWidgets wxUniversal for WASM ==="
|
|
|
|
|
echo "Project root: $PROJECT_ROOT"
|
|
|
|
|
echo "Build dir: $BUILD_DIR"
|
|
|
|
|
echo "wxWidgets source: $WX_SOURCE"
|
|
|
|
|
|
|
|
|
|
# Verify we're in the right place
|
2025-11-28 16:42:35 +01:00
|
|
|
if [ ! -f "$WX_SOURCE/configure.in" ]; then
|
2025-11-27 15:30:10 +01:00
|
|
|
echo "ERROR: wxWidgets source not found at $WX_SOURCE"
|
|
|
|
|
echo "Make sure the wxwidgets submodule is initialized"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2025-11-28 16:42:35 +01:00
|
|
|
# Regenerate configure if configure.in is newer
|
|
|
|
|
if [ "$WX_SOURCE/configure.in" -nt "$WX_SOURCE/configure" ]; then
|
|
|
|
|
echo "configure.in is newer than configure, regenerating..."
|
|
|
|
|
(cd "$WX_SOURCE" && autoconf)
|
|
|
|
|
fi
|
|
|
|
|
|
2025-11-27 15:30:10 +01:00
|
|
|
# Clean if requested
|
|
|
|
|
if [ "$1" = "--clean" ]; then
|
|
|
|
|
echo "Cleaning build directory..."
|
|
|
|
|
rm -rf "$BUILD_DIR"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Create build directory
|
|
|
|
|
mkdir -p "$BUILD_DIR"
|
|
|
|
|
cd "$BUILD_DIR"
|
|
|
|
|
|
|
|
|
|
# Configure with emconfigure
|
|
|
|
|
# Key flags based on wxWidgets-wasm:
|
|
|
|
|
# --host=emscripten Host system (detected via config.sub)
|
|
|
|
|
# --enable-universal Use wxUniversal (draws widgets directly)
|
|
|
|
|
# --disable-shared Build static libraries
|
|
|
|
|
# --with-opengl Enable OpenGL/WebGL support
|
|
|
|
|
# --disable-exceptions Emscripten doesn't support C++ exceptions well
|
|
|
|
|
# --disable-richtext Not needed for KiCad, simplifies build
|
|
|
|
|
# --without-libtiff Avoid external dependencies
|
|
|
|
|
# --disable-xlocale Browser environment handles locale
|
|
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
echo "=== Configuring ==="
|
|
|
|
|
|
|
|
|
|
# Set flags for Emscripten compatibility
|
|
|
|
|
# Z_HAVE_UNISTD_H ensures zlib includes <unistd.h> for read/write/lseek
|
2025-11-28 14:24:53 +01:00
|
|
|
# Include pcre2 headers from the build directory (generated during configure)
|
|
|
|
|
PCRE2_INCLUDE="$BUILD_DIR/3rdparty/pcre/src"
|
2025-11-27 15:30:10 +01:00
|
|
|
export CFLAGS="-DZ_HAVE_UNISTD_H=1"
|
2025-11-28 14:24:53 +01:00
|
|
|
export CXXFLAGS="-DZ_HAVE_UNISTD_H=1 -I$PCRE2_INCLUDE"
|
2025-11-27 15:30:10 +01:00
|
|
|
|
|
|
|
|
emconfigure "$WX_SOURCE/configure" \
|
|
|
|
|
--host=emscripten \
|
|
|
|
|
--enable-universal \
|
|
|
|
|
--disable-shared \
|
|
|
|
|
--with-opengl \
|
|
|
|
|
--disable-exceptions \
|
|
|
|
|
--disable-richtext \
|
|
|
|
|
--without-libtiff \
|
|
|
|
|
--disable-xlocale \
|
|
|
|
|
--with-cxx=17 \
|
|
|
|
|
--enable-utf8
|
|
|
|
|
|
2025-11-28 16:42:35 +01:00
|
|
|
# Build PCRE first to avoid race condition with parallel builds
|
|
|
|
|
# PCRE headers (pcre2.h) must be generated before regex.cpp compiles
|
|
|
|
|
echo ""
|
|
|
|
|
echo "=== Building PCRE first (dependency) ==="
|
|
|
|
|
emmake make -C 3rdparty/pcre
|
|
|
|
|
|
|
|
|
|
# Build wxWidgets
|
2025-11-27 15:30:10 +01:00
|
|
|
echo ""
|
2025-11-28 16:42:35 +01:00
|
|
|
echo "=== Building wxWidgets ==="
|
2025-11-27 15:30:10 +01:00
|
|
|
emmake make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu)
|
|
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
echo "=== Build complete ==="
|
|
|
|
|
ls -lh "$BUILD_DIR"/lib/*.a 2>/dev/null || echo "Libraries built in $BUILD_DIR/lib"
|