From 2ae565ba93a84add3dd891e31e894d61cd4be42b Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Fri, 2 May 2025 05:54:36 +0100 Subject: init.sh: move setvars/err_ to lib.sh these functions make more sense in lib.sh i made mk link lib.sh first, so that the functions on init.sh can still use them. Signed-off-by: Leah Rowe --- mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mk') diff --git a/mk b/mk index 7b4d69ae..0ae35b6d 100755 --- a/mk +++ b/mk @@ -12,8 +12,9 @@ if [ "./${0##*/}" != "${0}" ] || [ ! -f "mk" ] || [ -L "mk" ]; then exit 1 fi -. "include/init.sh" . "include/lib.sh" + +. "include/init.sh" . "include/inject.sh" . "include/mrc.sh" -- cgit v1.2.1 From 1f7e4b35cb2e95c7bbf1e3d39b10189b26f8d6ed Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Fri, 2 May 2025 10:56:14 +0100 Subject: mk: Download vendorfiles before building release Do it just after creating the src archive. This way, everything is downloaded all at once. Otherwise, a momentary lapse of internet uptime will cause a release build to fail later on, and one of lbmk's flaws is that this would then mean you must re-build from scratch. If we assume that the internet is working within a short period of time, then this change would mitigate that possibility. If something did happen during tar archive creation, that's a much shorter amount of time that is "wasted". Signed-off-by: Leah Rowe --- mk | 1 + 1 file changed, 1 insertion(+) (limited to 'mk') diff --git a/mk b/mk index 0ae35b6d..ec42d097 100755 --- a/mk +++ b/mk @@ -85,6 +85,7 @@ build_release() touch "$srcdir/lock" || $err "can't make lock file in $srcdir/" ( cd "$srcdir" || $err "$vdir: 2 !cd \"$srcdir\"" + x_ ./mk -d coreboot mk -b coreboot pico-serprog stm32-vserprog pcsx-redux x_ mv bin ../roms ) || $err "can't build rom images" -- cgit v1.2.1 From 9b11e93686c6b8298a1b4be912da339ac60ba65f Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Fri, 2 May 2025 11:20:55 +0100 Subject: mk: include rom.sh directly remove it from mkhelper files, because rom.sh doesn't initialise any variables globally, except one that never changes. Signed-off-by: Leah Rowe --- mk | 1 + 1 file changed, 1 insertion(+) (limited to 'mk') diff --git a/mk b/mk index ec42d097..6a46f93c 100755 --- a/mk +++ b/mk @@ -17,6 +17,7 @@ fi . "include/init.sh" . "include/inject.sh" . "include/mrc.sh" +. "include/rom.sh" eval "`setvars "" vdir src_dirname srcdir mode`" -- cgit v1.2.1 From d18d1c2cae2c1c43c56d5c10adb469266d1eb08b Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sat, 3 May 2025 04:16:10 +0100 Subject: lbmk: unified execution on find commands We have a lot of places in lbmk where the output of find is used, and then some function is executed on the result. This is messy, and bloats several of these functions. Now this is unified, into a new function: fx_ What fx_ does is execute a given function, for each result found, with the arguments for a find command appended. For example: find -name ".git" If you wanted to do: foo "$arg" Where "arg" is a search result from find, and you wanted to execute "foo" on each one, you would do: fx_ foo -name ".git" The find utility does have an -exec feature, but I've found that it only works for executables, not functions. fx_ does not return errors, so "foo" in this example would have to do its own error handling. Signed-off-by: Leah Rowe --- mk | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'mk') diff --git a/mk b/mk index 6a46f93c..8884d61e 100755 --- a/mk +++ b/mk @@ -278,20 +278,9 @@ check_project_hashes() [ ! -f "$XBMK_CACHE/hash/$project$tree" ] || \ read -r old_pjhash < "$XBMK_CACHE/hash/$project$tree" - x_ rm -f "$xbmktmp/project.list" "$xbmktmp/project.hash" \ - "$xbmktmp/project.tmp" - x_ touch "$xbmktmp/project.tmp" "$xbmktmp/project.hash" - - for rmchk in "$datadir" "$configdir/$tree" "$mdir"; do - [ ! -d "$rmchk" ] || find "$rmchk" -type f -not -path \ - "*/.git*/*" >> "$xbmktmp/project.tmp" || $err "!fh $rmchk" - done - sort "$xbmktmp/project.tmp" > "$xbmktmp/project.list" || $err "!pj srt" - - while read -r rmchk; do - [ ! -f "$rmchk" ] || x_ sha512sum "$rmchk" | awk \ - '{print $1}' >> "$xbmktmp/project.hash" || $err "!h $rmchk" - done < "$xbmktmp/project.list" + x_ rm -f "$xbmktmp/project.hash" + fx_ create_project_hash "$datadir" "$configdir/$tree" "$mdir" \ + -type f -not -path "*/.git*/*" pjhash="$(sha512sum "$xbmktmp/project.hash" | awk '{print $1}')" || : [ "$pjhash" != "$old_pjhash" ] && badhash="y" @@ -304,6 +293,12 @@ check_project_hashes() "elf/$project/$tree" "elf/$project/$target"; : } +create_project_hash() +{ + [ ! -f "$1" ] || x_ sha512sum "$1" | awk \ + '{print $1}' >> "$xbmktmp/project.hash" || $err "!h $1"; : +} + check_cross_compiler() { xgccargs="UPDATED_SUBMODULES=1 CPUS=$XBMK_THREADS" -- cgit v1.2.1 From 00d22f20829251f55cd2e859d6fae9a61220c072 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sat, 3 May 2025 06:53:25 +0100 Subject: lbmk: Unified local ./tmp handling Make it an absolute directory, relative to xbmktmp. Signed-off-by: Leah Rowe --- mk | 1 - 1 file changed, 1 deletion(-) (limited to 'mk') diff --git a/mk b/mk index 8884d61e..312ffce3 100755 --- a/mk +++ b/mk @@ -68,7 +68,6 @@ build_release() cd "$srcdir" || $err "$vdir: !cd \"$srcdir\"" ./mk -f - x_ rm -Rf tmp rmgit . x_ mv src/docs docs ) || $err "can't create release files" -- cgit v1.2.1 From 7a2f33264d713919bee5a6a4422f3664474b3420 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sat, 3 May 2025 18:04:47 +0100 Subject: mk: simplify check_gnu_path() the initial checks are unnecessary, since i always know what arguments are being provided. the -f check in the for loop is now an -x instead, more efficient and complete. Signed-off-by: Leah Rowe --- mk | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'mk') diff --git a/mk b/mk index 312ffce3..06a77522 100755 --- a/mk +++ b/mk @@ -332,35 +332,25 @@ check_cross_compiler() # 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" || : + x_ gnu_setver "$1" "$1" && 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 + for _bin in "$_gnudir/$2-"*; do + [ "${_bin#"$_gnudir/$2-"}" = "$_gnuver" ] && [ -x "$_bin" ] \ + && _gnuver="${_bin#"$_gnudir/$2-"}" && break; : done gnu_setver "$2" "$_gnudir/$2-$_gnuver" || return 1 [ "$gnatfull" = "$gccfull" ] || return 1 ( - rm -f "$XBMK_CACHE/gnupath/"* || $err "Cannot clear gnupath/" - cd "$XBMK_CACHE/gnupath" || $err "Can't cd to gnupath/" + remkdir "$XBMK_CACHE/gnupath" && x_ cd "$XBMK_CACHE/gnupath" for _gnubin in "$_gnudir/$2"*"-$_gnuver"; do _gnuutil="${_gnubin##*/}" && [ -e "$_gnubin" ] && \ x_ ln -s "$_gnubin" "${_gnuutil%"-$_gnuver"}" -- cgit v1.2.1 From 8f828e6cd35d82b0a0fa20b202d49ab092161fa3 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sat, 3 May 2025 18:14:59 +0100 Subject: mk: tidy up check_project_hashes() sha512sum check the extra function isn't needed at all. awk can just handle every line all at once. Signed-off-by: Leah Rowe --- mk | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'mk') diff --git a/mk b/mk index 06a77522..2020115b 100755 --- a/mk +++ b/mk @@ -277,9 +277,9 @@ check_project_hashes() [ ! -f "$XBMK_CACHE/hash/$project$tree" ] || \ read -r old_pjhash < "$XBMK_CACHE/hash/$project$tree" - x_ rm -f "$xbmktmp/project.hash" - fx_ create_project_hash "$datadir" "$configdir/$tree" "$mdir" \ - -type f -not -path "*/.git*/*" + fx_ sha512sum "$datadir" "$configdir/$tree" "$mdir" \ + -type f -not -path "*/.git*/*" | awk '{print $1}' > \ + "$xbmktmp/project.hash" || $err "!h $project $tree" pjhash="$(sha512sum "$xbmktmp/project.hash" | awk '{print $1}')" || : [ "$pjhash" != "$old_pjhash" ] && badhash="y" @@ -292,12 +292,6 @@ check_project_hashes() "elf/$project/$tree" "elf/$project/$target"; : } -create_project_hash() -{ - [ ! -f "$1" ] || x_ sha512sum "$1" | awk \ - '{print $1}' >> "$xbmktmp/project.hash" || $err "!h $1"; : -} - check_cross_compiler() { xgccargs="UPDATED_SUBMODULES=1 CPUS=$XBMK_THREADS" -- cgit v1.2.1 From aa4083443b14335c8ada088034434b584aacc789 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sat, 3 May 2025 18:30:37 +0100 Subject: mk: Allow use of x_ on prefix functions Use this for the sha512sum command, on the main mk script at the function check_project_hashes(). Signed-off-by: Leah Rowe --- mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mk') diff --git a/mk b/mk index 2020115b..28a4cb0c 100755 --- a/mk +++ b/mk @@ -277,7 +277,7 @@ check_project_hashes() [ ! -f "$XBMK_CACHE/hash/$project$tree" ] || \ read -r old_pjhash < "$XBMK_CACHE/hash/$project$tree" - fx_ sha512sum "$datadir" "$configdir/$tree" "$mdir" \ + fx_ "x_ sha512sum" "$datadir" "$configdir/$tree" "$mdir" \ -type f -not -path "*/.git*/*" | awk '{print $1}' > \ "$xbmktmp/project.hash" || $err "!h $project $tree" -- cgit v1.2.1 From c33467df1e6119e07608e4e35193815bd2050b1c Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 4 May 2025 08:02:14 +0100 Subject: mk: reduce indentation in check_cross_compiler() we only call it in one place. the resulting code is still quite clear. Signed-off-by: Leah Rowe --- mk | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'mk') diff --git a/mk b/mk index 28a4cb0c..765772b4 100755 --- a/mk +++ b/mk @@ -211,7 +211,9 @@ handle_defconfig() if [ "$mode" = "distclean" ] || [ "$mode" = "crossgcc-clean" ]; then [ -d "$srcdir" ] || return 0 fi - [ -z "$mode" ] && $dry check_cross_compiler + [ -z "$mode" ] && for _xarch in $xarch; do + $dry check_cross_compiler "$_xarch" + done; : for y in "$target_dir/config"/*; do [ "$_f" = "-d" ] || [ -f "$y" ] || continue @@ -295,29 +297,28 @@ check_project_hashes() check_cross_compiler() { xgccargs="UPDATED_SUBMODULES=1 CPUS=$XBMK_THREADS" - for _xarch in $xarch; do - cbdir="src/coreboot/$tree" - [ "$project" != "coreboot" ] && cbdir="src/coreboot/default" - [ -n "$xtree" ] && cbdir="src/coreboot/$xtree" - x_ ./mk -f coreboot "${cbdir#src/coreboot/}" + cbdir="src/coreboot/$tree" + [ "$project" != "coreboot" ] && cbdir="src/coreboot/default" + [ -n "$xtree" ] && cbdir="src/coreboot/$xtree" - export PATH="$xbmkpwd/$cbdir/util/crossgcc/xgcc/bin:$PATH" - export CROSS_COMPILE="${xarch% *}-" - [ -n "$xlang" ] && export BUILD_LANGUAGES="$xlang" + x_ ./mk -f coreboot "${cbdir#src/coreboot/}" - xfix="${_xarch%-*}" && [ "$xfix" = "x86_64" ] && xfix="x64" + export PATH="$xbmkpwd/$cbdir/util/crossgcc/xgcc/bin:$PATH" + export CROSS_COMPILE="${xarch% *}-" + [ -n "$xlang" ] && export BUILD_LANGUAGES="$xlang" - # match gnat-X to gcc - check_gnu_path gcc gnat || x_ check_gnu_path gnat gcc + xfix="${1%-*}" && [ "$xfix" = "x86_64" ] && xfix="x64" - # sometimes buildgcc fails for like no reason. try twice. - make -C "$cbdir" crossgcc-$xfix $xgccargs || \ - x_ make -C "$cbdir" crossgcc-$xfix $xgccargs + # match gnat-X to gcc + check_gnu_path gcc gnat || x_ check_gnu_path gnat gcc - # we only want to mess with hostcc to build xgcc - rm -f "$XBMK_CACHE/gnupath/"* || $err "Can't clear gnupath/"; : - done; : + # sometimes buildgcc fails for like no reason. try twice. + make -C "$cbdir" crossgcc-$xfix $xgccargs || \ + x_ make -C "$cbdir" crossgcc-$xfix $xgccargs + + # we only want to mess with hostcc to build xgcc + rm -f "$XBMK_CACHE/gnupath/"* || $err "Can't clear gnupath/"; : } # fix mismatching gcc/gnat versions on debian trixie/sid. as of december 2024, -- cgit v1.2.1 From 488d52e784f4520f679e5823ff2c48057037cbd8 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 4 May 2025 08:04:36 +0100 Subject: mk: re-make gnupath/ for each cross compiler it could be that some were left over before, for some reason. that isn't currently the case, but this will avoid the possibility in future. therefore, this is a preemptive bug fix. Signed-off-by: Leah Rowe --- mk | 1 + 1 file changed, 1 insertion(+) (limited to 'mk') diff --git a/mk b/mk index 765772b4..4d7cf116 100755 --- a/mk +++ b/mk @@ -296,6 +296,7 @@ check_project_hashes() check_cross_compiler() { + remkdir "$XBMK_CACHE/gnupath" xgccargs="UPDATED_SUBMODULES=1 CPUS=$XBMK_THREADS" cbdir="src/coreboot/$tree" -- cgit v1.2.1 From 1b7a9fd637d2ca98d1da5ded0e2090bd311b4b8c Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 4 May 2025 08:07:06 +0100 Subject: mk: tidy up check_cross_compiler only initialise variables at the point they're needed. Signed-off-by: Leah Rowe --- mk | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'mk') diff --git a/mk b/mk index 4d7cf116..2dd9379b 100755 --- a/mk +++ b/mk @@ -297,7 +297,6 @@ check_project_hashes() check_cross_compiler() { remkdir "$XBMK_CACHE/gnupath" - xgccargs="UPDATED_SUBMODULES=1 CPUS=$XBMK_THREADS" cbdir="src/coreboot/$tree" [ "$project" != "coreboot" ] && cbdir="src/coreboot/default" @@ -309,12 +308,11 @@ check_cross_compiler() export CROSS_COMPILE="${xarch% *}-" [ -n "$xlang" ] && export BUILD_LANGUAGES="$xlang" - xfix="${1%-*}" && [ "$xfix" = "x86_64" ] && xfix="x64" - # match gnat-X to gcc check_gnu_path gcc gnat || x_ check_gnu_path gnat gcc - # sometimes buildgcc fails for like no reason. try twice. + xfix="${1%-*}" && [ "$xfix" = "x86_64" ] && xfix="x64" + xgccargs="UPDATED_SUBMODULES=1 CPUS=$XBMK_THREADS" make -C "$cbdir" crossgcc-$xfix $xgccargs || \ x_ make -C "$cbdir" crossgcc-$xfix $xgccargs -- cgit v1.2.1 From f5b2bdb88681bd16f2a32c8fb3f51cfc65da9448 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 4 May 2025 08:07:53 +0100 Subject: mk: re-make gnupath/ after handling crossgcc instead of deleting every file within Signed-off-by: Leah Rowe --- mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mk') diff --git a/mk b/mk index 2dd9379b..c87acfe7 100755 --- a/mk +++ b/mk @@ -317,7 +317,7 @@ check_cross_compiler() x_ make -C "$cbdir" crossgcc-$xfix $xgccargs # we only want to mess with hostcc to build xgcc - rm -f "$XBMK_CACHE/gnupath/"* || $err "Can't clear gnupath/"; : + remkdir "$XBMK_CACHE/gnupath" } # fix mismatching gcc/gnat versions on debian trixie/sid. as of december 2024, -- cgit v1.2.1 From 184871bc17cdc5716d8d8bcfff03b0f7412b7a1a Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 4 May 2025 08:10:59 +0100 Subject: mk: remove useless code this was added a few commits ago, but the previous commit made me realise it's not needed at all. Signed-off-by: Leah Rowe --- mk | 2 -- 1 file changed, 2 deletions(-) (limited to 'mk') diff --git a/mk b/mk index c87acfe7..49cebaf1 100755 --- a/mk +++ b/mk @@ -296,8 +296,6 @@ check_project_hashes() check_cross_compiler() { - remkdir "$XBMK_CACHE/gnupath" - cbdir="src/coreboot/$tree" [ "$project" != "coreboot" ] && cbdir="src/coreboot/default" [ -n "$xtree" ] && cbdir="src/coreboot/$xtree" -- cgit v1.2.1 From fc71e52fdfc559d207ea54059a86edb81e928e33 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 4 May 2025 08:14:44 +0100 Subject: mk: tidy up xgccargs handling Signed-off-by: Leah Rowe --- mk | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'mk') diff --git a/mk b/mk index 49cebaf1..5a4afadf 100755 --- a/mk +++ b/mk @@ -310,9 +310,8 @@ check_cross_compiler() check_gnu_path gcc gnat || x_ check_gnu_path gnat gcc xfix="${1%-*}" && [ "$xfix" = "x86_64" ] && xfix="x64" - xgccargs="UPDATED_SUBMODULES=1 CPUS=$XBMK_THREADS" - make -C "$cbdir" crossgcc-$xfix $xgccargs || \ - x_ make -C "$cbdir" crossgcc-$xfix $xgccargs + xgccargs="crossgcc-$xfix UPDATED_SUBMODULES=1 CPUS=$XBMK_THREADS" + make -C "$cbdir" $xgccargs || x_ make -C "$cbdir" $xgccargs # we only want to mess with hostcc to build xgcc remkdir "$XBMK_CACHE/gnupath" -- cgit v1.2.1 From 54291ebb7209c314bb52f507bc6a1ecf2a28fbc9 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 4 May 2025 09:56:21 +0100 Subject: lbmk: MUCH safer err function Don't directly call a variable. Call a function that checks the variable instead. The new err function also checks whether an exit was actually done, and exits 1 if not. If an exit was done by the given function, but the exit was zero, this is also corrected to perform an exit 1. This fixes a longstanding design flaw of lbmk. Signed-off-by: Leah Rowe --- mk | 68 ++++++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'mk') diff --git a/mk b/mk index 5a4afadf..55f67a92 100755 --- a/mk +++ b/mk @@ -29,7 +29,7 @@ main() version) printf "%s\nWebsite: %s\n" "$relname" "$projectsite" ;; release|download|inject) $cmd "$@" ;; -*) return 1 ;; - *) $err "bad command" ;; + *) err "bad command" ;; esac set -u -e # some commands disable them. turn them on! } @@ -40,11 +40,11 @@ release() vdir="release" while getopts d:m: option; do - [ -z "$OPTARG" ] && $err "empty argument not allowed" + [ -z "$OPTARG" ] && err "empty argument not allowed" case "$option" in d) vdir="$OPTARG" ;; m) mode="$OPTARG" ;; - *) $err "invalid option '-$option'" ;; + *) err "invalid option '-$option'" ;; esac done @@ -52,10 +52,10 @@ release() src_dirname="${relname}_src" srcdir="$vdir/$src_dirname" - [ -e "$vdir" ] && $err "already exists: \"$vdir\"" - mkdir -p "$vdir" || $err "mkvdir: !mkdir -p \"$vdir\"" - git clone . "$srcdir" || $err "mkdir: !gitclone \"$srcdir\"" - touch "$srcdir/lock" || $err "can't make lock file in $srcdir/" + [ -e "$vdir" ] && err "already exists: \"$vdir\"" + mkdir -p "$vdir" || err "mkvdir: !mkdir -p \"$vdir\"" + git clone . "$srcdir" || err "mkdir: !gitclone \"$srcdir\"" + touch "$srcdir/lock" || err "can't make lock file in $srcdir/" build_release @@ -65,32 +65,32 @@ release() build_release() { ( - cd "$srcdir" || $err "$vdir: !cd \"$srcdir\"" + cd "$srcdir" || err "$vdir: !cd \"$srcdir\"" ./mk -f rmgit . x_ mv src/docs docs - ) || $err "can't create release files" + ) || err "can't create release files" git log --graph --pretty=format:'%Cred%h%Creset %s %Creset' \ - --abbrev-commit > "$srcdir/CHANGELOG" || $err "!gitlog $srcdir" - rm -f "$srcdir/lock" || $err "can't remove lock file in $srcdir" + --abbrev-commit > "$srcdir/CHANGELOG" || err "!gitlog $srcdir" + rm -f "$srcdir/lock" || err "can't remove lock file in $srcdir" ( - cd "${srcdir%/*}" || $err "$vdir: mktarball \"$srcdir\"" - mktarball "${srcdir##*/}" "${srcdir##*/}.tar.xz" || $err "$vdir: mksrc" - ) || $err "can't create src tarball" + cd "${srcdir%/*}" || err "$vdir: mktarball \"$srcdir\"" + mktarball "${srcdir##*/}" "${srcdir##*/}.tar.xz" || err "$vdir: mksrc" + ) || err "can't create src tarball" [ "$mode" = "src" ] && return 0 - touch "$srcdir/lock" || $err "can't make lock file in $srcdir/" + touch "$srcdir/lock" || err "can't make lock file in $srcdir/" ( - cd "$srcdir" || $err "$vdir: 2 !cd \"$srcdir\"" + cd "$srcdir" || err "$vdir: 2 !cd \"$srcdir\"" x_ ./mk -d coreboot mk -b coreboot pico-serprog stm32-vserprog pcsx-redux x_ mv bin ../roms - ) || $err "can't build rom images" + ) || err "can't build rom images" - rm -Rf "$srcdir" || $err "!rm -Rf $srcdir" + rm -Rf "$srcdir" || err "!rm -Rf $srcdir" } main "$@" && exit 0 @@ -110,7 +110,7 @@ trees() flags="f:b:m:u:c:x:s:l:n:d:" while getopts $flags option; do - [ -n "$_f" ] && $err "only one flag is permitted" + [ -n "$_f" ] && err "only one flag is permitted" _f="$1" case "$_f" in @@ -126,7 +126,7 @@ trees() -s) mode="savedefconfig" ;; -l) mode="olddefconfig" ;; -n) mode="nconfig" ;; - *) $err "invalid option '-$option'" ;; + *) err "invalid option '-$option'" ;; esac if [ -z "${OPTARG+x}" ]; then @@ -137,14 +137,14 @@ trees() project="${OPTARG#src/}" shift 2 done - [ -z "$_f" ] && $err "missing flag ($flags)" + [ -z "$_f" ] && err "missing flag ($flags)" if [ -z "$project" ]; then mk $_f $(ls -1 config/git) return 1 fi [ -f "config/git/$project/pkg.cfg" ] || \ - $err "config/git/$project/pkg.cfg missing" + err "config/git/$project/pkg.cfg missing" for d in "elf" "config/data" "config" "src"; do eval "${d#*/}dir=\"$d/$project\"" @@ -180,8 +180,8 @@ build_project() build_targets() { - [ -d "$configdir" ] || $err "directory, $configdir, does not exist" - [ $# -gt 0 ] || targets="$(ls -1 "$configdir")" || $err "!o $configdir" + [ -d "$configdir" ] || err "directory, $configdir, does not exist" + [ $# -gt 0 ] || targets="$(ls -1 "$configdir")" || err "!o $configdir" for x in $targets; do unset CROSS_COMPILE @@ -267,7 +267,7 @@ build_dependencies() for bd in $build_depend; do bd_p="${bd%%/*}" bd_t="${bd##*/}" - [ -z "$bd_p" ] && $dry $err "$project/$tree: !bd '$bd'" + [ -z "$bd_p" ] && $dry err "$project/$tree: !bd '$bd'" [ "${bd##*/}" = "$bd" ] && bd_t="" [ -z "$bd_p" ] || $dry x_ ./mk -b $bd_p $bd_t; : done; : @@ -281,14 +281,14 @@ check_project_hashes() fx_ "x_ sha512sum" "$datadir" "$configdir/$tree" "$mdir" \ -type f -not -path "*/.git*/*" | awk '{print $1}' > \ - "$xbmktmp/project.hash" || $err "!h $project $tree" + "$xbmktmp/project.hash" || err "!h $project $tree" pjhash="$(sha512sum "$xbmktmp/project.hash" | awk '{print $1}')" || : [ "$pjhash" != "$old_pjhash" ] && badhash="y" [ -f "$XBMK_CACHE/hash/$project$tree" ] || badhash="y" printf "%s\n" "$pjhash" > "$XBMK_CACHE/hash/$project$tree" || \ - $err "!mk $XBMK_CACHE/hash/$project$tree" + err "!mk $XBMK_CACHE/hash/$project$tree" [ "$badhash" != "y" ] || x_ rm -Rf "src/$project/$tree" \ "elf/$project/$tree" "elf/$project/$target"; : @@ -323,12 +323,12 @@ check_cross_compiler() # gnat in PATH never resolves to gnat-14, because gnat-14 was "experimental" check_gnu_path() { - command -v "$1" 1>/dev/null || $err "Host '$1' unavailable" + command -v "$1" 1>/dev/null || err "Host '$1' unavailable" eval "`setvars "" gccver gccfull gnatver gnatfull gccdir gnatdir`" x_ gnu_setver "$1" "$1" && gnu_setver "$2" "$2" || : - eval "[ -z \"\$$1ver\" ] && $err \"Cannot detect host '$1' version\"" + eval "[ -z \"\$$1ver\" ] && err \"Cannot detect host '$1' version\"" [ "$gnatfull" = "$gccfull" ] && return 0 eval "$1dir=\"$(dirname "$(command -v "$1")")\"" @@ -346,7 +346,7 @@ check_gnu_path() _gnuutil="${_gnubin##*/}" && [ -e "$_gnubin" ] && \ x_ ln -s "$_gnubin" "${_gnuutil%"-$_gnuver"}" done - ) || $err "Cannot create $2-$_gnuver link in $_gnudir"; : + ) || err "Cannot create $2-$_gnuver link in $_gnudir"; : } gnu_setver() @@ -360,7 +360,7 @@ gnu_setver() check_defconfig() { - [ -f "$defconfig" ] || $dry $err "$project/$target: missing defconfig" + [ -f "$defconfig" ] || $dry err "$project/$target: missing defconfig" dest_dir="$elfdir/$target/${defconfig#"$target_dir/config/"}" $dry elfcheck || return 1 # skip build if a previous one exists @@ -383,7 +383,7 @@ handle_makefile() [ -n "$mode" ] || [ -n "$btype" ] || $dry make -C \ "$srcdir" silentoldconfig || make -C "$srcdir" oldconfig || : - run_make_command || $err "handle_makefile $srcdir: no makefile!" + run_make_command || err "handle_makefile $srcdir: no makefile!" _copy=".config" && [ "$mode" = "savedefconfig" ] && _copy="defconfig" [ "${mode%config}" = "$mode" ] || \ @@ -419,11 +419,11 @@ check_cmake() check_autoconf() { ( - cd "$1" || $err "!cd $1" + cd "$1" || err "!cd $1" [ -f "bootstrap" ] && x_ ./bootstrap $bootstrapargs [ -f "autogen.sh" ] && x_ ./autogen.sh $autogenargs [ -f "configure" ] && x_ ./configure $autoconfargs; : - ) || $err "can't bootstrap project: $1"; : + ) || err "can't bootstrap project: $1"; : } check_makefile() -- cgit v1.2.1 From 6b247c93e25f7283524edb6b6e19ca3296c78006 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 5 May 2025 11:54:23 +0100 Subject: mk: Fix bad error handling for gnu_setver I mixed logical OR and AND by mistake. Oops! Signed-off-by: Leah Rowe --- mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mk') diff --git a/mk b/mk index 55f67a92..dcf135a1 100755 --- a/mk +++ b/mk @@ -326,7 +326,8 @@ check_gnu_path() command -v "$1" 1>/dev/null || err "Host '$1' unavailable" eval "`setvars "" gccver gccfull gnatver gnatfull gccdir gnatdir`" - x_ gnu_setver "$1" "$1" && gnu_setver "$2" "$2" || : + x_ 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 -- cgit v1.2.1 From c2182d821939a7d3c3e8ff2b6ff96e9e44ff96fa Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 5 May 2025 15:51:04 +0100 Subject: mk: simplify elfcheck() fe_() called inside subshell, ftw Signed-off-by: Leah Rowe --- mk | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'mk') diff --git a/mk b/mk index dcf135a1..08ac22a2 100755 --- a/mk +++ b/mk @@ -370,10 +370,8 @@ check_defconfig() elfcheck() { - # TODO: very hacky check. do it properly (based on build.list) - for elftest in "$dest_dir"/*; do - [ -e "$elftest" ] && e "$elftest" f && return 1 - done; : + # TODO: *STILL* very hacky check. do it properly (based on build.list) + ( fe_ "exit 1" "$dest_dir" -type f ) || return 1; : } handle_makefile() -- cgit v1.2.1 From f98e34a24dd21ebafbfac2e019d3a4bc1cf500cb Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 5 May 2025 20:33:02 +0100 Subject: singletree/elfcheck: use fx_, not fe_ fe_ returns an error on the find command, but we rely on the only error ever being our intentional exit, upon discovering files. in singletree, the directory being checked was already checked first, so we know it's safe not to err on find; and find not reporting an error if no files are found is ok. on elfcheck, it's very much the same thing. In fact, we very much want it to return 0 if the directory doesn't exist, or if files don't exist within it. Therefore, use fx_ which is designed for this use-case. Quick re-cap: fx and fe execute a given function name with each line outputting by find as an argument, each time. It is somewhat similar in scope to find's -exec command. We use fe_ as shorthand in several places all over lbmk. Signed-off-by: Leah Rowe --- mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mk') diff --git a/mk b/mk index 08ac22a2..a438d653 100755 --- a/mk +++ b/mk @@ -371,7 +371,7 @@ check_defconfig() elfcheck() { # TODO: *STILL* very hacky check. do it properly (based on build.list) - ( fe_ "exit 1" "$dest_dir" -type f ) || return 1; : + ( fx_ "exit 1" "$dest_dir" -type f ) || return 1; : } handle_makefile() -- cgit v1.2.1