This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Enough changes to Configure and metaunits warrant an update.
[perl5.git] / win32 / buildext.pl
1 =head1 NAME
2
3 buildext.pl - build extensions
4
5 =head1 SYNOPSIS
6
7     buildext.pl make [-make_opts] dep directory [target] !ext1 !ext2
8
9 E.g.
10
11     buildext.pl nmake -nologo perldll.def ..\ext
12
13     buildext.pl nmake -nologo perldll.def ..\ext clean
14
15     buildext.pl dmake perldll.def ..\ext
16
17     buildext.pl dmake perldll.def ..\ext clean
18
19 Will skip building extensions which are marked with an '!' char.
20 Mostly because they still not ported to specified platform.
21
22 =cut
23
24 use File::Basename;
25 use Cwd;
26 use FindExt;
27
28 # @ARGV with '!' at first position are exclusions
29 my %excl = map {$_=>1} map {/^!(.*)$/} @ARGV;
30 @ARGV = grep {!/^!/} @ARGV;
31
32 my $here = getcwd();
33 my $perl = $^X;
34 $here =~ s,/,\\,g;
35 if ($perl =~ m#^\.\.#)
36  {
37   $perl = "$here\\$perl";
38  }
39 (my $topdir = $perl) =~ s/\\[^\\]+$//;
40 # miniperl needs to find perlglob and pl2bat
41 $ENV{PATH} = "$topdir;$topdir\\win32\\bin;$ENV{PATH}";
42 #print "PATH=$ENV{PATH}\n";
43 my $pl2bat = "$topdir\\win32\\bin\\pl2bat";
44 unless (-f "$pl2bat.bat") {
45     my @args = ($perl, ("$pl2bat.pl") x 2);
46     print "@args\n";
47     system(@args) unless defined $::Cross::platform;
48 }
49 my $make = shift;
50 $make .= " ".shift while $ARGV[0]=~/^-/;
51 my $dep  = shift;
52 my $dmod = -M $dep;
53 my $dir  = shift;
54 chdir($dir) || die "Cannot cd to $dir\n";
55 my $targ  = shift;
56 (my $ext = getcwd()) =~ s,/,\\,g;
57 my $code;
58 FindExt::scan_ext($ext);
59
60 my @ext = FindExt::extensions();
61
62 foreach my $dir (sort @ext)
63  {
64   if (exists $excl{$dir}) {
65     warn "Skipping extension $ext\\$dir, not ported to current platform";
66     next;
67   }
68   if (chdir("$ext\\$dir"))
69    {
70     my $mmod = -M 'Makefile';
71     if (!(-f 'Makefile') || $mmod > $dmod)
72      {
73       print "\nRunning Makefile.PL in $dir\n";
74       my @perl = ($perl, "-I$here\\..\\lib", 'Makefile.PL',
75                   'INSTALLDIRS=perl', 'PERL_CORE=1');
76       if (defined $::Cross::platform) {
77         @perl = (@perl[0,1],"-MCross=$::Cross::platform",@perl[2..$#perl]);
78       }
79       print join(' ', @perl), "\n";
80       $code = system(@perl);
81       warn "$code from $dir's Makefile.PL" if $code;
82       $mmod = -M 'Makefile';
83       if ($mmod > $dmod)
84        {
85         warn "Makefile $mmod > $dmod ($dep)\n";
86        }
87      }  
88     if ($targ)
89      {
90       print "Making $targ in $dir\n$make $targ\n";
91       $code = system("$make $targ");
92       die "Unsuccessful make($dir): code=$code" if $code!=0;
93      }
94     else
95      {
96       print "Making $dir\n$make\n";
97       $code = system($make);
98       die "Unsuccessful make($dir): code=$code" if $code!=0;
99      }
100     chdir($here) || die "Cannot cd to $here:$!";
101    }
102   else
103    {
104     warn "Cannot cd to $ext\\$dir:$!";
105    }
106  }
107