BeOS update (Mirror maint-5.005 change #2727).
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / Embed.pm
index 39d797e..4b56e88 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: Embed.pm,v 1.22 1997/01/30 00:37:09 dougm Exp $
+# $Id: Embed.pm,v 1.2501 $
 require 5.002;
 
 package ExtUtils::Embed;
@@ -17,11 +17,7 @@ use vars qw(@ISA @EXPORT $VERSION
            );
 use strict;
 
-$VERSION = sprintf("%d.%02d", q$Revision: 1.2201 $ =~ /(\d+)\.(\d+)/);
-#for the namespace change
-$Devel::embed::VERSION = "99.99";
-
-sub Version { $VERSION; }
+$VERSION = sprintf("%d.%02d", q$Revision: 1.2505 $ =~ /(\d+)\.(\d+)/);
 
 @ISA = qw(Exporter);
 @EXPORT = qw(&xsinit &ldopts 
@@ -35,10 +31,27 @@ sub Version { $VERSION; }
 $Verbose = 0;
 $lib_ext = $Config{lib_ext} || '.a';
 
+sub is_cmd { $0 eq '-e' }
+
+sub my_return {
+    my $val = shift;
+    if(is_cmd) {
+       print $val;
+    }
+    else {
+       return $val;
+    }
+}
+
+sub is_perl_object {
+    $Config{ccflags} =~ /-DPERL_OBJECT/;  
+}
+
 sub xsinit { 
     my($file, $std, $mods) = @_;
     my($fh,@mods,%seen);
     $file ||= "perlxsi.c";
+    my $xsinit_proto = is_perl_object() ? "CPERLarg" : "void";
 
     if (@_) {
        @mods = @$mods if $mods;
@@ -62,10 +75,10 @@ sub xsinit {
     @mods = grep(!$seen{$_}++, @mods);
 
     print $fh &xsi_header();
-    print $fh "EXTERN_C void xs_init _((void));\n\n";     
+    print $fh "EXTERN_C void xs_init _(($xsinit_proto));\n\n";     
     print $fh &xsi_protos(@mods);
 
-    print $fh "\nEXTERN_C void\nxs_init()\n{\n";
+    print $fh "\nEXTERN_C void\nxs_init($xsinit_proto)\n{\n";
     print $fh &xsi_body(@mods);
     print $fh "}\n";
 
@@ -73,14 +86,24 @@ sub xsinit {
 
 sub xsi_header {
     return <<EOF;
-#ifdef __cplusplus
+#if defined(__cplusplus) && !defined(PERL_OBJECT)
+#define is_cplusplus
+#endif
+
+#ifdef is_cplusplus
 extern "C" {
 #endif
 
 #include <EXTERN.h>
 #include <perl.h>
-
-#ifdef __cplusplus
+#ifdef PERL_OBJECT
+#define NO_XSLOCKS
+#include <XSUB.h>
+#include "win32iop.h"
+#include <fcntl.h>
+#include <perlhost.h>
+#endif
+#ifdef is_cplusplus
 }
 #  ifndef EXTERN_C
 #    define EXTERN_C extern "C"
@@ -97,13 +120,14 @@ EOF
 sub xsi_protos {
     my(@exts) = @_;
     my(@retval,%seen);
-
+    my $boot_proto = is_perl_object() ? 
+       "CV* cv _CPERLarg" : "CV* cv";
     foreach $_ (@exts){
         my($pname) = canon('/', $_);
         my($mname, $cname);
         ($mname = $pname) =~ s!/!::!g;
         ($cname = $pname) =~ s!/!__!g;
-       my($ccode) = "EXTERN_C void boot_${cname} _((CV* cv));\n";
+       my($ccode) = "EXTERN_C void boot_${cname} _(($boot_proto));\n";
        next if $seen{$ccode}++;
         push(@retval, $ccode);
     }
@@ -114,8 +138,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, "\tchar *file = __FILE__;\n\n");
+    push(@retval, "\n");
 
     foreach $_ (@exts){
         my($pname) = canon('/', $_);
@@ -176,7 +201,7 @@ sub ldopts {
     my($mod,@ns,$root,$sub,$extra,$archive,@archives);
     print STDERR "Searching (@path) for archives\n" if $Verbose;
     foreach $mod (@mods) {
-       @ns = split('::', $mod);
+       @ns = split(/::|\/|\\/, $mod);
        $sub = $ns[-1];
        $root = $MM->catdir(@ns);
        
@@ -199,7 +224,7 @@ sub ldopts {
     }
     #print STDERR "\@potential_libs = @potential_libs\n";
 
-    my $libperl = (grep(/^(-l\w+perl)$/, @link_args))[0] || "-lperl";
+    my $libperl = (grep(/^-l\w*perl\w*$/, @link_args))[0] || "-lperl";
 
     my($extralibs, $bsloadlibs, $ldloadlibs, $ld_run_path) =
        $MM->ext(join ' ', 
@@ -212,24 +237,23 @@ sub ldopts {
     print STDERR "ldopts: '$linkage'\n" if $Verbose;
 
     return $linkage if scalar @_;
-    print "$linkage\n";
+    my_return("$linkage\n");
 }
 
 sub ccflags {
-   print " $Config{ccflags} ";
+    my_return(" $Config{ccflags} ");
 }
 
 sub ccdlflags {
-   print " $Config{ccdlflags} ";
+    my_return(" $Config{ccdlflags} ");
 }
 
 sub perl_inc {
-   print " -I$Config{archlibexp}/CORE ";
+    my_return(" -I$Config{archlibexp}/CORE ");
 }
 
 sub ccopts {
-   ccflags;
-   perl_inc;
+   ccflags . perl_inc;
 }
 
 sub canon {
@@ -392,7 +416,7 @@ This will print arguments for linking with B<libperl.a>, B<DynaLoader> 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 
-specifed by the B<-I> option.  
+specified by the B<-I> option.  
 In addition, when ModuleName.a is found, additional linker arguments
 are picked up from the B<extralibs.ld> file in the same directory.