Clean up CPAN.pm's environment variable the same way we do for CPANPLUS. Add an
[p5sagit/local-lib.git] / Makefile.PL
CommitLineData
391107e5 1use strict;
2use warnings;
c4dbb66c 3use File::Spec;
4use Cwd;
5use vars qw($bootstrapping $bootstrapping_args);
86f54d7f 6
c4dbb66c 7my $cwd;
86f54d7f 8BEGIN {
c4dbb66c 9 $cwd = Cwd::cwd();
d4dbe584 10 # watch out for fancy dashes. these can wind up in our @ARGV if the user is
11 # copypasting the bootstrap command from the POD displayed e.g. by perldoc
12 # on a Mac OS X terminal. since no software recognizes and handles these
13 # dashes, it's better to die loudly telling the user exactly what happened
14 # so they don't make the same mistake again rather than being the only
15 # program in the universe that works with them.
16 if(grep { /−/ } @ARGV) {
17 die <<'DEATH';
18WHOA THERE! It looks like you've got some fancy dashes in your commandline!
19These are *not* the traditional -- dashes that software recognizes. You
20probably got these by copy-pasting from the perldoc for this module as
21rendered by a UTF8-capable formatter. This most typically happens on an OS X
22terminal, but can happen elsewhere too. Please try again after replacing the
23dashes with normal minus signs.
24DEATH
25 }
c2447f35 26 if (my ($x) = grep { /^--bootstrap(?:=.*)?$/ } @ARGV) {
27 @ARGV = grep { !/^--bootstrap(?:=.*)?$/ } @ARGV;
86f54d7f 28 $bootstrapping = 1;
c4dbb66c 29 my ($path) = $x =~ /^--bootstrap(?:=(.*))?$/;
30 my @args = $path ? $path : ();
86f54d7f 31
32 {
33 local @INC = @INC;
34 unshift(@INC, 'lib');
35 require local::lib;
36 }
37
38 local::lib->import(@args);
39
c4dbb66c 40 my @libs = map { "-I$_" } split ':', $ENV{PERL5LIB};
41 $bootstrapping_args = "@libs";
86f54d7f 42 push(@ARGV,$ENV{PERL_MM_OPT});
c4dbb66c 43 push(@ARGV, @libs);
86f54d7f 44
45 system($^X, '-MExtUtils::MakeMaker 6.31', '-e1');
b57052ce 46 my $eumm = $? >> 8;
47
48 system($^X, '-MCPAN 1.80', '-e1');
49 my $cpan = $? >> 8;
50 my $cpan_command = '';
86f54d7f 51
715c31a0 52 system($^X, '-MCPAN', '-e',
279e9381 53 'my $done; require ExtUtils::MakeMaker;
54 my $orig = ExtUtils::MakeMaker->can("prompt");
55 *ExtUtils::MakeMaker::prompt = sub {
56 if (!$done && $_[0] =~ /manual configuration/) {
57 $done++;
58 return "no";
59 }
60 return $orig->(@_);
61 };
62 CPAN::Config->load;
63 unless ($done || -w $CPAN::Config->{keep_source_where}) {
715c31a0 64 my $save = $CPAN::Config->{urllist};
65 delete @{$CPAN::Config}{keys %$CPAN::Config};
66 $CPAN::Config->{urllist} = $save;
67 CPAN::Config->init;
68 }'
69 );
70
279e9381 71 $ENV{PERL_MM_USE_DEFAULT} = 1;
72
86f54d7f 73 # XXX - remove the force on EUMM once its test suite survive PERL_MM_OPT
74
b57052ce 75 if ($eumm) { # non-zero exit
76 $cpan_command .= 'force("install","ExtUtils::MakeMaker"); ';
77 }
78 if ($cpan) {
c2447f35 79 $cpan_command .= 'force("install","CPAN"); ';
b57052ce 80 }
81 if(length $cpan_command) {
82 system($^X, '-MCPAN', '-e', $cpan_command);
86f54d7f 83 }
715c31a0 84 if ($cpan) {
85 system($^X, '-MCPAN', '-e', 'CPAN::Config->load; CPAN::Config->commit;');
86 }
c4dbb66c 87
88 chdir($cwd);
86f54d7f 89 }
90}
91
391107e5 92use inc::Module::Install;
93
94name 'local-lib';
95all_from 'lib/local/lib.pm';
96
97requires 'ExtUtils::MakeMaker' => '6.31'; # version INSTALL_BASE was added
86f54d7f 98requires 'ExtUtils::CBuilder'; # this and ParseXS are needed for MB C_support
99requires 'ExtUtils::ParseXS';
391107e5 100requires 'Module::Build' => '0.28'; # lib -> lib/perl5 change
86f54d7f 101requires 'CPAN' => '1.80'; # sudo support
102
10fcef9b 103# No, really. See
104# https://rt.cpan.org/Public/Bug/Display.html?id=23735
105# for why CPAN now sets the CPANPLUS env var.
106# trouble is this means we can't auto_install(_now) CPAN itself
107# without this beautiful hack
108
109my $no_cpanplus_env = !exists $ENV{PERL5_CPANPLUS_IS_RUNNING};
9a021b2b 110my $no_cpan_env = !exists $ENV{PERL5_CPAN_IS_RUNNING};
10fcef9b 111require CPAN;
112delete $ENV{PERL5_CPANPLUS_IS_RUNNING} if $no_cpanplus_env;
9a021b2b 113delete $ENV{PERL5_CPAN_IS_RUNNING} if $no_cpan_env;
10fcef9b 114
c4dbb66c 115# and make sure that the user doesn't have any existing CPAN config that'll
116# cause us problems for the next few steps.
117require CPAN::HandleConfig;
118CPAN::HandleConfig->load;
119for my $eumm_setting ( qw/makepl_arg make_install_arg/ ) {
120 if ($CPAN::Config->{$eumm_setting} =~ /(?:PREFIX|INSTALL_BASE)/) {
121 die "Possibly invalid config detected in $eumm_setting: " . $CPAN::Config->{$eumm_setting};
122 }
123}
124
125for my $mb_setting (qw/mbuild_arg mbuild_install_arg mbuildpl_arg/) {
126 if ($CPAN::Config->{$mb_setting} =~ /(?:--prefix|--install_base)/) {
127 die "Possibly invalid config detected in $mb_setting: " . $CPAN::Config->{$mb_setting};
128 }
129}
130
86f54d7f 131if ($bootstrapping) {
132 auto_install_now;
c4dbb66c 133 postamble <<"END";
134PERL += $bootstrapping_args
135FULLPERL += $bootstrapping_args
136END
86f54d7f 137} else {
138 auto_install;
139}
c4dbb66c 140chdir($cwd);
391107e5 141WriteAll;