build 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 mode xp ser`
  16. err="fail"
  17. main()
  18. {
  19. [ $# -lt 1 ] && $err "bad command"
  20. spath="script/$1"
  21. for g in "which git" "git config --global user.name" \
  22. "git config --global user.email" "git_init"; do
  23. eval "$g 1>/dev/null 2>/dev/null || git_err \"$g\""
  24. done
  25. case "${1}" in
  26. version) printf "%s\nWebsite: %s\n" "$relname" "$projectsite" ;;
  27. release) shift 1; mkrelease $@ ;;
  28. inject) shift 1; vendor_inject $@ ;;
  29. download) shift 1; vendor_download $@ ;;
  30. roms)
  31. if [ $# -gt 1 ] && [ "$2" = "serprog" ]; then
  32. x_ ./update trees -b stm32-vserprog
  33. x_ ./update trees -b pico-serprog; return 0
  34. fi; shift 1
  35. x_ ./update trees -b coreboot $@ ;;
  36. *)
  37. [ -f "$spath" ] || $err "bad command"
  38. shift 1; "$spath" $@ || $err "excmd: $spath $@" ;;
  39. esac
  40. set -u -e # some commands disable them. turn them on!
  41. }
  42. git_init()
  43. {
  44. [ -L ".git" ] && return 1
  45. [ -e ".git" ] && return 0
  46. eval `setvars "$(date -Rud @$versiondate)" cdate _nogit`
  47. git init || return 1
  48. git add -A . || return 1
  49. git commit -m "$projectname $version" --date "$cdate" \
  50. --author="xbmk <xbmk@example.com>" || return 1
  51. git tag -a "$version" -m "$projectname $version" || return 1
  52. }
  53. git_err()
  54. {
  55. printf "You need to set git name/email, like so:\n%s\n\n" "$1" 1>&2
  56. $err "Git name/email not configured"
  57. }
  58. mkrelease()
  59. {
  60. export XBMK_RELEASE="y"
  61. vdir="release"
  62. while getopts d:m: option; do
  63. [ -z "$OPTARG" ] && $err "empty argument not allowed"
  64. case "$option" in
  65. d) vdir="$OPTARG" ;;
  66. m) mode="$OPTARG" ;;
  67. *) $err "invalid option '-$option'" ;;
  68. esac
  69. done
  70. vdir="$vdir/$version"
  71. src_dirname="${relname}_src"
  72. srcdir="$vdir/$src_dirname"
  73. [ -e "$vdir" ] && $err "already exists: \"$vdir\""
  74. mkdir -p "$vdir" || $err "mkvdir: !mkdir -p \"$vdir\""
  75. git clone . "$srcdir" || $err "mkdir: !gitclone \"$srcdir\""
  76. touch "$srcdir/lock" || $err "can't make lock file in $srcdir/"
  77. build_release
  78. printf "\n\nDONE! Check release files under %s\n" "$vdir"
  79. }
  80. build_release()
  81. {
  82. (
  83. cd "$srcdir" || $err "$vdir: !cd \"$srcdir\""
  84. ./update trees -f
  85. rmgit .
  86. x_ rm -Rf tmp
  87. x_ mv src/docs docs
  88. ) || $err "can't create release files"
  89. git log --graph --pretty=format:'%Cred%h%Creset %s %Creset' \
  90. --abbrev-commit > "$srcdir/CHANGELOG" || $err "!gitlog $srcdir"
  91. rm -f "$srcdir/lock" || $err "can't remove lock file in $srcdir"
  92. (
  93. cd "${srcdir%/*}" || $err "$vdir: mktarball \"$srcdir\""
  94. mktarball "${srcdir##*/}" "${srcdir##*/}.tar.xz" || $err "$vdir: mksrc"
  95. ) || $err "can't create src tarball"
  96. [ "$mode" = "src" ] && return 0
  97. touch "$srcdir/lock" || $err "can't make lock file in $srcdir/"
  98. (
  99. cd "$srcdir" || $err "$vdir: 2 !cd \"$srcdir\""
  100. ./update trees -b coreboot || $err "$vdir: roms-all"
  101. ./update trees -b pico-serprog || $err "$vdir: rp2040"
  102. ./update trees -b stm32-vserprog || $err "$vdir: stm32"
  103. x_ mv bin ../roms
  104. ) || $err "can't build rom images"
  105. rm -Rf "$srcdir" || $err "!rm -Rf $srcdir"
  106. }
  107. fail()
  108. {
  109. tmp_cleanup || printf "WARNING: can't rm tmpfiles: %s\n" "$TMPDIR" 1>&2
  110. err_ "${1}"
  111. }
  112. tmp_cleanup()
  113. {
  114. [ "$xbmk_parent" = "y" ] || return 0
  115. [ "$TMPDIR" = "/tmp" ] || rm -Rf "$TMPDIR" || return 1
  116. rm -f lock || return 1
  117. }
  118. main $@
  119. tmp_cleanup || err_ "can't rm TMPDIR upon non-zero exit: $TMPDIR"