Commit 2a08d1a0 authored by Richard Levitte's avatar Richard Levitte
Browse files

Make it possible to specify source files that will only be used for shared libs



There are rare cases when an object file will only be used when
building a shared library.  To enable this, we introduce
SHARED_SOURCE:

    SHARED_SOURCE[libfoo]=dllmain.c

Reviewed-by: default avatarAndy Polyakov <appro@openssl.org>
parent dcdb4028
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -358,6 +358,11 @@ sense at all to just have a rename like that (why not just use
"libbar" everywhere?), it does make sense when it can be used
conditionally.  See a little further below for an example.

In some cases, it's desirable to include some source files in the
shared form of a library only:

    SHARED_SOURCE[libfoo]=dllmain.c

For any file to be built, it's also possible to tell what extra
include paths the build of their source files should use:

+4 −0
Original line number Diff line number Diff line
@@ -233,6 +233,10 @@ indexes:
               SOURCE variables, and AS source files for programs and
               libraries.

  shared_sources =>
               a hash table just like 'sources', but only as source
               files (object files) for building shared libraries.

As an example, here is how the build.info files example from the
section above would be digested into a %unified_info table:

+7 −3
Original line number Diff line number Diff line
@@ -92,9 +92,11 @@
         $OUT .= libobj2shlib(shlib => $unified_info{sharednames}->{$lib},
                              lib => $lib,
                              objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
                                        @{$unified_info{sources}->{$lib}} ],
                                        (@{$unified_info{sources}->{$lib}},
                                         @{$unified_info{shared_sources}->{$lib}}) ],
                              deps => [ reducedepends(resolvedepends($lib)) ],
                              %ordinals);
         map { doobj($_, $lib, intent => "lib") } @{$unified_info{shared_sources}->{$lib}};
     }
     $OUT .= obj2lib(lib => $lib,
                     objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
@@ -111,9 +113,11 @@
     return "" if $cache{$lib};
     $OUT .= obj2dso(lib => $lib,
                     objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
                               @{$unified_info{sources}->{$lib}} ],
                               (@{$unified_info{sources}->{$lib}},
                                @{$unified_info{shared_sources}->{$lib}}) ],
                     deps => [ resolvedepends($lib) ]);
     map { doobj($_, $lib, intent => "dso") } @{$unified_info{sources}->{$lib}};
     map { doobj($_, $lib, intent => "dso") } (@{$unified_info{sources}->{$lib}},
                                               @{$unified_info{shared_sources}->{$lib}});
     $cache{$lib} = 1;
 }

+31 −1
Original line number Diff line number Diff line
@@ -1303,6 +1303,7 @@ if ($builder eq "unified") {

        my %ordinals = ();
        my %sources = ();
        my %shared_sources = ();
        my %includes = ();
        my %depends = ();
        my %renames = ();
@@ -1382,6 +1383,9 @@ if ($builder eq "unified") {
            qr/^\s*SOURCE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
            => sub { push @{$sources{$1}}, split(/\s+/, $2)
                         if !@skip || $skip[$#skip] > 0 },
            qr/^\s*SHARED_SOURCE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
            => sub { push @{$shared_sources{$1}}, split(/\s+/, $2)
                         if !@skip || $skip[$#skip] > 0 },
            qr/^\s*INCLUDE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
            => sub { push @{$includes{$1}}, split(/\s+/, $2)
                         if !@skip || $skip[$#skip] > 0 },
@@ -1567,6 +1571,32 @@ EOF
            }
        }

        foreach (keys %shared_sources) {
            my $dest = $_;
            my $ddest = cleanfile($buildd, $_, $blddir);
            if ($unified_info{rename}->{$ddest}) {
                $ddest = $unified_info{rename}->{$ddest};
            }
            foreach (@{$shared_sources{$dest}}) {
                my $s = cleanfile($sourced, $_, $blddir);

                # If it isn't in the source tree, we assume it's generated
                # in the build tree
                if (! -f $s) {
                    $s = cleanfile($buildd, $_, $blddir);
                }
                # We recognise C and asm files
                if ($s =~ /\.[csS]\b$/) {
                    (my $o = $_) =~ s/\.[csS]\b$/.o/;
                    $o = cleanfile($buildd, $o, $blddir);
                    $unified_info{shared_sources}->{$ddest}->{$o} = 1;
                    $unified_info{sources}->{$o}->{$s} = 1;
                } else {
                    die "unrecognised source file type for shared library: $s\n";
                }
            }
        }

        foreach (keys %generate) {
            my $dest = $_;
            my $ddest = cleanfile($buildd, $_, $blddir);
@@ -1636,7 +1666,7 @@ EOF
        $unified_info{$_} = [ sort keys %{$unified_info{$_}} ];
    }
    # Two level structures
    foreach my $l1 (("sources", "ldadd", "depends")) {
    foreach my $l1 (("sources", "shared_sources", "ldadd", "depends")) {
        foreach my $l2 (sort keys %{$unified_info{$l1}}) {
            $unified_info{$l1}->{$l2} =
                [ sort keys %{$unified_info{$l1}->{$l2}} ];