| 1 | #!./miniperl -w |
| 2 | |
| 3 | use strict; |
| 4 | if (@ARGV) { |
| 5 | my $dir = shift; |
| 6 | chdir $dir or die "Can't chdir '$dir': $!"; |
| 7 | unshift @INC, 'lib'; |
| 8 | } |
| 9 | |
| 10 | my $file = 'lib/buildcustomize.pl'; |
| 11 | |
| 12 | # To clarify, this isn't the entire suite of modules considered "toolchain" |
| 13 | # It's not even all modules needed to build ext/ |
| 14 | # It's just the source paths of the (minimum complete set of) modules in ext/ |
| 15 | # needed to build the nonxs modules |
| 16 | # After which, all nonxs modules are in lib, which was always sufficient to |
| 17 | # allow miniperl to build everything else. |
| 18 | # Term::ReadLine is not here for building but for allowing the debugger to |
| 19 | # run under miniperl when nothing but miniperl will build :-(. |
| 20 | |
| 21 | my @toolchain = qw(cpan/AutoLoader/lib |
| 22 | dist/Carp/lib |
| 23 | dist/Cwd dist/Cwd/lib |
| 24 | dist/ExtUtils-Command/lib |
| 25 | dist/ExtUtils-Install/lib |
| 26 | cpan/ExtUtils-MakeMaker/lib |
| 27 | dist/ExtUtils-Manifest/lib |
| 28 | cpan/File-Path/lib |
| 29 | ext/re |
| 30 | dist/Term-ReadLine/lib |
| 31 | dist/Exporter/lib |
| 32 | ext/File-Find/lib |
| 33 | cpan/Text-Tabs/lib |
| 34 | dist/constant/lib |
| 35 | ); |
| 36 | |
| 37 | # Used only in ExtUtils::Liblist::Kid::_win32_ext() |
| 38 | push @toolchain, 'cpan/Text-ParseWords/lib' if $^O eq 'MSWin32'; |
| 39 | push @toolchain, 'ext/VMS-Filespec/lib' if $^O eq 'VMS'; |
| 40 | |
| 41 | unshift @INC, @toolchain; |
| 42 | require File::Spec::Functions; |
| 43 | |
| 44 | # lib must be last, as the toolchain modules write themselves into it |
| 45 | # as they build, and it's important that @INC order ensures that the partially |
| 46 | # written files are always masked by the complete versions. |
| 47 | |
| 48 | my $inc = join ",\n ", |
| 49 | map { "q\0$_\0" } |
| 50 | (map {File::Spec::Functions::rel2abs($_)} @toolchain, 'lib'), '.'; |
| 51 | |
| 52 | open my $fh, '>', $file |
| 53 | or die "Can't open $file: $!"; |
| 54 | |
| 55 | my $error; |
| 56 | |
| 57 | # If any of the system's build tools are written in Perl, then this module |
| 58 | # may well be loaded by a much older version than we are building. So keep it |
| 59 | # as backwards compatible as is easy. |
| 60 | print $fh <<"EOT" or $error = "Can't print to $file: $!"; |
| 61 | #!perl |
| 62 | |
| 63 | # We are miniperl, building extensions |
| 64 | # Reset \@INC completely, adding the directories we need, and removing the |
| 65 | # installed directories (which we don't need to read, and may confuse us) |
| 66 | \@INC = ($inc); |
| 67 | EOT |
| 68 | |
| 69 | if ($error) { |
| 70 | close $fh |
| 71 | or warn "Can't unlink $file after error: $!"; |
| 72 | } else { |
| 73 | if (close $fh) { |
| 74 | do $file and exit; |
| 75 | $error = "Can't load generated $file: $@"; |
| 76 | } else { |
| 77 | $error = "Can't close $file: $!"; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | # It's going very wrong, so try to remove the botched file. |
| 82 | |
| 83 | unlink $file |
| 84 | or warn "Can't unlink $file after error: $!"; |
| 85 | die $error; |
| 86 | |
| 87 | # Local variables: |
| 88 | # cperl-indent-level: 4 |
| 89 | # indent-tabs-mode: nil |
| 90 | # End: |
| 91 | # |
| 92 | # ex: set ts=8 sts=4 sw=4 et: |