Skip to content

Commit

Permalink
Append CFLAGS and LDFLAGS to their Config.pm counterparts in EU::CBui…
Browse files Browse the repository at this point in the history
…lder

Since ExtUtils::CBuilder 0.27_04 (bleadperl commit 06e8058),
CFLAGS and LDFLAGS from the environment have overridden the Config.pm
ccflags and ldflags settings. This can cause binary incompatibilities
between the core Perl and extensions built with EU::CBuilder.

Append to the Config.pm values rather than overriding them.
  • Loading branch information
ntyni authored and Father Chrysostomos committed May 19, 2011
1 parent fbebf34 commit 011e8fb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
6 changes: 4 additions & 2 deletions dist/ExtUtils-CBuilder/lib/ExtUtils/CBuilder/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ sub new {
$self->{config}{$k} = $v unless exists $self->{config}{$k};
}
$self->{config}{cc} = $ENV{CC} if defined $ENV{CC};
$self->{config}{ccflags} = $ENV{CFLAGS} if defined $ENV{CFLAGS};
$self->{config}{ccflags} = join(" ", $self->{config}{ccflags}, $ENV{CFLAGS})
if defined $ENV{CFLAGS};
$self->{config}{cxx} = $ENV{CXX} if defined $ENV{CXX};
$self->{config}{cxxflags} = $ENV{CXXFLAGS} if defined $ENV{CXXFLAGS};
$self->{config}{ld} = $ENV{LD} if defined $ENV{LD};
$self->{config}{ldflags} = $ENV{LDFLAGS} if defined $ENV{LDFLAGS};
$self->{config}{ldflags} = join(" ", $self->{config}{ldflags}, $ENV{LDFLAGS})
if defined $ENV{LDFLAGS};

unless ( exists $self->{config}{cxx} ) {
my ($ccpath, $ccbase, $ccsfx ) = fileparse($self->{config}{cc}, qr/\.[^.]*/);
Expand Down
25 changes: 24 additions & 1 deletion dist/ExtUtils-CBuilder/t/04-base.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! perl -w

use strict;
use Test::More tests => 50;
use Test::More tests => 64;
use Config;
use Cwd;
use File::Path qw( mkpath );
Expand Down Expand Up @@ -328,6 +328,29 @@ is_deeply( $mksymlists_args,
"_prepare_mksymlists_args(): got expected arguments for Mksymlists",
);

my %testvars = (
CFLAGS => 'ccflags',
LDFLAGS => 'ldflags',
);

while (my ($VAR, $var) = each %testvars) {
local $ENV{$VAR};
$base = ExtUtils::CBuilder::Base->new( quiet => 1 );
ok( $base, "ExtUtils::CBuilder::Base->new() returned true value" );
isa_ok( $base, 'ExtUtils::CBuilder::Base' );
like($base->{config}{$var}, qr/\Q$Config{$var}/,
"honours $var from Config.pm");

$ENV{$VAR} = "-foo -bar";
$base = ExtUtils::CBuilder::Base->new( quiet => 1 );
ok( $base, "ExtUtils::CBuilder::Base->new() returned true value" );
isa_ok( $base, 'ExtUtils::CBuilder::Base' );
like($base->{config}{$var}, qr/\Q$ENV{$VAR}/,
"honours $VAR from the environment");
like($base->{config}{$var}, qr/\Q$Config{$var}/,
"doesn't override $var from Config.pm with $VAR from the environment");
}

#####

for ($source_file, $object_file, $lib_file) {
Expand Down

0 comments on commit 011e8fb

Please sign in to comment.