]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/conf/newvers.sh
Update in preparation for 13.3-RELEASE
[FreeBSD/FreeBSD.git] / 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
34 # Command line options:
35 #
36 #       -c      Print the copyright / license statement as a C comment and exit
37 #
38 #       -r      Reproducible build.  Do not embed directory names, user names,
39 #               time stamps or other dynamic information into the output file.
40 #               This is intended to allow two builds done at different times
41 #               and even by different people on different hosts to produce
42 #               identical output.
43 #
44 #       -R      Reproducible build if the tree represents an unmodified
45 #               checkout from a version control system.  Metadata is included
46 #               if the tree is modified.
47 #
48 #       -V var  Print ${var}="${val-of-var}" and exit
49 #
50 #       -v      Print TYPE REVISION BRANCH RELEASE VERSION RELDATE variables
51 #               like the -V command
52 #
53
54 TYPE="FreeBSD"
55 REVISION="13.3"
56 BRANCH="RELEASE"
57 if [ -n "${BRANCH_OVERRIDE}" ]; then
58         BRANCH=${BRANCH_OVERRIDE}
59 fi
60 RELEASE="${REVISION}-${BRANCH}"
61 VERSION="${TYPE} ${RELEASE}"
62
63 if [ -z "${SYSDIR}" ]; then
64     SYSDIR=$(dirname $0)/..
65 fi
66
67 RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' ${PARAMFILE:-${SYSDIR}/sys/param.h})
68
69 if [ -r "${SYSDIR}/../COPYRIGHT" ]; then
70         year=$(sed -Ee '/^Copyright .* The FreeBSD Project/!d;s/^.*1992-([0-9]*) .*$/\1/g' ${SYSDIR}/../COPYRIGHT)
71 else
72         year=$(date +%Y)
73 fi
74 # look for copyright template
75 b=share/examples/etc/bsd-style-copyright
76 for bsd_copyright in $b ../$b ../../$b ../../../$b /usr/src/$b /usr/$b
77 do
78         if [ -r "$bsd_copyright" ]; then
79                 COPYRIGHT=$(sed \
80                     -e "s/\[year\]/1992-$year/" \
81                     -e 's/\[your name here\]\.* /The FreeBSD Project./' \
82                     -e 's/\[your name\]\.*/The FreeBSD Project./' \
83                     -e '/\[id for your version control system, if any\]/d' \
84                     $bsd_copyright)
85                 break
86         fi
87 done
88
89 # no copyright found, use a dummy
90 if [ -z "$COPYRIGHT" ]; then
91         COPYRIGHT="/*-
92  * Copyright (c) 1992-$year The FreeBSD Project.
93  *
94  */"
95 fi
96
97 # add newline
98 COPYRIGHT="$COPYRIGHT
99 "
100
101 # We expand include_metadata later since we may set it to the
102 # future value of modified.
103 include_metadata=yes
104 modified=no
105 while getopts crRvV: opt; do
106         case "$opt" in
107         c)
108                 echo "$COPYRIGHT"
109                 exit 0
110                 ;;
111         r)
112                 include_metadata=no
113                 ;;
114         R)
115                 include_metadata=if-modified
116                 ;;
117         v)
118                 # Only put variables that are single lines here.
119                 for v in TYPE REVISION BRANCH RELEASE VERSION RELDATE; do
120                         eval val=\$${v}
121                         echo ${v}=\"${val}\"
122                 done
123                 exit 0
124                 ;;
125         V)
126                 v=$OPTARG
127                 eval val=\$${v}
128                 echo ${v}=\"${val}\"
129                 VARS_ONLY_EXIT=1
130                 ;;
131         esac
132 done
133 shift $((OPTIND - 1))
134
135 # VARS_ONLY means no files should be generated, this is just being
136 # included.
137 [ -n "$VARS_ONLY" ] && return 0
138
139 # VARS_ONLY_EXIT means no files should be generated, only the value of
140 # variables are being output.
141 [ -n "$VARS_ONLY_EXIT" ] && exit 0
142
143 #
144 # findvcs dir
145 #       Looks up directory dir at world root and up the filesystem
146 #
147 findvcs()
148 {
149         local savedir
150
151         savedir=$(pwd)
152         cd ${SYSDIR}/..
153         while [ $(pwd) != "/" ]; do
154                 if [ -e "./$1" ]; then
155                         VCSTOP=$(pwd)
156                         VCSDIR=${VCSTOP}"/$1"
157                         cd ${savedir}
158                         return 0
159                 fi
160                 cd ..
161         done
162         cd ${savedir}
163         return 1
164 }
165
166 git_tree_modified()
167 {
168         ! $git_cmd "--work-tree=${VCSTOP}" -c core.checkStat=minimal -c core.fileMode=off diff --quiet
169 }
170
171 LC_ALL=C; export LC_ALL
172 if [ ! -r version ]
173 then
174         echo 0 > version
175 fi
176
177 touch version
178 v=$(cat version)
179 u=${USER:-root}
180 d=$(pwd)
181 h=${HOSTNAME:-$(hostname)}
182 if [ -n "$SOURCE_DATE_EPOCH" ]; then
183         if ! t=$(date -r $SOURCE_DATE_EPOCH 2>/dev/null); then
184                 echo "Invalid SOURCE_DATE_EPOCH" >&2
185                 exit 1
186         fi
187 else
188         t=$(date)
189 fi
190 i=$(${MAKE:-make} -V KERN_IDENT)
191 compiler_v=$($(${MAKE:-make} -V CC) -v 2>&1 | grep -w 'version')
192
193 for dir in /usr/bin /usr/local/bin; do
194         if [ ! -z "${svnversion}" ] ; then
195                 break
196         fi
197         if [ -x "${dir}/svnversion" ] && [ -z ${svnversion} ] ; then
198                 # Run svnversion from ${dir} on this script; if return code
199                 # is not zero, the checkout might not be compatible with the
200                 # svnversion being used.
201                 ${dir}/svnversion $(realpath ${0}) >/dev/null 2>&1
202                 if [ $? -eq 0 ]; then
203                         svnversion=${dir}/svnversion
204                         break
205                 fi
206         fi
207 done
208
209 if [ -z "${svnversion}" ] && [ -x /usr/bin/svnliteversion ] ; then
210         /usr/bin/svnliteversion $(realpath ${0}) >/dev/null 2>&1
211         if [ $? -eq 0 ]; then
212                 svnversion=/usr/bin/svnliteversion
213         else
214                 svnversion=
215         fi
216 fi
217
218 if findvcs .git; then
219         for dir in /usr/bin /usr/local/bin; do
220                 if [ -x "${dir}/git" ] ; then
221                         git_cmd="${dir}/git -c help.autocorrect=0 --git-dir=${VCSDIR}"
222                         break
223                 fi
224         done
225 fi
226
227 if findvcs .gituprevision; then
228         gituprevision="${VCSTOP}/.gituprevision"
229 fi
230
231 if findvcs .hg; then
232         for dir in /usr/bin /usr/local/bin; do
233                 if [ -x "${dir}/hg" ] ; then
234                         hg_cmd="${dir}/hg -R ${VCSDIR}"
235                         break
236                 fi
237         done
238 fi
239
240 if [ -n "$svnversion" ] ; then
241         svn=$(cd ${SYSDIR} && $svnversion 2>/dev/null)
242         case "$svn" in
243         [0-9]*[MSP]|*:*)
244                 svn=" r${svn}"
245                 modified=yes
246                 ;;
247         [0-9]*)
248                 svn=" r${svn}"
249                 ;;
250         *)
251                 unset svn
252                 ;;
253         esac
254 fi
255
256 if [ -n "$git_cmd" ] ; then
257         git=$($git_cmd rev-parse --verify --short HEAD 2>/dev/null)
258         if [ "$($git_cmd rev-parse --is-shallow-repository)" = false ] ; then
259                 git_cnt=$($git_cmd rev-list --first-parent --count HEAD 2>/dev/null)
260                 if [ -n "$git_cnt" ] ; then
261                         git="n${git_cnt}-${git}"
262                 fi
263         fi
264         git_b=$($git_cmd rev-parse --abbrev-ref HEAD)
265         if [ -n "$git_b" -a "$git_b" != "HEAD" ] ; then
266                 git="${git_b}-${git}"
267         fi
268         if git_tree_modified; then
269                 git="${git}-dirty"
270                 modified=yes
271         fi
272         git=" ${git}"
273 fi
274
275 if [ -n "$gituprevision" ] ; then
276         gitup=" $(awk -F: '{print $2}' $gituprevision)"
277 fi
278
279 if [ -n "$hg_cmd" ] ; then
280         hg=$($hg_cmd id 2>/dev/null)
281         hgsvn=$($hg_cmd svn info 2>/dev/null | \
282                 awk -F': ' '/Revision/ { print $2 }')
283         if [ -n "$hgsvn" ] ; then
284                 svn=" r${hgsvn}"
285         fi
286         if [ -n "$hg" ] ; then
287                 hg=" ${hg}"
288         fi
289 fi
290
291 [ ${include_metadata} = "if-modified" -a ${modified} = "yes" ] && include_metadata=yes
292 if [ ${include_metadata} != "yes" ]; then
293         VERINFO="${VERSION}${svn}${git}${gitup}${hg} ${i}"
294         VERSTR="${VERINFO}\\n"
295 else
296         VERINFO="${VERSION} #${v}${svn}${git}${gitup}${hg}: ${t}"
297         VERSTR="${VERINFO}\\n    ${u}@${h}:${d}\\n"
298 fi
299
300 vers_content_new=$(cat << EOF
301 $COPYRIGHT
302 #define SCCSSTR "@(#)${VERINFO}"
303 #define VERSTR "${VERSTR}"
304 #define RELSTR "${RELEASE}"
305
306 char sccs[sizeof(SCCSSTR) > 128 ? sizeof(SCCSSTR) : 128] = SCCSSTR;
307 char version[sizeof(VERSTR) > 256 ? sizeof(VERSTR) : 256] = VERSTR;
308 char compiler_version[] = "${compiler_v}";
309 char ostype[] = "${TYPE}";
310 char osrelease[sizeof(RELSTR) > 32 ? sizeof(RELSTR) : 32] = RELSTR;
311 int osreldate = ${RELDATE};
312 char kern_ident[] = "${i}";
313 EOF
314 )
315 vers_content_old=$(cat vers.c 2>/dev/null || true)
316 if [ "$vers_content_new" != "$vers_content_old" ]; then
317         printf "%s\n" "$vers_content_new" > vers.c
318 fi
319
320 echo $((v + 1)) > version