trees: general code cleanup

Signed-off-by: Leah Rowe <leah@libreboot.org>
audit6
Leah Rowe 2024-07-10 22:14:39 +01:00
parent 17f3e61a0e
commit 3263eeb6b6
4 changed files with 53 additions and 73 deletions

View File

@ -12,7 +12,7 @@ fetch_targets()
e "src/$project/$tree" d && return 0 e "src/$project/$tree" d && return 0
printf "Creating %s tree %s\n" "$project" "$tree" printf "Creating %s tree %s\n" "$project" "$tree"
git_prep "$loc" "$loc" "$PWD/$cfgsdir/$tree/patches" \ git_prep "$loc" "$loc" "$PWD/$configdir/$tree/patches" \
"${loc%/*}/$tree" u; nuke "$project/$tree" "$project/$tree" "${loc%/*}/$tree" u; nuke "$project/$tree" "$project/$tree"
} }

View File

@ -37,7 +37,7 @@ chkvars()
} }
eval `setvars "" _nogit board xbmk_parent versiondate projectsite projectname \ eval `setvars "" _nogit board xbmk_parent versiondate projectsite projectname \
aur_notice cfgsdir datadir version relname` aur_notice configdir datadir version relname`
for fv in projectname projectsite version versiondate; do for fv in projectname projectsite version versiondate; do
eval "[ ! -f "$fv" ] || read -r $fv < \"$fv\" || :" eval "[ ! -f "$fv" ] || read -r $fv < \"$fv\" || :"

View File

