summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-12-23 16:16:26 +0000
committerLeah Rowe <leah@libreboot.org>2023-12-23 17:51:32 +0000
commit655d3cdc881f72d2fdd0797ad92edae2f36ac73e (patch)
tree1b93dd5c3ea6ccc88af19871cabf9d9028cc6131
parent25f9d9480fb61e0dd860560d46d8d433565aeb01 (diff)
lbmk scripts: general code cleanup/optimisation
Signed-off-by: Leah Rowe <leah@libreboot.org>
-rwxr-xr-xbuild21
-rwxr-xr-xinclude/err.sh21
-rwxr-xr-xscript/build/roms40
3 files changed, 30 insertions, 52 deletions
diff --git a/build b/build
index e06c1cea..ac6db677 100755
--- a/build
+++ b/build
@@ -37,22 +37,16 @@ main()
{
xx_ id -u 1>/dev/null 2>/dev/null
[ $# -lt 1 ] && fail "Too few arguments. Try: ${0} help"
- if [ "${1}" = "dependencies" ]; then
- xx_ install_packages $@
- lbmk_exit 0
- fi
-
- initialise_command $@ && shift 1
- check_git
- check_project
- git_init
+ [ "${1}" = "dependencies" ] && xx_ install_packages $@ && lbmk_exit 0
- execute_command $@
+ for cmd in initcmd check_git check_project git_init excmd; do
+ eval "${cmd} \$@"
+ done
lbmk_exit 0
}
-initialise_command()
+initcmd()
{
[ "$(id -u)" != "0" ] || fail "this command as root is not permitted"
@@ -104,11 +98,12 @@ git_init()
fail "${PWD}: cannot git-tag ${projectname}/${version}"
}
-execute_command()
+excmd()
{
lbmkcmd="${buildpath}/${option}"
+ echo "TEST: $lbmkcmd"
[ -f "${lbmkcmd}" ] || fail "Invalid command. Run: ${linkpath} help"
- "${lbmkcmd}" $@ || fail "execute_command: ${lbmkcmd} ${@}"
+ shift 1; "$lbmkcmd" $@ || fail "excmd: ${lbmkcmd} ${@}"
}
usage()
diff --git a/include/err.sh b/include/err.sh
index 6a8afd41..b7a273a6 100755
--- a/include/err.sh
+++ b/include/err.sh
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2022, 2023 Leah Rowe <leah@libreboot.org>
-version=""; versiondate=""; projectname=""; _nogit=""
+version=""; version_=""; versiondate=""; versiondate_=""; projectname=""; _nogit=""
x_() {
[ $# -lt 1 ] || ${@} || err_exit err ${@}
@@ -48,17 +48,11 @@ check_project()
[ ! -e ".git" ] || versiondate="$(git show --no-patch --no-notes \
--pretty='%ct' HEAD)" || versiondate="${versiondate_}"
- [ -n "${versiondate}" ] || fail "Unknown version date" || \
- err "Unknown version date"
- [ -n "${version}" ] || fail "Unknown version" || \
- err "Unknown version"
- [ -n "${projectname}" ] || fail "Unknown project" || \
- err "Unknown project"
-
- xx_ printf "%s\n" "${version}" > version || \
- x_ printf "%s\n" "${version}" > version
- xx_ printf "%s\n" "${versiondate}" > versiondate || \
- x_ printf "%s\n" "${versiondate}" > versiondate
+ for p in projectname version versiondate; do
+ eval "[ -n \"\$$p\" ] || fail \"$p unset\" || err \"$p unset\""
+ p_="x_ printf \"%s\\n\" \"\$$p\" > $p"
+ eval "x$p_ || $p_"
+ done
export LOCALVERSION="-${projectname}-${version%%-*}"
}
@@ -67,8 +61,7 @@ setvars()
{
_setvars=""
[ $# -lt 2 ] && err "setvars: too few arguments"
- val="${1}"
- shift 1
+ val="${1}" && shift 1
for var in $@; do
_setvars="${var}=\"${val}\"; ${_setvars}"
done
diff --git a/script/build/roms b/script/build/roms
index 068e063d..834a2fdd 100755
--- a/script/build/roms
+++ b/script/build/roms
@@ -21,7 +21,7 @@ kmapdir="config/grub/keymap"
# target.cfg files have to specifically enable [a] payload(s)
pv="payload_grub payload_grub_withseabios payload_seabios payload_memtest t"
pv="${pv} payload_seabios_withgrub payload_seabios_grubonly payload_uboot memtest_bin"
-v="romdir cbrom initmode displaymode cbcfg targetdir tree arch"
+v="romdir cbrom initmode displaymode cbcfg targetdir tree arch keymaps"
v="${v} grub_timeout ubdir board grub_scan_disk uboot_config"
eval "$(setvars "n" ${pv})"
eval "$(setvars "" ${v} boards _displaymode _payload _keyboard all targets)"
@@ -53,8 +53,7 @@ main()
err "Cannot generate list of boards for building"
for x in ${boards}; do
- eval "$(setvars "n" ${pv})"
- eval "$(setvars "" ${v})"
+ eval "$(setvars "n" ${pv}) $(setvars "" ${v})"
grub_background="background1280x800.png"
board="${x}"
check_target
@@ -65,7 +64,8 @@ main()
[ -z "${targets}" ] && err "No ROM images were compiled"
printf "\nROM images available in these directories:\n"
- printf "%s^^ ROM images available in these directories.\n\n" "$targets"
+ eval "printf \"${targets}\""
+ printf "^^ ROM images available in these directories.\n\n"
printf "DO NOT flash ROM images from elf/ - please use bin/ instead.\n"
}
@@ -127,20 +127,15 @@ prepare_target()
cbfstool="cbutils/${tree}/cbfstool"
cbrom="${cbdir}/build/coreboot.rom"
- [ -f "${cbfstool}" ] || \
- x_ ./update trees -b coreboot utils ${tree}
-
- build_dependency_seabios
+ [ -f "${cbfstool}" ] || x_ ./update trees -b coreboot utils ${tree}
memtest_bin="memtest86plus/build64/memtest.bin"
[ "${payload_memtest}" != "y" ] || [ -f "src/${memtest_bin}" ] || \
x_ ./update trees -b memtest86plus
- rm -f "${romdir}/"* || err "!prepare, rm files, ${romdir}"
-
- build_dependency_grub
- build_dependency_uboot
- build_target
+ for bt in dependency_seabios dependency_grub dependency_uboot target; do
+ eval "build_${bt}"
+ done
}
build_dependency_seabios()
@@ -162,14 +157,15 @@ build_dependency_grub()
rebuild_grub="n"
[ -f "${grubelf}" ] || rebuild_grub="y"
for keymapfile in "${kmapdir}"/*.gkb; do
- [ "${rebuild_grub}" = "y" ] || break
[ -f "${keymapfile}" ] || continue
+ keymaps="${keymaps} ${keymapfile}"
keymap="${keymapfile##*/}"
keymap="${keymap%.gkb}"
[ ! -f "elf/grub/keymap_${keymap}.cfg" ] && \
- rebuild_grub="y" && break
+ rebuild_grub="y"
done
+ [ -n "${_keyboard}" ] && keymaps="${kmapdir}/${_keyboard}.gkb"
[ "${rebuild_grub}" = "y" ] || return 0
x_ ./build grub
}
@@ -189,6 +185,8 @@ build_dependency_uboot()
build_target()
{
+ rm -f "${romdir}/"* || err "!prepare, rm files, ${romdir}"
+
for x in "normal" "vgarom" "libgfxinit"; do
initmode="${x}"
hmode="vesafb"
@@ -229,10 +227,8 @@ build_roms()
[ "${payload_memtest}" != "y" ] || \
x_ "${cbfstool}" "${cbrom}" add-payload \
-f "src/${memtest_bin}" -n img/memtest -c lzma
- [ "${payload_seabios}" = "y" ] && \
- build_seabios_roms
- [ "${payload_grub}" != "y" ] || \
- x_ build_grub_roms "${cbrom}" "grub"
+ [ "${payload_seabios}" = "y" ] && build_seabios_roms
+ [ "${payload_grub}" != "y" ] || x_ build_grub_roms "${cbrom}" "grub"
[ "${payload_uboot}" = "y" ] || return 0
x_ cp "${_cbrom}" "${cbrom}"
build_uboot_roms
@@ -299,12 +295,6 @@ build_grub_roms()
-f "${tmpcfg}" -n timeout.cfg -t raw
x_ rm -f "${tmpcfg}"
- keymaps=""
- for kmapfile in "${kmapdir}"/*; do
- keymaps="${keymaps} ${kmapfile}"
- done
- [ -z "${_keyboard}" ] || keymaps="${kmapdir}/${_keyboard}.gkb"
-
for keymapfile in ${keymaps}; do
[ -f "${keymapfile}" ] || continue
keymap="${keymapfile##*/}"