unify build/defconfig and modify/defconfig

they fundamentally perform the same action: copy
the .config file and run make, but build runs
make-all, while modify runs make-oldconfig or
make-menuconfig

merge this functionality together

also:
./handle config file

^ this is the new syntax, not:
./build defconfig for

for example:

./handle config file -b coreboot x200_8mb <-- build x200 rom
./handle config file -m coreboot x200_8mb <-- modify configs
./handle config file -u coreboot x200_8mb <-- make-oldconfig
./handle config file -u seabios
./handle config file -b u-boot

yes, 1 script and a sloccount reduction of 52. and the audit?
it continues.

Signed-off-by: Leah Rowe <leah@libreboot.org>
btrfsvols
Leah Rowe 2023-08-21 00:40:35 +01:00
parent 0faf2a0c6f
commit 7be4706552
4 changed files with 45 additions and 134 deletions

1
handle Symbolic link
View File

@ -0,0 +1 @@
lbmk

View File

@ -166,7 +166,7 @@ if [ ! -f "${seavgabiosrom}" ] \
|| [ ! -f elf/seabios/default/vgarom/bios.bin.elf ] \
|| [ ! -f elf/seabios/default/normal/bios.bin.elf ]; then
[ "${payload_seabios}" = "y" ] && \
./build defconfig for seabios
./handle config file -b seabios
fi
[ "${payload_memtest}" = "y" ] && [ ! -f "memtest86plus/memtest" ] && \
@ -211,7 +211,7 @@ if [ "${payload_grub}" = "y" ] \
fi
if [ "${payload_uboot}" = "y" ]; then
./build defconfig for u-boot ${board}
./handle config file -b u-boot ${board}
ubdir="elf/u-boot/${board}/${uboot_config}"
ubootelf="${ubdir}/u-boot.elf"
[ ! -f "${ubootelf}" ] && [ -f "${ubdir}/u-boot.bin" ] && \
@ -497,7 +497,8 @@ mkRoms()
return 0
fi
./build defconfig for coreboot ${board}
./handle config file -b coreboot ${board}
_corebootrom="elf/coreboot/${board}/${initmode}_${displaymode}"
[ "${initmode}" = "normal" ] && \
_corebootrom="${_corebootrom%_${displaymode}}"

View File

