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