105 lines
3.7 KiB
Bash
Executable File
105 lines
3.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
cd "$(dirname "$0")"
|
|
|
|
# LinuxCNC source basis: this probe compiles the core RS274 interpreter sources
|
|
# selected from linuxcnc-rs274-source-files.txt, keeping the native source
|
|
# object set tied to LinuxCNC src/emc/rs274ngc and tooldata source entries.
|
|
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_SOURCE_OBJECTS_BUILD_DIR-build/source-objects-test}
|
|
if [[ -z "$build_dir" ]]; then
|
|
echo "CNC_SIM_SOURCE_OBJECTS_BUILD_DIR must not be empty" >&2
|
|
exit 1
|
|
fi
|
|
if [[ "$build_dir" =~ [[:space:]] ]]; then
|
|
echo "CNC_SIM_SOURCE_OBJECTS_BUILD_DIR must not contain whitespace: $build_dir" >&2
|
|
exit 1
|
|
fi
|
|
manifest=${1:-linuxcnc-rs274-source-files.txt}
|
|
|
|
mkdir -p "$build_dir"
|
|
build_dir=$(cd "$build_dir" && pwd)
|
|
if [[ "$build_dir" == "/" ]]; then
|
|
echo "CNC_SIM_SOURCE_OBJECTS_BUILD_DIR must not be the filesystem root" >&2
|
|
exit 1
|
|
fi
|
|
exec 9>"$build_dir/source-objects.lock"
|
|
flock 9
|
|
preflight_cache_dir="$build_dir/preflight-cache"
|
|
|
|
LINUXCNC_ROOT="$linuxcnc_root" ./check-linuxcnc-inputs-cached.sh --cache-dir "$preflight_cache_dir" "$manifest"
|
|
manifest=$(cd "$(dirname "$manifest")" && pwd)/$(basename "$manifest")
|
|
linuxcnc_root=$(cd "$linuxcnc_root" && pwd)
|
|
|
|
common_flag_output=$(LINUXCNC_ROOT="$linuxcnc_root" ./list-linuxcnc-source-common-cxxflags.sh --python)
|
|
mapfile -t common_flags <<<"$common_flag_output"
|
|
|
|
source_output=$(CNC_SIM_PREFLIGHT_CACHE_DIR="$preflight_cache_dir" LINUXCNC_ROOT="$linuxcnc_root" ./list-linuxcnc-source-manifest-sources.sh "$manifest" core full)
|
|
mapfile -t sources <<<"$source_output"
|
|
|
|
objects=()
|
|
source_index=0
|
|
for source in "${sources[@]}"; do
|
|
objects+=("$build_dir/linuxcnc_${source_index}.o")
|
|
source_index=$((source_index + 1))
|
|
done
|
|
|
|
source_objects_signature="$build_dir/source-objects.signature"
|
|
source_objects_next_signature="$build_dir/source-objects.signature.next"
|
|
{
|
|
printf 'CXX=%s\n' "$cxx"
|
|
printf 'PWD=%s\n' "$PWD"
|
|
printf 'LINUXCNC_ROOT=%s\n' "$linuxcnc_root"
|
|
printf 'MANIFEST=%s\n' "$manifest"
|
|
printf 'BUILD_RULE_VERSION=1\n'
|
|
printf 'COMMON_FLAGS='
|
|
printf ' %s' "${common_flags[@]}"
|
|
printf '\n'
|
|
printf 'SOURCES:\n'
|
|
printf '%s\n' "${sources[@]}"
|
|
} > "$source_objects_next_signature"
|
|
if [[ ! -f "$source_objects_signature" ]] || ! cmp -s "$source_objects_signature" "$source_objects_next_signature"; then
|
|
rm -f "$build_dir"/linuxcnc_*.o "$build_dir"/linuxcnc_*.o.d
|
|
fi
|
|
mv "$source_objects_next_signature" "$source_objects_signature"
|
|
|
|
source_objects_makefile="$build_dir/source-objects.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'
|
|
|
|
source_index=0
|
|
for source in "${sources[@]}"; do
|
|
printf '%s: %s\n' "${objects[$source_index]}" "$source"
|
|
printf '\t@$(CXX) $(COMMON_FLAGS) -MMD -MP -MF %s.d -c %s -o %s\n\n' \
|
|
"${objects[$source_index]}" "$source" "${objects[$source_index]}"
|
|
source_index=$((source_index + 1))
|
|
done
|
|
printf '\n-include $(DEP_FILES)\n'
|
|
} > "$source_objects_makefile"
|
|
make --output-sync=target -j"$build_jobs" -f "$source_objects_makefile"
|
|
|
|
echo "linuxcnc rs274 source object build passed (${#sources[@]} objects)"
|
|
echo "built objects in $build_dir"
|