forked from libhugetlbfs/libhugetlbfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
localversion
executable file
·90 lines (79 loc) · 2.47 KB
/
localversion
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
84
85
86
87
88
89
90
#!/bin/sh
#
# libhugetlbfs - Easy use of Linux hugepages
# Copyright (C) 2006 Andy Whitcroft, IBM Corporation
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
if [ "$#" -lt 1 ]; then
echo "Usage: localversion <version file> <source> ..." 1>&2
exit 1
fi
file="$1"
if [ -f "$file" ]; then
read current_version <"$file"
fi
version="$current_version"
modified=0
# GIT: check for a git tree.
mod=`git diff-index HEAD 2>/dev/null`
if [ "$?" -eq 0 ]; then
# This is a GIT repo, see if it was modified.
if [ "$mod" != "" ]; then
modified=1
else
# Subtle, if we are in a git archive and the repository
# is clean then update the time on the version file
# thus ensuring it will be correct in any tarball.
touch "$file"
fi
# Try and get a real "tag relative" version name for it.
version=`git describe --tags HEAD 2>&1`
if [ "$?" -ne 0 ]; then
# ok, desperation just take the commit id.
version=`git log | awk '{ print $2; exit }'`
version="commit<$version>"
fi
else
if [ ! -f "$file" ]; then
echo 1>&2 "$0: ERROR: unversioned tarball"
echo "#error UNVERSIONED tarball" >"$file.h"
exit 1
fi
# No version control, use the modification times
# of the source.
for s in "$@"
do
if [ "$s" -nt "$file" ]; then
modified=1
fi
done
fi
if [ "$current_version" != "$version" ]; then
echo "version update: $version"
echo "$version" >"$file"
fi
# Update the c-define for this version, take the modification
# flags into account.
version_modified="$version"
[ "$modified" -eq 1 ] && version_modified="$version_modified (modified)"
if [ -f "$file.h" ]; then
read d1 current_version_modified <"$file.h"
fi
if [ "$current_version_modified" != "$version_modified" ]; then
echo "version string: $version_modified"
echo "// $version_modified" >"$file.h"
echo "#define VERSION \"$version_modified\"" >>"$file.h"
fi
exit 0