On 2/8/2003 9:35 PM, Ken Williams wrote:
Hi Schwern and so on,

The ExtUtils::ParseXS, which is now on CPAN, provides functionality equivalent to the 'xsubpp' script, and replaces xsubpp on the user's system with a wrapper script around the ExtUtils::ParseXS functionality.

However, it installs this wrapper script in site_perl/ (or wherever the user installs modules), and MakeMaker only looks for xsubpp at PERL_LIB/xsubpp - see MM_Unix.pm line 3910 in CVS:

my($xsdir) = File::Spec->catdir($self->{PERL_LIB},"ExtUtils");
... then later ...
XSUBPPDIR = $xsdir
XSUBPP = \$(XSUBPPDIR)/$xsubpp

The PERL_LIB setting defaults to $Config{privlibexp}.

So the issues are the following:

1) Shouldn't MM look for xsubpp anywhere in @INC?

2) To workaround, how do I get MakeMaker to install xsubpp in PERL_LIB?

-Ken

I'm not a MakeMaker expert, but setting 'INSTALLDIRS=perl' seems to do the right thing by installing to PERL_LIB.

Unrelated to the problem above, I've attached a patch against ExtUtils::ParseXS 1.99 to fix severaly problems under MSWin32. The reason I've posted this to the mailing list is that some of the changes related to the test script are really bad hacks to construct the compile and link commands to build the test XS file, which is something that MakeMaker would be much better at. I thought someone here might make some better suggestions.

Changes include:
* Explicitly untie and close the output file handle because ParseXS was holding the file handle open, preventing the compiler from opening it.
* Added an '--output FILENAME' flag to xsubpp and changed ParseXS to use the named file in the #line directives when the output file has an extension other than '.c' (i.e. '.cpp').
* Added conditional definition of the PERL_UNUSED_VAR macro to the output file in case it's not already defined for backwards compatibility with pre-5.8 versions of perl. (Not sure if this is the best solution.)
* In testing ParseXS, I encountered one module that did not expect xsubpp to die when it parsed a file NOT containing a 'MODULE ... PACKAGE ... PREFIX' line. I changed ParseXS so that it instead issued a 'warn' ing. I'm pretty much convinced my change is wrong, but there may be other modules that depend on the old behaviour. The change only involved s/die/warn/ in one place, so it's easily undone.

The rest of the changes involve the test script, and it's really messy. I don't think that I broke anything for any other platform, but it really needs a cleaner solution. Maybe someone here can suggest a way to use MakeMaker to construct the correct commands for compiling and linking the test XS file???

Randy.
diff -ur ExtUtils-ParseXS-1.99-orig/lib/ExtUtils/ParseXS.pm 
ExtUtils-ParseXS-1.99/lib/ExtUtils/ParseXS.pm
--- ExtUtils-ParseXS-1.99-orig/lib/ExtUtils/ParseXS.pm  2003-02-05 13:06:56.000000000 
-0500
+++ ExtUtils-ParseXS-1.99/lib/ExtUtils/ParseXS.pm       2003-02-09 13:12:42.000000000 
+-0500
@@ -88,6 +88,7 @@
   # other kind of reference, trust them that we can print to it.
   if (not ref $args{output}) {
     open my($fh), "> $args{output}" or die "Can't create $args{output}: $!";
+    $args{outfile} = $args{output};
     $args{output} = $fh;
   }
 
@@ -100,11 +101,15 @@
   $pwd = cwd();
   
   if ($WantLineNumbers) {
-    my $cfile = $filename;
-    $cfile =~ s/\.xs$/.c/i or $cfile .= ".c";
+    my $cfile;
+    if ( $args{outfile} ) {
+      $cfile = $args{outfile};
+    } else {
+      $cfile = $filename;
+      $cfile =~ s/\.xs$/.c/i or $cfile .= ".c";
+    }
     tie(*PSEUDO_STDOUT, 'ExtUtils::ParseXS::CountLines', $cfile, $args{output});
     select PSEUDO_STDOUT;
-
   } else {
     select $args{output};
   }
@@ -253,7 +258,14 @@
     
     print $_;
   }
-  die "Didn't find a 'MODULE ... PACKAGE ... PREFIX' line\n" unless defined $_;
+  warn "Didn't find a 'MODULE ... PACKAGE ... PREFIX' line\n" unless defined $_;
+
+    print <<"EOF";
+#ifndef PERL_UNUSED_VAR
+#  define PERL_UNUSED_VAR(var) if (0) var = var
+#endif
+
+EOF
 
   print "$ExtUtils::ParseXS::CountLines::SECTION_END_MARKER\n" if $WantLineNumbers;
 
