]> ncurses.scripts.mit.edu Git - ncurses.git/blob - test/listused.sh
ncurses 5.7 - patch 20090124
[ncurses.git] / test / listused.sh
1 #!/bin/sh
2 ##############################################################################
3 # Copyright (c) 2003,2006 Free Software Foundation, Inc.                     #
4 #                                                                            #
5 # Permission is hereby granted, free of charge, to any person obtaining a    #
6 # copy of this software and associated documentation files (the "Software"), #
7 # to deal in the Software without restriction, including without limitation  #
8 # the rights to use, copy, modify, merge, publish, distribute, distribute    #
9 # with modifications, sublicense, and/or sell copies of the Software, and to #
10 # permit persons to whom the Software is furnished to do so, subject to the  #
11 # following conditions:                                                      #
12 #                                                                            #
13 # The above copyright notice and this permission notice shall be included in #
14 # all copies or substantial portions of the Software.                        #
15 #                                                                            #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   #
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    #
19 # THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      #
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING    #
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER        #
22 # DEALINGS IN THE SOFTWARE.                                                  #
23 #                                                                            #
24 # Except as contained in this notice, the name(s) of the above copyright     #
25 # holders shall not be used in advertising or otherwise to promote the sale, #
26 # use or other dealings in this Software without prior written               #
27 # authorization.                                                             #
28 ##############################################################################
29 # $Id: listused.sh,v 1.7 2006/06/03 16:39:37 tom Exp $
30 # A very simple script to list entrypoints that are used by either a test
31 # program, or within the libraries.  This relies on the output format of 'nm',
32 # and assumes that the libraries are configured with TRACE defined, and using
33 # these options:
34 #       --disable-macros
35 #       --enable-widec
36 # Static libraries are used, to provide some filtering based on internal usage
37 # of the different symbols.
38
39 # keep the sorting independent of locale:
40 if test "${LANGUAGE+set}"    = set; then LANGUAGE=C;    export LANGUAGE;    fi
41 if test "${LANG+set}"        = set; then LANG=C;        export LANG;        fi
42 if test "${LC_ALL+set}"      = set; then LC_ALL=C;      export LC_ALL;      fi
43 if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
44 if test "${LC_CTYPE+set}"    = set; then LC_CTYPE=C;    export LC_CTYPE;    fi
45 if test "${LC_COLLATE+set}"  = set; then LC_COLLATE=C;  export LC_COLLATE;  fi
46
47 NM_OPTS=
48
49 if test ! -d ../objects ; then
50         echo "? need objects to run this script"
51         exit 1
52 elif test ! -d ../lib ; then
53         echo "? need libraries to run this script"
54         exit 1
55 fi
56
57 PROGS=
58 for name in `(echo "test:";sort modules; echo "progs:";sort ../progs/modules) |sed -e 's/[      ].*//' -e '/^[#@]/d'`
59 do
60         case $name in
61         *:)
62                 PROGS="$PROGS $name"
63                 ;;
64         *)
65                 NAME=../objects/${name}.o
66                 if test -f $NAME
67                 then
68                         PROGS="$PROGS $NAME"
69                 fi
70                 ;;
71         esac
72 done
73
74 # For each library -
75 for lib in ../lib/*.a
76 do
77         LIB=`basename $lib .a`
78         case $LIB in
79         *_*|*+*)
80                 continue
81                 ;;
82         esac
83
84         tmp=`echo $LIB|sed -e 's/w$//'`
85         echo
86         echo "${tmp}:"
87         echo $tmp |sed -e 's/./-/g'
88         # Construct a list of public externals provided by the library.
89         WANT=`nm $NM_OPTS $lib |\
90                 sed     -e 's/^[^ ]*//' \
91                         -e 's/^ *//' \
92                         -e '/^[ a-z] /d' \
93                         -e '/:$/d' \
94                         -e '/^$/d' \
95                         -e '/^U /d' \
96                         -e 's/^[A-Z] //' \
97                         -e '/^_/d' |\
98                 sort -u`
99         # List programs which use that external.
100         for name in $WANT
101         do
102                 HAVE=
103                 tags=
104                 last=
105                 for prog in $PROGS
106                 do
107                         case $prog in
108                         *:)
109                                 tags=$prog
110                                 ;;
111                         *)
112                                 TEST=`nm $NM_OPTS $prog |\
113                                         sed     -e 's/^[^ ]*//' \
114                                                 -e 's/^ *//' \
115                                                 -e '/^[ a-z] /d' \
116                                                 -e '/:$/d' \
117                                                 -e '/^$/d' \
118                                                 -e 's/^[A-Z] //' \
119                                                 -e '/^_/d' \
120                                                 -e 's/^'${name}'$/_/' \
121                                                 -e '/^[^_]/d'`
122                                 if test -n "$TEST"
123                                 then
124                                         have=`basename $prog .o`
125                                         if test -n "$HAVE"
126                                         then
127                                                 if test "$last" = "$tags"
128                                                 then
129                                                         HAVE="$HAVE $have"
130                                                 else
131                                                         HAVE="$HAVE $tags $have"
132                                                 fi
133                                         else
134                                                 HAVE="$tags $have"
135                                         fi
136                                         last="$tags"
137                                 fi
138                                 ;;
139                         esac
140                 done
141                 # if we did not find a program using it directly, see if it
142                 # is used within a library.
143                 if test -z "$HAVE"
144                 then
145                         for tmp in ../lib/*.a
146                         do 
147                                 case $tmp in
148                                 *_*|*+*)
149                                         continue
150                                         ;;
151                                 esac
152                                 TEST=`nm $NM_OPTS $tmp |\
153                                         sed     -e 's/^[^ ]*//' \
154                                                 -e 's/^ *//' \
155                                                 -e '/^[ a-z] /d' \
156                                                 -e '/:$/d' \
157                                                 -e '/^$/d' \
158                                                 -e '/^[A-TV-Z] /d' \
159                                                 -e 's/^[A-Z] //' \
160                                                 -e '/^_/d' \
161                                                 -e 's/^'${name}'$/_/' \
162                                                 -e '/^[^_]/d'`
163                                 if test -n "$TEST"
164                                 then
165                                         tmp=`basename $tmp .a |sed -e 's/w$//'`
166                                         HAVE=`echo $tmp | sed -e 's/lib/lib: /'`
167                                         break
168                                 fi
169                         done
170                 fi
171                 test -z "$HAVE" && HAVE="-"
172                 lenn=`expr 39 - length $name`
173                 lenn=`expr $lenn / 8`
174                 tabs=
175                 while test $lenn != 0
176                 do
177                         tabs="${tabs}   "
178                         lenn=`expr $lenn - 1`
179                 done
180                 echo "${name}${tabs}${HAVE}"
181         done
182 done