#!/usr/bin/env bash set -euo pipefail cd "$(dirname "$0")" linuxcnc_root=${LINUXCNC_ROOT:-../linuxcnc} cxx=${CXX:-g++} build_dir=$(mktemp -d "${TMPDIR:-/tmp}/cnc_sim_linuxcnc_wasm_rs274ngc_pre_link.XXXXXX") manifest=${1:-linuxcnc-rs274-wasm-source-files.txt} if [[ ! -f "$manifest" ]]; then echo "missing manifest: $manifest" >&2 exit 1 fi if [[ ! -d "$linuxcnc_root" ]]; then echo "missing LinuxCNC root: $linuxcnc_root" >&2 exit 1 fi trap 'rm -rf "$build_dir"' EXIT common_flags=( -std=c++20 -DULAPI -ffunction-sections -fdata-sections -I "$(pwd)/core/src" -include wctype.h -I "$(pwd)/core/include" -I "$(pwd)/core/wasm_shims" -I "$linuxcnc_root/src" -I "$linuxcnc_root/src/emc" -I "$linuxcnc_root/src/emc/nml_intf" -I "$linuxcnc_root/src/emc/rs274ngc" -I "$linuxcnc_root/src/emc/motion" -I "$linuxcnc_root/include" ) sources=( core/wasm_shims/dlfcn.cc core/wasm_shims/emc_status_shim.cc core/wasm_shims/gettext_shim.cc core/wasm_shims/linuxcnc_runtime_shim.cc core/wasm_shims/python_c_api_shim.cc core/wasm_shims/rtapi_compat.cc core/wasm_shims/tooldata/tooldata_mmap_backend.cc core/wasm_shims/tooldata/tooldata_runtime_stubs.cc core/wasm_shims/pythonplugin/python_plugin.cc core/src/canon_event_sink.cpp core/src/linuxcnc_canon_bridge.cpp core/src/linuxcnc_tooldata_fixture.cpp core/src/rtcp_kinematics.cpp ) while IFS=: read -r group path note; do case "$group" in core) if [[ ! -f "$linuxcnc_root/$path" ]]; then echo "missing manifest source: $path" >&2 exit 1 fi sources+=("$linuxcnc_root/$path") ;; ""|\#*|blocked) ;; *) echo "unknown manifest group: $group" >&2 exit 1 ;; esac done < "$manifest" sources+=(core/wasm_shims/rs274ngc_pre_probe_main.cc) objects=() object_index=0 for source in "${sources[@]}"; do obj="$build_dir/source_${object_index}.o" "$cxx" "${common_flags[@]}" -c "$source" -o "$obj" objects+=("$obj") object_index=$((object_index + 1)) done "$cxx" "${objects[@]}" \ -Wl,--gc-sections \ -lfmt \ -o "$build_dir/rs274ngc_pre_probe" "$build_dir/rs274ngc_pre_probe" echo "linuxcnc wasm rs274ngc_pre link probe passed"