-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-gitdefs.sh
54 lines (42 loc) · 1.47 KB
/
make-gitdefs.sh
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
#!/bin/bash
file='./client/gitdefs.inc'
if [ ! -d './.git/' ]; then
echo "#define NO_VERSIONCONTROL 1" >> '$file.tmp'
echo "Source tree not under version control, creating dummy gitdefs file..."
rm -f $file
mv '$file.tmp' $file
exit 0
fi
function shorten_tag {
local IFS='-'
local tag_array=
read -a tag_array <<< "$1"
unset tag_array[2] tag_array[3]
echo "${tag_array[*]}"
}
GIT_TAG_SHORT=`git describe --abbrev=4`
GIT_TAG_SHORT=$(shorten_tag $GIT_TAG_SHORT)
GIT_TAG_LONG=`git describe --abbrev=4 --dirty=-d`
GIT_REF_COMMIT=`git rev-parse HEAD`
GIT_COMMIT_COUNT=`git rev-list HEAD --count`
GIT_VERSION_DATE=`git log -1 --format=%at`
GIT_COMPATIBLE_VERSIONID=`git rev-list 1.6.0..HEAD --count`
GIT_COMPATIBLE_VERSIONID=`expr 2165 + $GIT_COMPATIBLE_VERSIONID`
echo "#define GIT_TAG_SHORT \"$GIT_TAG_SHORT\"" > '$file.tmp'
echo "#define GIT_TAG_LONG \"$GIT_TAG_LONG\"" >> '$file.tmp'
echo "#define GIT_REF_COMMIT \"$GIT_REF_COMMIT\"" >> '$file.tmp'
echo "#define GIT_COMMIT_COUNT $GIT_COMMIT_COUNT" >> '$file.tmp'
echo "#define VERSION_DATE $GIT_VERSION_DATE" >> '$file.tmp'
echo "#define COMPATIBLE_VERSIONID $GIT_COMPATIBLE_VERSIONID" >> '$file.tmp'
touch $file
diff --brief '$file.tmp' $file > /dev/null
has_changes=$?
if [ $has_changes -eq 1 ]
then
echo "Version changes detected updating the gitdefs file..."
rm -f $file
mv '$file.tmp' $file
else
echo "No Version changes detected, using the old gitdefs file..."
rm -f '$file.tmp'
fi