Merge branch 'master' into ladi-experimental
[jackdbus.git] / svnversion_regenerate.sh
blobf98f977e94871319cf107c388773d2ea5f568d25
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 OLDPWD=`pwd`
20 cd ..
22 if test $# -eq 2
23 then
24 DEFINE=${2}
25 else
26 DEFINE=SVN_VERSION
29 if test -d .svn
30 then
31 REV=`svnversion 2> /dev/null`
32 else
33 if test -d .git
34 then
35 git status >/dev/null # updates dirty state
36 REV=`git show | grep '^ *git-svn-id:' | sed 's/.*@\([0-9]*\) .*/\1/'`
37 if test ${REV}
38 then
39 test -z "$(git diff-index --name-only HEAD)" || REV="${REV}M"
40 else
41 REV=0+`git rev-parse HEAD`
42 test -z "$(git diff-index --name-only HEAD)" || REV="${REV}-dirty"
47 if test -z ${REV}
48 then
49 REV="unknown"
52 echo "#define ${DEFINE} \"${REV}\"" > ${TEMP_FILE}
53 if test ! -f ${OUTPUT_FILE}
54 then
55 echo "Generated ${OUTPUT_FILE} (${REV})"
56 cp ${TEMP_FILE} ${OUTPUT_FILE}
57 if test $? -ne 0; then exit 1; fi
58 else
59 if ! cmp -s ${OUTPUT_FILE} ${TEMP_FILE}
60 then echo "Regenerated ${OUTPUT_FILE} (${REV})"
61 cp ${TEMP_FILE} ${OUTPUT_FILE}
62 if test $? -ne 0; then exit 1; fi
66 cd "${OLDPWD}"
68 rm ${TEMP_FILE}
70 exit $?