summaryrefslogtreecommitdiff
path: root/include/tree.sh
diff options
context:
space:
mode:
Diffstat (limited to 'include/tree.sh')
-rw-r--r--include/tree.sh232
1 files changed, 168 insertions, 64 deletions
diff --git a/include/tree.sh b/include/tree.sh
index 8b126240..254f738d 100644
--- a/include/tree.sh
+++ b/include/tree.sh
@@ -4,11 +4,50 @@
# Copyright (c) 2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
# Copyright (c) 2023-2025 Leah Rowe <leah@libreboot.org>
-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 rev build_depend gccdir cmakedir \
- defconfig postmake mkhelpercfg dry dest_dir mdir cleanargs gccver gccfull \
- gnatver gnatfull do_make badhash badtghash tree forcepull`"
+# flag e.g. ./mk -b <-- mkflag would be "b"
+flag=""
+
+xarch=""
+srcdir=""
+premake=""
+gnatdir=""
+xlang=""
+mode=""
+makeargs=""
+elfdir=""
+cmd=""
+project=""
+target=""
+target_dir=""
+targets=""
+xgcctree=""
+release=""
+bootstrapargs=""
+mkhelper=""
+autoconfargs=""
+listfile=""
+autogenargs=""
+buildtype=""
+rev=""
+build_depend=""
+gccdir=""
+cmakedir=""
+defconfig=""
+postmake=""
+mkhelpercfg=""
+if_not_dry_build=""
+dest_dir=""
+mdir=""
+cleanargs=""
+gccver=""
+gccfull=""
+gnatver=""
+gnatfull=""
+do_make=""
+badhash=""
+badtghash=""
+tree=""
+forcepull=""
trees()
{
@@ -16,24 +55,24 @@ trees()
while getopts $flags option
do
- if [ -n "$_f" ]; then
+ if [ -n "$flag" ]; then
err "only one flag is permitted" "trees" "$@"
fi
- _f="$1"
+ flag="$1"
# the "mode" variable is affixed to a make command, example:
# ./mk -m coreboot does: make menuconfig -C src/coreboot/tree
- case "$_f" in
+ case "$flag" in
-d)
# -d is similar to -b, except that
# a large number of operations will be
- # skipped. these are "dry build" scenarios
+ # skipped. these are "if_not_dry_build build" scenarios
# where only a subset of build tasks are done,
- # and $dry is prefixed to skipped commands
+ # and $if_not_dry_build is prefixed to skipped commands
- dry=":"
+ if_not_dry_build=":"
;;
-b) : ;;
-u) mode="oldconfig" ;;
@@ -42,11 +81,11 @@ trees()
-x) mode="crossgcc-clean" ;;
-f) # download source code for a project
do_make="n" # lets us know not to build anything
- dry=":"
+ if_not_dry_build=":"
;;
-F) # same as -F, but don't skip git fetch/pull on cache
do_make="n" # lets us know not to build anything
- dry=":"
+ if_not_dry_build=":"
forcepull="y"
;;
-s) mode="savedefconfig" ;;
@@ -57,6 +96,7 @@ trees()
if [ -z "${OPTARG+x}" ]; then
shift 1
+
break
fi
@@ -66,11 +106,13 @@ trees()
shift 2
done
- if [ -z "$_f" ]; then
+ if [ -z "$flag" ]; then
err "missing flag ($flags)" "trees" "$@"
elif [ -z "$project" ]; then
- fx_ "x_ ./mk $_f" x_ ls -1 config/git
+ fx_ "x_ ./mk $flag" x_ ls -1 config/git
+
return 1
+
elif [ ! -f "config/git/$project/pkg.cfg" ]; then
err "config/git/$project/pkg.cfg missing" "trees" "$@"
fi
@@ -94,7 +136,9 @@ trees()
targets="$*"
cmd="build_targets $targets"
- singletree "$project" && cmd="build_project"
+ if singletree "$project"; then
+ cmd="build_project"
+ fi
remkdir "${tmpgit%/*}"
}
@@ -104,17 +148,22 @@ build_project()
if ! configure_project "$configdir"; then
return 0
elif [ -f "$listfile" ]; then
- $dry elfcheck || return 0; :
+ if ! $if_not_dry_build elfcheck; then
+ return 0
+ fi
fi
if [ "$mode" = "distclean" ]; then
mode="clean"
fi
- run_make_command || return 0
+ if ! run_make_command; then
+ return 0
+ fi
if [ -z "$mode" ]; then
- $dry copy_elf; :
+ $if_not_dry_build \
+ copy_elf; :
fi
}
@@ -134,7 +183,9 @@ build_targets()
if [ "$x" = "list" ]; then
x_ ls -1 "config/$project"
+
listfile=""
+
break
fi
@@ -161,7 +212,10 @@ handle_defconfig()
return 0
fi
- chkvars tree
+ if [ -z "$tree" ]; then
+ err "$configdir: 'tree' not set" "handle_defconfig" "$@"
+ fi
+
srcdir="src/$project/$tree"
if [ "$mode" = "${mode%clean}" ] && [ ! -d "$srcdir" ]; then
@@ -170,9 +224,9 @@ handle_defconfig()
for y in "$target_dir/config"/*
do
- if [ "$_f" != "-d" ] && [ ! -f "$y" ]; then
+ if [ "$flag" != "-d" ] && [ ! -f "$y" ]; then
continue
- elif [ "$_f" != "-d" ]; then
+ elif [ "$flag" != "-d" ]; then
defconfig="$y"
fi
@@ -182,9 +236,9 @@ handle_defconfig()
if [ -z "$mode" ]; then
for _xarch in $xarch; do
- if [ -n "$_xarch" ]
- then
- $dry check_cross_compiler "$_xarch"
+ if [ -n "$_xarch" ]; then
+ $if_not_dry_build \
+ check_cross_compiler "$_xarch"
fi
done; :
fi
@@ -192,27 +246,42 @@ handle_defconfig()
handle_makefile
if [ -z "$mode" ]; then
- $dry copy_elf
+ $if_not_dry_build \
+ copy_elf
fi
done; :
}
configure_project()
{
- eval "`setvars "" cleanargs build_depend autoconfargs xtree postmake \
- makeargs btype mkhelper bootstrapargs premake release xlang xarch \
- badhash badtghash`"
+ cleanargs=""
+ build_depend=""
+ autoconfargs=""
+ xgcctree=""
+ postmake=""
+ makeargs=""
+ buildtype=""
+ mkhelper=""
+ bootstrapargs=""
+ premake=""
+ release=""
+ xlang=""
+ xarch=""
+ badhash=""
+ badtghash=""
_tcfg="$1/target.cfg"
if [ ! -f "$_tcfg" ]; then
- btype="auto"
+ buildtype="auto"
fi
# globally initialise all variables for a source tree / target:
if e "$datadir/mkhelper.cfg" f; then
- eval "`setcfg "$datadir/mkhelper.cfg"`"
+ . "$datadir/mkhelper.cfg" || \
+ err "Can't read '$datadir/mkhelper.cfg'" \
+ "configure_project" "$@"
fi
# override target/tree specific variables from per-target config:
@@ -231,9 +300,10 @@ configure_project()
rev=""
tree=""
- eval "`setcfg "$_tcfg"`"
+ . "$_tcfg" || \
+ err "Can't read '$_tcfg'" "configure_project" "$@"
- if [ "$_f" = "-d" ]; then
+ if [ "$flag" = "-d" ]; then
build_depend="" # dry run
fi
if [ "$cmd" = "build_project" ]; then
@@ -263,12 +333,13 @@ configure_project()
if [ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ]; then
return 1
fi
- if [ -n "$btype" ] && [ "${mode%config}" != "$mode" ]; then
+ if [ -n "$buildtype" ] && [ "${mode%config}" != "$mode" ]; then
return 1
fi
if [ -z "$mode" ]; then
- $dry build_dependencies; :
+ $if_not_dry_build \
+ build_dependencies
fi
mdir="$xbmkpwd/config/submodule/$project"
@@ -301,14 +372,16 @@ build_dependencies()
bd_tree="${bd##*/}"
if [ -z "$bd_project" ]; then
- $dry err "$project/$tree: !bd '$bd'" \
- "build_dependencies" "$@"
+ $if_not_dry_build \
+ err "$project/$tree: !bd '$bd'" \
+ "build_dependencies" "$@"
fi
if [ "${bd##*/}" = "$bd" ]; then
bd_tree=""
fi
if [ -n "$bd_project" ]; then
- $dry x_ ./mk -b $bd_project $bd_tree; :
+ $if_not_dry_build \
+ x_ ./mk -b $bd_project $bd_tree; :
fi
done; :
}
@@ -362,19 +435,20 @@ project_up_to_date()
x_ mkdir -p "$XBMK_CACHE/$hashdir"
if [ -f "$XBMK_CACHE/$hashdir/$project$hashname" ]; then
- read -r old_hash < \
- "$XBMK_CACHE/$hashdir/$project$hashname" \
+ read -r old_hash < "$XBMK_CACHE/$hashdir/$project$hashname" \
|| err \
"$hashdir: err '$XBMK_CACHE/$hashdir/$project$hashname'" \
"project_up_to_date" "$hashdir" "$hashname" "$badhashvar" \
"$@"
fi
- fx_ "x_ sha512sum" find "$@" -type f -not -path "*/.git*/*" | awk \
- '{print $1}' > "$xbtmp/tmp.hash" || err "!h $project $hashdir" \
+ build_sbase
+ fx_ "x_ util/sbase/sha512sum" find "$@" -type f -not -path \
+ "*/.git*/*" | awk '{print $1}' > "$xbtmp/tmp.hash" || \
+ err "!h $project $hashdir" \
"project_up_to_date" "$hashdir" "$hashname" "$badhashvar" "$@"
- hash="$(x_ sha512sum "$xbtmp/tmp.hash" | awk '{print $1}' || \
+ hash="$(x_ "$sha512sum" "$xbtmp/tmp.hash" | awk '{print $1}' || \
err)" || err "$hashname: Can't read sha512 of '$xbtmp/tmp.hash'" \
"project_up_to_date" "$hashdir" "$hashname" "$badhashvar" "$@"
@@ -397,8 +471,8 @@ check_cross_compiler()
if [ "$project" != "coreboot" ]; then
cbdir="src/coreboot/default"
fi
- if [ -n "$xtree" ]; then
- cbdir="src/coreboot/$xtree"
+ if [ -n "$xgcctree" ]; then
+ cbdir="src/coreboot/$xgcctree"
fi
xfix="${1%-*}"
@@ -421,14 +495,19 @@ check_cross_compiler()
fi
if [ -f "$xgccfile" ]; then
- return 0 # a build already exists
+ # skip the build, because a build already exists:
+
+ return 0
fi
check_gnu_path gcc gnat || x_ check_gnu_path gnat gcc
make -C "$cbdir" $xgccargs || x_ make -C "$cbdir" $xgccargs
+
+ # this tells subsequent runs that the build was already done:
x_ touch "$xgccfile"
- remkdir "$xbtmp/gnupath" # reset hostcc
+ # reset hostcc in PATH:
+ remkdir "$xbtmp/gnupath"
}
# fix mismatching gcc/gnat versions on debian trixie/sid. as of december 2024,
@@ -538,13 +617,17 @@ gnu_setver()
check_defconfig()
{
if [ ! -f "$defconfig" ]; then
- $dry err "$project/$target: missing defconfig" \
- "check_defconfig" "$@"
+ $if_not_dry_build \
+ err "$project/$target: no config" "check_defconfig" "$@"
fi
dest_dir="$elfdir/$tree/$target/${defconfig#"$target_dir/config/"}"
- $dry elfcheck || return 1; : # skip build if a previous one exists
+ # skip build if a previous one exists:
+
+ if ! $if_not_dry_build elfcheck; then
+ return 1
+ fi
}
elfcheck()
@@ -556,8 +639,10 @@ elfcheck()
handle_makefile()
{
- $dry check_makefile "$srcdir" && \
- $dry x_ make -C "$srcdir" $cleanargs clean
+ if $if_not_dry_build check_makefile "$srcdir"; then
+ $if_not_dry_build \
+ x_ make -C "$srcdir" $cleanargs clean
+ fi
if [ -f "$defconfig" ]; then
x_ cp "$defconfig" "$srcdir/.config"
@@ -573,12 +658,14 @@ handle_makefile()
fi
if [ "${mode%config}" != "$mode" ]; then
- $dry x_ cp "$srcdir/$_copy" "$defconfig"; :
+ $if_not_dry_build \
+ x_ cp "$srcdir/$_copy" "$defconfig"; :
fi
if [ -e "$srcdir/.git" ] && [ "$project" = "u-boot" ] && \
[ "$mode" = "distclean" ]; then
- $dry x_ git -C "$srcdir" $cleanargs clean -fdx; :
+ $if_not_dry_build \
+ x_ git -C "$srcdir" $cleanargs clean -fdx; :
fi
}
@@ -588,30 +675,46 @@ run_make_command()
x_ $premake
fi
- $dry check_cmake "$srcdir" && [ -z "$mode" ] && \
- $dry check_autoconf "$srcdir"
- $dry check_makefile "$srcdir" || return 1
+ if $if_not_dry_build check_cmake "$srcdir"; then
+ if [ -z "$mode" ]; then
+ $if_not_dry_build \
+ check_autoconf "$srcdir"
+ fi
+ fi
+ if ! $if_not_dry_build check_makefile "$srcdir"; then
+ return 1
+ fi
- $dry x_ make -C "$srcdir" $mode -j$XBMK_THREADS $makeargs
+ $if_not_dry_build \
+ x_ make -C "$srcdir" $mode -j$XBMK_THREADS $makeargs
if [ -z "$mode" ]; then
x_ $mkhelper
fi
- check_makefile "$srcdir" || return 0
+ if ! check_makefile "$srcdir"; then
+ return 0
+ fi
if [ "$mode" = "clean" ]; then
- $dry make -C "$srcdir" $cleanargs distclean || \
- $dry x_ make -C "$srcdir" $cleanargs clean; :
+ $if_not_dry_build \
+ make -C "$srcdir" $cleanargs distclean || \
+ $if_not_dry_build \
+ x_ make -C "$srcdir" $cleanargs clean; :
fi
}
check_cmake()
{
if [ -n "$cmakedir" ]; then
- $dry check_makefile "$1" || cmake -B "$1" \
- "$1/$cmakedir" || $dry x_ check_makefile "$1"
- $dry x_ check_makefile "$1"; :
+ if ! $if_not_dry_build check_makefile "$1"; then
+ if ! cmake -B "$1" "$1/$cmakedir"; then
+ $if_not_dry_build \
+ x_ check_makefile "$1"
+ fi
+ fi
+ $if_not_dry_build \
+ x_ check_makefile "$1"; :
fi
}
@@ -637,6 +740,7 @@ check_makefile()
{
if [ ! -f "$1/Makefile" ] && [ ! -f "$1/makefile" ] && \
[ ! -f "$1/GNUmakefile" ]; then
+
return 1
fi
}