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
17 # This script acts as a simple interface for building extensions.
19 # It's actually a cut and shut of the Unix version ext/utils/makeext and the
20 # Windows version win32/build_ext.pl hence the two invocation styles.
22 # On Unix, it primarily used by the perl Makefile one extention at a time:
24 # d_dummy $(dynamic_ext): miniperl preplibrary FORCE
25 # @$(RUN) ./miniperl make_ext.pl --target=dynamic $@ MAKE=$(MAKE) LIBPERL_A=$(LIBPERL)
28 # If '--static' is specified, static extensions will be built.
29 # If '--dynamic' is specified, dynamic extensions will be built.
30 # If '--nonxs' is specified, nonxs extensions will be built.
31 # If '--all' is specified, all extensions will be built.
33 # make_ext.pl "MAKE=make [-make_opts]" --dir=directory [--target=target] [--static|--dynamic|--all] +ext2 !ext1
37 # make_ext.pl "MAKE=nmake -nologo" --dir=..\ext
39 # make_ext.pl "MAKE=nmake -nologo" --dir=..\ext --target=clean
41 # make_ext.pl MAKE=dmake --dir=..\ext
43 # make_ext.pl MAKE=dmake --dir=..\ext --target=clean
45 # Will skip building extensions which are marked with an '!' char.
46 # Mostly because they still not ported to specified platform.
48 # If any extensions are listed with a '+' char then only those
49 # extensions will be built, but only if they arent countermanded
50 # by an '!ext' and are appropriate to the type of building being done.
52 # It may be deleted in a later release of perl so try to
53 # avoid using it for other purposes.
55 my $is_Win32 = $^O eq 'MSWin32';
56 my $is_VMS = $^O eq 'VMS';
57 my $is_Unix = !$is_Win32 && !$is_VMS;
59 require FindExt if $is_Win32;
61 my (%excl, %incl, %opts, @extspec, @pass_through);
66 } elsif (/^\+(.*)$/) {
68 } elsif (/^--([\w\-]+)$/) {
70 } elsif (/^--([\w\-]+)=(.*)$/) {
73 push @pass_through, $_;
79 my $static = $opts{static} || $opts{all};
80 my $dynamic = $opts{dynamic} || $opts{all};
81 my $nonxs = $opts{nonxs} || $opts{all};
83 # The Perl Makefile.SH will expand all extensions to
84 # lib/auto/X/X.a (or lib/auto/X/Y/Y.a if nested)
85 # A user wishing to run make_ext might use
86 # X (or X/Y or X::Y if nested)
88 # canonise into X/Y form (pname)
91 if (s{^lib/auto/}{}) {
92 # Remove lib/auto prefix and /*.* suffix
94 } elsif (s{^ext/}{}) {
95 # Remove ext/ prefix and /pm_to_blib suffix
97 # Targets are given as files on disk, but the extension spec is still
98 # written using /s for each ::
100 } elsif (s{::}{\/}g) {
107 my $makecmd = shift @pass_through; # Should be something like MAKE=make
108 unshift @pass_through, 'PERL_CORE=1';
110 my $dir = $opts{dir} || 'ext';
111 my $target = $opts{target};
112 $target = 'all' unless defined $target;
114 # Previously, $make was taken from config.sh. However, the user might
115 # instead be running a possibly incompatible make. This might happen if
116 # the user types "gmake" instead of a plain "make", for example. The
117 # correct current value of MAKE will come through from the main perl
118 # makefile as MAKE=/whatever/make in $makecmd. We'll be cautious in
119 # case third party users of this script (are there any?) don't have the
120 # MAKE=$(MAKE) argument, which was added after 5.004_03.
121 unless(defined $makecmd and $makecmd =~ /^MAKE=(.*)$/) {
122 die "$0: WARNING: Please include MAKE=\$(MAKE) in \@ARGV\n";
125 # This isn't going to cope with anything fancy, such as spaces inside command
126 # names, but neither did what it replaced. Once there is a use case that needs
127 # it, please supply patches. Until then, I'm sticking to KISS
128 my @make = split ' ', $1 || $Config{make} || $ENV{MAKE};
129 # Using an array of 0 or 1 elements makes the subsequent code simpler.
130 my @run = $Config{run};
131 @run = () if not defined $run[0] or $run[0] eq '';
135 die "make_ext: no make target specified (eg all or clean)\n";
136 } elsif ($target !~ /(?:^all|clean)$/) {
137 # for the time being we are strict about what make_ext is used for
138 die "$0: unknown make target '$target'\n";
141 if (!@extspec and !$static and !$dynamic and !$nonxs) {
142 die "$0: no extension specified\n";
146 my %extra_passthrough;
149 (my $here = getcwd()) =~ s{/}{\\}g;
151 if ($perl =~ m#^\.\.#) {
152 $perl = "$here\\$perl";
154 (my $topdir = $perl) =~ s/\\[^\\]+$//;
155 # miniperl needs to find perlglob and pl2bat
156 $ENV{PATH} = "$topdir;$topdir\\win32\\bin;$ENV{PATH}";
157 my $pl2bat = "$topdir\\win32\\bin\\pl2bat";
158 unless (-f "$pl2bat.bat") {
159 my @args = ($perl, ("$pl2bat.pl") x 2);
161 system(@args) unless defined $::Cross::platform;
164 print "In ", getcwd();
165 chdir($dir) || die "Cannot cd to $dir\n";
166 (my $ext = getcwd()) =~ s{/}{\\}g;
167 FindExt::scan_ext($ext);
168 FindExt::set_static_extensions(split ' ', $Config{static_ext});
171 push @ext, FindExt::static_ext() if $static;
172 push @ext, FindExt::dynamic_ext() if $dynamic;
173 push @ext, FindExt::nonxs_ext() if $nonxs;
175 foreach (sort @ext) {
176 if (%incl and !exists $incl{$_}) {
177 #warn "Skipping extension $ext\\$_, not in inclusion list\n";
180 if (exists $excl{$_}) {
181 warn "Skipping extension $ext\\$_, not ported to current platform";
185 if(FindExt::is_static($_)) {
186 push @{$extra_passthrough{$_}}, 'LINKTYPE=static';
189 chdir '..'; # now in the Perl build directory
193 push @extspec, (split ' ', $Config{static_ext}) if $static;
194 push @extspec, (split ' ', $Config{dynamic_ext}) if $dynamic;
195 push @extspec, (split ' ', $Config{nonxs_ext}) if $nonxs;
198 foreach my $spec (@extspec) {
202 if (-d "ext/$spec") {
203 # Old style ext/Data/Dumper/
204 $ext_pathname = "ext/$spec";
206 # New style ext/Data-Dumper/
209 $ext_pathname = "ext/$copy";
212 if ($Config{osname} eq 'catamount') {
213 # Snowball's chance of building extensions.
214 die "This is $Config{osname}, not building $mname, sorry.\n";
217 print "\tMaking $mname ($target)\n";
219 build_extension($ext_pathname, $perl, $mname,
220 [@pass_through, @{$extra_passthrough{$spec} || []}]);
223 sub build_extension {
224 my ($ext_dir, $perl, $mname, $pass_through) = @_;
229 $perl ||= "$up/miniperl";
230 my $return_dir = $up;
231 my $lib_dir = "$up/lib";
233 = join $Config{path_sep}, $lib_dir, map {"$up/$_"} @toolchain;
235 unless (chdir "$ext_dir") {
236 warn "Cannot cd to $ext_dir: $!";
241 $makefile = 'descrip.mms';
242 if ($target =~ /clean$/
244 && -f "${makefile}_old") {
245 $makefile = "${makefile}_old";
248 $makefile = 'Makefile';
252 if (!-f 'Makefile.PL') {
253 print "\nCreating Makefile.PL in $ext_dir for $mname\n";
254 # We need to cope well with various possible layouts
255 my @dirs = split /::/, $mname;
256 my $leaf = pop @dirs;
257 my $leafname = "$leaf.pm";
258 my $pathname = join '/', @dirs, $leafname;
259 my @locations = ($leafname, $pathname, "lib/$pathname");
261 foreach (@locations) {
269 die "For $mname tried @locations in in $ext_dir but can't find source";
271 open my $fh, '>', 'Makefile.PL'
272 or die "Can't open Makefile.PL for writing: $!";
274 #-*- buffer-read-only: t -*-
276 # This Makefile.PL was written by $0.
277 # It will be deleted automatically by make realclean
280 use ExtUtils::MakeMaker;
284 VERSION_FROM => '$fromname',
285 ABSTRACT_FROM => '$fromname',
286 realclean => {FILES => 'Makefile.PL'},
291 close $fh or die "Can't close Makefile.PL: $!";
293 print "\nRunning Makefile.PL in $ext_dir\n";
295 # Presumably this can be simplified
297 if (defined $::Cross::platform) {
298 # Inherited from win32/buildext.pl
299 @cross = "-MCross=$::Cross::platform";
300 } elsif ($opts{cross}) {
301 # Inherited from make_ext.pl
305 my @args = (@cross, 'Makefile.PL');
307 my $libd = VMS::Filespec::vmspath($lib_dir);
308 push @args, "INST_LIB=$libd", "INST_ARCHLIB=$libd";
310 push @args, 'INSTALLDIRS=perl', 'INSTALLMAN1DIR=none',
311 'INSTALLMAN3DIR=none';
313 push @args, @$pass_through;
314 _quote_args(\@args) if $is_VMS;
315 print join(' ', @run, $perl, @args), "\n";
316 my $code = system @run, $perl, @args;
317 warn "$code from $ext_dir\'s Makefile.PL" if $code;
319 # Right. The reason for this little hack is that we're sitting inside
320 # a program run by ./miniperl, but there are tasks we need to perform
321 # when the 'realclean', 'distclean' or 'veryclean' targets are run.
322 # Unfortunately, they can be run *after* 'clean', which deletes
324 # So we do our best to leave a set of instructions identical to what
325 # we would do if we are run directly as 'realclean' etc
326 # Whilst we're perfect, unfortunately the targets we call are not, as
327 # some of them rely on a $(PERL) for their own distclean targets.
328 # But this always used to be a problem with the old /bin/sh version of
332 foreach my $clean_target ('realclean', 'veryclean') {
333 my $file = "$return_dir/$clean_target$suffix";
334 open my $fh, '>>', $file or die "open $file: $!";
335 # Quite possible that we're being run in parallel here.
336 # Can't use Fcntl this early to get the LOCK_EX
337 flock $fh, 2 or warn "flock $file: $!";
340 if test ! -f Makefile -a -f Makefile.old; then
341 echo "Note: Using Makefile.old"
342 make -f Makefile.old $clean_target MAKE='@make' @pass_through
344 if test ! -f Makefile ; then
345 echo "Warning: No Makefile!"
347 make $clean_target MAKE='@make' @pass_through
351 close $fh or die "close $file: $!";
356 if (not -f $makefile) {
357 print "Warning: No Makefile!\n";
361 _macroify_passthrough($pass_through);
362 unshift @$pass_through, "/DESCRIPTION=$makefile";
365 if (!$target or $target !~ /clean$/) {
366 # Give makefile an opportunity to rewrite itself.
367 # reassure users that life goes on...
368 my @args = ('config', @$pass_through);
369 _quote_args(\@args) if $is_VMS;
370 system(@run, @make, @args) and print "@run @make @args failed, continuing anyway...\n";
372 my @targ = ($target, @$pass_through);
373 _quote_args(\@targ) if $is_VMS;
374 print "Making $target in $ext_dir\n@run @make @targ\n";
375 my $code = system(@run, @make, @targ);
376 die "Unsuccessful make($ext_dir): code=$code" if $code != 0;
378 chdir $return_dir || die "Cannot cd to $return_dir: $!";
382 my $args = shift; # must be array reference
384 # Do not quote qualifiers that begin with '/'.
386 $_ =~ s/\"/""/g; # escape C<"> by doubling
393 sub _macroify_passthrough {
394 my $passthrough = shift;
395 _quote_args($passthrough);
396 my $macro = '/MACRO=(' . join(',',@$passthrough) . ')';
398 @$passthrough[0] = $macro;