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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. LAST_COMMIT_DATE=""
  18. if [ -e "$(which git 2>/dev/null)" -a "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
  19. # clean 'dirty' status of touched files that haven't been modified
  20. git diff >/dev/null 2>/dev/null
  21. # if latest commit is tagged and not dirty, then override using the tag name
  22. RAWDESC=$(git describe --abbrev=0 2>/dev/null)
  23. if [ "$(git rev-parse HEAD)" = "$(git rev-list -1 $RAWDESC 2>/dev/null)" ]; then
  24. git diff-index --quiet HEAD -- && DESC=$RAWDESC
  25. fi
  26. # otherwise generate suffix from git, i.e. string like "59887e8-dirty"
  27. SUFFIX=$(git rev-parse --short HEAD)
  28. git diff-index --quiet HEAD -- || SUFFIX="$SUFFIX-dirty"
  29. # get a string like "2012-04-10 16:27:19 +0200"
  30. LAST_COMMIT_DATE="$(git log -n 1 --format="%ci")"
  31. fi
  32. if [ -n "$DESC" ]; then
  33. NEWINFO="#define BUILD_DESC \"$DESC\""
  34. elif [ -n "$SUFFIX" ]; then
  35. NEWINFO="#define BUILD_SUFFIX $SUFFIX"
  36. else
  37. NEWINFO="// No build information available"
  38. fi
  39. # only update build.h if necessary
  40. if [ "$INFO" != "$NEWINFO" ]; then
  41. echo "$NEWINFO" >"$FILE"
  42. if [ -n "$LAST_COMMIT_DATE" ]; then
  43. echo "#define BUILD_DATE \"$LAST_COMMIT_DATE\"" >> "$FILE"
  44. fi
  45. fi