summaryrefslogtreecommitdiff
path: root/script/trees
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2024-12-30 15:08:54 +0000
committerLeah Rowe <leah@libreboot.org>2024-12-30 15:29:41 +0000
commitec2f07166624634d937715f4407cd19c0aaa8996 (patch)
tree8ea378ec2aa85d4241d0d6fb4cf50b6399a12279 /script/trees
parentf64b59962790936f49399b13f9a940d5e6230d32 (diff)
trees: match gcc/gnat versions both ways
on debian trixie/sid after updating from stable, sometimes gcc 13 and gnat 13 are both available, but gcc resolves to gcc-14 and gnat-14 isn't available. even when gnat-14 and gcc-14 are available, gnat will still either resolve to gnat-13, or nothing at all. in cases where gnat-14 is unavailable, but gcc and gnat 13 are both available, we should match gcc to gnat. Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'script/trees')
-rwxr-xr-xscript/trees64
1 files changed, 40 insertions, 24 deletions
diff --git a/script/trees b/script/trees
index 786461dc..d07f3254 100755
--- a/script/trees
+++ b/script/trees
@@ -15,7 +15,7 @@ eval `setvars "" xarch srcdir premake cmakedir xlang mode makeargs elfdir cmd \
project target target_dir targets xtree _f release bootstrapargs mkhelper \
autoconfargs listfile autogenargs btype tree rev tree_depend build_depend \
defconfig postmake mkhelpercfg dry dest_dir mdir cleanargs gccver gccfull \
- gnatver gnatfull gccdir`; badhash="n"
+ gnatver gnatfull gccdir gnatdir`; badhash="n"
main()
{
@@ -206,7 +206,11 @@ check_cross_compiler()
xfix="${_xarch%-*}" && [ "$xfix" = "x86_64" ] && xfix="x64"
- check_gnat_path
+ # match gnat-X to gcc
+ (
+ check_gnu_path gcc gnat || check_gnu_path gnat gcc || \
+ $err "Host GCC/GNAT mismatch"
+ ) || $err "Cannot match host GCC/GNAT versions"
# sometimes buildgcc fails for like no reason. try twice.
make -C "$cbdir" crossgcc-$xfix $xgccargs || \
@@ -215,43 +219,55 @@ check_cross_compiler()
done; return 0
}
-# fix mismatching gcc/gnat versions on debian trixie/sid
-check_gnat_path()
+# fix mismatching gcc/gnat versions on debian trixie/sid. as of december 2024,
+# trixie/sid had gnat-13 as gnat and gcc-14 as gcc, but has gnat-14 in apt. in
+# some cases, gcc 13+14 and gnat-13 are present; or gnat-14 and gcc-14, but
+# gnat in PATH never resolves to gnat-14, because gnat-14 was "experimental"
+check_gnu_path()
{
- rm -f xbmkpath/* || $err "Cannot clear xbmkpath/"
+ [ $# -lt 2 ] && $err "check_gnu_path: Too few arguments"
+ [ "$1" = "$2" ] && $err "check_gnu_path: Both arguments identical"
+ for _gnuarg in 1 2; do
+ eval "[ \"\$$_gnuarg\" = \"gcc\" ] && continue"
+ eval "[ \"\$$_gnuarg\" = \"gnat\" ] && continue"
+ $err "check_gnu_path: Invalid argument \"$_gnuarg\""
+ done
+ command -v $1 1>/dev/null || $err "Host gcc unavailable"
- eval `setvars "" gccver gccfull gnatver gnatfull gccdir`
- gnu_setver gcc gcc || $err "Command 'gcc' unavailable."
- gnu_setver gnat gnat || :
+ eval `setvars "" gccver gccfull gnatver gnatfull gccdir gnatdir`
+ gnu_setver "$1" "$1" || $err "Command '$1' unavailable."
+ gnu_setver "$2" "$2" || :
- [ -z "$gccver" ] && $err "Cannot detect host GCC version"
+ eval "[ -z \"\$$1ver\" ] && $err \"Cannot detect host '$1' version\""
[ "$gnatfull" = "$gccfull" ] && return 0
- gccdir="$(dirname "$(command -v gcc)")"
- for _gnatbin in "$gccdir/gnat-"*; do
- [ -f "$_gnatbin" ] || continue
- [ "${_gnatbin#"$gccdir/gnat-"}" = "$gccver" ] || continue
- gnatver="${_gnatbin#"$gccdir/gnat-"}"; break
+ eval "$1dir="$(dirname "$(command -v $1)")""
+ eval "_gnudir=\"\$$1dir\"; _gnuver=\"\$$1ver\""
+ for _gnubin in "$_gnudir/$2-"*; do
+ [ -f "$_gnubin" ] || continue
+ [ "${_gnubin#"$_gnudir/$2-"}" = "$_gnuver" ] || continue
+ gnatver="${_gnubin#"$_gnudir/$2-"}"; break
done
- gnu_setver "gnat" "$gccdir/gnat-$gccver" || $err "Unknown gnat version"
- [ "$gnatfull" = "$gccfull" ] || $err "GCC/GNAT versions do not match."
+ gnu_setver "$2" "$_gnudir/$2-$_gnuver" || return 1
+ [ "$gnatfull" = "$gccfull" ] || return 1
(
+ rm -f xbmkpath/* || $err "Cannot clear xbmkpath/"
x_ cd xbmkpath
- for _gnatbin in "$gccdir/gnat"*"-$gccver"; do
- [ -e "$_gnatbin" ] || continue; _gnatutil="${_gnatbin##*/}"
- x_ ln -s "$_gnatbin" "${_gnatutil%"-$gccver"}"
+ for _gnubin in "$_gnudir/$2"*"-$_gnuver"; do
+ [ -e "$_gnubin" ] || continue; _gnuutil="${_gnubin##*/}"
+ x_ ln -s "$_gnubin" "${_gnuutil%"-$_gnuver"}"
done
- ) || $err "Cannot create gnat-$gccver link in $gccdir"; :
+ ) || $err "Cannot create $2-$_gnuver link in $_gnudir"; :
}
gnu_setver()
{
eval "$2 --version 1>/dev/null 2>/dev/null || return 1"
- eval "${1}ver=\"`$2 --version 2>/dev/null | head -n1`\""
- eval "${1}ver=\"\${${1}ver##* }\""
- eval "${1}full=\"\${$1}ver\""
- eval "${1}ver=\"\${${1}ver%%.*}\""; :
+ eval "$1ver=\"`$2 --version 2>/dev/null | head -n1`\""
+ eval "$1ver=\"\${$1ver##* }\""
+ eval "$1full=\"\$$1ver\""
+ eval "$1ver=\"\${$1ver%%.*}\""; :
}
check_defconfig()