use -whole-archive linker flag when linking a shared library with static

libraries
This commit is contained in:
steven 2008-10-28 09:58:55 +00:00
parent 21f540029a
commit 0dba86f80d

View File

@ -1,5 +1,5 @@
#!/usr/bin/perl
# $OpenBSD: libtool,v 1.27 2008/10/27 10:34:18 steven Exp $
# $OpenBSD: libtool,v 1.28 2008/10/28 09:58:55 steven Exp $
# Copyright (c) 2007-2008 Steven Mestdagh <steven@openbsd.org>
#
@ -1070,22 +1070,29 @@ sub linkcmds
create_symlinks($ltdir, \@libfiles);
map { $_ = "$ltdir/". basename $_ } @libfiles;
print "symlinks to libfiles used for linking: @libfiles\n" if $D;
my $prev_was_archive = 0;
my $libcounter = 0;
foreach my $k (@finalorderedlibs) {
my $a = $libs{$k};
if ($a =~ m/\.a$/) {
# don't make a -lfoo out of a static library
if ($lmode == LIBRARY) {
# extract objects from archive
my $libfile = basename $a;
my $xdir = "$odir/$ltdir/${la}x/$libfile";
extract_archive($xdir, $a);
my @kobjs = get_objlist_from_archive($a);
map { $_ = "$xdir/$_"; } @kobjs;
push @libflags, @kobjs;
} elsif ($lmode == PROGRAM) {
push @libflags, $a;
if (!$prev_was_archive) {
push @libflags, '-Wl,-whole-archive';
}
}
push @libflags, $a;
if ($lmode == LIBRARY) {
if ($libcounter == @finalorderedlibs - 1) {
push @libflags, '-Wl,-no-whole-archive';
}
}
$prev_was_archive = 1;
} else {
if ($prev_was_archive) {
push @libflags, '-Wl,-no-whole-archive';
}
$prev_was_archive = 0;
my $lib = basename $a;
if ($lib =~ m/^lib(.*)\.so(\.\d+){2}/) {
$lib = $1;
@ -1095,6 +1102,7 @@ sub linkcmds
}
push @libflags, "-l$lib";
}
$libcounter++;
}
$cmd = "$ltprog";