summaryrefslogtreecommitdiff
path: root/buildutil/version-util
blob: f35d7f7fcabb2b13e00f41e25a8982242d076078 (plain)
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
#!/bin/sh
# -----------------------------------------------------------------------------
# Small shell script to determine the last commit version of the project
# It checks for CVS and .git repositories.
# The output is a string that can be used in a define at compile time to
# automatically mark repository versions.
# For CVS repositories the string contains the date and time of the commit
# that lead to the current version of files.
# For git repositories the output contains the git-id of the current tree.
# An indication if localy modified files exist is added.
# -----------------------------------------------------------------------------

[ $# -lt 1 ] && echo "USAGE: version-util <versionfile>" && exit 1

VERS_FILE=$1

function createVers ()
{
cat <<EOF
/* ATTENTION: this file is automatically generated and will be overwritten!
 * Manual changes will get lost!
 */
#ifndef GEN_VERSION_SUFFIX_H
#define GEN_VERSION_SUFFIX_H
#define VERSION_SUFFIX "$1"
#endif
EOF
}

function cvsVers ()
{
    d=`cvs log -r -N 2> /dev/null \
	| grep '^date:' \
	| cut -d ' ' -f 2-4 \
	| sort -u \
	| tail -1 \
	| tr -d ' \-:'`
    m=`cvs status 2> /dev/null \
	| grep 'Status: Locally Modified' > /dev/null && echo "_MOD"`
    echo "_cvs_${d}${m}"
}

function gitVers ()
{
    b=`git branch \
	| grep '^*' \
	| sed -e's/^* //'`
    h=`git show --pretty=format:"%h_%ci" HEAD \
	| head -1 \
	| tr -d ' \-:'`
    echo "_git_${b}_${h}"
}

function checkVers ()
{
    s=`$1`
    if [ ! -e ${VERS_FILE} ]; then
	echo "$VERS_FILE does not exist! creating a new one."
	createVers $s > ${VERS_FILE}
    else
	v=`grep '^#define VERSION_SUFFIX' ${VERS_FILE} \
	    | awk '{print $3}'`
	echo "s: $s"
	echo "v: $v"
	if [ "$v" != "\"$s\"" ]; then
	    echo "$VERS_FILE is being recreated!"
	    createVers $s > ${VERS_FILE}
	fi
    fi
}

if [ -d CVS ]; then
    checkVers cvsVers
fi

if [ -d .git ]; then
    checkVers gitVers
fi