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