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