build 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #!/usr/bin/env sh
  2. # SPDX-License-Identifier: GPL-3.0-or-later
  3. # Copyright (c) 2014-2015,2020-2024 Leah Rowe <leah@libreboot.org>
  4. # Copyright (c) 2015 Patrick "P. J." McDermott <pj@pehjota.net>
  5. # Copyright (c) 2015-2016 Klemens Nanni <contact@autoboot.org>
  6. # Copyright (c) 2022 Caleb La Grange <thonkpeasant@protonmail.com>
  7. set -u -e
  8. if [ "./${0##*/}" != "${0}" ] || [ ! -f "build" ] || [ -L "build" ]; then
  9. printf "You must run this in the proper work directory.\n" 1>&2
  10. exit 1
  11. fi
  12. . "include/lib.sh"
  13. . "include/vendor.sh"
  14. . "include/mrc.sh"
  15. eval "$(setvars "" vdir src_dirname srcdir _xm mode xp)"
  16. err="fail"
  17. linkpath="${0}"
  18. linkname="${linkpath##*/}"
  19. main()
  20. {
  21. [ $# -lt 1 ] && badcmd
  22. spath="script/$1"
  23. for g in "which git" "git config --global user.name" \
  24. "git config --global user.email" "git_init"; do
  25. eval "$g 1>/dev/null 2>/dev/null || git_err \"$g\""
  26. done
  27. case "${1}" in
  28. version) printf "%s\nWebsite: %s\n" "$relname" "$projectsite" ;;
  29. release) shift 1; mkrelease $@ ;;
  30. inject) shift 1; vendor_inject $@ ;;
  31. download) shift 1; vendor_download $@ ;;
  32. *)
  33. [ -f "$spath" ] || badcmd
  34. shift 1; "$spath" $@ || $err "excmd: $spath $@" ;;
  35. esac
  36. set -u -e # some commands disable them. turn them on!
  37. }
  38. git_init()
  39. {
  40. [ -L ".git" ] && return 1
  41. [ -e ".git" ] && return 0
  42. eval "$(setvars "$(date -Rud @$versiondate)" cdate _nogit)"
  43. git init || return 1
  44. git add -A . || return 1
  45. git commit -m "$projectname $version" --date "$cdate" \
  46. --author="xbmk <xbmk@example.com>" || return 1
  47. git tag -a "$version" -m "$projectname $version" || return 1
  48. }
  49. mkrelease()
  50. {
  51. export XBMK_RELEASE="y"
  52. vdir="release"
  53. while getopts d:m: option; do
  54. [ -z "$OPTARG" ] && badcmd "empty argument not allowed"
  55. case "$option" in
  56. d) vdir="$OPTARG" ;;
  57. m) mode="$OPTARG" ;;
  58. *) badcmd "invalid option '-$option'" ;;
  59. esac
  60. done
  61. vdir="$vdir/$version"
  62. src_dirname="${relname}_src"
  63. srcdir="$vdir/$src_dirname"
  64. [ -e "$vdir" ] && $err "already exists: \"$vdir\""
  65. mkdir -p "$vdir" || $err "mkvdir: !mkdir -p \"$vdir\""
  66. git clone . "$srcdir" || $err "mkdir: !gitclone \"$srcdir\""
  67. touch "$srcdir/lock" || $err "can't make lock file in $srcdir/"
  68. build_release
  69. printf "\n\nDONE! Check release files under %s\n" "$vdir"
  70. }
  71. build_release()
  72. {
  73. _xm="build_release $vdir"
  74. (
  75. cd "$srcdir" || $err "$_xm: !cd \"$srcdir\""
  76. fetch_trees
  77. x_ mv src/docs docs
  78. ) || $err "can't create release files"
  79. git log --graph --pretty=format:'%Cred%h%Creset %s %Creset' \
  80. --abbrev-commit > "$srcdir/CHANGELOG" || $err "!gitlog $srcdir"
  81. rm -f "$srcdir/lock" || $err "can't remove lock file in $srcdir"
  82. (
  83. cd "${srcdir%/*}" || $err "$_xm: mktarball \"$srcdir\""
  84. mktarball "${srcdir##*/}" "${srcdir##*/}.tar.xz" || $err "$_xm: mksrc"
  85. ) || $err "can't create src tarball"
  86. [ "$mode" = "src" ] && return 0
  87. touch "$srcdir/lock" || $err "can't make lock file in $srcdir/"
  88. (
  89. cd "$srcdir" || $err "$_xm: 2 !cd \"$srcdir\""
  90. ./build roms all || $err "$_xm: roms-all"
  91. ./build roms serprog rp2040 || $err "$_xm: rp2040"
  92. ./build roms serprog stm32 || $err "$_xm: stm32"
  93. x_ mv bin ../roms
  94. ) || $err "can't build rom images"
  95. rm -Rf "$srcdir" || $err "!rm -Rf $srcdir"
  96. }
  97. fetch_trees()
  98. {
  99. for x in $(items config/git); do
  100. ./update trees -f "$x" || $err "$_xm: fetch $x"
  101. singletree "$x" || x_ rm -Rf "src/$x/$x"
  102. done
  103. rmgit .
  104. }
  105. fail()
  106. {
  107. tmp_cleanup || printf "WARNING: can't rm tmpfiles: %s\n" "$tmpdir" 1>&2
  108. err_ "${1}"
  109. }
  110. tmp_cleanup()
  111. {
  112. [ "$tmpdir_was_set" = "n" ] || return 0
  113. rm -Rf "$tmpdir" || return 1
  114. rm -f lock || return 1
  115. }
  116. main $@
  117. tmp_cleanup || err_ "can't rm tmpdir upon non-zero exit: $tmpdir"