140 lines
4.8 KiB
Bash
Executable File
140 lines
4.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
cd "$(dirname "$0")"
|
|
|
|
# LinuxCNC source basis: this symbol probe compares the wasm mmap backend shim
|
|
# with src/emc/tooldata/tooldata_mmap.cc exports selected by LinuxCNC
|
|
# tooldata/Submakefile.
|
|
linuxcnc_root=${LINUXCNC_ROOT:-../linuxcnc}
|
|
cxx=${CXX:-g++}
|
|
if [[ -z ${CXX:-} ]] && command -v ccache >/dev/null 2>&1; then
|
|
cxx="ccache $cxx"
|
|
fi
|
|
build_jobs=${CNC_SIM_BUILD_JOBS:-8}
|
|
if ! [[ "$build_jobs" =~ ^[1-9][0-9]*$ ]]; then
|
|
echo "CNC_SIM_BUILD_JOBS must be a positive integer: $build_jobs" >&2
|
|
exit 1
|
|
fi
|
|
build_dir=${CNC_SIM_WASM_TOOLDATA_MMAP_SYMBOLS_BUILD_DIR-build/wasm-tooldata-mmap-symbols}
|
|
if [[ -z "$build_dir" ]]; then
|
|
echo "CNC_SIM_WASM_TOOLDATA_MMAP_SYMBOLS_BUILD_DIR must not be empty" >&2
|
|
exit 1
|
|
fi
|
|
if [[ "$build_dir" =~ [[:space:]] ]]; then
|
|
echo "CNC_SIM_WASM_TOOLDATA_MMAP_SYMBOLS_BUILD_DIR must not contain whitespace: $build_dir" >&2
|
|
exit 1
|
|
fi
|
|
mkdir -p "$build_dir"
|
|
build_dir=$(cd "$build_dir" && pwd)
|
|
if [[ "$build_dir" == "/" ]]; then
|
|
echo "CNC_SIM_WASM_TOOLDATA_MMAP_SYMBOLS_BUILD_DIR must not be the filesystem root" >&2
|
|
exit 1
|
|
fi
|
|
exec 9>"$build_dir/tooldata-mmap-symbols.lock"
|
|
flock 9
|
|
|
|
preflight_cache_dir=${CNC_SIM_PREFLIGHT_CACHE_DIR:-"$build_dir/preflight-cache"}
|
|
LINUXCNC_ROOT="$linuxcnc_root" ./check-linuxcnc-inputs-cached.sh --cache-dir "$preflight_cache_dir" --root-only
|
|
linuxcnc_root=$(cd "$linuxcnc_root" && pwd)
|
|
|
|
tooldata_mmap_backend_shim=$(./list-linuxcnc-wasm-safe-shims.sh tooldata_mmap_backend.cc)
|
|
tooldata_mmap_source=$(LINUXCNC_ROOT="$linuxcnc_root" ./list-linuxcnc-source-files.sh src/emc/tooldata/tooldata_mmap.cc)
|
|
|
|
common_flag_output=$(LINUXCNC_ROOT="$linuxcnc_root" ./list-linuxcnc-wasm-common-cxxflags.sh)
|
|
mapfile -t common_flags <<<"$common_flag_output"
|
|
|
|
sources=(
|
|
"$tooldata_mmap_backend_shim"
|
|
"$tooldata_mmap_source"
|
|
)
|
|
objects=(
|
|
"$build_dir/tooldata_mmap_backend.o"
|
|
"$build_dir/linuxcnc_tooldata_mmap.o"
|
|
)
|
|
|
|
signature="$build_dir/tooldata-mmap-symbols.signature"
|
|
next_signature="$build_dir/tooldata-mmap-symbols.signature.next"
|
|
{
|
|
printf 'CXX=%s\n' "$cxx"
|
|
printf 'PWD=%s\n' "$PWD"
|
|
printf 'LINUXCNC_ROOT=%s\n' "$linuxcnc_root"
|
|
printf 'BUILD_RULE_VERSION=1\n'
|
|
printf 'COMMON_FLAGS='
|
|
printf ' %s' "${common_flags[@]}"
|
|
printf '\n'
|
|
printf 'SOURCES:\n'
|
|
printf '%s\n' "${sources[@]}"
|
|
} > "$next_signature"
|
|
if [[ ! -f "$signature" ]] || ! cmp -s "$signature" "$next_signature"; then
|
|
rm -f "$build_dir"/*.o "$build_dir"/*.d
|
|
fi
|
|
mv "$next_signature" "$signature"
|
|
|
|
makefile="$build_dir/tooldata-mmap-symbols.mk"
|
|
{
|
|
printf 'CXX := %s\n' "$cxx"
|
|
printf 'COMMON_FLAGS :='
|
|
printf ' %s' "${common_flags[@]}"
|
|
printf '\n\n'
|
|
printf 'OBJECTS :='
|
|
printf ' %s' "${objects[@]}"
|
|
printf '\n\n'
|
|
printf 'DEP_FILES :=\n'
|
|
for object in "${objects[@]}"; do
|
|
printf 'DEP_FILES += %s.d\n' "$object"
|
|
done
|
|
printf '\n.PHONY: all\n'
|
|
printf 'all: $(OBJECTS)\n\n'
|
|
|
|
object_index=0
|
|
for source in "${sources[@]}"; do
|
|
printf '%s: %s\n' "${objects[$object_index]}" "$source"
|
|
printf '\t@$(CXX) $(COMMON_FLAGS) -MMD -MP -MF %s.d -c %s -o %s\n\n' "${objects[$object_index]}" "$source" "${objects[$object_index]}"
|
|
object_index=$((object_index + 1))
|
|
done
|
|
printf '\n-include $(DEP_FILES)\n'
|
|
} > "$makefile"
|
|
make --output-sync=target -j"$build_jobs" -f "$makefile" >/dev/null
|
|
|
|
symbols_signature="$build_dir/tooldata-mmap-symbols.nm.signature"
|
|
symbols_next_signature="$build_dir/tooldata-mmap-symbols.nm.signature.next"
|
|
{
|
|
printf 'SYMBOL_RULE_VERSION=1\n'
|
|
stat -c 'OBJECT=%n:%s:%y' "${objects[@]}"
|
|
} > "$symbols_next_signature"
|
|
if [[ ! -f "$symbols_signature" || ! -f "$build_dir/backend.exports" || ! -f "$build_dir/linuxcnc.exports" ]] ||
|
|
! cmp -s "$symbols_signature" "$symbols_next_signature"; then
|
|
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_mmap.o" \
|
|
| awk '$2 ~ /^[A-Z]$/ {print $3}' \
|
|
| LC_ALL=C sort -u \
|
|
> "$build_dir/linuxcnc.exports"
|
|
mv "$symbols_next_signature" "$symbols_signature"
|
|
else
|
|
rm -f "$symbols_next_signature"
|
|
fi
|
|
|
|
if ! comm -23 "$build_dir/linuxcnc.exports" "$build_dir/backend.exports" > "$build_dir/missing.exports"; then
|
|
exit 1
|
|
fi
|
|
|
|
if [[ -s "$build_dir/missing.exports" ]]; then
|
|
echo "missing wasm tooldata mmap backend exports from LinuxCNC tooldata_mmap.cc:" >&2
|
|
cat "$build_dir/missing.exports" >&2
|
|
exit 1
|
|
fi
|
|
|
|
comm -13 "$build_dir/linuxcnc.exports" "$build_dir/backend.exports" > "$build_dir/unexpected.exports"
|
|
if [[ -s "$build_dir/unexpected.exports" ]]; then
|
|
echo "unexpected wasm tooldata mmap backend exports beyond LinuxCNC tooldata_mmap.cc:" >&2
|
|
cat "$build_dir/unexpected.exports" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "linuxcnc wasm tooldata_mmap symbol probe passed"
|