Commit | Line | Data |
---|---|---|
8e232993 | 1 | package FindExt; |
28b605d8 | 2 | |
a1f2e719 | 3 | our $VERSION = '1.02'; |
28b605d8 | 4 | |
8e232993 | 5 | use strict; |
ca58f2ae | 6 | use warnings; |
8e232993 | 7 | |
ca58f2ae | 8 | my $no = join('|',qw(GDBM_File ODBM_File NDBM_File DB_File |
b699af07 | 9 | VMS VMS-DCLsym VMS-Stdio Sys-Syslog IPC-SysV I18N-Langinfo)); |
8e232993 NIS |
10 | $no = qr/^(?:$no)$/i; |
11 | ||
557ab4cb TC |
12 | sub apply_config { |
13 | my ($config) = @_; | |
14 | my @no; | |
15 | ||
16 | # duplicates logic from Configure (mostly) | |
17 | push @no, "DB_File" unless $config->{i_db}; | |
18 | push @no, "GDBM_File" unless $config->{i_gdbm}; | |
19 | push @no, "I18N-Langinfo" unless $config->{i_langinfo} && $config->{i_nl_langinfo}; | |
20 | push @no, "IPC-SysV" unless $config->{d_msg} || $config->{d_sem} || $config->{d_shm}; | |
21 | push @no, "NDBM_File" unless $config->{d_ndbm}; | |
22 | push @no, "ODBM_File" | |
23 | unless ($config->{i_dbm} || $config->{i_rpcsvcdbm}) && !$config->{d_cplusplus}; | |
24 | push @no, "VMS.*" unless $^O eq "VMS"; | |
25 | push @no, "Win32.*" unless $^O eq "MSWin32" || $^O eq "cygwin"; | |
26 | ||
27 | $no = join('|', @no); | |
28 | $no = qr/^(?:$no)$/i; | |
29 | } | |
30 | ||
8e232993 | 31 | my %ext; |
ca58f2ae YST |
32 | my %static; |
33 | ||
a1f2e719 | 34 | sub set_static_extensions { |
ca58f2ae YST |
35 | # adjust results of scan_ext, and also save |
36 | # statics in case scan_ext hasn't been called yet. | |
a1f2e719 VK |
37 | # if '*' is passed then all XS extensions are static |
38 | # (with possible exclusions) | |
ca58f2ae | 39 | %static = (); |
a1f2e719 | 40 | my @list = @_; |
14f183f1 | 41 | if (@_ and $_[0] eq '*') { |
a1f2e719 VK |
42 | my %excl = map {$_=>1} map {m/^!(.*)$/} @_[1 .. $#_]; |
43 | @list = grep {!exists $excl{$_}} keys %ext; | |
44 | } | |
45 | for (@list) { | |
ca58f2ae YST |
46 | $static{$_} = 1; |
47 | $ext{$_} = 'static' if $ext{$_} && $ext{$_} eq 'dynamic'; | |
48 | } | |
49 | } | |
50 | ||
8e232993 NIS |
51 | sub scan_ext |
52 | { | |
d57db09d | 53 | my $dir = shift; |
1f8a0b38 | 54 | find_ext("$dir/"); |
d57db09d | 55 | extensions(); |
8e232993 NIS |
56 | } |
57 | ||
442749d5 NC |
58 | sub _ext_eq { |
59 | my $key = shift; | |
60 | sub { | |
61 | sort grep $ext{$_} eq $key, keys %ext; | |
62 | } | |
ca58f2ae YST |
63 | } |
64 | ||
442749d5 NC |
65 | *dynamic_ext = _ext_eq('dynamic'); |
66 | *static_ext = _ext_eq('static'); | |
67 | *nonxs_ext = _ext_eq('nonxs'); | |
8e232993 | 68 | |
442749d5 NC |
69 | sub _ext_ne { |
70 | my $key = shift; | |
71 | sub { | |
72 | sort grep $ext{$_} ne $key, keys %ext; | |
73 | } | |
ca58f2ae YST |
74 | } |
75 | ||
442749d5 NC |
76 | *extensions = _ext_ne('known'); |
77 | # faithfully copy Configure in not including nonxs extensions for the nonce | |
78 | *known_extensions = _ext_ne('nonxs'); | |
ca58f2ae YST |
79 | |
80 | sub is_static | |
81 | { | |
82 | return $ext{$_[0]} eq 'static' | |
8e232993 NIS |
83 | } |
84 | ||
0a3660e3 NC |
85 | sub has_xs_or_c { |
86 | my $dir = shift; | |
87 | opendir my $dh, $dir or die "opendir $dir: $!"; | |
88 | while (defined (my $item = readdir $dh)) { | |
89 | return 1 if $item =~ /\.xs$/; | |
90 | return 1 if $item =~ /\.c$/; | |
91 | } | |
92 | return 0; | |
93 | } | |
94 | ||
1f8a0b38 | 95 | # Function to find available extensions, ignoring DynaLoader |
8e232993 NIS |
96 | sub find_ext |
97 | { | |
3380c781 | 98 | my $ext_dir = shift; |
1f8a0b38 | 99 | opendir my $dh, "$ext_dir"; |
3380c781 NC |
100 | while (defined (my $item = readdir $dh)) { |
101 | next if $item =~ /^\.\.?$/; | |
102 | next if $item eq "DynaLoader"; | |
1f8a0b38 NC |
103 | next unless -d "$ext_dir$item"; |
104 | my $this_ext = $item; | |
f44bdcee NC |
105 | my $leaf = $item; |
106 | ||
107 | $this_ext =~ s!-!/!g; | |
108 | $leaf =~ s/.*-//; | |
109 | ||
4d33dfde NC |
110 | # Temporary hack to cope with smokers that are not clearing directories: |
111 | next if $ext{$this_ext}; | |
112 | ||
88a6f4fc | 113 | if (has_xs_or_c("$ext_dir$item")) { |
3380c781 | 114 | $ext{$this_ext} = $static{$this_ext} ? 'static' : 'dynamic'; |
3380c781 | 115 | } else { |
1f8a0b38 | 116 | $ext{$this_ext} = 'nonxs'; |
ca58f2ae | 117 | } |
3380c781 | 118 | $ext{$this_ext} = 'known' if $ext{$this_ext} && $item =~ $no; |
ca58f2ae | 119 | } |
8e232993 NIS |
120 | } |
121 | ||
122 | 1; | |
3380c781 NC |
123 | # Local variables: |
124 | # cperl-indent-level: 4 | |
125 | # indent-tabs-mode: nil | |
126 | # End: | |
127 | # | |
128 | # ex: set ts=8 sts=4 sw=4 et: |