You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

genbuild.sh 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh
  2. # Copyright (c) 2012-2016 The Starwels developers
  3. # Distributed under the MIT software license, see the accompanying
  4. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
  5. if [ $# -gt 1 ]; then
  6. cd "$2"
  7. fi
  8. if [ $# -gt 0 ]; then
  9. FILE="$1"
  10. shift
  11. if [ -f "$FILE" ]; then
  12. INFO="$(head -n 1 "$FILE")"
  13. fi
  14. else
  15. echo "Usage: $0 <filename> <srcroot>"
  16. exit 1
  17. fi
  18. git_check_in_repo() {
  19. ! { git status --porcelain -uall --ignored "$@" 2>/dev/null || echo '??'; } | grep -q '?'
  20. }
  21. DESC=""
  22. SUFFIX=""
  23. if [ "${STARWELS_GENBUILD_NO_GIT}" != "1" -a -e "$(which git 2>/dev/null)" -a "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ] && git_check_in_repo share/genbuild.sh; then
  24. # clean 'dirty' status of touched files that haven't been modified
  25. git diff >/dev/null 2>/dev/null
  26. # if latest commit is tagged and not dirty, then override using the tag name
  27. RAWDESC=$(git describe --abbrev=0 2>/dev/null)
  28. if [ "$(git rev-parse HEAD)" = "$(git rev-list -1 $RAWDESC 2>/dev/null)" ]; then
  29. git diff-index --quiet HEAD -- && DESC=$RAWDESC
  30. fi
  31. # otherwise generate suffix from git, i.e. string like "59887e8-dirty"
  32. SUFFIX=$(git rev-parse --short HEAD)
  33. git diff-index --quiet HEAD -- || SUFFIX="$SUFFIX-dirty"
  34. fi
  35. if [ -n "$DESC" ]; then
  36. NEWINFO="#define BUILD_DESC \"$DESC\""
  37. elif [ -n "$SUFFIX" ]; then
  38. NEWINFO="#define BUILD_SUFFIX $SUFFIX"
  39. else
  40. NEWINFO="// No build information available"
  41. fi
  42. # only update build.h if necessary
  43. if [ "$INFO" != "$NEWINFO" ]; then
  44. echo "$NEWINFO" >"$FILE"
  45. fi