Upgrade to ExtUtils-MakeMaker-6.50
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / MM_Unix.pm
index 9d792a8..a997b1f 100644 (file)
@@ -1,48 +1,45 @@
 package ExtUtils::MM_Unix;
 
-require 5.005_03;  # Maybe further back, dunno
+require 5.006;
 
 use strict;
 
-use Exporter ();
 use Carp;
 use ExtUtils::MakeMaker::Config;
 use File::Basename qw(basename dirname);
 use DirHandle;
 
-use vars qw($VERSION @ISA
-            $Is_OS2 $Is_VMS $Is_Win32 $Is_Dos
-            $Is_OSF $Is_IRIX  $Is_NetBSD $Is_BSD
-            $Is_SunOS4 $Is_Solaris $Is_SunOS $Is_Interix
-            $Verbose %pm
-            %Config_Override
-           );
+our %Config_Override;
 
 use ExtUtils::MakeMaker qw($Verbose neatvalue);
 
-$VERSION = '1.50';
+# If we make $VERSION an our variable parse_version() breaks
+use vars qw($VERSION);
+$VERSION = '6.50';
 
 require ExtUtils::MM_Any;
-@ISA = qw(ExtUtils::MM_Any);
+our @ISA = qw(ExtUtils::MM_Any);
 
