build 3.5 KB

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