X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/f44bdceebeee2f09fe107f15d8b99b0280171932..65df57a84b55413fcde1e64b86e3d740485536d3:/win32/FindExt.pm diff --git a/win32/FindExt.pm b/win32/FindExt.pm index 9ba18b6..5f45a73 100644 --- a/win32/FindExt.pm +++ b/win32/FindExt.pm @@ -1,14 +1,36 @@ package FindExt; -our $VERSION = '1.02'; +our $VERSION = '1.03'; use strict; use warnings; -my $no = join('|',qw(GDBM_File ODBM_File NDBM_File DB_File - Syslog SysV Langinfo)); +my $no = join('|',qw(Amiga.* GDBM_File ODBM_File NDBM_File DB_File + VMS.* Sys-Syslog IPC-SysV I18N-Langinfo)); $no = qr/^(?:$no)$/i; +sub apply_config { + my ($config) = @_; + my @no; + + push @no, 'Sys-Syslog' if $^O eq 'MSWin32'; + + # duplicates logic from Configure (mostly) + push @no, "DB_File" unless $config->{i_db}; + push @no, "GDBM_File" unless $config->{i_gdbm}; + push @no, "I18N-Langinfo" unless $config->{i_langinfo} && $config->{d_nl_langinfo}; + push @no, "IPC-SysV" unless $config->{d_msg} || $config->{d_sem} || $config->{d_shm}; + push @no, "NDBM_File" unless $config->{d_ndbm}; + push @no, "ODBM_File" + unless ($config->{i_dbm} || $config->{i_rpcsvcdbm}) && !$config->{d_cplusplus}; + push @no, "Amiga.*" unless $^O eq "amigaos"; + push @no, "VMS.*" unless $^O eq "VMS"; + push @no, "Win32.*" unless $^O eq "MSWin32" || $^O eq "cygwin"; + + $no = join('|', @no); + $no = qr/^(?:$no)$/i; +} + my %ext; my %static; @@ -19,7 +41,7 @@ sub set_static_extensions { # (with possible exclusions) %static = (); my @list = @_; - if ($_[0] eq '*') { + if (@_ and $_[0] eq '*') { my %excl = map {$_=>1} map {m/^!(.*)$/} @_[1 .. $#_]; @list = grep {!exists $excl{$_}} keys %ext; } @@ -27,39 +49,41 @@ sub set_static_extensions { $static{$_} = 1; $ext{$_} = 'static' if $ext{$_} && $ext{$_} eq 'dynamic'; } -} - -sub scan_ext -{ - my $dir = shift; - find_ext("$dir/", ''); - extensions(); -} -sub dynamic_ext -{ - return sort grep $ext{$_} eq 'dynamic',keys %ext; + # Encode is a special case. If we are building Encode as a static + # extension, we need to explicitly list its subextensions as well. + # For other nested extensions, this is handled automatically by + # the appropriate Makefile.PL. + if ($ext{Encode} && $ext{Encode} eq 'static') { + require File::Find; + File::Find::find({ + no_chdir => 1, + wanted => sub { + return unless m!\b(Encode/.+)/Makefile\.PL!; + $static{$1} = 1; + $ext{$1} = 'static'; + }, + }, "../cpan/Encode"); + } } -sub static_ext -{ - return sort grep $ext{$_} eq 'static',keys %ext; +sub _ext_eq { + my $key = shift; + sub { + sort grep $ext{$_} eq $key, keys %ext; + } } -sub nonxs_ext -{ - return sort grep $ext{$_} eq 'nonxs',keys %ext; -} +*dynamic_ext = _ext_eq('dynamic'); +*static_ext = _ext_eq('static'); +*nonxs_ext = _ext_eq('nonxs'); -sub extensions -{ - return sort grep $ext{$_} ne 'known',keys %ext; +sub extensions { + sort grep $ext{$_} ne 'known', keys %ext; } -sub known_extensions -{ - # faithfully copy Configure in not including nonxs extensions for the nonce - return sort grep $ext{$_} ne 'nonxs',keys %ext; +sub known_extensions { + sort keys %ext; } sub is_static @@ -67,53 +91,46 @@ sub is_static return $ext{$_[0]} eq 'static' } -# Function to recursively find available extensions, ignoring DynaLoader -# NOTE: recursion limit of 10 to prevent runaway in case of symlink madness -sub find_ext +sub has_xs_or_c { + my $dir = shift; + opendir my $dh, $dir or die "opendir $dir: $!"; + while (defined (my $item = readdir $dh)) { + return 1 if $item =~ /\.xs$/; + return 1 if $item =~ /\.c$/; + } + return 0; +} + +# Function to find available extensions, ignoring DynaLoader +sub scan_ext { my $ext_dir = shift; - my $prefix = shift; - opendir my $dh, "$ext_dir$prefix"; + opendir my $dh, "$ext_dir"; while (defined (my $item = readdir $dh)) { next if $item =~ /^\.\.?$/; next if $item eq "DynaLoader"; - my $this_ext = my $this_ext_dir = "$prefix$item"; + next unless -d "$ext_dir/$item"; + my $this_ext = $item; my $leaf = $item; $this_ext =~ s!-!/!g; $leaf =~ s/.*-//; - if (-f "$ext_dir$this_ext_dir/$leaf.xs" || -f "$ext_dir$this_ext_dir/$leaf.c" ) { + # List/Util.xs lives in Scalar-List-Utils, Cwd.xs lives in PathTools + $this_ext = 'List/Util' if $this_ext eq 'Scalar/List/Utils'; + $this_ext = 'Cwd' if $this_ext eq 'PathTools'; + + # Temporary hack to cope with smokers that are not clearing directories: + next if $ext{$this_ext}; + + if (has_xs_or_c("$ext_dir/$item")) { $ext{$this_ext} = $static{$this_ext} ? 'static' : 'dynamic'; - } elsif (-f "$ext_dir$this_ext_dir/Makefile.PL") { - $ext{$this_ext} = 'nonxs'; } else { - # It's not actually an extension. So recurse into it. - if (-d "$ext_dir$this_ext_dir" && $prefix =~ tr#/## < 10) { - find_ext($ext_dir, "$this_ext_dir/"); - } + $ext{$this_ext} = 'nonxs'; } - $ext{$this_ext} = 'known' if $ext{$this_ext} && $item =~ $no; - } - -# Special case: Add in modules that nest beyond the first level. -# Currently threads/shared and Hash/Util/FieldHash, since they are -# not picked up by the recursive find above (and adding in general -# recursive finding breaks SDBM_File/sdbm). -# A.D. 20011025 (SDBM), ajgough 20071008 (FieldHash) - - if (!$prefix && -d "${ext_dir}threads/shared") { - $ext{"threads/shared"} = 'dynamic'; - } - if (!$prefix && -d "${ext_dir}Hash/Util/FieldHash") { - $ext{"Hash/Util/FieldHash"} = 'dynamic'; + $ext{$this_ext} = 'known' if $item =~ $no; } } 1; -# Local variables: -# cperl-indent-level: 4 -# indent-tabs-mode: nil -# End: -# # ex: set ts=8 sts=4 sw=4 et: