1#!/bin/sh -
2#
3#	$NetBSD: newvers.sh,v 1.56 2009/12/16 21:25:03 pooka Exp $
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
34if [ ! -e version ]; then
35	echo 0 > version
36fi
37
38v=$(cat version)
39t=$(LC_ALL=C date)
40u=${USER-root}
41h=$(hostname)
42d=$(pwd)
43cwd=$(dirname $0)
44copyright=$(awk '{ printf("\"%s\\n\"", $0); }' ${cwd}/copyright)
45
46while [ $# -gt 0 ]; do
47	case "$1" in
48	-r)
49		rflag=true
50		;;
51	-i)
52		id="$2"
53		shift
54		;;
55	-n)
56		nflag=true
57		;;
58	esac
59	shift
60done
61
62if [ -z "${id}" ]; then
63	if [ -f ident ]; then
64		id="$(cat ident)"
65	else
66		id=$(basename ${d})
67	fi
68fi
69
70osrelcmd=${cwd}/osrelease.sh
71
72ost="NetBSD"
73osr=$(sh $osrelcmd)
74
75if [ ! -z "${rflag}" ]; then
76	fullversion="${ost} ${osr} (${id})\n"
77else
78	fullversion="${ost} ${osr} (${id}) #${v}: ${t}\n\t${u}@${h}:${d}\n"
79fi
80
81echo $(expr ${v} + 1) > version
82
83cat << _EOF > vers.c
84/*
85 * Automatically generated file from $0
86 * Do not edit.
87 */
88#include <sys/cdefs.h>
89#include <sys/types.h>
90#include <sys/param.h>
91#include <sys/exec.h>
92#include <sys/exec_elf.h>
93
94const char ostype[] = "${ost}";
95const char osrelease[] = "${osr}";
96const char sccs[] = "@(#)${fullversion}";
97const char version[] = "${fullversion}";
98const char kernel_ident[] = "${id}";
99const char copyright[] =
100${copyright}
101"\n";
102_EOF
103
104[ ! -z "${nflag}" ] && exit 0
105
106cat << _EOF >> vers.c
107
108/*
109 * NetBSD identity note.
110 */
111#ifdef __arm__
112#define _SHT_NOTE	%note
113#else
114#define _SHT_NOTE	@note
115#endif
116
117#define	_S(TAG)	__STRING(TAG)
118__asm(
119	".section\t\".note.netbsd.ident\", \"\"," _S(_SHT_NOTE) "\n"
120	"\t.p2align\t2\n"
121	"\t.long\t" _S(ELF_NOTE_NETBSD_NAMESZ) "\n"
122	"\t.long\t" _S(ELF_NOTE_NETBSD_DESCSZ) "\n"
123	"\t.long\t" _S(ELF_NOTE_TYPE_NETBSD_TAG) "\n"
124	"\t.ascii\t" _S(ELF_NOTE_NETBSD_NAME) "\n"
125	"\t.long\t" _S(__NetBSD_Version__) "\n"
126	"\t.p2align\t2\n"
127);
128
129_EOF
130