jack2 codebase
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.

70 lines
1.3KB

  1. #!/bin/bash
  2. #set -x
  3. if test $# -ne 1 -a $# -ne 2
  4. then
  5. echo "Usage: "`basename "$0"`" <file> [define_name]"
  6. exit 1
  7. fi
  8. OUTPUT_FILE="`pwd`/${1}"
  9. TEMP_FILE="${OUTPUT_FILE}.tmp"
  10. #echo svnversion...
  11. #pwd
  12. #echo "$OUTPUT_FILE"
  13. #echo "$TEMP_FILE"
  14. # The script should reside in the toplevel source directory which should contain
  15. # all version control files.
  16. cd `dirname ${0}`
  17. if test $# -eq 2
  18. then
  19. DEFINE=${2}
  20. else
  21. DEFINE=SVN_VERSION
  22. fi
  23. if test -d .svn
  24. then
  25. REV=`svnversion 2> /dev/null`
  26. else
  27. if test -d .git
  28. then
  29. git status >/dev/null # updates dirty state
  30. REV=`git show | grep '^ *git-svn-id:' | sed 's/.*@\([0-9]*\) .*/\1/'`
  31. if test ${REV}
  32. then
  33. test -z "$(git diff-index --name-only HEAD)" || REV="${REV}M"
  34. else
  35. REV=0+`git rev-parse HEAD`
  36. test -z "$(git diff-index --name-only HEAD)" || REV="${REV}-dirty"
  37. fi
  38. fi
  39. fi
  40. if test -z ${REV}
  41. then
  42. REV="unknown"
  43. fi
  44. echo "#define ${DEFINE} \"${REV}\"" > "${TEMP_FILE}"
  45. if test ! -f "${OUTPUT_FILE}"
  46. then
  47. echo "Generated ${OUTPUT_FILE} (${REV})"
  48. cp "${TEMP_FILE}" "${OUTPUT_FILE}"
  49. if test $? -ne 0; then exit 1; fi
  50. else
  51. if ! cmp -s "${OUTPUT_FILE}" "${TEMP_FILE}"
  52. then echo "Regenerated ${OUTPUT_FILE} (${REV})"
  53. cp "${TEMP_FILE}" "${OUTPUT_FILE}"
  54. if test $? -ne 0; then exit 1; fi
  55. fi
  56. fi
  57. rm "${TEMP_FILE}"
  58. exit $?