build 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/usr/bin/env sh
  2. # SPDX-License-Identifier: GPL-3.0-or-later
  3. # Copyright (c) 2020-2024 Leah Rowe <leah@libreboot.org>
  4. # Copyright (c) 2022 Caleb La Grange <thonkpeasant@protonmail.com>
  5. set -u -e
  6. if [ "./${0##*/}" != "${0}" ] || [ ! -f "build" ] || [ -L "build" ]; then
  7. printf "You must run this in the proper work directory.\n" 1>&2
  8. exit 1
  9. fi
  10. . "include/lib.sh"
  11. . "include/vendor.sh"
  12. . "include/mrc.sh"
  13. eval `setvars "" vdir src_dirname srcdir mode xp ser`
  14. err="fail"
  15. main()
  16. {
  17. [ $# -lt 1 ] && $err "bad command"
  18. spath="script/$1"; shcmd="shift 1"
  19. [ "${1#-*}" != "$1" ] && spath="script/trees" && shcmd=":"
  20. for g in "command -v git" "git config --global user.name" \
  21. "git config --global user.email" "git_init"; do
  22. eval "$g 1>/dev/null 2>/dev/null || $err \"Unconfigured: $g\""
  23. done
  24. case "${spath#script/}" in
  25. version) printf "%s\nWebsite: %s\n" "$relname" "$projectsite" ;;
  26. release) shift 1; mkrelease "$@" ;;
  27. inject) shift 1; vendor_inject "$@" ;;
  28. download) shift 1; vendor_download "$@" ;;
  29. roms)
  30. [ $# -gt 1 ] && [ "$2" = "serprog" ] && \
  31. mk -b stm32-vserprog pico-serprog && return 0
  32. shift 1; x_ ./mk -b coreboot "$@" ;;
  33. *)
  34. [ -f "$spath" ] || $err "bad command"
  35. $shcmd; "$spath" "$@" || $err "excmd: $spath $(echo "$@")" ;;
  36. esac
  37. set -u -e # some commands disable them. turn them on!
  38. }
  39. git_init()
  40. {
  41. [ -L ".git" ] && return 1
  42. [ -e ".git" ] && return 0
  43. eval `setvars "$(date -Rud @$versiondate)" cdate _nogit`
  44. git init || return 1
  45. git add -A . || return 1
  46. git commit -m "$projectname $version" --date "$cdate" \
  47. --author="xbmk <xbmk@example.com>" || return 1
  48. git tag -a "$version" -m "$projectname $version" || return 1
  49. }
  50. mkrelease()
  51. {
  52. export XBMK_RELEASE="y"
  53. vdir="release"
  54. while getopts d:m: option; do
  55. [ -z "$OPTARG" ] && $err "empty argument not allowed"
  56. case "$option" in
  57. d) vdir="$OPTARG" ;;
  58. m) mode="$OPTARG" ;;
  59. *) $err "invalid option '-$option'" ;;
  60. esac
  61. done
  62. vdir="$vdir/$version"
  63. src_dirname="${relname}_src"
  64. srcdir="$vdir/$src_dirname"
  65. [ -e "$vdir" ] && $err "already exists: \"$vdir\""
  66. mkdir -p "$vdir" || $err "mkvdir: !mkdir -p \"$vdir\""
  67. git clone . "$srcdir" || $err "mkdir: !gitclone \"$srcdir\""
  68. touch "$srcdir/lock" || $err "can't make lock file in $srcdir/"
  69. build_release
  70. printf "\n\nDONE! Check release files under %s\n" "$vdir"
  71. }
  72. build_release()
  73. {
  74. (
  75. cd "$srcdir" || $err "$vdir: !cd \"$srcdir\""
  76. ./mk -f; x_ rm -Rf tmp; rmgit .
  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 "$vdir: mktarball \"$srcdir\""
  84. mktarball "${srcdir##*/}" "${srcdir##*/}.tar.xz" || $err "$vdir: 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 "$vdir: 2 !cd \"$srcdir\""
  90. mk -b coreboot pico-serprog stm32-vserprog pcsx-redux
  91. x_ mv bin ../roms
  92. ) || $err "can't build rom images"
  93. rm -Rf "$srcdir" || $err "!rm -Rf $srcdir"
  94. }
  95. fail()
  96. {
  97. tmp_cleanup || printf "WARNING: can't rm tmpfiles: %s\n" "$TMPDIR" 1>&2
  98. err_ "${1}"
  99. }
  100. tmp_cleanup()
  101. {
  102. [ "$xbmk_parent" = "y" ] || return 0
  103. [ "$TMPDIR" = "/tmp" ] || rm -Rf "$TMPDIR" || return 1
  104. rm -f lock || return 1
  105. }
  106. main "$@"
  107. tmp_cleanup || err_ "can't rm TMPDIR upon non-zero exit: $TMPDIR"