]>
Commit | Line | Data |
---|---|---|
0c80959c AF |
1 | #!/bin/sh |
2 | # Print a version string. | |
3 | scriptversion=2009-05-11.16 | |
4 | ||
5 | # Copyright (C) 2007-2008 Free Software Foundation | |
6 | # | |
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. | |
11 | # | |
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. | |
16 | # | |
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. | |
21 | ||
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". | |
28 | ||
29 | # In order to use intra-version strings in your project, you will need two | |
30 | # separate generated version string files: | |
31 | # | |
32 | # .tarball-version - present only in a distribution tarball, and not in | |
33 | # a checked-out repository. Created with contents that were learned at | |
34 | # the last time autoconf was run, and used by git-version-gen. Must not | |
35 | # be present in either $(srcdir) or $(builddir) for git-version-gen to | |
36 | # give accurate answers during normal development with a checked out tree, | |
37 | # but must be present in a tarball when there is no version control system. | |
38 | # Therefore, it cannot be used in any dependencies. GNUmakefile has | |
39 | # hooks to force a reconfigure at distribution time to get the value | |
40 | # correct, without penalizing normal development with extra reconfigures. | |
41 | # | |
42 | # .version - present in a checked-out repository and in a distribution | |
43 | # tarball. Usable in dependencies, particularly for files that don't | |
44 | # want to depend on config.h but do want to track version changes. | |
45 | # Delete this file prior to any autoconf run where you want to rebuild | |
46 | # files to pick up a version string change; and leave it stale to | |
47 | # minimize rebuild time after unrelated changes to configure sources. | |
48 | # | |
49 | # It is probably wise to add these two files to .gitignore, so that you | |
50 | # don't accidentally commit either generated file. | |
51 | # | |
52 | # Use the following line in your configure.ac, so that $(VERSION) will | |
53 | # automatically be up-to-date each time configure is run (and note that | |
54 | # since configure.ac no longer includes a version string, Makefile rules | |
55 | # should not depend on configure.ac for version updates). | |
56 | # | |
57 | # AC_INIT([GNU project], | |
58 | # m4_esyscmd([build-aux/git-version-gen .tarball-version]), | |
59 | # [bug-project@example]) | |
60 | # | |
61 | # Then use the following lines in your Makefile.am, so that .version | |
62 | # will be present for dependencies, and so that .tarball-version will | |
63 | # exist in distribution tarballs. | |
64 | # | |
65 | # BUILT_SOURCES = $(top_srcdir)/.version | |
66 | # $(top_srcdir)/.version: | |
67 | # echo $(VERSION) > $@-t && mv $@-t $@ | |
68 | # dist-hook: | |
69 | # echo $(VERSION) > $(distdir)/.tarball-version | |
70 | ||
71 | case $# in | |
72 | 1) ;; | |
73 | *) echo 1>&2 "Usage: $0 \$srcdir/.tarball-version"; exit 1;; | |
74 | esac | |
75 | ||
76 | tarball_version_file=$1 | |
77 | nl=' | |
78 | ' | |
79 | ||
80 | # First see if there is a tarball-only version file. | |
81 | # then try "git describe", then default. | |
82 | if test -f $tarball_version_file | |
83 | then | |
84 | v=`cat $tarball_version_file` || exit 1 | |
85 | case $v in | |
86 | *$nl*) v= ;; # reject multi-line output | |
87 | [0-9]*) ;; | |
88 | *) v= ;; | |
89 | esac | |
90 | test -z "$v" \ | |
91 | && echo "$0: WARNING: $tarball_version_file seems to be damaged" 1>&2 | |
92 | fi | |
93 | ||
94 | if test -n "$v" | |
95 | then | |
96 | : # use $v | |
97 | elif test -d .git \ | |
98 | && v=`git describe --abbrev=4 --match='${GNOME_TAG_PATTERN}_*' HEAD 2>/dev/null \ | |
99 | || git describe --abbrev=4 HEAD 2>/dev/null` \ | |
100 | && case $v in | |
101 | ${GNOME_TAG_PATTERN}_[0-9]*) ;; | |
102 | *) (exit 1) ;; | |
103 | esac | |
104 | then | |
105 | # Is this a new git that lists number of commits since the last | |
106 | # tag or the previous older version that did not? | |
107 | # Newer: v6.10-77-g0f8faeb | |
108 | # Older: v6.10-g0f8faeb | |
109 | case $v in | |
110 | *-*-*) : git describe is okay three part flavor ;; | |
111 | *-*) | |
112 | : git describe is older two part flavor | |
113 | # Recreate the number of commits and rewrite such that the | |
114 | # result is the same as if we were using the newer version | |
115 | # of git describe. | |
116 | vtag=`echo "$v" | sed 's/-.*//'` | |
117 | numcommits=`git rev-list "$vtag"..HEAD | wc -l` | |
118 | v=`echo "$v" | sed "s/\(.*\)-\(.*\)/\1-$numcommits-\2/"`; | |
119 | ;; | |
120 | esac | |
121 | ||
122 | # Change the first '-' to a '.', so version-comparing tools work properly. | |
123 | # Remove the "g" in git describe's output string, to save a byte. | |
124 | v=`echo "$v" | sed 's/-/./;s/\(.*\)-g/\1-/'`; | |
125 | else | |
126 | v=UNKNOWN | |
127 | fi | |
128 | ||
129 | #v=`echo "$v" |sed 's/^v//'` | |
130 | ||
131 | v=`echo "$v" | sed "s/${GNOME_TAG_PATTERN}_//" | tr _ .` | |
132 | ||
133 | # Don't declare a version "dirty" merely because a time stamp has changed. | |
134 | git status > /dev/null 2>&1 | |
135 | ||
136 | dirty=`sh -c 'git diff-index --name-only HEAD' 2>/dev/null` || dirty= | |
137 | case "$dirty" in | |
138 | '') ;; | |
139 | *) # Append the suffix only if there isn't one already. | |
140 | case $v in | |
141 | *-dirty) ;; | |
142 | *) v="$v-dirty" ;; | |
143 | esac ;; | |
144 | esac | |
145 | ||
146 | # Omit the trailing newline, so that m4_esyscmd can use the result directly. | |
147 | echo "$v" | tr -d '\012' | |
148 | ||
149 | # Local variables: | |
150 | # eval: (add-hook 'write-file-hooks 'time-stamp) | |
151 | # time-stamp-start: "scriptversion=" | |
152 | # time-stamp-format: "%:y-%02m-%02d.%02H" | |
153 | # time-stamp-end: "$" | |
154 | # End: |