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.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/sh
  2. if [ $# -gt 1 ]; then
  3. cd "$2"
  4. fi
  5. if [ $# -gt 0 ]; then
  6. FILE="$1"
  7. shift
  8. if [ -f "$FILE" ]; then
  9. INFO="$(head -n 1 "$FILE")"
  10. fi
  11. else
  12. echo "Usage: $0 <filename> <srcroot>"
  13. exit 1
  14. fi
  15. DESC=""
  16. SUFFIX=""
  17. if [ -e "$(which git 2>/dev/null)" -a "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
  18. # clean 'dirty' status of touched files that haven't been modified
  19. git diff >/dev/null 2>/dev/null
  20. # if latest commit is tagged and not dirty, then override using the tag name
  21. RAWDESC=$(git describe --abbrev=0 2>/dev/null)
  22. if [ "$(git rev-parse HEAD)" = "$(git rev-list -1 $RAWDESC 2>/dev/null)" ]; then
  23. git diff-index --quiet HEAD -- && DESC=$RAWDESC
  24. fi
  25. # otherwise generate suffix from git, i.e. string like "59887e8-dirty"
  26. SUFFIX=$(git rev-parse --short HEAD)
  27. git diff-index --quiet HEAD -- || SUFFIX="$SUFFIX-dirty"
  28. fi
  29. if [ -n "$DESC" ]; then
  30. NEWINFO="#define BUILD_DESC \"$DESC\""
  31. elif [ -n "$SUFFIX" ]; then
  32. NEWINFO="#define BUILD_SUFFIX $SUFFIX"
  33. else
  34. NEWINFO="// No build information available"
  35. fi
  36. # only update build.h if necessary
  37. if [ "$INFO" != "$NEWINFO" ]; then
  38. echo "$NEWINFO" >"$FILE"
  39. fi