1*7c478bd9Sstevel@tonic-gate#! /usr/bin/ksh
2*7c478bd9Sstevel@tonic-gate#
3*7c478bd9Sstevel@tonic-gate# CDDL HEADER START
4*7c478bd9Sstevel@tonic-gate#
5*7c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*7c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
7*7c478bd9Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
8*7c478bd9Sstevel@tonic-gate# with the License.
9*7c478bd9Sstevel@tonic-gate#
10*7c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*7c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
12*7c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
13*7c478bd9Sstevel@tonic-gate# and limitations under the License.
14*7c478bd9Sstevel@tonic-gate#
15*7c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
16*7c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*7c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
18*7c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
19*7c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
20*7c478bd9Sstevel@tonic-gate#
21*7c478bd9Sstevel@tonic-gate# CDDL HEADER END
22*7c478bd9Sstevel@tonic-gate#
23*7c478bd9Sstevel@tonic-gate#
24*7c478bd9Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
25*7c478bd9Sstevel@tonic-gate#
26*7c478bd9Sstevel@tonic-gate# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
27*7c478bd9Sstevel@tonic-gate# Use is subject to license terms.
28*7c478bd9Sstevel@tonic-gate#
29*7c478bd9Sstevel@tonic-gate
30*7c478bd9Sstevel@tonic-gateusage()
31*7c478bd9Sstevel@tonic-gate{
32*7c478bd9Sstevel@tonic-gate	echo "usage: bld_vernote [-D] -R <SUNWonld-README> -r <release> -o <outfile.s>"
33*7c478bd9Sstevel@tonic-gate}
34*7c478bd9Sstevel@tonic-gate
35*7c478bd9Sstevel@tonic-gatepad_notestring()
36*7c478bd9Sstevel@tonic-gate{
37*7c478bd9Sstevel@tonic-gate	extra=$1
38*7c478bd9Sstevel@tonic-gate	len=$(( ${#notestring} + $extra ))
39*7c478bd9Sstevel@tonic-gate	padlen=$(( $len % 4 ))
40*7c478bd9Sstevel@tonic-gate	while [[ $(( $len % 4)) != 0 ]]
41*7c478bd9Sstevel@tonic-gate	do
42*7c478bd9Sstevel@tonic-gate		notestring="${notestring}\0"
43*7c478bd9Sstevel@tonic-gate		len=$(( $len + 1 ))
44*7c478bd9Sstevel@tonic-gate	done
45*7c478bd9Sstevel@tonic-gate}
46*7c478bd9Sstevel@tonic-gate
47*7c478bd9Sstevel@tonic-gate
48*7c478bd9Sstevel@tonic-gatebuild_sparcnote()
49*7c478bd9Sstevel@tonic-gate{
50*7c478bd9Sstevel@tonic-gate	notestring="\tSolaris Link Editors: $release-$readmerev\n\0"
51*7c478bd9Sstevel@tonic-gate	#
52*7c478bd9Sstevel@tonic-gate	# The 'adjustment' is for the '\t\n\0'
53*7c478bd9Sstevel@tonic-gate	#
54*7c478bd9Sstevel@tonic-gate	pad_notestring -3
55*7c478bd9Sstevel@tonic-gate
56*7c478bd9Sstevel@tonic-gatecat > $notefile <<EOF
57*7c478bd9Sstevel@tonic-gate	.section	".note"
58*7c478bd9Sstevel@tonic-gate
59*7c478bd9Sstevel@tonic-gate#include <sgs.h>
60*7c478bd9Sstevel@tonic-gate
61*7c478bd9Sstevel@tonic-gate	.align	4
62*7c478bd9Sstevel@tonic-gate	.word	.endname - .startname	/* note name size */
63*7c478bd9Sstevel@tonic-gate	.word	0			/* note desc size */
64*7c478bd9Sstevel@tonic-gate	.word	0			/* note type */
65*7c478bd9Sstevel@tonic-gate.startname:
66*7c478bd9Sstevel@tonic-gate	.ascii	"$notestring"
67*7c478bd9Sstevel@tonic-gate.endname:
68*7c478bd9Sstevel@tonic-gate
69*7c478bd9Sstevel@tonic-gate	.section	".rodata", #alloc
70*7c478bd9Sstevel@tonic-gate	.global		link_ver_string
71*7c478bd9Sstevel@tonic-gatelink_ver_string:
72*7c478bd9Sstevel@tonic-gate	.type		link_ver_string, #object
73*7c478bd9Sstevel@tonic-gate	.ascii	"${release}-${readmerev}\0"
74*7c478bd9Sstevel@tonic-gate	.size	link_ver_string, .-link_ver_string
75*7c478bd9Sstevel@tonic-gateEOF
76*7c478bd9Sstevel@tonic-gate}
77*7c478bd9Sstevel@tonic-gate
78*7c478bd9Sstevel@tonic-gatebuild_i386note()
79*7c478bd9Sstevel@tonic-gate{
80*7c478bd9Sstevel@tonic-gate	notestring="\tSolaris Link Editors: $release-$readmerev\n"
81*7c478bd9Sstevel@tonic-gate	#
82*7c478bd9Sstevel@tonic-gate	# The 'adjustment' is for the '\t\n' and the
83*7c478bd9Sstevel@tonic-gate	# fact that the x86/amd64 assembler automatically
84*7c478bd9Sstevel@tonic-gate	# append a '\0' at the end of a string.
85*7c478bd9Sstevel@tonic-gate	#
86*7c478bd9Sstevel@tonic-gate	pad_notestring -1
87*7c478bd9Sstevel@tonic-gatecat > $notefile <<EOF
88*7c478bd9Sstevel@tonic-gate	.section	.note
89*7c478bd9Sstevel@tonic-gate
90*7c478bd9Sstevel@tonic-gate#include <sgs.h>
91*7c478bd9Sstevel@tonic-gate
92*7c478bd9Sstevel@tonic-gate	.align	4
93*7c478bd9Sstevel@tonic-gate	.long	.endname - .startname	/* note name size */
94*7c478bd9Sstevel@tonic-gate	.long	0			/* note desc size */
95*7c478bd9Sstevel@tonic-gate	.long	0			/* note type */
96*7c478bd9Sstevel@tonic-gate.startname:
97*7c478bd9Sstevel@tonic-gate	.string	"$notestring"
98*7c478bd9Sstevel@tonic-gate.endname:
99*7c478bd9Sstevel@tonic-gate
100*7c478bd9Sstevel@tonic-gate	.section	.rodata, "a"
101*7c478bd9Sstevel@tonic-gate	.globl		link_ver_string
102*7c478bd9Sstevel@tonic-gatelink_ver_string:
103*7c478bd9Sstevel@tonic-gate	.type	link_ver_string,@object
104*7c478bd9Sstevel@tonic-gate	.string	"${release}-${readmerev}\0"
105*7c478bd9Sstevel@tonic-gate	.size	link_ver_string, .-link_ver_string
106*7c478bd9Sstevel@tonic-gateEOF
107*7c478bd9Sstevel@tonic-gate}
108*7c478bd9Sstevel@tonic-gate
109*7c478bd9Sstevel@tonic-gate
110*7c478bd9Sstevel@tonic-gatenotefile=""
111*7c478bd9Sstevel@tonic-gaterelease=""
112*7c478bd9Sstevel@tonic-gatereadme=""
113*7c478bd9Sstevel@tonic-gatedebug=""
114*7c478bd9Sstevel@tonic-gate
115*7c478bd9Sstevel@tonic-gatewhile getopts DR:o:r: c
116*7c478bd9Sstevel@tonic-gatedo
117*7c478bd9Sstevel@tonic-gate	case $c in
118*7c478bd9Sstevel@tonic-gate	D)
119*7c478bd9Sstevel@tonic-gate		debug="1"
120*7c478bd9Sstevel@tonic-gate		;;
121*7c478bd9Sstevel@tonic-gate	o)
122*7c478bd9Sstevel@tonic-gate		notefile=$OPTARG
123*7c478bd9Sstevel@tonic-gate		;;
124*7c478bd9Sstevel@tonic-gate	r)
125*7c478bd9Sstevel@tonic-gate		release=$OPTARG
126*7c478bd9Sstevel@tonic-gate		;;
127*7c478bd9Sstevel@tonic-gate	R)
128*7c478bd9Sstevel@tonic-gate		readme=$OPTARG
129*7c478bd9Sstevel@tonic-gate		;;
130*7c478bd9Sstevel@tonic-gate	\?)
131*7c478bd9Sstevel@tonic-gate		usage
132*7c478bd9Sstevel@tonic-gate		exit 1
133*7c478bd9Sstevel@tonic-gate		;;
134*7c478bd9Sstevel@tonic-gate	esac
135*7c478bd9Sstevel@tonic-gatedone
136*7c478bd9Sstevel@tonic-gate
137*7c478bd9Sstevel@tonic-gateif [[ ( -z $notefile ) || ( -z $release ) || ( -z $readme ) ]]; then
138*7c478bd9Sstevel@tonic-gate	usage
139*7c478bd9Sstevel@tonic-gate	exit 1
140*7c478bd9Sstevel@tonic-gatefi
141*7c478bd9Sstevel@tonic-gate
142*7c478bd9Sstevel@tonic-gate
143*7c478bd9Sstevel@tonic-gateidentstring=$(head -10 $readme | grep '^#ident')
144*7c478bd9Sstevel@tonic-gateif [[ -z $identstring ]]; then
145*7c478bd9Sstevel@tonic-gate	echo "*** Fatal Error: building vernote.s: unable to find "
146*7c478bd9Sstevel@tonic-gate	echo "*** '#ident' string in first 10 lines of $readme"
147*7c478bd9Sstevel@tonic-gate	exit 1
148*7c478bd9Sstevel@tonic-gatefi
149*7c478bd9Sstevel@tonic-gate
150*7c478bd9Sstevel@tonic-gatereadmerev=$(echo $identstring | awk '{print $3;}')
151*7c478bd9Sstevel@tonic-gate
152*7c478bd9Sstevel@tonic-gateif [[ ( -z $readmerev ) || ( $readmerev = "%""I""%" ) ]]; then
153*7c478bd9Sstevel@tonic-gate	opwd=$(pwd)
154*7c478bd9Sstevel@tonic-gate	readdir=$(dirname $readme)
155*7c478bd9Sstevel@tonic-gate	readbase=$(basename $readme)
156*7c478bd9Sstevel@tonic-gate	cd $readdir
157*7c478bd9Sstevel@tonic-gate	readmerev=$(sccs get -p $readbase 2>/dev/null | \
158*7c478bd9Sstevel@tonic-gate		grep '^#ident' | \
159*7c478bd9Sstevel@tonic-gate		awk '{print $3;}')
160*7c478bd9Sstevel@tonic-gate	if [[ -z $readmerev ]]; then
161*7c478bd9Sstevel@tonic-gate		readmerev='0.0'
162*7c478bd9Sstevel@tonic-gate	fi
163*7c478bd9Sstevel@tonic-gate	cd $opwd
164*7c478bd9Sstevel@tonic-gate	debug="1"
165*7c478bd9Sstevel@tonic-gatefi
166*7c478bd9Sstevel@tonic-gate
167*7c478bd9Sstevel@tonic-gateif [[ ! -z $debug ]]; then
168*7c478bd9Sstevel@tonic-gate	wsname=
169*7c478bd9Sstevel@tonic-gate	if [[ ! -z $CODEMGR_WS ]]; then
170*7c478bd9Sstevel@tonic-gate		wsname=$(basename $CODEMGR_WS)
171*7c478bd9Sstevel@tonic-gate	fi
172*7c478bd9Sstevel@tonic-gate	readmerev=${readmerev}":"${wsname}"-${USER}-"$(date +%m/%d/%y)
173*7c478bd9Sstevel@tonic-gatefi
174*7c478bd9Sstevel@tonic-gate
175*7c478bd9Sstevel@tonic-gateif [[ $MACH = "sparc" ]]; then
176*7c478bd9Sstevel@tonic-gate	build_sparcnote
177*7c478bd9Sstevel@tonic-gateelif [[ $MACH = "i386" ]]; then
178*7c478bd9Sstevel@tonic-gate	build_i386note
179*7c478bd9Sstevel@tonic-gateelse
180*7c478bd9Sstevel@tonic-gate	echo "I don't know how to build a vernote.s for ${MACH}, so sorry"
181*7c478bd9Sstevel@tonic-gate	exit 1
182*7c478bd9Sstevel@tonic-gatefi
183