2 # Print a version string.
3 scriptversion
=2010-01-28.01
5 # Copyright (C) 2007-2010 Free Software Foundation, Inc.
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 of the License, or
10 # (at your option) any later version.
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, see <http://www.gnu.org/licenses/>.
20 # This script is derived from GIT-VERSION-GEN from GIT: http://git.or.cz/.
21 # It may be run two ways:
22 # - from a git repository in which the "git describe" command below
23 # produces useful output (thus requiring at least one signed tag)
24 # - from a non-git-repo directory containing a .tarball-version file, which
25 # presumes this script is invoked like "./git-version-gen .tarball-version".
27 # In order to use intra-version strings in your project, you will need two
28 # separate generated version string files:
30 # .tarball-version - present only in a distribution tarball, and not in
31 # a checked-out repository. Created with contents that were learned at
32 # the last time autoconf was run, and used by git-version-gen. Must not
33 # be present in either $(srcdir) or $(builddir) for git-version-gen to
34 # give accurate answers during normal development with a checked out tree,
35 # but must be present in a tarball when there is no version control system.
36 # Therefore, it cannot be used in any dependencies. GNUmakefile has
37 # hooks to force a reconfigure at distribution time to get the value
38 # correct, without penalizing normal development with extra reconfigures.
40 # .version - present in a checked-out repository and in a distribution
41 # tarball. Usable in dependencies, particularly for files that don't
42 # want to depend on config.h but do want to track version changes.
43 # Delete this file prior to any autoconf run where you want to rebuild
44 # files to pick up a version string change; and leave it stale to
45 # minimize rebuild time after unrelated changes to configure sources.
47 # It is probably wise to add these two files to .gitignore, so that you
48 # don't accidentally commit either generated file.
50 # Use the following line in your configure.ac, so that $(VERSION) will
51 # automatically be up-to-date each time configure is run (and note that
52 # since configure.ac no longer includes a version string, Makefile rules
53 # should not depend on configure.ac for version updates).
55 # AC_INIT([GNU project],
56 # m4_esyscmd([build-aux/git-version-gen .tarball-version]),
57 # [bug-project@example])
59 # Then use the following lines in your Makefile.am, so that .version
60 # will be present for dependencies, and so that .tarball-version will
61 # exist in distribution tarballs.
63 # BUILT_SOURCES = $(top_srcdir)/.version
64 # $(top_srcdir)/.version:
65 # echo $(VERSION) > $@-t && mv $@-t $@
67 # echo $(VERSION) > $(distdir)/.tarball-version
71 *) echo 1>&2 "Usage: $0 \$srcdir/.tarball-version"; exit 1;;
74 tarball_version_file
=$1
78 # First see if there is a tarball-only version file.
79 # then try "git describe", then default.
80 if test -f $tarball_version_file
82 v
=`cat $tarball_version_file` ||
exit 1
84 *$nl*) v
= ;; # reject multi-line output
89 && echo "$0: WARNING: $tarball_version_file seems to be damaged" 1>&2
96 && v
=`git describe --abbrev=4 --match='v*' HEAD 2>/dev/null \
97 || git describe --abbrev=4 HEAD 2>/dev/null` \
103 # Is this a new git that lists number of commits since the last
104 # tag or the previous older version that did not?
105 # Newer: v6.10-77-g0f8faeb
106 # Older: v6.10-g0f8faeb
108 *-*-*) : git describe is okay three part flavor
;;
110 : git describe is older two part flavor
111 # Recreate the number of commits and rewrite such that the
112 # result is the same as if we were using the newer version
114 vtag
=`echo "$v" | sed 's/-.*//'`
115 numcommits
=`git rev-list "$vtag"..HEAD | wc -l`
116 v
=`echo "$v" | sed "s/\(.*\)-\(.*\)/\1-$numcommits-\2/"`;
120 # Change the first '-' to a '.', so version-comparing tools work properly.
121 # Remove the "g" in git describe's output string, to save a byte.
122 v
=`echo "$v" | sed 's/-/./;s/\(.*\)-g/\1-/'`;
127 v
=`echo "$v" |sed 's/^v//'`
129 # Don't declare a version "dirty" merely because a time stamp has changed.
130 git status
> /dev
/null
2>&1
132 dirty
=`sh -c 'git diff-index --name-only HEAD' 2>/dev/null` || dirty
=
135 *) # Append the suffix only if there isn't one already.
142 # Omit the trailing newline, so that m4_esyscmd can use the result directly.
143 echo "$v" |
tr -d '\012'
146 # eval: (add-hook 'write-file-hooks 'time-stamp)
147 # time-stamp-start: "scriptversion="
148 # time-stamp-format: "%:y-%02m-%02d.%02H"
149 # time-stamp-end: "$"