2 # Print a version string.
3 scriptversion=2008-03-02.16
5 # Copyright (C) 2007 Free Software Foundation
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 # This script is derived from GIT-VERSION-GEN from GIT: http://git.or.cz/.
23 # It may be run two ways:
24 # - from a git repository in which the "git describe" command below
25 # produces useful output (thus requiring at least one signed tag)
26 # - from a non-git-repo directory containing a .tarball-version file, which
27 # presumes this script is invoked like "./git-version-gen .tarball-version".
31 *) echo 1>&2 "Usage: $0 \$srcdir/.tarball-version"; exit 1;;
34 tarball_version_file=$1
38 # First see if there is a tarball-only version file.
39 # then try "git describe", then default.
40 if test -f $tarball_version_file
42 v=`cat $tarball_version_file` || exit 1
44 *$nl*) v= ;; # reject multi-line output
49 && echo "$0: WARNING: $tarball_version_file seems to be damaged" 1>&2
56 && v=`git describe --abbrev=4 HEAD 2>/dev/null` \
62 # Is this a new git that lists number of commits since the last
63 # tag or the previous older version that did not?
64 # Newer: v6.10-77-g0f8faeb
65 # Older: v6.10-g0f8faeb
67 *-*-*) : git describe is okay three part flavor ;;
69 : git describe is older two part flavor
70 # Recreate the number of commits and rewrite such that the
71 # result is the same as if we were using the newer version
73 vtag=`echo "$v" | sed 's/-.*//'`
74 numcommits=`git rev-list "$vtag"..HEAD | wc -l`
75 v=`echo "$v" | sed "s/\(.*\)-\(.*\)/\1-$numcommits-\2/"`;
79 # Change the first '-' to a '.', so version-comparing tools work properly.
80 # Remove the "g" in git describe's output string, to save a byte.
81 v=`echo "$v" | sed 's/-/./;s/\(.*\)-g/\1-/'`;
86 v=`echo "$v" |sed 's/^v//'`
88 # Don't declare a version "dirty" merely because a time stamp has changed.
89 git status > /dev/null 2>&1
91 dirty=`sh -c 'git diff-index --name-only HEAD' 2>/dev/null` || dirty=
94 *) # Append the suffix only if there isn't one already.
101 # Omit the trailing newline, so that m4_esyscmd can use the result directly.
102 echo "$v" | tr -d '\012'
105 # eval: (add-hook 'write-file-hooks 'time-stamp)
106 # time-stamp-start: "scriptversion="
107 # time-stamp-format: "%:y-%02m-%02d.%02H"
108 # time-stamp-end: "$"