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