Skip to content
This repository has been archived by the owner on Mar 7, 2019. It is now read-only.

create a config.site file for autoconf #113

Merged
merged 2 commits into from Mar 13, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 53 additions & 7 deletions lib/Alien/Base/ModuleBuild.pm
Expand Up @@ -24,6 +24,8 @@ use Env qw( @PATH );
use Shell::Guess;
use Shell::Config::Generate;
use File::Path qw/mkpath/;
use Config;
use Text::ParseWords qw( shellwords );

use Alien::Base::PkgConfig;
use Alien::Base::ModuleBuild::Cabinet;
Expand Down Expand Up @@ -593,6 +595,21 @@ sub alien_detect_blib_scheme {
# Build Methods #
###################

sub _shell_config_generate
{
my $scg = Shell::Config::Generate->new;
$scg->comment(
'this script sets the environment needed to build this package.',
'generated by: ' . __FILE__,
);
$scg;
}

sub _filter_defines
{
join ' ', grep !/^-D/, shellwords($_[0]);
}

sub _env_do_system {
my $self = shift;
my $command = shift;
Expand All @@ -603,6 +620,8 @@ sub _env_do_system {
$self->alien_bin_requires->{'Alien::MSYS'} ||= 0
}

my $config;

foreach my $mod (keys %{ $self->alien_bin_requires }) {
my $version = $self->alien_bin_requires->{$mod};
eval qq{ use $mod $version () }; # should also work for version = 0
Expand All @@ -627,12 +646,40 @@ sub _env_do_system {
# add anything else to start of PATH
unshift @PATH, sort keys %path;

my $config = Shell::Config::Generate->new;
$config->comment(
'this script sets the environment needed to build this package.',
'generated by: ' . __FILE__,
);
$config ||= _shell_config_generate();
$config->prepend_path( PATH => sort keys %path );
}

local $ENV{CONFIG_SITE} = $ENV{CONFIG_SITE};

# If we are using autoconf, then create a site.config file
# that specifies the same compiler and compiler linker flags
# as were used for building Perl. This is helpful for
# mixed 32/64bit platforms where 32bit is the default but
# Perl is 64bit.
if($self->config_data('autoconf') && !defined $ENV{CONFIG_SITE}) {

local $CWD;
pop @CWD;

open my $fh, '>', 'config.site';
print $fh "CC='$Config{cc}'\n";
# -D define flags should be stripped because they are Perl
# specific.
print $fh "CFLAGS='", _filter_defines($Config{ccflags}), "'\n";
print $fh "CPPFLAGS='", _filter_defines($Config{cppflags}), "'\n";
print $fh "CXXFLAGS='", _filter_defines($Config{ccflags}), "'\n";
print $fh "LDFLAGS='$Config{ldflags}'\n";
close $fh;

my $config ||= _shell_config_generate();
my $config_site = File::Spec->catfile($CWD, 'config.site');
$config_site =~ s{\\}{/}g if $^O eq 'MSWin32';
$config->set( CONFIG_SITE => $config_site );
$ENV{CONFIG_SITE} = $config_site;
}

if($config) {
if($^O eq 'MSWin32') {
local $CWD;
pop @CWD;
Expand All @@ -645,9 +692,8 @@ sub _env_do_system {
$config->generate_file( Shell::Guess->bourne_shell, 'env.sh' );
$config->generate_file( Shell::Guess->c_shell, 'env.csh' );
}

}

$self->do_system( ref($command) ? @$command : $command );
}

Expand Down