make CPAN config reinit automagic
[p5sagit/local-lib.git] / Makefile.PL
CommitLineData
391107e5 1use strict;
2use warnings;
86f54d7f 3use vars qw($bootstrapping);
4
5BEGIN {
c2447f35 6 if (my ($x) = grep { /^--bootstrap(?:=.*)?$/ } @ARGV) {
7 @ARGV = grep { !/^--bootstrap(?:=.*)?$/ } @ARGV;
86f54d7f 8 $bootstrapping = 1;
c2447f35 9 $x =~ /^--bootstrap(?:=(.*))?$/;
86f54d7f 10 my @args = (defined $1 ? ($1) : ());
11
715c31a0 12 $ENV{PERL_MM_USE_DEFAULT} = 1;
86f54d7f 13 {
14 local @INC = @INC;
15 unshift(@INC, 'lib');
16 require local::lib;
17 }
18
19 local::lib->import(@args);
20
21 push(@ARGV,$ENV{PERL_MM_OPT});
4662123f 22 push(@ARGV, map { "-I$_" } split(':',$ENV{PERL5LIB}));
86f54d7f 23
24 system($^X, '-MExtUtils::MakeMaker 6.31', '-e1');
b57052ce 25 my $eumm = $? >> 8;
26
27 system($^X, '-MCPAN 1.80', '-e1');
28 my $cpan = $? >> 8;
29 my $cpan_command = '';
86f54d7f 30
715c31a0 31 system($^X, '-MCPAN', '-e',
32 'CPAN::Config->load;
33 unless (-w $CPAN::Config->{keep_source_where}) {
715c31a0 34 my $save = $CPAN::Config->{urllist};
35 delete @{$CPAN::Config}{keys %$CPAN::Config};
36 $CPAN::Config->{urllist} = $save;
4662123f 37 my $orig = ExtUtils::MakeMaker->can("prompt");
38 my $done;
39 *ExtUtils::MakeMaker::prompt = sub {
40 if (!$done && $_[0] =~ /manual configuration/) {
41 $done++;
42 return "no";
43 }
44 return $orig->(@_);
45 };
715c31a0 46 CPAN::Config->init;
47 }'
48 );
49
86f54d7f 50 # XXX - remove the force on EUMM once its test suite survive PERL_MM_OPT
51
b57052ce 52 if ($eumm) { # non-zero exit
53 $cpan_command .= 'force("install","ExtUtils::MakeMaker"); ';
54 }
55 if ($cpan) {
c2447f35 56 $cpan_command .= 'force("install","CPAN"); ';
b57052ce 57 }
58 if(length $cpan_command) {
59 system($^X, '-MCPAN', '-e', $cpan_command);
86f54d7f 60 }
715c31a0 61 if ($cpan) {
62 system($^X, '-MCPAN', '-e', 'CPAN::Config->load; CPAN::Config->commit;');
63 }
86f54d7f 64 }
65}
66
391107e5 67use inc::Module::Install;
68
69name 'local-lib';
70all_from 'lib/local/lib.pm';
71
72requires 'ExtUtils::MakeMaker' => '6.31'; # version INSTALL_BASE was added
86f54d7f 73requires 'ExtUtils::CBuilder'; # this and ParseXS are needed for MB C_support
74requires 'ExtUtils::ParseXS';
391107e5 75requires 'Module::Build' => '0.28'; # lib -> lib/perl5 change
86f54d7f 76requires 'CPAN' => '1.80'; # sudo support
77
10fcef9b 78# No, really. See
79# https://rt.cpan.org/Public/Bug/Display.html?id=23735
80# for why CPAN now sets the CPANPLUS env var.
81# trouble is this means we can't auto_install(_now) CPAN itself
82# without this beautiful hack
83
84my $no_cpanplus_env = !exists $ENV{PERL5_CPANPLUS_IS_RUNNING};
85require CPAN;
86delete $ENV{PERL5_CPANPLUS_IS_RUNNING} if $no_cpanplus_env;
87
86f54d7f 88if ($bootstrapping) {
89 auto_install_now;
90} else {
91 auto_install;
92}
391107e5 93
94WriteAll;