+
+ if (IS_CROSS) {
+ # If we're cross-compiling, it's possible that the host's
+ # Makefiles are around.
+ seek($mfh, 0, 0) or die "Cannot seek $makefile: $!";
+
+ my $cross_makefile;
+ while (<$mfh>) {
+ # XXX This might not be throughout enough.
+ # For example, it's possible to cause a false-positive
+ # if cross compiling on and for the Raspberry Pi,
+ # which is insane but plausible.
+ # False positives are really not troublesome, though;
+ # all they mean is that the module gets rebuilt.
+ if (/^CC = \Q$Config{cc}\E/) {
+ $cross_makefile = 1;
+ last;
+ }
+ }
+
+ if (!$cross_makefile) {
+ print "Deleting non-Cross makefile\n";
+ close $mfh or die "close $makefile: $!";
+ _unlink($makefile);
+ }
+ }
+ }
+
+ if (!-f $makefile) {
+ NO_MAKEFILE:
+ if (!-f 'Makefile.PL') {
+ unless (just_pm_to_blib($target, $ext_dir, $mname, $return_dir)) {
+ # No problems returned, so it has faked everything for us. :-)
+ chdir $return_dir || die "Cannot cd to $return_dir: $!";
+ return;
+ }
+
+ print "\nCreating Makefile.PL in $ext_dir for $mname\n" if $verbose;
+ my ($fromname, $key, $value);
+ if ($mname eq 'podlators') {
+ # We need to special case this somewhere, and this is fewer
+ # lines of code than a core-only Makefile.PL, and no more
+ # complex
+ $fromname = 'VERSION';
+ $key = 'DISTNAME';
+ $value = 'podlators';
+ $mname = 'Pod';
+ } else {
+ $key = 'ABSTRACT_FROM';
+ # We need to cope well with various possible layouts
+ my @dirs = split /::/, $mname;
+ my $leaf = pop @dirs;
+ my $leafname = "$leaf.pm";
+ my $pathname = join '/', @dirs, $leafname;
+ my @locations = ($leafname, $pathname, "lib/$pathname");
+ unshift @locations, 'lib/IO/Compress/Base.pm' if $mname eq 'IO::Compress';
+ foreach (@locations) {
+ if (-f $_) {
+ $fromname = $_;
+ last;
+ }
+ }
+
+ unless ($fromname) {
+ die "For $mname tried @locations in in $ext_dir but can't find source";
+ }
+ ($value = $fromname) =~ s/\.pm\z/.pod/;
+ $value = $fromname unless -e $value;
+ }
+ open my $fh, '>', 'Makefile.PL'
+ or die "Can't open Makefile.PL for writing: $!";
+ printf $fh <<'EOM', $0, $mname, $fromname, $key, $value;
+#-*- buffer-read-only: t -*-
+
+# This Makefile.PL was written by %s.
+# It will be deleted automatically by make realclean
+
+use strict;
+use ExtUtils::MakeMaker;
+
+# This is what the .PL extracts to. Not the ultimate file that is installed.
+# (ie Win32 runs pl2bat after this)
+
+# Doing this here avoids all sort of quoting issues that would come from
+# attempting to write out perl source with literals to generate the arrays and
+# hash.
+my @temps = 'Makefile.PL';
+foreach (glob('scripts/pod*.PL')) {
+ # The various pod*.PL extractors change directory. Doing that with relative
+ # paths in @INC breaks. It seems the lesser of two evils to copy (to avoid)
+ # the chdir doing anything, than to attempt to convert lib paths to
+ # absolute, and potentially run into problems with quoting special
+ # characters in the path to our build dir (such as spaces)
+ require File::Copy;
+
+ my $temp = $_;
+ $temp =~ s!scripts/!!;
+ File::Copy::copy($_, $temp) or die "Can't copy $temp to $_: $!";
+ push @temps, $temp;
+}
+
+my $script_ext = $^O eq 'VMS' ? '.com' : '';
+my %%pod_scripts;
+foreach (glob('pod*.PL')) {
+ my $script = $_;
+ s/.PL$/$script_ext/i;
+ $pod_scripts{$script} = $_;
+}
+my @exe_files = values %%pod_scripts;
+
+WriteMakefile(
+ NAME => '%s',
+ VERSION_FROM => '%s',
+ %-13s => '%s',
+ realclean => { FILES => "@temps" },
+ (%%pod_scripts ? (
+ PL_FILES => \%%pod_scripts,
+ EXE_FILES => \@exe_files,
+ clean => { FILES => "@exe_files" },
+ ) : ()),
+);
+
+# ex: set ro:
+EOM
+ close $fh or die "Can't close Makefile.PL: $!";
+ # As described in commit 23525070d6c0e51f:
+ # Push the atime and mtime of generated Makefile.PLs back 4
+ # seconds. In certain circumstances ( on virtual machines ) the
+ # generated Makefile.PL can produce a Makefile that is older than
+ # the Makefile.PL. Altering the atime and mtime backwards by 4
+ # seconds seems to resolve the issue.
+ eval {
+ my $ftime = time - 4;
+ utime $ftime, $ftime, 'Makefile.PL';
+ };
+ } elsif ($mname =~ /\A(?:Carp
+ |ExtUtils::CBuilder
+ |Safe
+ |Search::Dict)\z/x) {
+ # An explicit list of dual-life extensions that have a Makefile.PL
+ # for CPAN, but we have verified can also be built using the fakery.
+ my ($problem) = just_pm_to_blib($target, $ext_dir, $mname, $return_dir);
+ # We really need to sanity test that we can fake it.
+ # Otherwise "skips" will go undetected, and the build slow down for
+ # everyone, defeating the purpose.
+ if (defined $problem) {
+ if (-d "$return_dir/.git") {
+ # Get the list of files that git isn't ignoring:
+ my @files = `git ls-files --cached --others --exclude-standard 2>/dev/null`;
+ # on error (eg no git) we get nothing, but that's not a
+ # problem. The goal is to see if git thinks that the problem
+ # file is interesting, by getting a positive match with
+ # something git told us about, and if so bail out:
+ foreach (@files) {
+ chomp;
+ # We really need to sanity test that we can fake it.
+ # The intent is that this should only fail because
+ # you've just added a file to the dual-life dist that
+ # we can't handle. In which case you should either
+ # 1) remove the dist from the regex a few lines above.
+ # or
+ # 2) add the file to regex of "safe" filenames earlier
+ # in this function, that starts with ChangeLog
+ die "FATAL - $0 has $mname in the list of simple extensions, but it now contains file '$problem' which we can't handle"
+ if $problem eq $_;
+ }
+ # There's an unexpected file, but it seems to be something
+ # that git will ignore. So fall through to the regular
+ # Makefile.PL handling code below, on the assumption that
+ # we won't get here for a clean build.
+ }
+ warn "WARNING - $0 is building $mname using EU::MM, as it found file '$problem'";
+ } else {
+ # It faked everything for us.
+ chdir $return_dir || die "Cannot cd to $return_dir: $!";
+ return;
+ }
+ }
+
+ # We are going to have to use Makefile.PL:
+ print "\nRunning Makefile.PL in $ext_dir\n" if $verbose;
+
+ my @args = ("-I$lib_dir", 'Makefile.PL');
+ if ($is_VMS) {
+ my $libd = VMS::Filespec::vmspath($lib_dir);
+ push @args, "INST_LIB=$libd", "INST_ARCHLIB=$libd";
+ } else {
+ push @args, 'INSTALLDIRS=perl', 'INSTALLMAN1DIR=none',
+ 'INSTALLMAN3DIR=none';
+ }
+ push @args, @$pass_through;
+ _quote_args(\@args) if $is_VMS;
+ print join(' ', $perl, @args), "\n" if $verbose;
+ my $code = system $perl, @args;