Integrate change #9530 from maintperl into mainline.
[p5sagit/p5-mst-13.2.git] / win32 / buildext.pl
CommitLineData
17af6fb0 1use File::Find;
2use File::Basename;
3use Cwd;
4my $here = getcwd();
5my $perl = $^X;
6$here =~ s,/,\\,g;
7if ($perl =~ m#^\.\.#)
8 {
9 $perl = "$here\\$perl";
10 }
11my $make = shift;
f76dcffd 12$make .= " ".shift while $ARGV[0]=~/^-/;
17af6fb0 13my $dep = shift;
14my $dmod = -M $dep;
15my $dir = shift;
16chdir($dir) || die "Cannot cd to $dir\n";
17(my $ext = getcwd()) =~ s,/,\\,g;
18my $no = join('|',qw(DynaLoader GDBM_File ODBM_File NDBM_File DB_File Syslog Sysv));
19$no = qr/^(?:$no)$/i;
20my %ext;
21find(\&find_xs,'.');
22
23foreach my $dir (sort keys %ext)
24 {
25 if (chdir("$ext\\$dir"))
26 {
27 my $mmod = -M 'Makefile';
28 if (!(-f 'Makefile') || $mmod > $dmod)
29 {
0026721a 30 print "\nRunning Makefile.PL in $dir\n";
17af6fb0 31 my $code = system($perl,"-I$here\\..\lib",'Makefile.PL','INSTALLDIRS=perl');
32 warn "$code from $dir's Makefile.PL" if $code;
33 $mmod = -M 'Makefile';
34 if ($mmod > $dmod)
35 {
36 warn "Makefile $mmod > $dmod ($dep)\n";
37 }
38 }
39 print "\nMaking $dir\n";
40 system($make);
41 chdir($here) || die "Cannot cd to $here:$!";
42 }
43 else
44 {
45 warn "Cannot cd to $ext\\$dir:$!";
46 }
47 }
48
49sub find_xs
50{
0026721a 51 if (/^(.*)\.pm$/i || /^(.*)_pm.PL$/i)
17af6fb0 52 {
53 my $name = $1;
54 return if $name =~ $no;
55 my $dir = $File::Find::dir;
56 $dir =~ s,./,,;
57 return if exists $ext{$dir};
58 return unless -f "$ext/$dir/Makefile.PL";
59 if ($dir =~ /$name$/i)
60 {
61 $ext{$dir} = $name;
62 }
63 }
f76dcffd 64}