2023-09-30 00:31:40 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
# SPDX-FileCopyrightText: 2022 Caleb La Grange <thonkpeasant@protonmail.com>
|
|
|
|
# SPDX-FileCopyrightText: 2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
|
2024-01-01 17:08:38 +00:00
|
|
|
# SPDX-FileCopyrightText: 2020-2024 Leah Rowe <leah@libreboot.org>
|
2023-08-27 13:14:49 +00:00
|
|
|
|
2024-05-06 21:54:55 +00:00
|
|
|
export LC_COLLATE=C
|
|
|
|
export LC_ALL=C
|
|
|
|
|
|
|
|
tmpdir_was_set="y"
|
2023-10-15 10:22:43 +00:00
|
|
|
cbdir="src/coreboot/default"
|
|
|
|
cbcfgsdir="config/coreboot"
|
|
|
|
ifdtool="cbutils/default/ifdtool"
|
|
|
|
cbfstool="cbutils/default/cbfstool"
|
2023-12-30 13:08:29 +00:00
|
|
|
grubcfgsdir="config/grub"
|
|
|
|
layoutdir="/boot/grub/layouts"
|
|
|
|
. "${grubcfgsdir}/modules.list"
|
2024-01-01 15:02:34 +00:00
|
|
|
tmpgit="${PWD}/tmp/gitclone"
|
2024-05-06 21:54:55 +00:00
|
|
|
err="err_"
|
|
|
|
|
|
|
|
err_()
|
|
|
|
{
|
|
|
|
printf "ERROR %s: %s\n" "${0}" "${1}" 1>&2
|
|
|
|
exit 1
|
|
|
|
}
|
2023-10-15 10:22:43 +00:00
|
|
|
|
2024-05-06 21:54:55 +00:00
|
|
|
setvars()
|
|
|
|
{
|
|
|
|
_setvars=""
|
|
|
|
[ $# -lt 2 ] && $err "setvars: too few arguments"
|
|
|
|
val="${1}" && shift 1
|
|
|
|
for var in $@; do
|
|
|
|
_setvars="${var}=\"${val}\"; ${_setvars}"
|
|
|
|
done
|
|
|
|
printf "%s\n" "${_setvars% }"
|
|
|
|
}
|
2024-05-16 02:56:52 +00:00
|
|
|
eval "$(setvars "" versiondate tmpdir _nogit version board boarddir \
|
|
|
|
xbmk_release threads projectname relname)"
|
2024-05-06 21:54:55 +00:00
|
|
|
|
|
|
|
# if "y": a coreboot target won't be built if target.cfg says release="n"
|
|
|
|
# (this is used to exclude certain build targets from releases)
|
2024-05-16 02:56:52 +00:00
|
|
|
set | grep XBMK_RELEASE 1>/dev/null 2>/dev/null || xbmk_release="n" || :
|
|
|
|
[ -z "$xbmk_release" ] && xbmk_release="$XBMK_RELEASE"
|
|
|
|
[ "$xbmk_release" = "n" ] || [ "$xbmk_release" = "y" ] || xbmk_release="n"
|
|
|
|
export XBMK_RELEASE="$xbmk_release"
|
2024-05-06 21:54:55 +00:00
|
|
|
|
|
|
|
set | grep TMPDIR 1>/dev/null 2>/dev/null || tmpdir_was_set="n"
|
|
|
|
if [ "${tmpdir_was_set}" = "y" ]; then
|
2024-05-16 02:56:52 +00:00
|
|
|
[ "${TMPDIR%_*}" = "/tmp/xbmk" ] || tmpdir_was_set="n"
|
2024-05-06 21:54:55 +00:00
|
|
|
fi
|
|
|
|
if [ "${tmpdir_was_set}" = "n" ]; then
|
|
|
|
export TMPDIR="/tmp"
|
2024-05-16 02:56:52 +00:00
|
|
|
tmpdir="$(mktemp -d -t xbmk_XXXXXXXX)"
|
2024-05-06 21:54:55 +00:00
|
|
|
export TMPDIR="${tmpdir}"
|
|
|
|
else
|
|
|
|
export TMPDIR="${TMPDIR}"
|
|
|
|
tmpdir="${TMPDIR}"
|
|
|
|
fi
|
2023-10-15 10:22:43 +00:00
|
|
|
|
2024-05-16 02:56:52 +00:00
|
|
|
set | grep XBMK_THREADS 1>/dev/null 2>/dev/null && threads="$XBMK_THREADS"
|
2024-04-28 16:31:16 +00:00
|
|
|
[ -z "$threads" ] && threads=1
|
2024-03-27 07:14:47 +00:00
|
|
|
expr "X$threads" : "X-\{0,1\}[0123456789][0123456789]*$" \
|
|
|
|
1>/dev/null 2>/dev/null || threads=1 # user specified a non-integer
|
2024-05-16 02:56:52 +00:00
|
|
|
export XBMK_THREADS="$threads"
|
2024-04-28 16:31:16 +00:00
|
|
|
|
2024-05-15 02:01:25 +00:00
|
|
|
x_() {
|
|
|
|
[ $# -lt 1 ] || ${@} || $err "Unhandled non-zero exit: $@"; return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
read -r projectname < projectname || :
|
|
|
|
[ ! -f version ] || read -r version < version || :
|
|
|
|
version_="${version}"
|
|
|
|
[ ! -e ".git" ] || version="$(git describe --tags HEAD 2>&1)" || \
|
|
|
|
version="git-$(git rev-parse HEAD 2>&1)" || version="${version_}"
|
|
|
|
[ ! -f versiondate ] || read -r versiondate < versiondate || :
|
|
|
|
versiondate_="${versiondate}"
|
|
|
|
[ ! -e ".git" ] || versiondate="$(git show --no-patch --no-notes \
|
|
|
|
--pretty='%ct' HEAD)" || versiondate="${versiondate_}"
|
|
|
|
for p in projectname version versiondate; do
|
|
|
|
eval "[ -n \"\$$p\" ] || $err \"$p unset\""
|
|
|
|
eval "x_ printf \"%s\\n\" \"\$$p\" > $p"
|
|
|
|
done
|
|
|
|
relname="${projectname}-${version}"
|
|
|
|
export LOCALVERSION="-${projectname}-${version%%-*}"
|
|
|
|
|
2023-10-19 22:36:56 +00:00
|
|
|
items()
|
2023-08-27 13:14:49 +00:00
|
|
|
{
|
2023-09-27 20:46:20 +00:00
|
|
|
rval=1
|
2023-12-19 02:31:44 +00:00
|
|
|
if [ ! -d "${1}" ]; then
|
2023-12-19 02:32:56 +00:00
|
|
|
printf "items: directory '%s' doesn't exist" "${1}" 1>&2
|
2023-12-19 02:31:44 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2023-08-27 13:14:49 +00:00
|
|
|
for x in "${1}/"*; do
|
|
|
|
# -e used because this is for files *or* directories
|
|
|
|
[ -e "${x}" ] || continue
|
|
|
|
[ "${x##*/}" = "build.list" ] && continue
|
2023-09-09 22:15:17 +00:00
|
|
|
printf "%s\n" "${x##*/}" 2>/dev/null
|
2023-09-27 20:46:20 +00:00
|
|
|
rval=0
|
2023-08-27 13:14:49 +00:00
|
|
|
done
|
2023-09-27 20:46:20 +00:00
|
|
|
return ${rval}
|
2023-08-27 13:14:49 +00:00
|
|
|
}
|
2023-09-30 00:31:40 +00:00
|
|
|
|
|
|
|
scan_config()
|
|
|
|
{
|
|
|
|
awkstr=" /\{.*${1}.*}{/ {flag=1;next} /\}/{flag=0} flag { print }"
|
|
|
|
confdir="${2}"
|
2023-10-02 02:39:10 +00:00
|
|
|
revfile="$(mktemp -t sources.XXXXXXXXXX)"
|
2023-09-30 00:31:40 +00:00
|
|
|
cat "${confdir}/"* > "${revfile}" || \
|
safer, simpler error handling in lbmk
in shell scripts, a function named the same as a program included in
the $PATH will override that program. for example, you could make a
function called ls() and this would override the standand "ls".
in lbmk, a part of it was first trying to run the "fail" command,
deferring to "err", because some scripts call fail() which does
some minor cleanup before calling err.
in most cases, fail() is not defined, and it's possible that the user
could have a program called "fail" in their $PATH, the behaviour of
which we could not determine, and it could have disastrous effects.
lbmk error handling has been re-engineered in such a way that the
err function is defined in a variable, which defaults to err_ which
calls err_, so defined under include/err.sh.
in functions that require cleanup prior to error handling, a fail()
function is still defined, and err is overridden, thus:
err="fail"
this change has made xx_() obsolete, so now only x_ is used. the x_
function is a wrapper that can be used to run a command and exit with
non-zero status (from lbmk) if the command fails. the xx_ command
did the same thing, but called fail() which would have called err();
now everything is $err
example:
rm -f "$filename" || err "could not delete file"
this would now be:
rm -f "$filename" || $err "could not delete file"
overriding of err= must be done *after* including err.sh. for
example:
err="fail"
. "include/err.sh"
^ this is wrong. instead, one must do:
. "include/err.sh"
err="fail"
this is because err is set as a global variable under err.sh
the new error handling is much cleaner, and safer. it also reduces
the chance of mistakes such as: calling err when you meant to
call fail. this is because the standard way is now to call $err,
so you set err="fail" at the top of the script and all is well.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
$err "scan_config ${confdir}: Cannot concatenate files"
|
2023-09-30 00:31:40 +00:00
|
|
|
while read -r line ; do
|
|
|
|
set ${line} 1>/dev/null 2>/dev/null || :
|
2023-12-19 02:34:54 +00:00
|
|
|
if [ "${1%:}" = "depend" ]; then
|
|
|
|
depend="${depend} ${2}"
|
2023-12-27 17:26:37 +00:00
|
|
|
else
|
|
|
|
eval "${1%:}=\"${2}\""
|
2023-12-19 02:34:54 +00:00
|
|
|
fi
|
2023-09-30 00:31:40 +00:00
|
|
|
done << EOF
|
|
|
|
$(eval "awk '${awkstr}' \"${revfile}\"")
|
|
|
|
EOF
|
safer, simpler error handling in lbmk
in shell scripts, a function named the same as a program included in
the $PATH will override that program. for example, you could make a
function called ls() and this would override the standand "ls".
in lbmk, a part of it was first trying to run the "fail" command,
deferring to "err", because some scripts call fail() which does
some minor cleanup before calling err.
in most cases, fail() is not defined, and it's possible that the user
could have a program called "fail" in their $PATH, the behaviour of
which we could not determine, and it could have disastrous effects.
lbmk error handling has been re-engineered in such a way that the
err function is defined in a variable, which defaults to err_ which
calls err_, so defined under include/err.sh.
in functions that require cleanup prior to error handling, a fail()
function is still defined, and err is overridden, thus:
err="fail"
this change has made xx_() obsolete, so now only x_ is used. the x_
function is a wrapper that can be used to run a command and exit with
non-zero status (from lbmk) if the command fails. the xx_ command
did the same thing, but called fail() which would have called err();
now everything is $err
example:
rm -f "$filename" || err "could not delete file"
this would now be:
rm -f "$filename" || $err "could not delete file"
overriding of err= must be done *after* including err.sh. for
example:
err="fail"
. "include/err.sh"
^ this is wrong. instead, one must do:
. "include/err.sh"
err="fail"
this is because err is set as a global variable under err.sh
the new error handling is much cleaner, and safer. it also reduces
the chance of mistakes such as: calling err when you meant to
call fail. this is because the standard way is now to call $err,
so you set err="fail" at the top of the script and all is well.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
rm -f "$revfile" || $err "scan_config: Cannot remove tmpfile"
|
2023-09-30 00:31:40 +00:00
|
|
|
}
|
2023-10-07 04:16:46 +00:00
|
|
|
|
2023-10-15 10:22:43 +00:00
|
|
|
check_defconfig()
|
|
|
|
{
|
|
|
|
for x in "${1}"/config/*; do
|
2023-12-22 13:05:32 +00:00
|
|
|
[ -f "${x}" ] && return 1
|
2023-10-15 10:22:43 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2023-10-07 04:16:46 +00:00
|
|
|
handle_coreboot_utils()
|
|
|
|
{
|
|
|
|
for util in cbfstool ifdtool; do
|
2023-10-19 23:17:30 +00:00
|
|
|
x_ ./update trees ${_f} "src/coreboot/${1}/util/${util}"
|
2023-10-07 04:36:52 +00:00
|
|
|
[ -z "${mode}" ] && [ ! -f "cbutils/${1}/${util}" ] && \
|
2023-10-07 04:16:46 +00:00
|
|
|
x_ mkdir -p "cbutils/${1}" && \
|
|
|
|
x_ cp "src/coreboot/${1}/util/${util}/${util}" \
|
|
|
|
"cbutils/${1}"
|
2023-10-20 03:10:50 +00:00
|
|
|
[ -z "${mode}" ] || x_ rm -Rf "cbutils/${1}"
|
2023-10-07 04:16:46 +00:00
|
|
|
done
|
|
|
|
}
|
2023-12-22 09:46:43 +00:00
|
|
|
|
|
|
|
remkdir()
|
|
|
|
{
|
safer, simpler error handling in lbmk
in shell scripts, a function named the same as a program included in
the $PATH will override that program. for example, you could make a
function called ls() and this would override the standand "ls".
in lbmk, a part of it was first trying to run the "fail" command,
deferring to "err", because some scripts call fail() which does
some minor cleanup before calling err.
in most cases, fail() is not defined, and it's possible that the user
could have a program called "fail" in their $PATH, the behaviour of
which we could not determine, and it could have disastrous effects.
lbmk error handling has been re-engineered in such a way that the
err function is defined in a variable, which defaults to err_ which
calls err_, so defined under include/err.sh.
in functions that require cleanup prior to error handling, a fail()
function is still defined, and err is overridden, thus:
err="fail"
this change has made xx_() obsolete, so now only x_ is used. the x_
function is a wrapper that can be used to run a command and exit with
non-zero status (from lbmk) if the command fails. the xx_ command
did the same thing, but called fail() which would have called err();
now everything is $err
example:
rm -f "$filename" || err "could not delete file"
this would now be:
rm -f "$filename" || $err "could not delete file"
overriding of err= must be done *after* including err.sh. for
example:
err="fail"
. "include/err.sh"
^ this is wrong. instead, one must do:
. "include/err.sh"
err="fail"
this is because err is set as a global variable under err.sh
the new error handling is much cleaner, and safer. it also reduces
the chance of mistakes such as: calling err when you meant to
call fail. this is because the standard way is now to call $err,
so you set err="fail" at the top of the script and all is well.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
rm -Rf "${1}" || $err "remkdir: !rm -Rf \"${1}\""
|
|
|
|
mkdir -p "${1}" || $err "remkdir: !mkdir -p \"${1}\""
|
2023-12-22 09:46:43 +00:00
|
|
|
}
|
2024-05-06 21:54:55 +00:00
|
|
|
|
|
|
|
git_err()
|
|
|
|
{
|
|
|
|
printf "You need to set git name/email, like so:\n%s\n\n" "$1" 1>&2
|
|
|
|
$err "Git name/email not configured"
|
|
|
|
}
|
|
|
|
|
2024-05-14 22:17:22 +00:00
|
|
|
mktar_release()
|
|
|
|
{
|
2024-05-14 23:45:01 +00:00
|
|
|
printf "%s\n" "${version}" > "${1}/version" || return 1
|
|
|
|
printf "%s\n" "${versiondate}" > "${1}/versiondate" || return 1
|
|
|
|
printf "%s\n" "${projectname}" > "${1}/projectname" || return 1
|
|
|
|
|
2024-05-15 00:23:22 +00:00
|
|
|
mktarball "$1" "${1%/*}/${relname}_${1##*/}.tar.xz"
|
2024-05-14 22:17:22 +00:00
|
|
|
x_ rm -Rf "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
mktarball()
|
|
|
|
{
|
|
|
|
[ "${2%/*}" = "${2}" ] || \
|
|
|
|
mkdir -p "${2%/*}" || $err "mk, !mkdir -p \"${2%/*}\""
|
|
|
|
printf "\nCreating archive: %s\n\n" "$2"
|
2024-05-14 23:48:08 +00:00
|
|
|
tar -c "$1" | xz -T$threads -9e > "$2" || \
|
|
|
|
$err "mktarball 2, $1"
|
2024-05-14 23:37:12 +00:00
|
|
|
mksha512sum "${2}" "${2##*/}.sha512"
|
|
|
|
}
|
|
|
|
|
|
|
|
mksha512sum()
|
|
|
|
{
|
2024-05-14 22:17:22 +00:00
|
|
|
(
|
2024-05-14 23:37:12 +00:00
|
|
|
[ "${1%/*}" != "${1}" ] && x_ cd "${1%/*}"
|
|
|
|
sha512sum ./"${1##*/}" >> "${2}" || \
|
|
|
|
$err "!sha512sum \"${1}\" > \"${2}\""
|
2024-05-14 22:17:22 +00:00
|
|
|
) || $err "failed to create tarball checksum"
|
|
|
|
}
|
git.sh: Remove .git if XBMK_RELEASE=y
The build system already deletes .git in all source
directories for each given release, but does so at
the very end; it still does, but now it is deleted
one by one per project, to save space during very
large builds (release sizes vary wildly, depending
on how many trees exist for coreboot basically).
If you're building entirely in tmpfs (as I do), this
could be a problem if you have lots of .git/ directories.
This change reduces disk usage, or in the above example,
memory usage when running the build system from tmpfs.
This complements another recent change, where ROM images
are compressed per target during release builds, rather
than all at the very end of the process. It is part of a
series of optimisations, to reduce the memory and disk
usage of the build system, and to reduce I/O wastage
in general.
This change will not be the last of such changes!
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-05-18 03:53:31 +00:00
|
|
|
|
|
|
|
rmgit()
|
|
|
|
{
|
|
|
|
(
|
|
|
|
cd "$1" || $err "!cd gitrepo $1"
|
|
|
|
find . -name ".git" -exec rm -Rf {} + || $err "!rm .git $1"
|
|
|
|
find . -name ".gitmodules" -exec rm -Rf {} + || $err "!rm .gitmod $1"
|
|
|
|
) || $err "Cannot remove .git/.gitmodules in $1"
|
|
|
|
}
|