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) || ! -d "$Directory") {
28 die "First argument must specify the directory containing LLVM libs\n";
31 my $nmPath = $ARGV[1];
33 # Find the "dot" program
36 chomp($DotPath = `which dot`);
37 die "Can't find 'dot'" if (! -x "$DotPath");
40 if (!defined($nmPath) || $nmPath eq "") {
41 chomp($nmPath=`which nm`);
42 die "Can't find 'nm'" if (! -x "$nmPath");
45 # Open the directory and read its contents, sorting by name and differentiating
46 # by whether its a library (.a) or an object file (.o)
47 opendir DIR,$Directory;
48 my @files = readdir DIR;
50 @libs = grep(/libLLVM.*\.a$/,sort(@files));
51 @objs = grep(/LLVM.*\.o$/,sort(@files));
53 # Declare the hashes we will use to keep track of the library and object file
58 # Gather definitions from the libraries
59 foreach $lib (@libs ) {
61 "$nmPath -g $Directory/$lib | grep ' [ABCDGRST] ' | sed -e 's/^[0-9A-Fa-f]* [ABCDGRST] //' | sort | uniq |";
69 # Gather definitions from the object files.
70 foreach $obj (@objs ) {
72 "$nmPath -g $Directory/$obj | grep ' [ABCDGRST] ' | sed -e 's/^[0-9A-Fa-f]* [ABCDGRST] //' | sort | uniq |";
80 # Generate one entry in the <dl> list. This generates the <dt> and <dd> elements
81 # for one library or object file. The <dt> provides the name of the library or
82 # object. The <dd> provides a list of the libraries/objects it depends on.
86 $lib_ns =~ s/(.*)\.[oa]/$1/;
89 if ($WHY) { print "\n"; }
91 print " <dt><b>$lib</b</dt><dd><ul>\n";
94 "$nmPath -g -u $Directory/$lib | sed -e 's/^ *U //' | sort | uniq |";
99 if (defined($libdefs{$_}) && $libdefs{$_} ne $lib) {
100 $DepLibs{$libdefs{$_}} = [] unless exists $DepLibs{$libdefs{$_}};
101 push(@{$DepLibs{$libdefs{$_}}}, $_);
102 } elsif (defined($objdefs{$_}) && $objdefs{$_} ne $lib) {
104 $libroot =~ s/lib(.*).a/$1/;
105 if ($objdefs{$_} ne "$libroot.o") {
106 $DepLibs{$objdefs{$_}} = [] unless exists $DepLibs{$objdefs{$_}};
107 push(@{$DepLibs{$objdefs{$_}}}, $_);
112 for my $key (sort keys %DepLibs) {
117 my @syms = @{$DepLibs{$key}};
118 foreach $sym (@syms) {
123 print " <li>$key</li>\n";
125 $suffix = substr($key,length($key)-1,1);
126 $key =~ s/(.*)\.[oa]/$1/;
127 if ($suffix eq "a") {
128 if (!$FLAT) { print DOT "$lib_ns -> $key [ weight=0 ];\n" };
130 if (!$FLAT) { print DOT "$lib_ns -> $key [ weight=10];\n" };
138 print " </ul></dd>\n";
142 # Make sure we flush on write. This is slower but correct based on the way we
143 # write I/O in gen_one_entry.
146 # Print the definition list tag
150 open DOT, "| $DotPath -Tgif > libdeps.gif";
152 print DOT "digraph LibDeps {\n";
153 print DOT " size=\"40,15\"; \n";
154 print DOT " ratio=\"1.33333\"; \n";
155 print DOT " margin=\"0.25\"; \n";
156 print DOT " rankdir=\"LR\"; \n";
157 print DOT " mclimit=\"50.0\"; \n";
158 print DOT " ordering=\"out\"; \n";
159 print DOT " center=\"1\";\n";
160 print DOT "node [shape=\"box\",\n";
161 print DOT " color=\"#000088\",\n";
162 print DOT " fillcolor=\"#FFFACD\",\n";
163 print DOT " fontcolor=\"#3355BB\",\n";
164 print DOT " style=\"filled\",\n";
165 print DOT " fontname=\"sans\",\n";
166 print DOT " fontsize=\"24\"\n";
168 print DOT "edge [dir=\"forward\",style=\"solid\",color=\"#000088\"];\n";
171 # Print libraries first
172 foreach $lib (@libs) {
179 open DOT, "| $DotPath -Tgif > objdeps.gif";
180 print DOT "digraph ObjDeps {\n";
181 print DOT " size=\"8,10\";\n";
182 print DOT " margin=\"0.25\";\n";
183 print DOT " rankdir=\"LR\";\n";
184 print DOT " mclimit=\"50.0\";\n";
185 print DOT " ordering=\"out\";\n";
186 print DOT " center=\"1\";\n";
187 print DOT "node [shape=\"box\",\n";
188 print DOT " color=\"#000088\",\n";
189 print DOT " fillcolor=\"#FFFACD\",\n";
190 print DOT " fontcolor=\"#3355BB\",\n";
191 print DOT " fontname=\"sans\",\n";
192 print DOT " style=\"filled\",\n";
193 print DOT " fontsize=\"24\"\n";
195 print DOT "edge [dir=\"forward\",style=\"solid\",color=\"#000088\"];\n";
198 # Print objects second
199 foreach $obj (@objs) {
207 # Print end tag of definition list element