Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | ############################################################################## |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 3 | # Copyright 2020-2021,2022 Thomas E. Dickey # |
| 4 | # Copyright 2003-2006,2010 Free Software Foundation, Inc. # |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 5 | # # |
| 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 | ############################################################################## |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 30 | # $Id: listused.sh,v 1.12 2022/07/16 16:33:38 tom Exp $ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 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 |
| 34 | # these options: |
| 35 | # --disable-macros |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 36 | # --enable-opaque-curses |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 37 | # --enable-sp-funcs |
| 38 | # --enable-widec |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 39 | # --without-gpm |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 40 | # 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: |
| 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 |
| 50 | |
| 51 | NM_OPTS= |
| 52 | |
| 53 | if test ! -d ../objects ; then |
| 54 | echo "? need objects to run this script" |
| 55 | exit 1 |
| 56 | elif test ! -d ../lib ; then |
| 57 | echo "? need libraries to run this script" |
| 58 | exit 1 |
| 59 | fi |
| 60 | |
| 61 | PROGS= |
| 62 | for name in `(echo "test:";sort modules; echo "progs:";sort ../progs/modules) |sed -e 's/[ ].*//' -e '/^[#@]/d'` |
| 63 | do |
| 64 | case $name in |
| 65 | *:) |
| 66 | PROGS="$PROGS $name" |
| 67 | ;; |
| 68 | *) |
| 69 | NAME=../objects/${name}.o |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 70 | if test -f "$NAME" |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 71 | then |
| 72 | PROGS="$PROGS $NAME" |
| 73 | fi |
| 74 | ;; |
| 75 | esac |
| 76 | done |
| 77 | |
| 78 | # For each library - |
| 79 | for lib in ../lib/*.a |
| 80 | do |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 81 | LIB=`basename "$lib" .a` |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 82 | case $LIB in |
| 83 | *_*|*+*) |
| 84 | continue |
| 85 | ;; |
| 86 | esac |
| 87 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 88 | tmp=`echo "$LIB"|sed -e 's/w$//'` |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 89 | echo |
| 90 | echo "${tmp}:" |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 91 | echo "$tmp" |sed -e 's/./-/g' |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 92 | # Construct a list of public externals provided by the library. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 93 | WANT=`nm $NM_OPTS "$lib" |\ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 94 | 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 | *) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 116 | TEST=`nm $NM_OPTS "$prog" |\ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 117 | 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 |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 128 | have=`basename "$prog" .o` |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 129 | 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 |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 150 | do |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 151 | case $tmp in |
| 152 | *_*|*+*) |
| 153 | continue |
| 154 | ;; |
| 155 | esac |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 156 | TEST=`nm $NM_OPTS "$tmp" |\ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 157 | 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 |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 169 | tmp=`basename "$tmp" .a |sed -e 's/w$//'` |
| 170 | HAVE=`echo "$tmp" | sed -e 's/lib/lib: /'` |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 171 | break |
| 172 | fi |
| 173 | done |
| 174 | fi |
| 175 | test -z "$HAVE" && HAVE="-" |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 176 | lenn=`expr 39 - length "$name"` |
| 177 | lenn=`expr "$lenn" / 8` |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 178 | tabs= |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 179 | while test "$lenn" != 0 |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 180 | do |
| 181 | tabs="${tabs} " |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 182 | lenn=`expr "$lenn" - 1` |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 183 | done |
| 184 | echo "${name}${tabs}${HAVE}" |
| 185 | done |
| 186 | done |