diff options
Diffstat (limited to 'build')
-rwxr-xr-x | build | 142 |
1 files changed, 86 insertions, 56 deletions
@@ -1,55 +1,55 @@ #!/usr/bin/env sh # SPDX-License-Identifier: GPL-3.0-or-later -# SPDX-FileCopyrightText: 2014,2015,2020,2021,2023 Leah Rowe <leah@libreboot.org> +# SPDX-FileCopyrightText: 2014,2015,2020-2024 Leah Rowe <leah@libreboot.org> # SPDX-FileCopyrightText: 2015 Patrick "P. J." McDermott <pj@pehjota.net> # SPDX-FileCopyrightText: 2015, 2016 Klemens Nanni <contact@autoboot.org> # SPDX-FileCopyrightText: 2022, Caleb La Grange <thonkpeasant@protonmail.com> set -u -e -export LC_COLLATE=C -export LC_ALL=C +if [ "./${0##*/}" != "${0}" ] || [ ! -f "build" ] || [ -L "build" ]; then + printf "You must run this in the proper work directory.\n" 1>&2 + exit 1 +fi -. "include/err.sh" . "include/option.sh" +. "include/vendor.sh" +. "include/mrc.sh" -export LBMK_RELEASE="$lbmk_release" - -eval "$(setvars "" option aur_notice)" +eval "$(setvars "" aur_notice vdir src_dirname srcdir _xm mode xp)" err="fail" linkpath="${0}" linkname="${linkpath##*/}" -buildpath="./script/${linkname}" main() { x_ id -u 1>/dev/null 2>/dev/null - [ $# -lt 1 ] && $err "Too few arguments. Try: ${0} help" + [ $# -lt 1 ] && $err "Check $projectname documentation for help." + spath="script/$1" - [ "$1" = "dependencies" ] && x_ install_packages $@ && lbmk_exit 0 + [ "$1" = "dependencies" ] && x_ install_packages $@ && return 0 - for cmd in initcmd check_git check_project git_init excmd; do - eval "${cmd} \$@" - done - lbmk_exit 0 -} + which git 1>/dev/null 2>/dev/null || \ + git_err "git not installed. please install git-scm." + git config --global user.name 1>/dev/null 2>/dev/null || \ + git_err "git config --global user.name \"John Doe\"" + git config --global user.email 1>/dev/null 2>/dev/null || \ + git_err "git config --global user.email \"john.doe@example.com\"" + git_init -initcmd() -{ [ "$(id -u)" != "0" ] || $err "this command as root is not permitted" - check_project - case "${1}" in - help) usage ${0} ;; - list) items "${buildpath}" ;; - version) mkversion ;; + version) printf "%s\n" "$relname" ;; + release) shift 1; mkrelease $@ ;; + inject) shift 1; vendor_inject $@ ;; + download) shift 1; vendor_download $@ ;; *) - option="${1}" - return 0 ;; + [ -f "${spath}" ] || $err "Bad command. Check docs." + shift 1; "$spath" $@ || $err "excmd: ${spath} ${@}" ;; esac - lbmk_exit 0 + set -u -e # some commands disable them. turn them on! } install_packages() @@ -65,63 +65,92 @@ install_packages() . "config/dependencies/${2}" - x_ ${pkg_add} ${pkglist} - [ -z "${aur_notice}" ] && return 0 - printf "You must install AUR packages: %s\n" "$aur_notice" 1>&2 + x_ $pkg_add $pkglist && [ -n "$aur_notice" ] && \ + printf "Please install AUR packages: %s\n" "$aur_notice" 1>&2; return 0 } -# release archives contain .gitignore, but not .git. -# lbmk can be run from lbmk.git, or an archive. git_init() { [ -L ".git" ] && $err "Reference .git is a symlink" [ -e ".git" ] && return 0 - eval "$(setvars "$(date -Rd @${versiondate})" cdate _nogit)" + eval "$(setvars "$(date -Rud @${versiondate})" cdate _nogit)" git init || $err "${PWD}: cannot initialise Git repository" git add -A . || $err "${PWD}: cannot add files to Git repository" git commit -m "${projectname} ${version}" --date "${cdate}" \ - --author="lbmk <lbmk@libreboot.org>" || \ + --author="xbmk <xbmk@example.com>" || \ $err "$PWD: can't commit ${projectname}/${version}, date $cdate" git tag -a "${version}" -m "${projectname} ${version}" || \ $err "${PWD}: cannot git-tag ${projectname}/${version}" } -excmd() +mkrelease() { - lbmkcmd="${buildpath}/${option}" - [ -f "${lbmkcmd}" ] || $err "Invalid command. Run: ${linkpath} help" - shift 1; "$lbmkcmd" $@ || $err "excmd: ${lbmkcmd} ${@}" -} - -usage() -{ - progname=${0} - cat <<- EOF - $(mkversion) + export XBMK_RELEASE="y" + + vdir="release" + while getopts d:m: option; do + [ -z "${OPTARG}" ] && $err "Empty argument not allowed" + case "${option}" in + d) vdir="${OPTARG}" ;; + m) mode="${OPTARG}" ;; + *) $err "Invalid option" ;; + esac + done - USAGE: ${progname} <OPTION> + vdir="${vdir}/${version}" + src_dirname="${relname}_src" + srcdir="${vdir}/${src_dirname}" - possible values for 'OPTION': - $(items "${buildpath}") + [ -e "${vdir}" ] && $err "already exists: \"${vdir}\"" + mkdir -p "${vdir}" || $err "mkvdir: !mkdir -p \"${vdir}\"" + git clone . "${srcdir}" || $err "mkdir: !gitclone \"${srcdir}\"" - To know what ${projectname} version you're on, type: - ${progname} version + build_release - Refer to ${projectname} documentation for more info. - EOF + printf "\n\nDONE! Check release files under %s\n" "${vdir}" } -mkversion() +build_release() { - printf "revision: %s %s\n" "$projectname" "$version" - printf "revision date: %s\n" "$(date -Rud @${versiondate})" + _xm="build_release ${vdir}" + ( + cd "${srcdir}" || $err "${_xm}: !cd \"${srcdir}\"" + fetch_trees + x_ mv src/docs docs + ) || $err "can't create release files" + + git log --graph --pretty=format:'%Cred%h%Creset %s %Creset' \ + --abbrev-commit > "${srcdir}/CHANGELOG" || $err "!gitlog $srcdir" + + ( + cd "${srcdir%/*}" || $err "${_xm}: mktarball \"${srcdir}\"" + mktarball "${srcdir##*/}" "${srcdir##*/}.tar.xz" || $err "$_xm: mksrc" + ) || $err "can't create src tarball" + [ "${mode}" = "src" ] && return 0 + + ( + cd "${srcdir}" || $err "${_xm}: 2 !cd \"${srcdir}\"" + ./build roms all || $err "${_xm}: roms-all" + ./build roms serprog rp2040 || $err "${_xm}: rp2040" + ./build roms serprog stm32 || $err "${_xm}: stm32" + x_ mv bin ../roms + ) || $err "can't build rom images" + + rm -Rf "${srcdir}" || $err "!rm -Rf ${srcdir}" } -lbmk_exit() +fetch_trees() { - tmp_cleanup || err_ "lbmk_exit: can't rm tmpdir upon exit $1: $tmpdir" - exit $1 + for x in $(items config/git); do + ./update trees -f "$x" || $err "$_xm: fetch $x" + done + for x in config/*/build.list; do + [ -f "$x" ] && xp="${x#*/}" && xp="${xp%/*}" + [ ! -f "$x" ] || [ -L "$xp" ] || x_ rm -Rf "src/$xp/$xp" + done + rmgit . + rm -Rf tmp .git src/u-boot/*/test/lib/strlcat.c || $err "$_xm !rm" } fail() @@ -137,3 +166,4 @@ tmp_cleanup() } main $@ +tmp_cleanup || err_ "can't rm tmpdir upon non-zero exit: $tmpdir" |