Fix: [NewGRF] Make VA2 operator 11 (ror) behave well-defined when rotating by 0 bits.
[openttd-github.git] / findversion.sh
blob8fd292c8bc727fecab4a3e8983d7e98f1b228b6c
1 #!/bin/sh
3 # $Id$
5 # This file is part of OpenTTD.
6 # OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
7 # OpenTTD 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.
8 # See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
11 # Arguments given? Show help text.
12 if [ "$#" != "0" ]; then
13 cat <<EOF
14 Usage: ./findversion.sh
15 Finds the current revision and if the code is modified.
17 Output: <VERSION>\t<ISODATE>\t<MODIFIED>\t<HASH>
18 VERSION
19 a string describing what version of the code the current checkout is
20 based on.
21 This also includes the commit date, an indication of whether the checkout
22 was modified and which branch was checked out. This value is not
23 guaranteed to be sortable, but is mainly meant for identifying the
24 revision and user display.
26 If no revision identifier could be found, this is left empty.
27 ISODATE
28 the commit date of the revision this checkout is based on.
29 The commit date may differ from the author date.
30 This can be used to decide upon the age of the source.
32 If no timestamp could be found, this is left empty.
33 MODIFIED
34 Whether (the src directory of) this checkout is modified or not. A
35 value of 0 means not modified, a value of 2 means it was modified.
37 A value of 1 means that the modified status is unknown, because this
38 is not an git checkout for example.
40 HASH
41 the git revision hash
43 By setting the AWK environment variable, a caller can determine which
44 version of "awk" is used. If nothing is set, this script defaults to
45 "awk".
46 EOF
47 exit 1;
50 # Allow awk to be provided by the caller.
51 if [ -z "$AWK" ]; then
52 AWK=awk
55 # Find out some dirs
56 cd `dirname "$0"`
57 ROOT_DIR=`pwd`
59 # Determine if we are using a modified version
60 # Assume the dir is not modified
61 MODIFIED="0"
62 if [ -d "$ROOT_DIR/.git" ]; then
63 # We are a git checkout
64 # Refresh the index to make sure file stat info is in sync, then look for modifications
65 git update-index --refresh >/dev/null
66 if [ -n "`git diff-index HEAD`" ]; then
67 MODIFIED="2"
69 HASH=`LC_ALL=C git rev-parse --verify HEAD 2>/dev/null`
70 SHORTHASH=`echo ${HASH} | cut -c1-8`
71 ISODATE=`LC_ALL=C git show -s --pretty='format:%ci' HEAD | "$AWK" '{ gsub("-", "", $1); print $1 }'`
72 BRANCH="`git symbolic-ref -q HEAD 2>/dev/null | sed 's@.*/@@'`"
73 TAG="`git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null | sed 's@\^0$@@'`"
75 if [ -n "$TAG" ]; then
76 VERSION="${TAG}"
77 elif [ "${BRANCH}" = "master" ]; then
78 VERSION="${ISODATE}-g${SHORTHASH}"
79 else
80 VERSION="${ISODATE}-${BRANCH}-g${SHORTHASH}"
83 if [ "$MODIFIED" -eq "2" ]; then
84 VERSION="${VERSION}M"
86 elif [ -f "$ROOT_DIR/.ottdrev" ]; then
87 # We are an exported source bundle
88 cat $ROOT_DIR/.ottdrev
89 exit
90 else
91 # We don't know
92 MODIFIED="1"
93 HASH=""
94 SHORTHASH=""
95 BRANCH=""
96 ISODATE=""
97 TAG=""
98 VERSION=""
101 echo "$VERSION $ISODATE $MODIFIED $HASH"