1#!/bin/sh 2############################################################################## 3# Copyright 2020-2021,2022 Thomas E. Dickey # 4# Copyright 2003-2006,2010 Free Software Foundation, Inc. # 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############################################################################## 30# $Id: listused.sh,v 1.12 2022/07/16 16:33:38 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 34# these options: 35# --disable-macros 36# --enable-opaque-curses 37# --enable-sp-funcs 38# --enable-widec 39# --without-gpm 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: 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 70 if test -f "$NAME" 71 then 72 PROGS="$PROGS $NAME" 73 fi 74 ;; 75 esac 76done 77 78# For each library - 79for lib in ../lib/*.a 80do 81 LIB=`basename "$lib" .a` 82 case $LIB in 83 *_*|*+*) 84 continue 85 ;; 86 esac 87 88 tmp=`echo "$LIB"|sed -e 's/w$//'` 89 echo 90 echo "${tmp}:" 91 echo "$tmp" |sed -e 's/./-/g' 92 # Construct a list of public externals provided by the library. 93 WANT=`nm $NM_OPTS "$lib" |\ 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 *) 116 TEST=`nm $NM_OPTS "$prog" |\ 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 128 have=`basename "$prog" .o` 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 150 do 151 case $tmp in 152 *_*|*+*) 153 continue 154 ;; 155 esac 156 TEST=`nm $NM_OPTS "$tmp" |\ 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 169 tmp=`basename "$tmp" .a |sed -e 's/w$//'` 170 HAVE=`echo "$tmp" | sed -e 's/lib/lib: /'` 171 break 172 fi 173 done 174 fi 175 test -z "$HAVE" && HAVE="-" 176 lenn=`expr 39 - length "$name"` 177 lenn=`expr "$lenn" / 8` 178 tabs= 179 while test "$lenn" != 0 180 do 181 tabs="${tabs} " 182 lenn=`expr "$lenn" - 1` 183 done 184 echo "${name}${tabs}${HAVE}" 185 done 186done 187