Building: make it possible to force linking with static OpenSSL libs

Very simply, support having the .a extension to denote depending on
static libraries.  Note that this is not supported on native Windows
when building shared libraries, as there is not static library then,
just an import library with the same name.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1889)
This commit is contained in:
Richard Levitte 2016-11-09 20:01:51 +01:00
parent 42e055e124
commit 186a31e510
5 changed files with 47 additions and 20 deletions

View File

@ -9,15 +9,22 @@
# there are no duplicate dependencies and that they are in the # there are no duplicate dependencies and that they are in the
# right order. This is especially used to sort the list of # right order. This is especially used to sort the list of
# libraries that a build depends on. # libraries that a build depends on.
sub extensionlesslib {
my @result = map { $_ =~ /(\.a)?$/; $` } @_;
return @result if wantarray;
return $result[0];
}
sub resolvedepends { sub resolvedepends {
my $thing = shift; my $thing = shift;
my $extensionlessthing = extensionlesslib($thing);
my @listsofar = @_; # to check if we're looping my @listsofar = @_; # to check if we're looping
my @list = @{$unified_info{depends}->{$thing}}; my @list = @{$unified_info{depends}->{$extensionlessthing}};
my @newlist = (); my @newlist = ();
if (scalar @list) { if (scalar @list) {
foreach my $item (@list) { foreach my $item (@list) {
my $extensionlessitem = extensionlesslib($item);
# It's time to break off when the dependency list starts looping # It's time to break off when the dependency list starts looping
next if grep { $_ eq $item } @listsofar; next if grep { extensionlesslib($_) eq $extensionlessitem } @listsofar;
push @newlist, $item, resolvedepends($item, @listsofar, $item); push @newlist, $item, resolvedepends($item, @listsofar, $item);
} }
} }
@ -28,8 +35,9 @@
my @newlist = (); my @newlist = ();
while (@list) { while (@list) {
my $item = shift @list; my $item = shift @list;
my $extensionlessitem = extensionlesslib($item);
push @newlist, $item push @newlist, $item
unless grep { $item eq $_ } @list; unless grep { $extensionlessitem eq extensionlesslib($_) } @list;
} }
@newlist; @newlist;
} }

View File

@ -525,6 +525,17 @@ configdata.pm : $(SRCDIR)Configure $(SRCDIR)config.com {- join(" ", @{$config{bu
use File::Basename; use File::Basename;
use File::Spec::Functions qw/abs2rel rel2abs catfile catdir/; use File::Spec::Functions qw/abs2rel rel2abs catfile catdir/;
# Helper function to figure out dependencies on libraries
# It takes a list of library names and outputs a list of dependencies
sub compute_lib_depends {
if ($disabled{shared}) {
return map { $_ =~ /\.a$/ ? $`.".OLB" : $_.".OLB" } @_;
}
return map { $_ =~ /\.a$/
? $`.".OLB"
: $unified_info{sharednames}->{$_}.".EXE" } @_;
}
sub generatesrc { sub generatesrc {
my %args = @_; my %args = @_;
my $generator = join(" ", @{$args{generator}}); my $generator = join(" ", @{$args{generator}});
@ -627,9 +638,7 @@ EOF
my $libd = dirname($lib); my $libd = dirname($lib);
my $libn = basename($lib); my $libn = basename($lib);
(my $mkdef_key = $libn) =~ s/^${osslprefix_q}lib([^0-9]*)\d*/$1/i; (my $mkdef_key = $libn) =~ s/^${osslprefix_q}lib([^0-9]*)\d*/$1/i;
my @deps = map { my @deps = compute_lib_depends(@{$args{deps}});
$disabled{shared} ? $_.".OLB"
: $unified_info{sharednames}->{$_}.".EXE"; } @{$args{deps}};
my $deps = join(", -\n\t\t", @deps); my $deps = join(", -\n\t\t", @deps);
my $shlib_target = $disabled{shared} ? "" : $target{shared_target}; my $shlib_target = $disabled{shared} ? "" : $target{shared_target};
my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : ""; my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
@ -675,9 +684,7 @@ EOF
my $libn = basename($lib); my $libn = basename($lib);
(my $libn_nolib = $libn) =~ s/^lib//; (my $libn_nolib = $libn) =~ s/^lib//;
my @objs = map { "$_.OBJ" } @{$args{objs}}; my @objs = map { "$_.OBJ" } @{$args{objs}};
my @deps = map { my @deps = compute_lib_depends(@{$args{deps}});
$disabled{shared} ? $_.".OLB"
: $unified_info{sharednames}->{$_}.".EXE"; } @{$args{deps}};
my $deps = join(", -\n\t\t", @objs, @deps); my $deps = join(", -\n\t\t", @objs, @deps);
my $shlib_target = $disabled{shared} ? "" : $target{shared_target}; my $shlib_target = $disabled{shared} ? "" : $target{shared_target};
my $engine_opt = abs2rel(rel2abs(catfile($config{sourcedir}, my $engine_opt = abs2rel(rel2abs(catfile($config{sourcedir},
@ -727,9 +734,7 @@ EOF
my $bind = dirname($bin); my $bind = dirname($bin);
my $binn = basename($bin); my $binn = basename($bin);
my @objs = map { "$_.OBJ" } @{$args{objs}}; my @objs = map { "$_.OBJ" } @{$args{objs}};
my @deps = map { my @deps = compute_lib_depends(@{$args{deps}});
$disabled{shared} ? $_.".OLB"
: $unified_info{sharednames}->{$_}.".EXE"; } @{$args{deps}};
my $deps = join(", -\n\t\t", @objs, @deps); my $deps = join(", -\n\t\t", @objs, @deps);
# The "[]" hack is because in .OPT files, each line inherits the # The "[]" hack is because in .OPT files, each line inherits the
# previous line's file spec as default, so if no directory spec # previous line's file spec as default, so if no directory spec

View File

@ -844,13 +844,13 @@ configdata.pm: $(SRCDIR)/Configure $(SRCDIR)/config {- join(" ", @{$config{build
# It takes a list of library names and outputs a list of dependencies # It takes a list of library names and outputs a list of dependencies
sub compute_lib_depends { sub compute_lib_depends {
if ($disabled{shared}) { if ($disabled{shared}) {
return map { $_.$libext } @_; return map { $_ =~ /\.a$/ ? $`.$libext : $_.$libext } @_;
} }
# Depending on shared libraries: # Depending on shared libraries:
# On Windows POSIX layers, we depend on {libname}.dll.a # On Windows POSIX layers, we depend on {libname}.dll.a
# On Unix platforms, we depend on {shlibname}.so # On Unix platforms, we depend on {shlibname}.so
return map { shlib_simple($_) } @_; return map { $_ =~ /\.a$/ ? $`.$libext : shlib_simple($_) } @_;
} }
sub generatesrc { sub generatesrc {
@ -1073,11 +1073,16 @@ EOF
my $binn = basename($bin); my $binn = basename($bin);
my $objs = join(" ", map { $_.$objext } @{$args{objs}}); my $objs = join(" ", map { $_.$objext } @{$args{objs}});
my $deps = join(" ",compute_lib_depends(@{$args{deps}})); my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
my $linklibs = join("", map { my $d = dirname($_); my $linklibs = join("", map { if ($_ =~ /\.a$/) {
my $f = basename($_); " $_";
$d = "." if $d eq $f; } else {
(my $l = $f) =~ s/^lib//; my $d = dirname($_);
" -L$d -l$l" } @{$args{deps}}); my $f = basename($_);
$d = "." if $d eq $f;
(my $l = $f) =~ s/^lib//;
" -L$d -l$l"
}
} @{$args{deps}});
my $shlib_target = $disabled{shared} ? "" : $target{shared_target}; my $shlib_target = $disabled{shared} ? "" : $target{shared_target};
my $cc = '$(CC)'; my $cc = '$(CC)';
my $cflags = '$(CFLAGS) $(BIN_CFLAGS)'; my $cflags = '$(CFLAGS) $(BIN_CFLAGS)';

View File

@ -347,8 +347,10 @@ configdata.pm: "$(SRCDIR)\Configure" {- join(" ", map { '"'.$_.'"' } @{$config{b
# It takes a list of library names and outputs a list of dependencies # It takes a list of library names and outputs a list of dependencies
sub compute_lib_depends { sub compute_lib_depends {
if ($disabled{shared}) { if ($disabled{shared}) {
return map { $_.$libext } @_; return map { $_ =~ /\.a$/ ? $`.$libext : $_.$libext } @_;
} }
die "Linking with static OpenSSL libraries is not supported in this configuration\n"
if grep /\.a$/, @_;
return map { shlib_import($_) } @_; return map { shlib_import($_) } @_;
} }

View File

@ -1856,9 +1856,16 @@ EOF
$d = cleanfile($buildd, $_, $blddir); $d = cleanfile($buildd, $_, $blddir);
} }
# Take note if the file to depend on is being renamed # Take note if the file to depend on is being renamed
# Take extra care with files ending with .a, they should
# be treated without that extension, and the extension
# should be added back after treatment.
$d =~ /(\.a)?$/;
my $e = $1 // "";
$d = $`;
if ($unified_info{rename}->{$d}) { if ($unified_info{rename}->{$d}) {
$d = $unified_info{rename}->{$d}; $d = $unified_info{rename}->{$d};
} }
$d .= $e;
$unified_info{depends}->{$ddest}->{$d} = 1; $unified_info{depends}->{$ddest}->{$d} = 1;
# If we depend on a header file or a perl module, let's make # If we depend on a header file or a perl module, let's make
# sure it can get included # sure it can get included