X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=win32%2FFindExt.pm;h=7bf9d52ca51978d2ea2050dc7c866b650855843f;hb=17c79f43379fc059c3c23c26a109c793268b3956;hp=30392687d1617c8fd53d00ce21092b2b838fe085;hpb=28b605d8910b6ca7063fcd3cd10e0b471b6b8c9b;p=p5sagit%2Fp5-mst-13.2.git diff --git a/win32/FindExt.pm b/win32/FindExt.pm index 3039268..7bf9d52 100644 --- a/win32/FindExt.pm +++ b/win32/FindExt.pm @@ -1,66 +1,96 @@ package FindExt; -our $VERSION = '1.00'; +our $VERSION = '1.02'; use strict; -use File::Find; -use File::Basename; -use Cwd; +use warnings; -my $no = join('|',qw(DynaLoader GDBM_File ODBM_File NDBM_File DB_File - Syslog SysV Langinfo)); +my $no = join('|',qw(GDBM_File ODBM_File NDBM_File DB_File + VMS Sys-Syslog IPC-SysV I18N-Langinfo)); $no = qr/^(?:$no)$/i; my %ext; -my $ext; +my %static; + +sub set_static_extensions { + # adjust results of scan_ext, and also save + # statics in case scan_ext hasn't been called yet. + # if '*' is passed then all XS extensions are static + # (with possible exclusions) + %static = (); + my @list = @_; + if ($_[0] eq '*') { + my %excl = map {$_=>1} map {m/^!(.*)$/} @_[1 .. $#_]; + @list = grep {!exists $excl{$_}} keys %ext; + } + for (@list) { + $static{$_} = 1; + $ext{$_} = 'static' if $ext{$_} && $ext{$_} eq 'dynamic'; + } +} + sub scan_ext { - my $here = getcwd(); - my $dir = shift; - chdir($dir) || die "Cannot cd to $dir\n"; - ($ext = getcwd()) =~ s,/,\\,g; - find(\&find_ext,'.'); - chdir($here) || die "Cannot cd to $here\n"; - my @ext = extensions(); + my $dir = shift; + find_ext("$dir/"); + extensions(); } -sub dynamic_extensions -{ - return grep $ext{$_} eq 'dynamic',keys %ext; +sub _ext_eq { + my $key = shift; + sub { + sort grep $ext{$_} eq $key, keys %ext; + } } -sub noxs_extensions -{ - return grep $ext{$_} eq 'nonxs',keys %ext; +*dynamic_ext = _ext_eq('dynamic'); +*static_ext = _ext_eq('static'); +*nonxs_ext = _ext_eq('nonxs'); + +sub _ext_ne { + my $key = shift; + sub { + sort grep $ext{$_} ne $key, keys %ext; + } } -sub extensions +*extensions = _ext_ne('known'); +# faithfully copy Configure in not including nonxs extensions for the nonce +*known_extensions = _ext_ne('nonxs'); + +sub is_static { - return keys %ext; + return $ext{$_[0]} eq 'static' } +# Function to find available extensions, ignoring DynaLoader sub find_ext { - if (/^(.*)\.pm$/i || /^(.*)_pm\.PL$/i || /^(.*)\.xs$/i) - { - my $name = $1; - return if $name =~ $no; - my $dir = $File::Find::dir; - $dir =~ s,./,,; - return if exists $ext{$dir}; - return unless -f "$ext/$dir/Makefile.PL"; - if ($dir =~ /$name$/i) - { - if (-f "$ext/$dir/$name.xs") - { - $ext{$dir} = 'dynamic'; - } - else - { - $ext{$dir} = 'nonxs'; - } + my $ext_dir = shift; + opendir my $dh, "$ext_dir"; + while (defined (my $item = readdir $dh)) { + next if $item =~ /^\.\.?$/; + next if $item eq "DynaLoader"; + next unless -d "$ext_dir$item"; + my $this_ext = $item; + my $leaf = $item; + + $this_ext =~ s!-!/!g; + $leaf =~ s/.*-//; + + if (-f "$ext_dir$item/$leaf.xs" || -f "$ext_dir$item/$leaf.c" ) { + $ext{$this_ext} = $static{$this_ext} ? 'static' : 'dynamic'; + } else { + $ext{$this_ext} = 'nonxs'; + } + $ext{$this_ext} = 'known' if $ext{$this_ext} && $item =~ $no; } - } } 1; +# Local variables: +# cperl-indent-level: 4 +# indent-tabs-mode: nil +# End: +# +# ex: set ts=8 sts=4 sw=4 et: