-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmakeversion.sh
51 lines (39 loc) · 1.14 KB
/
makeversion.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
#!/bin/bash
# @brief Make version number
# @author Wolfram Rösler <[email protected]>
# @date 2017-02-12
# Check command line
if [ $# = 2 -a "$1" = "-o" ];then
# Called with -o: Create a .o file with the version number
bash $0 | ${CMAKE_CXX_COMPILER:-c++} -x c++ -c - -o "$2"
exit
elif [ $# != 0 ];then
# Illegal command line
echo "Generate version number"
echo "Usage: $0 [ -o version.o ]"
exit 1
fi
# Get the git repository version number
REPO=$(git describe --dirty --always --tags)
# Get the build time stamp
WHEN=$(date +"%Y-%m-%d %H:%M:%S")
# Get the user name
WHO="$USER"
# Get the machine name
WHERE=$(hostname)
# Get the OS version
WHAT=$(uname -sr)
# Put it all together
VERSION="$REPO (built $WHEN by $WHO on $WHERE with $WHAT)"
# Output the version number to the build log
echo "Building version $VERSION" >&2
# Create the version.cpp file
# NOTE: No includes to speed up compilation (remember that this file is
# re-created and compiled whenever a program is linked)
cat <<!
// This file was created by $0 on $(date)
// Do not edit - do not add to git
char const *Version() {
return "@(#)$VERSION" + 4;
}
!