FreeBSD/Linux Kernel Cross Reference
sys/conf/newvers.sh
1 #!/bin/sh -
2 #
3 # Copyright (c) 1984, 1986, 1990, 1993
4 # The Regents of the University of California. All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # 3. Neither the name of the University nor the names of its contributors
15 # may be used to endorse or promote products derived from this software
16 # without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 # SUCH DAMAGE.
29 #
30 # @(#)newvers.sh 8.1 (Berkeley) 4/20/94
31 # $FreeBSD: releng/11.1/sys/conf/newvers.sh 338978 2018-09-27 18:29:55Z gordon $
32
33 # Command line options:
34 #
35 # -r Reproducible build. Do not embed directory names, user
36 # names, time stamps or other dynamic information into
37 # the output file. This is intended to allow two builds
38 # done at different times and even by different people on
39 # different hosts to produce identical output.
40 #
41 # -R Reproducible build if the tree represents an unmodified
42 # checkout from a version control system. Metadata is
43 # included if the tree is modified.
44
45 TYPE="FreeBSD"
46 REVISION="11.1"
47 BRANCH="RELEASE-p15"
48 if [ -n "${BRANCH_OVERRIDE}" ]; then
49 BRANCH=${BRANCH_OVERRIDE}
50 fi
51 RELEASE="${REVISION}-${BRANCH}"
52 VERSION="${TYPE} ${RELEASE}"
53
54 if [ -z "${SYSDIR}" ]; then
55 SYSDIR=$(dirname $0)/..
56 fi
57
58 if [ -n "${PARAMFILE}" ]; then
59 RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \
60 ${PARAMFILE})
61 else
62 RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \
63 ${SYSDIR}/sys/param.h)
64 fi
65
66 b=share/examples/etc/bsd-style-copyright
67 if [ -r "${SYSDIR}/../COPYRIGHT" ]; then
68 year=$(sed -Ee '/^Copyright .* The FreeBSD Project/!d;s/^.*1992-([0-9]*) .*$/\1/g' ${SYSDIR}/../COPYRIGHT)
69 else
70 year=$(date +%Y)
71 fi
72 # look for copyright template
73 for bsd_copyright in ../$b ../../$b ../../../$b /usr/src/$b /usr/$b
74 do
75 if [ -r "$bsd_copyright" ]; then
76 COPYRIGHT=`sed \
77 -e "s/\[year\]/1992-$year/" \
78 -e 's/\[your name here\]\.* /The FreeBSD Project./' \
79 -e 's/\[your name\]\.*/The FreeBSD Project./' \
80 -e '/\[id for your version control system, if any\]/d' \
81 $bsd_copyright`
82 break
83 fi
84 done
85
86 # no copyright found, use a dummy
87 if [ -z "$COPYRIGHT" ]; then
88 COPYRIGHT="/*-
89 * Copyright (c) 1992-$year The FreeBSD Project.
90 * All rights reserved.
91 *
92 */"
93 fi
94
95 # add newline
96 COPYRIGHT="$COPYRIGHT
97 "
98
99 # VARS_ONLY means no files should be generated, this is just being
100 # included.
101 if [ -n "$VARS_ONLY" ]; then
102 return 0
103 fi
104
105 LC_ALL=C; export LC_ALL
106 if [ ! -r version ]
107 then
108 echo 0 > version
109 fi
110
111 touch version
112 v=`cat version`
113 u=${USER:-root}
114 d=`pwd`
115 h=${HOSTNAME:-`hostname`}
116 if [ -n "$SOURCE_DATE_EPOCH" ]; then
117 if ! t=`date -r $SOURCE_DATE_EPOCH 2>/dev/null`; then
118 echo "Invalid SOURCE_DATE_EPOCH" >&2
119 exit 1
120 fi
121 else
122 t=`date`
123 fi
124 i=`${MAKE:-make} -V KERN_IDENT`
125 compiler_v=$($(${MAKE:-make} -V CC) -v 2>&1 | grep -w 'version')
126
127 for dir in /usr/bin /usr/local/bin; do
128 if [ ! -z "${svnversion}" ] ; then
129 break
130 fi
131 if [ -x "${dir}/svnversion" ] && [ -z ${svnversion} ] ; then
132 # Run svnversion from ${dir} on this script; if return code
133 # is not zero, the checkout might not be compatible with the
134 # svnversion being used.
135 ${dir}/svnversion $(realpath ${0}) >/dev/null 2>&1
136 if [ $? -eq 0 ]; then
137 svnversion=${dir}/svnversion
138 break
139 fi
140 fi
141 done
142
143 if [ -z "${svnversion}" ] && [ -x /usr/bin/svnliteversion ] ; then
144 /usr/bin/svnliteversion $(realpath ${0}) >/dev/null 2>&1
145 if [ $? -eq 0 ]; then
146 svnversion=/usr/bin/svnliteversion
147 else
148 svnversion=
149 fi
150 fi
151
152 for dir in /usr/bin /usr/local/bin; do
153 if [ -x "${dir}/p4" ] && [ -z ${p4_cmd} ] ; then
154 p4_cmd=${dir}/p4
155 fi
156 done
157 if [ -d "${SYSDIR}/../.git" ] ; then
158 for dir in /usr/bin /usr/local/bin; do
159 if [ -x "${dir}/git" ] ; then
160 git_cmd="${dir}/git --git-dir=${SYSDIR}/../.git"
161 break
162 fi
163 done
164 fi
165
166 if [ -d "${SYSDIR}/../.hg" ] ; then
167 for dir in /usr/bin /usr/local/bin; do
168 if [ -x "${dir}/hg" ] ; then
169 hg_cmd="${dir}/hg -R ${SYSDIR}/.."
170 break
171 fi
172 done
173 fi
174
175 if [ -n "$svnversion" ] ; then
176 svn=`cd ${SYSDIR} && $svnversion 2>/dev/null`
177 case "$svn" in
178 [0-9]*[MSP]|*:*)
179 svn=" r${svn}"
180 modified=true
181 ;;
182 [0-9]*)
183 svn=" r${svn}"
184 ;;
185 *)
186 unset svn
187 ;;
188 esac
189 fi
190
191 if [ -n "$git_cmd" ] ; then
192 git=`$git_cmd rev-parse --verify --short HEAD 2>/dev/null`
193 svn=`$git_cmd svn find-rev $git 2>/dev/null`
194 if [ -n "$svn" ] ; then
195 svn=" r${svn}"
196 git="=${git}"
197 else
198 svn=`$git_cmd log | fgrep 'git-svn-id:' | head -1 | \
199 sed -n 's/^.*@\([0-9][0-9]*\).*$/\1/p'`
200 if [ -z "$svn" ] ; then
201 svn=`$git_cmd log --format='format:%N' | \
202 grep '^svn ' | head -1 | \
203 sed -n 's/^.*revision=\([0-9][0-9]*\).*$/\1/p'`
204 fi
205 if [ -n "$svn" ] ; then
206 svn=" r${svn}"
207 git="+${git}"
208 else
209 git=" ${git}"
210 fi
211 fi
212 git_b=`$git_cmd rev-parse --abbrev-ref HEAD`
213 if [ -n "$git_b" ] ; then
214 git="${git}(${git_b})"
215 fi
216 if $git_cmd --work-tree=${SYSDIR}/.. diff-index \
217 --name-only HEAD | read dummy; then
218 git="${git}-dirty"
219 modified=true
220 fi
221 fi
222
223 if [ -n "$p4_cmd" ] ; then
224 p4version=`cd ${SYSDIR} && $p4_cmd changes -m1 "./...#have" 2>&1 | \
225 awk '{ print $2 }'`
226 case "$p4version" in
227 [0-9]*)
228 p4version=" ${p4version}"
229 p4opened=`cd ${SYSDIR} && $p4_cmd opened ./... 2>&1`
230 case "$p4opened" in
231 File*) ;;
232 //*)
233 p4version="${p4version}+edit"
234 modified=true
235 ;;
236 esac
237 ;;
238 *) unset p4version ;;
239 esac
240 fi
241
242 if [ -n "$hg_cmd" ] ; then
243 hg=`$hg_cmd id 2>/dev/null`
244 svn=`$hg_cmd svn info 2>/dev/null | \
245 awk -F': ' '/Revision/ { print $2 }'`
246 if [ -n "$svn" ] ; then
247 svn=" r${svn}"
248 fi
249 if [ -n "$hg" ] ; then
250 hg=" ${hg}"
251 fi
252 fi
253
254 include_metadata=true
255 while getopts rR opt; do
256 case "$opt" in
257 r)
258 include_metadata=
259 ;;
260 R)
261 if [ -z "${modified}" ]; then
262 include_metadata=
263 fi
264 esac
265 done
266 shift $((OPTIND - 1))
267
268 if [ -z "${include_metadata}" ]; then
269 VERINFO="${VERSION} ${svn}${git}${hg}${p4version}"
270 VERSTR="${VERINFO}\\n"
271 else
272 VERINFO="${VERSION} #${v}${svn}${git}${hg}${p4version}: ${t}"
273 VERSTR="${VERINFO}\\n ${u}@${h}:${d}\\n"
274 fi
275
276 cat << EOF > vers.c
277 $COPYRIGHT
278 #define SCCSSTR "@(#)${VERINFO}"
279 #define VERSTR "${VERSTR}"
280 #define RELSTR "${RELEASE}"
281
282 char sccs[sizeof(SCCSSTR) > 128 ? sizeof(SCCSSTR) : 128] = SCCSSTR;
283 char version[sizeof(VERSTR) > 256 ? sizeof(VERSTR) : 256] = VERSTR;
284 char compiler_version[] = "${compiler_v}";
285 char ostype[] = "${TYPE}";
286 char osrelease[sizeof(RELSTR) > 32 ? sizeof(RELSTR) : 32] = RELSTR;
287 int osreldate = ${RELDATE};
288 char kern_ident[] = "${i}";
289 EOF
290
291 echo $((v + 1)) > version
Cache object: 1a304c73ff15791c9fc8f693729e677b
|