Add a `--clean' option for autoconf, autoheader, autoreconf and autom4te.
[autoconf/tsuna.git] / build-aux / git-version-gen
blob5f866258a158f83d3a5a6826dbe5d7738015eadc
1 #!/bin/sh
2 # Print a version string.
3 scriptversion=2007-11-03.22
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)
10 # 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, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 # 02110-1301, USA.
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 .version file, which
27 # presumes this script is invoked like "./git-version-gen .version".
29 case $# in
30 1) ;;
31 *) echo 1>&2 "Usage: $0 \$srcdir/.version"; exit 1;;
32 esac
34 tarball_version_file=$1
35 nl='
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
41 then
42 v=`cat $tarball_version_file` || exit 1
43 case $v in
44 *$nl*) v= ;; # reject multi-line output
45 [0-9]*) ;;
46 *) v= ;;
47 esac
48 test -z "$v" \
49 && echo "$0: WARNING: $tarball_version_file seems to be damaged" 1>&2
52 if test -n "$v"
53 then
54 : # use $v
55 elif test -d .git \
56 && v=`git describe --abbrev=4 HEAD 2>/dev/null` \
57 && case $v in
58 v[0-9]*) ;;
59 *) (exit 1) ;;
60 esac
61 then
62 # Change the first '-' to a '.', so version-comparing tools work properly.
63 # Remove the "g" in git-describe's output string, to save a byte.
64 v=`echo "$v" | sed 's/-/./;s/\(.*\)-g/\1-/'`;
65 else
66 v=UNKNOWN
69 v=`echo "$v" |sed 's/^v//'`
71 # Don't declare a version "dirty" merely because a time stamp has changed.
72 git-status > /dev/null 2>&1
74 dirty=`sh -c 'git diff-index --name-only HEAD' 2>/dev/null` || dirty=
75 case "$dirty" in
76 '') ;;
77 *) # Append the suffix only if there isn't one already.
78 case $v in
79 *-dirty) ;;
80 *) v="$v-dirty" ;;
81 esac ;;
82 esac
84 # Omit the trailing newline, so that m4_esyscmd can use the result directly.
85 echo "$v" | tr -d '\012'
87 # Local variables:
88 # eval: (add-hook 'write-file-hooks 'time-stamp)
89 # time-stamp-start: "scriptversion="
90 # time-stamp-format: "%:y-%02m-%02d.%02H"
91 # time-stamp-end: "$"
92 # End: