Upgrade to ExtUtils::CBuilder 0.12 and ExtUtils::ParseXS 2.10
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / MM_Win32.pm
index da1440f..4998c74 100644 (file)
@@ -19,7 +19,7 @@ the semantics.
 
 =cut 
 
-use Config;
+use ExtUtils::MakeMaker::Config;
 use File::Basename;
 use File::Spec;
 use ExtUtils::MakeMaker qw( neatvalue );
@@ -29,7 +29,7 @@ use vars qw(@ISA $VERSION $BORLAND $GCC $DMAKE $NMAKE);
 require ExtUtils::MM_Any;
 require ExtUtils::MM_Unix;
 @ISA = qw( ExtUtils::MM_Any ExtUtils::MM_Unix );
-$VERSION = '1.06';
+$VERSION = '1.12';
 
 $ENV{EMXSHELL} = 'sh'; # to run `commands`
 
@@ -121,20 +121,6 @@ sub maybe_command {
 }
 
 
-=item B<find_tests>
-
-The Win9x shell does not expand globs and I'll play it safe and assume
-other Windows variants don't either.
-
-So we do it for them.
-
-=cut
-
-sub find_tests {
-    return join(' ', <t\\*.t>);
-}
-
-
 =item B<init_DIRFILESEP>
 
 Using \ for Windows.
@@ -144,8 +130,10 @@ Using \ for Windows.
 sub init_DIRFILESEP {
     my($self) = shift;
 
-    # gotta be careful this isn't interpreted as an escape.
-    $self->{DIRFILESEP} = '^\\';
+    # The ^ makes sure its not interpreted as an escape in nmake
+    $self->{DIRFILESEP} = $NMAKE ? '^\\' :
+                          $DMAKE ? '\\\\'
+                                 : '\\';
 }
 
 =item B<init_others>
@@ -166,23 +154,31 @@ sub init_others {
     my ($self) = @_;
 
     # Used in favor of echo because echo won't strip quotes. :(
-    $self->{ECHO}     ||= '$(PERLRUN) -le "print qq{@ARGV}"';
-    $self->{TOUCH}    ||= '$(PERLRUN) -MExtUtils::Command -e touch';
-    $self->{CHMOD}    ||= '$(PERLRUN) -MExtUtils::Command -e chmod'; 
-    $self->{CP}       ||= '$(PERLRUN) -MExtUtils::Command -e cp';
-    $self->{RM_F}     ||= '$(PERLRUN) -MExtUtils::Command -e rm_f';
-    $self->{RM_RF}    ||= '$(PERLRUN) -MExtUtils::Command -e rm_rf';
-    $self->{MV}       ||= '$(PERLRUN) -MExtUtils::Command -e mv';
+    $self->{ECHO}     ||= $self->oneliner('print qq{@ARGV}', ['-l']);
+    $self->{ECHO_N}   ||= $self->oneliner('print qq{@ARGV}');
+
+    $self->{TOUCH}    ||= '$(ABSPERLRUN) -MExtUtils::Command -e touch';
+    $self->{CHMOD}    ||= '$(ABSPERLRUN) -MExtUtils::Command -e chmod'; 
+    $self->{CP}       ||= '$(ABSPERLRUN) -MExtUtils::Command -e cp';
+    $self->{RM_F}     ||= '$(ABSPERLRUN) -MExtUtils::Command -e rm_f';
+    $self->{RM_RF}    ||= '$(ABSPERLRUN) -MExtUtils::Command -e rm_rf';
+    $self->{MV}       ||= '$(ABSPERLRUN) -MExtUtils::Command -e mv';
     $self->{NOOP}     ||= 'rem';
-    $self->{TEST_F}   ||= '$(PERLRUN) -MExtUtils::Command -e test_f';
+    $self->{TEST_F}   ||= '$(ABSPERLRUN) -MExtUtils::Command -e test_f';
     $self->{DEV_NULL} ||= '> NUL';
 
-    # technically speaking, these should be in init_main()
+    $self->{FIXIN}    ||= $self->{PERL_CORE} ? 
+      "\$(PERLRUN) $self->{PERL_SRC}/win32/bin/pl2bat.pl" : 
+      'pl2bat.bat';
+
     $self->{LD}     ||= $Config{ld} || 'link';
     $self->{AR}     ||= $Config{ar} || 'lib';
 
     $self->SUPER::init_others;
 
+    # Setting SHELL from $Config{sh} can break dmake.  Its ok without it.
+    delete $self->{SHELL};
+
     $self->{LDLOADLIBS} ||= $Config{libs};
     # -Lfoo must come first for Borland, so we put it in LDDLFLAGS
     if ($BORLAND) {
@@ -201,11 +197,11 @@ sub init_others {
 }
 
 
-=item init_platform (o)
+=item init_platform
 
 Add MM_Win32_VERSION.
 
-=item platform_constants (o)
+=item platform_constants
 
 =cut
 
@@ -229,7 +225,7 @@ sub platform_constants {
 }
 
 
-=item special_targets (o)
+=item special_targets
 
 Add .USESHELL target for dmake.
 
@@ -248,7 +244,7 @@ MAKE_FRAG
 }
 
 
-=item static_lib (o)
+=item static_lib
 
 Changes how to run the linker.
 
@@ -263,7 +259,7 @@ sub static_lib {
 
     my(@m);
     push(@m, <<'END');
-$(INST_STATIC): $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)$(DIRFILESEP).exists
+$(INST_STATIC): $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)$(DFSEP).exists
        $(RM_RF) $@
 END
 
