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>
13 while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
15 last if /^--$/; # Stop processing arguments on --
17 # List command line options here...
18 if (/^-flat$/) { $FLAT = 1; next; }
19 print "Unknown option: $_ : ignoring!\n";
22 # Give first option a name.
23 my $Directory = $ARGV[0];
25 # Find the "dot" program
28 chomp($DotPath = `which dot`);
29 die "Can't find 'dot'" if (! -x "$DotPath");
32 chomp(my $nmPath=`which nm`);
33 die "Can't find 'nm'" if (! -x "$nmPath");
35 # Open the directory and read its contents, sorting by name and differentiating
36 # by whether its a library (.a) or an object file (.o)
37 opendir DIR,$Directory;
38 my @files = readdir DIR;
40 @libs = grep(/libLLVM.*\.a$/,sort(@files));
41 @objs = grep(/LLVM.*\.o$/,sort(@files));
43 # Declare the hashes we will use to keep track of the library and object file
48 # Gather definitions from the libraries
49 foreach $lib (@libs ) {
51 "$nmPath -g $Directory/$lib | grep ' [ABCDGRST] ' | sed -e 's/^[0-9A-Fa-f]* [ABCDGRST] //' | sort | uniq |";
59 # Gather definitions from the object files.
60 foreach $obj (@objs ) {
62 "$nmPath -g $Directory/$obj | grep ' [ABCDGRST] ' | sed -e 's/^[0-9A-Fa-f]* [ABCDGRST] //' | sort | uniq |";
70 # Generate one entry in the <dl> list. This generates the <dt> and <dd> elements
71 # for one library or object file. The <dt> provides the name of the library or
72 # object. The <dd> provides a list of the libraries/objects it depends on.
76 $lib_ns =~ s/(.*)\.[oa]/$1/;
80 print " <dt><b>$lib</b</dt><dd><ul>\n";
83 "$nmPath -g -u $Directory/$lib | sed -e 's/^ *U //' | sort | uniq |";
85 "| sort | uniq > GenLibDeps.out";
88 if (defined($libdefs{$_}) && $libdefs{$_} ne $lib) {
89 print DEPENDS "$libdefs{$_}\n";
90 } elsif (defined($objdefs{$_}) && $objdefs{$_} ne $lib) {
92 $libroot =~ s/lib(.*).a/$1/;
93 if ($objdefs{$_} ne "$libroot.o") {
94 print DEPENDS "$objdefs{$_}\n";
100 open DF, "<GenLibDeps.out";
106 print " <li>$_</li>\n";
108 $suffix = substr($_,length($_)-1,1);
109 $_ =~ s/(.*)\.[oa]/$1/;
110 if ($suffix eq "a") {
111 if (!$FLAT) { print DOT "$lib_ns -> $_ [ weight=0 ];\n" };
113 if (!$FLAT) { print DOT "$lib_ns -> $_ [ weight=10];\n" };
120 print " </ul></dd>\n";
124 # Make sure we flush on write. This is slower but correct based on the way we
125 # write I/O in gen_one_entry.
128 # Print the definition list tag
132 open DOT, "| $DotPath -Tgif > libdeps.gif";
134 print DOT "digraph LibDeps {size=\"40,15\"; ratio=\"1.33333\"; margin=\"0.25\"; rankdir=\"LR\"; mclimit=\"50.0\"; ordering=\"out\"; center=\"1\";\n";
135 print DOT "node [shape=\"box\",color=\"#000088\",fillcolor=\"#FFFACD\",fontcolor=\"#5577DD\",style=\"filled\",fontsize=\"24\"];\n";
136 print DOT "edge [style=\"solid\",color=\"#000088\"];\n";
139 # Print libraries first
140 foreach $lib (@libs) {
147 open DOT, "| $DotPath -Tgif > objdeps.gif";
148 print DOT "digraph ObjDeps {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 objects second
154 foreach $obj (@objs) {
162 # Print end tag of definition list element