From 2a08d1a05db937f8b1a62422b78ffe2fa07d3ead Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Tue, 29 Mar 2016 16:45:03 +0200 Subject: [PATCH] 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: Andy Polyakov --- Configurations/README | 5 +++++ Configurations/README.design | 4 ++++ Configurations/common.tmpl | 10 +++++++--- Configure | 32 +++++++++++++++++++++++++++++++- 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/Configurations/README b/Configurations/README index a4c156762c..a5a006e46a 100644 --- a/Configurations/README +++ b/Configurations/README @@ -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: diff --git a/Configurations/README.design b/Configurations/README.design index 5065960a76..574982fb5a 100644 --- a/Configurations/README.design +++ b/Configurations/README.design @@ -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: diff --git a/Configurations/common.tmpl b/Configurations/common.tmpl index d89817efd2..9c80070ea6 100644 --- a/Configurations/common.tmpl +++ b/Configurations/common.tmpl @@ -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; } diff --git a/Configure b/Configure index d8064d1564..b4afea950e 100755 --- a/Configure +++ b/Configure @@ -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}} ];