@ -37,6 +37,7 @@ config_name=""
crossgcc_ada=""
elfdir=""
listfile=""
mode=""
project=""
target=""
target_dir=""
@ -44,10 +45,27 @@ tree=""
main()
{
[ $# -lt 1 ] && err "Project name not specified"
project="${1}"
while getopts b:m:u: option
do
case "${1}" in
-b)
mode="all"
shift ;;
-u)
mode="oldconfig"
shift ;;
-m)
mode="menuconfig"
shift ;;
*)
err "Invalid option" ;;
esac
project="${OPTARG}"
shift
done
[ -z "${mode}" ] && err "mode not given (-m menuconfig or -u oldconfig)"
elfdir="elf/${project}"
shift 1
cfgsdir="resources/${project}"
[ -d "${cfgsdir}" ] || err "directory, ${cfgsdir}, does not exist"
@ -55,8 +73,6 @@ main()
listfile="${cfgsdir}/build.list"
[ -f "${listfile}" ] || err "list file, ${listfile}, does not exist"
printf "Building %s binaries (elf files)\n" ${project}
# Build for all targets if no argument is given
if [ "$#" -eq 0 ]; then
for target_dir in "${cfgsdir}"/*; do
@ -66,21 +82,24 @@ main()
done
fi
[ ! -d "${elfdir}" ] && \
[ ! -d "${elfdir}" ] && [ "${mode}" = "all" ] && \
mkdir -p ${elfdir}/
for x in "$@"; do
target="${x}"
if [ "${project}" = "coreboot" ]; then
printf "Running 'make %s' for project '%s, target '%s''\n" \
"${mode}" "${project}" "${target}"
if [ "${project}" = "coreboot" ] && [ "${mode}" = "all" ]; then
./update blobs download ${target} || err "blobutil"
fi
build_defconfig || exit 1
handle_defconfig || exit 1
done
printf "Done! The files are stored under %s/\n\n" ${elfdir}
[ "${mode}" = "all" ] && \
printf "Done! The files are stored under %s/\n\n" ${elfdir}
}
build_defconfig()
handle_defconfig()
{
handle_dependencies "${target}" || return 1
@ -89,12 +108,12 @@ build_defconfig()
config="${y}"
config_name="${config#$target_dir/config/}"
printf "build/defconfig/%s %s: build config %s\n" \
printf "build/defconfig/%s %s: handling config %s\n" \
${project} ${target} ${config_name}
check_config || continue
build_elf
copy_elf
[ "${mode}" != "all" ] || check_config || continue
run_make_command
[ "${mode}" != "all" ] || copy_elf
done
}
@ -123,7 +142,7 @@ handle_dependencies()
# u-boot and coreboot are both compiled with coreboot's crossgcc
if [ "${project}" = "coreboot" ] || [ "${project}" = "u-boot" ]; then
check_cross_compiler || err "crossgcc fail"
[ "${mode}" != "all" ] || check_cross_compiler || err "crossgcc"
fi
}
@ -199,22 +218,19 @@ check_config()
fi
done
mkdir -p "${dest_dir}"
printf "build/%s %s: building config %s).\n" \
${project} ${target} ${config_name}
}
build_elf()
run_make_command()
{
make -C "${codedir}" distclean || err "build_elf"
make -C "${codedir}" distclean || err "run_make_command"
cp "${config}" "${codedir}/.config" || err "build_elf"
make -C "${codedir}" silentoldconfig || \
cp "${config}" "${codedir}/.config" || err "run_make_command"
[ "${mode}" != "all" ] || make -C "${codedir}" silentoldconfig || \
make -C "${codedir}" oldconfig || : # don't error on oldconfig
[ "${project}" = "coreboot" ] && \
[ "${project}" = "coreboot" ] && [ "${mode}" = "all" ] && \
printf "%s\n" "${our_version}" > "${codedir}/.coreboot-version"
make -C "${codedir}" -j"$(nproc)" all || err "build_elf"
make -C "${codedir}" -j$(nproc) ${mode} || err "run_make_command"
}
copy_elf()

View File

@ -1,107 +0,0 @@
#!/usr/bin/env sh
#
# helper script: update project configs (based on defconfig)
#
# Copyright (C) 2021, 2023 Leah Rowe <info@minifree.org>
# Copyright (C) 2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e
cfgsdir=""
mode=""
project=""
main()
{
while getopts m:u: option
do
case "${1}" in
-u)
mode="oldconfig"
shift ;;
-m)
mode="menuconfig"
shift ;;
*)
err "Invalid option" ;;
esac
project="${OPTARG}"
shift
done
[ -z "${mode}" ] && err "mode not given (-m menuconfig or -u oldconfig)"
cfgsdir="resources/${project}"
[ -f "${cfgsdir}/build.list" ] || err "Invalid project name given"
printf "Updating %s configs using: make %s\n\n" "${project}" "${mode}"
if [ $# -gt 0 ]; then
for target in "${@}"; do
configure_target "${target}"
done
else
for target in ${cfgsdir}/*; do
[ ! -d "${target}" ] && continue
configure_target "${target##*/}"
done
fi
}
configure_target()
{
target=${1}
targetdir="${cfgsdir}/${target}"
if [ ! -f "${targetdir}/target.cfg" ]; then
printf "\nmodify/defconfig %s: no target.cfg for %s. SKIP!\n" \
"${project}" "${target}"
return 0
fi
tree="undefined"
. "${targetdir}/target.cfg"
[ "${tree}" = "undefined" ] && return 0
codedir="${project}/${tree}"
[ -d "${codedir}" ] || ./fetch_trees ${project} ${tree} || \
err "cant download $project"
for cfg in "${targetdir}/config/"*; do
[ ! -f "${cfg}" ] && continue
make distclean -BC "${codedir}"
[ -f "${cfg}_" ] && err "${cfg}_ exists from old run"
cp "${cfg}" "${cfg}_"
cp "${cfg}_" "${codedir}/.config"
make ${mode} -BC "${codedir}"
mv "${codedir}/.config" "${cfg}"
make distclean -BC "${codedir}"
rm -f "${cfg}_"
done
}
err()
{
printf "ERROR: modify/defconfig: %s\n" "${1}" 1>&2
exit 1
}
main $@