#!/bin/bash
# Run from CAD root with emcc 5.0.3. Arguments are the matching OCCT source
# tree, its CMake build tree (generated headers and static wasm libraries),
# and an output directory for iges-brep.mjs and iges-brep.wasm.
set -euo pipefail
source_path=$1
build_path=$2
output_path=$3
includes=()
while IFS= read -r path; do includes+=("-I$path"); done < <(find "$source_path/src" -name '*.hxx' -exec dirname {} \; | sort -u)
includes+=("-I$build_path/include/opencascade")
mkdir -p "$output_path"
em++ vendor/iges-brep/bridge.cpp -std=c++17 -O3 -msimd128 -fwasm-exceptions \
  -DOCCT_NO_PLUGINS -DIGNORE_NO_ATOMICS=1 "${includes[@]}" \
  -sENVIRONMENT=worker,node -sALLOW_MEMORY_GROWTH=1 -sSTACK_SIZE=1048576 \
  --no-entry --bind -o "$output_path/iges-brep.mjs" \
  "$build_path"/lin32/clang/lib/*.a
