5 # Copyright (C) 2011 Morten Welinder.
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License as
9 # published by the Free Software Foundation; either version 2 of the
10 # License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this library; if not, see <https://www.gnu.org/licenses/>.
20 # Author: Morten Welinder <terra@gnome.org>
23 # 1. This depends heavily on nm's output format.
24 # 2. We search for .o files. Things should be freshly compiled and there
25 # should be no old ones lying around.
26 # 3. Symbols used within the file that holds their definition might be
27 # shown as not used at all.
33 die "$0: must be run from top-level directory.\n"
34 unless (-r
"configure.ac" &&
47 my %symbols = ('main' => $USED);
49 &read_object_files
("src", 0);
50 &read_object_files
("plugins", 1);
51 &read_object_files
("component", 1);
53 foreach my $sym (sort keys %symbols) {
54 my $info = $symbols{$sym};
55 if (($info & ($DEFINED|$USED)) == $DEFINED) {
56 print STDERR
"$sym -- defined, but not used.\n";
62 sub read_object_files
{
63 my ($dir,$ignore_definitions) = @_;
66 open (*FIND
, "find $dir '(' -type f -name '*.o' -print ')' -o '(' -type d '(' -name intl -o -name macros -o -name .git -o -name win32 ')' -prune ')' |")
67 or die "$0: cannot execute find: $!\n";
69 foreach my $filename (<FIND
>) {
71 $filename =~ s
|^\
./||;
73 next if $exceptions{$filename};
74 my $basename = $filename;
75 $basename =~ s
|^.*/||;
76 next if $base_exceptions{$basename};
79 open (*NM
, "nm $filename |")
80 or die "$0: cannot execute nm: $1\n";
81 foreach my $line (<NM
>) {
83 if ($line =~ /^\S+\s+T\s+(\S+)$/) {
84 $symbols{$1} |= $DEFINED
85 unless $ignore_definitions;
86 } elsif ($line =~ /^\s+U\s+(\S+)$/) {
87 $symbols{$1} |= $USED;