This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Increase $DynaLoader'VERSION from 1.13 to 1.14,
[perl5.git] / ext / DynaLoader / DynaLoader_pm.PL
index 8476dad..495847c 100644 (file)
@@ -26,6 +26,10 @@ sub to_string {
 #   
 #  -- added by VKON, 03-10-2004 to separate $^O-specific between OSes
 #     (so that Win32 never checks for $^O eq 'VMS' for example)
+#
+# The $^O tests test both for $^O and for $Config{osname}.
+# The latter is better for some for cross-compilation setups.
+#
 sub expand_os_specific {
     my $s = shift;
     for ($s) {
@@ -36,7 +40,7 @@ sub expand_os_specific {
          if ($expr =~ m[^(.*?)<<\|\$\^O-$op-$os>>(.*?)$]s) {
              # #if;#else;#endif
              my ($if,$el) = ($1,$2);
-             if (($op eq 'eq' and $^O eq $os) || ($op eq 'ne' and $^O ne $os)) {
+             if (($op eq 'eq' and ($^O eq $os || $Config{osname} eq $os)) || ($op eq 'ne' and ($^O ne $os || $Config{osname} ne $os))) {
                  $if
              }
              else {
@@ -45,7 +49,7 @@ sub expand_os_specific {
          }
          else {
              # #if;#endif
-             if (($op eq 'eq' and $^O eq $os) || ($op eq 'ne' and $^O ne $os)) {
+             if (($op eq 'eq' and ($^O eq $os || $Config{osname} eq $os)) || ($op eq 'ne' and ($^O ne $os || $Config{osname} ne $os))) {
                  $expr
              }
              else {
@@ -64,7 +68,7 @@ unlink "DynaLoader.pm" if -f "DynaLoader.pm";
 open OUT, ">DynaLoader.pm" or die $!;
 print OUT <<'EOT';
 
-# Generated from DynaLoader.pm.PL
+# Generated from DynaLoader_pm.PL
 
 package DynaLoader;
 
@@ -80,10 +84,9 @@ package DynaLoader;
 #
 # Tim.Bunce@ig.co.uk, August 1994
 
-$VERSION = '1.07';
-
-require AutoLoader;
-*AUTOLOAD = \&AutoLoader::AUTOLOAD;
+BEGIN {
+    $VERSION = '1.14';
+}
 
 use Config;
 
@@ -103,14 +106,19 @@ $dl_debug = $ENV{PERL_DL_DEBUG} || 0 unless defined $dl_debug;
 
 sub dl_load_flags { 0x00 }
 
-# ($dl_dlext, $dlsrc)
-#         = @Config::Config{'dlext', 'dlsrc'};
 EOT
 
-$dl_dlext = $Config::Config{'dlext'};
-$dl_so = $Config::Config{'so'};
-print OUT "  (\$dl_dlext, \$dlsrc) = ('$dl_dlext', ",
-          to_string($Config::Config{'dlsrc'}), ")\n;";
+if ($ENV{PERL_BUILD_EXPAND_CONFIG_VARS}) {
+    print OUT "(\$dl_dlext, \$dl_so, \$dlsrc) = (",
+              to_string($Config{'dlext'}), ",",
+              to_string($Config{'so'}), ",",
+              to_string($Config{'dlsrc'}), ")\n;" ;
+}
+else {
+    print OUT <<'EOT';
+($dl_dlext, $dl_so, $dlsrc) = @Config::Config{qw(dlext so dlsrc)};
+EOT
+}
 
 print OUT expand_os_specific(<<'EOT');
 
@@ -123,11 +131,6 @@ $Is_VMS    = $^O eq 'VMS';
 <</$^O-eq-VMS>>
 $do_expand = <<$^O-eq-VMS>>1<<|$^O-eq-VMS>>0<</$^O-eq-VMS>>;
 
-<<$^O-eq-MacOS>>
-my $Mac_FS;
-$Mac_FS = eval { require Mac::FileSpec::Unixish };
-<</$^O-eq-MacOS>>
-
 @dl_require_symbols = ();       # names of symbols we need
 @dl_resolve_using   = ();       # names of files to link with
 @dl_library_path    = ();       # path to look for files
@@ -259,9 +262,6 @@ sub bootstrap_inherit {
     bootstrap(@_);
 }
 
-# The bootstrap function cannot be autoloaded (without complications)
-# so we define it here:
-
 sub bootstrap {
     # use local vars to enable $module.bs script to edit values
     local(@args) = @_;
@@ -301,33 +301,21 @@ sub bootstrap {
        }
     <</$^O-eq-NetWare>>
 
-    my $modpname = join(<<$^O-eq-MacOS>>':'<<|$^O-eq-MacOS>>'/'<</$^O-eq-MacOS>>,@modparts);
+    my $modpname = join('/',@modparts);
 
     print STDERR "DynaLoader::bootstrap for $module ",
-                      <<$^O-eq-MacOS>> "(:auto:$modpname:$modfname.<<=$dl_dlext>>)\n" 
-                      <<|$^O-eq-MacOS>>"(auto/$modpname/$modfname.<<=$dl_dlext>>)\n"<</$^O-eq-MacOS>>
+                      "(auto/$modpname/$modfname.$dl_dlext)\n"
        if $dl_debug;
 
     foreach (@INC) {
        <<$^O-eq-VMS>>chop($_ = VMS::Filespec::unixpath($_));<</$^O-eq-VMS>>
-       <<$^O-eq-MacOS>>
-           my $path = $_;
-           if ($Mac_FS && ! -d $path) {
-               $path = Mac::FileSpec::Unixish::nativize($path);
-           }
-           $path .= ":"  unless /:$/;
-           my $dir = "${path}auto:$modpname";
-       <<|$^O-eq-MacOS>>
            my $dir = "$_/auto/$modpname";
-       <</$^O-eq-MacOS>>
        
        next unless -d $dir; # skip over uninteresting directories
        
        # check for common cases to avoid autoload of dl_findfile
-       my $try = <<$^O-eq-MacOS>> "$dir:$modfname.<<=$dl_dlext>>" <<|$^O-eq-MacOS>> "$dir/$modfname.<<=$dl_dlext>>"<</$^O-eq-MacOS>>;
-       last if $file = <<$^O-eq-VMS>>($do_expand) ? dl_expandspec($try) : ((-f $try) && $try);
-       <<|$^O-eq-VMS>>(-f $try) && $try;
-       <</$^O-eq-VMS>>
+       my $try = "$dir/$modfname.$dl_dlext";
+       last if $file = ($do_expand) ? dl_expandspec($try) : ((-f $try) && $try);
        
        # no luck here, save dir for possible later dl_findfile search
        push @dirs, $dir;
@@ -395,19 +383,6 @@ sub bootstrap {
     &$xs(@args);
 }
 
-
-#sub _check_file {   # private utility to handle dl_expandspec vs -f tests
-#    my($file) = @_;
-#    return $file if (!$do_expand && -f $file); # the common case
-#    return $file if ( $do_expand && ($file=dl_expandspec($file)));
-#    return undef;
-#}
-
-
-# Let autosplit and the autoloader deal with these functions:
-__END__
-
-
 sub dl_findfile {
     # Read ext/DynaLoader/DynaLoader.doc for detailed information.
     # This function does not automatically consider the architecture
@@ -430,12 +405,6 @@ sub dl_findfile {
            next;
         }
        <</$^O-eq-VMS>>
-       <<$^O-eq-MacOS>>
-           if (m/:/ && -f $_) {
-               push(@found,$_);
-               last arg unless wantarray;
-           }
-       <</$^O-eq-MacOS>>
        <<$^O-ne-VMS>>
         if (m:/: && -f $_) {
            push(@found,$_);
@@ -448,30 +417,6 @@ sub dl_findfile {
         #  Using a -L prefix is the preferred option (faster and more robust)
         if (m:^-L:) { s/^-L//; push(@dirs, $_); next; }
 
-       <<$^O-eq-MacOS>>
-            #  Otherwise we try to try to spot directories by a heuristic
-            #  (this is a more complicated issue than it first appears)
-           if (m/:/ && -d $_) {   push(@dirs, $_); next; }
-            #  Only files should get this far...
-            my(@names, $name);    # what filenames to look for
-           s/^-l//;
-           push(@names, $_);
-            foreach $dir (@dirs, @dl_library_path) {
-               next unless -d $dir;
-               $dir =~ s/^([^:]+)$/:$1/;
-               $dir =~ s/:$//;
-               foreach $name (@names) {
-                   my($file) = "$dir:$name";
-                    print STDERR " checking in $dir for $name\n" if $dl_debug;
-                   if (-f $file) {
-                       push(@found, $file);
-                       next arg; # no need to look any further
-                    }
-                }
-           }
-           next;
-       <</$^O-eq-MacOS>>
-       
         #  Otherwise we try to try to spot directories by a heuristic
         #  (this is a more complicated issue than it first appears)
         if (m:/: && -d $_) {   push(@dirs, $_); next; }
@@ -486,23 +431,35 @@ sub dl_findfile {
         my(@names, $name);    # what filenames to look for
         if (m:-l: ) {          # convert -lname to appropriate library name
             s/-l//;
-            push(@names,"lib$_.<<=to_string($Config::Config{'so'})>>");
+            push(@names,"lib$_.$dl_so");
             push(@names,"lib$_.a");
         } else {                # Umm, a bare name. Try various alternatives:
             # these should be ordered with the most likely first
-            push(@names,"$_.<<=$dl_dlext>>")    unless m/\.<<=$dl_dlext>>$/o;
-            push(@names,"$_.<<=$dl_so>>")     unless m/\.<<=$dl_so>>$/o;
-            push(@names,"lib$_.<<=$dl_so>>")  unless m:/:;
+            push(@names,"$_.$dl_dlext")    unless m/\.$dl_dlext$/o;
+            push(@names,"$_.$dl_so")     unless m/\.$dl_so$/o;
+           <<$^O-eq-cygwin>>
+            push(@names,"cyg$_.$dl_so")  unless m:/:;
+           <</$^O-eq-cygwin>>
+            push(@names,"lib$_.$dl_so")  unless m:/:;
             push(@names,"$_.a")          if !m/\.a$/ and $dlsrc eq "dl_dld.xs";
             push(@names, $_);
         }
+       my $dirsep = '/';
+       <<$^O-eq-symbian>>
+       $dirsep = '\\';
+       if ($0 =~ /^([a-z]):/i) {
+           my $drive = $1;
+           @dirs = map { "$drive:$_" } @dirs;
+           @dl_library_path = map { "$drive:$_" } @dl_library_path;
+       }
+       <</$^O-eq-symbian>>
         foreach $dir (@dirs, @dl_library_path) {
             next unless -d $dir;
            <<$^O-eq-VMS>>
             chop($dir = VMS::Filespec::unixpath($dir));
            <</$^O-eq-VMS>>
             foreach $name (@names) {
-               my($file) = "$dir/$name";
+               my($file) = "$dir$dirsep$name";
                 print STDERR " checking in $dir for $name\n" if $dl_debug;
                $file = ($do_expand) ? dl_expandspec($file) : (-f $file && $file);
                #$file = _check_file($file);
@@ -524,12 +481,15 @@ sub dl_findfile {
 }
 
 
+<<$^O-eq-VMS>>
+# dl_expandspec should be defined in dl_vms.xs
+<<|$^O-eq-VMS>>
 sub dl_expandspec {
     my($spec) = @_;
     # Optional function invoked if DynaLoader.pm sets $do_expand.
     # Most systems do not require or use this function.
     # Some systems may implement it in the dl_*.xs file in which case
-    # this autoload version will not be called but is harmless.
+    # this Perl version should be excluded at build time.
 
     # This function is designed to deal with systems which treat some
     # 'filenames' in a special way. For example VMS 'Logical Names'
@@ -540,16 +500,11 @@ sub dl_expandspec {
 
     my $file = $spec; # default output to input
 
-    <<$^O-eq-VMS>>
-        # dl_expandspec should be defined in dl_vms.xs
-       require Carp;
-       Carp::croak("dl_expandspec: should be defined in XS file!\n");
-    <<|$^O-eq-VMS>>
        return undef unless -f $file;
-    <</$^O-eq-VMS>>
     print STDERR "dl_expandspec($spec) => $file\n" if $dl_debug;
     $file;
 }
+<</$^O-eq-VMS>>
 
 sub dl_find_symbol_anywhere
 {
@@ -562,6 +517,8 @@ sub dl_find_symbol_anywhere
     return undef;
 }
 
+__END__
+
 =head1 NAME
 
 DynaLoader - Dynamically load C libraries into Perl code
@@ -762,9 +719,8 @@ Some unusual systems, such as VMS, require special filename handling in
 order to deal with symbolic names for files (i.e., VMS's Logical Names).
 
 To support these systems a dl_expandspec() function can be implemented
-either in the F<dl_*.xs> file or code can be added to the autoloadable
-dl_expandspec() function in F<DynaLoader.pm>.  See F<DynaLoader.pm> for
-more information.
+either in the F<dl_*.xs> file or code can be added to the dl_expandspec()
+function in F<DynaLoader.pm>.  See F<DynaLoader_pm.PL> for more information.
 
 =item dl_load_file()
 
@@ -911,7 +867,7 @@ $filename is not defined then "DynaLoader" will be used.
 
 Syntax:
 
-bootstrap($module)
+bootstrap($module [...])
 
 This is the normal entry point for automatic dynamic loading in Perl.
 
@@ -964,6 +920,13 @@ it uses the function reference returned by dl_install_xsub for speed)
 
 =back
 
+All arguments to bootstrap() are passed to the module's bootstrap function.
+The default code generated by F<xsubpp> expects $module [, $version]
+If the optional $version argument is not given, it defaults to
+C<$XS_VERSION // $VERSION> in the module's symbol table. The default code
+compares the Perl-space version with the version of the compiled XS code,
+and croaks with an error if they do not match.
+
 =back