Interpolation fixes for PERL5LIB, improve --bootstrap handling
[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
23     system($^X, '-MExtUtils::MakeMaker 6.31', '-e1');
24     my $eumm = $? >> 8;
25
26     system($^X, '-MCPAN 1.80', '-e1');
27     my $cpan = $? >> 8;
28     my $cpan_command = '';
29
30     system($^X, '-MCPAN', '-e',
31       'CPAN::Config->load;
32        unless (-w $CPAN::Config->{keep_source_where}) {
33          $ENV{PERL_MM_USE_DEFAULT} = 0;
34          my $save = $CPAN::Config->{urllist};
35          delete @{$CPAN::Config}{keys %$CPAN::Config};
36          $CPAN::Config->{urllist} = $save;
37          CPAN::Config->init;
38        }'
39     );
40
41     # XXX - remove the force on EUMM once its test suite survive PERL_MM_OPT
42
43     if ($eumm) { # non-zero exit
44       $cpan_command .= 'force("install","ExtUtils::MakeMaker"); ';
45     }
46     if ($cpan) {
47       $cpan_command .= 'force("install","CPAN"); ';
48     }
49     if(length $cpan_command) {
50       system($^X, '-MCPAN', '-e', $cpan_command);
51     }
52     if ($cpan) {
53       system($^X, '-MCPAN', '-e', 'CPAN::Config->load; CPAN::Config->commit;');
54     }
55   }
56 }
57
58 use inc::Module::Install;
59
60 name 'local-lib';
61 all_from 'lib/local/lib.pm';
62
63 requires 'ExtUtils::MakeMaker' => '6.31'; # version INSTALL_BASE was added
64 requires 'ExtUtils::CBuilder'; # this and ParseXS are needed for MB C_support
65 requires 'ExtUtils::ParseXS';
66 requires 'Module::Build' => '0.28'; # lib -> lib/perl5 change
67 requires 'CPAN' => '1.80'; # sudo support
68
69 # No, really. See
70 # https://rt.cpan.org/Public/Bug/Display.html?id=23735
71 # for why CPAN now sets the CPANPLUS env var.
72 # trouble is this means we can't auto_install(_now) CPAN itself
73 # without this beautiful hack
74
75 my $no_cpanplus_env = !exists $ENV{PERL5_CPANPLUS_IS_RUNNING};
76 require CPAN;
77 delete $ENV{PERL5_CPANPLUS_IS_RUNNING} if $no_cpanplus_env;
78
79 if ($bootstrapping) {
80   auto_install_now;
81 } else {
82   auto_install;
83 }
84
85 WriteAll;