OS/390 cleanable gunk.
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / MM_Unix.pm
index 0254818..da84461 100644 (file)
@@ -7,7 +7,7 @@ use Config;
 use File::Basename qw(basename dirname fileparse);
 use DirHandle;
 use strict;
-our ($Is_Mac,$Is_OS2,$Is_VMS,$Is_Win32,$Is_Dos,$Is_PERL_OBJECT,
+our ($Is_Mac,$Is_OS2,$Is_VMS,$Is_Win32,$Is_Dos,
            $Verbose,%pm,%static,$Xsubpp_Version);
 
 our $VERSION = '1.12603';
@@ -20,8 +20,6 @@ $Is_Mac = $^O eq 'MacOS';
 $Is_Win32 = $^O eq 'MSWin32';
 $Is_Dos = $^O eq 'dos';
 
-$Is_PERL_OBJECT = $Config{'ccflags'} =~ /-DPERL_OBJECT/;
-
 if ($Is_VMS = $^O eq 'VMS') {
     require VMS::Filespec;
     import VMS::Filespec qw( &vmsify );
@@ -222,6 +220,7 @@ sub ExtUtils::MM_Unix::postamble ;
 sub ExtUtils::MM_Unix::ppd ;
 sub ExtUtils::MM_Unix::prefixify ;
 sub ExtUtils::MM_Unix::processPL ;
+sub ExtUtils::MM_Unix::quote_paren ;
 sub ExtUtils::MM_Unix::realclean ;
 sub ExtUtils::MM_Unix::replace_manpage_separator ;
 sub ExtUtils::MM_Unix::static ;
@@ -274,30 +273,30 @@ sub c_o {
         $cpp_cmd =~ s/^CCCMD\s*=\s*\$\(CC\)/$cpp/;
         push @m, '
 .c.i:
-       '. $cpp_cmd . ' $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.c > $*.i
+       '. $cpp_cmd . ' $(CCCDLFLAGS) -I$(PERL_INC) $(PASTHRU_DEFINE) $(DEFINE) $*.c > $*.i
 ';
     }
     push @m, '
 .c.s:
-       $(CCCMD) -S $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.c
+       $(CCCMD) -S $(CCCDLFLAGS) -I$(PERL_INC) $(PASTHRU_DEFINE) $(DEFINE) $*.c
 ';
     push @m, '
 .c$(OBJ_EXT):
-       $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.c
+       $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(PASTHRU_DEFINE) $(DEFINE) $*.c
 ';
     push @m, '
 .C$(OBJ_EXT):
-       $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.C
+       $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(PASTHRU_DEFINE) $(DEFINE) $*.C
 ' if $^O ne 'os2' and $^O ne 'MSWin32' and $^O ne 'dos'; #Case-specific
     push @m, '
 .cpp$(OBJ_EXT):
-       $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.cpp
+       $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(PASTHRU_DEFINE) $(DEFINE) $*.cpp
 
 .cxx$(OBJ_EXT):
-       $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.cxx
+       $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(PASTHRU_DEFINE) $(DEFINE) $*.cxx
 
 .cc$(OBJ_EXT):
-       $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.cc
+       $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(PASTHRU_DEFINE) $(DEFINE) $*.cc
 ';
     join "", @m;
 }
@@ -388,27 +387,6 @@ sub cflags {
        $self->{uc $_} ||= $cflags{$_}
     }
 
-    if ($Is_PERL_OBJECT) {
-        $self->{CCFLAGS} =~ s/-DPERL_OBJECT(\b|$)/-DPERL_CAPI/g;
-        if ($Is_Win32) { 
-           if ($Config{'cc'} =~ /^cl/i) {
-               # Turn off C++ mode of the MSC compiler
-               $self->{CCFLAGS} =~ s/-TP(\s|$)//g;
-               $self->{OPTIMIZE} =~ s/-TP(\s|$)//g;
-           }
-           elsif ($Config{'cc'} =~ /^bcc32/i) {
-               # Turn off C++ mode of the Borland compiler
-               $self->{CCFLAGS} =~ s/-P(\s|$)//g;
-               $self->{OPTIMIZE} =~ s/-P(\s|$)//g;
-           }
-           elsif ($Config{'cc'} =~ /^gcc/i) {
-               # Turn off C++ mode of the GCC compiler
-               $self->{CCFLAGS} =~ s/-xc\+\+(\s|$)//g;
-               $self->{OPTIMIZE} =~ s/-xc\+\+(\s|$)//g;
-           }
-        }
-    }
-
     if ($self->{POLLUTE}) {
        $self->{CCFLAGS} .= ' -DPERL_POLLUTE ';
     }
@@ -420,6 +398,9 @@ sub cflags {
        $pollute = '$(PERL_MALLOC_DEF)';
     }
 
+    $self->{CCFLAGS}  = quote_paren($self->{CCFLAGS});
+    $self->{OPTIMIZE} = quote_paren($self->{CCFLAGS});
+
     return $self->{CFLAGS} = qq{
 CCFLAGS = $self->{CCFLAGS}
 OPTIMIZE = $self->{OPTIMIZE}
@@ -478,7 +459,7 @@ EOT
                         *$(OBJ_EXT) *$(LIB_EXT) perl.exe perl perl$(EXE_EXT)
                         $(BOOTSTRAP) $(BASEEXT).bso
                         $(BASEEXT).def lib$(BASEEXT).def
-                        $(BASEEXT).exp
+                        $(BASEEXT).exp $(BASEEXT).x
                        ]);
     push @m, "\t-$self->{RM_RF} @otherfiles\n";
     # See realclean and ext/utils/make_ext for usage of Makefile.old
