forked from BOINC/boinc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_svn_version.sh
63 lines (57 loc) · 2.05 KB
/
generate_svn_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
62
63
#!/usr/bin/env bash
HEADER="svn_version.h"
TMPFILE="$HEADER.tmp"
echo "#ifndef SVN_VERSION_H" > $TMPFILE
echo "#define SVN_VERSION_H" >> $TMPFILE
echo "" >> $TMPFILE
if [ -d .git/svn ]; then
CMD="git svn info"
elif [ -d .git ]; then
GIT_LOG=`git log -n1 --pretty="format:%H"`
HOST=`hostname`
BRANCH=`git branch | sed -n 's/^\* *//p'`
remote=`git config --get branch.$BRANCH.remote 2>/dev/null`
if [ "$?" != "0" ]; then
remote="origin"
fi
URL=`git config --get remote.$remote.url`
DATE=`git log -n1 --pretty="format:%ct"`
elif [ -d .svn ]; then
CMD="svn info"
else
CMD=""
fi
if [ "x$GIT_LOG" != "x" ]; then
echo "#define SVN_VERSION \"$GIT_LOG [$URL] ($HOST:$PWD [$BRANCH])\"" >> $TMPFILE
echo "$GIT_LOG" | sed 's/^\(........\).*/#define GIT_REVISION 0x\1/' >> $TMPFILE
echo "#define GIT_DATE $DATE" >> $TMPFILE
test "x$URL" = "x" ||
echo "$URL" |
sed 's/.git$//;s%.*://%%;s/[^/]*@//;s/[^a-zA-Z0-9]/_/g;s/__*/_/g;
y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/;
s/^/#define REPOSITORY_/;s/$/ 1/' >> $TMPFILE
elif [ "x$CMD" != "x" ]; then
LANG=C
URL=`$CMD | awk '
/^URL/ { url = $2; };
/^Rev/ { rev = $2; };
END { print "#define SVN_VERSION \"Repository: " url \
" Revision: " rev "\"" >> "'"$TMPFILE"'";
print "#define SVN_REPOSITORY \"" url "\"" >> "'"$TMPFILE"'";
print "#define SVN_REVISION " rev >> "'"$TMPFILE"'";
print url };'`
echo $URL |
sed 's%.*://%%;s/[^/]*@//;s/[^a-zA-Z0-9]/_/g;s/__*/_/g;
y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/;
s/^/#define REPOSITORY_/;s/$/ 1/' >> $TMPFILE
else
echo "#include \"version.h\"" >> $TMPFILE
echo "#define SVN_VERSION BOINC_VERSION_STRING" >> $TMPFILE
fi
echo "" >> $TMPFILE
echo "#endif" >> $TMPFILE
if cmp "$HEADER" "$TMPFILE" >/dev/null 2>&1; then
rm -f "$TMPFILE"
else
mv "$TMPFILE" "$HEADER"
fi