This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Propagate bugfixes from {mini,}perlmain.c into ExtUtils::Embed.
[perl5.git] / lib / ExtUtils / Embed.pm
index 2d6470e..8953ce7 100644 (file)
@@ -1,12 +1,9 @@
-# $Id: Embed.pm,v 1.1.1.1 2002/01/16 19:27:19 schwern Exp $
 require 5.002;
 
 package ExtUtils::Embed;
 require Exporter;
-require FileHandle;
 use Config;
-use Getopt::Std;
-use File::Spec;
+require File::Spec;
 
 #Only when we need them
 #require ExtUtils::MakeMaker;
@@ -18,7 +15,8 @@ use vars qw(@ISA @EXPORT $VERSION
            );
 use strict;
 
-$VERSION = 1.26;
+# This is not a dual-life module, so no need for development version numbers
+$VERSION = '1.31';
 
 @ISA = qw(Exporter);
 @EXPORT = qw(&xsinit &ldopts 
@@ -54,7 +52,8 @@ sub xsinit {
        @mods = @$mods if $mods;
     }
     else {
-       getopts('o:s:');
+       require Getopt::Std;
+       Getopt::Std::getopts('o:s:');
        $file = $opt_o if defined $opt_o;
        $std  = $opt_s  if defined $opt_s;
        @mods = @ARGV;
@@ -65,7 +64,8 @@ sub xsinit {
        $fh = \*STDOUT;
     }
     else {
-       $fh = new FileHandle "> $file";
+        open $fh, '>', $file
+            or die "Can't open '$file': $!";
     }
 
     push(@mods, static_ext()) if defined $std;
@@ -85,6 +85,7 @@ sub xsi_header {
     return <<EOF;
 #include <EXTERN.h>
 #include <perl.h>
+#include <XSUB.h>
 
 EOF
 }    
@@ -109,8 +110,9 @@ sub xsi_body {
     my(@exts) = @_;
     my($pname,@retval,%seen);
     my($dl) = canon('/','DynaLoader');
-    push(@retval, "\tchar *file = __FILE__;\n");
-    push(@retval, "\tdXSUB_SYS;\n") if $] > 5.002;
+    push(@retval, "\tstatic const char file[] = __FILE__;\n");
+    push(@retval, "\tdXSUB_SYS;\n");
+    push(@retval, "\tPERL_UNUSED_CONTEXT;\n");
     push(@retval, "\n");
 
     foreach $_ (@exts){
@@ -133,7 +135,9 @@ sub xsi_body {
 
 sub static_ext {
     unless (scalar @Extensions) {
-       @Extensions = sort split /\s+/, $Config{static_ext};
+      my $static_ext = $Config{static_ext};
+      $static_ext =~ s/^\s+//;
+      @Extensions = sort split /\s+/, $static_ext;
        unshift @Extensions, qw(DynaLoader);
     }
     @Extensions;
@@ -141,6 +145,7 @@ sub static_ext {
 
 sub _escape {
     my $arg = shift;
+    return $$arg if $^O eq 'VMS'; # parens legal in qualifier lists
     $$arg =~ s/([\(\)])/\\$1/g;
 }
 
@@ -225,11 +230,13 @@ sub ldopts {
     if ($^O eq 'MSWin32') {
        $libperl = $Config{libperl};
     }
-    else {
+    elsif ($^O eq 'os390' && $Config{usedl}) {
+       # Nothing for OS/390 (z/OS) dynamic.
+    } else {
        $libperl = (grep(/^-l\w*perl\w*$/, @link_args))[0]
            || ($Config{libperl} =~ /^lib(\w+)(\Q$lib_ext\E|\.\Q$Config{dlext}\E)$/
                ? "-l$1" : '')
-           || "-lperl";
+               || "-lperl";
     }
 
     my $lpath = File::Spec->catdir($Config{archlibexp}, 'CORE');
@@ -276,7 +283,7 @@ sub canon {
        s:^(lib|ext)/(auto/)?::;
        s:/\w+\.\w+$::;
     }
-    grep(s:/:$as:, @ext) if ($as ne '/');
+    map(s:/:$as:, @ext) if ($as ne '/');
     @ext;
 }
 
@@ -425,7 +432,7 @@ rather than print it to STDOUT.
  perl -MExtUtils::Embed -e ldopts
 
 
-This will print arguments for linking with B<libperl.a>, B<DynaLoader> and 
+This will print arguments for linking with B<libperl> and
 extensions found in B<$Config{static_ext}>.  This includes libraries
 found in B<$Config{libs}> and the first ModuleName.a library
 for each extension that is found by searching B<@INC> or the path 
@@ -439,17 +446,8 @@ are picked up from the B<extralibs.ld> file in the same directory.
 
 This will do the same as the above example, along with printing additional arguments for linking with the B<Socket> extension.
 
-
- perl -MExtUtils::Embed -e ldopts -- DynaLoader
-
-
-This will print arguments for linking with just the B<DynaLoader> extension
-and B<libperl.a>.
-
-
  perl -MExtUtils::Embed -e ldopts -- -std Msql -- -L/usr/msql/lib -lmsql
 
-
 Any arguments after the second '--' token are additional linker
 arguments that will be examined for potential conflict.  If there is no
 conflict, the additional arguments will be part of the output.