blob: 4d49fa1507c387713701916e0974902a7b9b9ee0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#!/bin/sh
#
# Generate $1 with:
# #define BUILD_GIT_HEAD "<git-head-revision>"
# But do not touch $1 if the git-revision is already up-to-date.
#
if test "x$1" = "x" ; then
echo "usage: ./genversion <file>"
exit 1
fi
#
# Check whether this is a valid git repository.
# Set ISGIT to 1=true or 0=false.
#
ISGIT=0
REV=`git rev-parse --git-dir 2>/dev/null`
if test "x$?" = "x0" ; then
ISGIT=1
fi
#
# Check the old revision from $1.
#
if test -f "$1" ; then
OLDREV=`cat "$1"`
else
if test $ISGIT = 0 ; then
echo "WARNING: version file $1 is missing"
echo "#define BUILD_GIT_HEAD \"unknown-revision\""
exit 0
fi
OLDREV=""
fi
#
# Check new revision from "git describe". However, if this is no valid
# git-repository, return success and do nothing.
#
if test $ISGIT = 0 ; then
exit 0
fi
NEWREV=`git describe`
NEWREV="#define BUILD_GIT_HEAD \"$NEWREV\""
#
# Exit if the file is already up to date.
# Otherwise, write the new revision into the file.
#
if test "x$OLDREV" = "x$NEWREV" ; then
exit 0
fi
echo "$NEWREV" >"$1"
|