build 3.4 KB

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