]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/conf/newvers.sh
Update releng/12.1 to RC1 as part of the 12.1-RELEASE cycle.
[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 TYPE="FreeBSD"
48 REVISION="12.1"
49 BRANCH="RC1"
50 if [ -n "${BRANCH_OVERRIDE}" ]; then
51         BRANCH=${BRANCH_OVERRIDE}
52 fi
53 RELEASE="${REVISION}-${BRANCH}"
54 VERSION="${TYPE} ${RELEASE}"
55
56 #
57 # findvcs dir
58 #       Looks up directory dir at world root and up the filesystem
59 #
60 findvcs()
61 {
62         local savedir
63
64         savedir=$(pwd)
65         cd ${SYSDIR}/..
66         while [ $(pwd) != "/" ]; do
67                 if [ -e "./$1" ]; then
68                         VCSTOP=$(pwd)
69                         VCSDIR=${VCSTOP}"/$1"
70                         cd ${savedir}
71                         return 0
72                 fi
73                 cd ..
74         done
75         cd ${savedir}
76         return 1
77 }
78
79 if [ -z "${SYSDIR}" ]; then
80     SYSDIR=$(dirname $0)/..
81 fi
82
83 if [ -n "${PARAMFILE}" ]; then
84         RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \
85                 ${PARAMFILE})
86 else
87         RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \
88                 ${SYSDIR}/sys/param.h)
89 fi
90
91 b=share/examples/etc/bsd-style-copyright
92 if [ -r "${SYSDIR}/../COPYRIGHT" ]; then
93         year=$(sed -Ee '/^Copyright .* The FreeBSD Project/!d;s/^.*1992-([0-9]*) .*$/\1/g' ${SYSDIR}/../COPYRIGHT)
94 else
95         year=$(date +%Y)
96 fi
97 # look for copyright template
98 for bsd_copyright in ../$b ../../$b ../../../$b /usr/src/$b /usr/$b
99 do
100         if [ -r "$bsd_copyright" ]; then
101                 COPYRIGHT=`sed \
102                     -e "s/\[year\]/1992-$year/" \
103                     -e 's/\[your name here\]\.* /The FreeBSD Project./' \
104                     -e 's/\[your name\]\.*/The FreeBSD Project./' \
105                     -e '/\[id for your version control system, if any\]/d' \
106                     $bsd_copyright` 
107                 break
108         fi
109 done
110
111 # no copyright found, use a dummy
112 if [ -z "$COPYRIGHT" ]; then
113         COPYRIGHT="/*-
114  * Copyright (c) 1992-$year The FreeBSD Project.
115  * All rights reserved.
116  *
117  */"
118 fi
119
120 # add newline
121 COPYRIGHT="$COPYRIGHT
122 "
123
124 # VARS_ONLY means no files should be generated, this is just being
125 # included.
126 if [ -n "$VARS_ONLY" ]; then
127         return 0
128 fi
129
130 LC_ALL=C; export LC_ALL
131 if [ ! -r version ]
132 then
133         echo 0 > version
134 fi
135
136 touch version
137 v=`cat version`
138 u=${USER:-root}
139 d=`pwd`
140 h=${HOSTNAME:-`hostname`}
141 if [ -n "$SOURCE_DATE_EPOCH" ]; then
142         if ! t=`date -r $SOURCE_DATE_EPOCH 2>/dev/null`; then
143                 echo "Invalid SOURCE_DATE_EPOCH" >&2
144                 exit 1
145         fi
146 else
147         t=`date`
148 fi
149 i=`${MAKE:-make} -V KERN_IDENT`
150 compiler_v=$($(${MAKE:-make} -V CC) -v 2>&1 | grep -w 'version')
151
152 for dir in /usr/bin /usr/local/bin; do
153         if [ ! -z "${svnversion}" ] ; then
154                 break
155         fi
156         if [ -x "${dir}/svnversion" ] && [ -z ${svnversion} ] ; then
157                 # Run svnversion from ${dir} on this script; if return code
158                 # is not zero, the checkout might not be compatible with the
159                 # svnversion being used.
160                 ${dir}/svnversion $(realpath ${0}) >/dev/null 2>&1
161                 if [ $? -eq 0 ]; then
162                         svnversion=${dir}/svnversion
163                         break
164                 fi
165         fi
166 done
167
168 if [ -z "${svnversion}" ] && [ -x /usr/bin/svnliteversion ] ; then
169         /usr/bin/svnliteversion $(realpath ${0}) >/dev/null 2>&1
170         if [ $? -eq 0 ]; then
171                 svnversion=/usr/bin/svnliteversion
172         else
173                 svnversion=
174         fi
175 fi
176
177 for dir in /usr/bin /usr/local/bin; do
178         if [ -x "${dir}/p4" ] && [ -z ${p4_cmd} ] ; then
179                 p4_cmd=${dir}/p4
180         fi
181 done
182
183 if findvcs .git; then
184         for dir in /usr/bin /usr/local/bin; do
185                 if [ -x "${dir}/git" ] ; then
186                         git_cmd="${dir}/git -c help.autocorrect=0 --git-dir=${VCSDIR}"
187                         break
188                 fi
189         done
190 fi
191
192 if findvcs .hg; then
193         for dir in /usr/bin /usr/local/bin; do
194                 if [ -x "${dir}/hg" ] ; then
195                         hg_cmd="${dir}/hg -R ${VCSDIR}"
196                         break
197                 fi
198         done
199 fi
200
201 if [ -n "$svnversion" ] ; then
202         svn=`cd ${SYSDIR} && $svnversion 2>/dev/null`
203         case "$svn" in
204         [0-9]*[MSP]|*:*)
205                 svn=" r${svn}"
206                 modified=true
207                 ;;
208         [0-9]*)
209                 svn=" r${svn}"
210                 ;;
211         *)
212                 unset svn
213                 ;;
214         esac
215 fi
216
217 if [ -n "$git_cmd" ] ; then
218         git=`$git_cmd rev-parse --verify --short HEAD 2>/dev/null`
219         svn=`$git_cmd svn find-rev $git 2>/dev/null`
220         if [ -n "$svn" ] ; then
221                 svn=" r${svn}"
222                 git="=${git}"
223         else
224                 svn=`$git_cmd log --grep '^git-svn-id:' | \
225                     grep '^    git-svn-id:' | head -1 | \
226                     sed -n 's/^.*@\([0-9][0-9]*\).*$/\1/p'`
227                 if [ -z "$svn" ] ; then
228                         svn=`$git_cmd log --format='format:%N' | \
229                              grep '^svn ' | head -1 | \
230                              sed -n 's/^.*revision=\([0-9][0-9]*\).*$/\1/p'`
231                 fi
232                 if [ -n "$svn" ] ; then
233                         svn=" r${svn}"
234                         git="+${git}"
235                 else
236                         git=" ${git}"
237                 fi
238         fi
239         git_b=`$git_cmd rev-parse --abbrev-ref HEAD`
240         if [ -n "$git_b" ] ; then
241                 git="${git}(${git_b})"
242         fi
243         if $git_cmd --work-tree=${VCSTOP} diff-index \
244             --name-only HEAD | read dummy; then
245                 git="${git}-dirty"
246                 modified=true
247         fi
248 fi
249
250 if [ -n "$p4_cmd" ] ; then
251         p4version=`cd ${SYSDIR} && $p4_cmd changes -m1 "./...#have" 2>&1 | \
252                 awk '{ print $2 }'`
253         case "$p4version" in
254         [0-9]*)
255                 p4version=" ${p4version}"
256                 p4opened=`cd ${SYSDIR} && $p4_cmd opened ./... 2>&1`
257                 case "$p4opened" in
258                 File*) ;;
259                 //*)
260                         p4version="${p4version}+edit"
261                         modified=true
262                         ;;
263                 esac
264                 ;;
265         *)      unset p4version ;;
266         esac
267 fi
268
269 if [ -n "$hg_cmd" ] ; then
270         hg=`$hg_cmd id 2>/dev/null`
271         svn=`$hg_cmd svn info 2>/dev/null | \
272                 awk -F': ' '/Revision/ { print $2 }'`
273         if [ -n "$svn" ] ; then
274                 svn=" r${svn}"
275         fi
276         if [ -n "$hg" ] ; then
277                 hg=" ${hg}"
278         fi
279 fi
280
281 include_metadata=true
282 while getopts rR opt; do
283         case "$opt" in
284         r)
285                 include_metadata=
286                 ;;
287         R)
288                 if [ -z "${modified}" ]; then
289                         include_metadata=
290                 fi
291         esac
292 done
293 shift $((OPTIND - 1))
294
295 if [ -z "${include_metadata}" ]; then
296         VERINFO="${VERSION}${svn}${git}${hg}${p4version} ${i}"
297         VERSTR="${VERINFO}\\n"
298 else
299         VERINFO="${VERSION} #${v}${svn}${git}${hg}${p4version}: ${t}"
300         VERSTR="${VERINFO}\\n    ${u}@${h}:${d}\\n"
301 fi
302
303 cat << EOF > vers.c
304 $COPYRIGHT
305 #define SCCSSTR "@(#)${VERINFO}"
306 #define VERSTR "${VERSTR}"
307 #define RELSTR "${RELEASE}"
308
309 char sccs[sizeof(SCCSSTR) > 128 ? sizeof(SCCSSTR) : 128] = SCCSSTR;
310 char version[sizeof(VERSTR) > 256 ? sizeof(VERSTR) : 256] = VERSTR;
311 char compiler_version[] = "${compiler_v}";
312 char ostype[] = "${TYPE}";
313 char osrelease[sizeof(RELSTR) > 32 ? sizeof(RELSTR) : 32] = RELSTR;
314 int osreldate = ${RELDATE};
315 char kern_ident[] = "${i}";
316 EOF
317
318 echo $((v + 1)) > version