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 | ||
b78ac715 NC |
10 | my $file = 'lib/buildcustomize.pl'; |
11 | ||
5e4c4c91 NC |
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. | |
f61462d5 CB |
18 | # Term::ReadLine is not here for building but for allowing the debugger to |
19 | # run under miniperl when nothing but miniperl will build :-(. | |
5e4c4c91 NC |
20 | |
21 | my @toolchain = qw(cpan/AutoLoader/lib | |
634ff085 | 22 | dist/Carp/lib |
5e4c4c91 NC |
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 | |
7353f64c | 29 | ext/re |
f61462d5 | 30 | dist/Term-ReadLine/lib |
3110a055 | 31 | dist/Exporter/lib |
6de85bb4 | 32 | ext/File-Find/lib |
f4e064af | 33 | cpan/Text-Tabs/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'; | |
2d11a7e9 NC |
38 | push @toolchain, 'ext/VMS-Filespec/lib' if $^O eq 'VMS'; |
39 | ||
40 | unshift @INC, @toolchain; | |
41 | require File::Spec::Functions; | |
5e4c4c91 | 42 | |
2effe01f | 43 | # lib must be last, as the toolchain modules write themselves into it |
5e4c4c91 NC |
44 | # as they build, and it's important that @INC order ensures that the partially |
45 | # written files are always masked by the complete versions. | |
46 | ||
47 | my $inc = join ",\n ", | |
48 | map { "q\0$_\0" } | |
49 | (map {File::Spec::Functions::rel2abs($_)} @toolchain, 'lib'), '.'; | |
50 | ||
b78ac715 NC |
51 | open my $fh, '>', $file |
52 | or die "Can't open $file: $!"; | |
53 | ||
54 | my $error; | |
55 | ||
5e4c4c91 NC |
56 | # If any of the system's build tools are written in Perl, then this module |
57 | # may well be loaded by a much older version than we are building. So keep it | |
58 | # as backwards compatible as is easy. | |
b78ac715 | 59 | print $fh <<"EOT" or $error = "Can't print to $file: $!"; |
5e4c4c91 NC |
60 | #!perl |
61 | ||
62 | # We are miniperl, building extensions | |
63 | # Reset \@INC completely, adding the directories we need, and removing the | |
64 | # installed directories (which we don't need to read, and may confuse us) | |
65 | \@INC = ($inc); | |
66 | EOT | |
b78ac715 NC |
67 | |
68 | if ($error) { | |
69 | close $fh | |
70 | or warn "Can't unlink $file after error: $!"; | |
71 | } else { | |
8e6dd9cb NC |
72 | if (close $fh) { |
73 | do $file and exit; | |
74 | $error = "Can't load generated $file: $@"; | |
75 | } else { | |
76 | $error = "Can't close $file: $!"; | |
77 | } | |
b78ac715 NC |
78 | } |
79 | ||
80 | # It's going very wrong, so try to remove the botched file. | |
81 | ||
82 | unlink $file | |
83 | or warn "Can't unlink $file after error: $!"; | |
84 | die $error; | |
85 | ||
86 | # Local variables: | |
87 | # cperl-indent-level: 4 | |
88 | # indent-tabs-mode: nil | |
89 | # End: | |
90 | # | |
91 | # ex: set ts=8 sts=4 sw=4 et: |