This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Bump Data::Dumper version
[perl5.git] / win32 / FindExt.pm
CommitLineData
8e232993 1package FindExt;
28b605d8 2
abec5bed 3our $VERSION = '1.03';
28b605d8 4
8e232993 5use strict;
ca58f2ae 6use warnings;
8e232993 7
f2bbbc99 8my $no = join('|',qw(Amiga.* GDBM_File ODBM_File NDBM_File DB_File
6201c220 9 VMS.* Sys-Syslog IPC-SysV));
8e232993
NIS
10$no = qr/^(?:$no)$/i;
11
557ab4cb
TC
12sub apply_config {
13 my ($config) = @_;
14 my @no;
15
21339399
SH
16 push @no, 'Sys-Syslog' if $^O eq 'MSWin32';
17
557ab4cb
TC
18 # duplicates logic from Configure (mostly)
19 push @no, "DB_File" unless $config->{i_db};
20 push @no, "GDBM_File" unless $config->{i_gdbm};
557ab4cb
TC
21 push @no, "IPC-SysV" unless $config->{d_msg} || $config->{d_sem} || $config->{d_shm};
22 push @no, "NDBM_File" unless $config->{d_ndbm};
23 push @no, "ODBM_File"
24 unless ($config->{i_dbm} || $config->{i_rpcsvcdbm}) && !$config->{d_cplusplus};
f2bbbc99 25 push @no, "Amiga.*" unless $^O eq "amigaos";
557ab4cb
TC
26 push @no, "VMS.*" unless $^O eq "VMS";
27 push @no, "Win32.*" unless $^O eq "MSWin32" || $^O eq "cygwin";
28
29 $no = join('|', @no);
30 $no = qr/^(?:$no)$/i;
31}
32
8e232993 33my %ext;
ca58f2ae
YST
34my %static;
35
a1f2e719 36sub set_static_extensions {
ca58f2ae
YST
37 # adjust results of scan_ext, and also save
38 # statics in case scan_ext hasn't been called yet.
a1f2e719
VK
39 # if '*' is passed then all XS extensions are static
40 # (with possible exclusions)
ca58f2ae 41 %static = ();
a1f2e719 42 my @list = @_;
14f183f1 43 if (@_ and $_[0] eq '*') {
a1f2e719
VK
44 my %excl = map {$_=>1} map {m/^!(.*)$/} @_[1 .. $#_];
45 @list = grep {!exists $excl{$_}} keys %ext;
46 }
47 for (@list) {
ca58f2ae
YST
48 $static{$_} = 1;
49 $ext{$_} = 'static' if $ext{$_} && $ext{$_} eq 'dynamic';
50 }
21339399
SH
51
52 # Encode is a special case. If we are building Encode as a static
53 # extension, we need to explicitly list its subextensions as well.
54 # For other nested extensions, this is handled automatically by
55 # the appropriate Makefile.PL.
56 if ($ext{Encode} && $ext{Encode} eq 'static') {
2b7bd0cd
NC
57 require File::Find;
58 File::Find::find({
59 no_chdir => 1,
60 wanted => sub {
61 return unless m!\b(Encode/.+)/Makefile\.PL!;
62 $static{$1} = 1;
63 $ext{$1} = 'static';
64 },
65 }, "../cpan/Encode");
21339399 66 }
ca58f2ae
YST
67}
68
442749d5
NC
69sub _ext_eq {
70 my $key = shift;
71 sub {
72 sort grep $ext{$_} eq $key, keys %ext;
73 }
ca58f2ae
YST
74}
75
442749d5
NC
76*dynamic_ext = _ext_eq('dynamic');
77*static_ext = _ext_eq('static');
78*nonxs_ext = _ext_eq('nonxs');
8e232993 79
396a7feb
NC
80sub extensions {
81 sort grep $ext{$_} ne 'known', keys %ext;
ca58f2ae
YST
82}
83
f7b3892b
NC
84sub known_extensions {
85 sort keys %ext;
86}
ca58f2ae
YST
87
88sub is_static
89{
90 return $ext{$_[0]} eq 'static'
8e232993
NIS
91}
92
0a3660e3
NC
93sub has_xs_or_c {
94 my $dir = shift;
95 opendir my $dh, $dir or die "opendir $dir: $!";
96 while (defined (my $item = readdir $dh)) {
97 return 1 if $item =~ /\.xs$/;
98 return 1 if $item =~ /\.c$/;
99 }
100 return 0;
101}
102
1f8a0b38 103# Function to find available extensions, ignoring DynaLoader
33881c92 104sub scan_ext
8e232993 105{
3380c781 106 my $ext_dir = shift;
1f8a0b38 107 opendir my $dh, "$ext_dir";
3380c781
NC
108 while (defined (my $item = readdir $dh)) {
109 next if $item =~ /^\.\.?$/;
110 next if $item eq "DynaLoader";
33881c92 111 next unless -d "$ext_dir/$item";
1f8a0b38 112 my $this_ext = $item;
f44bdcee
NC
113 my $leaf = $item;
114
115 $this_ext =~ s!-!/!g;
116 $leaf =~ s/.*-//;
117
cb8c8458
SH
118 # List/Util.xs lives in Scalar-List-Utils, Cwd.xs lives in PathTools
119 $this_ext = 'List/Util' if $this_ext eq 'Scalar/List/Utils';
120 $this_ext = 'Cwd' if $this_ext eq 'PathTools';
121
4d33dfde
NC
122 # Temporary hack to cope with smokers that are not clearing directories:
123 next if $ext{$this_ext};
124
33881c92 125 if (has_xs_or_c("$ext_dir/$item")) {
3380c781 126 $ext{$this_ext} = $static{$this_ext} ? 'static' : 'dynamic';
3380c781 127 } else {
1f8a0b38 128 $ext{$this_ext} = 'nonxs';
ca58f2ae 129 }
33881c92 130 $ext{$this_ext} = 'known' if $item =~ $no;
ca58f2ae 131 }
8e232993
NIS
132}
133
1341;
3380c781 135# ex: set ts=8 sts=4 sw=4 et: