From 355a45b435ba6ef1dbceddf4d2cbeef9517ff370 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sat, 20 May 2023 17:53:03 +0100 Subject: build/cbutils: top-down coding style, main on top Signed-off-by: Leah Rowe --- resources/scripts/build/module/cbutils | 66 ++++++++++++++++------------------ 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/resources/scripts/build/module/cbutils b/resources/scripts/build/module/cbutils index a24cac02..487e4fd9 100755 --- a/resources/scripts/build/module/cbutils +++ b/resources/scripts/build/module/cbutils @@ -18,40 +18,31 @@ # along with this program. If not, see . # -# This script assumes that the current working directory is the root - [ "x${DEBUG+set}" = 'xset' ] && set -v set -u -e printf "Building coreboot utils\n" -buildutils() { - cbtree="${1}" - if [ ! -d "coreboot/${cbtree}/" ]; then - ./download coreboot $cbtree || return 1 - fi - if [ ! -d "coreboot/${cbtree}/" ]; then - printf "build/cbutils: coreboot/%s not found. Exiting\n" \ - "${cbtree}" - return 1 +main() +{ + if [ $# -gt 0 ]; then + for board in "${@}"; do + buildfromboardconfig ${board} || exit 1 + done + else + for boarddir in resources/coreboot/*; do + [ ! -d "${boarddir}" ] && continue + buildfromboardconfig ${boarddir##*/} || exit 1 + done fi - for util in cbfstool ifdtool; do - ( - cd "coreboot/${cbtree}/util/${util}/" - make -j$(nproc) || return 1 - ) - done - return 0 } buildfromboardconfig() { board="${1}" - if [ ! -d "resources/coreboot/${board}" ]; then + [ ! -d "resources/coreboot/${board}" ] && \ continue - fi - if [ ! -f "resources/coreboot/${board}/board.cfg" ]; then + [ ! -f "resources/coreboot/${board}/board.cfg" ] && \ continue - fi cbtree="undefined" . "resources/coreboot/${board}/board.cfg" # source if [ "${cbtree}" = "undefined" ]; then @@ -60,21 +51,24 @@ buildfromboardconfig() { return 1 fi buildutils "${cbtree}" || return 1 - return 0 } -if [ $# -gt 0 ]; then - for board in "${@}"; do - buildfromboardconfig ${board} || exit 1 - done -else - for boarddir in resources/coreboot/*; do - if [ ! -d "${boarddir}" ]; then - continue - fi - buildfromboardconfig ${boarddir##*/} || exit 1 +buildutils() { + cbtree="${1}" + if [ ! -d "coreboot/${cbtree}/" ]; then + ./download coreboot $cbtree || return 1 + fi + if [ ! -d "coreboot/${cbtree}/" ]; then + printf "build/cbutils: coreboot/%s not found. Exiting\n" \ + "${cbtree}" + return 1 + fi + for util in cbfstool ifdtool; do + ( + cd "coreboot/${cbtree}/util/${util}/" + make -j$(nproc) || return 1 + ) done -fi +} -printf "\n\n" -exit 0 +main $@ -- cgit v1.2.1