@@ -501,7 +482,8 @@ sub const_cccmd {
     return $self->{CONST_CCCMD} if $self->{CONST_CCCMD};
     return '' unless $self->needs_linking();
     return $self->{CONST_CCCMD} =
-       q{CCCMD = $(CC) -c $(INC) $(CCFLAGS) $(OPTIMIZE) \\
+       q{CCCMD = $(CC) -c $(PASTHRU_INC) $(INC) \\
+       $(CCFLAGS) $(OPTIMIZE) \\
        $(PERLTYPE) $(MPOLLUTE) $(DEFINE_VERSION) \\
        $(XS_DEFINE_VERSION)};
 }
@@ -524,7 +506,8 @@ sub const_config {
     foreach $m (@{$self->{CONFIG}}){
        # SITE*EXP macros are defined in &constants; avoid duplicates here
        next if $once_only{$m} or $m eq 'sitelibexp' or $m eq 'sitearchexp';
-       push @m, "\U$m\E = ".$self->{uc $m}."\n";
+       $self->{uc $m} = quote_paren($self->{uc $m});
+       push @m, uc($m) , ' = ' , $self->{uc $m}, "\n";
        $once_only{$m} = 1;
     }
     join('', @m);
@@ -1606,7 +1589,7 @@ sub init_dirscan {        # --- File and Directory Lists (.xs .pm .pod etc)
        # 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 ($name =~ /(config|setup).*\.pm/is) {
+           if ($self->{PERL_CORE} and $name =~ /(config|setup).*\.pm/is) {
                delete $manifypods{$name};
                next;
            }
@@ -1818,7 +1801,7 @@ usually solves this kind of problem.
     $self->{INST_SCRIPT} ||= $self->catdir($self->curdir,'blib','script');
 
     # The user who requests an installation directory explicitly
-    # should not have to tell us a architecture installation directory
+    # should not have to tell us an architecture installation directory
     # as well. We look if a directory exists that is named after the
     # architecture. If not we take it as a sign that it should be the
     # same as the requested installation directory. Otherwise we take
@@ -2806,7 +2789,7 @@ sub parse_version {
     my $inpod = 0;
     while (<FH>) {
        $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
-       next if $inpod;
+       next if $inpod || /^\s*#/;
        chop;
        # next unless /\$(([\w\:\']*)\bVERSION)\b.*\=/;
        next unless /([\$*])(([\w\:\']*)\bVERSION)\b.*\=/;
@@ -2871,10 +2854,14 @@ sub pasthru {
     my($sep) = $Is_VMS ? ',' : '';
     $sep .= "\\\n\t";
 
-    foreach $key (qw(LIB LIBPERL_A LINKTYPE PREFIX OPTIMIZE INC DEFINE)){
+    foreach $key (qw(LIB LIBPERL_A LINKTYPE PREFIX OPTIMIZE)) {
        push @pasthru, "$key=\"\$($key)\"";
     }
 
+    foreach $key (qw(DEFINE INC)) {
+       push @pasthru, "PASTHRU_$key=\"\$(PASTHRU_$key)\"";
+    }
+
     push @m, "\nPASTHRU = ", join ($sep, @pasthru), "\n";
     join "", @m;
 }
@@ -2956,7 +2943,6 @@ PERL_HDRS = \
        $(PERL_INC)/keywords.h          \
        $(PERL_INC)/mg.h                \
        $(PERL_INC)/nostdio.h           \
-       $(PERL_INC)/objXSUB.h           \
        $(PERL_INC)/op.h                \
        $(PERL_INC)/opcode.h            \
        $(PERL_INC)/opnames.h           \
@@ -3083,15 +3069,36 @@ destination and autosplits them. See L<ExtUtils::Install/DESCRIPTION>
 
 =cut
 
+sub _pm_to_blib_flush {
+    my ($self, $autodir, $rr, $ra, $rl) = @_;
+    $$rr .= 
+q{     }.$self->{NOECHO}.q[$(PERLRUNINST) -MExtUtils::Install \
+       -e "pm_to_blib({qw{].qq[@$ra].q[}},'].$autodir.q{','$(PM_FILTER)')"
+};
+    @$ra = ();
+    $$rl = 0;
+}
+
 sub pm_to_blib {
     my $self = shift;
     my($autodir) = $self->catdir('$(INST_LIB)','auto');
-    return q{
+    my $r = q{
 pm_to_blib: $(TO_INST_PM)
-       }.$self->{NOECHO}.q{$(PERLRUNINST) -MExtUtils::Install \
-        -e "pm_to_blib({qw{$(PM_TO_BLIB)}},'}.$autodir.q{','$(PM_FILTER)')"
-       }.$self->{NOECHO}.q{$(TOUCH) $@
 };
+    my %pm_to_blib = %{$self->{PM}};
+    my @a;
+    my $l;
+    while (my ($pm, $blib) = each %pm_to_blib) {
+       my $la = length $pm;
+       my $lb = length $blib;
+       if ($l + $la + $lb + @a / 2 > 200) { # limit line length
+           _pm_to_blib_flush($self, $autodir, \$r, \@a, \$l);
+        }
+        push @a, $pm, $blib;
+       $l += $la + $lb;
+    }
+    _pm_to_blib_flush($self, $autodir, \$r, \@a, \$l);
+    return $r.q{       }.$self->{NOECHO}.q{$(TOUCH) $@};
 }
 
 =item post_constants (o)
@@ -3175,6 +3182,22 @@ $target :: $plfile
     join "", @m;
 }
 
+=item quote_paren
+
+Backslashes parentheses C<()> in command line arguments.
+Doesn't handle recursive Makefile C<$(...)> constructs,
+but handles simple ones.
+
+=cut
+
+sub quote_paren {
+    local $_ = shift;
+    s/\$\((.+?)\)/\$\\\\($1\\\\)/g;    # protect $(...)
+    s/(?<!\\)([()])/\\$1/g;            # quote unprotected
+    s/\$\\\\\((.+?)\\\\\)/\$($1)/g;    # unprotect $(...)
+    return $_;
+}
+
 =item realclean (o)
 
 Defines the realclean target.
@@ -3367,7 +3390,7 @@ sub subdir_x {
 subdirs ::
 @[
        cd $subdir
-       \$(MAKE) all \$(PASTHRU)
+       \$(MAKE) -f \$(FIRST_MAKEFILE) all \$(PASTHRU)
        cd ..
 ]
 EOT
@@ -3376,7 +3399,7 @@ EOT
            return <<EOT;
 subdirs ::
        cd $subdir
-       \$(MAKE) all \$(PASTHRU)
+       \$(MAKE) -f \$(FIRST_MAKEFILE) all \$(PASTHRU)
        cd ..
 EOT
        }
@@ -3384,8 +3407,7 @@ EOT
        return <<EOT;
 
 subdirs ::
-       $self->{NOECHO}cd $subdir && \$(MAKE) all \$(PASTHRU)
-
+       $self->{NOECHO}cd $subdir && \$(MAKE) -f \$(FIRST_MAKEFILE) all \$(PASTHRU)
 EOT
     }
 }
@@ -3851,7 +3873,7 @@ sub xs_o {        # many makes are too dumb to use xs_c then c_o
     '
 .xs$(OBJ_EXT):
        $(PERLRUN) $(XSUBPP) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc && $(MV) $*.xsc $*.c
-       $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.c
+       $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(PASTHRU_DEFINE) $(DEFINE) $*.c
 ';
 }