3 # SPDX-License-Identifier: BSD-3-Clause
5 # Copyright (c) 1984, 1986, 1990, 1993
6 # The Regents of the University of California. All rights reserved.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
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.
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
32 # @(#)newvers.sh 8.1 (Berkeley) 4/20/94
35 # Command line options:
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.
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.
50 if [ -n "${BRANCH_OVERRIDE}" ]; then
51 BRANCH=${BRANCH_OVERRIDE}
53 RELEASE="${REVISION}-${BRANCH}"
54 VERSION="${TYPE} ${RELEASE}"
58 # Looks up directory dir at world root and up the filesystem
66 while [ $(pwd) != "/" ]; do
67 if [ -e "./$1" ]; then
79 if [ -z "${SYSDIR}" ]; then
80 SYSDIR=$(dirname $0)/..
83 if [ -n "${PARAMFILE}" ]; then
84 RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \
87 RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \
88 ${SYSDIR}/sys/param.h)
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)
97 # look for copyright template
98 for bsd_copyright in ../$b ../../$b ../../../$b /usr/src/$b /usr/$b
100 if [ -r "$bsd_copyright" ]; then
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' \
111 # no copyright found, use a dummy
112 if [ -z "$COPYRIGHT" ]; then
114 * Copyright (c) 1992-$year The FreeBSD Project.
115 * All rights reserved.
121 COPYRIGHT="$COPYRIGHT
124 # VARS_ONLY means no files should be generated, this is just being
126 if [ -n "$VARS_ONLY" ]; then
130 LC_ALL=C; export LC_ALL
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
149 i=`${MAKE:-make} -V KERN_IDENT`
150 compiler_v=$($(${MAKE:-make} -V CC) -v 2>&1 | grep -w 'version')
152 for dir in /usr/bin /usr/local/bin; do
153 if [ ! -z "${svnversion}" ] ; then
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
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
177 for dir in /usr/bin /usr/local/bin; do
178 if [ -x "${dir}/p4" ] && [ -z ${p4_cmd} ] ; then
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 --git-dir=${VCSDIR}"
193 for dir in /usr/bin /usr/local/bin; do
194 if [ -x "${dir}/hg" ] ; then
195 hg_cmd="${dir}/hg -R ${VCSDIR}"
201 if [ -n "$svnversion" ] ; then
202 svn=`cd ${SYSDIR} && $svnversion 2>/dev/null`
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
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'`
232 if [ -n "$svn" ] ; then
239 git_b=`$git_cmd rev-parse --abbrev-ref HEAD`
240 if [ -n "$git_b" ] ; then
241 git="${git}(${git_b})"
243 if $git_cmd --work-tree=${VCSTOP} diff-index \
244 --name-only HEAD | read dummy; then
250 if [ -n "$p4_cmd" ] ; then
251 p4version=`cd ${SYSDIR} && $p4_cmd changes -m1 "./...#have" 2>&1 | \
255 p4version=" ${p4version}"
256 p4opened=`cd ${SYSDIR} && $p4_cmd opened ./... 2>&1`
260 p4version="${p4version}+edit"
265 *) unset p4version ;;
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
276 if [ -n "$hg" ] ; then
281 include_metadata=true
282 while getopts rR opt; do
288 if [ -z "${modified}" ]; then
293 shift $((OPTIND - 1))
295 if [ -z "${include_metadata}" ]; then
296 VERINFO="${VERSION} ${svn}${git}${hg}${p4version}"
297 VERSTR="${VERINFO}\\n"
299 VERINFO="${VERSION} #${v}${svn}${git}${hg}${p4version}: ${t}"
300 VERSTR="${VERINFO}\\n ${u}@${h}:${d}\\n"
305 #define SCCSSTR "@(#)${VERINFO}"
306 #define VERSTR "${VERSTR}"
307 #define RELSTR "${RELEASE}"
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}";
318 echo $((v + 1)) > version