@ -29,13 +29,13 @@ mkpayload_grub()
eval `setvars "" grub_modules grub_install_modules` eval `setvars "" grub_modules grub_install_modules`
$dry eval `setcfg "$grubdata/module/$tree"` $dry eval `setcfg "$grubdata/module/$tree"`
$dry x_ rm -f "$cdir/grub.elf" $dry x_ rm -f "$srcdir/grub.elf"
$dry "${cdir}/grub-mkstandalone" --grub-mkimage="${cdir}/grub-mkimage" \ $dry "$srcdir/grub-mkstandalone" --grub-mkimage="$srcdir/grub-mkimage" \
-O i386-coreboot -o "${cdir}/grub.elf" -d "${cdir}/grub-core/" \ -O i386-coreboot -o "$srcdir/grub.elf" -d "${srcdir}/grub-core/" \
--fonts= --themes= --locales= --modules="$grub_modules" \ --fonts= --themes= --locales= --modules="$grub_modules" \
--install-modules="$grub_install_modules" \ --install-modules="$grub_install_modules" \
"/boot/grub/grub_default.cfg=${cdir}/.config" \ "/boot/grub/grub_default.cfg=${srcdir}/.config" \
"/boot/grub/grub.cfg=$grubdata/memdisk.cfg" \ "/boot/grub/grub.cfg=$grubdata/memdisk.cfg" \
"/background.png=$grubdata/background/background1280x800.png" || \ "/background.png=$grubdata/background/background1280x800.png" || \
$err "$tree: cannot build grub.elf"; return 0 $err "$tree: cannot build grub.elf"; return 0
@ -44,8 +44,8 @@ mkpayload_grub()
mkvendorfiles() mkvendorfiles()
{ {
check_coreboot_utils "$tree" check_coreboot_utils "$tree"
printf "%s\n" "${version%%-*}" > "$cdir/.coreboot-version" || \ printf "%s\n" "${version%%-*}" > "$srcdir/.coreboot-version" || \
$err "!mk $cdir .coreboot-version" $err "!mk $srcdir .coreboot-version"
[ -z "$mode" ] && [ "$target" != "$tree" ] && \ [ -z "$mode" ] && [ "$target" != "$tree" ] && \
x_ ./vendor download $target; return 0 x_ ./vendor download $target; return 0
} }
@ -71,7 +71,7 @@ mkcorebootbin()
{ {
[ "$target" = "$tree" ] && return 0 [ "$target" = "$tree" ] && return 0
tmprom="$cdir/build/coreboot.rom" tmprom="$srcdir/build/coreboot.rom"
initmode="${defconfig##*/}"; displaymode="${initmode##*_}" initmode="${defconfig##*/}"; displaymode="${initmode##*_}"
initmode="${initmode%%_*}" initmode="${initmode%%_*}"
[ -n "$displaymode" ] && displaymode="_$displaymode" [ -n "$displaymode" ] && displaymode="_$displaymode"

View File

@ -9,10 +9,10 @@ set -u -e
. "include/lib.sh" . "include/lib.sh"
. "include/git.sh" . "include/git.sh"
eval `setvars "" xarch cdir defconfig cmakedir xlang mode makeargs elfdir cmd \ eval `setvars "" xarch srcdir premake cmakedir xlang mode makeargs elfdir cmd \
project target target_dir targets xtree _f release bootstrapargs mkhelper \ project target target_dir targets xtree _f release bootstrapargs mkhelper \
autoconfargs listfile autogenargs btype tree rev tree_depend build_depend \ autoconfargs listfile autogenargs btype tree rev tree_depend build_depend \
premake postmake mkhelpercfg dry` defconfig postmake mkhelpercfg dry dest_dir`
main() main()
{ {
@ -44,36 +44,27 @@ main()
[ -f "config/git/$project/pkg.cfg" ] || $err "'$project' not defined" [ -f "config/git/$project/pkg.cfg" ] || $err "'$project' not defined"
elfdir="elf/$project" for d in "elf" "config/data" "config" "src"; do
datadir="config/data/$project" eval "${d#*/}dir=\"$d/$project\""
cfgsdir="config/$project" done; dest_dir="$elfdir"
listfile="$datadir/build.list" # needed on multi, optional on single listfile="$datadir/build.list"
[ -f "$listfile" ] || listfile="" # optional on all projects [ -f "$listfile" ] || listfile="" # optional on all projects
mkhelpercfg="$datadir/mkhelper.cfg" mkhelpercfg="$datadir/mkhelper.cfg"
e "$mkhelpercfg" f missing && mkhelpercfg="$TMPDIR/mkhelper.cfg" && \
x_ touch "$mkhelpercfg"
targets="$@" targets="$@"
remkdir "${tmpgit%/*}"
}
handle_project()
{
cmd="build_targets $targets" && singletree "$project" && \ cmd="build_targets $targets" && singletree "$project" && \
cmd="build_project"; $cmd cmd="build_project"
[ -f "$listfile" ] || return 0 remkdir "${tmpgit%/*}"
[ -z "$mode" ] && $dry printf "\n\nOK! Check %s/\n\n" "$elfdir"; :
} }
build_project() build_project()
{ {
configure_project "$cfgsdir" || return 0 configure_project "$configdir" || return 0
[ ! -f "$listfile" ] || $dry elfcheck || return 0
dest_dir="$elfdir"
[ ! -f "$listfile" ] || elfcheck || return 0
cdir="src/${project}"
x_ ./update trees -f "$project"
[ "$mode" = "distclean" ] && mode="clean" [ "$mode" = "distclean" ] && mode="clean"
run_make_command || return 0 run_make_command || return 0
@ -83,10 +74,8 @@ build_project()
build_targets() build_targets()
{ {
[ -d "$cfgsdir" ] || $err "directory, $cfgsdir, does not exist" [ -d "$configdir" ] || $err "directory, $configdir, does not exist"
[ $# -gt 0 ] || targets="$(ls -1 "$configdir")" || $err "!o $configdir"
[ $# -gt 0 ] || \
targets="$(ls -1 "$cfgsdir")" || $err "$cfgsdir: Canot get options"
for x in $targets; do for x in $targets; do
[ "$x" = "list" ] && x_ ls -1 "config/$project" && \ [ "$x" = "list" ] && x_ ls -1 "config/$project" && \
@ -101,7 +90,19 @@ build_targets()
handle_defconfig() handle_defconfig()
{ {
handle_src_tree "$target" || return 0 target_dir="$configdir/$target"
[ -f "CHANGELOG" ] || fetch_project "$project"
configure_project "$target_dir" || return 0
x_ mkdir -p "$elfdir/$target"
chkvars tree
srcdir="src/$project/$tree"
if [ "$mode" = "distclean" ] || [ "$mode" = "crossgcc-clean" ]; then
[ -d "$srcdir" ] || return 0
fi
[ -z "$mode" ] && $dry check_cross_compiler
for y in "$target_dir/config"/*; do for y in "$target_dir/config"/*; do
[ "$_f" = "-d" ] || [ -f "$y" ] || continue [ "$_f" = "-d" ] || [ -f "$y" ] || continue
@ -113,25 +114,6 @@ handle_defconfig()
done; return 0 done; return 0
} }
handle_src_tree()
{
target_dir="$cfgsdir/$target"
[ -f "CHANGELOG" ] || fetch_project "$project"
configure_project "$target_dir" || return 1
x_ mkdir -p "$elfdir/$target"
chkvars tree
cdir="src/$project/$tree"
if [ "$mode" = "distclean" ] || [ "$mode" = "crossgcc-clean" ]; then
[ -d "$cdir" ] || return 1
fi
x_ ./update trees -f "$project" "$target"
[ -z "$mode" ] && $dry check_cross_compiler; return 0
}
configure_project() configure_project()
{ {
eval `setvars "" xarch xlang build_depend autoconfargs xtree postmake \ eval `setvars "" xarch xlang build_depend autoconfargs xtree postmake \
@ -167,6 +149,7 @@ configure_project()
done done
fi fi
[ "$mode" = "fetch" ] || x_ ./update trees -f "$project" $target
[ "$mode" = "fetch" ] || return 0 [ "$mode" = "fetch" ] || return 0
[ -f "CHANGELOG" ] && return 1; fetch_${cmd#build_}; return 1 [ -f "CHANGELOG" ] && return 1; fetch_${cmd#build_}; return 1
} }
@ -194,10 +177,9 @@ check_cross_compiler()
check_defconfig() 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/"}" dest_dir="$elfdir/$target/${defconfig#"$target_dir/config/"}"
$dry elfcheck || return 1 # skip build if a previous one exists
$dry elfcheck || return 1 # skip build if a previous one exists
$dry x_ mkdir -p "$dest_dir" $dry x_ mkdir -p "$dest_dir"
} }
@ -211,32 +193,32 @@ elfcheck()
handle_makefile() handle_makefile()
{ {
$dry check_makefile "$cdir" && x_ make clean -C "$cdir" $dry check_makefile "$srcdir" && x_ make clean -C "$srcdir"
[ -f "$defconfig" ] && x_ cp "$defconfig" "$cdir/.config" [ -f "$defconfig" ] && x_ cp "$defconfig" "$srcdir/.config"
[ -n "$mode" ] || [ -n "$btype" ] || $dry make -C \ [ -n "$mode" ] || [ -n "$btype" ] || $dry make -C \
"$cdir" silentoldconfig || make -C "$cdir" oldconfig || : "$srcdir" silentoldconfig || make -C "$srcdir" oldconfig || :
run_make_command || $err "handle_makefile $cdir: no makefile!" run_make_command || $err "handle_makefile $srcdir: no makefile!"
_copy=".config" && [ "$mode" = "savedefconfig" ] && _copy="defconfig" _copy=".config" && [ "$mode" = "savedefconfig" ] && _copy="defconfig"
[ "${mode%config}" = "$mode" ] || $dry x_ cp "$cdir/$_copy" "$defconfig" [ "${mode%config}" = "$mode" ] || \
$dry x_ cp "$srcdir/$_copy" "$defconfig"
[ -e "$cdir/.git" ] && [ "$project" = "u-boot" ] && \ [ -e "$srcdir/.git" ] && [ "$project" = "u-boot" ] && \
[ "$mode" = "distclean" ] && $dry x_ git -C "$cdir" clean -fdx; : [ "$mode" = "distclean" ] && $dry x_ git -C "$srcdir" clean -fdx; :
} }
run_make_command() run_make_command()
{ {
[ -z "$premake" ] || [ -n "$mode" ] || $premake || $err "!$premake" [ -z "$premake" ] || [ -n "$mode" ] || $premake || $err "!$premake"
$dry check_cmake "$cdir" && [ -z "$mode" ] && $dry check_autoconf \ $dry check_cmake "$srcdir" && [ -z "$mode" ] && $dry check_autoconf \
"$cdir"; $dry check_makefile "$cdir" || return 1 "$srcdir"; $dry check_makefile "$srcdir" || return 1
$dry make -C "$cdir" $mode -j$XBMK_THREADS $makeargs \ $dry make -C "$srcdir" $mode -j$XBMK_THREADS $makeargs || $err "!$mode"
|| $err "$cdir mk$mode"
[ -z "$mkhelper" ] || [ -n "$mode" ] || $mkhelper || $err "!$mkhelper" [ -z "$mkhelper" ] || [ -n "$mode" ] || $mkhelper || $err "!$mkhelper"
[ "$mode" = "clean" ] && $dry make -C "$cdir" distclean || :; return 0 [ "$mode" = "clean" ] && $dry make -C "$srcdir" distclean || :; :
} }
check_cmake() check_cmake()
@ -267,12 +249,10 @@ check_makefile()
copy_elf() copy_elf()
{ {
[ -f "$listfile" ] && x_ mkdir -p "$dest_dir" && while read -r f; do [ -f "$listfile" ] && x_ mkdir -p "$dest_dir" && while read -r f; do
[ -f "$cdir/$f" ] && x_ cp "$cdir/$f" "$dest_dir" [ -f "$srcdir/$f" ] && x_ cp "$srcdir/$f" "$dest_dir"
done < "$listfile"; x_ make clean -C "$cdir" done < "$listfile"; x_ make clean -C "$srcdir"
} }
main $@ main $@
e "$mkhelpercfg" f missing && mkhelpercfg="$TMPDIR/mkhelper.cfg" && x_ \
touch "$mkhelpercfg"
. "$mkhelpercfg" . "$mkhelpercfg"
handle_project $cmd