SOOT

 view release on metacpan or  search on metacpan

inc/inc_ExtUtils-CBuilder/ExtUtils/CBuilder/Base.pm  view on Meta::CPAN

package ExtUtils::CBuilder::Base;

use strict;
use File::Spec;
use File::Basename;
use Cwd ();
use Config;
use Text::ParseWords;
use IO::File;
use Data::Dumper;$Data::Dumper::Indent=1;
use IPC::Cmd qw(can_run);
use File::Temp qw(tempfile);

use vars qw($VERSION);
$VERSION = '0.280202';

# More details about C/C++ compilers:
# http://developers.sun.com/sunstudio/documentation/product/compiler.jsp
# http://gcc.gnu.org/
# http://publib.boulder.ibm.com/infocenter/comphelp/v101v121/index.jsp
# http://msdn.microsoft.com/en-us/vstudio/default.aspx

my %cc2cxx = (
    # first line order is important to support wrappers like in pkgsrc
    cc => [ 'c++', 'CC', 'aCC', 'cxx', ], # Sun Studio, HP ANSI C/C++ Compilers
    gcc => [ 'g++' ], # GNU Compiler Collection
    xlc => [ 'xlC' ], # IBM C/C++ Set, xlc without thread-safety
    xlc_r => [ 'xlC_r' ], # IBM C/C++ Set, xlc with thread-safety
    cl    => [ 'cl' ], # Microsoft Visual Studio
);

sub new {
  my $class = shift;
  my $self = bless {@_}, $class;

  $self->{properties}{perl} = $class->find_perl_interpreter
    or warn "Warning: Can't locate your perl binary";

  while (my ($k,$v) = each %Config) {
    $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}{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};

  unless ( exists $self->{config}{cxx} ) {
    my ($ccpath, $ccbase, $ccsfx ) = fileparse($self->{config}{cc}, qr/\.[^.]*/);
    foreach my $cxx (@{$cc2cxx{$ccbase}}) {
      if( can_run( File::Spec->catfile( $ccpath, $cxx, $ccsfx ) ) ) {
        $self->{config}{cxx} = File::Spec->catfile( $ccpath, $cxx, $ccsfx );
	last;
      }
      if( can_run( File::Spec->catfile( $cxx, $ccsfx ) ) ) {
        $self->{config}{cxx} = File::Spec->catfile( $cxx, $ccsfx );
	last;
      }
      if( can_run( $cxx ) ) {
        $self->{config}{cxx} = $cxx;
	last;
      }
    }
    unless ( exists $self->{config}{cxx} ) {
      $self->{config}{cxx} = $self->{config}{cc};
      my $cflags = $self->{config}{cflags};
      $self->{config}{cxxflags} = '-x c++';
      $self->{config}{cxxflags} .= " $cflags" if defined $cflags;
    }
  }

  return $self;
}

sub find_perl_interpreter {
  my $perl;
  File::Spec->file_name_is_absolute($perl = $^X)
    or -f ($perl = $Config::Config{perlpath})
    or ($perl = $^X); # XXX how about using IPC::Cmd::can_run here?
  return $perl;
}

sub add_to_cleanup {
  my $self = shift;
  foreach (@_) {
    $self->{files_to_clean}{$_} = 1;
  }
}

sub cleanup {
  my $self = shift;
  foreach my $file (keys %{$self->{files_to_clean}}) {
    unlink $file;
  }
}

sub get_config {
    return %{ $_[0]->{config} };
}

sub object_file {
  my ($self, $filename) = @_;

  # File name, minus the suffix
  (my $file_base = $filename) =~ s/\.[^.]+$//;
  return "$file_base$self->{config}{obj_ext}";



( run in 1.454 second using v1.01-cache-2.11-cpan-5735350b133 )