This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pp.c: White-space, comments only
[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
30 my @toolchain = qw(cpan/AutoLoader/lib
31                    dist/Carp/lib
32                    dist/PathTools dist/PathTools/lib
33                    cpan/ExtUtils-Install/lib
34                    cpan/ExtUtils-MakeMaker/lib
35                    cpan/ExtUtils-Manifest/lib
36                    cpan/File-Path/lib
37                    ext/re
38                    dist/Term-ReadLine/lib
39                    dist/Exporter/lib
40                    ext/File-Find/lib
41                    cpan/Text-Tabs/lib
42                    dist/constant/lib
43                    cpan/version/lib
44                    cpan/Getopt-Long/lib
45                    );
46
47 # Text-ParseWords used only in ExtUtils::Liblist::Kid::_win32_ext()
48 # the rest are for XS building on Win32, since nonxs and xs build simultaneously
49 # on Win32 if parallel building
50 push @toolchain, qw(
51         cpan/Text-ParseWords/lib
52         dist/ExtUtils-ParseXS/lib
53         cpan/parent/lib
54         cpan/ExtUtils-Constant/lib
55 ) if $^O eq 'MSWin32';
56 push @toolchain, 'ext/VMS-Filespec/lib' if $^O eq 'VMS';
57
58 unshift @INC, @toolchain;
59 require File::Spec::Functions;
60 require Cwd;
61
62 my $cwd  = Cwd::getcwd();
63
64 # lib must be last, as the toolchain modules write themselves into it
65 # as they build, and it's important that @INC order ensures that the partially
66 # written files are always masked by the complete versions.
67
68 my $inc = join ",\n        ",
69     map { "q\0$_\0" }
70     (map {File::Spec::Functions::rel2abs($_, $cwd)} (
71 # faster build on the non-parallel Win32 build process
72         $^O eq 'MSWin32' ? ('lib', @toolchain ) : (@toolchain, 'lib')
73     ));
74
75 open my $fh, '>', $file
76     or die "Can't open $file: $!";
77
78 my $error;
79
80 # If any of the system's build tools are written in Perl, then this module
81 # may well be loaded by a much older version than we are building. So keep it
82 # as backwards compatible as is easy.
83 print $fh <<"EOT" or $error = "Can't print to $file: $!";
84 #!perl
85
86 #   !!!!!!!   DO NOT EDIT THIS FILE   !!!!!!!
87 #   This file is generated by write_buildcustomize.pl.
88 #   Any changes made here will be lost!
89
90 # We are miniperl, building extensions
91 # Replace the first entry of \@INC ("lib") with the list of
92 # directories we need.
93 splice(\@INC, 0, 1, $inc);
94 \$^O = '$osname';
95 __END__
96 EOT
97
98 if ($error) {
99     close $fh
100         or warn "Can't unlink $file after error: $!";
101 } else {
102     if (close $fh) {
103         do $file and exit;
104         $error = "Can't load generated $file: $@";
105     } else {
106         $error = "Can't close $file: $!";
107     }
108 }
109
110 # It's going very wrong, so try to remove the botched file.
111
112 unlink $file
113     or warn "Can't unlink $file after error: $!";
114 die $error;
115
116 # ex: set ts=8 sts=4 sw=4 et: