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 if (!defined($Directory)) {
28 die "First argument must be the directory containing LLVM libs\n";
30 my $nmPath = $ARGV[1];
32 # Find the "dot" program
35 chomp($DotPath = `which dot`);
36 die "Can't find 'dot'" if (! -x "$DotPath");
39 if (!defined($nmPath) || $nmPath eq "") {
40 chomp($nmPath=`which nm`);
41 die "Can't find 'nm'" if (! -x "$nmPath");
44 # Open the directory and read its contents, sorting by name and differentiating
45 # by whether its a library (.a) or an object file (.o)
46 opendir DIR,$Directory;
47 my @files = readdir DIR;
49 @libs = grep(/libLLVM.*\.a$/,sort(@files));
50 @objs = grep(/LLVM.*\.o$/,sort(@files));
52 # Declare the hashes we will use to keep track of the library and object file
57 # Gather definitions from the libraries
58 foreach $lib (@libs ) {
60 "$nmPath -g $Directory/$lib | grep ' [ABCDGRST] ' | sed -e 's/^[0-9A-Fa-f]* [ABCDGRST] //' | sort | uniq |";
68 # Gather definitions from the object files.
69 foreach $obj (@objs ) {
71 "$nmPath -g $Directory/$obj | grep ' [ABCDGRST] ' | sed -e 's/^[0-9A-Fa-f]* [ABCDGRST] //' | sort | uniq |";
79 # Generate one entry in the <dl> list. This generates the <dt> and <dd> elements
80 # for one library or object file. The <dt> provides the name of the library or
81 # object. The <dd> provides a list of the libraries/objects it depends on.
85 $lib_ns =~ s/(.*)\.[oa]/$1/;
88 if ($WHY) { print "\n"; }
90 print " <dt><b>$lib</b</dt><dd><ul>\n";
93 "$nmPath -g -u $Directory/$lib | sed -e 's/^ *U //' | sort | uniq |";
98 if (defined($libdefs{$_}) && $libdefs{$_} ne $lib) {
99 $DepLibs{$libdefs{$_}} = [] unless exists $DepLibs{$libdefs{$_}};
100 push(@{$DepLibs{$libdefs{$_}}}, $_);
101 } elsif (defined($objdefs{$_}) && $objdefs{$_} ne $lib) {
103 $libroot =~ s/lib(.*).a/$1/;
104 if ($objdefs{$_} ne "$libroot.o") {
105 $DepLibs{$objdefs{$_}} = [] unless exists $DepLibs{$objdefs{$_}};
106 push(@{$DepLibs{$objdefs{$_}}}, $_);
111 for my $key (sort keys %DepLibs) {
116 my @syms = @{$DepLibs{$key}};
117 foreach $sym (@syms) {
122 print " <li>$key</li>\n";
124 $suffix = substr($key,length($key)-1,1);
125 $key =~ s/(.*)\.[oa]/$1/;
126 if ($suffix eq "a") {
127 if (!$FLAT) { print DOT "$lib_ns -> $key [ weight=0 ];\n" };
129 if (!$FLAT) { print DOT "$lib_ns -> $key [ weight=10];\n" };
137 print " </ul></dd>\n";
141 # Make sure we flush on write. This is slower but correct based on the way we
142 # write I/O in gen_one_entry.
145 # Print the definition list tag
149 open DOT, "| $DotPath -Tgif > libdeps.gif";
151 print DOT "digraph LibDeps {\n";
152 print DOT " size=\"40,15\"; \n";
153 print DOT " ratio=\"1.33333\"; \n";
154 print DOT " margin=\"0.25\"; \n";
155 print DOT " rankdir=\"LR\"; \n";
156 print DOT " mclimit=\"50.0\"; \n";
157 print DOT " ordering=\"out\"; \n";
158 print DOT " center=\"1\";\n";
159 print DOT "node [shape=\"box\",\n";
160 print DOT " color=\"#000088\",\n";
161 print DOT " fillcolor=\"#FFFACD\",\n";
162 print DOT " fontcolor=\"#3355BB\",\n";
163 print DOT " style=\"filled\",\n";
164 print DOT " fontname=\"sans\",\n";
165 print DOT " fontsize=\"24\"\n";
167 print DOT "edge [dir=\"forward\",style=\"solid\",color=\"#000088\"];\n";
170 # Print libraries first
171 foreach $lib (@libs) {
178 open DOT, "| $DotPath -Tgif > objdeps.gif";
179 print DOT "digraph ObjDeps {\n";
180 print DOT " size=\"8,10\";\n";
181 print DOT " margin=\"0.25\";\n";
182 print DOT " rankdir=\"LR\";\n";
183 print DOT " mclimit=\"50.0\";\n";
184 print DOT " ordering=\"out\";\n";
185 print DOT " center=\"1\";\n";
186 print DOT "node [shape=\"box\",\n";
187 print DOT " color=\"#000088\",\n";
188 print DOT " fillcolor=\"#FFFACD\",\n";
189 print DOT " fontcolor=\"#3355BB\",\n";
190 print DOT " fontname=\"sans\",\n";
191 print DOT " style=\"filled\",\n";
192 print DOT " fontsize=\"24\"\n";
194 print DOT "edge [dir=\"forward\",style=\"solid\",color=\"#000088\"];\n";
197 # Print objects second
198 foreach $obj (@objs) {
206 # Print end tag of definition list element