+my %libobjs;
+my %objdeps=();
+# Gather library definitions at object file granularity (optional)
+if ($PEROBJ) {
+ foreach my $lib (@libs ) {
+ `$ranlibPath $Directory/$lib`;
+ my $libpath = $lib;
+ $libpath =~ s/^libLLVM(.*)\.a/$1/;
+ $libpath =~ s/(.+)CodeGen$/Target\/$1/;
+ $libpath =~ s/(.+)AsmPrinter$/Target\/$1\/AsmPrinter/;
+ $libpath =~ s/(.+)AsmParser$/Target\/$1\/AsmParser/;
+ $libpath =~ s/(.+)Info$/Target\/$1\/TargetInfo/;
+ $libpath =~ s/(.+)Disassembler$/Target\/$1\/Disassembler/;
+ $libpath =~ s/SelectionDAG/CodeGen\/SelectionDAG/;
+ $libpath =~ s/^AsmPrinter/CodeGen\/AsmPrinter/;
+ $libpath =~ s/^BitReader/Bitcode\/Reader/;
+ $libpath =~ s/^BitWriter/Bitcode\/Writer/;
+ $libpath =~ s/^CppBackend/Target\/CppBackend/;
+ $libpath =~ s/^MSIL/Target\/MSIL/;
+ $libpath =~ s/^Core/IR/;
+ $libpath =~ s/^Instrumentation/Transforms\/Instrumentation/;
+ $libpath =~ s/^Interpreter/ExecutionEngine\/Interpreter/;
+ $libpath =~ s/^JIT/ExecutionEngine\/JIT/;
+ $libpath =~ s/^ScalarOpts/Transforms\/Scalar/;
+ $libpath =~ s/^TransformUtils/Transforms\/Utils/;
+ $libpath =~ s/^ipa/Analysis\/IPA/;
+ $libpath =~ s/^ipo/Transforms\/IPO/;
+ $libpath = "lib/".$libpath."/";
+ open DEFS, "$nmPath -sg $Directory/$lib|";
+ while (<DEFS>) {
+ chomp;
+ if (/^([^ ]*) in ([^ ]*)/) {
+ my $objfile = $libpath.$2;
+ $objdefs{$1} = $objfile;
+ $objdeps{$objfile} = {};
+ $libobjs{$lib}{$objfile}=1;
+# my $p = "../llvm/".$objfile;
+# $p =~ s/Support\/reg(.*).o/Support\/reg$1.c/;
+# $p =~ s/.o$/.cpp/;
+# unless (-e $p) {
+# die "$p\n"
+# }
+ }
+ }
+ close DEFS or die "nm failed";
+ }
+ foreach my $lib (@libs ) {
+ my $libpath = $lib;
+ $libpath =~ s/^libLLVM(.*)\.a/$1/;
+ $libpath =~ s/(.+)CodeGen$/Target\/$1/;
+ $libpath =~ s/(.+)AsmPrinter$/Target\/$1\/AsmPrinter/;
+ $libpath =~ s/(.+)AsmParser$/Target\/$1\/AsmParser/;
+ $libpath =~ s/(.+)Info$/Target\/$1\/TargetInfo/;
+ $libpath =~ s/(.+)Disassembler$/Target\/$1\/Disassembler/;
+ $libpath =~ s/SelectionDAG/CodeGen\/SelectionDAG/;
+ $libpath =~ s/^AsmPrinter/CodeGen\/AsmPrinter/;
+ $libpath =~ s/^BitReader/Bitcode\/Reader/;
+ $libpath =~ s/^BitWriter/Bitcode\/Writer/;
+ $libpath =~ s/^CppBackend/Target\/CppBackend/;
+ $libpath =~ s/^MSIL/Target\/MSIL/;
+ $libpath =~ s/^Core/VMCore/;
+ $libpath =~ s/^Instrumentation/Transforms\/Instrumentation/;
+ $libpath =~ s/^Interpreter/ExecutionEngine\/Interpreter/;
+ $libpath =~ s/^JIT/ExecutionEngine\/JIT/;
+ $libpath =~ s/^ScalarOpts/Transforms\/Scalar/;
+ $libpath =~ s/^TransformUtils/Transforms\/Utils/;
+ $libpath =~ s/^ipa/Analysis\/IPA/;
+ $libpath =~ s/^ipo/Transforms\/IPO/;
+ $libpath = "lib/".$libpath."/";
+ open UDEFS, "$nmPath -Aup $Directory/$lib|";
+ while (<UDEFS>) {
+ chomp;
+ if (/:([^:]+):/) {
+ my $obj = $libpath.$1;
+ s/[^ ]+: *U //;
+ if (defined($objdefs{$_})) {
+ $objdeps{$obj}{$objdefs{$_}}=1;
+ }
+ }
+ }
+ close UDEFS or die "nm failed"
+ }
+} else {