Upgrade DB_File to 1.818.
[p5sagit/p5-mst-13.2.git] / win32 / buildext.pl
CommitLineData
7e050124 1=head1 NAME
2
3buildext.pl - build extensions
4
5=head1 SYNOPSIS
6
1a76ca1a 7 buildext.pl "MAKE=make [-make_opts]" --dir=directory [--target=target] [--static|--dynamic|--all] +ext2 !ext1
7e050124 8
9E.g.
10
1a76ca1a 11 buildext.pl "MAKE=nmake -nologo" --dir=..\ext
7e050124 12
1a76ca1a 13 buildext.pl "MAKE=nmake -nologo" --dir=..\ext --target=clean
7e050124 14
1a76ca1a 15 buildext.pl MAKE=dmake --dir=..\ext
7e050124 16
1a76ca1a 17 buildext.pl MAKE=dmake --dir=..\ext --target=clean
7e050124 18
fefd7080 19Will skip building extensions which are marked with an '!' char.
20Mostly because they still not ported to specified platform.
21
a24cc0c0 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 26If '--static' specified, only static extensions will be built.
27If '--dynamic' specified, only dynamic extensions will be built.
28
7e050124 29=cut
30
aaaf44d7 31use strict;
17af6fb0 32use Cwd;
484c6321 33require FindExt;
d2b25974 34use Config;
fefd7080 35
36# @ARGV with '!' at first position are exclusions
a24cc0c0 37# @ARGV with '+' at first position are inclusions
4feb7f09 38# -- are long options.
39
484c6321 40my (%excl, %incl, %opts, @extspec, @pass_through);
4feb7f09 41
42foreach (@ARGV) {
43 if (/^!(.*)$/) {
44 $excl{$1} = 1;
45 } elsif (/^\+(.*)$/) {
46 $incl{$1} = 1;
47 } elsif (/^--([\w\-]+)$/) {
48 $opts{$1} = 1;
1a76ca1a 49 } elsif (/^--([\w\-]+)=(.*)$/) {
50 $opts{$1} = $2;
484c6321 51 } elsif (/=/) {
52 push @pass_through, $_;
4feb7f09 53 } else {
484c6321 54 push @extspec, $_;
4feb7f09 55 }
d2b25974 56}
d2b25974 57
aaaf44d7 58my $static = $opts{static} || $opts{all};
59my $dynamic = $opts{dynamic} || $opts{all};
4feb7f09 60
484c6321 61my $makecmd = shift @pass_through;
62unshift @pass_through, 'PERL_CORE=1';
63
1a76ca1a 64my $dir = $opts{dir} || 'ext';
484c6321 65my $target = $opts{target};
66$target = 'all' unless defined $target;
4feb7f09 67
eb1f8df7 68unless(defined $makecmd and $makecmd =~ /^MAKE=(.*)$/) {
69 die "$0: WARNING: Please include MAKE=\$(MAKE) in \@ARGV\n";
8ed969f8 70}
484c6321 71
eb1f8df7 72# This isn't going to cope with anything fancy, such as spaces inside command
73# names, but neither did what it replaced. Once there is a use case that needs
74# it, please supply patches. Until then, I'm sticking to KISS
75my @make = split ' ', $1 || $Config{make} || $ENV{MAKE};
76# Using an array of 0 or 1 elements makes the subsequent code simpler.
484c6321 77my @run = $Config{run};
78@run = () if not defined $run[0] or $run[0] eq '';
8ed969f8 79
a1f2e719 80(my $here = getcwd()) =~ s{/}{\\}g;
17af6fb0 81my $perl = $^X;
a1f2e719 82if ($perl =~ m#^\.\.#) {
83 $perl = "$here\\$perl";
84}
200dcf2d 85(my $topdir = $perl) =~ s/\\[^\\]+$//;
3a7016a8 86# miniperl needs to find perlglob and pl2bat
87$ENV{PATH} = "$topdir;$topdir\\win32\\bin;$ENV{PATH}";
3a7016a8 88my $pl2bat = "$topdir\\win32\\bin\\pl2bat";
89unless (-f "$pl2bat.bat") {
90 my @args = ($perl, ("$pl2bat.pl") x 2);
91 print "@args\n";
fefd7080 92 system(@args) unless defined $::Cross::platform;
3a7016a8 93}
4feb7f09 94
1a76ca1a 95print "In ", getcwd();
17af6fb0 96chdir($dir) || die "Cannot cd to $dir\n";
a1f2e719 97(my $ext = getcwd()) =~ s{/}{\\}g;
8e232993 98FindExt::scan_ext($ext);
1a76ca1a 99FindExt::set_static_extensions(split ' ', $Config{static_ext});
17af6fb0 100
3fd041e4 101my @ext;
102push @ext, FindExt::static_ext() if $static;
103push @ext, FindExt::dynamic_ext(), FindExt::nonxs_ext() if $dynamic;
8e232993 104
a24cc0c0 105
d2b25974 106foreach $dir (sort @ext)
17af6fb0 107 {
a24cc0c0 108 if (%incl and !exists $incl{$dir}) {
109 #warn "Skipping extension $ext\\$dir, not in inclusion list\n";
110 next;
111 }
fefd7080 112 if (exists $excl{$dir}) {
113 warn "Skipping extension $ext\\$dir, not ported to current platform";
114 next;
115 }
484c6321 116
117 build_extension($ext, "$ext\\$dir", $here, "$here\\..\\lib",
118 [@pass_through,
119 FindExt::is_static($dir) ? ('LINKTYPE=static') : ()]);
120 }
121
122sub build_extension {
123 my ($ext, $ext_dir, $return_dir, $lib_dir, $pass_through) = @_;
124 unless (chdir "$ext_dir") {
125 warn "Cannot cd to $ext_dir: $!";
126 return;
127 }
128
129 if (!-f 'Makefile') {
130 print "\nRunning Makefile.PL in $ext_dir\n";
131
132 # Presumably this can be simplified
133 my @cross;
134 if (defined $::Cross::platform) {
135 # Inherited from win32/buildext.pl
136 @cross = "-MCross=$::Cross::platform";
137 } elsif ($opts{cross}) {
138 # Inherited from make_ext.pl
139 @cross = '-MCross';
140 }
141
142 my @perl = (@run, $perl, "-I$lib_dir", @cross, 'Makefile.PL',
143 'INSTALLDIRS=perl', 'INSTALLMAN3DIR=none', 'PERL_CORE=1',
144 @$pass_through);
145 print join(' ', @perl), "\n";
146 my $code = system @perl;
147 warn "$code from $ext_dir\'s Makefile.PL" if $code;
148 }
149 if (!$target or $target !~ /clean$/) {
42fe6305 150 # Give makefile an opportunity to rewrite itself.
151 # reassure users that life goes on...
eb1f8df7 152 my @config = (@run, @make, 'config', @$pass_through);
484c6321 153 system @config and print "@config failed, continuing anyway...\n";
42fe6305 154 }
eb1f8df7 155 my @targ = (@run, @make, $target, @$pass_through);
a79902b1 156 print "Making $target in $ext_dir\n@targ\n";
484c6321 157 my $code = system @targ;
158 die "Unsuccessful make($ext_dir): code=$code" if $code != 0;
17af6fb0 159
484c6321 160 chdir $return_dir || die "Cannot cd to $return_dir: $!";
161}