Debian Codegraph @

tools/git-version-gen

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