]> 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 #     -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.2"
52 BRANCH="RELEASE-p8"
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 if [ -z "${SYSDIR}" ]; then
83     SYSDIR=$(dirname $0)/..
84 fi
85
86 RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' ${PARAMFILE:-${SYSDIR}/sys/param.h})
87
88 if [ -r "${SYSDIR}/../COPYRIGHT" ]; then
89         year=$(sed -Ee '/^Copyright .* The FreeBSD Project/!d;s/^.*1992-([0-9]*) .*$/\1/g' ${SYSDIR}/../COPYRIGHT)
90 else
91         year=$(date +%Y)
92 fi
93 # look for copyright template
94 b=share/examples/etc/bsd-style-copyright
95 for bsd_copyright in ../$b ../../$b ../../../$b /usr/src/$b /usr/$b
96 do
97         if [ -r "$bsd_copyright" ]; then
98                 COPYRIGHT=`sed \
99                     -e "s/\[year\]/1992-$year/" \
100                     -e 's/\[your name here\]\.* /The FreeBSD Project./' \
101                     -e 's/\[your name\]\.*/The FreeBSD Project./' \
102                     -e '/\[id for your version control system, if any\]/d' \
103                     $bsd_copyright` 
104                 break
105         fi
106 done
107
108 # no copyright found, use a dummy
109 if [ -z "$COPYRIGHT" ]; then
110         COPYRIGHT="/*-
111  * Copyright (c) 1992-$year The FreeBSD Project.
112  * All rights reserved.
113  *
114  */"
115 fi
116
117 # add newline
118 COPYRIGHT="$COPYRIGHT
119 "
120
121 # VARS_ONLY means no files should be generated, this is just being
122 # included.
123 [ -n "$VARS_ONLY" ] && return 0
124
125 LC_ALL=C; export LC_ALL
126 if [ ! -r version ]
127 then
128         echo 0 > version
129 fi
130
131 touch version
132 v=`cat version`
133 u=${USER:-root}
134 d=`pwd`
135 h=${HOSTNAME:-`hostname`}
136 if [ -n "$SOURCE_DATE_EPOCH" ]; then
137         if ! t=`date -r $SOURCE_DATE_EPOCH 2>/dev/null`; then
138                 echo "Invalid SOURCE_DATE_EPOCH" >&2
139                 exit 1
140         fi
141 else
142         t=`date`
143 fi
144 i=`${MAKE:-make} -V KERN_IDENT`
145 compiler_v=$($(${MAKE:-make} -V CC) -v 2>&1 | grep -w 'version')
146
147 for dir in /usr/bin /usr/local/bin; do
148         if [ ! -z "${svnversion}" ] ; then
149                 break
150         fi
151         if [ -x "${dir}/svnversion" ] && [ -z ${svnversion} ] ; then
152                 # Run svnversion from ${dir} on this script; if return code
153                 # is not zero, the checkout might not be compatible with the
154                 # svnversion being used.
155                 ${dir}/svnversion $(realpath ${0}) >/dev/null 2>&1
156                 if [ $? -eq 0 ]; then
157                         svnversion=${dir}/svnversion
158                         break
159                 fi
160         fi
161 done
162
163 if [ -z "${svnversion}" ] && [ -x /usr/bin/svnliteversion ] ; then
164         /usr/bin/svnliteversion $(realpath ${0}) >/dev/null 2>&1
165         if [ $? -eq 0 ]; then
166                 svnversion=/usr/bin/svnliteversion
167         else
168                 svnversion=
169         fi
170 fi
171
172 for dir in /usr/bin /usr/local/bin; do
173         if [ -x "${dir}/p4" ] && [ -z ${p4_cmd} ] ; then
174                 p4_cmd=${dir}/p4
175         fi
176 done
177
178 if findvcs .git; then
179         for dir in /usr/bin /usr/local/bin; do
180                 if [ -x "${dir}/git" ] ; then
181                         git_cmd="${dir}/git -c help.autocorrect=0 --git-dir=${VCSDIR}"
182                         break
183                 fi
184         done
185 fi
186
187 if findvcs .hg; then
188         for dir in /usr/bin /usr/local/bin; do
189                 if [ -x "${dir}/hg" ] ; then
190                         hg_cmd="${dir}/hg -R ${VCSDIR}"
191                         break
192                 fi
193         done
194 fi
195
196 if [ -n "$svnversion" ] ; then
197         svn=`cd ${SYSDIR} && $svnversion 2>/dev/null`
198         case "$svn" in
199         [0-9]*[MSP]|*:*)
200                 svn=" r${svn}"
201                 modified=true
202                 ;;
203         [0-9]*)
204                 svn=" r${svn}"
205                 ;;
206         *)
207                 unset svn
208                 ;;
209         esac
210 fi
211
212 if [ -n "$git_cmd" ] ; then
213         git=`$git_cmd rev-parse --verify --short HEAD 2>/dev/null`
214         svn=`$git_cmd svn find-rev $git 2>/dev/null`
215         if [ -n "$svn" ] ; then
216                 svn=" r${svn}"
217                 git="=${git}"
218         else
219                 svn=`$git_cmd log --grep '^git-svn-id:' | \
220                     grep '^    git-svn-id:' | head -1 | \
221                     sed -n 's/^.*@\([0-9][0-9]*\).*$/\1/p'`
222                 if [ -z "$svn" ] ; then
223                         svn=`$git_cmd log --format='format:%N' | \
224                              grep '^svn ' | head -1 | \
225                              sed -n 's/^.*revision=\([0-9][0-9]*\).*$/\1/p'`
226                 fi
227                 if [ -n "$svn" ] ; then
228                         svn=" r${svn}"
229                         git="+${git}"
230                 else
231                         git=" ${git}"
232                 fi
233         fi
234         git_b=`$git_cmd rev-parse --abbrev-ref HEAD`
235         if [ -n "$git_b" ] ; then
236                 git="${git}(${git_b})"
237         fi
238         if $git_cmd --work-tree=${VCSTOP} diff-index \
239             --name-only HEAD | read dummy; then
240                 git="${git}-dirty"
241                 modified=true
242         fi
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}${hg}${p4version} ${i}"
292         VERSTR="${VERINFO}\\n"
293 else
294         VERINFO="${VERSION} #${v}${svn}${git}${hg}${p4version}: ${t}"
295         VERSTR="${VERINFO}\\n    ${u}@${h}:${d}\\n"
296 fi
297
298 cat << EOF > vers.c
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 echo $((v + 1)) > version