universalisos/tools/uos-cdk/uos-cdk-gen

81 lines
3.2 KiB
Bash
Executable file

#!/usr/bin/env bash
# uos-cdk-gen — generate the UniversalisOS CDK slot layout.
#
# Creates uos-cdk/<arch>/<proc>/{bin,<triple>/lib/ldscripts,lib/gcc/<triple>/}
# mirroring the PikeOS CDK structure so that share/definition/*.target.xml
# (UOS_PREFIX:cdk/<arch>/<proc>/bin/<arch>_<proc>-<tool>) resolves for real.
#
# Version policy (per docs/parity/CDK_CONFIG_BUILD_PARITY_SPEC.md §4.1): the
# parity pin is gcc 7.4.0 + binutils 2.31. That combo is not buildable on this
# host in reasonable time, so we apply the spec's documented fallback: newest
# host gcc that accepts the same -march/-mfpu flags, with the deviation
# recorded in uos-cdk/VERSIONS.md. Wrappers exec the host cross toolchain with
# the exact PikeOS flag set per slot.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
# PikeOS layout: $PIKEOS_PREFIX/cdk/<arch>/<proc> — so our prefix root gets cdk/
# and target/ directly (UOS_PREFIX:cdk/... resolves here).
CDK="${UOS_CDK_DIR:-$ROOT/cdk}"
POOL="${UOS_POOL_DIR:-$ROOT/target}"
# slot: arch proc triple hostprefix cflags
SLOTS=(
"arm v7hf arm-unknown-eabihf arm-none-eabi -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard"
"arm v8hf aarch64-unknown-elf aarch64-linux-gnu -march=armv8-a"
"riscv rv64 riscv64-unknown-elf riscv64-linux-gnu -march=rv64g -mabi=lp64d"
)
have() { command -v "$1" >/dev/null 2>&1; }
emit_wrapper() { # path hosttool extra-flags...
local path="$1"; shift
local tool="$1"; shift
cat > "$path" <<EOF
#!/usr/bin/env bash
# uos-cdk wrapper: $(basename "$path") -> $tool (uos-cdk generated)
exec $tool $@ "\$@"
EOF
chmod +x "$path"
}
mkdir -p "$CDK"
echo "# uos-cdk versions (generated $(date -u +%Y-%m-%dT%H:%M:%SZ))" > "$CDK/VERSIONS.md"
echo >> "$CDK/VERSIONS.md"
echo "| slot | triple | backing host tool | version | deviation |" >> "$CDK/VERSIONS.md"
echo "|---|---|---|---|---|" >> "$CDK/VERSIONS.md"
for slot in "${SLOTS[@]}"; do
read -r arch proc triple hostprefix cflags <<< "$slot"
dir="$CDK/$arch/$proc"
bindir="$dir/bin"
mkdir -p "$bindir" "$dir/$triple/lib/ldscripts" "$dir/lib/gcc/$triple" "$POOL/$arch/$proc"
if ! have "$hostprefix-gcc"; then
echo "WARN: $hostprefix-gcc not found — skipping $arch/$proc" >&2
echo "| $arch/$proc | $triple | MISSING | - | host toolchain absent |" >> "$CDK/VERSIONS.md"
continue
fi
ver=$("$hostprefix-gcc" -dumpversion)
# compiler-family wrappers (carry the PikeOS flag set)
for t in gcc g++ cpp; do
host="$hostprefix-$t"; have "$host" || host="$hostprefix-gcc"
emit_wrapper "$bindir/${arch}_${proc}-$t" "$host" $cflags
done
# binutils-family wrappers (no cflags)
for t in ar as ld nm objcopy objdump ranlib strip; do
host="$hostprefix-$t"
if have "$host"; then
emit_wrapper "$bindir/${arch}_${proc}-$t" "$host"
fi
done
# gdb: no cross-gdb on this host; back with multi-arch host gdb.
if have gdb; then
emit_wrapper "$bindir/${arch}_${proc}-gdb" "gdb"
fi
echo "| $arch/$proc | $triple | $hostprefix-gcc | $ver | pinned 7.4.0/2.31 -> host fallback (spec §4.1) |" >> "$CDK/VERSIONS.md"
echo "generated slot $arch/$proc ($triple, gcc $ver)"
done
echo
echo "uos-cdk at $CDK"
echo "use with: UOS_PREFIX=$ROOT uos-target check <slot> (paths resolve via UOS_PREFIX:cdk/...)"