#!/usr/bin/env bash set -euo pipefail cd "$(dirname "$0")" # LinuxCNC source basis: wasm-safe probes compile the manifest-selected # src/emc/rs274ngc, src/emc/ini, and src/emc/tooldata sources against # browser shims, so include roots mirror LinuxCNC src/Makefile and the rs274, # ini, and tooldata Submakefiles without linking native LinuxCNC libraries. linuxcnc_root=${LINUXCNC_ROOT:-../linuxcnc} preflight_cache_dir=${CNC_SIM_PREFLIGHT_CACHE_DIR:-build/linuxcnc-helper-preflight-cache} std_flag=-std=c++17 include_core_include=0 include_core_src=0 include_tooldata=0 include_wctype=0 syntax_only=0 function_sections=0 data_sections=0 profile=base while [[ "$#" -gt 0 ]]; do case "$1" in --profile) if [[ "$#" -lt 2 ]]; then echo "missing --profile value" >&2 exit 1 fi profile=$2 shift 2 ;; --std) if [[ "$#" -lt 2 ]]; then echo "missing --std value" >&2 exit 1 fi std_flag=-std="$2" shift 2 ;; --core-include) include_core_include=1 shift ;; --core-src) include_core_src=1 shift ;; --tooldata-include) include_tooldata=1 shift ;; --wctype) include_wctype=1 shift ;; --syntax-only) syntax_only=1 shift ;; --function-sections) function_sections=1 shift ;; --data-sections) data_sections=1 shift ;; --) shift break ;; *) echo "unknown wasm cxxflag option: $1" >&2 exit 1 ;; esac done case "$profile" in base|core20|core20-sections) ;; *) echo "unknown wasm cxxflag profile: $profile" >&2 exit 1 ;; esac case "$profile" in core20|core20-sections) std_flag=-std=c++20 include_core_include=1 include_core_src=1 include_wctype=1 ;; esac case "$profile" in core20-sections) function_sections=1 data_sections=1 ;; esac LINUXCNC_ROOT="$linuxcnc_root" ./check-linuxcnc-inputs-cached.sh --cache-dir "$preflight_cache_dir" --root-only printf '%s\n' \ "$std_flag" \ -DULAPI \ -DCNC_SIM_ENABLE_LINUXCNC_WASM_SAFE_PROBE \ $([[ "$syntax_only" -eq 1 ]] && printf '%s\n' -fsyntax-only) \ $([[ "$include_wctype" -eq 1 ]] && printf '%s\n' -include wctype.h) \ $([[ "$function_sections" -eq 1 ]] && printf '%s\n' -ffunction-sections) \ $([[ "$data_sections" -eq 1 ]] && printf '%s\n' -fdata-sections) \ $([[ "$include_core_include" -eq 1 ]] && printf '%s\n' -I "$(pwd)/core/include") \ $([[ "$include_core_src" -eq 1 ]] && printf '%s\n' -I "$(pwd)/core/src") \ $([[ "$include_tooldata" -eq 1 ]] && printf '%s\n' -I "$linuxcnc_root/src/emc/tooldata") \ -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"