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