]>
Commit | Line | Data |
---|---|---|
9a1955a7 JF |
1 | #!/bin/sh |
2 | # Print a version string. | |
a09c6604 | 3 | scriptversion=2018-08-31.20; # UTC |
9a1955a7 | 4 | |
a09c6604 | 5 | # Copyright (C) 2018 Red Hat, Inc. |
9a1955a7 JF |
6 | # Copyright (C) 2007-2010 Free Software Foundation, Inc. |
7 | # | |
8 | # This program is free software: you can redistribute it and/or modify | |
9 | # it under the terms of the GNU General Public License as published by | |
10 | # the Free Software Foundation; either version 3 of the License, or | |
11 | # (at your option) any later version. | |
12 | # | |
13 | # This program is distributed in the hope that it will be useful, | |
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | # GNU General Public License for more details. | |
17 | # | |
18 | # You should have received a copy of the GNU General Public License | |
19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 | ||
21 | # This script is derived from GIT-VERSION-GEN from GIT: http://git.or.cz/. | |
22 | # It may be run two ways: | |
23 | # - from a git repository in which the "git describe" command below | |
24 | # produces useful output (thus requiring at least one signed tag) | |
25 | # - from a non-git-repo directory containing a .tarball-version file, which | |
26 | # presumes this script is invoked like "./git-version-gen .tarball-version". | |
27 | ||
28 | # In order to use intra-version strings in your project, you will need two | |
29 | # separate generated version string files: | |
30 | # | |
31 | # .tarball-version - present only in a distribution tarball, and not in | |
32 | # a checked-out repository. Created with contents that were learned at | |
33 | # the last time autoconf was run, and used by git-version-gen. Must not | |
34 | # be present in either $(srcdir) or $(builddir) for git-version-gen to | |
35 | # give accurate answers during normal development with a checked out tree, | |
36 | # but must be present in a tarball when there is no version control system. | |
37 | # Therefore, it cannot be used in any dependencies. GNUmakefile has | |
38 | # hooks to force a reconfigure at distribution time to get the value | |
39 | # correct, without penalizing normal development with extra reconfigures. | |
40 | # | |
41 | # .version - present in a checked-out repository and in a distribution | |
42 | # tarball. Usable in dependencies, particularly for files that don't | |
43 | # want to depend on config.h but do want to track version changes. | |
44 | # Delete this file prior to any autoconf run where you want to rebuild | |
45 | # files to pick up a version string change; and leave it stale to | |
46 | # minimize rebuild time after unrelated changes to configure sources. | |
47 | # | |
48 | # It is probably wise to add these two files to .gitignore, so that you | |
49 | # don't accidentally commit either generated file. | |
50 | # | |
a09c6604 JF |
51 | # In order to use git archive versions another two files has to be presented: |
52 | # | |
53 | # .gitarchive-version - present in checked-out repository and git | |
54 | # archive tarball, but not in the distribution tarball. Used as a last | |
55 | # option for version. File must contain special string $Format:%d$, | |
56 | # which is substitued by git on archive operation. | |
57 | # | |
58 | # .gitattributes - present in checked-out repository and git archive | |
59 | # tarball, but not in the distribution tarball. Must set export-subst | |
60 | # attribute for .gitarchive-version file. | |
61 | # | |
9a1955a7 JF |
62 | # Use the following line in your configure.ac, so that $(VERSION) will |
63 | # automatically be up-to-date each time configure is run (and note that | |
64 | # since configure.ac no longer includes a version string, Makefile rules | |
65 | # should not depend on configure.ac for version updates). | |
66 | # | |
67 | # AC_INIT([GNU project], | |
68 | # m4_esyscmd([build-aux/git-version-gen .tarball-version]), | |
69 | # [bug-project@example]) | |
70 | # | |
71 | # Then use the following lines in your Makefile.am, so that .version | |
72 | # will be present for dependencies, and so that .tarball-version will | |
73 | # exist in distribution tarballs. | |
74 | # | |
75 | # BUILT_SOURCES = $(top_srcdir)/.version | |
76 | # $(top_srcdir)/.version: | |
77 | # echo $(VERSION) > $@-t && mv $@-t $@ | |
78 | # dist-hook: | |
79 | # echo $(VERSION) > $(distdir)/.tarball-version | |
80 | ||
81 | case $# in | |
a09c6604 | 82 | 1|2|3) ;; |
9a1955a7 | 83 | *) echo 1>&2 "Usage: $0 \$srcdir/.tarball-version" \ |
a09c6604 | 84 | '[$srcdir/.gitarchive-version] [TAG-NORMALIZATION-SED-SCRIPT]' |
9a1955a7 JF |
85 | exit 1;; |
86 | esac | |
87 | ||
88 | tarball_version_file=$1 | |
a09c6604 JF |
89 | gitarchive_version_file=$2 |
90 | tag_sed_script="${3:-s/x/x/}" | |
9a1955a7 JF |
91 | nl=' |
92 | ' | |
93 | ||
94 | # Avoid meddling by environment variable of the same name. | |
95 | v= | |
96 | ||
97 | # First see if there is a tarball-only version file. | |
98 | # then try "git describe", then default. | |
99 | if test -f $tarball_version_file | |
100 | then | |
101 | v=`cat $tarball_version_file` || exit 1 | |
102 | case $v in | |
103 | *$nl*) v= ;; # reject multi-line output | |
104 | [0-9]*) ;; | |
105 | *) v= ;; | |
106 | esac | |
107 | test -z "$v" \ | |
108 | && echo "$0: WARNING: $tarball_version_file seems to be damaged" 1>&2 | |
109 | fi | |
110 | ||
111 | if test -n "$v" | |
112 | then | |
113 | : # use $v | |
114 | # Otherwise, if there is at least one git commit involving the working | |
115 | # directory, and "git describe" output looks sensible, use that to | |
116 | # derive a version string. | |
117 | elif test "`git log -1 --pretty=format:x . 2>&1`" = x \ | |
118 | && v=`git describe --abbrev=4 --match='v*' HEAD 2>/dev/null \ | |
119 | || git describe --abbrev=4 HEAD 2>/dev/null` \ | |
120 | && v=`printf '%s\n' "$v" | sed "$tag_sed_script"` \ | |
121 | && case $v in | |
122 | v[0-9]*) ;; | |
123 | *) (exit 1) ;; | |
124 | esac | |
125 | then | |
126 | # Is this a new git that lists number of commits since the last | |
127 | # tag or the previous older version that did not? | |
128 | # Newer: v6.10-77-g0f8faeb | |
129 | # Older: v6.10-g0f8faeb | |
130 | case $v in | |
131 | *-*-*) : git describe is okay three part flavor ;; | |
132 | *-*) | |
133 | : git describe is older two part flavor | |
134 | # Recreate the number of commits and rewrite such that the | |
135 | # result is the same as if we were using the newer version | |
136 | # of git describe. | |
137 | vtag=`echo "$v" | sed 's/-.*//'` | |
138 | numcommits=`git rev-list "$vtag"..HEAD | wc -l` | |
139 | v=`echo "$v" | sed "s/\(.*\)-\(.*\)/\1-$numcommits-\2/"`; | |
140 | ;; | |
141 | esac | |
142 | ||
143 | # Change the first '-' to a '.', so version-comparing tools work properly. | |
144 | # Remove the "g" in git describe's output string, to save a byte. | |
145 | v=`echo "$v" | sed 's/-/./;s/\(.*\)-g/\1-/'`; | |
146 | else | |
a09c6604 JF |
147 | if test -f $gitarchive_version_file |
148 | then | |
149 | v=`sed 's/^.*tag: \(v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' $gitarchive_version_file` || exit 1 | |
150 | case $v in | |
151 | *$nl*) v= ;; # reject multi-line output | |
152 | v[0-9]*) ;; | |
153 | *) v= ;; | |
154 | esac | |
155 | test -z "$v" \ | |
156 | && echo "$0: WARNING: $gitarchive_version_file doesn't contain valid version tag" 1>&2 \ | |
157 | && v=UNKNOWN | |
158 | else | |
159 | v=UNKNOWN | |
160 | fi | |
9a1955a7 JF |
161 | fi |
162 | ||
163 | v=`echo "$v" |sed 's/^v//'` | |
164 | ||
165 | # Don't declare a version "dirty" merely because a time stamp has changed. | |
166 | git update-index --refresh > /dev/null 2>&1 | |
167 | ||
168 | dirty=`sh -c 'git diff-index --name-only HEAD' 2>/dev/null` || dirty= | |
169 | case "$dirty" in | |
170 | '') ;; | |
171 | *) # Append the suffix only if there isn't one already. | |
172 | case $v in | |
173 | *-dirty) ;; | |
174 | *) v="$v-dirty" ;; | |
175 | esac ;; | |
176 | esac | |
177 | ||
178 | # Omit the trailing newline, so that m4_esyscmd can use the result directly. | |
179 | echo "$v" | tr -d "$nl" | |
180 | ||
181 | # Local variables: | |
182 | # eval: (add-hook 'write-file-hooks 'time-stamp) | |
183 | # time-stamp-start: "scriptversion=" | |
184 | # time-stamp-format: "%:y-%02m-%02d.%02H" | |
185 | # time-stamp-time-zone: "UTC" | |
186 | # time-stamp-end: "; # UTC" | |
187 | # End: |