File: version.sh

package info (click to toggle)
davs2 1.6-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,300 kB
  • sloc: cpp: 46,477; asm: 33,824; sh: 4,156; ansic: 1,824; makefile: 280
file content (62 lines) | stat: -rwxr-xr-x 3,753 bytes parent folder | download
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
#!/bin/sh

# ============================================================================
# File:
#   version.sh
#   - get version of repository and generate the file version.h
# Author:
#   Falei LUO <falei.luo@gmail.com>
# ============================================================================

# setting API version
api=`grep '#define DAVS2_BUILD' < ./source/davs2.h | sed 's/^.* \([1-9][0-9]*\).*$/\1/'`
VER_R=0
VER_SHA=${VER_SHA:-not-in-git-tree}

# get version of remote origin/master and local HEAD
if [ "not-in-git-tree" != "$VER_SHA" ] && [ -d .git ] && command -v git >/dev/null 2>&1 ; then
    VER_R=`git rev-list --count origin/master`
    VER_SHA=`git rev-parse HEAD | cut -c -16`
fi

# generate version numbers
VER_MAJOR=`echo $(($api / 10))`
VER_MINOR=`echo $(($api % 10))`

# date and time information
BUILD_TIME=`date "+%Y-%m-%d %H:%M:%S"`

# generate the file version.h
echo "// ==========================================================================="  > version.h
echo "// version.h"                                                                   >> version.h
echo "// - collection of version numbers"                                             >> version.h
echo "//"                                                                             >> version.h
echo "// Author:  Falei LUO <falei.luo@gmail.com>"                                    >> version.h
echo "//"                                                                             >> version.h
echo "// ===========================================================================" >> version.h
echo ""                                                                               >> version.h
echo "#ifndef DAVS2_VERSION_H"                                                        >> version.h
echo "#define DAVS2_VERSION_H"                                                        >> version.h
echo ""                                                                               >> version.h
echo "// version number"                                                              >> version.h
echo "#define VER_MAJOR         $VER_MAJOR     // major version number"               >> version.h
echo "#define VER_MINOR         $VER_MINOR     // minor version number"               >> version.h
echo "#define VER_BUILD         $VER_R    // build number"                            >> version.h
echo "#define VER_SHA_STR       \"$VER_SHA\"  // commit id"                           >> version.h
echo ""                                                                               >> version.h
echo "// stringify"                                                                   >> version.h
echo "#define _TOSTR(x)       #x            // stringify x"                           >> version.h
echo "#define TOSTR(x)        _TOSTR(x)     // stringify x, perform macro expansion"  >> version.h
echo ""                                                                               >> version.h
echo "// define XVERSION string"                                                      >> version.h
echo "#define XVERSION        VER_MAJOR, VER_MINOR, VER_BUILD"                        >> version.h
echo "#define XVERSION_STR    TOSTR(VER_MAJOR) \".\" TOSTR(VER_MINOR) \".\" TOSTR(VER_BUILD) \" \" VER_SHA_STR" >> version.h
echo "#define XBUILD_TIME     \"$BUILD_TIME\""                                        >> version.h
echo ""                                                                               >> version.h
echo "#endif // DAVS2_VERSION_H"                                                      >> version.h

mv version.h source/version.h

# show version informations
echo "#define DAVS2_BUILD      $api"
echo "#define DAVS2_POINTVER \"$VER_MAJOR.$VER_MINOR.$VER_R\""