+my %Is;
 BEGIN { 
-    $Is_OS2     = $^O eq 'os2';
-    $Is_Win32   = $^O eq 'MSWin32' || $Config{osname} eq 'NetWare';
-    $Is_Dos     = $^O eq 'dos';
-    $Is_VMS     = $^O eq 'VMS';
-    $Is_OSF     = $^O eq 'dec_osf';
-    $Is_IRIX    = $^O eq 'irix';
-    $Is_NetBSD  = $^O eq 'netbsd';
-    $Is_Interix = $^O eq 'interix';
-    $Is_SunOS4  = $^O eq 'sunos';
-    $Is_Solaris = $^O eq 'solaris';
-    $Is_SunOS   = $Is_SunOS4 || $Is_Solaris;
-    $Is_BSD     = $^O =~ /^(?:free|net|open)bsd$/ or
-                  $^O eq 'bsdos' or $^O eq 'interix';
+    $Is{OS2}     = $^O eq 'os2';
+    $Is{Win32}   = $^O eq 'MSWin32' || $Config{osname} eq 'NetWare';
+    $Is{Dos}     = $^O eq 'dos';
+    $Is{VMS}     = $^O eq 'VMS';
+    $Is{OSF}     = $^O eq 'dec_osf';
+    $Is{IRIX}    = $^O eq 'irix';
+    $Is{NetBSD}  = $^O eq 'netbsd';
+    $Is{Interix} = $^O eq 'interix';
+    $Is{SunOS4}  = $^O eq 'sunos';
+    $Is{Solaris} = $^O eq 'solaris';
+    $Is{SunOS}   = $Is{SunOS4} || $Is{Solaris};
+    $Is{BSD}     = ($^O =~ /^(?:free|net|open)bsd$/ or
+                   grep( $^O eq $_, qw(bsdos interix dragonfly) )
+                  );
 }
 
 BEGIN {
-    if( $Is_VMS ) {
+    if( $Is{VMS} ) {
         # For things like vmsify()
         require VMS::Filespec;
         VMS::Filespec->import;
@@ -131,37 +128,42 @@ sub c_o {
     my($self) = shift;
     return '' unless $self->needs_linking();
     my(@m);
+    
+    my $command = '$(CCCMD)';
+    my $flags   = '$(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE)';
+    
     if (my $cpp = $Config{cpprun}) {
         my $cpp_cmd = $self->const_cccmd;
         $cpp_cmd =~ s/^CCCMD\s*=\s*\$\(CC\)/$cpp/;
-        push @m, '
+        push @m, qq{
 .c.i:
-       '. $cpp_cmd . ' $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.c > $*.i
-';
+       $cpp_cmd $flags \$*.c > \$*.i
+};
     }
-    push @m, '
+
+    push @m, qq{
 .c.s:
-       $(CCCMD) -S $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.c
-';
-    push @m, '
-.c$(OBJ_EXT):
-       $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.c
-';
-    push @m, '
-.C$(OBJ_EXT):
-       $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.C
-' if !$Is_OS2 and !$Is_Win32 and !$Is_Dos; #Case-specific
-    push @m, '
-.cpp$(OBJ_EXT):
-       $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.cpp
+       $command -S $flags \$*.c
 
-.cxx$(OBJ_EXT):
-       $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.cxx
+.c\$(OBJ_EXT):
+       $command $flags \$*.c
 
-.cc$(OBJ_EXT):
-       $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.cc
-';
-    join "", @m;
+.cpp\$(OBJ_EXT):
+       $command $flags \$*.cpp
+
+.cxx\$(OBJ_EXT):
+       $command $flags \$*.cxx
+
+.cc\$(OBJ_EXT):
+       $command $flags \$*.cc
+};
+
+    push @m, qq{
+.C\$(OBJ_EXT):
+       $command \$*.C
+} if !$Is{OS2} and !$Is{Win32} and !$Is{Dos}; #Case-specific
+
+    return join "", @m;
 }
 
 =item cflags (o)
@@ -227,8 +229,7 @@ sub cflags {
          echo perltype=\$perltype
          echo optdebug=\$optdebug
          `;
-       my($line);
-       foreach $line (@o){
+       foreach my $line (@o){
            chomp $line;
            if ($line =~ /(.*?)=\s*(.*)\s*$/){
                $cflags{$1} = $2;
@@ -304,16 +305,19 @@ sub const_config {
 # --- Constants Sections ---
 
     my($self) = shift;
-    my(@m,$m);
-    push(@m,"\n# These definitions are from config.sh (via $INC{'Config.pm'})\n");
-    push(@m,"\n# They may have been overridden via Makefile.PL or on the command line\n");
+    my @m = <<"END";
+
+# These definitions are from config.sh (via $INC{'Config.pm'}).
+# They may have been overridden via Makefile.PL or on the command line.
+END
+
     my(%once_only);
-    foreach $m (@{$self->{CONFIG}}){
-       # SITE*EXP macros are defined in &constants; avoid duplicates here
-       next if $once_only{$m};
-       $self->{uc $m} = quote_paren($self->{uc $m});
-       push @m, uc($m) , ' = ' , $self->{uc $m}, "\n";
-       $once_only{$m} = 1;
+    foreach my $key (@{$self->{CONFIG}}){
+        # SITE*EXP macros are defined in &constants; avoid duplicates here
+        next if $once_only{$key};
+        $self->{uc $key} = quote_paren($self->{uc $key});
+        push @m, uc($key) , ' = ' , $self->{uc $key}, "\n";
+        $once_only{$key} = 1;
     }
     join('', @m);
 }
@@ -334,19 +338,18 @@ sub const_loadlibs {
 # See ExtUtils::Liblist for details
 #
 };
-    my($tmp);
-    for $tmp (qw/
-        EXTRALIBS LDLOADLIBS BSLOADLIBS
-        /) {
-       next unless defined $self->{$tmp};
-       push @m, "$tmp = $self->{$tmp}\n";
+    for my $tmp (qw/
+         EXTRALIBS LDLOADLIBS BSLOADLIBS
+         /) {
+        next unless defined $self->{$tmp};
+        push @m, "$tmp = $self->{$tmp}\n";
     }
     # don't set LD_RUN_PATH if empty
-    for $tmp (qw/
-        LD_RUN_PATH
-        /) {
-       next unless $self->{$tmp};
-       push @m, "$tmp = $self->{$tmp}\n";
+    for my $tmp (qw/
+         LD_RUN_PATH
+         /) {
+        next unless $self->{$tmp};
+        push @m, "$tmp = $self->{$tmp}\n";
     }
     return join "", @m;
 }
@@ -374,7 +377,7 @@ sub constants {
               INST_ARCHLIB INST_SCRIPT INST_BIN INST_LIB
               INST_MAN1DIR INST_MAN3DIR
               MAN1EXT      MAN3EXT
-              INSTALLDIRS INSTALLBASE DESTDIR PREFIX
+              INSTALLDIRS INSTALL_BASE DESTDIR PREFIX
               PERLPREFIX      SITEPREFIX      VENDORPREFIX
                    ),
                    (map { ("INSTALL".$_,
@@ -634,7 +637,7 @@ manifest :
        $(PERLRUN) "-MExtUtils::Manifest=mkmanifest" -e mkmanifest
 
 veryclean : realclean
-       $(RM_F) *~ *.orig */*~ */*.orig
+       $(RM_F) *~ */*~ *.orig */*.orig *.bak */*.bak *.old */*.old 
 
 MAKE_FRAG
 
@@ -854,7 +857,7 @@ sub dynamic_bs {
 BOOTSTRAP =
 ' unless $self->has_link_code();
 
-    my $target = $Is_VMS ? '$(MMS$TARGET)' : '$@';
+    my $target = $Is{VMS} ? '$(MMS$TARGET)' : '$@';
 
     return sprintf <<'MAKE_FRAG', ($target) x 5;
 BOOTSTRAP = $(BASEEXT).bs
@@ -893,10 +896,10 @@ sub dynamic_lib {
     my($inst_dynamic_dep) = $attribs{INST_DYNAMIC_DEP} || "";
     my($armaybe) = $attribs{ARMAYBE} || $self->{ARMAYBE} || ":";
     my($ldfrom) = '$(LDFROM)';
-    $armaybe = 'ar' if ($Is_OSF and $armaybe eq ':');
+    $armaybe = 'ar' if ($Is{OSF} and $armaybe eq ':');
     my(@m);
-    my $ld_opt = $Is_OS2 ? '$(OPTIMIZE) ' : '';        # Useful on other systems too?
-    my $ld_fix = $Is_OS2 ? '|| ( $(RM_F) $@ && sh -c false )' : '';
+    my $ld_opt = $Is{OS2} ? '$(OPTIMIZE) ' : '';       # Useful on other systems too?
+    my $ld_fix = $Is{OS2} ? '|| ( $(RM_F) $@ && sh -c false )' : '';
     push(@m,'
 # This section creates the dynamically loadable $(INST_DYNAMIC)
 # from $(OBJECT) and possibly $(MYEXTLIB).
@@ -912,10 +915,10 @@ $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DFSEP).
        push(@m,'       $(ARMAYBE) cr '.$ldfrom.' $(OBJECT)'."\n");
        push(@m,'       $(RANLIB) '."$ldfrom\n");
     }
-    $ldfrom = "-all $ldfrom -none" if $Is_OSF;
+    $ldfrom = "-all $ldfrom -none" if $Is{OSF};
 
     # The IRIX linker doesn't use LD_RUN_PATH
-    my $ldrun = $Is_IRIX && $self->{LD_RUN_PATH} ?         
+    my $ldrun = $Is{IRIX} && $self->{LD_RUN_PATH} ?         
                        qq{-rpath "$self->{LD_RUN_PATH}"} : '';
 
     # For example in AIX the shared objects/libraries from previous builds
@@ -928,7 +931,7 @@ $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DFSEP).
 
     my $libs = '$(LDLOADLIBS)';
 
-    if (($Is_NetBSD || $Is_Interix) && $Config{'useshrplib'}) {
+    if (($Is{NetBSD} || $Is{Interix}) && $Config{'useshrplib'} eq 'true') {
        # Use nothing on static perl platforms, and to the flags needed
        # to link against the shared libperl library on shared perl
        # platforms.  We peek at lddlflags to see if we need -Wl,-R
@@ -990,7 +993,7 @@ Finds the executables PERL and FULLPERL
 
 sub find_perl {
     my($self, $ver, $names, $dirs, $trace) = @_;
-    my($name, $dir);
+
     if ($trace >= 2){
         print "Looking for perl $ver by these names:
 @$names
@@ -1001,8 +1004,10 @@ in these dirs:
 
     my $stderr_duped = 0;
     local *STDERR_COPY;
-    unless ($Is_BSD) {
-        if( open(STDERR_COPY, '>&STDERR') ) {
+
+    unless ($Is{BSD}) {
+        # >& and lexical filehandles together give 5.6.2 indigestion
+        if( open(STDERR_COPY, '>&STDERR') ) {  ## no critic
             $stderr_duped = 1;
         }
         else {
@@ -1013,8 +1018,8 @@ WARNING
         }
     }
 
-    foreach $name (@$names){
-        foreach $dir (@$dirs){
+    foreach my $name (@$names){
+        foreach my $dir (@$dirs){
             next unless defined $dir; # $self->{PERL_SRC} may be undefined
             my ($abs, $val);
             if ($self->file_name_is_absolute($name)) {     # /foo/bar
@@ -1030,25 +1035,31 @@ WARNING
             print "Executing $abs\n" if ($trace >= 2);
 
             my $version_check = qq{$abs -le "require $ver; print qq{VER_OK}"};
-            # To avoid using the unportable 2>&1 to supress STDERR,
+            $version_check = "$Config{run} $version_check"
+                if defined $Config{run} and length $Config{run};
+
+            # To avoid using the unportable 2>&1 to suppress STDERR,
             # we close it before running the command.
             # However, thanks to a thread library bug in many BSDs
             # ( http://www.freebsd.org/cgi/query-pr.cgi?pr=51535 )
             # we cannot use the fancier more portable way in here
             # but instead need to use the traditional 2>&1 construct.
-            if ($Is_BSD) {
+            if ($Is{BSD}) {
                 $val = `$version_check 2>&1`;
             } else {
                 close STDERR if $stderr_duped;
                 $val = `$version_check`;
-                open STDERR, '>&STDERR_COPY' if $stderr_duped;
+
+                # 5.6.2's 3-arg open doesn't work with >&
+                open STDERR, ">&STDERR_COPY"  ## no critic
+                        if $stderr_duped;
             }
 
-            if ($val =~ /^VER_OK/) {
+            if ($val =~ /^VER_OK/m) {
                 print "Using PERL=$abs\n" if $trace;
                 return $abs;
             } elsif ($trace >= 2) {
-                print "Result: '$val'\n";
+                print "Result: '$val' ".($? >> 8)."\n";
             }
         }
     }
@@ -1065,95 +1076,101 @@ Inserts the sharpbang or equivalent magic number to a set of @files.
 
 =cut
 
-sub fixin { # stolen from the pink Camel book, more or less
-    my($self, @files) = @_;
+sub fixin {    # stolen from the pink Camel book, more or less
+    my ( $self, @files ) = @_;
 
-    my($does_shbang) = $Config{'sharpbang'} =~ /^\s*\#\!/;
+    my ($does_shbang) = $Config{'sharpbang'} =~ /^\s*\#\!/;
     for my $file (@files) {
         my $file_new = "$file.new";
         my $file_bak = "$file.bak";
 
-       local(*FIXIN);
-       local(*FIXOUT);
-       open(FIXIN, $file) or croak "Can't process '$file': $!";
-       local $/ = "\n";
-       chomp(my $line = <FIXIN>);
-       next unless $line =~ s/^\s*\#!\s*//;     # Not a shbang file.
-       # Now figure out the interpreter name.
-       my($cmd,$arg) = split ' ', $line, 2;
-       $cmd =~ s!^.*/!!;
-
-       # Now look (in reverse) for interpreter in absolute PATH (unless perl).
+        open( my $fixin, '<', $file ) or croak "Can't process '$file': $!";
+        local $/ = "\n";
+        chomp( my $line = <$fixin> );
+        next unless $line =~ s/^\s*\#!\s*//;    # Not a shbang file.
+        # Now figure out the interpreter name.
+        my ( $cmd, $arg ) = split ' ', $line, 2;
+        $cmd =~ s!^.*/!!;
+
+        # Now look (in reverse) for interpreter in absolute PATH (unless perl).
         my $interpreter;
-       if ($cmd eq "perl") {
-            if ($Config{startperl} =~ m,^\#!.*/perl,) {
+        if ( $cmd eq "perl" ) {
+            if ( $Config{startperl} =~ m,^\#!.*/perl, ) {
                 $interpreter = $Config{startperl};
                 $interpreter =~ s,^\#!,,;
-            } else {
+            }
+            else {
                 $interpreter = $Config{perlpath};
             }
-       } else {
-           my(@absdirs) = reverse grep {$self->file_name_is_absolute} $self->path;
-           $interpreter = '';
-           my($dir);
-           foreach $dir (@absdirs) {
-               if ($self->maybe_command($cmd)) {
-                   warn "Ignoring $interpreter in $file\n" if $Verbose && $interpreter;
-                   $interpreter = $self->catfile($dir,$cmd);
-               }
-           }
-       }
-       # Figure out how to invoke interpreter on this machine.
-
-       my($shb) = "";
-       if ($interpreter) {
-           print STDOUT "Changing sharpbang in $file to $interpreter" if $Verbose;
-           # this is probably value-free on DOSISH platforms
-           if ($does_shbang) {
-               $shb .= "$Config{'sharpbang'}$interpreter";
-               $shb .= ' ' . $arg if defined $arg;
-               $shb .= "\n";
-           }
-           $shb .= qq{
+        }
+        else {
+            my (@absdirs)
+                = reverse grep { $self->file_name_is_absolute } $self->path;
+            $interpreter = '';
+
+            foreach my $dir (@absdirs) {
+                if ( $self->maybe_command($cmd) ) {
+                    warn "Ignoring $interpreter in $file\n"
+                        if $Verbose && $interpreter;
+                    $interpreter = $self->catfile( $dir, $cmd );
+                }
+            }
+        }
+
+        # Figure out how to invoke interpreter on this machine.
+
+        my ($shb) = "";
+        if ($interpreter) {
+            print STDOUT "Changing sharpbang in $file to $interpreter"
+                if $Verbose;
+
+            # this is probably value-free on DOSISH platforms
+            if ($does_shbang) {
+                $shb .= "$Config{'sharpbang'}$interpreter";
+                $shb .= ' ' . $arg if defined $arg;
+                $shb .= "\n";
+            }
+            $shb .= qq{
 eval 'exec $interpreter $arg -S \$0 \${1+"\$\@"}'
     if 0; # not running under some shell
-} unless $Is_Win32; # this won't work on win32, so don't
-       } else {
-           warn "Can't find $cmd in PATH, $file unchanged"
-               if $Verbose;
-           next;
-       }
+} unless $Is{Win32};    # this won't work on win32, so don't
+        }
+        else {
+            warn "Can't find $cmd in PATH, $file unchanged"
+                if $Verbose;
+            next;
+        }
 
-       unless ( open(FIXOUT,">$file_new") ) {
-           warn "Can't create new $file: $!\n";
-           next;
-       }
-       
-       # Print out the new #! line (or equivalent).
-       local $\;
-       undef $/;
-       print FIXOUT $shb, <FIXIN>;
-       close FIXIN;
-       close FIXOUT;
+        open( my $fixout, ">", "$file_new" ) or do {
+            warn "Can't create new $file: $!\n";
+            next;
+        };
+
+        # Print out the new #! line (or equivalent).
+        local $\;
+        local $/;
+        print $fixout $shb, <$fixin>;
+        close $fixin;
+        close $fixout;
 
         chmod 0666, $file_bak;
         unlink $file_bak;
-       unless ( _rename($file, $file_bak) ) {  
-           warn "Can't rename $file to $file_bak: $!";
-           next;
-       }
-       unless ( _rename($file_new, $file) ) {  
-           warn "Can't rename $file_new to $file: $!";
-           unless ( _rename($file_bak, $file) ) {
-               warn "Can't rename $file_bak back to $file either: $!";
-               warn "Leaving $file renamed as $file_bak\n";
-           }
-           next;
-       }
-       unlink $file_bak;
-    } continue {
-       close(FIXIN) if fileno(FIXIN);
-       system("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';;
+        unless ( _rename( $file, $file_bak ) ) {
+            warn "Can't rename $file to $file_bak: $!";
+            next;
+        }
+        unless ( _rename( $file_new, $file ) ) {
+            warn "Can't rename $file_new to $file: $!";
+            unless ( _rename( $file_bak, $file ) ) {
+                warn "Can't rename $file_bak back to $file either: $!";
+                warn "Leaving $file renamed as $file_bak\n";
+            }
+            next;
+        }
+        unlink $file_bak;
+    }
+    continue {
+        system("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
     }
 }
 
@@ -1162,7 +1179,7 @@ sub _rename {
     my($old, $new) = @_;
 
     foreach my $file ($old, $new) {
-        if( $Is_VMS and basename($file) !~ /\./ ) {
+        if( $Is{VMS} and basename($file) !~ /\./ ) {
             # rename() in 5.8.0 on VMS will not rename a file if it
             # does not contain a dot yet it returns success.
             $file = "$file.";
@@ -1182,7 +1199,7 @@ Writes an empty FORCE: target.
 sub force {
     my($self) = shift;
     '# Phony target to force checking subdirectories.
-FORCE:
+FORCE :
        $(NOECHO) $(NOOP)
 ';
 }
@@ -1229,8 +1246,8 @@ sub has_link_code {
 
 =item init_dirscan
 
-Scans the directory structure and initializes DIR, XS, XS_FILES, PM,
-C, C_FILES, O_FILES, H, H_FILES, PL_FILES, MAN*PODS, EXE_FILES.
+Scans the directory structure and initializes DIR, XS, XS_FILES,
+C, C_FILES, O_FILES, H, H_FILES, PL_FILES, EXE_FILES.
 
 Called by init_main.
 
@@ -1238,18 +1255,17 @@ Called by init_main.
 
 sub init_dirscan {     # --- File and Directory Lists (.xs .pm .pod etc)
     my($self) = @_;
-    my($name, %dir, %xs, %c, %h, %pl_files, %manifypods);
-    my %pm;
+    my(%dir, %xs, %c, %h, %pl_files, %pm);
 
     my %ignore = map {( $_ => 1 )} qw(Makefile.PL Build.PL test.pl t);
 
     # ignore the distdir
-    $Is_VMS ? $ignore{"$self->{DISTVNAME}.dir"} = 1
+    $Is{VMS} ? $ignore{"$self->{DISTVNAME}.dir"} = 1
             : $ignore{$self->{DISTVNAME}} = 1;
 
-    @ignore{map lc, keys %ignore} = values %ignore if $Is_VMS;
+    @ignore{map lc, keys %ignore} = values %ignore if $Is{VMS};
 
-    foreach $name ($self->lsdir($Curdir)){
+    foreach my $name ($self->lsdir($Curdir)){
        next if $name =~ /\#/;
        next if $name eq $Curdir or $name eq $Updir or $ignore{$name};
        next unless $self->libscan($name);
@@ -1268,10 +1284,10 @@ sub init_dirscan {      # --- File and Directory Lists (.xs .pm .pod etc)
            $h{$name} = 1;
        } elsif ($name =~ /\.PL\z/) {
            ($pl_files{$name} = $name) =~ s/\.PL\z// ;
-       } elsif (($Is_VMS || $Is_Dos) && $name =~ /[._]pl$/i) {
+       } elsif (($Is{VMS} || $Is{Dos}) && $name =~ /[._]pl$/i) {
            # case-insensitive filesystem, one dot per name, so foo.h.PL
            # under Unix appears as foo.h_pl under VMS or fooh.pl on Dos
-           local($/); open(PL,$name); my $txt = <PL>; close PL;
+           local($/); open(my $pl, '<', $name); my $txt = <$pl>; close $pl;
            if ($txt =~ /Extracting \S+ \(with variable substitutions/) {
                ($pl_files{$name} = $name) =~ s/[._]pl\z//i ;
            }
@@ -1283,6 +1299,141 @@ sub init_dirscan {      # --- File and Directory Lists (.xs .pm .pod etc)
        }
     }
 
+    $self->{PL_FILES}   ||= \%pl_files;
+    $self->{DIR}        ||= [sort keys %dir];
+    $self->{XS}         ||= \%xs;
+    $self->{C}          ||= [sort keys %c];
+    $self->{H}          ||= [sort keys %h];
+    $self->{PM}         ||= \%pm;
+
+    my @o_files = @{$self->{C}};
+    $self->{O_FILES} = [grep s/\.c(pp|xx|c)?\z/$self->{OBJ_EXT}/i, @o_files];
+}
+
+
+=item init_MANPODS
+
+Determines if man pages should be generated and initializes MAN1PODS
+and MAN3PODS as appropriate.
+
+=cut
+
+sub init_MANPODS {
+    my $self = shift;
+
+    # Set up names of manual pages to generate from pods
+    foreach my $man (qw(MAN1 MAN3)) {
+       if ( $self->{"${man}PODS"}
+             or $self->{"INSTALL${man}DIR"} =~ /^(none|\s*)$/
+        ) {
+            $self->{"${man}PODS"} ||= {};
+        }
+        else {
+            my $init_method = "init_${man}PODS";
+            $self->$init_method();
+       }
+    }
+}
+
+
+sub _has_pod {
+    my($self, $file) = @_;
+
+    my($ispod)=0;
+    if (open( my $fh, '<', $file )) {
+        while (<$fh>) {
+            if (/^=(?:head\d+|item|pod)\b/) {
+                $ispod=1;
+                last;
+            }
+        }
+        close $fh;
+    } else {
+        # If it doesn't exist yet, we assume, it has pods in it
+        $ispod = 1;
+    }
+
+    return $ispod;
+}
+
+
+=item init_MAN1PODS
+
+Initializes MAN1PODS from the list of EXE_FILES.
+
+=cut
+
+sub init_MAN1PODS {
+    my($self) = @_;
+
+    if ( exists $self->{EXE_FILES} ) {
+       foreach my $name (@{$self->{EXE_FILES}}) {
+           next unless $self->_has_pod($name);
+
+           $self->{MAN1PODS}->{$name} =
+               $self->catfile("\$(INST_MAN1DIR)", 
+                              basename($name).".\$(MAN1EXT)");
+       }
+    }
+}
+
+
+=item init_MAN3PODS
+
+Initializes MAN3PODS from the list of PM files.
+
+=cut
+
+sub init_MAN3PODS {
+    my $self = shift;
+
+    my %manifypods = (); # we collect the keys first, i.e. the files
+                         # we have to convert to pod
+
+    foreach my $name (keys %{$self->{PM}}) {
+       if ($name =~ /\.pod\z/ ) {
+           $manifypods{$name} = $self->{PM}{$name};
+       } elsif ($name =~ /\.p[ml]\z/ ) {
+           if( $self->_has_pod($name) ) {
+               $manifypods{$name} = $self->{PM}{$name};
+           }
+       }
+    }
+
+    my $parentlibs_re = join '|', @{$self->{PMLIBPARENTDIRS}};
+
+    # Remove "Configure.pm" and similar, if it's not the only pod listed
+    # To force inclusion, just name it "Configure.pod", or override 
+    # MAN3PODS
+    foreach my $name (keys %manifypods) {
+       if ($self->{PERL_CORE} and $name =~ /(config|setup).*\.pm/is) {
+           delete $manifypods{$name};
+           next;
+       }
+       my($manpagename) = $name;
+       $manpagename =~ s/\.p(od|m|l)\z//;
+       # everything below lib is ok
+       unless($manpagename =~ s!^\W*($parentlibs_re)\W+!!s) {
+           $manpagename = $self->catfile(
+               split(/::/,$self->{PARENT_NAME}),$manpagename
+           );
+       }
+       $manpagename = $self->replace_manpage_separator($manpagename);
+       $self->{MAN3PODS}->{$name} =
+           $self->catfile("\$(INST_MAN3DIR)", "$manpagename.\$(MAN3EXT)");
+    }
+}
+
+
+=item init_PM
+
+Initializes PMLIBDIRS and PM from PMLIBDIRS.
+
+=cut
+
+sub init_PM {
+    my $self = shift;
+
     # Some larger extensions often wish to install a number of *.pm/pl
     # files into the library in various locations.
 
@@ -1310,7 +1461,7 @@ sub init_dirscan {        # --- File and Directory Lists (.xs .pm .pod etc)
     # that's important for nested modules.
 
     unless( $self->{PMLIBDIRS} ) {
-        if( $Is_VMS ) {
+        if( $Is{VMS} ) {
             # Avoid logical name vs directory collisions
             $self->{PMLIBDIRS} = ['./lib', "./$self->{BASEEXT}"];
         }
@@ -1324,12 +1475,18 @@ sub init_dirscan {      # --- File and Directory Lists (.xs .pm .pod etc)
     # Avoid $_ wherever possible:
     # @{$self->{PMLIBDIRS}} = grep -d && !$dir{$_}, @{$self->{PMLIBDIRS}};
     my (@pmlibdirs) = @{$self->{PMLIBDIRS}};
-    my ($pmlibdir);
     @{$self->{PMLIBDIRS}} = ();
-    foreach $pmlibdir (@pmlibdirs) {
+    my %dir = map { ($_ => $_) } @{$self->{DIR}};
+    foreach my $pmlibdir (@pmlibdirs) {
        -d $pmlibdir && !$dir{$pmlibdir} && push @{$self->{PMLIBDIRS}}, $pmlibdir;
     }
 
+    unless( $self->{PMLIBPARENTDIRS} ) {
+       @{$self->{PMLIBPARENTDIRS}} = ('lib');
+    }
+
+    return if $self->{PM} and $self->{ARGS}{PM};
+
     if (@{$self->{PMLIBDIRS}}){
        print "Searching PMLIBDIRS: @{$self->{PMLIBDIRS}}\n"
            if ($Verbose >= 2);
@@ -1349,116 +1506,22 @@ sub init_dirscan {     # --- File and Directory Lists (.xs .pm .pod etc)
             my $prefix = $self->{INST_LIBDIR};
             my $striplibpath;
 
+           my $parentlibs_re = join '|', @{$self->{PMLIBPARENTDIRS}};
            $prefix =  $self->{INST_LIB} 
-                if ($striplibpath = $path) =~ s:^(\W*)lib\W:$1:i;
+                if ($striplibpath = $path) =~ s{^(\W*)($parentlibs_re)\W}
+                                              {$1}i;
 
            my($inst) = $self->catfile($prefix,$striplibpath);
            local($_) = $inst; # for backwards compatibility
            $inst = $self->libscan($inst);
            print "libscan($path) => '$inst'\n" if ($Verbose >= 2);
            return unless $inst;
-           $pm{$path} = $inst;
+           $self->{PM}{$path} = $inst;
        }, @{$self->{PMLIBDIRS}});
     }
-
-    $self->{PM}  ||= \%pm;
-    $self->{PL_FILES} ||= \%pl_files;
-
-    $self->{DIR} ||= [sort keys %dir];
-
-    $self->{XS}  ||= \%xs;
-    $self->{C}   ||= [sort keys %c];
-    my @o_files = @{$self->{C}};
-    $self->{O_FILES} = [grep s/\.c(pp|xx|c)?\z/$self->{OBJ_EXT}/i, @o_files];
-                            
-    $self->{H}   ||= [sort keys %h];
-
-    # Set up names of manual pages to generate from pods
-    my %pods;
-    foreach my $man (qw(MAN1 MAN3)) {
-       unless ($self->{"${man}PODS"}) {
-           $self->{"${man}PODS"} = {};
-           $pods{$man} = 1 unless 
-              $self->{"INSTALL${man}DIR"} =~ /^(none|\s*)$/;
-       }
-    }
-
-    if ($pods{MAN1}) {
-       if ( exists $self->{EXE_FILES} ) {
-           foreach $name (@{$self->{EXE_FILES}}) {
-               local *FH;
-               my($ispod)=0;
-               if (open(FH,"<$name")) {
-                   while (<FH>) {
-                       if (/^=(?:head\d+|item|pod)\b/) {
-                           $ispod=1;
-                           last;
-                       }
-                   }
-                   close FH;
-               } else {
-                   # If it doesn't exist yet, we assume, it has pods in it
-                   $ispod = 1;
-               }
-               next unless $ispod;
-               if ($pods{MAN1}) {
-                   $self->{MAN1PODS}->{$name} =
-                     $self->catfile("\$(INST_MAN1DIR)", basename($name).".\$(MAN1EXT)");
-               }
-           }
-       }
-    }
-    if ($pods{MAN3}) {
-       my %manifypods = (); # we collect the keys first, i.e. the files
-                            # we have to convert to pod
-       foreach $name (keys %{$self->{PM}}) {
-           if ($name =~ /\.pod\z/ ) {
-               $manifypods{$name} = $self->{PM}{$name};
-           } elsif ($name =~ /\.p[ml]\z/ ) {
-               local *FH;
-               my($ispod)=0;
-               if (open(FH,"<$name")) {
-                   while (<FH>) {
-                       if (/^=head1\s+\w+/) {
-                           $ispod=1;
-                           last;
-                       }
-                   }
-                   close FH;
-               } else {
-                   $ispod = 1;
-               }
-               if( $ispod ) {
-                   $manifypods{$name} = $self->{PM}{$name};
-               }
-           }
-       }
-
-       # Remove "Configure.pm" and similar, if it's not the only pod listed
-       # To force inclusion, just name it "Configure.pod", or override 
-        # MAN3PODS
-       foreach $name (keys %manifypods) {
-           if ($self->{PERL_CORE} and $name =~ /(config|setup).*\.pm/is) {
-               delete $manifypods{$name};
-               next;
-           }
-           my($manpagename) = $name;
-           $manpagename =~ s/\.p(od|m|l)\z//;
-           # everything below lib is ok
-           unless($manpagename =~ s!^\W*lib\W+!!s) {
-               $manpagename = $self->catfile(
-                                split(/::/,$self->{PARENT_NAME}),$manpagename
-                               );
-           }
-           if ($pods{MAN3}) {
-               $manpagename = $self->replace_manpage_separator($manpagename);
-               $self->{MAN3PODS}->{$name} =
-                 $self->catfile("\$(INST_MAN3DIR)", "$manpagename.\$(MAN3EXT)");
-           }
-       }
-    }
 }
 
+
 =item init_DIRFILESEP
 
 Using / for Unix.  Called by init_main.
@@ -1528,24 +1591,17 @@ sub init_main {
     my $inc_carp_dir   = dirname($INC{'Carp.pm'});
 
     unless ($self->{PERL_SRC}){
-       my($dir);
-       foreach $dir ($Updir,
-                  $self->catdir($Updir,$Updir),
-                  $self->catdir($Updir,$Updir,$Updir),
-                  $self->catdir($Updir,$Updir,$Updir,$Updir),
-                  $self->catdir($Updir,$Updir,$Updir,$Updir,$Updir))
-        {
-           if (
-               -f $self->catfile($dir,"config_h.SH")
-               &&
-               -f $self->catfile($dir,"perl.h")
-               &&
-               -f $self->catfile($dir,"lib","Exporter.pm")
-              ) {
-               $self->{PERL_SRC}=$dir ;
-               last;
-           }
-       }
+        foreach my $dir_count (1..8) { # 8 is the VMS limit for nesting
+            my $dir = $self->catdir(($Updir) x $dir_count);
+
+            if (-f $self->catfile($dir,"config_h.SH")   &&
+                -f $self->catfile($dir,"perl.h")        &&
+                -f $self->catfile($dir,"lib","strict.pm")
+            ) {
+                $self->{PERL_SRC}=$dir ;
+                last;
+            }
+        }
     }
 
     warn "PERL_CORE is set but I can't find your PERL_SRC!\n" if
@@ -1559,11 +1615,11 @@ sub init_main {
               $self->catdir("$self->{PERL_SRC}","xlib",$Cross::platform);
             $self->{PERL_INC}     = 
               $self->catdir("$self->{PERL_SRC}","xlib",$Cross::platform, 
-                                 $Is_Win32?("CORE"):());
+                                 $Is{Win32}?("CORE"):());
         }
         else {
             $self->{PERL_ARCHLIB} = $self->{PERL_LIB};
-            $self->{PERL_INC}     = ($Is_Win32) ? 
+            $self->{PERL_INC}     = ($Is{Win32}) ? 
               $self->catdir($self->{PERL_LIB},"CORE") : $self->{PERL_SRC};
         }
 
@@ -1571,11 +1627,11 @@ sub init_main {
        unless (
                -s $self->catfile($self->{PERL_SRC},'cflags')
                or
-               $Is_VMS
+               $Is{VMS}
                &&
                -s $self->catfile($self->{PERL_SRC},'perlshr_attr.opt')
                or
-               $Is_Win32
+               $Is{Win32}
               ){
            warn qq{
 You cannot build extensions below the perl source tree after executing
@@ -1603,15 +1659,18 @@ from the perl source tree.
            and not $old){
            # Maybe somebody tries to build an extension with an
            # uninstalled Perl outside of Perl build tree
-           my $found;
+           my $lib;
            for my $dir (@INC) {
-             $found = $dir, last if -e $self->catdir($dir, "Config.pm");
+             $lib = $dir, last if -e $self->catdir($dir, "Config.pm");
            }
-           if ($found) {
-             my $inc = dirname $found;
+           if ($lib) {
+              # Win32 puts its header files in /perl/src/lib/CORE.
+              # Unix leaves them in /perl/src.
+             my $inc = $Is{Win32} ? $self->catdir($lib, "CORE" )
+                                  : dirname $lib;
              if (-e $self->catdir($inc, "perl.h")) {
-               $self->{PERL_LIB}          = $found;
-               $self->{PERL_ARCHLIB}      = $found;
+               $self->{PERL_LIB}          = $lib;
+               $self->{PERL_ARCHLIB}      = $lib;
                $self->{PERL_INC}          = $inc;
                $self->{UNINSTALLED_PERL}  = 1;
                print STDOUT <<EOP;
@@ -1634,17 +1693,17 @@ EOP
 
     # Get some stuff out of %Config if we haven't yet done so
     print STDOUT "CONFIG must be an array ref\n"
-       if ($self->{CONFIG} and ref $self->{CONFIG} ne 'ARRAY');
+        if ($self->{CONFIG} and ref $self->{CONFIG} ne 'ARRAY');
     $self->{CONFIG} = [] unless (ref $self->{CONFIG});
     push(@{$self->{CONFIG}}, @ExtUtils::MakeMaker::Get_from_Config);
     push(@{$self->{CONFIG}}, 'shellflags') if $Config{shellflags};
     my(%once_only);
     foreach my $m (@{$self->{CONFIG}}){
-       next if $once_only{$m};
-       print STDOUT "CONFIG key '$m' does not exist in Config.pm\n"
-               unless exists $Config{$m};
-       $self->{uc $m} ||= $Config{$m};
-       $once_only{$m} = 1;
+        next if $once_only{$m};
+        print STDOUT "CONFIG key '$m' does not exist in Config.pm\n"
+                unless exists $Config{$m};
+        $self->{uc $m} ||= $Config{$m};
+        $once_only{$m} = 1;
     }
 
 # This is too dangerous:
@@ -1664,11 +1723,11 @@ EOP
 
     $self->{LIBPERL_A} ||= "libperl$self->{LIB_EXT}";
 
-    # make a simple check if we find Exporter
+    # make a simple check if we find strict
     warn "Warning: PERL_LIB ($self->{PERL_LIB}) seems not to be a perl library directory
-        (Exporter.pm not found)"
-       unless -f $self->catfile("$self->{PERL_LIB}","Exporter.pm") ||
-        $self->{NAME} eq "ExtUtils::MakeMaker";
+        (strict.pm not found)"
+        unless -f $self->catfile("$self->{PERL_LIB}","strict.pm") ||
+               $self->{NAME} eq "ExtUtils::MakeMaker";
 }
 
 =item init_others
@@ -1694,8 +1753,8 @@ sub init_others { # --- Initialize Other Attributes
 
     $self->{LIBS} = [''] unless @{$self->{LIBS}} && defined $self->{LIBS}[0];
     $self->{LD_RUN_PATH} = "";
-    my($libs);
-    foreach $libs ( @{$self->{LIBS}} ){
+
+    foreach my $libs ( @{$self->{LIBS}} ){
        $libs =~ s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace
        my(@libs) = $self->extliblist($libs);
        if ($libs[0] or $libs[1] or $libs[2]){
@@ -1872,7 +1931,7 @@ sub init_PERL {
     my $thisperl = $self->canonpath($^X);
     $thisperl .= $Config{exe_ext} unless 
                 # VMS might have a file version # at the end
-      $Is_VMS ? $thisperl =~ m/$Config{exe_ext}(;\d+)?$/i
+      $Is{VMS} ? $thisperl =~ m/$Config{exe_ext}(;\d+)?$/i
               : $thisperl =~ m/$Config{exe_ext}$/i;
 
     # We need a relative path to perl when in the core.
@@ -1899,7 +1958,7 @@ sub init_PERL {
 
     # When built for debugging, VMS doesn't create perl.exe but ndbgperl.exe.
     my $perl_name = 'perl';
-    $perl_name = 'ndbgperl' if $Is_VMS && 
+    $perl_name = 'ndbgperl' if $Is{VMS} && 
       defined $Config{usevmsdebug} && $Config{usevmsdebug} eq 'define';
 
     # XXX This logic is flawed.  If "miniperl" is anywhere in the path
@@ -1917,6 +1976,11 @@ sub init_PERL {
     }
     else {
         $self->{ABSPERL} = $self->rel2abs($self->{ABSPERL});
+
+        # Quote the perl command if it contains whitespace
+        $self->{ABSPERL} = $self->quote_literal($self->{ABSPERL})
+          if $self->{ABSPERL} =~ /\s/;
+
         $self->{ABSPERL} = 'MCR '.$self->{ABSPERL} if $has_mcr;
     }
 
@@ -2074,7 +2138,7 @@ pure_site_install ::
                $(INST_LIB) $(DESTINSTALLSITELIB) \
                $(INST_ARCHLIB) $(DESTINSTALLSITEARCH) \
                $(INST_BIN) $(DESTINSTALLSITEBIN) \
-               $(INST_SCRIPT) $(DESTINSTALLSCRIPT) \
+               $(INST_SCRIPT) $(DESTINSTALLSITESCRIPT) \
                $(INST_MAN1DIR) $(DESTINSTALLSITEMAN1DIR) \
                $(INST_MAN3DIR) $(DESTINSTALLSITEMAN3DIR)
        $(NOECHO) $(WARN_IF_OLD_PACKLIST) \
@@ -2087,7 +2151,7 @@ pure_vendor_install ::
                $(INST_LIB) $(DESTINSTALLVENDORLIB) \
                $(INST_ARCHLIB) $(DESTINSTALLVENDORARCH) \
                $(INST_BIN) $(DESTINSTALLVENDORBIN) \
-               $(INST_SCRIPT) $(DESTINSTALLSCRIPT) \
+               $(INST_SCRIPT) $(DESTINSTALLVENDORSCRIPT) \
                $(INST_MAN1DIR) $(DESTINSTALLVENDORMAN1DIR) \
                $(INST_MAN3DIR) $(DESTINSTALLVENDORMAN3DIR)
 
@@ -2156,7 +2220,7 @@ sub installbin {
     my @exefiles = @{$self->{EXE_FILES}};
     return "" unless @exefiles;
 
-    @exefiles = map vmsify($_), @exefiles if $Is_VMS;
+    @exefiles = map vmsify($_), @exefiles if $Is{VMS};
 
     my %fromto;
     for my $from (@exefiles) {
@@ -2166,7 +2230,7 @@ sub installbin {
        my $to = $self->libscan($path);
        print "libscan($from) => '$to'\n" if ($Verbose >=2);
 
-        $to = vmsify($to) if $Is_VMS;
+        $to = vmsify($to) if $Is{VMS};
        $fromto{$from} = $to;
     }
     my @to   = values %fromto;
@@ -2340,16 +2404,14 @@ $(MAKE_APERL_FILE) : $(FIRST_MAKEFILE) pm_to_blib
 
        if( exists $self->{INCLUDE_EXT} ){
                my $found = 0;
-               my $incl;
-               my $xx;
 
-               ($xx = $File::Find::name) =~ s,.*?/auto/,,s;
+               (my $xx = $File::Find::name) =~ s,.*?/auto/,,s;
                $xx =~ s,/?$_,,;
                $xx =~ s,/,::,g;
 
                # Throw away anything not explicitly marked for inclusion.
                # DynaLoader is implied.
-               foreach $incl ((@{$self->{INCLUDE_EXT}},'DynaLoader')){
+               foreach my $incl ((@{$self->{INCLUDE_EXT}},'DynaLoader')){
                        if( $xx eq $incl ){
                                $found++;
                                last;
@@ -2358,15 +2420,12 @@ $(MAKE_APERL_FILE) : $(FIRST_MAKEFILE) pm_to_blib
                return unless $found;
        }
        elsif( exists $self->{EXCLUDE_EXT} ){
-               my $excl;
-               my $xx;
-
-               ($xx = $File::Find::name) =~ s,.*?/auto/,,s;
+               (my $xx = $File::Find::name) =~ s,.*?/auto/,,s;
                $xx =~ s,/?$_,,;
                $xx =~ s,/,::,g;
 
                # Throw away anything explicitly marked for exclusion
-               foreach $excl (@{$self->{EXCLUDE_EXT}}){
+               foreach my $excl (@{$self->{EXCLUDE_EXT}}){
                        return if( $xx eq $excl );
                }
        }
@@ -2394,7 +2453,7 @@ $(MAKE_APERL_FILE) : $(FIRST_MAKEFILE) pm_to_blib
        push @$extra, $_;
     }
 
-    grep(s/^(.*)/"-I$1"/, @{$perlinc || []});
+    s/^(.*)/"-I$1"/ for @{$perlinc || []};
 
     $target ||= "perl";
     $tmp    ||= ".";
@@ -2424,10 +2483,10 @@ MAP_PRELIBS   = $Config{perllibs} $Config{cryptlib}
 
         if (! -f $libperl and ! -f $lperl) {
           # We did not find a static libperl. Maybe there is a shared one?
-          if ($Is_SunOS) {
+          if ($Is{SunOS}) {
             $lperl  = $libperl = "$dir/$Config{libperl}";
             # SUNOS ld does not take the full path to a shared library
-            $libperl = '' if $Is_SunOS4;
+            $libperl = '' if $Is{SunOS4};
           }
         }
 
@@ -2451,8 +2510,7 @@ $(INST_ARCHAUTODIR)/extralibs.all : $(INST_ARCHAUTODIR)$(DFSEP).exists '.join("
        $(NOECHO) $(TOUCH) $@
 ';
 
-    my $catfile;
-    foreach $catfile (@$extra){
+    foreach my $catfile (@$extra){
        push @m, "\tcat $catfile >> \$\@\n";
     }
 
@@ -2480,7 +2538,7 @@ $tmp/perlmain.c: $makefilename}, q{
 
 
     push @m, q{
-doc_inst_perl:
+doc_inst_perl :
        $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLARCHLIB)/perllocal.pod
        -$(NOECHO) $(MKPATH) $(DESTINSTALLARCHLIB)
        -$(NOECHO) $(DOC_INSTALL) \
@@ -2493,9 +2551,9 @@ doc_inst_perl:
 };
 
     push @m, q{
-inst_perl: pure_inst_perl doc_inst_perl
+inst_perl : pure_inst_perl doc_inst_perl
 
-pure_inst_perl: $(MAP_TARGET)
+pure_inst_perl : $(MAP_TARGET)
        }.$self->{CP}.q{ $(MAP_TARGET) }.$self->catfile('$(DESTINSTALLBIN)','$(MAP_TARGET)').q{
 
 clean :: map_clean
@@ -2524,7 +2582,7 @@ $(OBJECT) : $(FIRST_MAKEFILE)
 
 ' if $self->{OBJECT};
 
-    my $newer_than_target = $Is_VMS ? '$(MMS$SOURCE_LIST)' : '$?';
+    my $newer_than_target = $Is{VMS} ? '$(MMS$SOURCE_LIST)' : '$?';
     my $mpl_args = join " ", map qq["$_"], @ARGV;
 
     $m .= sprintf <<'MAKE_FRAG', $newer_than_target, $mpl_args;
@@ -2569,8 +2627,8 @@ also has_link_code())
 
 sub needs_linking {
     my($self) = shift;
-    my($child,$caller);
-    $caller = (caller(0))[3];
+
+    my $caller = (caller(0))[3];
     confess("needs_linking called too early") if 
       $caller =~ /^ExtUtils::MakeMaker::/;
     return $self->{NEEDS_LINKING} if defined $self->{NEEDS_LINKING};
@@ -2578,7 +2636,7 @@ sub needs_linking {
        $self->{NEEDS_LINKING} = 1;
        return 1;
     }
-    foreach $child (keys %{$self->{CHILDREN}}) {
+    foreach my $child (keys %{$self->{CHILDREN}}) {
        if ($self->{CHILDREN}->{$child}->needs_linking) {
            $self->{NEEDS_LINKING} = 1;
            return 1;
@@ -2587,22 +2645,6 @@ sub needs_linking {
     return $self->{NEEDS_LINKING} = 0;
 }
 
-=item nicetext
-
-misnamed method (will have to be changed). The MM_Unix method just
-returns the argument without further processing.
-
-On VMS used to insure that colons marking targets are preceded by
-space - most Unix Makes don't need this, but it's necessary under VMS
-to distinguish the target delimiter from a colon appearing as part of
-a filespec.
-
-=cut
-
-sub nicetext {
-    my($self,$text) = @_;
-    $text;
-}
 
 =item parse_abstract
 
@@ -2613,13 +2655,13 @@ parse a file and return what you think is the ABSTRACT
 sub parse_abstract {
     my($self,$parsefile) = @_;
     my $result;
-    local *FH;
+
     local $/ = "\n";
-    open(FH,$parsefile) or die "Could not open '$parsefile': $!";
+    open(my $fh, '<', $parsefile) or die "Could not open '$parsefile': $!";
     my $inpod = 0;
     my $package = $self->{DISTNAME};
     $package =~ s/-/::/g;
-    while (<FH>) {
+    while (<$fh>) {
         $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
         next if !$inpod;
         chop;
@@ -2627,47 +2669,64 @@ sub parse_abstract {
         $result = $2;
         last;
     }
-    close FH;
+    close $fh;
+
     return $result;
 }
 
 =item parse_version
 
-parse a file and return what you think is $VERSION in this file set to.
+    my $version = MM->parse_version($file);
+
+Parse a $file and return what $VERSION is set to by the first assignment.
 It will return the string "undef" if it can't figure out what $VERSION
-is. $VERSION should be for all to see, so our $VERSION or plain $VERSION
-are okay, but my $VERSION is not.
+is. $VERSION should be for all to see, so C<our $VERSION> or plain $VERSION
+are okay, but C<my $VERSION> is not.
+
+parse_version() will try to C<use version> before checking for C<$VERSION> so the following will work.
+
+    $VERSION = qv(1.2.3);
 
 =cut
 
 sub parse_version {
     my($self,$parsefile) = @_;
     my $result;
-    local *FH;
+
     local $/ = "\n";
     local $_;
-    open(FH,$parsefile) or die "Could not open '$parsefile': $!";
+    open(my $fh, '<', $parsefile) or die "Could not open '$parsefile': $!";
     my $inpod = 0;
-    while (<FH>) {
-       $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
-       next if $inpod || /^\s*#/;
-       chop;
-       next unless /(?<!\\)([\$*])(([\w\:\']*)\bVERSION)\b.*\=/;
-       my $eval = qq{
-           package ExtUtils::MakeMaker::_version;
-           no strict;
-
-           local $1$2;
-           \$$2=undef; do {
-               $_
-           }; \$$2
-       };
+    while (<$fh>) {
+        $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
+        next if $inpod || /^\s*#/;
+        chop;
+        next unless /(?<!\\)([\$*])(([\w\:\']*)\bVERSION)\b.*\=/;
+        my $eval = qq{
+            package ExtUtils::MakeMaker::_version;
+            no strict;
+            BEGIN { eval {
+                # Ensure any version() routine which might have leaked
+                # into this package has been deleted.  Interferes with
+                # version->import()
+                undef *version;
+                require version;
+                "version"->import;
+            } }
+
+            local $1$2;
+            \$$2=undef;
+            do {
+                $_
+            };
+            \$$2;
+        };
         local $^W = 0;
-       $result = eval($eval);
-       warn "Could not eval '$eval' in $parsefile: $@" if $@;
-       last;
+        $result = eval($eval);  ## no critic
+        warn "Could not eval '$eval' in $parsefile: $@" if $@;
+        last;
     }
-    close FH;
+    close $fh;
 
     $result = "undef" unless defined $result;
     return $result;
@@ -2683,21 +2742,21 @@ subdirectories.
 
 sub pasthru {
     my($self) = shift;
-    my(@m,$key);
+    my(@m);
 
     my(@pasthru);
-    my($sep) = $Is_VMS ? ',' : '';
+    my($sep) = $Is{VMS} ? ',' : '';
     $sep .= "\\\n\t";
 
-    foreach $key (qw(LIB LIBPERL_A LINKTYPE OPTIMIZE
-                     PREFIX INSTALLBASE)
+    foreach my $key (qw(LIB LIBPERL_A LINKTYPE OPTIMIZE
+                     PREFIX INSTALL_BASE)
                  ) 
     {
         next unless defined $self->{$key};
        push @pasthru, "$key=\"\$($key)\"";
     }
 
-    foreach $key (qw(DEFINE INC)) {
+    foreach my $key (qw(DEFINE INC)) {
         next unless defined $self->{$key};
        push @pasthru, "PASTHRU_$key=\"\$(PASTHRU_$key)\"";
     }
@@ -2787,7 +2846,6 @@ PERL_HDRS = \
        $(PERL_INC)/regnodes.h          \
        $(PERL_INC)/scope.h             \
        $(PERL_INC)/sv.h                \
-       $(PERL_INC)/thrdvar.h           \
        $(PERL_INC)/thread.h            \
        $(PERL_INC)/unixish.h           \
        $(PERL_INC)/util.h
@@ -2889,6 +2947,14 @@ sub postamble {
     "";
 }
 
+# transform dot-separated version string into comma-separated quadruple
+# examples:  '1.2.3.4.5' => '1,2,3,4'
+#            '1.2.3'     => '1,2,3,0'
+sub _ppd_version {
+    my ($self, $string) = @_;
+    return join ',', ((split /\./, $string), (0) x 4)[0..3];
+}
+
 =item ppd
 
 Defines target that creates a PPD (Perl Package Description) file
@@ -2899,13 +2965,7 @@ for a binary distribution.
 sub ppd {
     my($self) = @_;
 
-    if ($self->{ABSTRACT_FROM}){
-        $self->{ABSTRACT} = $self->parse_abstract($self->{ABSTRACT_FROM}) or
-            carp "WARNING: Setting ABSTRACT via file ".
-                 "'$self->{ABSTRACT_FROM}' failed\n";
-    }
-
-    my ($pack_ver) = join ",", (split (/\./, $self->{VERSION}), (0)x4)[0..3];
+    my $pack_ver = $self->_ppd_version($self->{VERSION});
 
     my $abstract = $self->{ABSTRACT} || '';
     $abstract =~ s/\n/\\n/sg;
@@ -2924,18 +2984,31 @@ sub ppd {
 PPD_HTML
 
     $ppd_xml .= "    <IMPLEMENTATION>\n";
+    if ( $self->{MIN_PERL_VERSION} ) {
+        my $min_perl_version = $self->_ppd_version($self->{MIN_PERL_VERSION});
+        $ppd_xml .= sprintf <<'PPD_PERLVERS', $min_perl_version;
+        <PERLCORE VERSION="%s" />
+PPD_PERLVERS
+
+    }
     foreach my $prereq (sort keys %{$self->{PREREQ_PM}}) {
         my $pre_req = $prereq;
         $pre_req =~ s/::/-/g;
-        my ($dep_ver) = join ",", (split (/\./, $self->{PREREQ_PM}{$prereq}), 
-                                  (0) x 4) [0 .. 3];
+        my $dep_ver = $self->_ppd_version($self->{PREREQ_PM}{$prereq});
         $ppd_xml .= sprintf <<'PPD_OUT', $pre_req, $dep_ver;
         <DEPENDENCY NAME="%s" VERSION="%s" />
 PPD_OUT
 
     }
 
-    $ppd_xml .= sprintf <<'PPD_OUT', $Config{archname};
+    my $archname = $Config{archname};
+    if ($] >= 5.008) {
+        # archname did not change from 5.6 to 5.8, but those versions may
+        # not be not binary compatible so now we append the part of the
+        # version that changes when binary compatibility may change
+        $archname .= "-". substr($Config{version},0,3);
+    }
+    $ppd_xml .= sprintf <<'PPD_OUT', $archname;
         <OS NAME="$(OSNAME)" />
         <ARCHITECTURE NAME="%s" />
 PPD_OUT
@@ -2964,7 +3037,7 @@ PPD_XML
 
     return sprintf <<'PPD_OUT', join "\n\t", @ppd_cmds;
 # Creates a PPD (Perl Package Description) for a binary distribution.
-ppd:
+ppd :
        %s
 PPD_OUT
 
@@ -3041,9 +3114,9 @@ sub processPL {
                     : [$pl_files->{$plfile}];
 
        foreach my $target (@$list) {
-            if( $Is_VMS ) {
-                $plfile = vmsify($plfile);
-                $target = vmsify($target);
+            if( $Is{VMS} ) {
+                $plfile = vmsify($self->eliminate_macros($plfile));
+                $target = vmsify($self->eliminate_macros($target));
             }
 
            # Normally a .PL file runs AFTER pm_to_blib so it can have
@@ -3142,7 +3215,7 @@ sub oneliner {
 
     $switches = join ' ', @$switches;
 
-    return qq{\$(ABSPERLRUN) $switches -e $cmd};   
+    return qq{\$(ABSPERLRUN) $switches -e $cmd --};   
 }
 
 
@@ -3330,11 +3403,11 @@ Defines targets to process subdirectories.
 sub subdirs {
 # --- Sub-directory Sections ---
     my($self) = shift;
-    my(@m,$dir);
+    my(@m);
     # This method provides a mechanism to automatically deal with
     # subdirectories containing further Makefile.PL scripts.
     # It calls the subdir_x() method for each subdirectory.
-    foreach $dir (@{$self->{DIR}}){
+    foreach my $dir (@{$self->{DIR}}){
        push(@m, $self->subdir_x($dir));
 ####   print "Including $dir subdirectory\n";
     }
@@ -3375,17 +3448,21 @@ TESTDB_SW = -d
 
 testdb :: testdb_\$(LINKTYPE)
 
-test :: \$(TEST_TYPE)
+test :: \$(TEST_TYPE) subdirs-test
+
+subdirs-test ::
+       \$(NOECHO) \$(NOOP)
+
 ");
 
     foreach my $dir (@{ $self->{DIR} }) {
-        my $test = $self->oneliner(sprintf <<'CODE', $dir);
-chdir '%s';  
-system '$(MAKE) test $(PASTHRU)' 
-    if -f '$(FIRST_MAKEFILE)';
-CODE
+        my $test = $self->cd($dir, '$(MAKE) test $(PASTHRU)');
+
+        push @m, <<END
+subdirs-test ::
+       \$(NOECHO) $test
 
-        push(@m, "\t\$(NOECHO) $test\n");
+END
     }
 
     push(@m, "\t\$(NOECHO) \$(ECHO) 'No tests defined for \$(NAME) extension.'\n")
@@ -3506,23 +3583,22 @@ sub tool_xsubpp {
     my $tmdir   = File::Spec->catdir($self->{PERL_LIB},"ExtUtils");
     my(@tmdeps) = $self->catfile($tmdir,'typemap');
     if( $self->{TYPEMAPS} ){
-       my $typemap;
-       foreach $typemap (@{$self->{TYPEMAPS}}){
-               if( ! -f  $typemap ){
-                       warn "Typemap $typemap not found.\n";
-               }
-               else{
-                       push(@tmdeps,  $typemap);
-               }
-       }
+        foreach my $typemap (@{$self->{TYPEMAPS}}){
+            if( ! -f  $typemap ) {
+                warn "Typemap $typemap not found.\n";
+            }
+            else {
+                push(@tmdeps,  $typemap);
+            }
+        }
     }
     push(@tmdeps, "typemap") if -f "typemap";
     my(@tmargs) = map("-typemap $_", @tmdeps);
     if( exists $self->{XSOPT} ){
-       unshift( @tmargs, $self->{XSOPT} );
+        unshift( @tmargs, $self->{XSOPT} );
     }
 
-    if ($Is_VMS                          &&
+    if ($Is{VMS}                          &&
         $Config{'ldflags'}               && 
         $Config{'ldflags'} =~ m!/Debug!i &&
         (!exists($self->{XSOPT}) || $self->{XSOPT} !~ /linenumbers/)