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);
18 # This script acts as a simple interface for building extensions.
20 # It's actually a cut and shut of the Unix version ext/utils/makeext and the
21 # Windows version win32/build_ext.pl hence the two invocation styles.
23 # On Unix, it primarily used by the perl Makefile one extention at a time:
25 # d_dummy $(dynamic_ext): miniperl preplibrary FORCE
26 # @$(RUN) ./miniperl make_ext.pl --target=dynamic $@ MAKE=$(MAKE) LIBPERL_A=$(LIBPERL)
29 # If '--static' is specified, static extensions will be built.
30 # If '--dynamic' is specified, dynamic extensions will be built.
31 # If '--nonxs' is specified, nonxs extensions will be built.
32 # If '--all' is specified, all extensions will be built.
34 # make_ext.pl "MAKE=make [-make_opts]" --dir=directory [--target=target] [--static|--dynamic|--all] +ext2 !ext1
38 # make_ext.pl "MAKE=nmake -nologo" --dir=..\ext
40 # make_ext.pl "MAKE=nmake -nologo" --dir=..\ext --target=clean
42 # make_ext.pl MAKE=dmake --dir=..\ext
44 # make_ext.pl MAKE=dmake --dir=..\ext --target=clean
46 # Will skip building extensions which are marked with an '!' char.
47 # Mostly because they still not ported to specified platform.
49 # If any extensions are listed with a '+' char then only those
50 # extensions will be built, but only if they arent countermanded
51 # by an '!ext' and are appropriate to the type of building being done.
53 # It may be deleted in a later release of perl so try to
54 # avoid using it for other purposes.
56 my $is_Win32 = $^O eq 'MSWin32';
57 my $is_VMS = $^O eq 'VMS';
58 my $is_Unix = !$is_Win32 && !$is_VMS;
60 require FindExt if $is_Win32;
62 my (%excl, %incl, %opts, @extspec, @pass_through);
67 } elsif (/^\+(.*)$/) {
69 } elsif (/^--([\w\-]+)$/) {
71 } elsif (/^--([\w\-]+)=(.*)$/) {
74 push @pass_through, $_;
80 my $static = $opts{static} || $opts{all};
81 my $dynamic = $opts{dynamic} || $opts{all};
82 my $nonxs = $opts{nonxs} || $opts{all};
84 # The Perl Makefile.SH will expand all extensions to
85 # lib/auto/X/X.a (or lib/auto/X/Y/Y.a if nested)
86 # A user wishing to run make_ext might use
87 # X (or X/Y or X::Y if nested)
89 # canonise into X/Y form (pname)
92 if (s{^lib/auto/}{}) {
93 # Remove lib/auto prefix and /*.* suffix
95 } elsif (s{^ext/}{}) {
96 # Remove ext/ prefix and /pm_to_blib suffix
98 # Targets are given as files on disk, but the extension spec is still
99 # written using /s for each ::
101 } elsif (s{::}{\/}g) {
108 my $makecmd = shift @pass_through; # Should be something like MAKE=make
109 unshift @pass_through, 'PERL_CORE=1';
111 my $dir = $opts{dir} || 'ext';
112 my $target = $opts{target};
113 $target = 'all' unless defined $target;
115 # Previously, $make was taken from config.sh. However, the user might
116 # instead be running a possibly incompatible make. This might happen if
117 # the user types "gmake" instead of a plain "make", for example. The
118 # correct current value of MAKE will come through from the main perl
119 # makefile as MAKE=/whatever/make in $makecmd. We'll be cautious in
120 # case third party users of this script (are there any?) don't have the
121 # MAKE=$(MAKE) argument, which was added after 5.004_03.
122 unless(defined $makecmd and $makecmd =~ /^MAKE=(.*)$/) {
123 die "$0: WARNING: Please include MAKE=\$(MAKE) in \@ARGV\n";
126 # This isn't going to cope with anything fancy, such as spaces inside command
127 # names, but neither did what it replaced. Once there is a use case that needs
128 # it, please supply patches. Until then, I'm sticking to KISS
129 my @make = split ' ', $1 || $Config{make} || $ENV{MAKE};
130 # Using an array of 0 or 1 elements makes the subsequent code simpler.
131 my @run = $Config{run};
132 @run = () if not defined $run[0] or $run[0] eq '';
136 die "make_ext: no make target specified (eg all or clean)\n";
137 } elsif ($target !~ /(?:^all|clean)$/) {
138 # for the time being we are strict about what make_ext is used for
139 die "$0: unknown make target '$target'\n";
142 if (!@extspec and !$static and !$dynamic and !$nonxs) {
143 die "$0: no extension specified\n";
147 my %extra_passthrough;
150 (my $here = getcwd()) =~ s{/}{\\}g;
152 if ($perl =~ m#^\.\.#) {
153 $perl = "$here\\$perl";
155 (my $topdir = $perl) =~ s/\\[^\\]+$//;
156 # miniperl needs to find perlglob and pl2bat
157 $ENV{PATH} = "$topdir;$topdir\\win32\\bin;$ENV{PATH}";
158 my $pl2bat = "$topdir\\win32\\bin\\pl2bat";
159 unless (-f "$pl2bat.bat") {
160 my @args = ($perl, ("$pl2bat.pl") x 2);
162 system(@args) unless defined $::Cross::platform;
165 print "In ", getcwd();
166 chdir($dir) || die "Cannot cd to $dir\n";
167 (my $ext = getcwd()) =~ s{/}{\\}g;
168 FindExt::scan_ext($ext);
169 FindExt::set_static_extensions(split ' ', $Config{static_ext});
172 push @ext, FindExt::static_ext() if $static;
173 push @ext, FindExt::dynamic_ext() if $dynamic;
174 push @ext, FindExt::nonxs_ext() if $nonxs;
176 foreach (sort @ext) {
177 if (%incl and !exists $incl{$_}) {
178 #warn "Skipping extension $ext\\$_, not in inclusion list\n";
181 if (exists $excl{$_}) {
182 warn "Skipping extension $ext\\$_, not ported to current platform";
186 if(FindExt::is_static($_)) {
187 push @{$extra_passthrough{$_}}, 'LINKTYPE=static';
190 chdir '..'; # now in the Perl build directory
194 push @extspec, (split ' ', $Config{static_ext}) if $static;
195 push @extspec, (split ' ', $Config{dynamic_ext}) if $dynamic;
196 push @extspec, (split ' ', $Config{nonxs_ext}) if $nonxs;
199 foreach my $spec (@extspec) {
203 if (-d "ext/$spec") {
204 # Old style ext/Data/Dumper/
205 $ext_pathname = "ext/$spec";
207 # New style ext/Data-Dumper/
210 $ext_pathname = "ext/$copy";
213 if ($Config{osname} eq 'catamount') {
214 # Snowball's chance of building extensions.
215 die "This is $Config{osname}, not building $mname, sorry.\n";
218 print "\tMaking $mname ($target)\n";
220 build_extension($ext_pathname, $perl, $mname,
221 [@pass_through, @{$extra_passthrough{$spec} || []}]);
224 sub build_extension {
225 my ($ext_dir, $perl, $mname, $pass_through) = @_;
230 $perl ||= "$up/miniperl";
231 my $return_dir = $up;
232 my $lib_dir = "$up/lib";
234 = join $Config{path_sep}, $lib_dir, map {"$up/$_"} @toolchain;
236 unless (chdir "$ext_dir") {
237 warn "Cannot cd to $ext_dir: $!";
242 $makefile = 'descrip.mms';
243 if ($target =~ /clean$/
245 && -f "${makefile}_old") {
246 $makefile = "${makefile}_old";
249 $makefile = 'Makefile';
253 if (!-f 'Makefile.PL') {
254 print "\nCreating Makefile.PL in $ext_dir for $mname\n";
255 # We need to cope well with various possible layouts
256 my @dirs = split /::/, $mname;
257 my $leaf = pop @dirs;
258 my $leafname = "$leaf.pm";
259 my $pathname = join '/', @dirs, $leafname;
260 my @locations = ($leafname, $pathname, "lib/$pathname");
262 foreach (@locations) {
270 die "For $mname tried @locations in in $ext_dir but can't find source";
272 open my $fh, '>', 'Makefile.PL'
273 or die "Can't open Makefile.PL for writing: $!";
275 #-*- buffer-read-only: t -*-
277 # This Makefile.PL was written by $0.
278 # It will be deleted automatically by make realclean
281 use ExtUtils::MakeMaker;
285 VERSION_FROM => '$fromname',
286 ABSTRACT_FROM => '$fromname',
287 realclean => {FILES => 'Makefile.PL'},
292 close $fh or die "Can't close Makefile.PL: $!";
294 print "\nRunning Makefile.PL in $ext_dir\n";
296 # Presumably this can be simplified
298 if (defined $::Cross::platform) {
299 # Inherited from win32/buildext.pl
300 @cross = "-MCross=$::Cross::platform";
301 } elsif ($opts{cross}) {
302 # Inherited from make_ext.pl
306 my @args = (@cross, 'Makefile.PL');
308 my $libd = VMS::Filespec::vmspath($lib_dir);
309 push @args, "INST_LIB=$libd", "INST_ARCHLIB=$libd";
311 push @args, 'INSTALLDIRS=perl', 'INSTALLMAN1DIR=none',
312 'INSTALLMAN3DIR=none';
314 push @args, @$pass_through;
315 _quote_args(\@args) if $is_VMS;
316 print join(' ', @run, $perl, @args), "\n";
317 my $code = system @run, $perl, @args;
318 warn "$code from $ext_dir\'s Makefile.PL" if $code;
320 # Right. The reason for this little hack is that we're sitting inside
321 # a program run by ./miniperl, but there are tasks we need to perform
322 # when the 'realclean', 'distclean' or 'veryclean' targets are run.
323 # Unfortunately, they can be run *after* 'clean', which deletes
325 # So we do our best to leave a set of instructions identical to what
326 # we would do if we are run directly as 'realclean' etc
327 # Whilst we're perfect, unfortunately the targets we call are not, as
328 # some of them rely on a $(PERL) for their own distclean targets.
329 # But this always used to be a problem with the old /bin/sh version of
333 foreach my $clean_target ('realclean', 'veryclean') {
334 my $file = "$return_dir/$clean_target$suffix";
335 open my $fh, '>>', $file or die "open $file: $!";
336 # Quite possible that we're being run in parallel here.
337 # Can't use Fcntl this early to get the LOCK_EX
338 flock $fh, 2 or warn "flock $file: $!";
341 if test ! -f Makefile -a -f Makefile.old; then
342 echo "Note: Using Makefile.old"
343 make -f Makefile.old $clean_target MAKE='@make' @pass_through
345 if test ! -f Makefile ; then
346 echo "Warning: No Makefile!"
348 make $clean_target MAKE='@make' @pass_through
352 close $fh or die "close $file: $!";
357 if (not -f $makefile) {
358 print "Warning: No Makefile!\n";
362 _macroify_passthrough($pass_through);
363 unshift @$pass_through, "/DESCRIPTION=$makefile";
366 if (!$target or $target !~ /clean$/) {
367 # Give makefile an opportunity to rewrite itself.
368 # reassure users that life goes on...
369 my @args = ('config', @$pass_through);
370 _quote_args(\@args) if $is_VMS;
371 system(@run, @make, @args) and print "@run @make @args failed, continuing anyway...\n";
373 my @targ = ($target, @$pass_through);
374 _quote_args(\@targ) if $is_VMS;
375 print "Making $target in $ext_dir\n@run @make @targ\n";
376 my $code = system(@run, @make, @targ);
377 die "Unsuccessful make($ext_dir): code=$code" if $code != 0;
379 chdir $return_dir || die "Cannot cd to $return_dir: $!";
383 my $args = shift; # must be array reference
385 # Do not quote qualifiers that begin with '/'.
387 $_ =~ s/\"/""/g; # escape C<"> by doubling
394 sub _macroify_passthrough {
395 my $passthrough = shift;
396 _quote_args($passthrough);
397 my $macro = '/MACRO=(' . join(',',@$passthrough) . ')';
399 @$passthrough[0] = $macro;