build 3.6 KB

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