-
Notifications
You must be signed in to change notification settings - Fork 2
/
update-git-version.sh
executable file
·61 lines (52 loc) · 1.22 KB
/
update-git-version.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
55
56
57
58
59
60
61
#!/bin/sh
#
# Update git-version.sh, but only if it has actually changed so that
# make does not rebuild everything every time.
set -e
cd "$(dirname "$0")"
comment="Unknown error trying to generate git version string"
git_version="unknown"
if test -f .git/info/exclude
then
if git --version > /dev/null
then
if git diff-files --quiet && git diff-index --cached --quiet HEAD
then
dirty=""
else
dirty="-dirty"
fi
if tmp="$(git describe --all --long)"
then
comment="output of \"git describe --all --long\" plus dirty status"
git_version="$tmp$dirty"
else
comment="Error running command: git describe --all --long"
fi
else
comment="Cannot run cmd: git --version"
fi
else
comment="Could not find file .git/info/exclude"
fi
cat>git-version.h.new<<EOF
/* DO NOT EDIT THIS FILE.
* It was generated by the $(basename "$0") script.
*/
#ifndef GIT_VERSION_H
#define GIT_VERSION_H
/* ${comment} */
#define GIT_VERSION_STR "${git_version}"
#endif /* ! GIT_VERSION_H */
EOF
if test -f "git-version.h"
then
if cmp -s "git-version.h.new" "git-version.h"
then
rm "git-version.h.new"
else
mv -f "git-version.h.new" "git-version.h"
fi
else
mv -f "git-version.h.new" "git-version.h"
fi