make CPAN config reinit automagic
[p5sagit/local-lib.git] / Makefile.PL
1 use strict;
2 use warnings;
3 use vars qw($bootstrapping);
4
5 BEGIN {
6   if (my ($x) = grep { /^--bootstrap(?:=.*)?$/ } @ARGV) {
7     @ARGV = grep { !/^--bootstrap(?:=.*)?$/ } @ARGV;
8     $bootstrapping = 1;
9     $x =~ /^--bootstrap(?:=(.*))?$/;
10     my @args = (defined $1 ? ($1) : ());
11
12     $ENV{PERL_MM_USE_DEFAULT} = 1;
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});
22     push(@ARGV, map { "-I$_" } split(':',$ENV{PERL5LIB}));
23
24     system($^X, '-MExtUtils::MakeMaker 6.31', '-e1');
25     my $eumm = $? >> 8;
26
27     system($^X, '-MCPAN 1.80', '-e1');
28     my $cpan = $? >> 8;
29     my $cpan_command = '';
30
31     system($^X, '-MCPAN', '-e',
32       'CPAN::Config->load;
33        unless (-w $CPAN::Config->{keep_source_where}) {
34          my $save = $CPAN::Config->{urllist};
35          delete @{$CPAN::Config}{keys %$CPAN::Config};
36          $CPAN::Config->{urllist} = $save;
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          };
46          CPAN::Config->init;
47        }'
48     );
49
50     # XXX - remove the force on EUMM once its test suite survive PERL_MM_OPT
51
52     if ($eumm) { # non-zero exit
53       $cpan_command .= 'force("install","ExtUtils::MakeMaker"); ';
54     }
55     if ($cpan) {
56       $cpan_command .= 'force("install","CPAN"); ';
57     }
58     if(length $cpan_command) {
59       system($^X, '-MCPAN', '-e', $cpan_command);
60     }
61     if ($cpan) {
62       system($^X, '-MCPAN', '-e', 'CPAN::Config->load; CPAN::Config->commit;');
63     }
64   }
65 }
66
67 use inc::Module::Install;
68
69 name 'local-lib';
70 all_from 'lib/local/lib.pm';
71
72 requires 'ExtUtils::MakeMaker' => '6.31'; # version INSTALL_BASE was added
73 requires 'ExtUtils::CBuilder'; # this and ParseXS are needed for MB C_support
74 requires 'ExtUtils::ParseXS';
75 requires 'Module::Build' => '0.28'; # lib -> lib/perl5 change
76 requires 'CPAN' => '1.80'; # sudo support
77
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
84 my $no_cpanplus_env = !exists $ENV{PERL5_CPANPLUS_IS_RUNNING};
85 require CPAN;
86 delete $ENV{PERL5_CPANPLUS_IS_RUNNING} if $no_cpanplus_env;
87
88 if ($bootstrapping) {
89   auto_install_now;
90 } else {
91   auto_install;
92 }
93
94 WriteAll;