llvm.org GIT mirror llvm / 18743f4
New flag for GenLibDeps, and llvm-config-perobjincl. This allows to show the explicit files that need to be built/linked to get an LLVM component. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95300 91177308-0d34-0410-b5e6-96231b3b80d8 Torok Edwin 10 years ago
3 changed file(s) with 187 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
5252 $(Verb) cd $(PROJ_OBJ_ROOT) ; \
5353 $(ConfigStatusScript) tools/llvm-config/llvm-config.in
5454
55 llvm-config-perobj: llvm-config.in $(GenLibDeps) $(LibDir) $(wildcard $(LibDir)/*.a)
56 $(Echo) "Generating llvm-config-perobj"
57 $(Verb) $(PERL) $(GenLibDeps) -perobj -flat $(LibDir) "$(NM_PATH)" >PerobjDeps.txt
58 $(Echo) "Checking for cyclic dependencies between LLVM objects."
59 $(Verb) $(PERL) $(PROJ_SRC_DIR)/find-cycles.pl < PerobjDepsIncl.txt > PerobjDepsInclFinal.txt || rm -f $@
60 $(Verb) $(ECHO) 's/@LLVM_CPPFLAGS@/$(subst /,\/,$(SUB_CPPFLAGS))/' \
61 > temp.sed
62 $(Verb) $(ECHO) 's/@LLVM_CFLAGS@/$(subst /,\/,$(SUB_CFLAGS))/' \
63 >> temp.sed
64 $(Verb) $(ECHO) 's/@LLVM_CXXFLAGS@/$(subst /,\/,$(SUB_CXXFLAGS))/' \
65 >> temp.sed
66 $(Verb) $(ECHO) 's/@LLVM_LDFLAGS@/$(subst /,\/,$(SUB_LDFLAGS))/' \
67 >> temp.sed
68 $(Verb) $(ECHO) 's/@LLVM_BUILDMODE@/$(subst /,\/,$(BuildMode))/' \
69 >> temp.sed
70 $(Verb) $(SED) -f temp.sed < $< > $@
71 $(Verb) $(RM) temp.sed
72 $(Verb) cat PerobjDepsFinal.txt >> $@
73 $(Verb) chmod +x $@
74
75 llvm-config-perobjincl: llvm-config.in $(GenLibDeps) $(LibDir) $(wildcard $(LibDir)/*.a)
76 $(Echo) "Generating llvm-config-perobjincl"
77 $(Verb) $(PERL) $(GenLibDeps) -perobj -perobjincl -flat $(LibDir) "$(NM_PATH)" >PerobjDepsIncl.txt
78 $(Echo) "Checking for cyclic dependencies between LLVM objects."
79 $(Verb) $(PERL) $(PROJ_SRC_DIR)/find-cycles.pl < PerobjDepsIncl.txt > PerobjDepsInclFinal.txt
80 $(Verb) $(ECHO) 's/@LLVM_CPPFLAGS@/$(subst /,\/,$(SUB_CPPFLAGS))/' \
81 > temp.sed
82 $(Verb) $(ECHO) 's/@LLVM_CFLAGS@/$(subst /,\/,$(SUB_CFLAGS))/' \
83 >> temp.sed
84 $(Verb) $(ECHO) 's/@LLVM_CXXFLAGS@/$(subst /,\/,$(SUB_CXXFLAGS))/' \
85 >> temp.sed
86 $(Verb) $(ECHO) 's/@LLVM_LDFLAGS@/$(subst /,\/,$(SUB_LDFLAGS))/' \
87 >> temp.sed
88 $(Verb) $(ECHO) 's/@LLVM_BUILDMODE@/$(subst /,\/,$(BuildMode))/' \
89 >> temp.sed
90 $(Verb) $(SED) -f temp.sed < $< > $@
91 $(Verb) $(RM) temp.sed
92 $(Verb) cat PerobjDepsInclFinal.txt >> $@
93 $(Verb) chmod +x $@
94
5595 # Build our final script.
5696 $(ToolDir)/llvm-config: llvm-config.in $(FinalLibDeps)
5797 $(Echo) "Building llvm-config script."
6161 print STDERR "find-cycles.pl: Circular dependency between *.a files:\n";
6262 print STDERR "find-cycles.pl: ", join(' ', @archives), "\n";
6363 push @modules, @archives; # WORKAROUND: Duplicate *.a files. Ick.
64 } elsif (@modules > 1) {
65 $cycles_found = $cycles_found + 1;
66 print STDERR "find-cycles.pl: Circular dependency between *.o files:\n";
67 print STDERR "find-cycles.pl: ", join(' ', @modules), "\n";
68 push @modules, @modules; # WORKAROUND: Duplicate *.o files. Ick.
6469 }
6570
6671 # Add to our output. (@modules is already as sorted as we need it to be.)
88 # Syntax: GenLibDeps.pl [-flat] [path_to_nm_binary]
99 #
1010 use strict;
11
11 use warnings;
1212 # Parse arguments...
1313 my $FLAT = 0;
1414 my $WHY = 0;
15 my $PEROBJ = 0;
16 my $PEROBJINCL = 0;
1517 while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
1618 shift;
1719 last if /^--$/; # Stop processing arguments on --
1921 # List command line options here...
2022 if (/^-flat$/) { $FLAT = 1; next; }
2123 if (/^-why/) { $WHY = 1; $FLAT = 1; next; }
24 if (/^-perobj$/) { $PEROBJ = 1; next; }
25 if (/^-perobjincl/) { $PEROBJINCL = 1; next;}
2226 print "Unknown option: $_ : ignoring!\n";
2327 }
2428
4448 if (!defined($nmPath) || $nmPath eq "") {
4549 chomp($nmPath=`which nm`);
4650 die "Can't find 'nm'" if (! -x "$nmPath");
51 }
52
53 my $ranlibPath;
54 if ($PEROBJ) {
55 $ranlibPath = $ARGV[2];
56 if (defined($ENV{RANLIB})) {
57 chomp($ranlibPath=$ENV{RANLIB});
58 }
59
60 if (!defined($ranlibPath) || $ranlibPath eq "") {
61 chomp($ranlibPath=`which ranlib`);
62 die "Can't find 'ranlib'" if (! -x "$ranlibPath");
63 }
4764 }
4865
4966 # Open the directory and read its contents, sorting by name and differentiating
5976 my %libdefs;
6077 my %objdefs;
6178
79 my %libobjs;
80 my %objdeps=();
81 # Gather library definitions at object file granularity (optional)
82 if ($PEROBJ) {
83 foreach my $lib (@libs ) {
84 `$ranlibPath $Directory/$lib`;
85 my $libpath = $lib;
86 $libpath =~ s/^libLLVM(.*)\.a/$1/;
87 $libpath =~ s/(.+)CodeGen$/Target\/$1/;
88 $libpath =~ s/(.+)AsmPrinter$/Target\/$1\/AsmPrinter/;
89 $libpath =~ s/(.+)AsmParser$/Target\/$1\/AsmParser/;
90 $libpath =~ s/(.+)Info$/Target\/$1\/TargetInfo/;
91 $libpath =~ s/(.+)Disassembler$/Target\/$1\/Disassembler/;
92 $libpath =~ s/SelectionDAG/CodeGen\/SelectionDAG/;
93 $libpath =~ s/^AsmPrinter/CodeGen\/AsmPrinter/;
94 $libpath =~ s/^BitReader/Bitcode\/Reader/;
95 $libpath =~ s/^BitWriter/Bitcode\/Writer/;
96 $libpath =~ s/^CBackend/Target\/CBackend/;
97 $libpath =~ s/^CppBackend/Target\/CppBackend/;
98 $libpath =~ s/^MSIL/Target\/MSIL/;
99 $libpath =~ s/^Core/VMCore/;
100 $libpath =~ s/^Instrumentation/Transforms\/Instrumentation/;
101 $libpath =~ s/^Interpreter/ExecutionEngine\/Interpreter/;
102 $libpath =~ s/^JIT/ExecutionEngine\/JIT/;
103 $libpath =~ s/^ScalarOpts/Transforms\/Scalar/;
104 $libpath =~ s/^TransformUtils/Transforms\/Utils/;
105 $libpath =~ s/^ipa/Analysis\/IPA/;
106 $libpath =~ s/^ipo/Transforms\/IPO/;
107 $libpath =~ s/^pic16passes/Target\/PIC16\/PIC16Passes/;
108 $libpath = "lib/".$libpath."/";
109 open DEFS, "$nmPath -sg $Directory/$lib|";
110 while () {
111 chomp;
112 if (/^([^ ]*) in ([^ ]*)/) {
113 my $objfile = $libpath.$2;
114 $objdefs{$1} = $objfile;
115 $objdeps{$objfile} = {};
116 $libobjs{$lib}{$objfile}=1;
117 # my $p = "../llvm/".$objfile;
118 # $p =~ s/Support\/reg(.*).o/Support\/reg$1.c/;
119 # $p =~ s/.o$/.cpp/;
120 # unless (-e $p) {
121 # die "$p\n"
122 # }
123 }
124 }
125 close DEFS or die "nm failed";
126 }
127 foreach my $lib (@libs ) {
128 my $libpath = $lib;
129 $libpath =~ s/^libLLVM(.*)\.a/$1/;
130 $libpath =~ s/(.+)CodeGen$/Target\/$1/;
131 $libpath =~ s/(.+)AsmPrinter$/Target\/$1\/AsmPrinter/;
132 $libpath =~ s/(.+)AsmParser$/Target\/$1\/AsmParser/;
133 $libpath =~ s/(.+)Info$/Target\/$1\/TargetInfo/;
134 $libpath =~ s/(.+)Disassembler$/Target\/$1\/Disassembler/;
135 $libpath =~ s/SelectionDAG/CodeGen\/SelectionDAG/;
136 $libpath =~ s/^AsmPrinter/CodeGen\/AsmPrinter/;
137 $libpath =~ s/^BitReader/Bitcode\/Reader/;
138 $libpath =~ s/^BitWriter/Bitcode\/Writer/;
139 $libpath =~ s/^CBackend/Target\/CBackend/;
140 $libpath =~ s/^CppBackend/Target\/CppBackend/;
141 $libpath =~ s/^MSIL/Target\/MSIL/;
142 $libpath =~ s/^Core/VMCore/;
143 $libpath =~ s/^Instrumentation/Transforms\/Instrumentation/;
144 $libpath =~ s/^Interpreter/ExecutionEngine\/Interpreter/;
145 $libpath =~ s/^JIT/ExecutionEngine\/JIT/;
146 $libpath =~ s/^ScalarOpts/Transforms\/Scalar/;
147 $libpath =~ s/^TransformUtils/Transforms\/Utils/;
148 $libpath =~ s/^ipa/Analysis\/IPA/;
149 $libpath =~ s/^ipo/Transforms\/IPO/;
150 $libpath =~ s/^pic16passes/Target\/PIC16\/PIC16Passes/;
151 $libpath = "lib/".$libpath."/";
152 open UDEFS, "$nmPath -Aup $Directory/$lib|";
153 while () {
154 chomp;
155 if (/:([^:]+):/) {
156 my $obj = $libpath.$1;
157 s/[^ ]+: *U //;
158 if (defined($objdefs{$_})) {
159 $objdeps{$obj}{$objdefs{$_}}=1;
160 }
161 }
162 }
163 close UDEFS or die "nm failed"
164 }
165 } else {
62166 # Gather definitions from the libraries
63167 foreach my $lib (@libs ) {
64168 open DEFS, "$nmPath -g $Directory/$lib|";
70174 $libdefs{$_} = $lib;
71175 }
72176 close DEFS or die "nm failed";
177 }
73178 }
74179
75180 # Gather definitions from the object files.
108213 $DepLibs{$libdefs{$_}} = [] unless exists $DepLibs{$libdefs{$_}};
109214 push(@{$DepLibs{$libdefs{$_}}}, $_);
110215 } elsif (defined($objdefs{$_}) && $objdefs{$_} ne $lib) {
216 if ($PEROBJ && !$PEROBJINCL) {
217 # -perobjincl makes .a files depend on .o files they contain themselves
218 # default is don't depend on these.
219 next if defined $libobjs{$lib}{$objdefs{$_}};
220 }
111221 my $libroot = $lib;
112222 $libroot =~ s/lib(.*).a/$1/;
113223 if ($objdefs{$_} ne "$libroot.o") {
142252 }
143253 }
144254 close UNDEFS or die "nm failed";
255 }
256 if ($PEROBJINCL) {
257 # include the .a's objects
258 for my $obj (keys %{$libobjs{$lib}}) {
259 $DepLibs{$obj} = ["<.a object>"] unless exists $DepLibs{$obj};
260 }
261 my $madechange = 1;
262 while($madechange) {
263 $madechange = 0;
264 my %temp = %DepLibs;
265 foreach my $obj (keys %DepLibs) {
266 foreach my $objdeps (keys %{$objdeps{$obj}}) {
267 next if defined $temp{$objdeps};
268 push(@{$temp{$objdeps}}, $obj);
269 $madechange = 1;
270 }
271 }
272 %DepLibs = %temp;
273 }
145274 }
146275
147276 for my $key (sort keys %DepLibs) {
206335 # Print libraries first
207336 foreach my $lib (@libs) {
208337 gen_one_entry($lib);
338 }
339
340 if ($PEROBJ) {
341 foreach my $obj (keys %objdeps) {
342 print "$obj:";
343 if (!$PEROBJINCL) {
344 foreach my $dep (keys %{$objdeps{$obj}}) {
345 print " $dep";
346 }
347 }
348 print "\n";
349 }
209350 }
210351
211352 if (!$FLAT) {