143003dfeSmillert#!./miniperl 243003dfeSmillertuse strict; 343003dfeSmillertuse warnings; 443003dfeSmillertuse Config; 543003dfeSmillert 6b39c5158Smillertmy $is_Win32 = $^O eq 'MSWin32'; 7b39c5158Smillertmy $is_VMS = $^O eq 'VMS'; 8b39c5158Smillertmy $is_Unix = !$is_Win32 && !$is_VMS; 9b39c5158Smillert 10b39c5158Smillertmy @ext_dirs = qw(cpan dist ext); 11b39c5158Smillertmy $ext_dirs_re = '(?:' . join('|', @ext_dirs) . ')'; 12b39c5158Smillert 1343003dfeSmillert# This script acts as a simple interface for building extensions. 1443003dfeSmillert 1543003dfeSmillert# It's actually a cut and shut of the Unix version ext/utils/makeext and the 1643003dfeSmillert# Windows version win32/build_ext.pl hence the two invocation styles. 1743003dfeSmillert 18898184e3Ssthen# On Unix, it primarily used by the perl Makefile one extension at a time: 1943003dfeSmillert# 2043003dfeSmillert# d_dummy $(dynamic_ext): miniperl preplibrary FORCE 2143003dfeSmillert# @$(RUN) ./miniperl make_ext.pl --target=dynamic $@ MAKE=$(MAKE) LIBPERL_A=$(LIBPERL) 2243003dfeSmillert# 2343003dfeSmillert# On Windows or VMS, 2443003dfeSmillert# If '--static' is specified, static extensions will be built. 25b39c5158Smillert# If '--dynamic' is specified, dynamic extensions will be built. 26b39c5158Smillert# If '--nonxs' is specified, nonxs extensions will be built. 27898184e3Ssthen# If '--dynaloader' is specified, DynaLoader will be built. 2843003dfeSmillert# If '--all' is specified, all extensions will be built. 2943003dfeSmillert# 3043003dfeSmillert# make_ext.pl "MAKE=make [-make_opts]" --dir=directory [--target=target] [--static|--dynamic|--all] +ext2 !ext1 3143003dfeSmillert# 3243003dfeSmillert# E.g. 3343003dfeSmillert# 3443003dfeSmillert# make_ext.pl "MAKE=nmake -nologo" --dir=..\ext 3543003dfeSmillert# 3643003dfeSmillert# make_ext.pl "MAKE=nmake -nologo" --dir=..\ext --target=clean 3743003dfeSmillert# 3843003dfeSmillert# make_ext.pl MAKE=dmake --dir=..\ext 3943003dfeSmillert# 4043003dfeSmillert# make_ext.pl MAKE=dmake --dir=..\ext --target=clean 4143003dfeSmillert# 4243003dfeSmillert# Will skip building extensions which are marked with an '!' char. 4343003dfeSmillert# Mostly because they still not ported to specified platform. 4443003dfeSmillert# 4543003dfeSmillert# If any extensions are listed with a '+' char then only those 4643003dfeSmillert# extensions will be built, but only if they arent countermanded 4743003dfeSmillert# by an '!ext' and are appropriate to the type of building being done. 4843003dfeSmillert 4943003dfeSmillert# It may be deleted in a later release of perl so try to 5043003dfeSmillert# avoid using it for other purposes. 5143003dfeSmillert 5243003dfeSmillertmy (%excl, %incl, %opts, @extspec, @pass_through); 5343003dfeSmillert 5443003dfeSmillertforeach (@ARGV) { 5543003dfeSmillert if (/^!(.*)$/) { 5643003dfeSmillert $excl{$1} = 1; 5743003dfeSmillert } elsif (/^\+(.*)$/) { 5843003dfeSmillert $incl{$1} = 1; 5943003dfeSmillert } elsif (/^--([\w\-]+)$/) { 6043003dfeSmillert $opts{$1} = 1; 6143003dfeSmillert } elsif (/^--([\w\-]+)=(.*)$/) { 62b39c5158Smillert push @{$opts{$1}}, $2; 6343003dfeSmillert } elsif (/=/) { 6443003dfeSmillert push @pass_through, $_; 6543003dfeSmillert } elsif (length) { 6643003dfeSmillert push @extspec, $_; 6743003dfeSmillert } 6843003dfeSmillert} 6943003dfeSmillert 7043003dfeSmillertmy $static = $opts{static} || $opts{all}; 7143003dfeSmillertmy $dynamic = $opts{dynamic} || $opts{all}; 72b39c5158Smillertmy $nonxs = $opts{nonxs} || $opts{all}; 73b39c5158Smillertmy $dynaloader = $opts{dynaloader} || $opts{all}; 7443003dfeSmillert 7543003dfeSmillert# The Perl Makefile.SH will expand all extensions to 7643003dfeSmillert# lib/auto/X/X.a (or lib/auto/X/Y/Y.a if nested) 7743003dfeSmillert# A user wishing to run make_ext might use 7843003dfeSmillert# X (or X/Y or X::Y if nested) 7943003dfeSmillert 8043003dfeSmillert# canonise into X/Y form (pname) 8143003dfeSmillert 8243003dfeSmillertforeach (@extspec) { 8343003dfeSmillert if (s{^lib/auto/}{}) { 8443003dfeSmillert # Remove lib/auto prefix and /*.* suffix 8543003dfeSmillert s{/[^/]+\.[^/]+$}{}; 86b39c5158Smillert } elsif (s{^$ext_dirs_re/}{}) { 8743003dfeSmillert # Remove ext/ prefix and /pm_to_blib suffix 8843003dfeSmillert s{/pm_to_blib$}{}; 8943003dfeSmillert # Targets are given as files on disk, but the extension spec is still 9043003dfeSmillert # written using /s for each :: 9143003dfeSmillert tr!-!/!; 9243003dfeSmillert } elsif (s{::}{\/}g) { 9343003dfeSmillert # Convert :: to / 9443003dfeSmillert } else { 9543003dfeSmillert s/\..*o//; 9643003dfeSmillert } 9743003dfeSmillert} 9843003dfeSmillert 9943003dfeSmillertmy $makecmd = shift @pass_through; # Should be something like MAKE=make 10043003dfeSmillertunshift @pass_through, 'PERL_CORE=1'; 10143003dfeSmillert 102b39c5158Smillertmy @dirs = @{$opts{dir} || \@ext_dirs}; 103b39c5158Smillertmy $target = $opts{target}[0]; 10443003dfeSmillert$target = 'all' unless defined $target; 10543003dfeSmillert 10643003dfeSmillert# Previously, $make was taken from config.sh. However, the user might 10743003dfeSmillert# instead be running a possibly incompatible make. This might happen if 10843003dfeSmillert# the user types "gmake" instead of a plain "make", for example. The 10943003dfeSmillert# correct current value of MAKE will come through from the main perl 11043003dfeSmillert# makefile as MAKE=/whatever/make in $makecmd. We'll be cautious in 11143003dfeSmillert# case third party users of this script (are there any?) don't have the 11243003dfeSmillert# MAKE=$(MAKE) argument, which was added after 5.004_03. 11343003dfeSmillertunless(defined $makecmd and $makecmd =~ /^MAKE=(.*)$/) { 11443003dfeSmillert die "$0: WARNING: Please include MAKE=\$(MAKE) in \@ARGV\n"; 11543003dfeSmillert} 11643003dfeSmillert 11743003dfeSmillert# This isn't going to cope with anything fancy, such as spaces inside command 11843003dfeSmillert# names, but neither did what it replaced. Once there is a use case that needs 11943003dfeSmillert# it, please supply patches. Until then, I'm sticking to KISS 12043003dfeSmillertmy @make = split ' ', $1 || $Config{make} || $ENV{MAKE}; 12143003dfeSmillert# Using an array of 0 or 1 elements makes the subsequent code simpler. 12243003dfeSmillertmy @run = $Config{run}; 12343003dfeSmillert@run = () if not defined $run[0] or $run[0] eq ''; 12443003dfeSmillert 12543003dfeSmillert 12643003dfeSmillertif ($target eq '') { 12743003dfeSmillert die "make_ext: no make target specified (eg all or clean)\n"; 12843003dfeSmillert} elsif ($target !~ /(?:^all|clean)$/) { 12943003dfeSmillert # for the time being we are strict about what make_ext is used for 13043003dfeSmillert die "$0: unknown make target '$target'\n"; 13143003dfeSmillert} 13243003dfeSmillert 133b39c5158Smillertif (!@extspec and !$static and !$dynamic and !$nonxs and !$dynaloader) { 13443003dfeSmillert die "$0: no extension specified\n"; 13543003dfeSmillert} 13643003dfeSmillert 13743003dfeSmillertmy $perl; 13843003dfeSmillertmy %extra_passthrough; 13943003dfeSmillert 14043003dfeSmillertif ($is_Win32) { 141*91f110e0Safresh1 require Cwd; 142*91f110e0Safresh1 require FindExt; 143*91f110e0Safresh1 my $build = Cwd::getcwd(); 14443003dfeSmillert $perl = $^X; 14543003dfeSmillert if ($perl =~ m#^\.\.#) { 146898184e3Ssthen my $here = $build; 147898184e3Ssthen $here =~ s{/}{\\}g; 14843003dfeSmillert $perl = "$here\\$perl"; 14943003dfeSmillert } 15043003dfeSmillert (my $topdir = $perl) =~ s/\\[^\\]+$//; 15143003dfeSmillert # miniperl needs to find perlglob and pl2bat 15243003dfeSmillert $ENV{PATH} = "$topdir;$topdir\\win32\\bin;$ENV{PATH}"; 15343003dfeSmillert my $pl2bat = "$topdir\\win32\\bin\\pl2bat"; 15443003dfeSmillert unless (-f "$pl2bat.bat") { 155b39c5158Smillert my @args = ($perl, "-I$topdir\\lib", ("$pl2bat.pl") x 2); 15643003dfeSmillert print "@args\n"; 15743003dfeSmillert system(@args) unless defined $::Cross::platform; 15843003dfeSmillert } 15943003dfeSmillert 160b39c5158Smillert print "In $build"; 161b39c5158Smillert foreach my $dir (@dirs) { 162b39c5158Smillert chdir($dir) or die "Cannot cd to $dir: $!\n"; 163*91f110e0Safresh1 (my $ext = Cwd::getcwd()) =~ s{/}{\\}g; 16443003dfeSmillert FindExt::scan_ext($ext); 16543003dfeSmillert FindExt::set_static_extensions(split ' ', $Config{static_ext}); 166b39c5158Smillert chdir $build 167b39c5158Smillert or die "Couldn't chdir to '$build': $!"; # restore our start directory 168b39c5158Smillert } 16943003dfeSmillert 17043003dfeSmillert my @ext; 17143003dfeSmillert push @ext, FindExt::static_ext() if $static; 172b39c5158Smillert push @ext, FindExt::dynamic_ext() if $dynamic; 173b39c5158Smillert push @ext, FindExt::nonxs_ext() if $nonxs; 174b39c5158Smillert push @ext, 'DynaLoader' if $dynaloader; 17543003dfeSmillert 17643003dfeSmillert foreach (sort @ext) { 17743003dfeSmillert if (%incl and !exists $incl{$_}) { 178b39c5158Smillert #warn "Skipping extension $_, not in inclusion list\n"; 17943003dfeSmillert next; 18043003dfeSmillert } 18143003dfeSmillert if (exists $excl{$_}) { 182b39c5158Smillert warn "Skipping extension $_, not ported to current platform"; 18343003dfeSmillert next; 18443003dfeSmillert } 18543003dfeSmillert push @extspec, $_; 186b39c5158Smillert if($_ eq 'DynaLoader' and $target !~ /clean$/) { 187b39c5158Smillert # No, we don't know why nmake can't work out the dependency chain 188b39c5158Smillert push @{$extra_passthrough{$_}}, 'DynaLoader.c'; 189b39c5158Smillert } elsif(FindExt::is_static($_)) { 19043003dfeSmillert push @{$extra_passthrough{$_}}, 'LINKTYPE=static'; 19143003dfeSmillert } 19243003dfeSmillert } 193b39c5158Smillert 194b39c5158Smillert chdir '..' 195b39c5158Smillert or die "Couldn't chdir to build directory: $!"; # now in the Perl build 19643003dfeSmillert} 19743003dfeSmillertelsif ($is_VMS) { 19843003dfeSmillert $perl = $^X; 19943003dfeSmillert push @extspec, (split ' ', $Config{static_ext}) if $static; 20043003dfeSmillert push @extspec, (split ' ', $Config{dynamic_ext}) if $dynamic; 201b39c5158Smillert push @extspec, (split ' ', $Config{nonxs_ext}) if $nonxs; 202b39c5158Smillert push @extspec, 'DynaLoader' if $dynaloader; 203b39c5158Smillert} 204b39c5158Smillert 205b39c5158Smillert{ 206b39c5158Smillert # Cwd needs to be built before Encode recurses into subdirectories. 207898184e3Ssthen # Pod::Simple needs to be built before Pod::Functions 208b39c5158Smillert # This seems to be the simplest way to ensure this ordering: 209b39c5158Smillert my (@first, @other); 210b39c5158Smillert foreach (@extspec) { 211898184e3Ssthen if ($_ eq 'Cwd' || $_ eq 'Pod/Simple') { 212b39c5158Smillert push @first, $_; 213b39c5158Smillert } else { 214b39c5158Smillert push @other, $_; 215b39c5158Smillert } 216b39c5158Smillert } 217b39c5158Smillert @extspec = (@first, @other); 218b39c5158Smillert} 219b39c5158Smillert 220b39c5158Smillertif ($Config{osname} eq 'catamount' and @extspec) { 221b39c5158Smillert # Snowball's chance of building extensions. 222b39c5158Smillert die "This is $Config{osname}, not building $extspec[0], sorry.\n"; 22343003dfeSmillert} 22443003dfeSmillert 22543003dfeSmillertforeach my $spec (@extspec) { 22643003dfeSmillert my $mname = $spec; 22743003dfeSmillert $mname =~ s!/!::!g; 22843003dfeSmillert my $ext_pathname; 229b39c5158Smillert 230b39c5158Smillert # Try new style ext/Data-Dumper/ first 231b39c5158Smillert my $copy = $spec; 232b39c5158Smillert $copy =~ tr!/!-!; 233b39c5158Smillert foreach my $dir (@ext_dirs) { 234b39c5158Smillert if (-d "$dir/$copy") { 235b39c5158Smillert $ext_pathname = "$dir/$copy"; 236b39c5158Smillert last; 237b39c5158Smillert } 238b39c5158Smillert } 239b39c5158Smillert 240b39c5158Smillert if (!defined $ext_pathname) { 24143003dfeSmillert if (-d "ext/$spec") { 24243003dfeSmillert # Old style ext/Data/Dumper/ 24343003dfeSmillert $ext_pathname = "ext/$spec"; 24443003dfeSmillert } else { 245b39c5158Smillert warn "Can't find extension $spec in any of @ext_dirs"; 246b39c5158Smillert next; 24743003dfeSmillert } 24843003dfeSmillert } 24943003dfeSmillert 25043003dfeSmillert print "\tMaking $mname ($target)\n"; 25143003dfeSmillert 252b39c5158Smillert build_extension($ext_pathname, $perl, $mname, 25343003dfeSmillert [@pass_through, @{$extra_passthrough{$spec} || []}]); 25443003dfeSmillert} 25543003dfeSmillert 25643003dfeSmillertsub build_extension { 257b39c5158Smillert my ($ext_dir, $perl, $mname, $pass_through) = @_; 258b39c5158Smillert 25943003dfeSmillert unless (chdir "$ext_dir") { 26043003dfeSmillert warn "Cannot cd to $ext_dir: $!"; 26143003dfeSmillert return; 26243003dfeSmillert } 263b39c5158Smillert 264b39c5158Smillert my $up = $ext_dir; 265b39c5158Smillert $up =~ s![^/]+!..!g; 266b39c5158Smillert 267b39c5158Smillert $perl ||= "$up/miniperl"; 268b39c5158Smillert my $return_dir = $up; 269b39c5158Smillert my $lib_dir = "$up/lib"; 270b39c5158Smillert $ENV{PERL_CORE} = 1; 271b39c5158Smillert 27243003dfeSmillert my $makefile; 27343003dfeSmillert if ($is_VMS) { 27443003dfeSmillert $makefile = 'descrip.mms'; 27543003dfeSmillert if ($target =~ /clean$/ 27643003dfeSmillert && !-f $makefile 27743003dfeSmillert && -f "${makefile}_old") { 27843003dfeSmillert $makefile = "${makefile}_old"; 27943003dfeSmillert } 28043003dfeSmillert } else { 28143003dfeSmillert $makefile = 'Makefile'; 28243003dfeSmillert } 28343003dfeSmillert 284*91f110e0Safresh1 if (-f $makefile) { 285*91f110e0Safresh1 open my $mfh, $makefile or die "Cannot open $makefile: $!"; 286*91f110e0Safresh1 while (<$mfh>) { 287*91f110e0Safresh1 # Plagiarised from CPAN::Distribution 288*91f110e0Safresh1 last if /MakeMaker post_initialize section/; 289*91f110e0Safresh1 next unless /^#\s+VERSION_FROM\s+=>\s+(.+)/; 290*91f110e0Safresh1 my $vmod = eval $1; 291*91f110e0Safresh1 my $oldv; 292*91f110e0Safresh1 while (<$mfh>) { 293*91f110e0Safresh1 next unless /^XS_VERSION = (\S+)/; 294*91f110e0Safresh1 $oldv = $1; 295*91f110e0Safresh1 last; 296*91f110e0Safresh1 } 297*91f110e0Safresh1 last unless defined $oldv; 298*91f110e0Safresh1 require ExtUtils::MM_Unix; 299*91f110e0Safresh1 defined (my $newv = parse_version MM $vmod) or last; 300*91f110e0Safresh1 if ($newv ne $oldv) { 301*91f110e0Safresh1 1 while unlink $makefile 302*91f110e0Safresh1 } 303*91f110e0Safresh1 } 304*91f110e0Safresh1 } 305*91f110e0Safresh1 30643003dfeSmillert if (!-f $makefile) { 30743003dfeSmillert if (!-f 'Makefile.PL') { 30843003dfeSmillert print "\nCreating Makefile.PL in $ext_dir for $mname\n"; 309898184e3Ssthen my ($fromname, $key, $value); 310898184e3Ssthen if ($mname eq 'podlators') { 311898184e3Ssthen # We need to special case this somewhere, and this is fewer 312898184e3Ssthen # lines of code than a core-only Makefile.PL, and no more 313898184e3Ssthen # complex 314898184e3Ssthen $fromname = 'VERSION'; 315898184e3Ssthen $key = 'DISTNAME'; 316898184e3Ssthen $value = 'podlators'; 317898184e3Ssthen $mname = 'Pod'; 318898184e3Ssthen } else { 319898184e3Ssthen $key = 'ABSTRACT_FROM'; 32043003dfeSmillert # We need to cope well with various possible layouts 32143003dfeSmillert my @dirs = split /::/, $mname; 32243003dfeSmillert my $leaf = pop @dirs; 32343003dfeSmillert my $leafname = "$leaf.pm"; 32443003dfeSmillert my $pathname = join '/', @dirs, $leafname; 32543003dfeSmillert my @locations = ($leafname, $pathname, "lib/$pathname"); 32643003dfeSmillert foreach (@locations) { 32743003dfeSmillert if (-f $_) { 32843003dfeSmillert $fromname = $_; 32943003dfeSmillert last; 33043003dfeSmillert } 33143003dfeSmillert } 33243003dfeSmillert 33343003dfeSmillert unless ($fromname) { 33443003dfeSmillert die "For $mname tried @locations in in $ext_dir but can't find source"; 33543003dfeSmillert } 336898184e3Ssthen ($value = $fromname) =~ s/\.pm\z/.pod/; 337898184e3Ssthen $value = $fromname unless -e $value; 338898184e3Ssthen } 33943003dfeSmillert open my $fh, '>', 'Makefile.PL' 34043003dfeSmillert or die "Can't open Makefile.PL for writing: $!"; 341898184e3Ssthen printf $fh <<'EOM', $0, $mname, $fromname, $key, $value; 34243003dfeSmillert#-*- buffer-read-only: t -*- 34343003dfeSmillert 344898184e3Ssthen# This Makefile.PL was written by %s. 34543003dfeSmillert# It will be deleted automatically by make realclean 34643003dfeSmillert 34743003dfeSmillertuse strict; 34843003dfeSmillertuse ExtUtils::MakeMaker; 34943003dfeSmillert 350898184e3Ssthen# This is what the .PL extracts to. Not the ultimate file that is installed. 351898184e3Ssthen# (ie Win32 runs pl2bat after this) 352898184e3Ssthen 353898184e3Ssthen# Doing this here avoids all sort of quoting issues that would come from 354898184e3Ssthen# attempting to write out perl source with literals to generate the arrays and 355898184e3Ssthen# hash. 356898184e3Ssthenmy @temps = 'Makefile.PL'; 357898184e3Ssthenforeach (glob('scripts/pod*.PL')) { 358898184e3Ssthen # The various pod*.PL extractors change directory. Doing that with relative 359898184e3Ssthen # paths in @INC breaks. It seems the lesser of two evils to copy (to avoid) 360898184e3Ssthen # the chdir doing anything, than to attempt to convert lib paths to 361898184e3Ssthen # absolute, and potentially run into problems with quoting special 362898184e3Ssthen # characters in the path to our build dir (such as spaces) 363898184e3Ssthen require File::Copy; 364898184e3Ssthen 365898184e3Ssthen my $temp = $_; 366898184e3Ssthen $temp =~ s!scripts/!!; 367898184e3Ssthen File::Copy::copy($_, $temp) or die "Can't copy $temp to $_: $!"; 368898184e3Ssthen push @temps, $temp; 369898184e3Ssthen} 370898184e3Ssthen 371898184e3Ssthenmy $script_ext = $^O eq 'VMS' ? '.com' : ''; 372898184e3Ssthenmy %%pod_scripts; 373898184e3Ssthenforeach (glob('pod*.PL')) { 374898184e3Ssthen my $script = $_; 375898184e3Ssthen s/.PL$/$script_ext/i; 376898184e3Ssthen $pod_scripts{$script} = $_; 377898184e3Ssthen} 378898184e3Ssthenmy @exe_files = values %%pod_scripts; 379898184e3Ssthen 38043003dfeSmillertWriteMakefile( 381898184e3Ssthen NAME => '%s', 382898184e3Ssthen VERSION_FROM => '%s', 383898184e3Ssthen %-13s => '%s', 384898184e3Ssthen realclean => { FILES => "@temps" }, 385898184e3Ssthen (%%pod_scripts ? ( 386898184e3Ssthen PL_FILES => \%%pod_scripts, 387898184e3Ssthen EXE_FILES => \@exe_files, 388898184e3Ssthen clean => { FILES => "@exe_files" }, 389898184e3Ssthen ) : ()), 39043003dfeSmillert); 39143003dfeSmillert 39243003dfeSmillert# ex: set ro: 39343003dfeSmillertEOM 39443003dfeSmillert close $fh or die "Can't close Makefile.PL: $!"; 395*91f110e0Safresh1 # As described in commit 23525070d6c0e51f: 396*91f110e0Safresh1 # Push the atime and mtime of generated Makefile.PLs back 4 397*91f110e0Safresh1 # seconds. In certain circumstances ( on virtual machines ) the 398*91f110e0Safresh1 # generated Makefile.PL can produce a Makefile that is older than 399*91f110e0Safresh1 # the Makefile.PL. Altering the atime and mtime backwards by 4 400*91f110e0Safresh1 # seconds seems to resolve the issue. 401898184e3Ssthen eval { 402898184e3Ssthen my $ftime = time - 4; 403898184e3Ssthen utime $ftime, $ftime, 'Makefile.PL'; 404898184e3Ssthen }; 405*91f110e0Safresh1 } 40643003dfeSmillert print "\nRunning Makefile.PL in $ext_dir\n"; 40743003dfeSmillert 40843003dfeSmillert # Presumably this can be simplified 40943003dfeSmillert my @cross; 41043003dfeSmillert if (defined $::Cross::platform) { 41143003dfeSmillert # Inherited from win32/buildext.pl 41243003dfeSmillert @cross = "-MCross=$::Cross::platform"; 41343003dfeSmillert } elsif ($opts{cross}) { 41443003dfeSmillert # Inherited from make_ext.pl 41543003dfeSmillert @cross = '-MCross'; 41643003dfeSmillert } 41743003dfeSmillert 418898184e3Ssthen my @args = ("-I$lib_dir", @cross, 'Makefile.PL'); 41943003dfeSmillert if ($is_VMS) { 42043003dfeSmillert my $libd = VMS::Filespec::vmspath($lib_dir); 42143003dfeSmillert push @args, "INST_LIB=$libd", "INST_ARCHLIB=$libd"; 42243003dfeSmillert } else { 42343003dfeSmillert push @args, 'INSTALLDIRS=perl', 'INSTALLMAN1DIR=none', 42443003dfeSmillert 'INSTALLMAN3DIR=none'; 42543003dfeSmillert } 42643003dfeSmillert push @args, @$pass_through; 42743003dfeSmillert _quote_args(\@args) if $is_VMS; 42843003dfeSmillert print join(' ', @run, $perl, @args), "\n"; 42943003dfeSmillert my $code = system @run, $perl, @args; 43043003dfeSmillert warn "$code from $ext_dir\'s Makefile.PL" if $code; 43143003dfeSmillert 43243003dfeSmillert # Right. The reason for this little hack is that we're sitting inside 43343003dfeSmillert # a program run by ./miniperl, but there are tasks we need to perform 43443003dfeSmillert # when the 'realclean', 'distclean' or 'veryclean' targets are run. 43543003dfeSmillert # Unfortunately, they can be run *after* 'clean', which deletes 43643003dfeSmillert # ./miniperl 43743003dfeSmillert # So we do our best to leave a set of instructions identical to what 43843003dfeSmillert # we would do if we are run directly as 'realclean' etc 43943003dfeSmillert # Whilst we're perfect, unfortunately the targets we call are not, as 44043003dfeSmillert # some of them rely on a $(PERL) for their own distclean targets. 44143003dfeSmillert # But this always used to be a problem with the old /bin/sh version of 44243003dfeSmillert # this. 44343003dfeSmillert if ($is_Unix) { 44443003dfeSmillert my $suffix = '.sh'; 44543003dfeSmillert foreach my $clean_target ('realclean', 'veryclean') { 44643003dfeSmillert my $file = "$return_dir/$clean_target$suffix"; 44743003dfeSmillert open my $fh, '>>', $file or die "open $file: $!"; 44843003dfeSmillert # Quite possible that we're being run in parallel here. 44943003dfeSmillert # Can't use Fcntl this early to get the LOCK_EX 45043003dfeSmillert flock $fh, 2 or warn "flock $file: $!"; 45143003dfeSmillert print $fh <<"EOS"; 45243003dfeSmillertcd $ext_dir 45343003dfeSmillertif test ! -f Makefile -a -f Makefile.old; then 45443003dfeSmillert echo "Note: Using Makefile.old" 45543003dfeSmillert make -f Makefile.old $clean_target MAKE='@make' @pass_through 45643003dfeSmillertelse 45743003dfeSmillert if test ! -f Makefile ; then 45843003dfeSmillert echo "Warning: No Makefile!" 45943003dfeSmillert fi 46043003dfeSmillert make $clean_target MAKE='@make' @pass_through 46143003dfeSmillertfi 46243003dfeSmillertcd $return_dir 46343003dfeSmillertEOS 46443003dfeSmillert close $fh or die "close $file: $!"; 46543003dfeSmillert } 46643003dfeSmillert } 46743003dfeSmillert } 46843003dfeSmillert 46943003dfeSmillert if (not -f $makefile) { 47043003dfeSmillert print "Warning: No Makefile!\n"; 47143003dfeSmillert } 47243003dfeSmillert 47343003dfeSmillert if ($is_VMS) { 474*91f110e0Safresh1 _quote_args($pass_through); 475*91f110e0Safresh1 @$pass_through = ( 476*91f110e0Safresh1 "/DESCRIPTION=$makefile", 477*91f110e0Safresh1 '/MACRO=(' . join(',',@$pass_through) . ')' 478*91f110e0Safresh1 ); 47943003dfeSmillert } 48043003dfeSmillert 48143003dfeSmillert if (!$target or $target !~ /clean$/) { 48243003dfeSmillert # Give makefile an opportunity to rewrite itself. 48343003dfeSmillert # reassure users that life goes on... 48443003dfeSmillert my @args = ('config', @$pass_through); 48543003dfeSmillert system(@run, @make, @args) and print "@run @make @args failed, continuing anyway...\n"; 48643003dfeSmillert } 48743003dfeSmillert my @targ = ($target, @$pass_through); 48843003dfeSmillert print "Making $target in $ext_dir\n@run @make @targ\n"; 48943003dfeSmillert my $code = system(@run, @make, @targ); 49043003dfeSmillert die "Unsuccessful make($ext_dir): code=$code" if $code != 0; 49143003dfeSmillert 49243003dfeSmillert chdir $return_dir || die "Cannot cd to $return_dir: $!"; 49343003dfeSmillert} 49443003dfeSmillert 49543003dfeSmillertsub _quote_args { 49643003dfeSmillert my $args = shift; # must be array reference 49743003dfeSmillert 49843003dfeSmillert # Do not quote qualifiers that begin with '/'. 49943003dfeSmillert map { if (!/^\//) { 50043003dfeSmillert $_ =~ s/\"/""/g; # escape C<"> by doubling 50143003dfeSmillert $_ = q(").$_.q("); 50243003dfeSmillert } 50343003dfeSmillert } @{$args} 50443003dfeSmillert ; 50543003dfeSmillert} 506