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