+
+ my %attrs = %{$unified_info{attributes}->{libraries}->{$lib}};
+
+ my @deps = ( resolvedepends(getsrclibs('sources', $lib)) );
+
+ # We support two types of objs, those who are specific to this library
+ # (they end up in @objs) and those that we get indirectly, via other
+ # libraries (they end up in @foreign_objs). We get the latter any time
+ # someone has done something like this in build.info:
+ # SOURCE[libfoo.a]=libbar.a
+ # The indirect object files must be kept in a separate array so they
+ # don't get rebuilt unnecessarily (and with incorrect auxiliary
+ # information).
+ #
+ # Object files can't be collected commonly for shared and static
+ # libraries, because we contain their respective object files in
+ # {shared_sources} and {sources}, and because the implications are
+ # slightly different for each library form.
+ #
+ # We grab all these "foreign" object files recursively with getlibobjs().
+
+ unless ($disabled{shared} || $lib =~ /\.a$/) {
+ my $obj2shlib = defined &obj2shlib ? \&obj2shlib : \&libobj2shlib;
+ # If this library sources other static libraries and those
+ # libraries are marked {noinst}, there's no need to include
+ # all of their object files. Instead, we treat those static
+ # libraries as dependents alongside any other library this
+ # one depends on, and let symbol resolution do its job.
+ my @sourced_libs = ();
+ my @objs = ();
+ my @foreign_objs = ();
+ my @deps = ();
+ foreach (@{$unified_info{shared_sources}->{$lib}}) {
+ if ($_ !~ m|\.a$|) {
+ push @objs, $_;
+ } elsif ($unified_info{attributes}->{libraries}->{$_}->{noinst}) {
+ push @deps, $_;
+ } else {
+ push @deps, getsrclibs('sources', $_);
+ push @foreign_objs, getlibobjs('sources', $_);
+ }
+ }
+ @deps = ( grep { $_ ne $lib } resolvedepends($lib, @deps) );
+ print STDERR "DEBUG[dolib:shlib] \%attrs for $lib : ", ,
+ join(",", map { "\n $_ = $attrs{$_}" } sort keys %attrs), "\n"
+ if %attrs && $debug_rules;
+ print STDERR "DEBUG[dolib:shlib] \@deps for $lib : ",
+ join(",", map { "\n $_" } @deps), "\n"
+ if @deps && $debug_rules;
+ print STDERR "DEBUG[dolib:shlib] \@objs for $lib : ",
+ join(",", map { "\n $_" } @objs), "\n"
+ if @objs && $debug_rules;
+ print STDERR "DEBUG[dolib:shlib] \@foreign_objs for $lib : ",
+ join(",", map { "\n $_" } @foreign_objs), "\n"
+ if @foreign_objs && $debug_rules;
+ $OUT .= $obj2shlib->(lib => $lib,
+ attrs => { %attrs },
+ objs => [ @objs, @foreign_objs ],
+ deps => [ @deps ]);
+ foreach (@objs) {
+ # If this is somehow a compiled object, take care of it that way
+ # Otherwise, it might simply be generated
+ if (defined $unified_info{sources}->{$_}) {
+ if($_ =~ /\.a$/) {
+ dolib($_);
+ } else {
+ doobj($_, $lib, intent => "shlib", attrs => { %attrs });
+ }
+ } else {
+ dogenerate($_, undef, undef, intent => "lib");
+ }
+ }
+ }
+ {
+ # When putting static libraries together, we cannot rely on any
+ # symbol resolution, so for all static libraries used as source for
+ # this one, as well as other libraries they depend on, we simply
+ # grab all their object files unconditionally,
+ # Symbol resolution will happen when any program, module or shared
+ # library is linked with this one.
+ my @objs = ();
+ my @sourcedeps = ();
+ my @foreign_objs = ();
+ foreach (@{$unified_info{sources}->{$lib}}) {
+ if ($_ !~ m|\.a$|) {
+ push @objs, $_;
+ } else {
+ push @sourcedeps, $_;
+ }
+ }
+ @sourcedeps = ( grep { $_ ne $lib } resolvedepends(@sourcedeps) );
+ print STDERR "DEBUG[dolib:lib] : \@sourcedeps for $_ : ",
+ join(",", map { "\n $_" } @sourcedeps), "\n"
+ if @sourcedeps && $debug_rules;
+ @foreign_objs = getlibobjs('sources', @sourcedeps);
+ print STDERR "DEBUG[dolib:lib] \%attrs for $lib : ", ,
+ join(",", map { "\n $_ = $attrs{$_}" } sort keys %attrs), "\n"
+ if %attrs && $debug_rules;
+ print STDERR "DEBUG[dolib:lib] \@objs for $lib : ",
+ join(",", map { "\n $_" } @objs), "\n"
+ if @objs && $debug_rules;
+ print STDERR "DEBUG[dolib:lib] \@foreign_objs for $lib : ",
+ join(",", map { "\n $_" } @foreign_objs), "\n"
+ if @foreign_objs && $debug_rules;
+ $OUT .= obj2lib(lib => $lib, attrs => { %attrs },
+ objs => [ @objs, @foreign_objs ]);
+ foreach (@objs) {
+ doobj($_, $lib, intent => "lib", attrs => { %attrs });
+ }