/
genversion.sh
83 lines (76 loc) · 2.7 KB
/
genversion.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
##########################################################################
## ##
## This file is part of Wallpaper Switcher, a virtual desktop ##
## wallpaper (background image) switcher for KDE Plasma 5. ##
## ##
## Copyright (c) 2016 Jonathan Marten <jjm@keelhaul.me.uk> ##
## Home page: http://github.com/martenjj/wallpaperswitch ##
## ##
## This program is free software; you can redistribute it and/or ##
## modify it under the terms of the GNU General Public License as ##
## published by the Free Software Foundation; either version 2 of ##
## the License, or (at your option) any later version. ##
## ##
## It is distributed in the hope that it will be useful, but ##
## WITHOUT ANY WARRANTY; without even the implied warranty of ##
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
## GNU General Public License for more details. ##
## ##
## You should have received a copy of the GNU General Public ##
## License along with this program; see the file COPYING for further ##
## details. If not, see http://www.gnu.org/licenses/ ##
## ##
##########################################################################
SRC=$1 # CMAKE_CURRENT_SOURCE_DIR
BIN=$2 # CMAKE_CURRENT_BINARY_DIR
VER=$3 # base application version
VCSTYPE= # VCS type detected
VCSREV= # VCS revision
if [ -d "$SRC/.svn" ] # is source under SVN?
then
VCSTYPE="SVN"
VCSREV=`svn info $SRC 2>/dev/null | sed -n -e'/^Revision:/ { s/^[^:]*: *//;p;q }'`
echo "Current $VCSTYPE revision: ${VCSREV:-unknown}"
else # source not under SVN
if [ -d "$SRC/.git" ] # try for GIT instead
then
VCSTYPE="GIT"
VCSREV=`cd $SRC && git describe 2>/dev/null`
# formatted version
if [ ! -n "$VCSREV" ] # if not available then
then # hash of last commit
VCSREV=`cd $SRC && git log -1 --abbrev-commit | sed -e 's/commit *//;q'`
fi
echo "Current $VCSTYPE revision: ${VCSREV:-unknown}"
fi
fi
TMPFILE="$BIN/version.h.tmp" # temporary header file
{
echo "#ifndef VERSION"
echo "#define VERSION \"${VER}\""
echo "#endif"
echo
echo "#define VCS_REVISION_STRING \"${VCSREV}\""
echo "#define VCS_TYPE_STRING \"${VCSTYPE}\""
if [ -n "$VCSREV" ]
then
echo "#define VCS_HAVE_VERSION 1"
fi
echo
} >$TMPFILE
OUTFILE="$BIN/version.h" # the real header file
if [ ! -f $OUTFILE ] # does not exist yet
then
echo "Creating $OUTFILE..."
else # already exists
if cmp -s $TMPFILE $OUTFILE # is it still current?
then
rm $TMPFILE # yes, nothing to do
exit 0
else
echo "Updating $OUTFILE..."
fi
fi
mv $TMPFILE $OUTFILE # update the header file
exit 0 # successfully updated