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