3 # Program: GenLibDeps.pl
5 # Synopsis: Generate HTML output that shows the dependencies between a set of
6 # libraries. The output of this script should periodically replace
7 # the similar content in the UsingLibraries.html document.
9 # Syntax: GenLibDeps.pl [-flat] <directory_with_libraries_in_it> [path_to_nm_binary]
15 while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
17 last if /^--$/; # Stop processing arguments on --
19 # List command line options here...
20 if (/^-flat$/) { $FLAT = 1; next; }
21 if (/^-why/) { $WHY = 1; $FLAT = 1; next; }
22 print "Unknown option: $_ : ignoring!\n";
25 # Give first option a name.
26 my $Directory = $ARGV[0];
27 my $nmPath = $ARGV[1];
29 # Find the "dot" program
32 chomp($DotPath = `which dot`);
33 die "Can't find 'dot'" if (! -x "$DotPath");
37 chomp($nmPath=`which nm`);
38 die "Can't find 'nm'" if (! -x "$nmPath");
41 # Open the directory and read its contents, sorting by name and differentiating
42 # by whether its a library (.a) or an object file (.o)
43 opendir DIR,$Directory;
44 my @files = readdir DIR;
46 @libs = grep(/libLLVM.*\.a$/,sort(@files));
47 @objs = grep(/LLVM.*\.o$/,sort(@files));
49 # Declare the hashes we will use to keep track of the library and object file
54 # Gather definitions from the libraries
55 foreach $lib (@libs ) {
57 "$nmPath -g $Directory/$lib | grep ' [ABCDGRST] ' | sed -e 's/^[0-9A-Fa-f]* [ABCDGRST] //' | sort | uniq |";
65 # Gather definitions from the object files.
66 foreach $obj (@objs ) {
68 "$nmPath -g $Directory/$obj | grep ' [ABCDGRST] ' | sed -e 's/^[0-9A-Fa-f]* [ABCDGRST] //' | sort | uniq |";
76 # Generate one entry in the <dl> list. This generates the <dt> and <dd> elements
77 # for one library or object file. The <dt> provides the name of the library or
78 # object. The <dd> provides a list of the libraries/objects it depends on.
82 $lib_ns =~ s/(.*)\.[oa]/$1/;
85 if ($WHY) { print "\n"; }
87 print " <dt><b>$lib</b</dt><dd><ul>\n";
90 "$nmPath -g -u $Directory/$lib | sed -e 's/^ *U //' | sort | uniq |";
95 if (defined($libdefs{$_}) && $libdefs{$_} ne $lib) {
96 $DepLibs{$libdefs{$_}} = [] unless exists $DepLibs{$libdefs{$_}};
97 push(@{$DepLibs{$libdefs{$_}}}, $_);
98 } elsif (defined($objdefs{$_}) && $objdefs{$_} ne $lib) {
100 $libroot =~ s/lib(.*).a/$1/;
101 if ($objdefs{$_} ne "$libroot.o") {
102 $DepLibs{$objdefs{$_}} = [] unless exists $DepLibs{$objdefs{$_}};
103 push(@{$DepLibs{$objdefs{$_}}}, $_);
108 for my $key (sort keys %DepLibs) {
113 my @syms = @{$DepLibs{$key}};
114 foreach $sym (@syms) {
119 print " <li>$key</li>\n";
121 $suffix = substr($key,length($key)-1,1);
122 $key =~ s/(.*)\.[oa]/$1/;
123 if ($suffix eq "a") {
124 if (!$FLAT) { print DOT "$lib_ns -> $key [ weight=0 ];\n" };
126 if (!$FLAT) { print DOT "$lib_ns -> $key [ weight=10];\n" };
134 print " </ul></dd>\n";
138 # Make sure we flush on write. This is slower but correct based on the way we
139 # write I/O in gen_one_entry.
142 # Print the definition list tag
146 open DOT, "| $DotPath -Tgif > libdeps.gif";
148 print DOT "digraph LibDeps {size=\"40,15\"; ratio=\"1.33333\"; margin=\"0.25\"; rankdir=\"LR\"; mclimit=\"50.0\"; ordering=\"out\"; center=\"1\";\n";
149 print DOT "node [shape=\"box\",color=\"#000088\",fillcolor=\"#FFFACD\",fontcolor=\"#5577DD\",style=\"filled\",fontsize=\"24\"];\n";
150 print DOT "edge [style=\"solid\",color=\"#000088\"];\n";
153 # Print libraries first
154 foreach $lib (@libs) {
161 open DOT, "| $DotPath -Tgif > objdeps.gif";
162 print DOT "digraph ObjDeps {size=\"40,15\"; ratio=\"1.33333\"; margin=\"0.25\"; rankdir=\"LR\"; mclimit=\"50.0\"; ordering=\"out\"; center=\"1\";\n";
163 print DOT "node [shape=\"box\",color=\"#000088\",fillcolor=\"#FFFACD\",fontcolor=\"#5577DD\",style=\"filled\",fontsize=\"24\"];\n";
164 print DOT "edge [style=\"solid\",color=\"#000088\"];\n";
167 # Print objects second
168 foreach $obj (@objs) {
176 # Print end tag of definition list element