blob: 45653ebd68b29f76fb3f4bd1caaffaff261400dc [file] [log] [blame]
Steve Kondikae271bc2015-11-15 02:50:53 +01001#!/bin/sh
2##############################################################################
micky3879b9f5e72025-07-08 18:04:53 -04003# Copyright 2020-2021,2022 Thomas E. Dickey #
4# Copyright 2003-2006,2010 Free Software Foundation, Inc. #
Steve Kondikae271bc2015-11-15 02:50:53 +01005# #
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: #
13# #
14# The above copyright notice and this permission notice shall be included in #
15# all copies or substantial portions of the Software. #
16# #
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. #
24# #
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 #
28# authorization. #
29##############################################################################
micky3879b9f5e72025-07-08 18:04:53 -040030# $Id: listused.sh,v 1.12 2022/07/16 16:33:38 tom Exp $
Steve Kondikae271bc2015-11-15 02:50:53 +010031# 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
34# these options:
35# --disable-macros
micky3879b9f5e72025-07-08 18:04:53 -040036# --enable-opaque-curses
Steve Kondikae271bc2015-11-15 02:50:53 +010037# --enable-sp-funcs
38# --enable-widec
micky3879b9f5e72025-07-08 18:04:53 -040039# --without-gpm
Steve Kondikae271bc2015-11-15 02:50:53 +010040# Static libraries are used, to provide some filtering based on internal usage
41# of the different symbols.
42
43# keep the sorting independent of locale:
44if test "${LANGUAGE+set}" = set; then LANGUAGE=C; export LANGUAGE; fi
45if test "${LANG+set}" = set; then LANG=C; export LANG; fi
46if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
47if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
48if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi
49if test "${LC_COLLATE+set}" = set; then LC_COLLATE=C; export LC_COLLATE; fi
50
51NM_OPTS=
52
53if test ! -d ../objects ; then
54 echo "? need objects to run this script"
55 exit 1
56elif test ! -d ../lib ; then
57 echo "? need libraries to run this script"
58 exit 1
59fi
60
61PROGS=
62for name in `(echo "test:";sort modules; echo "progs:";sort ../progs/modules) |sed -e 's/[ ].*//' -e '/^[#@]/d'`
63do
64 case $name in
65 *:)
66 PROGS="$PROGS $name"
67 ;;
68 *)
69 NAME=../objects/${name}.o
micky3879b9f5e72025-07-08 18:04:53 -040070 if test -f "$NAME"
Steve Kondikae271bc2015-11-15 02:50:53 +010071 then
72 PROGS="$PROGS $NAME"
73 fi
74 ;;
75 esac
76done
77
78# For each library -
79for lib in ../lib/*.a
80do
micky3879b9f5e72025-07-08 18:04:53 -040081 LIB=`basename "$lib" .a`
Steve Kondikae271bc2015-11-15 02:50:53 +010082 case $LIB in
83 *_*|*+*)
84 continue
85 ;;
86 esac
87
micky3879b9f5e72025-07-08 18:04:53 -040088 tmp=`echo "$LIB"|sed -e 's/w$//'`
Steve Kondikae271bc2015-11-15 02:50:53 +010089 echo
90 echo "${tmp}:"
micky3879b9f5e72025-07-08 18:04:53 -040091 echo "$tmp" |sed -e 's/./-/g'
Steve Kondikae271bc2015-11-15 02:50:53 +010092 # Construct a list of public externals provided by the library.
micky3879b9f5e72025-07-08 18:04:53 -040093 WANT=`nm $NM_OPTS "$lib" |\
Steve Kondikae271bc2015-11-15 02:50:53 +010094 sed -e 's/^[^ ]*//' \
95 -e 's/^ *//' \
96 -e '/^[ a-z] /d' \
97 -e '/:$/d' \
98 -e '/^$/d' \
99 -e '/^U /d' \
100 -e 's/^[A-Z] //' \
101 -e '/^_/d' |\
102 sort -u`
103 # List programs which use that external.
104 for name in $WANT
105 do
106 HAVE=
107 tags=
108 last=
109 for prog in $PROGS
110 do
111 case $prog in
112 *:)
113 tags=$prog
114 ;;
115 *)
micky3879b9f5e72025-07-08 18:04:53 -0400116 TEST=`nm $NM_OPTS "$prog" |\
Steve Kondikae271bc2015-11-15 02:50:53 +0100117 sed -e 's/^[^ ]*//' \
118 -e 's/^ *//' \
119 -e '/^[ a-z] /d' \
120 -e '/:$/d' \
121 -e '/^$/d' \
122 -e 's/^[A-Z] //' \
123 -e '/^_/d' \
124 -e 's/^'${name}'$/_/' \
125 -e '/^[^_]/d'`
126 if test -n "$TEST"
127 then
micky3879b9f5e72025-07-08 18:04:53 -0400128 have=`basename "$prog" .o`
Steve Kondikae271bc2015-11-15 02:50:53 +0100129 if test -n "$HAVE"
130 then
131 if test "$last" = "$tags"
132 then
133 HAVE="$HAVE $have"
134 else
135 HAVE="$HAVE $tags $have"
136 fi
137 else
138 HAVE="$tags $have"
139 fi
140 last="$tags"
141 fi
142 ;;
143 esac
144 done
145 # if we did not find a program using it directly, see if it
146 # is used within a library.
147 if test -z "$HAVE"
148 then
149 for tmp in ../lib/*.a
micky3879b9f5e72025-07-08 18:04:53 -0400150 do
Steve Kondikae271bc2015-11-15 02:50:53 +0100151 case $tmp in
152 *_*|*+*)
153 continue
154 ;;
155 esac
micky3879b9f5e72025-07-08 18:04:53 -0400156 TEST=`nm $NM_OPTS "$tmp" |\
Steve Kondikae271bc2015-11-15 02:50:53 +0100157 sed -e 's/^[^ ]*//' \
158 -e 's/^ *//' \
159 -e '/^[ a-z] /d' \
160 -e '/:$/d' \
161 -e '/^$/d' \
162 -e '/^[A-TV-Z] /d' \
163 -e 's/^[A-Z] //' \
164 -e '/^_/d' \
165 -e 's/^'${name}'$/_/' \
166 -e '/^[^_]/d'`
167 if test -n "$TEST"
168 then
micky3879b9f5e72025-07-08 18:04:53 -0400169 tmp=`basename "$tmp" .a |sed -e 's/w$//'`
170 HAVE=`echo "$tmp" | sed -e 's/lib/lib: /'`
Steve Kondikae271bc2015-11-15 02:50:53 +0100171 break
172 fi
173 done
174 fi
175 test -z "$HAVE" && HAVE="-"
micky3879b9f5e72025-07-08 18:04:53 -0400176 lenn=`expr 39 - length "$name"`
177 lenn=`expr "$lenn" / 8`
Steve Kondikae271bc2015-11-15 02:50:53 +0100178 tabs=
micky3879b9f5e72025-07-08 18:04:53 -0400179 while test "$lenn" != 0
Steve Kondikae271bc2015-11-15 02:50:53 +0100180 do
181 tabs="${tabs} "
micky3879b9f5e72025-07-08 18:04:53 -0400182 lenn=`expr "$lenn" - 1`
Steve Kondikae271bc2015-11-15 02:50:53 +0100183 done
184 echo "${name}${tabs}${HAVE}"
185 done
186done