提交 33105818 编写于 作者: R Richard Levitte

Make it possible to build static-only libraries

The trick is to use the .a extension explicitely in the build.info files.
Reviewed-by: NRich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3243)
上级 a68d3505
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
my $thing = shift; my $thing = shift;
my $extensionlessthing = extensionlesslib($thing); 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}->{$extensionlessthing}}; my @list = @{$unified_info{depends}->{$thing} //
$unified_info{depends}->{$extensionlessthing}};
my @newlist = (); my @newlist = ();
if (scalar @list) { if (scalar @list) {
foreach my $item (@list) { foreach my $item (@list) {
...@@ -33,13 +34,22 @@ ...@@ -33,13 +34,22 @@
sub reducedepends { sub reducedepends {
my @list = @_; my @list = @_;
my @newlist = (); my @newlist = ();
my %replace = ();
while (@list) { while (@list) {
my $item = shift @list; my $item = shift @list;
my $extensionlessitem = extensionlesslib($item); my $extensionlessitem = extensionlesslib($item);
push @newlist, $item if (grep { $extensionlessitem eq extensionlesslib($_) } @list) {
unless grep { $extensionlessitem eq extensionlesslib($_) } @list; if ($item ne $extensionlessitem) {
# If this instance of the library is explicitely static, we
# prefer that to any shared library name, since it must have
# been done on purpose.
$replace{$extensionlessitem} = $item;
}
} else {
push @newlist, $item;
}
} }
@newlist; map { $replace{$_} // $_; } @newlist;
} }
# is_installed checks if a given file will be installed (i.e. they are # is_installed checks if a given file will be installed (i.e. they are
...@@ -113,7 +123,7 @@ ...@@ -113,7 +123,7 @@
sub dolib { sub dolib {
my $lib = shift; my $lib = shift;
return "" if $cache{$lib}; return "" if $cache{$lib};
unless ($disabled{shared}) { unless ($disabled{shared} || $lib =~ /\.a$/) {
my %ordinals = my %ordinals =
$unified_info{ordinals}->{$lib} $unified_info{ordinals}->{$lib}
? (ordinals => $unified_info{ordinals}->{$lib}) : (); ? (ordinals => $unified_info{ordinals}->{$lib}) : ();
......
...@@ -42,8 +42,18 @@ ...@@ -42,8 +42,18 @@
# Because we need to make two computations of these data, # Because we need to make two computations of these data,
# we store them in arrays for reuse # we store them in arrays for reuse
our @shlibs = map { $unified_info{sharednames}->{$_} || () } @{$unified_info{libraries}}; our @libs =
our @install_shlibs = map { $unified_info{sharednames}->{$_} || () } @{$unified_info{install}->{libraries}}; map { (my $x = $_) =~ s/\.a$//; $x }
@{$unified_info{libraries}};
our @shlibs =
map { $unified_info{sharednames}->{$_} || () }
grep(!/\.a$/, @{$unified_info{libraries}});
our @install_libs =
map { (my $x = $_) =~ s/\.a$//; $x }
@{$unified_info{install}->{libraries}};
our @install_shlibs =
map { $unified_info{sharednames}->{$_} || () }
grep(!/\.a$/, @{$unified_info{install}->{libraries}});
our @generated = ( ( map { (my $x = $_) =~ s|\.S$|\.s|; $x } our @generated = ( ( map { (my $x = $_) =~ s|\.S$|\.s|; $x }
grep { defined $unified_info{generate}->{$_} } grep { defined $unified_info{generate}->{$_} }
map { @{$unified_info{sources}->{$_}} } map { @{$unified_info{sources}->{$_}} }
...@@ -113,7 +123,7 @@ SHLIB_EXT=.EXE ...@@ -113,7 +123,7 @@ SHLIB_EXT=.EXE
OBJ_EXT=.OBJ OBJ_EXT=.OBJ
DEP_EXT=.D DEP_EXT=.D
LIBS={- join(", ", map { "-\n\t".$_.".OLB" } @{$unified_info{libraries}}) -} LIBS={- join(", ", map { "-\n\t".$_.".OLB" } @libs) -}
SHLIBS={- join(", ", map { "-\n\t".$_.".EXE" } @shlibs) -} SHLIBS={- join(", ", map { "-\n\t".$_.".EXE" } @shlibs) -}
ENGINES={- join(", ", map { "-\n\t".$_.".EXE" } @{$unified_info{engines}}) -} ENGINES={- join(", ", map { "-\n\t".$_.".EXE" } @{$unified_info{engines}}) -}
PROGRAMS={- join(", ", map { "-\n\t".$_.".EXE" } @{$unified_info{programs}}) -} PROGRAMS={- join(", ", map { "-\n\t".$_.".EXE" } @{$unified_info{programs}}) -}
...@@ -127,7 +137,7 @@ DEPS={- our @deps = map { (my $x = $_) =~ s|\.o$|\$(DEP_EXT)|; $x; } ...@@ -127,7 +137,7 @@ DEPS={- our @deps = map { (my $x = $_) =~ s|\.o$|\$(DEP_EXT)|; $x; }
GENERATED_MANDATORY={- join(", ", map { "-\n\t".$_ } @{$unified_info{depends}->{""}} ) -} GENERATED_MANDATORY={- join(", ", map { "-\n\t".$_ } @{$unified_info{depends}->{""}} ) -}
GENERATED={- join(", ", map { "-\n\t".$_ } @generated) -} GENERATED={- join(", ", map { "-\n\t".$_ } @generated) -}
INSTALL_LIBS={- join(", ", map { "-\n\t".$_.".OLB" } @{$unified_info{install}->{libraries}}) -} INSTALL_LIBS={- join(", ", map { "-\n\t".$_.".OLB" } @install_libs) -}
INSTALL_SHLIBS={- join(", ", map { "-\n\t".$_.".EXE" } @install_shlibs) -} INSTALL_SHLIBS={- join(", ", map { "-\n\t".$_.".EXE" } @install_shlibs) -}
INSTALL_ENGINES={- join(", ", map { "-\n\t".$_.".EXE" } @{$unified_info{install}->{engines}}) -} INSTALL_ENGINES={- join(", ", map { "-\n\t".$_.".EXE" } @{$unified_info{install}->{engines}}) -}
INSTALL_PROGRAMS={- join(", ", map { "-\n\t".$_.".EXE" } @{$unified_info{install}->{programs}}) -} INSTALL_PROGRAMS={- join(", ", map { "-\n\t".$_.".EXE" } @{$unified_info{install}->{programs}}) -}
...@@ -230,10 +240,10 @@ NODEBUG=@ ...@@ -230,10 +240,10 @@ NODEBUG=@
$(NODEBUG) ! Set up logical names for the libraries, so LINK and $(NODEBUG) ! Set up logical names for the libraries, so LINK and
$(NODEBUG) ! running programs can use them. $(NODEBUG) ! running programs can use them.
$(NODEBUG) ! $(NODEBUG) !
$(NODEBUG) {- join("\n\t\$(NODEBUG) ", map { "DEFINE ".uc($_)." 'F\$ENV(\"DEFAULT\")'".uc($_)."\$(SHLIB_EXT)" } map { $unified_info{sharednames}->{$_} || () } @{$unified_info{libraries}}) || "!" -} $(NODEBUG) {- join("\n\t\$(NODEBUG) ", map { "DEFINE ".uc($_)." 'F\$ENV(\"DEFAULT\")'".uc($_)."\$(SHLIB_EXT)" } @shlibs) || "!" -}
.LAST : .LAST :
$(NODEBUG) {- join("\n\t\$(NODEBUG) ", map { "DEASSIGN ".uc($_) } map { $unified_info{sharednames}->{$_} || () } @{$unified_info{libraries}}) || "!" -} $(NODEBUG) {- join("\n\t\$(NODEBUG) ", map { "DEASSIGN ".uc($_) } @shlibs) || "!" -}
$(NODEBUG) DEASSIGN ossl_dataroot $(NODEBUG) DEASSIGN ossl_dataroot
$(NODEBUG) DEASSIGN ossl_installroot $(NODEBUG) DEASSIGN ossl_installroot
$(NODEBUG) DEASSIGN internal $(NODEBUG) DEASSIGN internal
...@@ -317,7 +327,7 @@ uninstall : uninstall_docs uninstall_sw ...@@ -317,7 +327,7 @@ uninstall : uninstall_docs uninstall_sw
# Because VMS wants the generation number (or *) to delete files, we can't # Because VMS wants the generation number (or *) to delete files, we can't
# use $(LIBS), $(PROGRAMS), $(GENERATED) and $(ENGINES)directly. # use $(LIBS), $(PROGRAMS), $(GENERATED) and $(ENGINES)directly.
libclean : libclean :
{- join("\n\t", map { "- DELETE $_.OLB;*" } @{$unified_info{libraries}}) || "@ !" -} {- join("\n\t", map { "- DELETE $_.OLB;*" } @libs) || "@ !" -}
{- join("\n\t", map { "- DELETE $_.EXE;*,$_.MAP;*,$_.OPT;*" } @shlibs) || "@ !" -} {- join("\n\t", map { "- DELETE $_.EXE;*,$_.MAP;*,$_.OPT;*" } @shlibs) || "@ !" -}
clean : libclean clean : libclean
...@@ -407,7 +417,7 @@ _install_dev_ns : check_INSTALLTOP ...@@ -407,7 +417,7 @@ _install_dev_ns : check_INSTALLTOP
- CREATE/DIR ossl_installroot:[LIB.'arch'] - CREATE/DIR ossl_installroot:[LIB.'arch']
{- join("\n ", {- join("\n ",
map { "COPY/PROT=W:R $_.OLB ossl_installroot:[LIB.'arch']" } map { "COPY/PROT=W:R $_.OLB ossl_installroot:[LIB.'arch']" }
@{$unified_info{install}->{libraries}}) -} @install_libs) -}
install_dev : install_shared _install_dev_ns install_dev : install_shared _install_dev_ns
...@@ -729,7 +739,7 @@ EOF ...@@ -729,7 +739,7 @@ EOF
} }
sub obj2lib { sub obj2lib {
my %args = @_; my %args = @_;
my $lib = $args{lib}; (my $lib = $args{lib}) =~ s/\.a$//;
my $objs = join(", -\n\t\t", map { $_.".OBJ" } (@{$args{objs}})); my $objs = join(", -\n\t\t", map { $_.".OBJ" } (@{$args{objs}}));
my $fill_lib = join("\n\t", (map { "LIBRARY/REPLACE $lib.OLB $_.OBJ" } my $fill_lib = join("\n\t", (map { "LIBRARY/REPLACE $lib.OLB $_.OBJ" }
@{$args{objs}})); @{$args{objs}}));
......
...@@ -38,20 +38,26 @@ ...@@ -38,20 +38,26 @@
# removed. On some systems, they may therefore return the exact same # removed. On some systems, they may therefore return the exact same
# string. # string.
sub shlib { sub shlib {
return () if $disabled{shared};
my $lib = shift; my $lib = shift;
return () if $disabled{shared} || $lib =~ /\.a$/;
return $unified_info{sharednames}->{$lib} . $shlibext; return $unified_info{sharednames}->{$lib} . $shlibext;
} }
sub shlib_simple { sub shlib_simple {
return () if $disabled{shared};
my $lib = shift; my $lib = shift;
return () if $disabled{shared} || $lib =~ /\.a$/;
if (windowsdll()) { if (windowsdll()) {
return $lib . $shlibextimport; return $lib . $shlibextimport;
} }
return $lib . $shlibextsimple; return $lib . $shlibextsimple;
} }
# Easy fixing of static library names
sub lib {
(my $lib = shift) =~ s/\.a$//;
return $lib . $libext;
}
# dso is a complement to shlib / shlib_simple that returns the # dso is a complement to shlib / shlib_simple that returns the
# given libname with the simple shared extension (possible SO version # given libname with the simple shared extension (possible SO version
# removed). This differs from shlib_simple() by being unconditional. # removed). This differs from shlib_simple() by being unconditional.
...@@ -84,7 +90,7 @@ SHLIB_MAJOR={- $config{shlib_major} -} ...@@ -84,7 +90,7 @@ SHLIB_MAJOR={- $config{shlib_major} -}
SHLIB_MINOR={- $config{shlib_minor} -} SHLIB_MINOR={- $config{shlib_minor} -}
SHLIB_TARGET={- $target{shared_target} -} SHLIB_TARGET={- $target{shared_target} -}
LIBS={- join(" ", map { $_.$libext } @{$unified_info{libraries}}) -} LIBS={- join(" ", map { lib($_) } @{$unified_info{libraries}}) -}
SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{libraries}}) -} SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{libraries}}) -}
SHLIB_INFO={- join(" ", map { "\"".shlib($_).";".shlib_simple($_)."\"" } @{$unified_info{libraries}}) -} SHLIB_INFO={- join(" ", map { "\"".shlib($_).";".shlib_simple($_)."\"" } @{$unified_info{libraries}}) -}
ENGINES={- join(" ", map { dso($_) } @{$unified_info{engines}}) -} ENGINES={- join(" ", map { dso($_) } @{$unified_info{engines}}) -}
...@@ -103,7 +109,7 @@ GENERATED={- join(" ", ...@@ -103,7 +109,7 @@ GENERATED={- join(" ",
grep { /\.o$/ } keys %{$unified_info{sources}} ), grep { /\.o$/ } keys %{$unified_info{sources}} ),
( grep { /\.h$/ } keys %{$unified_info{generate}} )) -} ( grep { /\.h$/ } keys %{$unified_info{generate}} )) -}
INSTALL_LIBS={- join(" ", map { $_.$libext } @{$unified_info{install}->{libraries}}) -} INSTALL_LIBS={- join(" ", map { lib($_) } @{$unified_info{install}->{libraries}}) -}
INSTALL_SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{install}->{libraries}}) -} INSTALL_SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{install}->{libraries}}) -}
INSTALL_SHLIB_INFO={- join(" ", map { "\"".shlib($_).";".shlib_simple($_)."\"" } @{$unified_info{install}->{libraries}}) -} INSTALL_SHLIB_INFO={- join(" ", map { "\"".shlib($_).";".shlib_simple($_)."\"" } @{$unified_info{install}->{libraries}}) -}
INSTALL_ENGINES={- join(" ", map { dso($_) } @{$unified_info{install}->{engines}}) -} INSTALL_ENGINES={- join(" ", map { dso($_) } @{$unified_info{install}->{engines}}) -}
...@@ -769,7 +775,7 @@ configdata.pm: $(SRCDIR)/Configure $(SRCDIR)/config {- join(" ", @{$config{build ...@@ -769,7 +775,7 @@ 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 { $_ =~ /\.a$/ ? $`.$libext : $_.$libext } @_; return map { lib($_) } @_;
} }
# Depending on shared libraries: # Depending on shared libraries:
...@@ -983,7 +989,7 @@ EOF ...@@ -983,7 +989,7 @@ EOF
} }
sub obj2lib { sub obj2lib {
my %args = @_; my %args = @_;
my $lib = $args{lib}; (my $lib = $args{lib}) =~ s/\.a$//;
my $objs = join(" ", map { $_.$objext } @{$args{objs}}); my $objs = join(" ", map { $_.$objext } @{$args{objs}});
return <<"EOF"; return <<"EOF";
$lib$libext: $objs $lib$libext: $objs
......
...@@ -31,14 +31,20 @@ ...@@ -31,14 +31,20 @@
$win_commonroot = $ENV{$win_commonroot}; $win_commonroot = $ENV{$win_commonroot};
sub shlib { sub shlib {
return () if $disabled{shared};
my $lib = shift; my $lib = shift;
return () if $disabled{shared} || $lib =~ /\.a$/;
return () unless defined $unified_info{sharednames}->{$lib};
return $unified_info{sharednames}->{$lib} . $shlibext; return $unified_info{sharednames}->{$lib} . $shlibext;
} }
sub lib {
(my $lib = shift) =~ s/\.a$//;
return $lib . $libext;
}
sub shlib_import { sub shlib_import {
return () if $disabled{shared};
my $lib = shift; my $lib = shift;
return () if $disabled{shared} || $lib =~ /\.a$/;
return $lib . $shlibextimport; return $lib . $shlibextimport;
} }
...@@ -67,7 +73,7 @@ MINOR={- $config{minor} -} ...@@ -67,7 +73,7 @@ MINOR={- $config{minor} -}
SHLIB_VERSION_NUMBER={- $config{shlib_version_number} -} SHLIB_VERSION_NUMBER={- $config{shlib_version_number} -}
LIBS={- join(" ", map { $_.$libext } @{$unified_info{libraries}}) -} LIBS={- join(" ", map { lib($_) } @{$unified_info{libraries}}) -}
SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{libraries}}) -} SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{libraries}}) -}
SHLIBPDBS={- join(" ", map { local $shlibext = ".pdb"; shlib($_) } @{$unified_info{libraries}}) -} SHLIBPDBS={- join(" ", map { local $shlibext = ".pdb"; shlib($_) } @{$unified_info{libraries}}) -}
ENGINES={- join(" ", map { dso($_) } @{$unified_info{engines}}) -} ENGINES={- join(" ", map { dso($_) } @{$unified_info{engines}}) -}
...@@ -88,7 +94,7 @@ GENERATED={- join(" ", ...@@ -88,7 +94,7 @@ GENERATED={- join(" ",
grep { /\.o$/ } keys %{$unified_info{sources}} ), grep { /\.o$/ } keys %{$unified_info{sources}} ),
( grep { /\.h$/ } keys %{$unified_info{generate}} )) -} ( grep { /\.h$/ } keys %{$unified_info{generate}} )) -}
INSTALL_LIBS={- join(" ", map { $_.$libext } @{$unified_info{install}->{libraries}}) -} INSTALL_LIBS={- join(" ", map { lib($_) } @{$unified_info{install}->{libraries}}) -}
INSTALL_SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{install}->{libraries}}) -} INSTALL_SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{install}->{libraries}}) -}
INSTALL_SHLIBPDBS={- join(" ", map { local $shlibext = ".pdb"; shlib($_) } @{$unified_info{install}->{libraries}}) -} INSTALL_SHLIBPDBS={- join(" ", map { local $shlibext = ".pdb"; shlib($_) } @{$unified_info{install}->{libraries}}) -}
INSTALL_ENGINES={- join(" ", map { dso($_) } @{$unified_info{install}->{engines}}) -} INSTALL_ENGINES={- join(" ", map { dso($_) } @{$unified_info{install}->{engines}}) -}
...@@ -352,11 +358,14 @@ configdata.pm: "$(SRCDIR)\Configure" {- join(" ", map { '"'.$_.'"' } @{$config{b ...@@ -352,11 +358,14 @@ 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 { $_ =~ /\.a$/ ? $`.$libext : $_.$libext } @_; return map { lib($_) } @_;
} }
die "Linking with static OpenSSL libraries is not supported in this configuration\n" foreach (@_) {
if grep /\.a$/, @_; (my $l = $_) =~ s/\.a$//;
return map { shlib_import($_) } @_; die "Linking with static variants of shared libraries is not supported in this configuration\n"
if $l ne $_ && shlib($l);
}
return map { shlib_import($_) or lib($_) } @_;
} }
sub generatesrc { sub generatesrc {
...@@ -530,13 +539,15 @@ $objs$linklibs \$(EX_LIBS) ...@@ -530,13 +539,15 @@ $objs$linklibs \$(EX_LIBS)
EOF EOF
} }
sub obj2lib { sub obj2lib {
my %args = @_;
my $lib = $args{lib};
# Because static libs and import libs are both named the same in native # Because static libs and import libs are both named the same in native
# Windows, we can't have both. We skip the static lib in that case, # Windows, we can't have both. We skip the static lib in that case,
# as the shared libs are what we use anyway. # as the shared libs are what we use anyway.
return "" unless $disabled{"shared"}; return "" unless $disabled{"shared"} || $lib =~ /\.a$/;
my %args = @_; $lib =~ s/\.a$//;
my $lib = $args{lib};
my $objs = join("\n", map { $_.$objext } @{$args{objs}}); my $objs = join("\n", map { $_.$objext } @{$args{objs}});
my $deps = join(" ", map { $_.$objext } @{$args{objs}}); my $deps = join(" ", map { $_.$objext } @{$args{objs}});
return <<"EOF"; return <<"EOF";
......
...@@ -1732,12 +1732,24 @@ EOF ...@@ -1732,12 +1732,24 @@ EOF
} }
# Additionally, we set up sharednames for libraries that don't # Additionally, we set up sharednames for libraries that don't
# have any, as themselves. # have any, as themselves. Only for libraries that aren't
foreach (keys %{$unified_info{libraries}}) { # explicitely static.
foreach (grep !/\.a$/, keys %{$unified_info{libraries}}) {
if (!defined $unified_info{sharednames}->{$_}) { if (!defined $unified_info{sharednames}->{$_}) {
$unified_info{sharednames}->{$_} = $_ $unified_info{sharednames}->{$_} = $_
} }
} }
# Check that we haven't defined any library as both shared and
# explicitely static. That is forbidden.
my @doubles = ();
foreach (grep /\.a$/, keys %{$unified_info{libraries}}) {
(my $l = $_) =~ s/\.a$//;
push @doubles, $l if defined $unified_info{sharednames}->{$l};
}
die "these libraries are both explicitely static and shared:\n ",
join(" ", @doubles), "\n"
if @doubles;
} }
foreach (keys %ordinals) { foreach (keys %ordinals) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册