@@ -921,6 +933,8 @@
 
   chdir($orig_cwd);
   select($orig_fh);
+  untie *PSEUDO_STDOUT if tied *PSEUDO_STDOUT;
+
   return 1;
 }
 
@@ -1804,7 +1818,9 @@
   print {$self->{fh}} $self->{buffer};
 }
 
-
+sub UNTIE {
+  # This sub does nothing, but is neccessary for references to be released.
+}
 
 
 
diff -ur ExtUtils-ParseXS-1.99-orig/lib/ExtUtils/xsubpp 
ExtUtils-ParseXS-1.99/lib/ExtUtils/xsubpp
--- ExtUtils-ParseXS-1.99-orig/lib/ExtUtils/xsubpp      2002-12-08 04:09:30.000000000 
-0500
+++ ExtUtils-ParseXS-1.99/lib/ExtUtils/xsubpp   2003-02-09 06:53:14.000000000 -0500
@@ -21,6 +21,7 @@
                      except!
                      v
                      typemap=s@
+                     output=s
                      s=s
                     ))
   or die $usage;
diff -ur ExtUtils-ParseXS-1.99-orig/t/basic.t ExtUtils-ParseXS-1.99/t/basic.t
--- ExtUtils-ParseXS-1.99-orig/t/basic.t        2003-02-05 13:11:24.000000000 -0500
+++ ExtUtils-ParseXS-1.99/t/basic.t     2003-02-09 12:57:33.000000000 -0500
@@ -16,6 +16,11 @@
 
 use Carp; $SIG{__WARN__} = \&Carp::cluck;
 
+sub Is_MSVC { return $^O eq 'MSWin32'
+                 && $Config{cc} =~ /cl(?:\.exe)?$/i
+                 && $Config{ld} =~ /link(?:\.exe)?$/i
+}
+
 #########################
 
 # Try sending to filehandle
@@ -31,12 +36,26 @@
 if (have_compiler()) {
   my $corelib = File::Spec->catdir($Config{archlib}, 'CORE');
   my $o_file = "XSTest$Config{obj_ext}";
+  my $cc_out = Is_MSVC() ? '-Fo' : '-o ';
 
-  ok !do_system("$Config{cc} -c $Config{ccflags} -I$corelib -o $o_file XSTest.c");
+  ok !do_system("$Config{cc} -c $Config{ccflags} -I$corelib "
+               . $cc_out . "$o_file XSTest.c");
   ok -e $o_file, 1, "Make sure $o_file exists";
-  
+
   my $lib_file = "XSTest.$Config{dlext}";
-  ok !do_system("$Config{shrpenv} $Config{ld} $Config{lddlflags} -o $lib_file 
$o_file");
+  my $ld_out = '-o ';
+  my $libs = '';
+  if ( $^O eq 'MSWin32' ) {
+      use ExtUtils::Mksymlists;
+      Mksymlists( 'NAME' => 'XSTest', 'DLBASE' => 'XSTest', 'IMPORTS' => {} );
+
+      if ( Is_MSVC() ) {
+         $ld_out = '-OUT:';
+         $libs = "$Config{libs} $Config{libperl} -def:XSTest.def";
+      }
+  }
+  ok !do_system("$Config{shrpenv} $Config{ld} $Config{lddlflags} "
+               . $ld_out . "$lib_file $o_file $libs" );
 
   eval {require XSTest};
   ok $@, '';
@@ -51,10 +70,17 @@
 
 sub find_in_path {
   my $thing = shift;
-  my @path = split ':', $ENV{PATH};
+  my $path_sep = $Config{path_sep} || ':';
+  my @exe_ext = ();
+  if ( $^O eq 'MSWin32' ) {
+      push @exe_ext, split $path_sep, $ENV{PATHEXT} || '.com;.exe;.bat';
+  }
+  my @path = split $path_sep, $ENV{PATH};
   foreach (@path) {
     my $fullpath = File::Spec->catfile($_, $thing);
-    return $fullpath if -e $fullpath;
+    foreach my $ext ( @exe_ext ) {
+       return "$fullpath$ext" if -e "$fullpath$ext";
+    }
   }
   return;
 }


Reply via email to