#!/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_tooldata_runtime_symbols.XXXXXX") trap 'rm -rf "$build_dir"' EXIT LINUXCNC_ROOT="$linuxcnc_root" ./check-linuxcnc-inputs.sh --root-only tooldata_mmap_backend_shim=$(./list-linuxcnc-wasm-safe-shims.sh tooldata_mmap_backend.cc) tooldata_runtime_stubs_shim=$(./list-linuxcnc-wasm-safe-shims.sh tooldata_runtime_stubs.cc) linuxcnc_source_output=$(LINUXCNC_ROOT="$linuxcnc_root" ./list-linuxcnc-source-files.sh \ src/emc/tooldata/tooldata_db.cc \ src/emc/tooldata/tooldata_nml.cc) mapfile -t linuxcnc_sources <<<"$linuxcnc_source_output" tooldata_db_source=${linuxcnc_sources[0]} tooldata_nml_source=${linuxcnc_sources[1]} common_flag_output=$(LINUXCNC_ROOT="$linuxcnc_root" ./list-linuxcnc-wasm-common-cxxflags.sh) mapfile -t common_flags <<<"$common_flag_output" "$cxx" "${common_flags[@]}" \ -c "$tooldata_runtime_stubs_shim" \ -o "$build_dir/tooldata_runtime_stubs.o" "$cxx" "${common_flags[@]}" \ -c "$tooldata_mmap_backend_shim" \ -o "$build_dir/tooldata_mmap_backend.o" "$cxx" "${common_flags[@]}" \ -c "$tooldata_db_source" \ -o "$build_dir/linuxcnc_tooldata_db.o" "$cxx" "${common_flags[@]}" \ -c "$tooldata_nml_source" \ -o "$build_dir/linuxcnc_tooldata_nml.o" nm --defined-only "$build_dir/tooldata_runtime_stubs.o" \ | awk '$2 ~ /^[A-Z]$/ {print $3}' \ | LC_ALL=C sort -u \ > "$build_dir/runtime.exports" nm --defined-only "$build_dir/tooldata_mmap_backend.o" \ | awk '$2 ~ /^[A-Z]$/ {print $3}' \ | LC_ALL=C sort -u \ > "$build_dir/backend.exports" nm --defined-only "$build_dir"/linuxcnc_tooldata_*.o \ | awk '$2 ~ /^[A-Z]$/ {print $3}' \ | LC_ALL=C sort -u \ > "$build_dir/linuxcnc-runtime.exports" comm -23 "$build_dir/linuxcnc-runtime.exports" "$build_dir/backend.exports" \ > "$build_dir/expected.exports" comm -23 "$build_dir/expected.exports" "$build_dir/runtime.exports" > "$build_dir/missing.exports" if [[ -s "$build_dir/missing.exports" ]]; then echo "missing wasm tooldata runtime stub exports from LinuxCNC runtime sources:" >&2 cat "$build_dir/missing.exports" >&2 exit 1 fi comm -13 "$build_dir/expected.exports" "$build_dir/runtime.exports" > "$build_dir/unexpected.exports" if [[ -s "$build_dir/unexpected.exports" ]]; then echo "unexpected wasm tooldata runtime stub exports beyond LinuxCNC runtime sources:" >&2 cat "$build_dir/unexpected.exports" >&2 exit 1 fi echo "linuxcnc wasm tooldata runtime symbol probe passed"