Symbian port: add Series 90 support
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / MM_Unix.pm
index d8f0564..22cea82 100644 (file)
@@ -4,7 +4,6 @@ require 5.005_03;  # Maybe further back, dunno
 
 use strict;
 
-use Exporter ();
 use Carp;
 use ExtUtils::MakeMaker::Config;
 use File::Basename qw(basename dirname);
@@ -14,13 +13,12 @@ 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
            );
 
 use ExtUtils::MakeMaker qw($Verbose neatvalue);
 
-$VERSION = '1.49';
+$VERSION = '1.51_01';
 
 require ExtUtils::MM_Any;
 @ISA = qw(ExtUtils::MM_Any);
@@ -374,7 +372,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".$_,
@@ -1030,7 +1028,7 @@ 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,
+            # 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 )
@@ -1048,7 +1046,7 @@ WARNING
                 print "Using PERL=$abs\n" if $trace;
                 return $abs;
             } elsif ($trace >= 2) {
-                print "Result: '$val'\n";
+                print "Result: '$val' ".($? >> 8)."\n";
             }
         }
     }
@@ -1229,8 +1227,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,8 +1236,7 @@ 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($name, %dir, %xs, %c, %h, %pl_files, %pm);
 
     my %ignore = map {( $_ => 1 )} qw(Makefile.PL Build.PL test.pl t);
 
@@ -1283,6 +1280,142 @@ 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) = @_;
+
+    local *FH;
+    my($ispod)=0;
+    if (open(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.
 
@@ -1324,12 +1457,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 +1488,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.
@@ -1603,15 +1648,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;
@@ -2074,7 +2122,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 +2135,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)
 
@@ -2490,7 +2538,7 @@ doc_inst_perl:
                MAP_LIBPERL "$(MAP_LIBPERL)" \
                >> }.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{
 
-};
+} if -f 'Makefile.PL';
 
     push @m, q{
 inst_perl: pure_inst_perl doc_inst_perl
@@ -2690,7 +2738,7 @@ sub pasthru {
     $sep .= "\\\n\t";
 
     foreach $key (qw(LIB LIBPERL_A LINKTYPE OPTIMIZE
-                     PREFIX INSTALLBASE)
+                     PREFIX INSTALL_BASE)
                  ) 
     {
         next unless defined $self->{$key};
@@ -2899,12 +2947,6 @@ 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 $abstract = $self->{ABSTRACT} || '';
@@ -2935,7 +2977,14 @@ 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
@@ -3042,17 +3091,33 @@ sub processPL {
 
        foreach my $target (@$list) {
             if( $Is_VMS ) {
-                $plfile = vmsify($plfile);
-                $target = vmsify($target);
+                $plfile = vmsify($self->eliminate_macros($plfile));
+                $target = vmsify($self->eliminate_macros($target));
             }
 
-            $m .= sprintf <<'MAKE_FRAG', ($target) x 2, ($plfile) x 2, $target;
+           # Normally a .PL file runs AFTER pm_to_blib so it can have
+           # blib in its @INC and load the just built modules.  BUT if
+           # the generated module is something in $(TO_INST_PM) which
+           # pm_to_blib depends on then it can't depend on pm_to_blib
+           # else we have a dependency loop.
+           my $pm_dep;
+           my $perlrun;
+           if( defined $self->{PM}{$target} ) {
+               $pm_dep  = '';
+               $perlrun = 'PERLRUN';
+           }
+           else {
+               $pm_dep  = 'pm_to_blib';
+               $perlrun = 'PERLRUNINST';
+           }
 
-all :: %s
-       $(NOECHO) $(NOOP)
+            $m .= <<MAKE_FRAG;
+
+all :: $target
+       \$(NOECHO) \$(NOOP)
 
-%s :: %s pm_to_blib
-       $(PERLRUNINST) %s %s
+$target :: $plfile $pm_dep
+       \$($perlrun) $plfile $target
 MAKE_FRAG
 
        }
@@ -3126,7 +3191,7 @@ sub oneliner {
 
     $switches = join ' ', @$switches;
 
-    return qq{\$(ABSPERLRUN) $switches -e $cmd};   
+    return qq{\$(ABSPERLRUN) $switches -e $cmd --};   
 }
 
 
@@ -3350,6 +3415,7 @@ sub test {
     }
     # note: 'test.pl' name is also hardcoded in init_dirscan()
     my(@m);
+    my $subdirs_test = ($self->{DIR} && @{$self->{DIR}} ? 'subdirs-test' : '');
     push(@m,"
 TEST_VERBOSE=0
 TEST_TYPE=test_\$(LINKTYPE)
@@ -3359,17 +3425,17 @@ TESTDB_SW = -d
 
 testdb :: testdb_\$(LINKTYPE)
 
-test :: \$(TEST_TYPE)
+test :: \$(TEST_TYPE) $subdirs_test
 ");
 
     foreach my $dir (@{ $self->{DIR} }) {
         my $test = $self->oneliner(sprintf <<'CODE', $dir);
 chdir '%s';  
-system '$(MAKE) test $(PASTHRU)' 
+system '$(MAKE) $(USEMAKEFILE) $(FIRST_MAKEFILE) test $(PASTHRU)' 
     if -f '$(FIRST_MAKEFILE)';
 CODE
 
-        push(@m, "\t\$(NOECHO) $test\n");
+        push(@m, "\nsubdirs-test ::\n\t\$(NOECHO) $test\n");
     }
 
     push(@m, "\t\$(NOECHO) \$(ECHO) 'No tests defined for \$(NAME) extension.'\n")