This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Drop references to obsolete MinGW 1.x (gcc 2.95)
[perl5.git] / win32 / FindExt.pm
index d122f30..fe1febd 100644 (file)
@@ -6,7 +6,7 @@ use strict;
 use warnings;
 
 my $no = join('|',qw(GDBM_File ODBM_File NDBM_File DB_File
-                    Syslog SysV Langinfo));
+                     VMS VMS-DCLsym VMS-Stdio Sys-Syslog IPC-SysV I18N-Langinfo));
 $no = qr/^(?:$no)$/i;
 
 my %ext;
@@ -32,77 +32,72 @@ sub set_static_extensions {
 sub scan_ext
 {
     my $dir  = shift;
-    find_ext("$dir/", '');
+    find_ext("$dir/");
     extensions();
 }
 
-sub dynamic_ext
-{
- return sort grep $ext{$_} eq 'dynamic',keys %ext;
-}
-
-sub static_ext
-{
- return sort grep $ext{$_} eq 'static',keys %ext;
+sub _ext_eq {
+    my $key = shift;
+    sub {
+        sort grep $ext{$_} eq $key, keys %ext;
+    }
 }
 
-sub nonxs_ext
-{
- return sort grep $ext{$_} eq 'nonxs',keys %ext;
-}
+*dynamic_ext = _ext_eq('dynamic');
+*static_ext = _ext_eq('static');
+*nonxs_ext = _ext_eq('nonxs');
 
-sub extensions
-{
- return sort grep $ext{$_} ne 'known',keys %ext;
+sub _ext_ne {
+    my $key = shift;
+    sub {
+        sort grep $ext{$_} ne $key, keys %ext;
+    }
 }
 
-sub known_extensions
-{
- # faithfully copy Configure in not including nonxs extensions for the nonce
- return sort grep $ext{$_} ne 'nonxs',keys %ext;
-}
+*extensions = _ext_ne('known');
+# faithfully copy Configure in not including nonxs extensions for the nonce
+*known_extensions = _ext_ne('nonxs');
 
 sub is_static
 {
  return $ext{$_[0]} eq 'static'
 }
 
-# Function to recursively find available extensions, ignoring DynaLoader
-# NOTE: recursion limit of 10 to prevent runaway in case of symlink madness
+sub has_xs_or_c {
+    my $dir = shift;
+    opendir my $dh, $dir or die "opendir $dir: $!";
+    while (defined (my $item = readdir $dh)) {
+        return 1 if $item =~ /\.xs$/;
+        return 1 if $item =~ /\.c$/;
+    }
+    return 0;
+}
+
+# Function to find available extensions, ignoring DynaLoader
 sub find_ext
 {
     my $ext_dir = shift;
-    my $prefix = shift;
-    opendir my $dh, "$ext_dir$prefix";
+    opendir my $dh, "$ext_dir";
     while (defined (my $item = readdir $dh)) {
         next if $item =~ /^\.\.?$/;
         next if $item eq "DynaLoader";
-        my $this_ext = "$prefix$item";
-        if (-f "$ext_dir$this_ext/$item.xs" || -f "$ext_dir$this_ext/$item.c" ) {
+        next unless -d "$ext_dir$item";
+        my $this_ext = $item;
+        my $leaf = $item;
+
+        $this_ext =~ s!-!/!g;
+        $leaf =~ s/.*-//;
+
+       # Temporary hack to cope with smokers that are not clearing directories:
+        next if $ext{$this_ext};
+
+        if (has_xs_or_c("$ext_dir$item")) {
             $ext{$this_ext} = $static{$this_ext} ? 'static' : 'dynamic';
-        } elsif (-f "$ext_dir$this_ext/Makefile.PL") {
-            $ext{$this_ext} = 'nonxs';
         } else {
-            # It's not actually an extension. So recurse into it.
-            if (-d "$ext_dir$this_ext" && $prefix =~ tr#/## < 10) {
-                find_ext($ext_dir, "$this_ext/");
-            }
+            $ext{$this_ext} = 'nonxs';
         }
         $ext{$this_ext} = 'known' if $ext{$this_ext} && $item =~ $no;
     }
-
-# Special case:  Add in modules that nest beyond the first level.
-# Currently threads/shared and Hash/Util/FieldHash, since they are
-# not picked up by the recursive find above (and adding in general
-# recursive finding breaks SDBM_File/sdbm).
-# A.D. 20011025 (SDBM), ajgough 20071008 (FieldHash)
-
-    if (!$prefix && -d "${ext_dir}threads/shared") {
-        $ext{"threads/shared"} = 'dynamic';
-    }
-    if (!$prefix && -d "${ext_dir}Hash/Util/FieldHash") {
-        $ext{"Hash/Util/FieldHash"} = 'dynamic';
-    }
 }
 
 1;