I actually have Linux installed on this machine, but for reasons which
I'm not going to get into here I use Win98 for day-to-day computing. I
therefore took it as a challenge to get Parrot to build with crufty ol'
command.com.

I used MinGW 3.1.0-1 and ActivePerl 5.8.6.811 to build Parrot.

I configured Parrot with

   perl Configure.pl --cc=gcc --without-icu

I ran into a number of issues while trying to get Parrot to compile.

Problem 1 - If you try to redirect output to paths containing forward
slashes, command.com will complain (and not create the file).

Solution 1 - Configure the build system to use backslashes in Makefiles.
This functionality already exists, but was not fully enabled. I also
changed a few Perl scripts to use the 'slash' configuration parameter
instead of hard-coded forward slashes, and to perform variable
substitution before slash substitution.


Problem 2 - Redirecting output of a batch file does not redirect output
of the commands executed by it. The perldoc command supplied with
ActivePerl is a batch file.

Solution 2 - Use a command line switch to send perldoc's output to a
file instead of redirection.


Problem 3 - The value of $(MAKE) supplied by mingw32-make contains
forward slashes. This doesn't sit well with command.com.

Solution 3 - Override $(MAKE).


Problem 4 - Single backslashes in C strings are a no-no. This manifests
itself when filenames are inserted into the #line directives in
generated C code.
Solution 4 - Substitute double backslashes for single backslashes in
#line directives.

I include a patch I made for the above problems. Some of the changes are
kind of kludgey, so I would appreciate comments and suggestions on how to
improve them.


I still haven't gotten compilation to finish, but it's a lot further
along than when I started. Currently, it fails with a zillion "undefined
reference" errors on the command

g++ -s  -g  -shared   "C:/Users/Clement/src/parrot/parrot/src/extend.o"
-o python_group.dll "lib-python_group.o" "pybuiltin.o" "pyclass.o"
"pyobject.o" "pyboolean.o" "pycomplex.o" "pydict.o" "pyexception.o"
"pyfloat.o" "pyfunc.o" "pyboundmeth.o" "pyboundcall.o" "pynci.o"
"pystaticmeth.o" "pygen.o" "pyint.o" "pylist.o" "pylong.o" "pymodule.o"
"pynone.o" "pytype.o" "pyslice.o" "pystring.o" "pytuple.o"
"pyproxytype.o" "pyproxyclass.o" "pyiter.o"

C:/Users/Clement/src/parrot/parrot/src/extend.o(.text+0x306): In
function `Parrot_PMC_get_cstring_intkey':
C:/Users/Clement/src/parrot/parrot/src/extend.c:256: undefined reference
to `string_to_cstring'
C:/Users/Clement/src/parrot/parrot/src/extend.o(.text+0x363): In
function `Parrot_PMC_get_cstring':
C:/Users/Clement/src/parrot/parrot/src/extend.c:276: undefined reference
to `string_to_cstring'
C:/Users/Clement/src/parrot/parrot/src/extend.o(.text+0x3c6): In
function `Parrot_PMC_get_cstringn':
C:/Users/Clement/src/parrot/parrot/src/extend.c:299: undefined reference
to `string_to_cstring'

...

Index: build_tools/ops2c.pl
===================================================================
--- build_tools/ops2c.pl        (revision 8268)
+++ build_tools/ops2c.pl        (working copy)
@@ -411,7 +411,11 @@
 my $line = 0; while (<SOURCE>) { $line++; } $line+=2;
 close(SOURCE);
 open(SOURCE, ">>$source") || die "Error appending to $source: $!\n";
