8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / sgs / lorder / lorder.sh
blobbea4cd4804c7693cfddc8dedc4d11418a79e3991
1 #! /bin/sh -f
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
22 # Copyright (c) 1989 AT&T
23 # All Rights Reserved
25 # Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
28 # COMMON LORDER
31 if [ -z "$TMPDIR" ]
32 then
33 TDIR="/tmp"
34 else
35 TDIR=$TMPDIR
37 trap "rm -f $TDIR/$$symdef $TDIR/$$symref $TDIR/$$tmp; exit" 1 2 13 15
38 PFX=
39 WHERE=/usr/bin
41 USAGE="Usage: ${PFX}lorder file ..."
42 for i in "$@"
44 case "$i" in
45 -*) echo "$USAGE";
46 exit 2;;
47 esac
49 if [ ! -r "$i" ]
50 then
51 echo "${PFX}lorder: $i: cannot open"
52 exit 2;
54 done
56 case $# in
57 0) echo "$USAGE"
58 exit 2;;
59 1) case $1 in
60 *.o) set $1 $1
61 esac
62 esac
64 # The following sed script is commented here.
65 # The first three expressions in the sed script
66 # insures that we only have lines
67 # that contain file names and the external
68 # declarations associated with each file.
69 # The next two parts of the sed script put the pattern
70 # (in this case the file name) into the hold space
71 # and creates the "filename filename" lines and
72 # writes them out. The first part is for .o files,
73 # the second is for .o's in archives.
74 # The last 2 sections of code are exactly alike but
75 # they handle different external symbols, namely the
76 # symbols that are defined in the text section, data section, bss
77 # section or common symbols and symbols
78 # that are referenced but not defined in this file.
79 # A line containing the symbol (from the pattern space) and
80 # the file it is referenced in (from the hold space) is
81 # put into the pattern space.
82 # If its text, data, bss or common it is written out to the
83 # symbol definition (symdef) file, otherwise it was referenced
84 # but not declared in this file so it is written out to the
85 # symbol referenced (symref) file.
88 ${WHERE}/${PFX}nm -p $* 2>$TDIR/$$tmp | sed -e '/^[ ]*$/d' -e '
89 /^[0-9]* R $/d
90 / [a-zFLS] /d
91 /[^]]:$/{
92 s/://
94 s/.*/& &/
98 /]:$/{
99 s/]://
100 s/^.*\[//
102 s/.*/& &/
106 / [TDBNCAR] /{
107 s/^.* [TDBNCAR] //
109 s/\n/ /
110 w '$TDIR/$$symdef'
113 / U /{
114 s/^.* U //
116 s/\n/ /
117 w '$TDIR/$$symref'
121 if [ -s $TDIR/$$tmp ]
122 then
123 sed -e "s/^${PFX}nm:/${PFX}lorder:/" < $TDIR/$$tmp >&2
124 rm -f $TDIR/$$symdef $TDIR/$$symref $TDIR/$$tmp
125 exit 1
127 sort $TDIR/$$symdef -o $TDIR/$$symdef
128 sort $TDIR/$$symref -o $TDIR/$$symref
129 join $TDIR/$$symref $TDIR/$$symdef | sed 's/[^ ]* *//'
130 rm -f $TDIR/$$symdef $TDIR/$$symref $TDIR/$$tmp