1package FindExt; 2 3our $VERSION = '1.01'; 4 5use strict; 6use warnings; 7 8my $no = join('|',qw(GDBM_File ODBM_File NDBM_File DB_File 9 Syslog SysV Langinfo)); 10$no = qr/^(?:$no)$/i; 11 12my %ext; 13my $ext; 14my %static; 15 16sub getcwd { 17 $ENV{'PWD'} = Win32::GetCwd(); 18 $ENV{'PWD'} =~ s:\\:/:g ; 19 return $ENV{'PWD'}; 20} 21 22sub set_static_extensions 23{ 24 # adjust results of scan_ext, and also save 25 # statics in case scan_ext hasn't been called yet. 26 %static = (); 27 for (@_) { 28 $static{$_} = 1; 29 $ext{$_} = 'static' if $ext{$_} && $ext{$_} eq 'dynamic'; 30 } 31} 32 33sub scan_ext 34{ 35 my $here = getcwd(); 36 my $dir = shift; 37 chdir($dir) || die "Cannot cd to $dir\n"; 38 ($ext = getcwd()) =~ s,/,\\,g; 39 find_ext(''); 40 chdir($here) || die "Cannot cd to $here\n"; 41 my @ext = extensions(); 42} 43 44sub dynamic_ext 45{ 46 return sort grep $ext{$_} eq 'dynamic',keys %ext; 47} 48 49sub static_ext 50{ 51 return sort grep $ext{$_} eq 'static',keys %ext; 52} 53 54sub nonxs_ext 55{ 56 return sort grep $ext{$_} eq 'nonxs',keys %ext; 57} 58 59sub extensions 60{ 61 return sort grep $ext{$_} ne 'known',keys %ext; 62} 63 64sub known_extensions 65{ 66 # faithfully copy Configure in not including nonxs extensions for the nonce 67 return sort grep $ext{$_} ne 'nonxs',keys %ext; 68} 69 70sub is_static 71{ 72 return $ext{$_[0]} eq 'static' 73} 74 75# Function to recursively find available extensions, ignoring DynaLoader 76# NOTE: recursion limit of 10 to prevent runaway in case of symlink madness 77sub find_ext 78{ 79 opendir my $dh, '.'; 80 my @items = grep { !/^\.\.?$/ } readdir $dh; 81 closedir $dh; 82 for my $xxx (@items) { 83 if ($xxx ne "DynaLoader") { 84 if (-f "$xxx/$xxx.xs") { 85 $ext{"$_[0]$xxx"} = $static{"$_[0]$xxx"} ? 'static' : 'dynamic'; 86 } elsif (-f "$xxx/Makefile.PL") { 87 $ext{"$_[0]$xxx"} = 'nonxs'; 88 } else { 89 if (-d $xxx && @_ < 10) { 90 chdir $xxx; 91 find_ext("$_[0]$xxx/", @_); 92 chdir ".."; 93 } 94 } 95 $ext{"$_[0]$xxx"} = 'known' if $ext{"$_[0]$xxx"} && $xxx =~ $no; 96 } 97 } 98 99# Special case: Add in threads/shared since it is not picked up by the 100# recursive find above (and adding in general recursive finding breaks 101# SDBM_File/sdbm). A.D. 10/25/2001. 102 103 if (!$_[0] && -d "threads/shared") { 104 $ext{"threads/shared"} = 'dynamic'; 105 } 106} 107 1081; 109