This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Yet another twist.
[perl5.git] / win32 / FindExt.pm
1 package FindExt;
2
3 our $VERSION = '1.00';
4
5 # We (probably) have not got a Config.pm yet 
6 BEGIN { $INC{'Config.pm'} = __FILE__ };
7
8 use strict;
9 use File::Find;
10 use File::Basename;
11 use Cwd;
12
13 my $no = join('|',qw(DynaLoader GDBM_File ODBM_File NDBM_File DB_File
14                      Syslog SysV Langinfo));
15 $no = qr/^(?:$no)$/i;
16
17 my %ext;
18 my $ext;
19 sub scan_ext
20 {
21  my $here = getcwd();
22  my $dir  = shift;
23  chdir($dir) || die "Cannot cd to $dir\n";
24  ($ext = getcwd()) =~ s,/,\\,g;
25  find(\&find_ext,'.');
26  chdir($here) || die "Cannot cd to $here\n";
27  my @ext = extensions();
28 }
29
30 sub dynamic_extensions
31 {
32  return grep $ext{$_} eq 'dynamic',keys %ext;
33 }
34
35 sub noxs_extensions
36 {
37  return grep $ext{$_} eq 'nonxs',keys %ext;
38 }
39
40 sub extensions
41 {
42  return keys %ext;
43 }
44
45 sub find_ext
46 {
47  if (/^(.*)\.pm$/i || /^(.*)_pm\.PL$/i || /^(.*)\.xs$/i)
48   {
49    my $name = $1;
50    return if $name =~ $no; 
51    my $dir = $File::Find::dir; 
52    $dir =~ s,./,,;
53    return if exists $ext{$dir};
54    return unless -f "$ext/$dir/Makefile.PL";
55    if ($dir =~ /$name$/i)
56     {
57      if (-f "$ext/$dir/$name.xs")
58       {
59        $ext{$dir} = 'dynamic'; 
60       }
61      else
62       {
63        $ext{$dir} = 'nonxs'; 
64       }
65     }
66   }
67 }
68
69 1;