-
Notifications
You must be signed in to change notification settings - Fork 3
/
setversion.sh
executable file
·74 lines (60 loc) · 2.1 KB
/
setversion.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
#! /bin/sh
# Copyright (c) 2007 - 2009 Ralph Glasstetter, Michael Riepe
# This program is free software; see COPYING for details.
#
# Create a header file containing a version string, max. revision number and
# some timestamps of the project by scanning for the SVN "Id" keyword lines
# of the files supplied as arguments.
#
# The script should be called during the build procedure by make, scons...
# therefore the output header file contains an artificial "Id" line from
# previous calls and is scanned additionally in case of incremental calls
# with just a few changed (or no) files as arguments.
#@(#) $Id$
# location of this script (specify the input/output filenames below rel. to this!)
DIR=`dirname "$0"`
# Optional text file containing the version string of the last official release
VERSION_FILE="$DIR/VERSION"
# That's the output header file (which is also read if present!)
HEADER_FILE="$DIR/src/version.h"
# Default version string
VERSION=0.0.0
# Get VERSION from text file
[ -f "$VERSION_FILE" ] && read VERSION < "$VERSION_FILE"
# Append appropriate suffix
if [ -d $DIR/.svn ]
then VERSION="$VERSION-svn"
else VERSION="$VERSION-release"
fi
# maybe we want to know when the project was built?
BUILT=`TZ=UTC date '+%Y-%m-%d %H:%M:%SZ'`
# extract&analyse the Id keyword lines from the given source files
getids() {
sed -ne 's,^[^ ]\+ \+\$Id: \(.*\) \$.*,\1,p' "$@" < /dev/null
[ -f "$HEADER_FILE" ] && \
sed -ne 's,^#define LASTID \(.*\)$,\1,p' "$HEADER_FILE"
}
set -- $(getids "$@" | sort -k 2n,2 -k 3,4 -k 1,1 | tail -1)
NAME=$1
REVISION=$2
DATE=$3
TIME=$4
AUTHOR=$5
CHANGED="$3 $4"
cat <<EOF >$HEADER_FILE
/* This file was automatically generated by $0.
* DO NOT EDIT!
* Last changed source file (read on input) was:
*/
#define LASTID $NAME $REVISION $DATE $TIME $AUTHOR
#ifndef _VERSION_H
#define _VERSION_H
#define VERSION "$VERSION"
#define REVISION "$REVISION"
#define CHANGED "$CHANGED"
#define BUILT "$BUILT"
#endif /* _VERSION_H */
EOF
echo >&2 "Last change made on $DATE at $TIME in file '$NAME' by '$AUTHOR'"
echo >&2 "Prepared header file '$HEADER_FILE' for version/revision: $VERSION/$REVISION"
exit