Debian Codegraph @

pTk/fakeld

raw
1 #!/usr/local/bin/perl -w
2
3 use strict;
4
5 my %ref;
6 my %def;
7 my %file;
8 my %where;
9 my %need;
10
11 sub read_object
12 {
13 my $obj = shift;
14 open(NM,"nm -p $obj|") || die "Cannot open nm $obj:$!";
15 $def{$obj} = {};
16 $file{$obj} = {};
17 my @refs = ();
18 while (<NM>)
19 {
20 if (/\b([A-Z])\b\s*_?(.*)$/)
21 {
22 my ($kind,$name) = ($1,$2);
23 $file{$obj}{$name} = $kind;
24 if ($kind ne 'U')
25 {
26 $def{$obj}{$name} = $kind;
27 $where{$name} = [] unless (exists $where{$name});
28 push(@{$where{$name}},$obj);
29 }
30 else
31 {
32 $ref{$name} = [] unless (exists $ref{$name});
33 push(@{$ref{$name}},$obj);
34 push(@refs,$name);
35 }
36 }
37 }
38 close(NM);
39 return $need{$obj} = \@refs;
40 }
41
42 warn "Scanning object files\n";
43 foreach my $obj (<*.o>,<../*.o>)
44 {
45 # next if $obj =~ /_f\.o$/;
46 read_object($obj);
47 }
48
49 my %inc;
50
51 warn "Analysing...\n";
52
53 sub process
54 {
55 my $file = shift;
56 $inc{$file} = 1;
57 if (exists $need{$file})
58 {
59 foreach my $sym (@{$need{$file}})
60 {
61 if (exists $where{$sym})
62 {
63 print "$file need $sym ",join(' ',@{$where{$sym}}),"\n";
64 if (@{$where{$sym}} > 1)
65 {
66 # warn "Multiply defined $sym\n";
67 }
68 else
69 {
70 my $inc = $where{$sym}->[0];
71 unless (exists $inc{$inc})
72 {
73 process($inc);
74 }
75 }
76 }
77 }
78 }
79 }
80
81 foreach my $file (@ARGV)
82 {
83 process($file);
84 }