8 # To clarify, this isn't the entire suite of modules considered "toolchain"
9 # It's not even all modules needed to build ext/
10 # It's just the source paths of the (minimum complete set of) modules in ext/
11 # needed to build the nonxs modules
12 # After which, all nonxs modules are in lib, which was always sufficient to
13 # allow miniperl to build everything else.
15 my @toolchain = qw(ext/constant/lib ext/Cwd ext/ExtUtils-Command/lib
16 ext/ExtUtils-Install/lib ext/ExtUtils-MakeMaker/lib
17 ext/ExtUtils-Manifest/lib ext/Text-ParseWords/lib
18 ext/File-Path/lib ext/AutoLoader/lib);
20 # This script acts as a simple interface for building extensions.
22 # It's actually a cut and shut of the Unix version ext/utils/makeext and the
23 # Windows version win32/build_ext.pl hence the two invocation styles.
25 # On Unix, it primarily used by the perl Makefile one extention at a time:
27 # d_dummy $(dynamic_ext): miniperl preplibrary FORCE
28 # @$(RUN) ./miniperl make_ext.pl --target=dynamic $@ MAKE=$(MAKE) LIBPERL_A=$(LIBPERL)
31 # If '--static' is specified, static extensions will be built.
32 # If '--dynamic' is specified, dynamic extensions will be built.
33 # If '--nonxs' is specified, nonxs extensions will be built.
34 # If '--all' is specified, all extensions will be built.
36 # make_ext.pl "MAKE=make [-make_opts]" --dir=directory [--target=target] [--static|--dynamic|--all] +ext2 !ext1
40 # make_ext.pl "MAKE=nmake -nologo" --dir=..\ext
42 # make_ext.pl "MAKE=nmake -nologo" --dir=..\ext --target=clean
44 # make_ext.pl MAKE=dmake --dir=..\ext
46 # make_ext.pl MAKE=dmake --dir=..\ext --target=clean
48 # Will skip building extensions which are marked with an '!' char.
49 # Mostly because they still not ported to specified platform.
51 # If any extensions are listed with a '+' char then only those
52 # extensions will be built, but only if they arent countermanded
53 # by an '!ext' and are appropriate to the type of building being done.
55 # It may be deleted in a later release of perl so try to
56 # avoid using it for other purposes.
58 my $is_Win32 = $^O eq 'MSWin32';
59 my $is_VMS = $^O eq 'VMS';
60 my $is_Unix = !$is_Win32 && !$is_VMS;
62 require FindExt if $is_Win32;
64 my (%excl, %incl, %opts, @extspec, @pass_through);
69 } elsif (/^\+(.*)$/) {
71 } elsif (/^--([\w\-]+)$/) {
73 } elsif (/^--([\w\-]+)=(.*)$/) {
76 push @pass_through, $_;
82 my $static = $opts{static} || $opts{all};
83 my $dynamic = $opts{dynamic} || $opts{all};
84 my $nonxs = $opts{nonxs} || $opts{all};
86 # The Perl Makefile.SH will expand all extensions to
87 # lib/auto/X/X.a (or lib/auto/X/Y/Y.a if nested)
88 # A user wishing to run make_ext might use
89 # X (or X/Y or X::Y if nested)
91 # canonise into X/Y form (pname)
94 if (s{^lib/auto/}{}) {
95 # Remove lib/auto prefix and /*.* suffix
97 } elsif (s{^ext/}{}) {
98 # Remove ext/ prefix and /pm_to_blib suffix
100 # Targets are given as files on disk, but the extension spec is still
101 # written using /s for each ::
103 } elsif (s{::}{\/}g) {
110 my $makecmd = shift @pass_through; # Should be something like MAKE=make
111 unshift @pass_through, 'PERL_CORE=1';
113 my $dir = $opts{dir} || 'ext';
114 my $target = $opts{target};
115 $target = 'all' unless defined $target;
117 # Previously, $make was taken from config.sh. However, the user might
118 # instead be running a possibly incompatible make. This might happen if
119 # the user types "gmake" instead of a plain "make", for example. The
120 # correct current value of MAKE will come through from the main perl
121 # makefile as MAKE=/whatever/make in $makecmd. We'll be cautious in
122 # case third party users of this script (are there any?) don't have the
123 # MAKE=$(MAKE) argument, which was added after 5.004_03.
124 unless(defined $makecmd and $makecmd =~ /^MAKE=(.*)$/) {
125 die "$0: WARNING: Please include MAKE=\$(MAKE) in \@ARGV\n";
128 # This isn't going to cope with anything fancy, such as spaces inside command
129 # names, but neither did what it replaced. Once there is a use case that needs
130 # it, please supply patches. Until then, I'm sticking to KISS
131 my @make = split ' ', $1 || $Config{make} || $ENV{MAKE};
132 # Using an array of 0 or 1 elements makes the subsequent code simpler.
133 my @run = $Config{run};
134 @run = () if not defined $run[0] or $run[0] eq '';
138 die "make_ext: no make target specified (eg all or clean)\n";
139 } elsif ($target !~ /(?:^all|clean)$/) {
140 # for the time being we are strict about what make_ext is used for
141 die "$0: unknown make target '$target'\n";
144 if (!@extspec and !$static and !$dynamic and !$nonxs) {
145 die "$0: no extension specified\n";
149 my %extra_passthrough;
152 (my $here = getcwd()) =~ s{/}{\\}g;
154 if ($perl =~ m#^\.\.#) {
155 $perl = "$here\\$perl";
157 (my $topdir = $perl) =~ s/\\[^\\]+$//;
158 # miniperl needs to find perlglob and pl2bat
159 $ENV{PATH} = "$topdir;$topdir\\win32\\bin;$ENV{PATH}";
160 my $pl2bat = "$topdir\\win32\\bin\\pl2bat";
161 unless (-f "$pl2bat.bat") {
162 my @args = ($perl, ("$pl2bat.pl") x 2);
164 system(@args) unless defined $::Cross::platform;
167 print "In ", getcwd();
168 chdir($dir) || die "Cannot cd to $dir\n";
169 (my $ext = getcwd()) =~ s{/}{\\}g;
170 FindExt::scan_ext($ext);
171 FindExt::set_static_extensions(split ' ', $Config{static_ext});
174 push @ext, FindExt::static_ext() if $static;
175 push @ext, FindExt::dynamic_ext() if $dynamic;
176 push @ext, FindExt::nonxs_ext() if $nonxs;
178 foreach (sort @ext) {
179 if (%incl and !exists $incl{$_}) {
180 #warn "Skipping extension $ext\\$_, not in inclusion list\n";
183 if (exists $excl{$_}) {
184 warn "Skipping extension $ext\\$_, not ported to current platform";
188 if(FindExt::is_static($_)) {
189 push @{$extra_passthrough{$_}}, 'LINKTYPE=static';
192 chdir '..'; # now in the Perl build directory
196 push @extspec, (split ' ', $Config{static_ext}) if $static;
197 push @extspec, (split ' ', $Config{dynamic_ext}) if $dynamic;
198 push @extspec, (split ' ', $Config{nonxs_ext}) if $nonxs;
201 foreach my $spec (@extspec) {
205 if (-d "ext/$spec") {
206 # Old style ext/Data/Dumper/
207 $ext_pathname = "ext/$spec";
209 # New style ext/Data-Dumper/
212 $ext_pathname = "ext/$copy";
215 if ($Config{osname} eq 'catamount') {
216 # Snowball's chance of building extensions.
217 die "This is $Config{osname}, not building $mname, sorry.\n";
220 print "\tMaking $mname ($target)\n";
222 build_extension($ext_pathname, $perl, $mname,
223 [@pass_through, @{$extra_passthrough{$spec} || []}]);
226 sub build_extension {
227 my ($ext_dir, $perl, $mname, $pass_through) = @_;
232 $perl ||= "$up/miniperl";
233 my $return_dir = $up;
234 my $lib_dir = "$up/lib";
235 # $lib_dir must be last, as we're copying files into it, and in a parallel
236 # make there's a race condition if one process tries to open a module that
237 # another process has half-written.
239 = join $Config{path_sep}, (map {"$up/$_"} @toolchain), $lib_dir;
241 unless (chdir "$ext_dir") {
242 warn "Cannot cd to $ext_dir: $!";
247 $makefile = 'descrip.mms';
248 if ($target =~ /clean$/
250 && -f "${makefile}_old") {
251 $makefile = "${makefile}_old";
254 $makefile = 'Makefile';
258 if (!-f 'Makefile.PL') {
259 print "\nCreating Makefile.PL in $ext_dir for $mname\n";
260 # We need to cope well with various possible layouts
261 my @dirs = split /::/, $mname;
262 my $leaf = pop @dirs;
263 my $leafname = "$leaf.pm";
264 my $pathname = join '/', @dirs, $leafname;
265 my @locations = ($leafname, $pathname, "lib/$pathname");
267 foreach (@locations) {
275 die "For $mname tried @locations in in $ext_dir but can't find source";
277 open my $fh, '>', 'Makefile.PL'
278 or die "Can't open Makefile.PL for writing: $!";
280 #-*- buffer-read-only: t -*-
282 # This Makefile.PL was written by $0.
283 # It will be deleted automatically by make realclean
286 use ExtUtils::MakeMaker;
290 VERSION_FROM => '$fromname',
291 ABSTRACT_FROM => '$fromname',
292 realclean => {FILES => 'Makefile.PL'},
297 close $fh or die "Can't close Makefile.PL: $!";
299 print "\nRunning Makefile.PL in $ext_dir\n";
301 # Presumably this can be simplified
303 if (defined $::Cross::platform) {
304 # Inherited from win32/buildext.pl
305 @cross = "-MCross=$::Cross::platform";
306 } elsif ($opts{cross}) {
307 # Inherited from make_ext.pl
311 my @args = (@cross, 'Makefile.PL');
313 my $libd = VMS::Filespec::vmspath($lib_dir);
314 push @args, "INST_LIB=$libd", "INST_ARCHLIB=$libd";
316 push @args, 'INSTALLDIRS=perl', 'INSTALLMAN1DIR=none',
317 'INSTALLMAN3DIR=none';
319 push @args, @$pass_through;
320 _quote_args(\@args) if $is_VMS;
321 print join(' ', @run, $perl, @args), "\n";
322 my $code = system @run, $perl, @args;
323 warn "$code from $ext_dir\'s Makefile.PL" if $code;
325 # Right. The reason for this little hack is that we're sitting inside
326 # a program run by ./miniperl, but there are tasks we need to perform
327 # when the 'realclean', 'distclean' or 'veryclean' targets are run.
328 # Unfortunately, they can be run *after* 'clean', which deletes
330 # So we do our best to leave a set of instructions identical to what
331 # we would do if we are run directly as 'realclean' etc
332 # Whilst we're perfect, unfortunately the targets we call are not, as
333 # some of them rely on a $(PERL) for their own distclean targets.
334 # But this always used to be a problem with the old /bin/sh version of
338 foreach my $clean_target ('realclean', 'veryclean') {
339 my $file = "$return_dir/$clean_target$suffix";
340 open my $fh, '>>', $file or die "open $file: $!";
341 # Quite possible that we're being run in parallel here.
342 # Can't use Fcntl this early to get the LOCK_EX
343 flock $fh, 2 or warn "flock $file: $!";
346 if test ! -f Makefile -a -f Makefile.old; then
347 echo "Note: Using Makefile.old"
348 make -f Makefile.old $clean_target MAKE='@make' @pass_through
350 if test ! -f Makefile ; then
351 echo "Warning: No Makefile!"
353 make $clean_target MAKE='@make' @pass_through
357 close $fh or die "close $file: $!";
362 if (not -f $makefile) {
363 print "Warning: No Makefile!\n";
367 _macroify_passthrough($pass_through);
368 unshift @$pass_through, "/DESCRIPTION=$makefile";
371 if (!$target or $target !~ /clean$/) {
372 # Give makefile an opportunity to rewrite itself.
373 # reassure users that life goes on...
374 my @args = ('config', @$pass_through);
375 _quote_args(\@args) if $is_VMS;
376 system(@run, @make, @args) and print "@run @make @args failed, continuing anyway...\n";
378 my @targ = ($target, @$pass_through);
379 _quote_args(\@targ) if $is_VMS;
380 print "Making $target in $ext_dir\n@run @make @targ\n";
381 my $code = system(@run, @make, @targ);
382 die "Unsuccessful make($ext_dir): code=$code" if $code != 0;
384 chdir $return_dir || die "Cannot cd to $return_dir: $!";
388 my $args = shift; # must be array reference
390 # Do not quote qualifiers that begin with '/'.
392 $_ =~ s/\"/""/g; # escape C<"> by doubling
399 sub _macroify_passthrough {
400 my $passthrough = shift;
401 _quote_args($passthrough);
402 my $macro = '/MACRO=(' . join(',',@$passthrough) . ')';
404 @$passthrough[0] = $macro;