This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update B's size/offset for CvFLAGS to U32, following commit 51c78f1b91bbcd7a.
[perl5.git] / write_buildcustomize.pl
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
13 my $file = 'lib/buildcustomize.pl';
14
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.
21 # Term::ReadLine is not here for building but for allowing the debugger to
22 # run under miniperl when nothing but miniperl will build :-(.
23
24 my @toolchain = qw(cpan/AutoLoader/lib
25                    dist/Carp/lib
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
32                    ext/re
33                    dist/Term-ReadLine/lib
34                    );
35
36 # Used only in ExtUtils::Liblist::Kid::_win32_ext()
37 push @toolchain, 'cpan/Text-ParseWords/lib' if $^O eq 'MSWin32';
38
39 # lib must be last, as the toolchain modules write themselves into it
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
47 open my $fh, '>', $file
48     or die "Can't open $file: $!";
49
50 my $error;
51
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.
55 print $fh <<"EOT" or $error = "Can't print to $file: $!";
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
63
64 if ($error) {
65     close $fh
66         or warn "Can't unlink $file after error: $!";
67 } else {
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     }
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: