]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/conf/newvers.sh
12.3: update to RC1
[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.3"
52 BRANCH="RC1"
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         git_cnt=$($git_cmd rev-list --first-parent --count HEAD 2>/dev/null)
215         if [ -n "$git_cnt" ] ; then
216                 git="n${git_cnt}-${git}"
217         fi
218         git_b=$($git_cmd rev-parse --abbrev-ref HEAD)
219         if [ -n "$git_b" -a "$git_b" != "HEAD" ] ; then
220                 git="${git_b}-${git}"
221         fi
222         if $git_cmd --work-tree=${VCSTOP} diff-index \
223             --name-only HEAD | read dummy; then
224                 git="${git}-dirty"
225                 modified=true
226         fi
227         git=" ${git}"
228 fi
229
230 if [ -n "$p4_cmd" ] ; then
231         p4version=`cd ${SYSDIR} && $p4_cmd changes -m1 "./...#have" 2>&1 | \
232                 awk '{ print $2 }'`
233         case "$p4version" in
234         [0-9]*)
235                 p4version=" ${p4version}"
236                 p4opened=`cd ${SYSDIR} && $p4_cmd opened ./... 2>&1`
237                 case "$p4opened" in
238                 File*) ;;
239                 //*)
240                         p4version="${p4version}+edit"
241                         modified=true
242                         ;;
243                 esac
244                 ;;
245         *)      unset p4version ;;
246         esac
247 fi
248
249 if [ -n "$hg_cmd" ] ; then
250         hg=`$hg_cmd id 2>/dev/null`
251         svn=`$hg_cmd svn info 2>/dev/null | \
252                 awk -F': ' '/Revision/ { print $2 }'`
253         if [ -n "$svn" ] ; then
254                 svn=" r${svn}"
255         fi
256         if [ -n "$hg" ] ; then
257                 hg=" ${hg}"
258         fi
259 fi
260
261 include_metadata=true
262 while getopts rR opt; do
263         case "$opt" in
264         r)
265                 include_metadata=
266                 ;;
267         R)
268                 if [ -z "${modified}" ]; then
269                         include_metadata=
270                 fi
271         esac
272 done
273 shift $((OPTIND - 1))
274
275 if [ -z "${include_metadata}" ]; then
276         VERINFO="${VERSION}${svn}${git}${hg}${p4version} ${i}"
277         VERSTR="${VERINFO}\\n"
278 else
279         VERINFO="${VERSION} #${v}${svn}${git}${hg}${p4version}: ${t}"
280         VERSTR="${VERINFO}\\n    ${u}@${h}:${d}\\n"
281 fi
282
283 cat << EOF > vers.c
284 $COPYRIGHT
285 #define SCCSSTR "@(#)${VERINFO}"
286 #define VERSTR "${VERSTR}"
287 #define RELSTR "${RELEASE}"
288
289 char sccs[sizeof(SCCSSTR) > 128 ? sizeof(SCCSSTR) : 128] = SCCSSTR;
290 char version[sizeof(VERSTR) > 256 ? sizeof(VERSTR) : 256] = VERSTR;
291 char compiler_version[] = "${compiler_v}";
292 char ostype[] = "${TYPE}";
293 char osrelease[sizeof(RELSTR) > 32 ? sizeof(RELSTR) : 32] = RELSTR;
294 int osreldate = ${RELDATE};
295 char kern_ident[] = "${i}";
296 EOF
297
298 echo $((v + 1)) > version