166 lines
5.7 KiB
Bash
Executable File
166 lines
5.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
cd "$(dirname "$0")"
|
|
|
|
# LinuxCNC source basis: the native API smoke links the thin cnc_sim API bridge
|
|
# with LinuxCNC RS274 headers, native support libraries, and source-backed
|
|
# canon/kinematics adapters selected from core/CMakeLists.txt.
|
|
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_API_NATIVE_BUILD_DIR-build/api-native-test}
|
|
if [[ -z "$build_dir" ]]; then
|
|
echo "CNC_SIM_API_NATIVE_BUILD_DIR must not be empty" >&2
|
|
exit 1
|
|
fi
|
|
if [[ "$build_dir" =~ [[:space:]] ]]; then
|
|
echo "CNC_SIM_API_NATIVE_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_API_NATIVE_BUILD_DIR must not be the filesystem root" >&2
|
|
exit 1
|
|
fi
|
|
exec 9>"$build_dir/api-native.lock"
|
|
flock 9
|
|
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)
|
|
|
|
var_file="$build_dir/rs274ngc-api.var"
|
|
cp "$linuxcnc_root/tests/halui/jogging/sim.var" "$var_file"
|
|
|
|
common_flag_output=$(
|
|
CNC_SIM_PREFLIGHT_CACHE_DIR="$preflight_cache_dir" \
|
|
LINUXCNC_ROOT="$linuxcnc_root" ./list-linuxcnc-source-common-cxxflags.sh \
|
|
--no-ulapi \
|
|
--python \
|
|
--core-include \
|
|
--core-src
|
|
)
|
|
mapfile -t common_flags <<<"$common_flag_output"
|
|
link_flag_output=$(CNC_SIM_PREFLIGHT_CACHE_DIR="$preflight_cache_dir" LINUXCNC_ROOT="$linuxcnc_root" ./list-linuxcnc-native-linkflags.sh)
|
|
mapfile -t link_flags <<<"$link_flag_output"
|
|
bridge_object_output=$(CNC_SIM_PREFLIGHT_CACHE_DIR="$preflight_cache_dir" LINUXCNC_ROOT="$linuxcnc_root" ./build-linuxcnc-native-bridge-objects.sh)
|
|
mapfile -t bridge_objects <<<"$bridge_object_output"
|
|
bridge_source_list="$build_dir/linuxcnc_bridge_smoke_project_sources.txt"
|
|
./list-linuxcnc-bridge-smoke-project-sources.sh > "$bridge_source_list"
|
|
mapfile -t bridge_sources < "$bridge_source_list"
|
|
project_source_list="$build_dir/linuxcnc_rs274_api_project_sources.txt"
|
|
./list-linuxcnc-rs274-api-project-sources.sh > "$project_source_list"
|
|
mapfile -t api_sources < "$project_source_list"
|
|
|
|
is_bridge_source() {
|
|
local source=$1
|
|
local candidate
|
|
for candidate in "${bridge_sources[@]}"; do
|
|
if [[ "$candidate" == "$source" ]]; then
|
|
return 0
|
|
fi
|
|
done
|
|
return 1
|
|
}
|
|
|
|
objects=()
|
|
project_index=0
|
|
api_extra_sources=()
|
|
for source in "${api_sources[@]}"; do
|
|
if is_bridge_source "$source"; then
|
|
continue
|
|
fi
|
|
api_extra_sources+=("$source")
|
|
objects+=("$build_dir/project_${project_index}.o")
|
|
project_index=$((project_index + 1))
|
|
done
|
|
main_object="$build_dir/cnc_sim_api_linuxcnc_rs274_smoke.o"
|
|
objects+=("$main_object")
|
|
target="$build_dir/cnc_sim_api_linuxcnc_rs274_smoke"
|
|
|
|
api_signature="$build_dir/api-native.signature"
|
|
api_next_signature="$build_dir/api-native.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 'LINK_FLAGS='
|
|
printf ' %s' "${link_flags[@]}"
|
|
printf '\n'
|
|
printf 'BRIDGE_OBJECTS:\n'
|
|
printf '%s\n' "${bridge_objects[@]}"
|
|
printf 'API_EXTRA_SOURCES:\n'
|
|
printf '%s\n' "${api_extra_sources[@]}"
|
|
} > "$api_next_signature"
|
|
if [[ ! -f "$api_signature" ]] || ! cmp -s "$api_signature" "$api_next_signature"; then
|
|
rm -f "$build_dir"/project_*.o \
|
|
"$build_dir"/*.d \
|
|
"$main_object" \
|
|
"$target"
|
|
fi
|
|
mv "$api_next_signature" "$api_signature"
|
|
|
|
api_makefile="$build_dir/api-native.mk"
|
|
{
|
|
printf 'CXX := %s\n' "$cxx"
|
|
printf 'COMMON_FLAGS :='
|
|
printf ' %s' "${common_flags[@]}"
|
|
printf '\n'
|
|
printf 'LINK_FLAGS :='
|
|
printf ' %s' "${link_flags[@]}"
|
|
printf '\n'
|
|
printf 'BRIDGE_OBJECTS :='
|
|
printf ' %s' "${bridge_objects[@]}"
|
|
printf '\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: %s\n\n' "$target"
|
|
|
|
project_index=0
|
|
for source in "${api_extra_sources[@]}"; do
|
|
source_flags=()
|
|
case "$source" in
|
|
core/src/gcode_backend.cpp)
|
|
source_flags+=(-DCNC_SIM_ENABLE_LINUXCNC_RS274_BACKEND)
|
|
;;
|
|
esac
|
|
printf '%s: %s\n' "$build_dir/project_${project_index}.o" "$source"
|
|
printf '\t@$(CXX) $(COMMON_FLAGS)'
|
|
printf ' %s' "${source_flags[@]}"
|
|
printf ' -MMD -MP -MF %s.d -c %s -o %s\n\n' \
|
|
"$build_dir/project_${project_index}.o" "$source" "$build_dir/project_${project_index}.o"
|
|
project_index=$((project_index + 1))
|
|
done
|
|
|
|
printf '%s: core/tests/cnc_sim_api_linuxcnc_rs274_smoke.cpp\n' "$main_object"
|
|
printf '\t@$(CXX) $(COMMON_FLAGS) -MMD -MP -MF %s.d -c core/tests/cnc_sim_api_linuxcnc_rs274_smoke.cpp -o %s\n\n' \
|
|
"$main_object" "$main_object"
|
|
printf '%s: $(BRIDGE_OBJECTS) $(OBJECTS)\n' "$target"
|
|
printf '\t@$(CXX) $(BRIDGE_OBJECTS) $(OBJECTS) $(LINK_FLAGS) -lrs274 -ltooldata -lpython3.13 -o %s\n\n' "$target"
|
|
printf '\n-include $(DEP_FILES)\n'
|
|
} > "$api_makefile"
|
|
make --output-sync=target -j"$build_jobs" -f "$api_makefile"
|
|
|
|
CNC_SIM_RS274_VAR="$var_file" "$target"
|
|
|
|
echo "linuxcnc rs274 API backend smoke passed"
|