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