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