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
15 ext/ExtUtils-Install/lib ext/ExtUtils-MakeMaker/lib
16 ext/ExtUtils-Manifest/lib ext/Text-ParseWords/lib
19 # This script acts as a simple interface for building extensions.
21 # It's actually a cut and shut of the Unix version ext/utils/makeext and the
22 # Windows version win32/build_ext.pl hence the two invocation styles.
24 # On Unix, it primarily used by the perl Makefile one extention at a time:
26 # d_dummy $(dynamic_ext): miniperl preplibrary FORCE
27 # @$(RUN) ./miniperl make_ext.pl --target=dynamic $@ MAKE=$(MAKE) LIBPERL_A=$(LIBPERL)
30 # If '--static' is specified, static extensions will be built.
31 # If '--dynamic' is specified, dynamic extensions will be built.
32 # If '--nonxs' is specified, nonxs extensions will be built.
33 # If '--all' is specified, all extensions will be built.
35 # make_ext.pl "MAKE=make [-make_opts]" --dir=directory [--target=target] [--static|--dynamic|--all] +ext2 !ext1
39 # make_ext.pl "MAKE=nmake -nologo" --dir=..\ext
41 # make_ext.pl "MAKE=nmake -nologo" --dir=..\ext --target=clean
43 # make_ext.pl MAKE=dmake --dir=..\ext
45 # make_ext.pl MAKE=dmake --dir=..\ext --target=clean
47 # Will skip building extensions which are marked with an '!' char.
48 # Mostly because they still not ported to specified platform.
50 # If any extensions are listed with a '+' char then only those
51 # extensions will be built, but only if they arent countermanded
52 # by an '!ext' and are appropriate to the type of building being done.
54 # It may be deleted in a later release of perl so try to
55 # avoid using it for other purposes.
57 my $is_Win32 = $^O eq 'MSWin32';
58 my $is_VMS = $^O eq 'VMS';
59 my $is_Unix = !$is_Win32 && !$is_VMS;
61 require FindExt if $is_Win32;
63 my (%excl, %incl, %opts, @extspec, @pass_through);
68 } elsif (/^\+(.*)$/) {
70 } elsif (/^--([\w\-]+)$/) {
72 } elsif (/^--([\w\-]+)=(.*)$/) {
75 push @pass_through, $_;
81 my $static = $opts{static} || $opts{all};
82 my $dynamic = $opts{dynamic} || $opts{all};
83 my $nonxs = $opts{nonxs} || $opts{all};
85 # The Perl Makefile.SH will expand all extensions to
86 # lib/auto/X/X.a (or lib/auto/X/Y/Y.a if nested)
87 # A user wishing to run make_ext might use
88 # X (or X/Y or X::Y if nested)
90 # canonise into X/Y form (pname)
93 if (s{^lib/auto/}{}) {
94 # Remove lib/auto prefix and /*.* suffix
96 } elsif (s{^ext/}{}) {
97 # Remove ext/ prefix and /pm_to_blib suffix
99 # Targets are given as files on disk, but the extension spec is still
100 # written using /s for each ::
102 } elsif (s{::}{\/}g) {
109 my $makecmd = shift @pass_through; # Should be something like MAKE=make
110 unshift @pass_through, 'PERL_CORE=1';
112 my $dir = $opts{dir} || 'ext';
113 my $target = $opts{target};
114 $target = 'all' unless defined $target;
116 # Previously, $make was taken from config.sh. However, the user might
117 # instead be running a possibly incompatible make. This might happen if
118 # the user types "gmake" instead of a plain "make", for example. The
119 # correct current value of MAKE will come through from the main perl
120 # makefile as MAKE=/whatever/make in $makecmd. We'll be cautious in
121 # case third party users of this script (are there any?) don't have the
122 # MAKE=$(MAKE) argument, which was added after 5.004_03.
123 unless(defined $makecmd and $makecmd =~ /^MAKE=(.*)$/) {
124 die "$0: WARNING: Please include MAKE=\$(MAKE) in \@ARGV\n";
127 # This isn't going to cope with anything fancy, such as spaces inside command
128 # names, but neither did what it replaced. Once there is a use case that needs
129 # it, please supply patches. Until then, I'm sticking to KISS
130 my @make = split ' ', $1 || $Config{make} || $ENV{MAKE};
131 # Using an array of 0 or 1 elements makes the subsequent code simpler.
132 my @run = $Config{run};
133 @run = () if not defined $run[0] or $run[0] eq '';
137 die "make_ext: no make target specified (eg all or clean)\n";
138 } elsif ($target !~ /(?:^all|clean)$/) {
139 # for the time being we are strict about what make_ext is used for
140 die "$0: unknown make target '$target'\n";
143 if (!@extspec and !$static and !$dynamic and !$nonxs) {
144 die "$0: no extension specified\n";
148 my %extra_passthrough;
151 (my $here = getcwd()) =~ s{/}{\\}g;
153 if ($perl =~ m#^\.\.#) {
154 $perl = "$here\\$perl";
156 (my $topdir = $perl) =~ s/\\[^\\]+$//;
157 # miniperl needs to find perlglob and pl2bat
158 $ENV{PATH} = "$topdir;$topdir\\win32\\bin;$ENV{PATH}";
159 my $pl2bat = "$topdir\\win32\\bin\\pl2bat";
160 unless (-f "$pl2bat.bat") {
161 my @args = ($perl, ("$pl2bat.pl") x 2);
163 system(@args) unless defined $::Cross::platform;
166 print "In ", getcwd();
167 chdir($dir) || die "Cannot cd to $dir\n";
168 (my $ext = getcwd()) =~ s{/}{\\}g;
169 FindExt::scan_ext($ext);
170 FindExt::set_static_extensions(split ' ', $Config{static_ext});
173 push @ext, FindExt::static_ext() if $static;
174 push @ext, FindExt::dynamic_ext() if $dynamic;
175 push @ext, FindExt::nonxs_ext() if $nonxs;
177 foreach (sort @ext) {
178 if (%incl and !exists $incl{$_}) {
179 #warn "Skipping extension $ext\\$_, not in inclusion list\n";
182 if (exists $excl{$_}) {
183 warn "Skipping extension $ext\\$_, not ported to current platform";
187 if(FindExt::is_static($_)) {
188 push @{$extra_passthrough{$_}}, 'LINKTYPE=static';
191 chdir '..'; # now in the Perl build directory
195 push @extspec, (split ' ', $Config{static_ext}) if $static;
196 push @extspec, (split ' ', $Config{dynamic_ext}) if $dynamic;
197 push @extspec, (split ' ', $Config{nonxs_ext}) if $nonxs;
200 foreach my $spec (@extspec) {
204 if (-d "ext/$spec") {
205 # Old style ext/Data/Dumper/
206 $ext_pathname = "ext/$spec";
208 # New style ext/Data-Dumper/
211 $ext_pathname = "ext/$copy";
214 if ($Config{osname} eq 'catamount') {
215 # Snowball's chance of building extensions.
216 die "This is $Config{osname}, not building $mname, sorry.\n";
219 print "\tMaking $mname ($target)\n";
221 build_extension($ext_pathname, $perl, $mname,
222 [@pass_through, @{$extra_passthrough{$spec} || []}]);
225 sub build_extension {
226 my ($ext_dir, $perl, $mname, $pass_through) = @_;
231 $perl ||= "$up/miniperl";
232 my $return_dir = $up;
233 my $lib_dir = "$up/lib";
234 # $lib_dir must be last, as we're copying files into it, and in a parallel
235 # make there's a race condition if one process tries to open a module that
236 # another process has half-written.
238 = join $Config{path_sep}, (map {"$up/$_"} @toolchain), $lib_dir;
240 unless (chdir "$ext_dir") {
241 warn "Cannot cd to $ext_dir: $!";
246 $makefile = 'descrip.mms';
247 if ($target =~ /clean$/
249 && -f "${makefile}_old") {
250 $makefile = "${makefile}_old";
253 $makefile = 'Makefile';
257 if (!-f 'Makefile.PL') {
258 print "\nCreating Makefile.PL in $ext_dir for $mname\n";
259 # We need to cope well with various possible layouts
260 my @dirs = split /::/, $mname;
261 my $leaf = pop @dirs;
262 my $leafname = "$leaf.pm";
263 my $pathname = join '/', @dirs, $leafname;
264 my @locations = ($leafname, $pathname, "lib/$pathname");
266 foreach (@locations) {
274 die "For $mname tried @locations in in $ext_dir but can't find source";
276 open my $fh, '>', 'Makefile.PL'
277 or die "Can't open Makefile.PL for writing: $!";
279 #-*- buffer-read-only: t -*-
281 # This Makefile.PL was written by $0.
282 # It will be deleted automatically by make realclean
285 use ExtUtils::MakeMaker;
289 VERSION_FROM => '$fromname',
290 ABSTRACT_FROM => '$fromname',
291 realclean => {FILES => 'Makefile.PL'},
296 close $fh or die "Can't close Makefile.PL: $!";
298 print "\nRunning Makefile.PL in $ext_dir\n";
300 # Presumably this can be simplified
302 if (defined $::Cross::platform) {
303 # Inherited from win32/buildext.pl
304 @cross = "-MCross=$::Cross::platform";
305 } elsif ($opts{cross}) {
306 # Inherited from make_ext.pl
310 my @args = (@cross, 'Makefile.PL');
312 my $libd = VMS::Filespec::vmspath($lib_dir);
313 push @args, "INST_LIB=$libd", "INST_ARCHLIB=$libd";
315 push @args, 'INSTALLDIRS=perl', 'INSTALLMAN1DIR=none',
316 'INSTALLMAN3DIR=none';
318 push @args, @$pass_through;
319 _quote_args(\@args) if $is_VMS;
320 print join(' ', @run, $perl, @args), "\n";
321 my $code = system @run, $perl, @args;
322 warn "$code from $ext_dir\'s Makefile.PL" if $code;
324 # Right. The reason for this little hack is that we're sitting inside
325 # a program run by ./miniperl, but there are tasks we need to perform
326 # when the 'realclean', 'distclean' or 'veryclean' targets are run.
327 # Unfortunately, they can be run *after* 'clean', which deletes
329 # So we do our best to leave a set of instructions identical to what
330 # we would do if we are run directly as 'realclean' etc
331 # Whilst we're perfect, unfortunately the targets we call are not, as
332 # some of them rely on a $(PERL) for their own distclean targets.
333 # But this always used to be a problem with the old /bin/sh version of
337 foreach my $clean_target ('realclean', 'veryclean') {
338 my $file = "$return_dir/$clean_target$suffix";
339 open my $fh, '>>', $file or die "open $file: $!";
340 # Quite possible that we're being run in parallel here.
341 # Can't use Fcntl this early to get the LOCK_EX
342 flock $fh, 2 or warn "flock $file: $!";
345 if test ! -f Makefile -a -f Makefile.old; then
346 echo "Note: Using Makefile.old"
347 make -f Makefile.old $clean_target MAKE='@make' @pass_through
349 if test ! -f Makefile ; then
350 echo "Warning: No Makefile!"
352 make $clean_target MAKE='@make' @pass_through
356 close $fh or die "close $file: $!";
361 if (not -f $makefile) {
362 print "Warning: No Makefile!\n";
366 _macroify_passthrough($pass_through);
367 unshift @$pass_through, "/DESCRIPTION=$makefile";
370 if (!$target or $target !~ /clean$/) {
371 # Give makefile an opportunity to rewrite itself.
372 # reassure users that life goes on...
373 my @args = ('config', @$pass_through);
374 _quote_args(\@args) if $is_VMS;
375 system(@run, @make, @args) and print "@run @make @args failed, continuing anyway...\n";
377 my @targ = ($target, @$pass_through);
378 _quote_args(\@targ) if $is_VMS;
379 print "Making $target in $ext_dir\n@run @make @targ\n";
380 my $code = system(@run, @make, @targ);
381 die "Unsuccessful make($ext_dir): code=$code" if $code != 0;
383 chdir $return_dir || die "Cannot cd to $return_dir: $!";
387 my $args = shift; # must be array reference
389 # Do not quote qualifiers that begin with '/'.
391 $_ =~ s/\"/""/g; # escape C<"> by doubling
398 sub _macroify_passthrough {
399 my $passthrough = shift;
400 _quote_args($passthrough);
401 my $macro = '/MACRO=(' . join(',',@$passthrough) . ')';
403 @$passthrough[0] = $macro;