Final move from meta-3.0 to meta-3.5
[p5sagit/p5-mst-13.2.git] / win32 / FindExt.pm
CommitLineData
8e232993 1package FindExt;
28b605d8 2
a1f2e719 3our $VERSION = '1.02';
28b605d8 4
8e232993 5use strict;
ca58f2ae 6use warnings;
8e232993 7
ca58f2ae 8my $no = join('|',qw(GDBM_File ODBM_File NDBM_File DB_File
86c8d741 9 Syslog SysV Langinfo));
8e232993 10$no = qr/^(?:$no)$/i;
11
12my %ext;
13my $ext;
ca58f2ae 14my %static;
15
16sub getcwd {
cf2f24a4 17 $_ = `cd`;
18 chomp;
19 s:\\:/:g ;
20 return $ENV{'PWD'} = $_;
ca58f2ae 21}
22
a1f2e719 23sub set_static_extensions {
ca58f2ae 24 # adjust results of scan_ext, and also save
25 # statics in case scan_ext hasn't been called yet.
a1f2e719 26 # if '*' is passed then all XS extensions are static
27 # (with possible exclusions)
ca58f2ae 28 %static = ();
a1f2e719 29 my @list = @_;
30 if ($_[0] eq '*') {
31 my %excl = map {$_=>1} map {m/^!(.*)$/} @_[1 .. $#_];
32 @list = grep {!exists $excl{$_}} keys %ext;
33 }
34 for (@list) {
ca58f2ae 35 $static{$_} = 1;
36 $ext{$_} = 'static' if $ext{$_} && $ext{$_} eq 'dynamic';
37 }
38}
39
8e232993 40sub scan_ext
41{
42 my $here = getcwd();
43 my $dir = shift;
44 chdir($dir) || die "Cannot cd to $dir\n";
45 ($ext = getcwd()) =~ s,/,\\,g;
ca58f2ae 46 find_ext('');
8e232993 47 chdir($here) || die "Cannot cd to $here\n";
48 my @ext = extensions();
49}
50
ca58f2ae 51sub dynamic_ext
52{
53 return sort grep $ext{$_} eq 'dynamic',keys %ext;
54}
55
56sub static_ext
8e232993 57{
ca58f2ae 58 return sort grep $ext{$_} eq 'static',keys %ext;
8e232993 59}
60
ca58f2ae 61sub nonxs_ext
8e232993 62{
ca58f2ae 63 return sort grep $ext{$_} eq 'nonxs',keys %ext;
8e232993 64}
65
66sub extensions
67{
ca58f2ae 68 return sort grep $ext{$_} ne 'known',keys %ext;
69}
70
71sub known_extensions
72{
73 # faithfully copy Configure in not including nonxs extensions for the nonce
74 return sort grep $ext{$_} ne 'nonxs',keys %ext;
75}
76
77sub is_static
78{
79 return $ext{$_[0]} eq 'static'
8e232993 80}
81
ca58f2ae 82# Function to recursively find available extensions, ignoring DynaLoader
83# NOTE: recursion limit of 10 to prevent runaway in case of symlink madness
8e232993 84sub find_ext
85{
679f4c1f 86 opendir my $dh, '.';
87 my @items = grep { !/^\.\.?$/ } readdir $dh;
88 closedir $dh;
89 for my $xxx (@items) {
ca58f2ae 90 if ($xxx ne "DynaLoader") {
78ff2d7b 91 if (-f "$xxx/$xxx.xs" || -f "$xxx/$xxx.c" ) {
ca58f2ae 92 $ext{"$_[0]$xxx"} = $static{"$_[0]$xxx"} ? 'static' : 'dynamic';
93 } elsif (-f "$xxx/Makefile.PL") {
94 $ext{"$_[0]$xxx"} = 'nonxs';
95 } else {
96 if (-d $xxx && @_ < 10) {
97 chdir $xxx;
98 find_ext("$_[0]$xxx/", @_);
99 chdir "..";
100 }
101 }
102 $ext{"$_[0]$xxx"} = 'known' if $ext{"$_[0]$xxx"} && $xxx =~ $no;
103 }
104 }
105
9788a75a 106# Special case: Add in modules that nest beyond the first level.
107# Currently threads/shared and Hash/Util/FieldHash, since they are
108# not picked up by the recursive find above (and adding in general
109# recursive finding breaks SDBM_File/sdbm).
110# A.D. 20011025 (SDBM), ajgough 20071008 (FieldHash)
ca58f2ae 111
112 if (!$_[0] && -d "threads/shared") {
113 $ext{"threads/shared"} = 'dynamic';
8e232993 114 }
9788a75a 115 if (!$_[0] && -d "Hash/Util/FieldHash") {
116 $ext{"Hash/Util/FieldHash"} = 'dynamic';
117 }
8e232993 118}
119
1201;