Upgrade to ExtUtils-CBuilder-0.15 (with a small edit to
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / CBuilder / Base.pm
index fb20773..4ab8378 100644 (file)
@@ -7,8 +7,7 @@ use Config;
 use Text::ParseWords;
 
 use vars qw($VERSION);
-$VERSION = '0.00_02';
-$VERSION = eval $VERSION;
+$VERSION = '0.12';
 
 sub new {
   my $class = shift;
@@ -33,7 +32,16 @@ sub find_perl_interpreter {
 
 sub add_to_cleanup {
   my $self = shift;
-  my %files = map {$_, 1} @_;
+  foreach (@_) {
+    $self->{files_to_clean}{$_} = 1;
+  }
+}
+
+sub cleanup {
+  my $self = shift;
+  foreach my $file (keys %{$self->{files_to_clean}}) {
+    unlink $file;
+  }
 }
 
 sub object_file {
@@ -66,6 +74,11 @@ sub arg_exec_file {
   return ('-o', $file);
 }
 
+sub arg_defines {
+  my ($self, %args) = @_;
+  return map "-D$_=$args{$_}", keys %args;
+}
+
 sub compile {
   my ($self, %args) = @_;
   die "Missing 'source' argument to compile()" unless defined $args{source};
@@ -78,11 +91,13 @@ sub compile {
     (@{$args{include_dirs} || []},
      $self->perl_inc());
   
+  my @defines = $self->arg_defines( %{$args{defines} || {}} );
+  
   my @extra_compiler_flags = $self->split_like_shell($args{extra_compiler_flags});
   my @cccdlflags = $self->split_like_shell($cf->{cccdlflags});
   my @ccflags = $self->split_like_shell($cf->{ccflags});
   my @optimize = $self->split_like_shell($cf->{optimize});
-  my @flags = (@include_dirs, @cccdlflags, @extra_compiler_flags,
+  my @flags = (@include_dirs, @defines, @cccdlflags, @extra_compiler_flags,
               $self->arg_nolink,
               @ccflags, @optimize,
               $self->arg_object_file($args{object_file}),
@@ -139,6 +154,8 @@ sub exe_file {
 
 sub need_prelink { 0 }
 
+sub extra_link_args_after_prelink { return }
+
 sub prelink {
   my ($self, %args) = @_;
   
@@ -153,6 +170,7 @@ sub prelink {
     NAME     => $args{dl_name},
     DLBASE   => $args{dl_base},
     FILE     => $args{dl_file},
+    VERSION  => (defined $args{dl_version} ? $args{dl_version} : '0.0'),
   );
   
   # Mksymlists will create one of these files
@@ -168,7 +186,7 @@ sub link_executable {
   my ($self, %args) = @_;
   return $self->_do_link('exe_file', lddl => 0, %args);
 }
-                                  
+
 sub _do_link {
   my ($self, $type, %args) = @_;
 
@@ -181,12 +199,16 @@ sub _do_link {
   my @temp_files;
   @temp_files =
     $self->prelink(%args,
-                  dl_name => $args{module_name}) if $self->need_prelink;
+                  dl_name => $args{module_name}) if $args{lddl} && $self->need_prelink;
   
-  my @linker_flags = $self->split_like_shell($args{extra_linker_flags});
+  my @linker_flags = ($self->split_like_shell($args{extra_linker_flags}),
+                     $self->extra_link_args_after_prelink(%args, dl_name => $args{module_name},
+                                                          prelink_res => \@temp_files));
+
   my @output = $args{lddl} ? $self->arg_share_object_file($out) : $self->arg_exec_file($out);
   my @shrp = $self->split_like_shell($cf->{shrpenv});
   my @ld = $self->split_like_shell($cf->{ld});
+  
   $self->do_system(@shrp, @ld, @output, @$objects, @linker_flags)
     or die "error building $out from @$objects";
   
@@ -216,29 +238,27 @@ sub perl_src {
   # N.B. makemaker actually searches regardless of PERL_CORE, but
   # only squawks at not finding it if PERL_CORE is set
 
-  if ($ENV{PERL_CORE}) {
-    my $Updir  = File::Spec->updir;
-    my($dir);
-    foreach $dir ($Updir,
-                  File::Spec->catdir($Updir,$Updir),
-                  File::Spec->catdir($Updir,$Updir,$Updir),
-                  File::Spec->catdir($Updir,$Updir,$Updir,$Updir),
-                  File::Spec->catdir($Updir,$Updir,$Updir,$Updir,$Updir))
-    {
-      if (
-           -f File::Spec->catfile($dir,"config_h.SH")
-           &&
-           -f File::Spec->catfile($dir,"perl.h")
-          &&
-           -f File::Spec->catfile($dir,"lib","Exporter.pm")
-        ) {
-        return $dir;
-      }
+  return unless $ENV{PERL_CORE};
+
+  my $Updir  = File::Spec->updir;
+  my $dir = $Updir;
+
+  # Try up to 5 levels upwards
+  for (1..5) {
+    if (
+       -f File::Spec->catfile($dir,"config_h.SH")
+       &&
+       -f File::Spec->catfile($dir,"perl.h")
+       &&
+       -f File::Spec->catfile($dir,"lib","Exporter.pm")
+       ) {
+      return $dir;
     }
 
-    warn "PERL_CORE is set but I can't find your perl source!\n";
+    $dir = File::Spec->catdir($dir, $Updir);
   }
-
+  
+  warn "PERL_CORE is set but I can't find your perl source!\n";
   return;
 }
 
@@ -249,4 +269,9 @@ sub perl_inc {
   $self->perl_src() || File::Spec->catdir($self->{config}{archlibexp},"CORE");
 }
 
+sub DESTROY {
+  my $self = shift;
+  $self->cleanup();
+}
+
 1;