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