@@ -286,12 +282,11 @@ q{        $(AR) }.($BORLAND ? '$@ $(OBJECT:^"+")'
        $(NOECHO) $(ECHO) "$(EXTRALIBS)" >> $(PERL_SRC)\ext.libs
 MAKE_FRAG
 
-    push @m, "\n", $self->dir_target('$(INST_ARCHAUTODIR)');
     join('', @m);
 }
 
 
-=item dynamic_lib (o)
+=item dynamic_lib
 
 Complicated stuff for Win32 that I don't understand. :(
 
@@ -325,7 +320,7 @@ sub dynamic_lib {
 OTHERLDFLAGS = '.$otherldflags.'
 INST_DYNAMIC_DEP = '.$inst_dynamic_dep.'
 
-$(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DIRFILESEP).exists $(EXPORT_LIST) $(PERL_ARCHIVE) $(INST_DYNAMIC_DEP)
+$(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DFSEP).exists $(EXPORT_LIST) $(PERL_ARCHIVE) $(INST_DYNAMIC_DEP)
 ');
     if ($GCC) {
       push(@m,  
@@ -350,28 +345,20 @@ $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DIRFILE
        $(CHMOD) $(PERM_RWX) $@
 ';
 
-    push @m, $self->dir_target('$(INST_ARCHAUTODIR)');
     join('',@m);
 }
 
-=item clean
+=item extra_clean_files
 
 Clean out some extra dll.{base,exp} files which might be generated by
 gcc.  Otherwise, take out all *.pdb files.
 
 =cut
 
-sub clean
-{
-    my ($self) = shift;
-    my $s = $self->SUPER::clean(@_);
-    my $clean = $GCC ? 'dll.base dll.exp' : '*.pdb';
-    $s .= <<END;
-clean ::
-       -\$(RM_F) $clean
+sub extra_clean_files {
+    my $self = shift;
 
-END
-    return $s;
+    return $GCC ? (qw(dll.base dll.exp)) : ('*.pdb');
 }
 
 =item init_linker
@@ -403,7 +390,7 @@ sub perl_script {
 }
 
 
-=item xs_o (o)
+=item xs_o
 
 This target is stubbed out.  Not sure why.
 
@@ -414,7 +401,7 @@ sub xs_o {
 }
 
 
-=item pasthru (o)
+=item pasthru
 
 All we send is -nologo to nmake to prevent it from printing its damned
 banner.
@@ -427,7 +414,7 @@ sub pasthru {
 }
 
 
-=item oneliner (o)
+=item oneliner
 
 These are based on what command.com does on Win98.  They may be wrong
 for other Windows shells, I don't know.
@@ -447,7 +434,7 @@ sub oneliner {
 
     $switches = join ' ', @$switches;
 
-    return qq{\$(PERLRUN) $switches -e $cmd};
+    return qq{\$(ABSPERLRUN) $switches -e $cmd};
 }
 
 
@@ -458,6 +445,15 @@ sub quote_literal {
     # Win98's command.com
     $text =~ s{"}{\\"}g;
 
+    # dmake eats '{' inside double quotes and leaves alone { outside double
+    # quotes; however it transforms {{ into { either inside and outside double
+    # quotes.  It also translates }} into }.  The escaping below is not
+    # 100% correct.
+    if( $DMAKE ) {
+        $text =~ s/{/{{/g;
+        $text =~ s/}}/}}}/g;
+    }
+
     return qq{"$text"};
 }
 
@@ -472,16 +468,62 @@ sub escape_newlines {
 }
 
 
+=item cd
+
+dmake can handle Unix style cd'ing but nmake (at least 1.5) cannot.  It
+wants:
+
+    cd dir
+    command
+    another_command
+    cd ..
+
+B<NOTE> This cd can only go one level down.  So far this sufficient for
+what MakeMaker needs.
+
+=cut
+
+sub cd {
+    my($self, $dir, @cmds) = @_;
+
+    return $self->SUPER::cd($dir, @cmds) unless $NMAKE;
+
+    my $cmd = join "\n\t", map "$_", @cmds;
+
+    # No leading tab and no trailing newline makes for easier embedding.
+    my $make_frag = sprintf <<'MAKE_FRAG', $dir, $cmd;
+cd %s
+       %s
+       cd ..
+MAKE_FRAG
+
+    chomp $make_frag;
+
+    return $make_frag;
+}
+
+
 =item max_exec_len
 
-Using 31K, a safe number gotten from Windows 2000.
+nmake 1.50 limits command length to 2048 characters.
 
 =cut
 
 sub max_exec_len {
     my $self = shift;
 
-    return $self->{_MAX_EXEC_LEN} ||= 31 * 1024;
+    return $self->{_MAX_EXEC_LEN} ||= 2 * 1024;
+}
+
+
+=item os_flavor
+
+Windows is Win32.
+
+=cut
+
+sub os_flavor {
+    return('Win32');
 }