xref: /titanic_51/usr/src/cmd/sgs/libconv/common/bld_vernote.ksh (revision a563a037ee1e9e7c39304f3775eb7327ab86b914)
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 (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# ident	"%Z%%M%	%I%	%E% SMI"
24#
25# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
26# Use is subject to license terms.
27#
28
29usage()
30{
31	echo "usage: bld_vernote -R <revision> -r <release> -o <outfile.s>"
32}
33
34pad_notestring()
35{
36	extra=$1
37	len=$(( ${#notestring} + $extra ))
38	padlen=$(( $len % 4 ))
39	while [[ $(( $len % 4)) != 0 ]]
40	do
41		notestring="${notestring}\0"
42		len=$(( $len + 1 ))
43	done
44}
45
46
47build_sparcnote()
48{
49	notestring="\tSolaris Link Editors: $release-$revision\n\0"
50	#
51	# The 'adjustment' is for the '\t\n\0'
52	#
53	pad_notestring -3
54
55cat > $notefile <<EOF
56	.section	".note"
57
58#include <sgs.h>
59
60	.align	4
61	.word	.endname - .startname	/* note name size */
62	.word	0			/* note desc size */
63	.word	0			/* note type */
64.startname:
65	.ascii	"$notestring"
66.endname:
67
68	.section	".rodata", #alloc
69	.global		link_ver_string
70link_ver_string:
71	.type		link_ver_string, #object
72	.ascii	"${release}-${revision}\0"
73	.size	link_ver_string, .-link_ver_string
74EOF
75}
76
77build_i386note()
78{
79	notestring="\tSolaris Link Editors: $release-$revision\n"
80	#
81	# The 'adjustment' is for the '\t\n' and the
82	# fact that the x86/amd64 assembler automatically
83	# append a '\0' at the end of a string.
84	#
85	pad_notestring -1
86cat > $notefile <<EOF
87	.section	.note
88
89#include <sgs.h>
90
91	.align	4
92	.long	.endname - .startname	/* note name size */
93	.long	0			/* note desc size */
94	.long	0			/* note type */
95.startname:
96	.string	"$notestring"
97.endname:
98
99	.section	.rodata, "a"
100	.globl		link_ver_string
101link_ver_string:
102	.type	link_ver_string,@object
103	.string	"${release}-${revision}\0"
104	.size	link_ver_string, .-link_ver_string
105EOF
106}
107
108
109notefile=""
110release=""
111revision=""
112
113while getopts DR:o:r: c
114do
115	case $c in
116	o)
117		notefile=$OPTARG
118		;;
119	r)
120		release=$OPTARG
121		;;
122	R)
123		revision=$OPTARG
124		;;
125	\?)
126		usage
127		exit 1
128		;;
129	esac
130done
131
132if [[ ( -z $notefile ) || ( -z $release ) || ( -z $revision ) ]]; then
133	usage
134	exit 1
135fi
136
137
138if [[ $MACH = "sparc" ]]; then
139	build_sparcnote
140elif [[ $MACH = "i386" ]]; then
141	build_i386note
142else
143	echo "I don't know how to build a vernote.s for ${MACH}, so sorry"
144	exit 1
145fi
146