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>
master
Leah Rowe 2024-12-30 15:08:54 +00:00
parent f64b599627
commit ec2f071666
1 changed files with 40 additions and 24 deletions

View File

@ -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 \ project target target_dir targets xtree _f release bootstrapargs mkhelper \
autoconfargs listfile autogenargs btype tree rev tree_depend build_depend \ autoconfargs listfile autogenargs btype tree rev tree_depend build_depend \
defconfig postmake mkhelpercfg dry dest_dir mdir cleanargs gccver gccfull \ defconfig postmake mkhelpercfg dry dest_dir mdir cleanargs gccver gccfull \
gnatver gnatfull gccdir`; badhash="n" gnatver gnatfull gccdir gnatdir`; badhash="n"
main() main()
{ {
@ -206,7 +206,11 @@ check_cross_compiler()
xfix="${_xarch%-*}" && [ "$xfix" = "x86_64" ] && xfix="x64" 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. # sometimes buildgcc fails for like no reason. try twice.
make -C "$cbdir" crossgcc-$xfix $xgccargs || \ make -C "$cbdir" crossgcc-$xfix $xgccargs || \
@ -215,43 +219,55 @@ check_cross_compiler()
done; return 0 done; return 0
} }
# fix mismatching gcc/gnat versions on debian trixie/sid # fix mismatching gcc/gnat versions on debian trixie/sid. as of december 2024,
check_gnat_path() # 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` eval `setvars "" gccver gccfull gnatver gnatfull gccdir gnatdir`
gnu_setver gcc gcc || $err "Command 'gcc' unavailable." gnu_setver "$1" "$1" || $err "Command '$1' unavailable."
gnu_setver gnat gnat || : 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 [ "$gnatfull" = "$gccfull" ] && return 0
gccdir="$(dirname "$(command -v gcc)")" eval "$1dir="$(dirname "$(command -v $1)")""
for _gnatbin in "$gccdir/gnat-"*; do eval "_gnudir=\"\$$1dir\"; _gnuver=\"\$$1ver\""
[ -f "$_gnatbin" ] || continue for _gnubin in "$_gnudir/$2-"*; do
[ "${_gnatbin#"$gccdir/gnat-"}" = "$gccver" ] || continue [ -f "$_gnubin" ] || continue
gnatver="${_gnatbin#"$gccdir/gnat-"}"; break [ "${_gnubin#"$_gnudir/$2-"}" = "$_gnuver" ] || continue
gnatver="${_gnubin#"$_gnudir/$2-"}"; break
done done
gnu_setver "gnat" "$gccdir/gnat-$gccver" || $err "Unknown gnat version" gnu_setver "$2" "$_gnudir/$2-$_gnuver" || return 1
[ "$gnatfull" = "$gccfull" ] || $err "GCC/GNAT versions do not match." [ "$gnatfull" = "$gccfull" ] || return 1
( (
rm -f xbmkpath/* || $err "Cannot clear xbmkpath/"
x_ cd xbmkpath x_ cd xbmkpath
for _gnatbin in "$gccdir/gnat"*"-$gccver"; do for _gnubin in "$_gnudir/$2"*"-$_gnuver"; do
[ -e "$_gnatbin" ] || continue; _gnatutil="${_gnatbin##*/}" [ -e "$_gnubin" ] || continue; _gnuutil="${_gnubin##*/}"
x_ ln -s "$_gnatbin" "${_gnatutil%"-$gccver"}" x_ ln -s "$_gnubin" "${_gnuutil%"-$_gnuver"}"
done done
) || $err "Cannot create gnat-$gccver link in $gccdir"; : ) || $err "Cannot create $2-$_gnuver link in $_gnudir"; :
} }
gnu_setver() gnu_setver()
{ {
eval "$2 --version 1>/dev/null 2>/dev/null || return 1" eval "$2 --version 1>/dev/null 2>/dev/null || return 1"
eval "${1}ver=\"`$2 --version 2>/dev/null | head -n1`\"" eval "$1ver=\"`$2 --version 2>/dev/null | head -n1`\""
eval "${1}ver=\"\${${1}ver##* }\"" eval "$1ver=\"\${$1ver##* }\""
eval "${1}full=\"\${$1}ver\"" eval "$1full=\"\$$1ver\""
eval "${1}ver=\"\${${1}ver%%.*}\""; : eval "$1ver=\"\${$1ver%%.*}\""; :
} }
check_defconfig() check_defconfig()