mk: add forx function for shorthand loops

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-09-17 01:35:30 +01:00
parent 7c025e1036
commit 856551a36d
5 changed files with 30 additions and 29 deletions
+2 -5
View File
@@ -24,8 +24,7 @@ inject()
archive="$1";
new_mac="xx:xx:xx:xx:xx:xx"
nuke=""
xchanged=""
eval "`newvar nuke xchanged`"
[ $# -gt 1 ] && case "$2" in
nuke)
@@ -169,9 +168,7 @@ modify_mac()
x_ cp "${CONFIG_GBE_BIN_PATH##*../}" "$xbtmp/gbe"
if [ -n "$new_mac" ] && [ "$new_mac" != "restore" ]; then
x_ make -C util/nvmutil clean
x_ make -C util/nvmutil
forx 'x_ make -C util/nvmutil %s' clean nvmutil
x_ "$nvmutil" "$xbtmp/gbe" setmac "$new_mac"
fi
+1 -4
View File
@@ -131,10 +131,7 @@ mkcorebootbin()
return 0
$if_not_dry_build \
check_coreboot_util cbfstool
$if_not_dry_build \
check_coreboot_util ifdtool
forx 'check_coreboot_util %s' cbfstool ifdtool
for y in "$target_dir/config"/*; do
defconfig="$y"
+1 -4
View File
@@ -443,10 +443,7 @@ bootstrap()
x_ "$mk" -f coreboot "${cbdir##*/}"
x_ "$mk" -f me_cleaner
x_ "$mk" -b bios_extract
x_ "$mk" -b biosutilities
x_ "$mk" -b uefitool
x_ "$mk" -b libarchive # for bsdtar and bsdunzip
forx 'x_ \"$mk\" -b %s' bios_extract biosutilities uefitool libarchive
[ -d "${kbc1126_ec_dump%/*}" ] && \
x_ make -C "$cbdir/util/kbc1126"
+3 -9
View File
@@ -22,9 +22,7 @@ release()
x_ git clone . "$rsrc"
update_xbmkver "$rsrc"
prep_release src
prep_release tarball
prep_release bin
forx 'prep_release %s' src tarball bin
x_ rm -Rf "$rsrc"
@@ -55,8 +53,7 @@ prep_release_src()
x_ ./mk -f
fx_ "x_ rm -Rf" x_ find . -name ".git"
fx_ "x_ rm -Rf" x_ find . -name ".gitmodules"
forx 'fx_ \"x_ rm -Rf\" x_ find . -name \".%s\"' git gitmodules
( fx_ nuke x_ find config -type f -name "nuke.list" ) || \
err "can't prune project files" "prep_release_src" "$@"; :
@@ -93,10 +90,7 @@ prep_release_bin()
{
x_ ./mk -d coreboot
x_ ./mk -b coreboot
x_ ./mk -b pico-serprog
x_ ./mk -b stm32-vserprog
x_ ./mk -b pcsx-redux
forx 'x_ ./mk -b' coreboot pico-serprog stm32-vserprog pcsx-redux
fx_ mkrom_tarball x_ find bin -mindepth 1 -maxdepth 1 \
-type d -name "serprog_*"
+23 -7
View File
@@ -9,15 +9,27 @@
set -u -e
eval "`printf "LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE \
LC_MONETARY LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE \
LC_MEASUREMENT LC_IDENTIFICATION LC_ALL\n" | \
awk '{ for (i=1; i<=NF; i++) $i = "export " $i "=C.UTF-8;"; print }'`"
findpath()
{
eval "$(printf '%s\n' "$@" | awk '{printf "readlink -f \"%s\" \
2>/dev/null || realpath \"%s\" 2>/dev/null || return 1;",$0,$0}')"
forx 'readlink -f \"%s\" 2>/dev/null || \
x_ realpath \"%s\" 2>/dev/null' "$@"
}
# WARNING: relies on -o option in grep.
# gnu, busybox, openbsd, netbsd and freebsd all have it
forx()
{
awkarg="{printf \"${1-};\""
shift 1 2>/dev/null || :
scount="$(printf "%s\n" "$awkarg" | grep -o "%s" | wc -l)"
while [ $scount -gt 0 ]; do
awkarg="$awkarg,\$0"
scount="$(expr $scount - 1 || :)"
done
eval "$(printf '%s\n' "$@" | awk "$awkarg}")"
}
x_()
@@ -33,6 +45,10 @@ err()
exit 1
}
forx 'export %s=\"C.UTF-8\"' LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME \
LC_COLLATE LC_MONETARY LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS \
LC_TELEPHONE LC_MEASUREMENT LC_IDENTIFICATION LC_ALL
(
mk="$0"
[ "${mk##*/}" != "$mk" ] || \