11541Srgrimes#!/bin/sh -
21541Srgrimes#
31541Srgrimes# Copyright (c) 1984, 1986, 1990, 1993
41541Srgrimes#	The Regents of the University of California.  All rights reserved.
51541Srgrimes#
61541Srgrimes# Redistribution and use in source and binary forms, with or without
71541Srgrimes# modification, are permitted provided that the following conditions
81541Srgrimes# are met:
91541Srgrimes# 1. Redistributions of source code must retain the above copyright
101541Srgrimes#    notice, this list of conditions and the following disclaimer.
111541Srgrimes# 2. Redistributions in binary form must reproduce the above copyright
121541Srgrimes#    notice, this list of conditions and the following disclaimer in the
131541Srgrimes#    documentation and/or other materials provided with the distribution.
141541Srgrimes# 4. Neither the name of the University nor the names of its contributors
151541Srgrimes#    may be used to endorse or promote products derived from this software
161541Srgrimes#    without specific prior written permission.
171541Srgrimes#
181541Srgrimes# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
191541Srgrimes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
201541Srgrimes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
211541Srgrimes# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
221541Srgrimes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
231541Srgrimes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
241541Srgrimes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
251541Srgrimes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
261541Srgrimes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
271541Srgrimes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
281541Srgrimes# SUCH DAMAGE.
291541Srgrimes#
301541Srgrimes#	@(#)newvers.sh	8.1 (Berkeley) 4/20/94
3150477Speter# $FreeBSD: releng/10.1/sys/conf/newvers.sh 310419 2016-12-22 16:19:05Z delphij $
321541Srgrimes
337153SphkTYPE="FreeBSD"
34270665SgjbREVISION="10.1"
35310419SdelphijBRANCH="RELEASE-p45"
36149258Scpercivaif [ "X${BRANCH_OVERRIDE}" != "X" ]; then
37149258Scperciva	BRANCH=${BRANCH_OVERRIDE}
38149258Scpercivafi
3918868SjkhRELEASE="${REVISION}-${BRANCH}"
409515SrgrimesVERSION="${TYPE} ${RELEASE}"
419515Srgrimes
42255930Sianif [ "X${SYSDIR}" = "X" ]; then
43255930Sian    SYSDIR=$(dirname $0)/..
44255930Sianfi
45255930Sian
4636283Seivindif [ "X${PARAMFILE}" != "X" ]; then
4736283Seivind	RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \
4836283Seivind		${PARAMFILE})
4936283Seivindelse
5036283Seivind	RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \
51213077Simp		${SYSDIR}/sys/param.h)
5236283Seivindfi
538003Sphk
5417432Swoschb=share/examples/etc/bsd-style-copyright
5517432Swoschyear=`date '+%Y'`
5617432Swosch# look for copyright template
5717432Swoschfor bsd_copyright in ../$b ../../$b ../../../$b /usr/src/$b /usr/$b
5817432Swoschdo
5917432Swosch	if [ -r "$bsd_copyright" ]; then
6027302Swosch		COPYRIGHT=`sed \
61124377Sru		    -e "s/\[year\]/1992-$year/" \
62124343Sru		    -e 's/\[your name here\]\.* /The FreeBSD Project./' \
63124343Sru		    -e 's/\[your name\]\.*/The FreeBSD Project./' \
6427302Swosch		    -e '/\[id for your version control system, if any\]/d' \
6527302Swosch		    $bsd_copyright` 
6617432Swosch		break
6717432Swosch	fi
6817432Swoschdone
6917432Swosch
7017432Swosch# no copyright found, use a dummy
7117432Swoschif [ X"$COPYRIGHT" = X ]; then
72140137Strhodes	COPYRIGHT="/*-
73124377Sru * Copyright (c) 1992-$year The FreeBSD Project.
74124341Sru * All rights reserved.
7517432Swosch *
7617432Swosch */"
7717432Swoschfi
7817432Swosch
7917432Swosch# add newline
8017432SwoschCOPYRIGHT="$COPYRIGHT
8117432Swosch"
8217432Swosch
8373349SruLC_ALL=C; export LC_ALL
849515Srgrimesif [ ! -r version ]
859515Srgrimesthen
869515Srgrimes	echo 0 > version
878003Sphkfi
888003Sphk
899515Srgrimestouch version
90140299Sruv=`cat version` u=${USER:-root} d=`pwd` h=${HOSTNAME:-`hostname`} t=`date`
91135371Srui=`${MAKE:-make} -V KERN_IDENT`
92246246Savgcompiler_v=$($(${MAKE:-make} -V CC) -v 2>&1 | grep 'version')
93179637Sphk
94252505Sgjbfor dir in /usr/bin /usr/local/bin; do
95252505Sgjb	if [ ! -z "${svnversion}" ] ; then
96252505Sgjb		break
97252505Sgjb	fi
98240547Srpaulo	if [ -x "${dir}/svnversion" ] && [ -z ${svnversion} ] ; then
99254094Sgjb		# Run svnversion from ${dir} on this script; if return code
100254094Sgjb		# is not zero, the checkout might not be compatible with the
101254094Sgjb		# svnversion being used.
102254217Sgjb		${dir}/svnversion $(realpath ${0}) >/dev/null 2>&1
103254094Sgjb		if [ $? -eq 0 ]; then
104254094Sgjb			svnversion=${dir}/svnversion
105254094Sgjb			break
106254094Sgjb		fi
107197334Smlaier	fi
108252505Sgjbdone
109254094Sgjb
110254094Sgjbif [ -z "${svnversion}" ] && [ -x /usr/bin/svnliteversion ] ; then
111254217Sgjb	/usr/bin/svnliteversion $(realpath ${0}) >/dev/null 2>&1
112254094Sgjb	if [ $? -eq 0 ]; then
113254094Sgjb		svnversion=/usr/bin/svnliteversion
114254094Sgjb	else
115254094Sgjb		svnversion=
116254094Sgjb	fi
117254094Sgjbfi
118254094Sgjb
119252505Sgjbfor dir in /usr/bin /usr/local/bin; do
120240547Srpaulo	if [ -x "${dir}/p4" ] && [ -z ${p4_cmd} ] ; then
121240547Srpaulo		p4_cmd=${dir}/p4
122240547Srpaulo	fi
123213077Simpdone
124231558Savgif [ -d "${SYSDIR}/../.git" ] ; then
125252505Sgjb	for dir in /usr/bin /usr/local/bin; do
126231558Savg		if [ -x "${dir}/git" ] ; then
127231558Savg			git_cmd="${dir}/git --git-dir=${SYSDIR}/../.git"
128231558Savg			break
129231558Savg		fi
130231558Savg	done
131231558Savgfi
132197334Smlaier
133261430Srpauloif [ -d "${SYSDIR}/../.hg" ] ; then
134261430Srpaulo	for dir in /usr/bin /usr/local/bin; do
135261430Srpaulo		if [ -x "${dir}/hg" ] ; then
136261532Srpaulo			hg_cmd="${dir}/hg -R ${SYSDIR}/.."
137261430Srpaulo			break
138261430Srpaulo		fi
139261430Srpaulo	done
140261430Srpaulofi
141261430Srpaulo
142213077Simpif [ -n "$svnversion" ] ; then
143253956Sgjb	svn=`cd ${SYSDIR} && $svnversion 2>/dev/null`
144226863Sdougb	case "$svn" in
145226863Sdougb	[0-9]*)	svn=" r${svn}" ;;
146226863Sdougb	*)	unset svn ;;
147226863Sdougb	esac
148213077Simpfi
149179655Sdougb
150213077Simpif [ -n "$git_cmd" ] ; then
151213077Simp	git=`$git_cmd rev-parse --verify --short HEAD 2>/dev/null`
152213077Simp	svn=`$git_cmd svn find-rev $git 2>/dev/null`
153213077Simp	if [ -n "$svn" ] ; then
154213077Simp		svn=" r${svn}"
155213077Simp		git="=${git}"
156213077Simp	else
157213077Simp		svn=`$git_cmd log | fgrep 'git-svn-id:' | head -1 | \
158213077Simp		     sed -n 's/^.*@\([0-9][0-9]*\).*$/\1/p'`
159253602Savg		if [ -z "$svn" ] ; then
160253602Savg			svn=`$git_cmd log --format='format:%N' | \
161253602Savg			     grep '^svn ' | head -1 | \
162253602Savg			     sed -n 's/^.*revision=\([0-9][0-9]*\).*$/\1/p'`
163253602Savg		fi
164253601Savg		if [ -n "$svn" ] ; then
165197334Smlaier			svn=" r${svn}"
166213077Simp			git="+${git}"
167197334Smlaier		else
168213077Simp			git=" ${git}"
169197334Smlaier		fi
170197334Smlaier	fi
171256014Srpaulo	git_b=`$git_cmd rev-parse --abbrev-ref HEAD`
172256014Srpaulo	if [ -n "$git_b" ] ; then
173256014Srpaulo		git="${git}(${git_b})"
174256014Srpaulo	fi
175213077Simp	if $git_cmd --work-tree=${SYSDIR}/.. diff-index \
176213077Simp	    --name-only HEAD | read dummy; then
177213077Simp		git="${git}-dirty"
178213077Simp	fi
179213077Simpfi
180179637Sphk
181240547Srpauloif [ -n "$p4_cmd" ] ; then
182240547Srpaulo	p4version=`cd ${SYSDIR} && $p4_cmd changes -m1 "./...#have" 2>&1 | \
183240547Srpaulo		awk '{ print $2 }'`
184240547Srpaulo	case "$p4version" in
185240547Srpaulo	[0-9]*)
186240547Srpaulo		p4version=" ${p4version}"
187240805Srpaulo		p4opened=`cd ${SYSDIR} && $p4_cmd opened ./... 2>&1`
188240547Srpaulo		case "$p4opened" in
189240547Srpaulo		File*) ;;
190240805Srpaulo		//*)	p4version="${p4version}+edit" ;;
191240547Srpaulo		esac
192240547Srpaulo		;;
193240547Srpaulo	*)	unset p4version ;;
194240547Srpaulo	esac
195240547Srpaulofi
196240547Srpaulo
197261430Srpauloif [ -n "$hg_cmd" ] ; then
198261430Srpaulo	hg=`$hg_cmd id 2>/dev/null`
199261430Srpaulo	svn=`$hg_cmd svn info 2>/dev/null | \
200261430Srpaulo		awk -F': ' '/Revision/ { print $2 }'`
201261430Srpaulo	if [ -n "$svn" ] ; then
202261430Srpaulo		svn=" r${svn}"
203261430Srpaulo	fi
204261430Srpaulo	if [ -n "$hg" ] ; then
205261430Srpaulo		hg=" ${hg}"
206261430Srpaulo	fi
207261430Srpaulofi
208261430Srpaulo
20949511Sjkhcat << EOF > vers.c
21049511Sjkh$COPYRIGHT
211261430Srpaulo#define SCCSSTR "@(#)${VERSION} #${v}${svn}${git}${hg}${p4version}: ${t}"
212261430Srpaulo#define VERSTR "${VERSION} #${v}${svn}${git}${hg}${p4version}: ${t}\\n    ${u}@${h}:${d}\\n"
213149258Scperciva#define RELSTR "${RELEASE}"
214149258Scperciva
215149258Scpercivachar sccs[sizeof(SCCSSTR) > 128 ? sizeof(SCCSSTR) : 128] = SCCSSTR;
216149258Scpercivachar version[sizeof(VERSTR) > 256 ? sizeof(VERSTR) : 256] = VERSTR;
217246246Savgchar compiler_version[] = "${compiler_v}";
21849511Sjkhchar ostype[] = "${TYPE}";
219149258Scpercivachar osrelease[sizeof(RELSTR) > 32 ? sizeof(RELSTR) : 32] = RELSTR;
22049511Sjkhint osreldate = ${RELDATE};
221116105Sjmallettchar kern_ident[] = "${i}";
22249511SjkhEOF
2237153Sphk
224222218Sruecho $((v + 1)) > version
225