-print SOURCE qq{#line $line "$source"\n} unless $nolines_flag;
+unless ($nolines_flag) {
+    my $source_escaped = $source;
+    $source_escaped =~ s|(\\)|$1$1|g; # escape backslashes
+    print SOURCE qq{#line $line "$source_escaped"\n};
+}
 
 
 #
Index: lib/Parrot/Pmc2c.pm
===================================================================
--- lib/Parrot/Pmc2c.pm (revision 8268)
+++ lib/Parrot/Pmc2c.pm (working copy)
@@ -260,7 +260,11 @@
     my ($self, $line, $file) = @_;
 
     return '' if $self->{opt}{nolines};
-    return qq{#line $line "$file"\n} if defined $file;
+    if (defined $file) {
+        my $file_escaped = $file;
+        $file_escaped =~ s|(\\)|$1$1|g; # escape backslashes
+        return qq{#line $line "$file_escaped"\n};
+    }
     return qq{#line $line\n};
 }
 
Index: lib/Parrot/Configure/Step.pm
===================================================================
--- lib/Parrot/Configure/Step.pm        (revision 8268)
+++ lib/Parrot/Configure/Step.pm        (working copy)
@@ -223,26 +223,27 @@
             $_ = $2;
         }
     }
+    s{
+      \$\{(\w+)\}
+    }{
+      if(defined(my $val=Configure::Data->get($1))) {
+        #use Data::Dumper;warn Dumper("val for $1 is ",$val);
+        $val;
+      }
+      else {
+        warn "value for '$1' in $source is undef";
+        '';
+      }
+    }egx;
     if ( $options{replace_slashes} ) {
       s{(/+)}{
-       my $len = length $1;
-       my $slash = Configure::Data->get('slash');
-       '/' x ($len/2) . ($len%2 ? $slash : ''); }eg;
-      }
-      s{
-       \$\{(\w+)\}
-      }{
-       if(defined(my $val=Configure::Data->get($1))) {
-          #use Data::Dumper;warn Dumper("val for $1 is ",$val);
-         $val;
-       }
-       else {
-         warn "value for '$1' in $source is undef";
-         '';
-       }
-      }egx;
-      print OUT;
+        my $len = length $1;
+        my $slash = Configure::Data->get('slash');
+        '/' x ($len/2) . ($len%2 ? $slash : '');
+      }eg;
     }
+    print OUT;
+  }
 
     close IN  or die "Can't close $source: $!";
     close OUT or die "Can't close $target: $!";
Index: lib/Parrot/OpsFile.pm
===================================================================
--- lib/Parrot/OpsFile.pm       (revision 8268)
+++ lib/Parrot/OpsFile.pm       (working copy)
@@ -564,7 +564,9 @@
 
         $body =~ s/\$(\d+)/[EMAIL PROTECTED]/mg;
 
-        $op->body( $nolines ? $body : qq{#line $line "$file"\n$body} );
+        my $file_escaped = $file;
+        $file_escaped =~ s|(\\)|$1$1|g; # escape backslashes
+        $op->body( $nolines ? $body : qq{#line $line "$file_escaped"\n$body} );
 
         # Constants here are defined in include/parrot/op.h
         or_flag(\$jumps, "PARROT_JUMP_RELATIVE")   if ($branch);
Index: config/init/hints/mswin32.pl
===================================================================
--- config/init/hints/mswin32.pl        (revision 8268)
+++ config/init/hints/mswin32.pl        (working copy)
@@ -160,8 +160,10 @@
                                'link' => 'gcc',
                                'linkflags' => '-s ',
                                'make' => 'mingw32-make',
+                               'make_set_make' => 'MAKE = mingw32-make',
                                'ncilib_link_extra' => 'src/libnci_test.def',
                                'o' => '.o',
+                               'slash' => '\\',
                        );
                } elsif ($make =~ /dmake/i) {
                        # mingw Perl
Index: config/gen/makefiles/docs.in
===================================================================
--- config/gen/makefiles/docs.in        (revision 8268)
+++ config/gen/makefiles/docs.in        (working copy)
@@ -37,7 +37,7 @@
        $(MKDIR) ops
 
 packfile-c.pod: ../src/packfile.c
-       perldoc -u ../src/packfile.c > packfile-c.pod
+       perldoc -ud packfile-c.pod ../src/packfile.c 
 
 clean:
        $(RM_F) packfile-c.pod $(POD)
Index: config/gen/makefiles.pl
===================================================================
--- config/gen/makefiles.pl     (revision 8268)
+++ config/gen/makefiles.pl     (working copy)
@@ -125,18 +125,21 @@
     Configure::Data->set(pod => $pod);
   
     genfile('config/gen/makefiles/docs.in',      'docs/Makefile',
-            commentType => '#');
+            commentType     => '#',
+            replace_slashes => 1);
   
     Configure::Data->set(pod => undef);
   
     open MAKEFILE, ">> docs/Makefile" or die "open >> docs/Makefile: $!";
   
+    my $slash = Configure::Data->get('slash');
+  
     foreach my $ops (@ops) {
         my $pod = $ops;
         $pod =~ s/\.ops$/.pod/;
         print MAKEFILE <<"EOM";
-ops/$pod: ../ops/$ops
-       perldoc -u ../ops/$ops > ops/$pod
+ops$slash$pod: ..${slash}ops${slash}$ops
+       perldoc -ud ops${slash}$pod ..${slash}ops${slash}$ops
 
 EOM
     }

Reply via email to