summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2011-02-14 10:14:18 +0000
committerNicholas Clark <nick@ccl4.org>2011-02-15 14:10:05 +0000
commit5e4c4c91bd52a48de59520d5e9b4e3478e49c613 (patch)
treef48289786af8d9237deb0640edf73e19f7dfda34
parent43c0c913165d6abe1bc0cb45a784eb1c32c3700b (diff)
downloadperl-5e4c4c91bd52a48de59520d5e9b4e3478e49c613.tar.gz
Use a buildcustomize.pl to set @INC in miniperl when building extensions.
With the build tools now shipped in various subdirectories of cpan/ and dist/ we need to add several paths to @INC when invoking MakeMaker (etc) to build extensions. The previous approach of using $ENV{PERL5LIB} was fragile, because: a: It was hitting the length limit for %ENV variables on VMS b: It was running the risk of race conditions in a parallel build - ExtUtils::Makemaker "knows" to add -I../..lib, which puts lib at the *front* of @INC, but if one parallel process happens to copy a module into lib/ whilst another is searching for it, the second may get a partial read c: Overwriting $ENV{PERL5LIB} breaks any system where any of the installed build tools are actually implemented in Perl, if they are relying on $ENV{PERL5LIB} for setup This approach a: Doesn't have %ENV length limits b: Ensures that lib/ is last, so copy targets are always shadowing copy sources c: Only affects miniperl, and doesn't touch $ENV{PERL5LIB} Approaches that turned out to have fatal flaws: 1: Using $ENV{PERL5OPT} with a module fails because ExtUtils::MakeMaker searches for the build perl without setting lib, and treats the error caused by a failed -M as "not a valid perl 5 binary" 2: Refactoring ExtUtils::MakeMaker to *not* use -I for lib, and instead rely on $ENV{PERL5LIB} [which includes "../../lib"] fails because: some extensions have subdirectories, and on these EU::MM correctly uses -I../../../lib, where as $ENV{PERL5LIB} only has space for relative paths, and only with two levels. This approach actually takes advantage of ExtUtils::MakeMaker setting an -I option correct for the depth of directory being built.
-rw-r--r--Cross/Makefile-cross-SH13
-rw-r--r--MANIFEST1
-rwxr-xr-xMakefile.SH13
-rwxr-xr-xinstallperl2
-rw-r--r--make_ext.pl38
-rw-r--r--vms/descrip_mms.template8
-rw-r--r--win32/Makefile14
-rw-r--r--win32/makefile.mk15
-rw-r--r--write_buildcustomize.pl50
9 files changed, 97 insertions, 57 deletions
diff --git a/Cross/Makefile-cross-SH b/Cross/Makefile-cross-SH
index 2ea58f5a9d..d1d2cbf7a1 100644
--- a/Cross/Makefile-cross-SH
+++ b/Cross/Makefile-cross-SH
@@ -324,7 +324,7 @@ $spitshell >>$Makefile <<'!NO!SUBS!'
CONFIGPM = xlib/$(CROSS_NAME)/Config.pm
-private = preplibrary $(CONFIGPM) $(CROSS_LIB)/Config.pod
+private = preplibrary $(CONFIGPM) $(CROSS_LIB)/Config.pod lib/buildcustomize.pl
shextract = Makefile cflags config.h makedepend \
makedir myconfig writemain pod/Makefile
@@ -738,6 +738,9 @@ lib/lib.pm: miniperl $(CONFIGPM)
@-rm -f $@
$(LDLIBPTH) ./miniperl -Ilib -MCross lib/lib_pm.PL
+lib/buildcustomize.pl: $(MINIPERL_EXE) write_buildcustomize.pl
+ $(MINIPERL) write_buildcustomize.pl >lib/buildcustomize.pl
+
unidatafiles $(unidatafiles): uni.data
uni.data: miniperl$(EXE_EXT) $(CONFIGPM) lib/unicore/mktables
@@ -904,16 +907,16 @@ manicheck: FORCE
-$(DYNALOADER): preplibrary FORCE
+$(DYNALOADER): lib/buildcustomize.pl preplibrary FORCE
@$(LDLIBPTH) $(RUN) ./miniperl$(EXE_EXT) -Ilib make_ext.pl --cross $@ MAKE=$(MAKE) LIBPERL_A=$(LIBPERL) LINKTYPE=static $(STATIC_LDFLAGS)
-d_dummy $(dynamic_ext): miniperl$(EXE_EXT) preplibrary makeppport $(DYNALOADER) FORCE
+d_dummy $(dynamic_ext): miniperl$(EXE_EXT) lib/buildcustomize.pl preplibrary makeppport $(DYNALOADER) FORCE
@$(LDLIBPTH) $(RUN) ./miniperl$(EXE_EXT) -Ilib make_ext.pl --cross $@ MAKE=$(MAKE) LIBPERL_A=$(LIBPERL) LINKTYPE=dynamic
-s_dummy $(static_ext): miniperl$(EXE_EXT) preplibrary makeppport $(DYNALOADER) FORCE
+s_dummy $(static_ext): miniperl$(EXE_EXT) lib/buildcustomize.pl preplibrary makeppport $(DYNALOADER) FORCE
@$(LDLIBPTH) $(RUN) ./miniperl$(EXE_EXT) -Ilib make_ext.pl --cross $@ MAKE=$(MAKE) LIBPERL_A=$(LIBPERL) LINKTYPE=static $(STATIC_LDFLAGS)
-n_dummy $(nonxs_ext): miniperl$(EXE_EXT) preplibrary $(DYNALOADER) FORCE
+n_dummy $(nonxs_ext): miniperl$(EXE_EXT) lib/buildcustomize.pl preplibrary $(DYNALOADER) FORCE
@$(LDLIBPTH) $(RUN) ./miniperl$(EXE_EXT) -Ilib make_ext.pl --cross $@ MAKE=$(MAKE) LIBPERL_A=$(LIBPERL)
!NO!SUBS!
diff --git a/MANIFEST b/MANIFEST
index 982fab7ac8..11323a752e 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -5180,6 +5180,7 @@ win32/win32thread.h Win32 port mapping to threads
win32/wince.c WinCE port
win32/wince.h WinCE port
win32/wincesck.c WinCE port
+write_buildcustomize.pl Generate lib/buildcustomize.pl
x2p/a2p.c Output of a2p.y run through byacc
x2p/a2p.h Global declarations
x2p/a2p.pod Pod for awk to perl translator
diff --git a/Makefile.SH b/Makefile.SH
index c8ad2a8f52..6577cc3e58 100755
--- a/Makefile.SH
+++ b/Makefile.SH
@@ -419,7 +419,7 @@ esac
## In the following dollars and backticks do not need the extra backslash.
$spitshell >>$Makefile <<'!NO!SUBS!'
-private = preplibrary $(CONFIGPM) $(CONFIGPOD) lib/ExtUtils/Miniperl.pm git_version.h
+private = preplibrary $(CONFIGPM) $(CONFIGPOD) lib/ExtUtils/Miniperl.pm git_version.h lib/buildcustomize.pl
# Files to be built with variable substitution before miniperl
# is available.
@@ -999,6 +999,9 @@ lib/re.pm: ext/re/re.pm
@-rm -f $@
cp ext/re/re.pm lib/re.pm
+lib/buildcustomize.pl: $(MINIPERL_EXE) write_buildcustomize.pl
+ $(MINIPERL) write_buildcustomize.pl >lib/buildcustomize.pl
+
unidatafiles $(unidatafiles) pod/perluniprops.pod: uni.data
uni.data: $(MINIPERL_EXE) $(CONFIGPM) lib/unicore/mktables $(nonxs_ext)
@@ -1167,16 +1170,16 @@ manicheck: FORCE
#
# DynaLoader may be needed for extensions that use Makefile.PL.
-$(DYNALOADER): $(MINIPERL_EXE) preplibrary FORCE $(nonxs_ext)
+$(DYNALOADER): $(MINIPERL_EXE) lib/buildcustomize.pl preplibrary FORCE $(nonxs_ext)
$(MINIPERL) make_ext.pl $@ MAKE=$(MAKE) LIBPERL_A=$(LIBPERL) LINKTYPE=static $(STATIC_LDFLAGS)
-d_dummy $(dynamic_ext): $(MINIPERL_EXE) preplibrary makeppport $(DYNALOADER) FORCE $(PERLEXPORT)
+d_dummy $(dynamic_ext): $(MINIPERL_EXE) lib/buildcustomize.pl preplibrary makeppport $(DYNALOADER) FORCE $(PERLEXPORT)
$(MINIPERL) make_ext.pl $@ MAKE=$(MAKE) LIBPERL_A=$(LIBPERL) LINKTYPE=dynamic
-s_dummy $(static_ext): $(MINIPERL_EXE) preplibrary makeppport $(DYNALOADER) FORCE
+s_dummy $(static_ext): $(MINIPERL_EXE) lib/buildcustomize.pl preplibrary makeppport $(DYNALOADER) FORCE
$(MINIPERL) make_ext.pl $@ MAKE=$(MAKE) LIBPERL_A=$(LIBPERL) LINKTYPE=static $(STATIC_LDFLAGS)
-n_dummy $(nonxs_ext): $(MINIPERL_EXE) preplibrary FORCE
+n_dummy $(nonxs_ext): $(MINIPERL_EXE) lib/buildcustomize.pl preplibrary FORCE
$(MINIPERL) make_ext.pl $@ MAKE=$(MAKE) LIBPERL_A=$(LIBPERL)
!NO!SUBS!
diff --git a/installperl b/installperl
index 74856aab18..f29f8e512f 100755
--- a/installperl
+++ b/installperl
@@ -714,6 +714,8 @@ sub installlib {
# ignore the test extensions
return if $dir =~ m{\bXS/(?:APItest|Typemap)\b};
return if $name =~ m{\b(?:APItest|Typemap)\.pm$};
+ # ignore the build support code
+ return if $name =~ /\bbuildcustomize\.pl$/;
# ignore the demo files
return if $dir =~ /\b(?:demos?|eg)\b/;
# ignore unneeded unicore files
diff --git a/make_ext.pl b/make_ext.pl
index b780ec9dab..13a15b4601 100644
--- a/make_ext.pl
+++ b/make_ext.pl
@@ -4,11 +4,9 @@ use warnings;
use Config;
BEGIN {
if ($^O eq 'MSWin32') {
- unshift @INC, ('../dist/Cwd', '../dist/Cwd/lib');
- require File::Spec::Functions;
+ unshift @INC, '../dist/Cwd';
require FindExt;
- }
- else {
+ } else {
unshift @INC, 'dist/Cwd';
}
}
@@ -18,27 +16,6 @@ my $is_Win32 = $^O eq 'MSWin32';
my $is_VMS = $^O eq 'VMS';
my $is_Unix = !$is_Win32 && !$is_VMS;
-# To clarify, this isn't the entire suite of modules considered "toolchain"
-# It's not even all modules needed to build ext/
-# It's just the source paths of the (minimum complete set of) modules in ext/
-# needed to build the nonxs modules
-# After which, all nonxs modules are in lib, which was always sufficient to
-# allow miniperl to build everything else.
-
-# This list cannot get any longer without overflowing the length limit for
-# environment variables on VMS
-my @toolchain = qw(cpan/AutoLoader/lib
- dist/Cwd dist/Cwd/lib
- dist/ExtUtils-Command/lib
- dist/ExtUtils-Install/lib
- cpan/ExtUtils-MakeMaker/lib
- dist/ExtUtils-Manifest/lib
- cpan/File-Path/lib
- );
-
-# Used only in ExtUtils::Liblist::Kid::_win32_ext()
-push @toolchain, 'cpan/Text-ParseWords/lib' if $is_Win32;
-
my @ext_dirs = qw(cpan dist ext);
my $ext_dirs_re = '(?:' . join('|', @ext_dirs) . ')';
@@ -296,16 +273,7 @@ sub build_extension {
$perl ||= "$up/miniperl";
my $return_dir = $up;
my $lib_dir = "$up/lib";
- # $lib_dir must be last, as we're copying files into it, and in a parallel
- # make there's a race condition if one process tries to open a module that
- # another process has half-written.
- my @new_inc = ((map {"$up/$_"} @toolchain), $lib_dir);
- if ($is_Win32) {
- @new_inc = map {File::Spec::Functions::rel2abs($_)} @new_inc;
- }
- $ENV{PERL5LIB} = join $Config{path_sep}, @new_inc;
$ENV{PERL_CORE} = 1;
- # warn $ENV{PERL5LIB};
my $makefile;
if ($is_VMS) {
@@ -421,7 +389,7 @@ EOM
@cross = '-MCross';
}
- my @args = (@cross, 'Makefile.PL');
+ my @args = ("-I$lib_dir", @cross, 'Makefile.PL');
if ($is_VMS) {
my $libd = VMS::Filespec::vmspath($lib_dir);
push @args, "INST_LIB=$libd", "INST_ARCHLIB=$libd";
diff --git a/vms/descrip_mms.template b/vms/descrip_mms.template
index 82fddde428..846afa49c8 100644
--- a/vms/descrip_mms.template
+++ b/vms/descrip_mms.template
@@ -361,7 +361,7 @@ CRTLOPTS =,$(CRTL)/Options
unidatadirs = lib/unicore/To lib/unicore/lib
# Modules which must be installed before we can build extensions
-LIBPREREQ = $(ARCHDIR)Config.pm $(ARCHDIR)Config_heavy.pl [.lib.VMS]Filespec.pm $(ARCHDIR)vmspipe.com [.lib]re.pm
+LIBPREREQ = $(ARCHDIR)Config.pm $(ARCHDIR)Config_heavy.pl [.lib.VMS]Filespec.pm $(ARCHDIR)vmspipe.com [.lib]re.pm [.lib]buildcustomize.pl
utils1 = [.lib.pods]perldoc.com [.lib.ExtUtils]Miniperl.pm [.utils]c2ph.com [.utils]h2ph.com
utils2 = [.utils]h2xs.com [.utils]libnetcfg.com [.lib]perlbug.com [.utils]dprofpp.com [.utils]json_pp.com
@@ -460,6 +460,9 @@ archcorefiles : $(ac) $(ARCHAUTO)time.stamp
[.lib]re.pm : [.ext.re]re.pm
Copy/NoConfirm/Log $(MMS$SOURCE) [.lib]
+[.lib]buildcustomize.pl : write_buildcustomize.pl $(MINIPERL_EXE)
+ $(MINIPERL) write_buildcustomize.pl > [.lib]buildcustomize.pl
+
vmspipe.com : [.vms]vmspipe.com
Copy/NoConfirm/Log $(MMS$SOURCE) []
@@ -566,7 +569,7 @@ unidatafiles.ts : $(MINIPERL_EXE) [.lib]Config.pm [.lib.unicore]mktables nonxsex
@ If F$Search("$(MMS$TARGET)").nes."" Then Delete/NoLog/NoConfirm $(MMS$TARGET);*
@ Copy/NoConfirm _NLA0: $(MMS$TARGET)
-DynaLoader$(O) : $(ARCHDIR)Config.pm $(MINIPERL_EXE) [.lib.VMS]Filespec.pm
+DynaLoader$(O) : [.lib]buildcustomize.pl $(ARCHDIR)Config.pm $(MINIPERL_EXE) [.lib.VMS]Filespec.pm
$(MINIPERL) make_ext.pl "MAKE=$(MMS)" "DynaLoader"
dynext : $(LIBPREREQ) $(DBG)perlshr$(E) unidatafiles.ts DynaLoader$(O) preplibrary makeppport $(MINIPERL_EXE)
@@ -1896,6 +1899,7 @@ tidy : cleanlis
- If F$Search("[.utils]*.com;-1").nes."" Then Purge/NoConfirm/Log [.utils]*.com
- If F$Search("[.x2p]*.com;-1").nes."" Then Purge/NoConfirm/Log [.x2p]*.com
- If F$Search("[.lib.pods]*.com;-1").nes."" Then Purge/NoConfirm/Log [.lib.pods]*.com
+ - If F$Search("[.lib]buildcustomize.pl;-1").nes."" Then Purge/NoConfirm/Log [.lib]buildcustomize.pl
clean : tidy cleantest
- $(MINIPERL) make_ext.pl "MAKE=$(MMS)" "--all" "--target=clean"
diff --git a/win32/Makefile b/win32/Makefile
index ceaaaa5ca4..4897a4ad35 100644
--- a/win32/Makefile
+++ b/win32/Makefile
@@ -858,6 +858,9 @@ $(CONFIGPM) : $(MINIPERL) ..\config.sh config_h.PL ..\minimod.pl
-$(MINIPERL) -I..\lib $(ICWD) config_h.PL "INST_VER=$(INST_VER)"
if errorlevel 1 $(MAKE) /$(MAKEFLAGS) $(CONFIGPM)
+..\lib\buildcustomize.pl: $(MINIPERL) ..\write_buildcustomize.pl
+ $(MINIPERL) -I..\lib ..\write_buildcustomize.pl .. >..\lib\buildcustomize.pl
+
$(MINIPERL) : $(MINIDIR) $(MINI_OBJ)
$(LINK32) -subsystem:console -out:$@ @<<
$(LINK_FLAGS) $(LIBFILES) $(MINI_OBJ)
@@ -982,24 +985,24 @@ MakePPPort: $(MINIPERL) $(CONFIGPM) Extensions_nonxs
#-------------------------------------------------------------------------------
# There's no direct way to mark a dependency on
# DynaLoader.pm, so this will have to do
-Extensions: ..\make_ext.pl $(PERLDEP) $(CONFIGPM) $(DYNALOADER)
+Extensions: ..\make_ext.pl ..\lib\buildcustomize.pl $(PERLDEP) $(CONFIGPM) $(DYNALOADER)
$(XCOPY) ..\*.h $(COREDIR)\*.*
$(MINIPERL) -I..\lib ..\make_ext.pl "MAKE=$(MAKE)" --dir=$(CPANDIR) --dir=$(DISTDIR) --dir=$(EXTDIR) --dynamic
-Extensions_reonly: ..\make_ext.pl $(PERLDEP) $(CONFIGPM) $(DYNALOADER)
+Extensions_reonly: ..\make_ext.pl ..\lib\buildcustomize.pl $(PERLDEP) $(CONFIGPM) $(DYNALOADER)
$(XCOPY) ..\*.h $(COREDIR)\*.*
$(MINIPERL) -I..\lib ..\make_ext.pl "MAKE=$(MAKE)" --dir=$(CPANDIR) --dir=$(DISTDIR) --dir=$(EXTDIR) --dynamic +re
-Extensions_static : ..\make_ext.pl list_static_libs.pl $(PERLDEP) $(CONFIGPM)
+Extensions_static : ..\make_ext.pl ..\lib\buildcustomize.pl list_static_libs.pl $(PERLDEP) $(CONFIGPM)
$(XCOPY) ..\*.h $(COREDIR)\*.*
$(MINIPERL) -I..\lib ..\make_ext.pl "MAKE=$(MAKE)" --dir=$(CPANDIR) --dir=$(DISTDIR) --dir=$(EXTDIR) --static
$(MINIPERL) -I..\lib list_static_libs.pl > Extensions_static
-Extensions_nonxs: ..\make_ext.pl $(PERLDEP) $(CONFIGPM)
+Extensions_nonxs: ..\make_ext.pl ..\lib\buildcustomize.pl $(PERLDEP) $(CONFIGPM)
$(XCOPY) ..\*.h $(COREDIR)\*.*
$(MINIPERL) -I..\lib ..\make_ext.pl "MAKE=$(MAKE)" --dir=$(CPANDIR) --dir=$(DISTDIR) --dir=$(EXTDIR) --nonxs
-$(DYNALOADER) : ..\make_ext.pl $(PERLDEP) $(CONFIGPM) Extensions_nonxs
+$(DYNALOADER) : ..\make_ext.pl ..\lib\buildcustomize.pl $(PERLDEP) $(CONFIGPM) Extensions_nonxs
$(XCOPY) ..\*.h $(COREDIR)\*.*
$(MINIPERL) -I..\lib ..\make_ext.pl "MAKE=$(MAKE)" --dir=$(EXTDIR) --dynaloader
@@ -1094,6 +1097,7 @@ distclean: realclean
-del /f $(LIBDIR)\Win32CORE.pm
-del /f $(LIBDIR)\Win32API\File.pm
-del /f $(LIBDIR)\Win32API\File\cFile.pc
+ -del /f $(LIBDIR)\buildcustomize.pl
-del /f $(DISTDIR)\XSLoader\XSLoader.pm
-if exist $(LIBDIR)\App rmdir /s /q $(LIBDIR)\App
-if exist $(LIBDIR)\Archive rmdir /s /q $(LIBDIR)\Archive
diff --git a/win32/makefile.mk b/win32/makefile.mk
index f3fface05a..fcc30ac473 100644
--- a/win32/makefile.mk
+++ b/win32/makefile.mk
@@ -1160,6 +1160,10 @@ $(CONFIGPM) : $(MINIPERL) ..\config.sh config_h.PL ..\minimod.pl
$(MINIPERL) -I..\lib $(ICWD) config_h.PL "INST_VER=$(INST_VER)" \
|| $(MAKE) $(MAKEMACROS) $(CONFIGPM) $(MAKEFILE)
+..\lib\buildcustomize.pl: $(MINIPERL) ..\write_buildcustomize.pl
+ $(MINIPERL) -I..\lib ..\write_buildcustomize.pl .. >..\lib\buildcustomize.pl
+
+
$(MINIPERL) : $(MINIDIR) $(MINI_OBJ) $(CRTIPMLIBS)
.IF "$(CCTYPE)" == "BORLAND"
if not exist $(CCLIBDIR)\PSDK\odbccp32.lib \
@@ -1370,24 +1374,24 @@ MakePPPort: $(MINIPERL) $(CONFIGPM) Extensions_nonxs
#-------------------------------------------------------------------------------
# There's no direct way to mark a dependency on
# DynaLoader.pm, so this will have to do
-Extensions : ..\make_ext.pl $(PERLDEP) $(CONFIGPM) $(DYNALOADER)
+Extensions : ..\make_ext.pl ..\lib\buildcustomize.pl $(PERLDEP) $(CONFIGPM) $(DYNALOADER)
$(XCOPY) ..\*.h $(COREDIR)\*.*
$(MINIPERL) -I..\lib ..\make_ext.pl "MAKE=$(MAKE)" --dir=$(CPANDIR) --dir=$(DISTDIR) --dir=$(EXTDIR) --dynamic
-Extensions_reonly : ..\make_ext.pl $(PERLDEP) $(CONFIGPM) $(DYNALOADER)
+Extensions_reonly : ..\make_ext.pl ..\lib\buildcustomize.pl $(PERLDEP) $(CONFIGPM) $(DYNALOADER)
$(XCOPY) ..\*.h $(COREDIR)\*.*
$(MINIPERL) -I..\lib ..\make_ext.pl "MAKE=$(MAKE)" --dir=$(CPANDIR) --dir=$(DISTDIR) --dir=$(EXTDIR) --dynamic +re
-Extensions_static : ..\make_ext.pl list_static_libs.pl $(PERLDEP) $(CONFIGPM)
+Extensions_static : ..\make_ext.pl ..\lib\buildcustomize.pl list_static_libs.pl $(PERLDEP) $(CONFIGPM)
$(XCOPY) ..\*.h $(COREDIR)\*.*
$(MINIPERL) -I..\lib ..\make_ext.pl "MAKE=$(MAKE)" --dir=$(CPANDIR) --dir=$(DISTDIR) --dir=$(EXTDIR) --static
$(MINIPERL) -I..\lib list_static_libs.pl > Extensions_static
-Extensions_nonxs : ..\make_ext.pl $(PERLDEP) $(CONFIGPM)
+Extensions_nonxs : ..\make_ext.pl ..\lib\buildcustomize.pl $(PERLDEP) $(CONFIGPM)
$(XCOPY) ..\*.h $(COREDIR)\*.*
$(MINIPERL) -I..\lib ..\make_ext.pl "MAKE=$(MAKE)" --dir=$(CPANDIR) --dir=$(DISTDIR) --dir=$(EXTDIR) --nonxs
-$(DYNALOADER) : ..\make_ext.pl $(PERLDEP) $(CONFIGPM) Extensions_nonxs
+$(DYNALOADER) : ..\make_ext.pl ..\lib\buildcustomize.pl $(PERLDEP) $(CONFIGPM) Extensions_nonxs
$(XCOPY) ..\*.h $(COREDIR)\*.*
$(MINIPERL) -I..\lib ..\make_ext.pl "MAKE=$(MAKE)" --dir=$(EXTDIR) --dynaloader
@@ -1479,6 +1483,7 @@ distclean: realclean
-del /f $(LIBDIR)\Win32CORE.pm
-del /f $(LIBDIR)\Win32API\File.pm
-del /f $(LIBDIR)\Win32API\File\cFile.pc
+ -del /f $(LIBDIR)\buildcustomize.pl
-del /f $(DISTDIR)\XSLoader\XSLoader.pm
-if exist $(LIBDIR)\App rmdir /s /q $(LIBDIR)\App
-if exist $(LIBDIR)\Archive rmdir /s /q $(LIBDIR)\Archive
diff --git a/write_buildcustomize.pl b/write_buildcustomize.pl
new file mode 100644
index 0000000000..7d7589645d
--- /dev/null
+++ b/write_buildcustomize.pl
@@ -0,0 +1,50 @@
+#!./miniperl -w
+
+use strict;
+if (@ARGV) {
+ my $dir = shift;
+ chdir $dir or die "Can't chdir '$dir': $!";
+ unshift @INC, 'lib';
+}
+
+unshift @INC, ('dist/Cwd', 'dist/Cwd/lib');
+require File::Spec::Functions;
+
+# To clarify, this isn't the entire suite of modules considered "toolchain"
+# It's not even all modules needed to build ext/
+# It's just the source paths of the (minimum complete set of) modules in ext/
+# needed to build the nonxs modules
+# After which, all nonxs modules are in lib, which was always sufficient to
+# allow miniperl to build everything else.
+
+my @toolchain = qw(cpan/AutoLoader/lib
+ dist/Cwd dist/Cwd/lib
+ dist/ExtUtils-Command/lib
+ dist/ExtUtils-Install/lib
+ cpan/ExtUtils-MakeMaker/lib
+ dist/ExtUtils-Manifest/lib
+ cpan/File-Path/lib
+ );
+
+# Used only in ExtUtils::Liblist::Kid::_win32_ext()
+push @toolchain, 'cpan/Text-ParseWords/lib' if $^O eq 'MSWin32';
+
+# lib must be last, as the the toolchain modules write themselves into it
+# as they build, and it's important that @INC order ensures that the partially
+# written files are always masked by the complete versions.
+
+my $inc = join ",\n ",
+ map { "q\0$_\0" }
+ (map {File::Spec::Functions::rel2abs($_)} @toolchain, 'lib'), '.';
+
+# If any of the system's build tools are written in Perl, then this module
+# may well be loaded by a much older version than we are building. So keep it
+# as backwards compatible as is easy.
+print <<"EOT";
+#!perl
+
+# We are miniperl, building extensions
+# Reset \@INC completely, adding the directories we need, and removing the
+# installed directories (which we don't need to read, and may confuse us)
+\@INC = ($inc);
+EOT