diff options
Diffstat (limited to 'script/trees')
-rwxr-xr-x | script/trees | 88 |
1 files changed, 75 insertions, 13 deletions
diff --git a/script/trees b/script/trees index 698d2b34..045a49f7 100755 --- a/script/trees +++ b/script/trees @@ -2,7 +2,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later # Copyright (c) 2022-2023 Alper Nebi Yasak <alpernebiyasak@gmail.com> # Copyright (c) 2022 Ferass El Hafidi <vitali64pmemail@protonmail.com> -# Copyright (c) 2023-2024 Leah Rowe <leah@libreboot.org> +# Copyright (c) 2023-2025 Leah Rowe <leah@libreboot.org> set -u -e @@ -11,10 +11,11 @@ set -u -e XBMKPATH="$PATH" -eval `setvars "" xarch srcdir premake cmakedir xlang mode makeargs elfdir cmd \ +eval "`setvars "" xarch srcdir premake gnatdir 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`; badhash="n" + defconfig postmake mkhelpercfg dry dest_dir mdir cleanargs gccver gccfull \ + gnatver gnatfull gccdir cmakedir`"; badhash="n" main() { @@ -52,7 +53,7 @@ main() e "$mkhelpercfg" f missing && mkhelpercfg="$TMPDIR/mkhelper.cfg" && \ x_ touch "$mkhelpercfg" - targets="$@"; cmd="build_targets $targets" + targets="$*"; cmd="build_targets $targets" singletree "$project" && cmd="build_project" remkdir "${tmpgit%/*}" @@ -114,14 +115,15 @@ handle_defconfig() configure_project() { - eval `setvars "" xarch xlang build_depend autoconfargs xtree postmake \ + eval "`setvars "" cleanargs build_depend autoconfargs xtree postmake \ tree_depend makeargs btype mkhelper bootstrapargs premake release \ - cleanargs` + xarch xlang`" _tcfg="$1/target.cfg"; badhash="n"; [ -f "$_tcfg" ] || btype="auto" - [ -f "$datadir/mkhelper.cfg" ] && eval `setcfg "$datadir/mkhelper.cfg"` + [ -f "$datadir/mkhelper.cfg" ] && \ + eval "`setcfg "$datadir/mkhelper.cfg"`" while [ -f "$_tcfg" ] || [ "$cmd" != "build_project" ]; do - eval `setvars "" rev tree`; eval `setcfg "$_tcfg"` + eval "`setvars "" rev tree`"; eval "`setcfg "$_tcfg"`" printf "Loading %s config: %s\n" "$project" "$_tcfg" [ "$_f" = "-d" ] && build_depend="" # dry run @@ -139,7 +141,7 @@ configure_project() [ -n "$tree" ] && mdir="$mdir/$tree" [ -f "CHANGELOG" ] || check_project_hashes - [ "$mode" = "fetch" ] || x_ ./mk -f "$project" $target + [ "$mode" = "fetch" ] || x_ ./mk -f "$project" "$target" [ "$mode" = "fetch" ] || return 0 [ -f "CHANGELOG" ] && return 1; fetch_${cmd#build_}; return 1 } @@ -197,7 +199,7 @@ check_cross_compiler() [ "$project" != "coreboot" ] && cbdir="src/coreboot/default" [ -n "$xtree" ] && cbdir="src/coreboot/$xtree" - x_ ./mk -f coreboot ${cbdir#src/coreboot/} + x_ ./mk -f coreboot "${cbdir#src/coreboot/}" export PATH="$PWD/$cbdir/util/crossgcc/xgcc/bin:$PATH" export CROSS_COMPILE="${xarch% *}-" @@ -205,13 +207,72 @@ check_cross_compiler() xfix="${_xarch%-*}" && [ "$xfix" = "x86_64" ] && xfix="x64" + # match gnat-X to gcc + check_gnu_path gcc gnat || check_gnu_path gnat gcc || \ + $err "Cannot match host GCC/GNAT versions" + # sometimes buildgcc fails for like no reason. try twice. make -C "$cbdir" crossgcc-$xfix $xgccargs || \ make -C "$cbdir" crossgcc-$xfix $xgccargs || \ $err "!mkxgcc $project/$xtree '$xfix' '$xgccargs'" + + # we only want to mess with hostcc to build xgcc + rm -f "$XBMK_CACHE/xbmkpath/"* || \ + $err "Cannot clear xbmkpath/"; : done; return 0 } +# 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() +{ + [ $# -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 '$1' unavailable" + + eval "`setvars "" gccver gccfull gnatver gnatfull gccdir gnatdir`" + gnu_setver "$1" "$1" || $err "Command '$1' unavailable." + gnu_setver "$2" "$2" || : + + eval "[ -z \"\$$1ver\" ] && $err \"Cannot detect host '$1' version\"" + [ "$gnatfull" = "$gccfull" ] && return 0 + + 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 + _gnuver="${_gnubin#"$_gnudir/$2-"}"; break + done + gnu_setver "$2" "$_gnudir/$2-$_gnuver" || return 1 + [ "$gnatfull" = "$gccfull" ] || return 1 + + ( + rm -f "$XBMK_CACHE/xbmkpath/"* || $err "Cannot clear xbmkpath/" + cd "$XBMK_CACHE/xbmkpath" || $err "Can't cd to xbmkpath/" + for _gnubin in "$_gnudir/$2"*"-$_gnuver"; do + [ -e "$_gnubin" ] || continue; _gnuutil="${_gnubin##*/}" + x_ ln -s "$_gnubin" "${_gnuutil%"-$_gnuver"}" + done + ) || $err "Cannot create $2-$_gnuver link in $_gnudir"; : +} + +gnu_setver() +{ + eval "$2 --version 1>/dev/null 2>/dev/null || return 1" + eval "$1ver=\"`"$2" --version 2>/dev/null | head -n1`\"" + eval "$1ver=\"\${$1ver##* }\"" + eval "$1full=\"\$$1ver\"" + eval "$1ver=\"\${$1ver%%.*}\""; : +} + check_defconfig() { [ -f "$defconfig" ] || $dry $err "$project/$target: missing defconfig" @@ -243,7 +304,8 @@ handle_makefile() $dry x_ cp "$srcdir/$_copy" "$defconfig" [ -e "$srcdir/.git" ] && [ "$project" = "u-boot" ] && \ - [ "$mode" = "distclean" ] && $dry x_ git -C "$srcdir" $cleanargs clean -fdx; : + [ "$mode" = "distclean" ] && \ + $dry x_ git -C "$srcdir" $cleanargs clean -fdx; : } run_make_command() @@ -255,7 +317,7 @@ run_make_command() $dry make -C "$srcdir" $mode -j$XBMK_THREADS $makeargs || $err "!$mode" [ -z "$mkhelper" ] || [ -n "$mode" ] || $mkhelper || $err "!$mkhelper" - [ "$mode" = "clean" ] && \ + [ "$mode" != "clean" ] || \ $dry make -C "$srcdir" $cleanargs distclean || :; : } @@ -291,6 +353,6 @@ copy_elf() done < "$listfile"; x_ make clean -C "$srcdir" $cleanargs } -main $@ || exit 0 +main "$@" || exit 0 . "$mkhelpercfg" $cmd |