7 # To clarify, this isn't the entire suite of modules considered "toolchain"
8 # It's not even all modules needed to build ext/
9 # It's just the source paths of the (minimum complete set of) modules in ext/
10 # needed to build the nonxs modules
11 # After which, all nonxs modules are in lib, which was always sufficient to
12 # allow miniperl to build everything else.
14 my @toolchain = qw(ext/constant/lib ext/ExtUtils-Command/lib);
16 # This script acts as a simple interface for building extensions.
18 # It's actually a cut and shut of the Unix version ext/utils/makeext and the
19 # Windows version win32/build_ext.pl hence the two invocation styles.
21 # On Unix, it primarily used by the perl Makefile one extention at a time:
23 # d_dummy $(dynamic_ext): miniperl preplibrary FORCE
24 # @$(RUN) ./miniperl make_ext.pl --target=dynamic $@ MAKE=$(MAKE) LIBPERL_A=$(LIBPERL)
27 # If '--static' is specified, static extensions will be built.
28 # If '--dynamic' is specified, dynamic extensions will be built.
29 # If '--nonxs' is specified, nonxs extensions will be built.
30 # If '--all' is specified, all extensions will be built.
32 # make_ext.pl "MAKE=make [-make_opts]" --dir=directory [--target=target] [--static|--dynamic|--all] +ext2 !ext1
36 # make_ext.pl "MAKE=nmake -nologo" --dir=..\ext
38 # make_ext.pl "MAKE=nmake -nologo" --dir=..\ext --target=clean
40 # make_ext.pl MAKE=dmake --dir=..\ext
42 # make_ext.pl MAKE=dmake --dir=..\ext --target=clean
44 # Will skip building extensions which are marked with an '!' char.
45 # Mostly because they still not ported to specified platform.
47 # If any extensions are listed with a '+' char then only those
48 # extensions will be built, but only if they arent countermanded
49 # by an '!ext' and are appropriate to the type of building being done.
51 # It may be deleted in a later release of perl so try to
52 # avoid using it for other purposes.
54 my $is_Win32 = $^O eq 'MSWin32';
55 my $is_VMS = $^O eq 'VMS';
56 my $is_Unix = !$is_Win32 && !$is_VMS;
58 require FindExt if $is_Win32;
60 my (%excl, %incl, %opts, @extspec, @pass_through);
65 } elsif (/^\+(.*)$/) {
67 } elsif (/^--([\w\-]+)$/) {
69 } elsif (/^--([\w\-]+)=(.*)$/) {
72 push @pass_through, $_;
78 my $static = $opts{static} || $opts{all};
79 my $dynamic = $opts{dynamic} || $opts{all};
80 my $nonxs = $opts{nonxs} || $opts{all};
82 # The Perl Makefile.SH will expand all extensions to
83 # lib/auto/X/X.a (or lib/auto/X/Y/Y.a if nested)
84 # A user wishing to run make_ext might use
85 # X (or X/Y or X::Y if nested)
87 # canonise into X/Y form (pname)
90 if (s{^lib/auto/}{}) {
91 # Remove lib/auto prefix and /*.* suffix
93 } elsif (s{^ext/}{}) {
94 # Remove ext/ prefix and /pm_to_blib suffix
96 # Targets are given as files on disk, but the extension spec is still
97 # written using /s for each ::
99 } elsif (s{::}{\/}g) {
106 my $makecmd = shift @pass_through; # Should be something like MAKE=make
107 unshift @pass_through, 'PERL_CORE=1';
109 my $dir = $opts{dir} || 'ext';
110 my $target = $opts{target};
111 $target = 'all' unless defined $target;
113 # Previously, $make was taken from config.sh. However, the user might
114 # instead be running a possibly incompatible make. This might happen if
115 # the user types "gmake" instead of a plain "make", for example. The
116 # correct current value of MAKE will come through from the main perl
117 # makefile as MAKE=/whatever/make in $makecmd. We'll be cautious in
118 # case third party users of this script (are there any?) don't have the
119 # MAKE=$(MAKE) argument, which was added after 5.004_03.
120 unless(defined $makecmd and $makecmd =~ /^MAKE=(.*)$/) {
121 die "$0: WARNING: Please include MAKE=\$(MAKE) in \@ARGV\n";
124 # This isn't going to cope with anything fancy, such as spaces inside command
125 # names, but neither did what it replaced. Once there is a use case that needs
126 # it, please supply patches. Until then, I'm sticking to KISS
127 my @make = split ' ', $1 || $Config{make} || $ENV{MAKE};
128 # Using an array of 0 or 1 elements makes the subsequent code simpler.
129 my @run = $Config{run};
130 @run = () if not defined $run[0] or $run[0] eq '';
134 die "make_ext: no make target specified (eg all or clean)\n";
135 } elsif ($target !~ /(?:^all|clean)$/) {
136 # for the time being we are strict about what make_ext is used for
137 die "$0: unknown make target '$target'\n";
140 if (!@extspec and !$static and !$dynamic and !$nonxs) {
141 die "$0: no extension specified\n";
145 my %extra_passthrough;
148 (my $here = getcwd()) =~ s{/}{\\}g;
150 if ($perl =~ m#^\.\.#) {
151 $perl = "$here\\$perl";
153 (my $topdir = $perl) =~ s/\\[^\\]+$//;
154 # miniperl needs to find perlglob and pl2bat
155 $ENV{PATH} = "$topdir;$topdir\\win32\\bin;$ENV{PATH}";
156 my $pl2bat = "$topdir\\win32\\bin\\pl2bat";
157 unless (-f "$pl2bat.bat") {
158 my @args = ($perl, ("$pl2bat.pl") x 2);
160 system(@args) unless defined $::Cross::platform;
163 print "In ", getcwd();
164 chdir($dir) || die "Cannot cd to $dir\n";
165 (my $ext = getcwd()) =~ s{/}{\\}g;
166 FindExt::scan_ext($ext);
167 FindExt::set_static_extensions(split ' ', $Config{static_ext});
170 push @ext, FindExt::static_ext() if $static;
171 push @ext, FindExt::dynamic_ext() if $dynamic;
172 push @ext, FindExt::nonxs_ext() if $nonxs;
174 foreach (sort @ext) {
175 if (%incl and !exists $incl{$_}) {
176 #warn "Skipping extension $ext\\$_, not in inclusion list\n";
179 if (exists $excl{$_}) {
180 warn "Skipping extension $ext\\$_, not ported to current platform";
184 if(FindExt::is_static($_)) {
185 push @{$extra_passthrough{$_}}, 'LINKTYPE=static';
188 chdir '..'; # now in the Perl build directory
192 push @extspec, (split ' ', $Config{static_ext}) if $static;
193 push @extspec, (split ' ', $Config{dynamic_ext}) if $dynamic;
194 push @extspec, (split ' ', $Config{nonxs_ext}) if $nonxs;
197 foreach my $spec (@extspec) {
201 if (-d "ext/$spec") {
202 # Old style ext/Data/Dumper/
203 $ext_pathname = "ext/$spec";
205 # New style ext/Data-Dumper/
208 $ext_pathname = "ext/$copy";
211 if ($Config{osname} eq 'catamount') {
212 # Snowball's chance of building extensions.
213 die "This is $Config{osname}, not building $mname, sorry.\n";
216 print "\tMaking $mname ($target)\n";
218 build_extension($ext_pathname, $perl, $mname,
219 [@pass_through, @{$extra_passthrough{$spec} || []}]);
222 sub build_extension {
223 my ($ext_dir, $perl, $mname, $pass_through) = @_;
228 $perl ||= "$up/miniperl";
229 my $return_dir = $up;
230 my $lib_dir = "$up/lib";
232 = join $Config{path_sep}, $lib_dir, map {"$up/$_"} @toolchain;
234 unless (chdir "$ext_dir") {
235 warn "Cannot cd to $ext_dir: $!";
240 $makefile = 'descrip.mms';
241 if ($target =~ /clean$/
243 && -f "${makefile}_old") {
244 $makefile = "${makefile}_old";
247 $makefile = 'Makefile';
251 if (!-f 'Makefile.PL') {
252 print "\nCreating Makefile.PL in $ext_dir for $mname\n";
253 # We need to cope well with various possible layouts
254 my @dirs = split /::/, $mname;
255 my $leaf = pop @dirs;
256 my $leafname = "$leaf.pm";
257 my $pathname = join '/', @dirs, $leafname;
258 my @locations = ($leafname, $pathname, "lib/$pathname");
260 foreach (@locations) {
268 die "For $mname tried @locations in in $ext_dir but can't find source";
270 open my $fh, '>', 'Makefile.PL'
271 or die "Can't open Makefile.PL for writing: $!";
273 #-*- buffer-read-only: t -*-
275 # This Makefile.PL was written by $0.
276 # It will be deleted automatically by make realclean
279 use ExtUtils::MakeMaker;
283 VERSION_FROM => '$fromname',
284 ABSTRACT_FROM => '$fromname',
285 realclean => {FILES => 'Makefile.PL'},
290 close $fh or die "Can't close Makefile.PL: $!";
292 print "\nRunning Makefile.PL in $ext_dir\n";
294 # Presumably this can be simplified
296 if (defined $::Cross::platform) {
297 # Inherited from win32/buildext.pl
298 @cross = "-MCross=$::Cross::platform";
299 } elsif ($opts{cross}) {
300 # Inherited from make_ext.pl
304 my @args = (@cross, 'Makefile.PL');
306 my $libd = VMS::Filespec::vmspath($lib_dir);
307 push @args, "INST_LIB=$libd", "INST_ARCHLIB=$libd";
309 push @args, 'INSTALLDIRS=perl', 'INSTALLMAN1DIR=none',
310 'INSTALLMAN3DIR=none';
312 push @args, @$pass_through;
313 _quote_args(\@args) if $is_VMS;
314 print join(' ', @run, $perl, @args), "\n";
315 my $code = system @run, $perl, @args;
316 warn "$code from $ext_dir\'s Makefile.PL" if $code;
318 # Right. The reason for this little hack is that we're sitting inside
319 # a program run by ./miniperl, but there are tasks we need to perform
320 # when the 'realclean', 'distclean' or 'veryclean' targets are run.
321 # Unfortunately, they can be run *after* 'clean', which deletes
323 # So we do our best to leave a set of instructions identical to what
324 # we would do if we are run directly as 'realclean' etc
325 # Whilst we're perfect, unfortunately the targets we call are not, as
326 # some of them rely on a $(PERL) for their own distclean targets.
327 # But this always used to be a problem with the old /bin/sh version of
331 foreach my $clean_target ('realclean', 'veryclean') {
332 my $file = "$return_dir/$clean_target$suffix";
333 open my $fh, '>>', $file or die "open $file: $!";
334 # Quite possible that we're being run in parallel here.
335 # Can't use Fcntl this early to get the LOCK_EX
336 flock $fh, 2 or warn "flock $file: $!";
339 if test ! -f Makefile -a -f Makefile.old; then
340 echo "Note: Using Makefile.old"
341 make -f Makefile.old $clean_target MAKE='@make' @pass_through
343 if test ! -f Makefile ; then
344 echo "Warning: No Makefile!"
346 make $clean_target MAKE='@make' @pass_through
350 close $fh or die "close $file: $!";
355 if (not -f $makefile) {
356 print "Warning: No Makefile!\n";
360 _macroify_passthrough($pass_through);
361 unshift @$pass_through, "/DESCRIPTION=$makefile";
364 if (!$target or $target !~ /clean$/) {
365 # Give makefile an opportunity to rewrite itself.
366 # reassure users that life goes on...
367 my @args = ('config', @$pass_through);
368 _quote_args(\@args) if $is_VMS;
369 system(@run, @make, @args) and print "@run @make @args failed, continuing anyway...\n";
371 my @targ = ($target, @$pass_through);
372 _quote_args(\@targ) if $is_VMS;
373 print "Making $target in $ext_dir\n@run @make @targ\n";
374 my $code = system(@run, @make, @targ);
375 die "Unsuccessful make($ext_dir): code=$code" if $code != 0;
377 chdir $return_dir || die "Cannot cd to $return_dir: $!";
381 my $args = shift; # must be array reference
383 # Do not quote qualifiers that begin with '/'.
385 $_ =~ s/\"/""/g; # escape C<"> by doubling
392 sub _macroify_passthrough {
393 my $passthrough = shift;
394 _quote_args($passthrough);
395 my $macro = '/MACRO=(' . join(',',@$passthrough) . ')';
397 @$passthrough[0] = $macro;