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