This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Break the --create-perllibst-h and --list-static-libs options out of buildext.pl
[perl5.git] / win32 / buildext.pl
CommitLineData
7e050124
PK
1=head1 NAME
2
3buildext.pl - build extensions
4
5=head1 SYNOPSIS
6
a24cc0c0 7 buildext.pl make [-make_opts] dep directory [target] [--static|--dynamic] +ext2 !ext1
7e050124
PK
8
9E.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
fefd7080
VK
19Will skip building extensions which are marked with an '!' char.
20Mostly because they still not ported to specified platform.
21
a24cc0c0
YO
22If any extensions are listed with a '+' char then only those
23extensions will be built, but only if they arent countermanded
24by an '!ext' and are appropriate to the type of building being done.
25
d2b25974
VK
26If '--static' specified, only static extensions will be built.
27If '--dynamic' specified, only dynamic extensions will be built.
28
7e050124
PK
29=cut
30
17af6fb0 31use Cwd;
8e232993 32use FindExt;
d2b25974 33use Config;
fefd7080
VK
34
35# @ARGV with '!' at first position are exclusions
36my %excl = map {$_=>1} map {/^!(.*)$/} @ARGV;
37@ARGV = grep {!/^!/} @ARGV;
a24cc0c0
YO
38# @ARGV with '+' at first position are inclusions
39my %incl = map {$_=>1} map {/^\+(.*)$/} @ARGV;
40@ARGV = grep {!/^\+/} @ARGV;
fefd7080 41
d2b25974
VK
42# --static/--dynamic
43my %opts = map {$_=>1} map {/^--([\w\-]+)$/} @ARGV;
44@ARGV = grep {!/^--([\w\-]+)$/} @ARGV;
45my ($static,$dynamic) = ((exists $opts{static}?1:0),(exists $opts{dynamic}?1:0));
46if ("$static,$dynamic" eq "0,0") {
47 ($static,$dynamic) = (1,1);
48}
d2b25974 49
a1f2e719 50(my $here = getcwd()) =~ s{/}{\\}g;
17af6fb0 51my $perl = $^X;
a1f2e719
VK
52if ($perl =~ m#^\.\.#) {
53 $perl = "$here\\$perl";
54}
200dcf2d 55(my $topdir = $perl) =~ s/\\[^\\]+$//;
3a7016a8
GS
56# miniperl needs to find perlglob and pl2bat
57$ENV{PATH} = "$topdir;$topdir\\win32\\bin;$ENV{PATH}";
3a7016a8
GS
58my $pl2bat = "$topdir\\win32\\bin\\pl2bat";
59unless (-f "$pl2bat.bat") {
60 my @args = ($perl, ("$pl2bat.pl") x 2);
61 print "@args\n";
fefd7080 62 system(@args) unless defined $::Cross::platform;
3a7016a8 63}
17af6fb0 64my $make = shift;
f76dcffd 65$make .= " ".shift while $ARGV[0]=~/^-/;
17af6fb0
NIS
66my $dep = shift;
67my $dmod = -M $dep;
68my $dir = shift;
69chdir($dir) || die "Cannot cd to $dir\n";
7e050124 70my $targ = shift;
a1f2e719 71(my $ext = getcwd()) =~ s{/}{\\}g;
fefd7080 72my $code;
8e232993 73FindExt::scan_ext($ext);
3fd041e4 74FindExt::set_static_extensions(split ' ', $Config{static_ext}) if $ext ne "ext";
17af6fb0 75
3fd041e4
YST
76my @ext;
77push @ext, FindExt::static_ext() if $static;
78push @ext, FindExt::dynamic_ext(), FindExt::nonxs_ext() if $dynamic;
8e232993 79
a24cc0c0 80
d2b25974 81foreach $dir (sort @ext)
17af6fb0 82 {
a24cc0c0
YO
83 if (%incl and !exists $incl{$dir}) {
84 #warn "Skipping extension $ext\\$dir, not in inclusion list\n";
85 next;
86 }
fefd7080
VK
87 if (exists $excl{$dir}) {
88 warn "Skipping extension $ext\\$dir, not ported to current platform";
89 next;
90 }
17af6fb0
NIS
91 if (chdir("$ext\\$dir"))
92 {
93 my $mmod = -M 'Makefile';
94 if (!(-f 'Makefile') || $mmod > $dmod)
95 {
0026721a 96 print "\nRunning Makefile.PL in $dir\n";
e7d8b26b 97 my @perl = ($perl, "-I$here\\..\\lib", 'Makefile.PL',
d2b25974 98 'INSTALLDIRS=perl', 'PERL_CORE=1',
3fd041e4
YST
99 (FindExt::is_static($dir)
100 ? ('LINKTYPE=static') : ()), # if ext is static
d2b25974 101 );
fefd7080
VK
102 if (defined $::Cross::platform) {
103 @perl = (@perl[0,1],"-MCross=$::Cross::platform",@perl[2..$#perl]);
104 }
e7d8b26b 105 print join(' ', @perl), "\n";
fefd7080 106 $code = system(@perl);
d2b25974 107 warn "$code from $dir\'s Makefile.PL" if $code;
17af6fb0
NIS
108 $mmod = -M 'Makefile';
109 if ($mmod > $dmod)
110 {
111 warn "Makefile $mmod > $dmod ($dep)\n";
112 }
113 }
7e050124
PK
114 if ($targ)
115 {
116 print "Making $targ in $dir\n$make $targ\n";
fefd7080
VK
117 $code = system("$make $targ");
118 die "Unsuccessful make($dir): code=$code" if $code!=0;
7e050124
PK
119 }
120 else
121 {
122 print "Making $dir\n$make\n";
fefd7080
VK
123 $code = system($make);
124 die "Unsuccessful make($dir): code=$code" if $code!=0;
7e050124 125 }
17af6fb0
NIS
126 chdir($here) || die "Cannot cd to $here:$!";
127 }
128 else
129 {
130 warn "Cannot cd to $ext\\$dir:$!";
131 }
132 }
133