2 ##############################################################################
3 # Copyright 2020-2021,2022 Thomas E. Dickey #
4 # Copyright 2003-2006,2010 Free Software Foundation, Inc. #
6 # Permission is hereby granted, free of charge, to any person obtaining a #
7 # copy of this software and associated documentation files (the "Software"), #
8 # to deal in the Software without restriction, including without limitation #
9 # the rights to use, copy, modify, merge, publish, distribute, distribute #
10 # with modifications, sublicense, and/or sell copies of the Software, and to #
11 # permit persons to whom the Software is furnished to do so, subject to the #
12 # following conditions: #
14 # The above copyright notice and this permission notice shall be included in #
15 # all copies or substantial portions of the Software. #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
20 # THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
23 # DEALINGS IN THE SOFTWARE. #
25 # Except as contained in this notice, the name(s) of the above copyright #
26 # holders shall not be used in advertising or otherwise to promote the sale, #
27 # use or other dealings in this Software without prior written #
29 ##############################################################################
30 # $Id: listused.sh,v 1.11 2022/04/09 23:03:25 tom Exp $
31 # A very simple script to list all entrypoints that are used by either a test
32 # program, or within the libraries. This relies on the output format of 'nm',
33 # and assumes that the libraries are configured with TRACE defined, and using
36 # --enable-opaque-curses
40 # Static libraries are used, to provide some filtering based on internal usage
41 # of the different symbols.
43 # keep the sorting independent of locale:
44 if test "${LANGUAGE+set}" = set; then LANGUAGE=C; export LANGUAGE; fi
45 if test "${LANG+set}" = set; then LANG=C; export LANG; fi
46 if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
47 if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
48 if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi
49 if test "${LC_COLLATE+set}" = set; then LC_COLLATE=C; export LC_COLLATE; fi
53 if test ! -d ../objects ; then
54 echo "? need objects to run this script"
56 elif test ! -d ../lib ; then
57 echo "? need libraries to run this script"
62 for name in `(echo "test:";sort modules; echo "progs:";sort ../progs/modules) |sed -e 's/[ ].*//' -e '/^[#@]/d'`
69 NAME=../objects/${name}.o
81 LIB=`basename $lib .a`
88 tmp=`echo $LIB|sed -e 's/w$//'`
91 echo $tmp |sed -e 's/./-/g'
92 # Construct a list of public externals provided by the library.
93 WANT=`nm $NM_OPTS $lib |\
103 # List programs which use that external.
116 TEST=`nm $NM_OPTS $prog |\
117 sed -e 's/^[^ ]*//' \
124 -e 's/^'${name}'$/_/' \
128 have=`basename $prog .o`
131 if test "$last" = "$tags"
135 HAVE="$HAVE $tags $have"
145 # if we did not find a program using it directly, see if it
146 # is used within a library.
149 for tmp in ../lib/*.a
156 TEST=`nm $NM_OPTS $tmp |\
157 sed -e 's/^[^ ]*//' \
165 -e 's/^'${name}'$/_/' \
169 tmp=`basename $tmp .a |sed -e 's/w$//'`
170 HAVE=`echo $tmp | sed -e 's/lib/lib: /'`
175 test -z "$HAVE" && HAVE="-"
176 lenn=`expr 39 - length $name`
177 lenn=`expr $lenn / 8`
179 while test $lenn != 0
182 lenn=`expr $lenn - 1`
184 echo "${name}${tabs}${HAVE}"