This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Continue what #4494 started; introduce uid and gid formats.
[perl5.git] / lib / ExtUtils / MM_Unix.pm
index 0e4712c..9a8aefb 100644 (file)
@@ -11,8 +11,7 @@ use vars qw($VERSION $Is_Mac $Is_OS2 $Is_VMS $Is_Win32 $Is_Dos $Is_PERL_OBJECT
 $VERSION = substr q$Revision: 1.12602 $, 10;
 # $Id: MM_Unix.pm,v 1.126 1998/06/28 21:32:49 k Exp k $
 
-Exporter::import('ExtUtils::MakeMaker',
-       qw( $Verbose &neatvalue));
+Exporter::import('ExtUtils::MakeMaker', qw($Verbose &neatvalue));
 
 $Is_OS2 = $^O eq 'os2';
 $Is_Mac = $^O eq 'MacOS';
@@ -378,7 +377,7 @@ sub cflags {
 
     if ($Is_PERL_OBJECT) {
         $self->{CCFLAGS} =~ s/-DPERL_OBJECT(\b|$)/-DPERL_CAPI/g;
-        if ($Is_Win32 && $Config{'cc'} =~ /^cl.exe/i) {
+        if ($Is_Win32 && $Config{'cc'} =~ /^cl/i) {
             # Turn off C++ mode of the MSC compiler
             $self->{CCFLAGS} =~ s/-TP(\s|$)//;
             $self->{OPTIMIZE} =~ s/-TP(\s|$)//;
@@ -389,12 +388,20 @@ sub cflags {
        $self->{CCFLAGS} .= ' -DPERL_POLLUTE ';
     }
 
+    my $pollute = '';
+    if ($Config{usemymalloc} and not $Config{bincompat5005}
+       and not $Config{ccflags} =~ /-DPERL_POLLUTE_MALLOC\b/
+       and $self->{PERL_MALLOC_OK}) {
+       $pollute = '$(PERL_MALLOC_DEF)';
+    }
+
     return $self->{CFLAGS} = qq{
 CCFLAGS = $self->{CCFLAGS}
 OPTIMIZE = $self->{OPTIMIZE}
 PERLTYPE = $self->{PERLTYPE}
 LARGE = $self->{LARGE}
 SPLIT = $self->{SPLIT}
+MPOLLUTE = $pollute
 };
 
 }
@@ -418,7 +425,19 @@ clean ::
 ');
     # clean subdirectories first
     for $dir (@{$self->{DIR}}) {
-       push @m, "\t-cd $dir && \$(TEST_F) $self->{MAKEFILE} && \$(MAKE) clean\n";
+       if ($Is_Win32  &&  Win32::IsWin95()) {
+           push @m, <<EOT;
+       cd $dir
+       \$(TEST_F) $self->{MAKEFILE}
+       \$(MAKE) clean
+       cd ..
+EOT
+       }
+       else {
+           push @m, <<EOT;
+       -cd $dir && \$(TEST_F) $self->{MAKEFILE} && \$(MAKE) clean
+EOT
+       }
     }
 
     my(@otherfiles) = values %{$self->{XS}}; # .c files from *.xs files
@@ -451,7 +470,7 @@ sub const_cccmd {
     return '' unless $self->needs_linking();
     return $self->{CONST_CCCMD} =
        q{CCCMD = $(CC) -c $(INC) $(CCFLAGS) $(OPTIMIZE) \\
-       $(PERLTYPE) $(LARGE) $(SPLIT) $(DEFINE_VERSION) \\
+       $(PERLTYPE) $(LARGE) $(SPLIT) $(MPOLLUTE) $(DEFINE_VERSION) \\
        $(XS_DEFINE_VERSION)};
 }
 
@@ -536,6 +555,7 @@ VERSION_MACRO = VERSION
 DEFINE_VERSION = -D\$(VERSION_MACRO)=\\\"\$(VERSION)\\\"
 XS_VERSION_MACRO = XS_VERSION
 XS_DEFINE_VERSION = -D\$(XS_VERSION_MACRO)=\\\"\$(XS_VERSION)\\\"
+PERL_MALLOC_DEF = -DPERL_EXTMALLOC_DEF -Dmalloc=Perl_malloc -Dfree=Perl_mfree -Drealloc=Perl_realloc -Dcalloc=Perl_calloc
 };
 
     push @m, qq{
@@ -1383,9 +1403,9 @@ sub init_dirscan {        # --- File and Directory Lists (.xs .pm .pod etc)
            $h{$name} = 1;
        } elsif ($name =~ /\.PL$/) {
            ($pl_files{$name} = $name) =~ s/\.PL$// ;
-       } elsif ($Is_VMS && $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
+           # under Unix appears as foo.h_pl under VMS or fooh.pl on Dos
            local($/); open(PL,$name); my $txt = <PL>; close PL;
            if ($txt =~ /Extracting \S+ \(with variable substitutions/) {
                ($pl_files{$name} = $name) =~ s/[._]pl$//i ;
@@ -1666,10 +1686,34 @@ from the perl source tree.
        }
     } else {
        # we should also consider $ENV{PERL5LIB} here
+        my $old = $self->{PERL_LIB} || $self->{PERL_ARCHLIB} || $self->{PERL_INC};
        $self->{PERL_LIB}     ||= $Config::Config{privlibexp};
        $self->{PERL_ARCHLIB} ||= $Config::Config{archlibexp};
        $self->{PERL_INC}     = $self->catdir("$self->{PERL_ARCHLIB}","CORE"); # wild guess for now
        my $perl_h;
+
+       if (not -f ($perl_h = $self->catfile($self->{PERL_INC},"perl.h"))
+           and not $old){
+           # Maybe somebody tries to build an extension with an
+           # uninstalled Perl outside of Perl build tree
+           my $found;
+           for my $dir (@INC) {
+             $found = $dir, last if -e $self->catdir($dir, "Config.pm");
+           }
+           if ($found) {
+             my $inc = dirname $found;
+             if (-e $self->catdir($inc, "perl.h")) {
+               $self->{PERL_LIB}          = $found;
+               $self->{PERL_ARCHLIB}      = $found;
+               $self->{PERL_INC}          = $inc;
+               $self->{UNINSTALLED_PERL}  = 1;
+               print STDOUT <<EOP;
+... Detected uninstalled Perl.  Trying to continue.
+EOP
+             }
+           }
+       }
+       
        unless (-f ($perl_h = $self->catfile($self->{PERL_INC},"perl.h"))){
            die qq{
 Error: Unable to locate installed Perl libraries or Perl source code.
@@ -1760,8 +1804,7 @@ usually solves this kind of problem.
 
     my($install_variable,$search_prefix,$replace_prefix);
 
-    # The rule, taken from Configure, is that if prefix contains perl,
-    # we shape the tree
+    # If the prefix contains perl, Configure shapes the tree as follows:
     #    perlprefix/lib/                INSTALLPRIVLIB
     #    perlprefix/lib/pod/
     #    perlprefix/lib/site_perl/     INSTALLSITELIB
@@ -1773,6 +1816,11 @@ usually solves this kind of problem.
     #    prefix/lib/perl5/site_perl/   INSTALLSITELIB
     #    prefix/bin/                   INSTALLBIN
     #    prefix/lib/perl5/man/         INSTALLMAN1DIR
+    #
+    # The above results in various kinds of breakage on various
+    # platforms, so we cope with it as follows: if prefix/lib/perl5
+    # or prefix/lib/perl5/man exist, we'll replace those instead
+    # of /prefix/{lib,man}
 
     $replace_prefix = qq[\$\(PREFIX\)];
     for $install_variable (qw/
@@ -1781,36 +1829,45 @@ usually solves this kind of problem.
                           /) {
        $self->prefixify($install_variable,$configure_prefix,$replace_prefix);
     }
-    $search_prefix = $configure_prefix =~ /perl/ ?
-       $self->catdir($configure_prefix,"lib") :
-       $self->catdir($configure_prefix,"lib","perl5");
+    my $funkylibdir = $self->catdir($configure_prefix,"lib","perl5");
+    $funkylibdir = '' unless -d $funkylibdir;
+    $search_prefix = $funkylibdir || $self->catdir($configure_prefix,"lib");
     if ($self->{LIB}) {
        $self->{INSTALLPRIVLIB} = $self->{INSTALLSITELIB} = $self->{LIB};
        $self->{INSTALLARCHLIB} = $self->{INSTALLSITEARCH} = 
            $self->catdir($self->{LIB},$Config{'archname'});
-    } else {
-       $replace_prefix = $self->{PREFIX} =~ /perl/ ? 
-           $self->catdir(qq[\$\(PREFIX\)],"lib") :
-               $self->catdir(qq[\$\(PREFIX\)],"lib","perl5");
+    }
+    else {
+       if (-d $self->catdir($self->{PREFIX},"lib","perl5")) {
+           $replace_prefix = $self->catdir(qq[\$\(PREFIX\)],"lib", "perl5");
+       }
+       else {
+           $replace_prefix = $self->catdir(qq[\$\(PREFIX\)],"lib");
+       }
        for $install_variable (qw/
                               INSTALLPRIVLIB
                               INSTALLARCHLIB
                               INSTALLSITELIB
                               INSTALLSITEARCH
-                              /) {
+                              /)
+       {
            $self->prefixify($install_variable,$search_prefix,$replace_prefix);
        }
     }
-    $search_prefix = $configure_prefix =~ /perl/ ?
-       $self->catdir($configure_prefix,"man") :
-           $self->catdir($configure_prefix,"lib","perl5","man");
-    $replace_prefix = $self->{PREFIX} =~ /perl/ ? 
-       $self->catdir(qq[\$\(PREFIX\)],"man") :
-           $self->catdir(qq[\$\(PREFIX\)],"lib","perl5","man");
+    my $funkymandir = $self->catdir($configure_prefix,"lib","perl5","man");
+    $funkymandir = '' unless -d $funkymandir;
+    $search_prefix = $funkymandir || $self->catdir($configure_prefix,"man");
+    if (-d $self->catdir($self->{PREFIX},"lib","perl5", "man")) {
+       $replace_prefix = $self->catdir(qq[\$\(PREFIX\)],"lib", "perl5", "man");
+    }
+    else {
+       $replace_prefix = $self->catdir(qq[\$\(PREFIX\)],"man");
+    }
     for $install_variable (qw/
                           INSTALLMAN1DIR
                           INSTALLMAN3DIR
-                          /) {
+                          /)
+    {
        $self->prefixify($install_variable,$search_prefix,$replace_prefix);
     }
 
@@ -2078,6 +2135,7 @@ pure_site_install ::
                }.$self->catdir('$(PERL_ARCHLIB)','auto','$(FULLEXT)').q{
 
 doc_perl_install ::
+       -}.$self->{NOECHO}.q{$(MKPATH) $(INSTALLARCHLIB)
        -}.$self->{NOECHO}.q{$(DOC_INSTALL) \
                "Module" "$(NAME)" \
                "installed into" "$(INSTALLPRIVLIB)" \
@@ -2087,6 +2145,7 @@ doc_perl_install ::
                >> }.$self->catfile('$(INSTALLARCHLIB)','perllocal.pod').q{
 
 doc_site_install ::
+       -}.$self->{NOECHO}.q{$(MKPATH) $(INSTALLARCHLIB)
        -}.$self->{NOECHO}.q{$(DOC_INSTALL) \
                "Module" "$(NAME)" \
                "installed into" "$(INSTALLSITELIB)" \
@@ -2453,6 +2512,7 @@ $tmp/perlmain.c: $makefilename}, q{
     push @m, q{
 doc_inst_perl:
        }.$self->{NOECHO}.q{echo Appending installation info to $(INSTALLARCHLIB)/perllocal.pod
+       -}.$self->{NOECHO}.q{$(MKPATH) $(INSTALLARCHLIB)
        -}.$self->{NOECHO}.q{$(DOC_INSTALL) \
                "Perl binary" "$(MAP_TARGET)" \
                MAP_STATIC "$(MAP_STATIC)" \
@@ -2535,6 +2595,10 @@ sub manifypods {
        $pod2man_exe = $self->catfile($Config{scriptdirexp},'pod2man');
     }
     unless ($pod2man_exe = $self->perl_script($pod2man_exe)) {
+      # Maybe a build by uninstalled Perl?
+      $pod2man_exe = $self->catfile($self->{PERL_INC}, "pod", "pod2man");
+    }
+    unless ($pod2man_exe = $self->perl_script($pod2man_exe)) {
        # No pod2man but some MAN3PODS to be installed
        print <<END;
 
@@ -2661,7 +2725,9 @@ sub nicetext {
 
 =item parse_version
 
-parse a file and return what you think is $VERSION in this file set to
+parse a file and return what you think is $VERSION in this file set to.
+It will return the string "undef" if it can't figure out what $VERSION
+is.
 
 =cut
 
@@ -2689,7 +2755,7 @@ sub parse_version {
        };
        local($^W) = 0;
        $result = eval($eval);
-       die "Could not eval '$eval' in $parsefile: $@" if $@;
+       warn "Could not eval '$eval' in $parsefile: $@" if $@;
        $result = "undef" unless defined $result;
        last;
     }
@@ -3020,7 +3086,9 @@ sub realclean {
 realclean purge ::  clean
 ');
     # realclean subdirectories first (already cleaned)
-    my $sub = "\t-cd %s && \$(TEST_F) %s && \$(MAKE) %s realclean\n";
+    my $sub = ($Is_Win32  &&  Win32::IsWin95()) ?
+      "\tcd %s\n\t\$(TEST_F) %s\n\t\$(MAKE) %s realclean\n\tcd ..\n" :
+      "\t-cd %s && \$(TEST_F) %s && \$(MAKE) %s realclean\n";
     foreach(@{$self->{DIR}}){
        push(@m, sprintf($sub,$_,"$self->{MAKEFILE}.old","-f $self->{MAKEFILE}.old"));
        push(@m, sprintf($sub,$_,"$self->{MAKEFILE}",''));
@@ -3164,12 +3232,22 @@ Helper subroutine for subdirs
 sub subdir_x {
     my($self, $subdir) = @_;
     my(@m);
-    qq{
+    if ($Is_Win32 && Win32::IsWin95()) {
+       return <<EOT;
+subdirs ::
+       cd $subdir
+       \$(MAKE) all \$(PASTHRU)
+       cd ..
+EOT
+    }
+    else {
+       return <<EOT;
 
 subdirs ::
        $self->{NOECHO}cd $subdir && \$(MAKE) all \$(PASTHRU)
 
-};
+EOT
+    }
 }
 
 =item subdirs (o)