3 # Copyright (c) 1984, 1986, 1990, 1993
4 # The Regents of the University of California. All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # 3. Neither the name of the University nor the names of its contributors
15 # may be used to endorse or promote products derived from this software
16 # without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # @(#)newvers.sh 8.1 (Berkeley) 4/20/94
33 # Command line options:
35 # -r Reproducible build. Do not embed directory names, user
36 # names, time stamps or other dynamic information into
37 # the output file. This is intended to allow two builds
38 # done at different times and even by different people on
39 # different hosts to produce identical output.
41 # -R Reproducible build if the tree represents an unmodified
42 # checkout from a version control system. Metadata is
43 # included if the tree is modified.
48 if [ -n "${BRANCH_OVERRIDE}" ]; then
49 BRANCH=${BRANCH_OVERRIDE}
51 RELEASE="${REVISION}-${BRANCH}"
52 VERSION="${TYPE} ${RELEASE}"
54 if [ -z "${SYSDIR}" ]; then
55 SYSDIR=$(dirname $0)/..
58 if [ -n "${PARAMFILE}" ]; then
59 RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \
62 RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \
63 ${SYSDIR}/sys/param.h)
66 b=share/examples/etc/bsd-style-copyright
67 if [ -r "${SYSDIR}/../COPYRIGHT" ]; then
68 year=$(sed -Ee '/^Copyright .* The FreeBSD Project/!d;s/^.*1992-([0-9]*) .*$/\1/g' ${SYSDIR}/../COPYRIGHT)
72 # look for copyright template
73 for bsd_copyright in ../$b ../../$b ../../../$b /usr/src/$b /usr/$b
75 if [ -r "$bsd_copyright" ]; then
77 -e "s/\[year\]/1992-$year/" \
78 -e 's/\[your name here\]\.* /The FreeBSD Project./' \
79 -e 's/\[your name\]\.*/The FreeBSD Project./' \
80 -e '/\[id for your version control system, if any\]/d' \
86 # no copyright found, use a dummy
87 if [ -z "$COPYRIGHT" ]; then
89 * Copyright (c) 1992-$year The FreeBSD Project.
90 * All rights reserved.
99 # VARS_ONLY means no files should be generated, this is just being
101 if [ -n "$VARS_ONLY" ]; then
105 LC_ALL=C; export LC_ALL
115 h=${HOSTNAME:-`hostname`}
116 if [ -n "$SOURCE_DATE_EPOCH" ]; then
117 if ! t=`date -r $SOURCE_DATE_EPOCH 2>/dev/null`; then
118 echo "Invalid SOURCE_DATE_EPOCH" >&2
124 i=`${MAKE:-make} -V KERN_IDENT`
125 compiler_v=$($(${MAKE:-make} -V CC) -v 2>&1 | grep -w 'version')
127 for dir in /usr/bin /usr/local/bin; do
128 if [ ! -z "${svnversion}" ] ; then
131 if [ -x "${dir}/svnversion" ] && [ -z ${svnversion} ] ; then
132 # Run svnversion from ${dir} on this script; if return code
133 # is not zero, the checkout might not be compatible with the
134 # svnversion being used.
135 ${dir}/svnversion $(realpath ${0}) >/dev/null 2>&1
136 if [ $? -eq 0 ]; then
137 svnversion=${dir}/svnversion
143 if [ -z "${svnversion}" ] && [ -x /usr/bin/svnliteversion ] ; then
144 /usr/bin/svnliteversion $(realpath ${0}) >/dev/null 2>&1
145 if [ $? -eq 0 ]; then
146 svnversion=/usr/bin/svnliteversion
152 for dir in /usr/bin /usr/local/bin; do
153 if [ -x "${dir}/p4" ] && [ -z ${p4_cmd} ] ; then
157 if [ -d "${SYSDIR}/../.git" ] ; then
158 for dir in /usr/bin /usr/local/bin; do
159 if [ -x "${dir}/git" ] ; then
160 git_cmd="${dir}/git --git-dir=${SYSDIR}/../.git"
166 if [ -d "${SYSDIR}/../.hg" ] ; then
167 for dir in /usr/bin /usr/local/bin; do
168 if [ -x "${dir}/hg" ] ; then
169 hg_cmd="${dir}/hg -R ${SYSDIR}/.."
175 if [ -n "$svnversion" ] ; then
176 svn=`cd ${SYSDIR} && $svnversion 2>/dev/null`
191 if [ -n "$git_cmd" ] ; then
192 git=`$git_cmd rev-parse --verify --short HEAD 2>/dev/null`
193 svn=`$git_cmd svn find-rev $git 2>/dev/null`
194 if [ -n "$svn" ] ; then
198 svn=`$git_cmd log | fgrep 'git-svn-id:' | head -1 | \
199 sed -n 's/^.*@\([0-9][0-9]*\).*$/\1/p'`
200 if [ -z "$svn" ] ; then
201 svn=`$git_cmd log --format='format:%N' | \
202 grep '^svn ' | head -1 | \
203 sed -n 's/^.*revision=\([0-9][0-9]*\).*$/\1/p'`
205 if [ -n "$svn" ] ; then
212 git_b=`$git_cmd rev-parse --abbrev-ref HEAD`
213 if [ -n "$git_b" ] ; then
214 git="${git}(${git_b})"
216 if $git_cmd --work-tree=${SYSDIR}/.. diff-index \
217 --name-only HEAD | read dummy; then
223 if [ -n "$p4_cmd" ] ; then
224 p4version=`cd ${SYSDIR} && $p4_cmd changes -m1 "./...#have" 2>&1 | \
228 p4version=" ${p4version}"
229 p4opened=`cd ${SYSDIR} && $p4_cmd opened ./... 2>&1`
233 p4version="${p4version}+edit"
238 *) unset p4version ;;
242 if [ -n "$hg_cmd" ] ; then
243 hg=`$hg_cmd id 2>/dev/null`
244 svn=`$hg_cmd svn info 2>/dev/null | \
245 awk -F': ' '/Revision/ { print $2 }'`
246 if [ -n "$svn" ] ; then
249 if [ -n "$hg" ] ; then
254 include_metadata=true
255 while getopts rR opt; do
261 if [ -z "${modified}" ]; then
266 shift $((OPTIND - 1))
268 if [ -z "${include_metadata}" ]; then
269 VERINFO="${VERSION} ${svn}${git}${hg}${p4version}"
270 VERSTR="${VERINFO}\\n"
272 VERINFO="${VERSION} #${v}${svn}${git}${hg}${p4version}: ${t}"
273 VERSTR="${VERINFO}\\n ${u}@${h}:${d}\\n"
278 #define SCCSSTR "@(#)${VERINFO}"
279 #define VERSTR "${VERSTR}"
280 #define RELSTR "${RELEASE}"
282 char sccs[sizeof(SCCSSTR) > 128 ? sizeof(SCCSSTR) : 128] = SCCSSTR;
283 char version[sizeof(VERSTR) > 256 ? sizeof(VERSTR) : 256] = VERSTR;
284 char compiler_version[] = "${compiler_v}";
285 char ostype[] = "${TYPE}";
286 char osrelease[sizeof(RELSTR) > 32 ? sizeof(RELSTR) : 32] = RELSTR;
287 int osreldate = ${RELDATE};
288 char kern_ident[] = "${i}";
291 echo $((v + 1)) > version