Merge branch '407_ctrl_w_not_delete_line'
[midnight-commander.git] / maint / unrefglobals.pl
blob03595942393e2ccf1321af35fd2863f60e72705a
1 #!/usr/bin/perl
3 # Copyright (c) 2003, Pavel Roskin
4 # This script is Free Software, and it can be copied, distributed and
5 # modified under the terms of GNU General Public License, version 2.
7 # Run this script on the map with cross-reference generated by GNU ld,
8 # and it will generate a list of symbols that don't need to be global.
9 # To create the map, run something like this:
10 # make LDFLAGS=-Wl,-Map,output.map,--cref
12 use strict;
14 my %symbols;
15 my %syms;
16 my %objs;
18 if ($#ARGV != 0) {
19 print "Usage: unrefglobals.pl mapfile\n";
20 exit 1;
23 if (!open (MAP, "$ARGV[0]")) {
24 print "Cannot open file \"$ARGV[0]\"\n";
25 exit 1;
28 my $line;
29 my $next_line = <MAP>;
30 while (1) {
31 last unless $next_line;
32 $line = $next_line;
33 $next_line = <MAP>;
34 next unless ($line =~ m{^[A-Za-z_][A-Za-z0-9_]* +[^ /][^ ]+\.o$} or
35 $line =~ m{^[A-Za-z_][A-Za-z0-9_]* +[^ /][^ ]+\.a\([^ ]+\.o\)$});
36 if (!$next_line or ($next_line !~ /^ /)) {
37 my @arr = split (' ', $line);
38 $symbols{$arr[0]} = $arr[1];
39 $syms{$arr[0]} = 1;
40 $objs{$arr[1]} = 1;
44 close(MAP);
46 foreach my $obj (sort keys %objs) {
47 print "$obj\n";
48 foreach my $sym (sort keys %syms) {
49 print "\t$sym\n" if ($symbols{$sym} eq $obj);