WIP: convert to lwmk

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-09-07 13:41:59 +01:00
parent 8d0ad21112
commit 2b34aeea5d
909 changed files with 6807 additions and 186660 deletions
+14 -261
View File
@@ -23,16 +23,10 @@ buildtype=""
cleanargs=""
cmakedir=""
cmd=""
defconfig=""
mozconfig=""
dest_dir=""
elfdir=""
forcepull=""
gccdir=""
gccfull=""
gccver=""
gnatdir=""
gnatfull=""
gnatver=""
listfile=""
makeargs=""
mdir=""
@@ -49,13 +43,10 @@ target=""
target_dir=""
targets=""
tree=""
xarch=""
xgcctree=""
xlang=""
trees()
{
flags="f:F:b:m:u:c:x:s:l:n:d:"
flags="f:F:b:c:x:d:"
while getopts $flags option; do
@@ -66,9 +57,6 @@ trees()
flag="$1"
# the "mode" variable is affixed to a make command, example:
# ./mk -m coreboot does: make menuconfig -C src/coreboot/tree
case "$flag" in
-d)
@@ -84,10 +72,6 @@ trees()
-b) : ;;
-u) mode="oldconfig" ;;
-m) mode="menuconfig" ;;
-c) mode="distclean" ;;
-x) mode="crossgcc-clean" ;;
@@ -106,12 +90,6 @@ trees()
fi
;;
-s) mode="savedefconfig" ;;
-l) mode="olddefconfig" ;;
-n) mode="nconfig" ;;
*) err "invalid option '-$option'" "trees" "$@" ;;
esac
@@ -238,7 +216,7 @@ build_targets()
target="$x"
x_ handle_defconfig
x_ handle_mozconfig
if [ -z "$mode" ]; then
@@ -247,7 +225,7 @@ build_targets()
done; :
}
handle_defconfig()
handle_mozconfig()
{
target_dir="$configdir/$target"
@@ -263,7 +241,7 @@ handle_defconfig()
if [ -z "$tree" ]; then
err "$configdir: 'tree' not set" "handle_defconfig" "$@"
err "$configdir: 'tree' not set" "handle_mozconfig" "$@"
fi
srcdir="src/$project/$tree"
@@ -283,26 +261,12 @@ handle_defconfig()
elif [ "$flag" != "-d" ]; then
defconfig="$y"
mozconfig="$y"
fi
if [ -z "$mode" ]; then
check_defconfig || continue; :
fi
if [ -z "$mode" ]; then
for _xarch in $xarch; do
$if_dry_build \
break
if [ -n "$_xarch" ]; then
check_cross_compiler "$_xarch"
fi
done; :
check_mozconfig || continue; :
fi
handle_makefile
@@ -331,9 +295,6 @@ configure_project()
postmake=""
premake=""
release=""
xarch=""
xgcctree=""
xlang=""
if [ ! -f "$tcfg" ]; then
@@ -406,12 +367,6 @@ configure_project()
return 1
fi
if [ -n "$buildtype" ] && \
[ "${mode%config}" != "$mode" ]; then
return 1
fi
if [ -z "$mode" ]; then
$if_not_dry_build \
@@ -554,196 +509,15 @@ project_up_to_date()
eval "[ \"\$$badhashvar\" = \"y\" ] && return 1"; :
}
check_cross_compiler()
check_mozconfig()
{
cbdir="src/coreboot/$tree"
if [ "$project" != "coreboot" ]; then
cbdir="src/coreboot/default"
fi
if [ -n "$xgcctree" ]; then
cbdir="src/coreboot/$xgcctree"
fi
xfix="${1%-*}"
if [ "$xfix" = "x86_64" ]; then
xfix="x64"
fi
xgccfile="elf/coreboot/$tree/xgcc_${xfix}_was_compiled"
xgccargs="crossgcc-$xfix UPDATED_SUBMODULES=1 CPUS=$XBMK_THREADS"
x_ ./mk -f coreboot "${cbdir#src/coreboot/}"
x_ xbmkdir "elf/coreboot/$tree" # TODO: is this needed?
export PATH="$xbmkpwd/$cbdir/util/crossgcc/xgcc/bin:$PATH"
export CROSS_COMPILE="${xarch% *}-"
if [ -n "$xlang" ]; then
export BUILD_LANGUAGES="$xlang"
fi
if [ -f "$xgccfile" ]; then
# skip the build, because a build already exists:
return 0
fi
check_gnu_path gcc gnat || x_ check_gnu_path gnat gcc
# try twice because xgcc sometimes fails for, like, no reason
#
make -C "$cbdir" $xgccargs || x_ make -C "$cbdir" $xgccargs
# this tells subsequent runs that the build was already done:
#
x_ touch "$xgccfile"
# reset hostcc in PATH:
#
remkdir "$xbtmp/gnupath"
}
# host toolchain version correction:
# fix mismatching gcc/gnat versions on debian trixie/sid. as of december 2024,
# trixie/sid had gnat-13 as gnat and gcc-14 as gcc, but has gnat-14 in apt. in
# some cases, gcc 13+14 and gnat-13 are present; or gnat-14 and gcc-14, but
# gnat in PATH never resolves to gnat-14, because gnat-14 was "experimental"
# note that this was implemented for debian trixie-testing, but this same
# issue will likely occur in future distros, including newer debian testing
# releases. this just matches up the versions of each toolchain component.
check_gnu_path()
{
if ! command -v "$1" 1>/dev/null; then
err "Host '$1' unavailable" "check_gnu_path" "$@"
fi
gccdir=""
gccfull=""
gccver=""
gnatdir=""
gnatfull=""
gnatver=""
if host_gcc_gnat_match "$@"; then
return 0
elif ! match_gcc_gnat_versions "$@"; then
return 1
fi
}
# check if gcc/gnat versions already match:
host_gcc_gnat_match()
{
if ! gnu_setver "$1" "$1"; then
err "Command '$1' unavailable." "check_gnu_path" "$@"
fi
gnu_setver "$2" "$2" || :
eval "[ -z \"\$$1ver\" ] && err \"Cannot detect host '$1' version\""
if [ "$gnatfull" != "$gccfull" ]; then
# non-matching host gcc/gnat versions
return 1
fi
}
# find all host gcc/gnat versions, matching them up in PATH:
match_gcc_gnat_versions()
{
eval "$1dir=\"$(dirname "$(command -v "$1")")\""
eval "_gnudir=\"\$$1dir\""
eval "_gnuver=\"\$$1ver\""
for _bin in "$_gnudir/$2-"*; do
if [ "${_bin#"$_gnudir/$2-"}" = "$_gnuver" ] && [ -x "$_bin" ]
then
_gnuver="${_bin#"$_gnudir/$2-"}"
break
fi
done
if ! gnu_setver "$2" "$_gnudir/$2-$_gnuver"; then
return 1
elif [ "$gnatfull" != "$gccfull" ]; then
return 1
fi
( link_gcc_gnat_versions "$@" "$_gnudir" "$_gnuver" ) || \
err "Can't link '$2-$_gnuver' '$_gnudir'" "check_gnu_path" "$@"; :
}
# create symlinks in PATH, so that the GCC/GNAT versions match:
link_gcc_gnat_versions()
{
_gnudir="$3"
_gnuver="$4"
remkdir "$xbtmp/gnupath"
x_ cd "$xbtmp/gnupath"
for _gnubin in "$_gnudir/$2"*"-$_gnuver"; do
_gnuutil="${_gnubin##*/}"
if [ -e "$_gnubin" ]; then
x_ ln -s "$_gnubin" "${_gnuutil%"-$_gnuver"}"
fi
done
}
# get the gcc/gnat version
# fail: return 1 if util not found
gnu_setver()
{
eval "$2 --version 1>/dev/null 2>/dev/null || return 1"
eval "$1ver=\"`"$2" --version 2>/dev/null | head -n1`\""
eval "$1ver=\"\${$1ver##* }\""
eval "$1full=\"\$$1ver\""
eval "$1ver=\"\${$1ver%%.*}\""; :
}
check_defconfig()
{
if [ ! -f "$defconfig" ]; then
if [ ! -f "$mozconfig" ]; then
$if_not_dry_build \
err "$project/$target: no config" "check_defconfig" "$@"
err "$project/$target: no config" "check_mozconfig" "$@"
fi
dest_dir="$elfdir/$tree/$target/${defconfig#"$target_dir/config/"}"
dest_dir="$elfdir/$tree/$target/${mozconfig#"$target_dir/config/"}"
# skip build if a previous one exists:
@@ -775,34 +549,13 @@ handle_makefile()
x_ make -C "$srcdir" $cleanargs clean
fi
if [ -f "$defconfig" ]; then
if [ -f "$mozconfig" ]; then
x_ cp "$defconfig" "$srcdir/.config"
x_ cp "$mozconfig" "$srcdir/mozconfig"
fi
run_make_command || \
err "no makefile!" "handle_makefile" "$@"
_copy=".config"
if [ "$mode" = "savedefconfig" ]; then
_copy="defconfig"
fi
if [ "${mode%config}" != "$mode" ]; then
$if_not_dry_build \
x_ cp "$srcdir/$_copy" "$defconfig"; :
fi
if [ -e "$srcdir/.git" ] && \
[ "$project" = "u-boot" ] && \
[ "$mode" = "distclean" ]; then
$if_not_dry_build \
x_ git -C "$srcdir" $cleanargs clean -fdx; :
fi
err "no makefile!" "handle_makefile" "$@"; :
}
run_make_command()