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]
16 while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
18 last if /^--$/; # Stop processing arguments on --
20 # List command line options here...
21 if (/^-flat$/) { $FLAT = 1; next; }
22 if (/^-why/) { $WHY = 1; $FLAT = 1; next; }
23 print "Unknown option: $_ : ignoring!\n";
26 # Give first option a name.
27 my $Directory = $ARGV[0];
28 if (!defined($Directory) || ! -d
"$Directory") {
29 die "First argument must specify the directory containing LLVM libs\n";
32 my $nmPath = $ARGV[1];
34 # Find the "dot" program
37 chomp($DotPath = `which dot`);
38 die "Can't find 'dot'" if (! -x
"$DotPath");
41 if (!defined($nmPath) || $nmPath eq "") {
42 chomp($nmPath=`which nm`);
43 die "Can't find 'nm'" if (! -x
"$nmPath");
46 # Open the directory and read its contents, sorting by name and differentiating
47 # by whether its a library (.a) or an object file (.o)
48 opendir DIR
,$Directory;
49 my @files = readdir DIR
;
51 my @libs = grep(/libLLVM.*\.a$/,sort(@files));
52 my @objs = grep(/LLVM.*\.o$/,sort(@files));
54 # Declare the hashes we will use to keep track of the library and object file
59 # Gather definitions from the libraries
60 foreach my $lib (@libs ) {
61 open DEFS
, "$nmPath -g $Directory/$lib|";
63 next if (! / [ABCDGRST] /);
64 s/^[^ ]* [ABCDGRST] //;
65 s/\015?\012//; # not sure if <DEFS> is in binmode and uses LF or CRLF.
66 # this strips both LF and CRLF.
72 # Gather definitions from the object files.
73 foreach my $obj (@objs ) {
74 open DEFS
, "$nmPath -g $Directory/$obj |";
76 next if (! / [ABCDGRST] /);
77 s/^[^ ]* [ABCDGRST] //;
78 s/\015?\012//; # not sure if <DEFS> is in binmode and uses LF or CRLF.
79 # this strips both LF and CRLF.
85 # Generate one entry in the <dl> list. This generates the <dt> and <dd> elements
86 # for one library or object file. The <dt> provides the name of the library or
87 # object. The <dd> provides a list of the libraries/objects it depends on.
91 $lib_ns =~ s/(.*)\.[oa]/$1/;
94 if ($WHY) { print "\n"; }
96 print " <dt><b>$lib</b</dt><dd><ul>\n";
99 "$nmPath -g -u $Directory/$lib | sed -e 's/^ *U //' | sort | uniq |";
104 if (defined($libdefs{$_}) && $libdefs{$_} ne $lib) {
105 $DepLibs{$libdefs{$_}} = [] unless exists $DepLibs{$libdefs{$_}};
106 push(@
{$DepLibs{$libdefs{$_}}}, $_);
107 } elsif (defined($objdefs{$_}) && $objdefs{$_} ne $lib) {
109 $libroot =~ s/lib(.*).a/$1/;
110 if ($objdefs{$_} ne "$libroot.o") {
111 $DepLibs{$objdefs{$_}} = [] unless exists $DepLibs{$objdefs{$_}};
112 push(@
{$DepLibs{$objdefs{$_}}}, $_);
117 for my $key (sort keys %DepLibs) {
122 my @syms = @
{$DepLibs{$key}};
123 foreach my $sym (@syms) {
128 print " <li>$key</li>\n";
130 my $suffix = substr($key,length($key)-1,1);
131 $key =~ s/(.*)\.[oa]/$1/;
132 if ($suffix eq "a") {
133 if (!$FLAT) { print DOT
"$lib_ns -> $key [ weight=0 ];\n" };
135 if (!$FLAT) { print DOT
"$lib_ns -> $key [ weight=10];\n" };
143 print " </ul></dd>\n";
147 # Make sure we flush on write. This is slower but correct based on the way we
148 # write I/O in gen_one_entry.
151 # Print the definition list tag
155 open DOT
, "| $DotPath -Tgif > libdeps.gif";
157 print DOT
"digraph LibDeps {\n";
158 print DOT
" size=\"40,15\"; \n";
159 print DOT
" ratio=\"1.33333\"; \n";
160 print DOT
" margin=\"0.25\"; \n";
161 print DOT
" rankdir=\"LR\"; \n";
162 print DOT
" mclimit=\"50.0\"; \n";
163 print DOT
" ordering=\"out\"; \n";
164 print DOT
" center=\"1\";\n";
165 print DOT
"node [shape=\"box\",\n";
166 print DOT
" color=\"#000088\",\n";
167 print DOT
" fillcolor=\"#FFFACD\",\n";
168 print DOT
" fontcolor=\"#3355BB\",\n";
169 print DOT
" style=\"filled\",\n";
170 print DOT
" fontname=\"sans\",\n";
171 print DOT
" fontsize=\"24\"\n";
173 print DOT
"edge [dir=\"forward\",style=\"solid\",color=\"#000088\"];\n";
176 # Print libraries first
177 foreach my $lib (@libs) {
184 open DOT
, "| $DotPath -Tgif > objdeps.gif";
185 print DOT
"digraph ObjDeps {\n";
186 print DOT
" size=\"8,10\";\n";
187 print DOT
" margin=\"0.25\";\n";
188 print DOT
" rankdir=\"LR\";\n";
189 print DOT
" mclimit=\"50.0\";\n";
190 print DOT
" ordering=\"out\";\n";
191 print DOT
" center=\"1\";\n";
192 print DOT
"node [shape=\"box\",\n";
193 print DOT
" color=\"#000088\",\n";
194 print DOT
" fillcolor=\"#FFFACD\",\n";
195 print DOT
" fontcolor=\"#3355BB\",\n";
196 print DOT
" fontname=\"sans\",\n";
197 print DOT
" style=\"filled\",\n";
198 print DOT
" fontsize=\"24\"\n";
200 print DOT
"edge [dir=\"forward\",style=\"solid\",color=\"#000088\"];\n";
203 # Print objects second
204 foreach my $obj (@objs) {
212 # Print end tag of definition list element