]> perl5.git.perl.org Git - perl5.git/blob - write_buildcustomize.pl This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perlrecharclass: minor clean-up of "Extended Bracketed Character Classes"
[perl5.git] / write_buildcustomize.pl
1 #!./miniperl -w
2
3 use strict;
4
5 my $osname = $^O;
6 my $file = 'lib/buildcustomize.pl';
7
8 if ( @ARGV % 2 ) {
9     my $dir = shift;
10     chdir $dir or die "Can't chdir '$dir': $!";
11     unshift @INC, 'lib';
12 }
13
14 if ( @ARGV ) {
15     # Used during cross-compilation.
16     $osname = $ARGV[1];
17 }
18
19 # To clarify, this isn't the entire suite of modules considered "toolchain"
20 # It's not even all modules needed to build ext/
21 # It's just the source paths of the (minimum complete set of) modules in ext/
22 # needed to build the nonxs modules
23 # After which, all nonxs modules are in lib, which was always sufficient to
24 # allow miniperl to build everything else.
25 # Getopt::Long is here because it's used by podlators, which is one of the
26 # nonxs modules.
27 # Term::ReadLine is not here for building but for allowing the debugger to
28 # run under miniperl when nothing but miniperl will build :-(.
29 # Text::ParseWords is required in ExtUtils::Liblist::Kid
30
31 my @toolchain = qw(
32     cpan/AutoLoader/lib
33     dist/Carp/lib
34     dist/PathTools
35     dist/PathTools/lib
36     cpan/ExtUtils-Install/lib
37     cpan/ExtUtils-MakeMaker/lib
38     cpan/ExtUtils-Manifest/lib
39     cpan/File-Path/lib
40     ext/re
41     dist/Term-ReadLine/lib
42     dist/Exporter/lib
43     ext/File-Find/lib
44     cpan/Text-Tabs/lib
45     dist/constant/lib
46     cpan/version/lib
47     cpan/Getopt-Long/lib
48     cpan/Text-ParseWords/lib
49     cpan/ExtUtils-PL2Bat/lib
50 );
51
52 # These are for XS building on Win32, since nonxs and xs build simultaneously
53 # on Win32 if parallel building
54 push @toolchain, qw(
55     dist/ExtUtils-ParseXS/lib
56     cpan/parent/lib
57     cpan/ExtUtils-Constant/lib
58     dist/base/lib
59 ) if $^O eq 'MSWin32';
60 push @toolchain, 'ext/VMS-Filespec/lib' if $^O eq 'VMS';
61
62 unshift @INC, @toolchain;
63 require File::Spec::Functions;
64 require Cwd;
65
66 my $cwd  = Cwd::getcwd();
67
68 defined $cwd
69     or die "$0: Can't determine current working directory\n";
70
71 # lib must be last, as the toolchain modules write themselves into it
72 # as they build, and it's important that @INC order ensures that the partially
73 # written files are always masked by the complete versions.
74
75 my $inc = join ",\n        ",
76     map { "q\0$_\0" }
77     (map {File::Spec::Functions::rel2abs($_, $cwd)} (
78 # faster build on the non-parallel Win32 build process
79         $^O eq 'MSWin32' ? ('lib', @toolchain ) : (@toolchain, 'lib')
80     ));
81
82 open my $fh, '>', $file
83     or die "Can't open $file: $!";
84
85 my $error;
86
87 # If any of the system's build tools are written in Perl, then this module
88 # may well be loaded by a much older version than we are building. So keep it
89 # as backwards compatible as is easy.
90 print $fh <<"EOT" or $error = "Can't print to $file: $!";
91 #!perl
92
93 #   !!!!!!!   DO NOT EDIT THIS FILE   !!!!!!!
94 #   This file is generated by write_buildcustomize.pl.
95 #   Any changes made here will be lost!
96
97 # We are miniperl, building extensions
98 # Replace the first entry of \@INC ("lib") with the list of
99 # directories we need.
100 splice(\@INC, 0, 1, $inc);
101 \$^O = '$osname';
102 __END__
103 EOT
104
105 if ($error) {
106     close $fh
107         or warn "Can't unlink $file after error: $!";
108 } else {
109     if (close $fh) {
110         do $file and exit;
111         $error = "Can't load generated $file: $@";
112     } else {
113         $error = "Can't close $file: $!";
114     }
115 }
116
117 # It's going very wrong, so try to remove the botched file.
118
119 unlink $file
120     or warn "Can't unlink $file after error: $!";
121 die $error;
122
123 # ex: set ts=8 sts=4 sw=4 et: