And bump it again to 1.82 for an M::I API issue.
[p5sagit/local-lib.git] / Makefile.PL
1 use strict;
2 use warnings;
3 use File::Spec;
4 use Cwd;
5 use vars qw($bootstrapping $bootstrapping_args $no_manpages);
6 use Config;
7
8 my $cwd;
9 BEGIN {
10   $cwd = Cwd::cwd();
11   # watch out for fancy dashes. these can wind up in our @ARGV if the user is
12   # copypasting the bootstrap command from the POD displayed e.g. by perldoc
13   # on a Mac OS X terminal. since no software recognizes and handles these
14   # dashes, it's better to die loudly telling the user exactly what happened
15   # so they don't make the same mistake again rather than being the only
16   # program in the universe that works with them.
17   if(grep { /−/ } @ARGV) {
18       die <<'DEATH';
19 WHOA THERE! It looks like you've got some fancy dashes in your commandline!
20 These are *not* the traditional -- dashes that software recognizes. You
21 probably got these by copy-pasting from the perldoc for this module as
22 rendered by a UTF8-capable formatter. This most typically happens on an OS X
23 terminal, but can happen elsewhere too. Please try again after replacing the
24 dashes with normal minus signs.
25 DEATH
26   }
27   if (my ($x) = grep { /^--bootstrap(?:=.*)?$/ } @ARGV) {
28     @ARGV = grep { !/^--bootstrap(?:=.*)?$/ } @ARGV;
29     $bootstrapping = 1;
30     if(my ($x) = grep { /^--no-manpages/ } @ARGV) {
31       $no_manpages = 1;
32       @ARGV = grep { !/^--no-manpages/ } @ARGV;
33     }
34     my ($path) = $x =~ /^--bootstrap(?:=(.*))?$/;
35     my @args = $path ? $path : ();
36
37     {
38       local @INC = @INC;
39       unshift(@INC, 'lib');
40       require local::lib;
41     }
42
43     local::lib->import(@args);
44
45     my @libs = map { "-I$_" } split $Config{path_sep}, $ENV{PERL5LIB};
46     $bootstrapping_args = "@libs";
47     push(@ARGV,$ENV{PERL_MM_OPT});
48     push(@ARGV, @libs);
49
50     system($^X, '-MExtUtils::MakeMaker 6.31', '-e1');
51     my $eumm = $? >> 8;
52
53     system($^X, '-MExtUtils::Install 1.43', '-e1');
54     my $eui = $? >> 8;
55
56     system($^X, '-MCPAN 1.82', '-e1');
57     my $cpan = $? >> 8;
58     my $cpan_command = '';
59
60     system($^X, '-MCPAN', '-e',
61       'my $done; require ExtUtils::MakeMaker;
62        my $orig = ExtUtils::MakeMaker->can("prompt");
63        *ExtUtils::MakeMaker::prompt = sub ($;$) {
64          if (!$done && $_[0] =~ /manual configuration/) {
65            $done++;
66            return "no";
67          }
68          return $orig->(@_);
69        };
70        CPAN::Config->load;
71        unless ($done || -w $CPAN::Config->{keep_source_where}) {
72          my $save = $CPAN::Config->{urllist};
73          delete @{$CPAN::Config}{keys %$CPAN::Config};
74          $CPAN::Config->{urllist} = $save;
75          CPAN::Config->init;
76        }'
77     );
78
79     $ENV{PERL_MM_USE_DEFAULT} = 1;
80
81     # XXX - remove the force on EUMM once its test suite survive PERL_MM_OPT
82
83     if ($eumm) { # non-zero exit
84       $cpan_command .= 'force("install","ExtUtils::MakeMaker"); ';
85     }
86     if ($eui) {
87       $cpan_command .= 'install("ExtUtils::Install"); ';
88     }
89     if ($cpan) {
90       $cpan_command .= 'force("install","CPAN"); ';
91     }
92     if(length $cpan_command) {
93       system($^X, '-MCPAN', '-e', $cpan_command);
94     }
95     if ($cpan) {
96       system($^X, '-MCPAN', '-e', 'CPAN::Config->load; CPAN::Config->commit;');
97     }
98     if($no_manpages) {
99       # if we call this code directly, the changes get written to
100       # $BOOTSTRAP/lib/perl5/CPAN/Config.pm, not where the user expects them to
101       # be in their ~/.cpan/CPAN/MyConfig.pm.
102       system($^X, '-MCPAN',
103         '-e', 
104         q[CPAN::HandleConfig->load;],
105         '-e', 
106         q[$CPAN::Config->{makepl_arg}  = ] . 
107           q['INSTALLMAN1DIR=none INSTALLMAN3DIR=none';],
108         '-e',
109         q[$CPAN::Config->{buildpl_arg} = ] .
110           q['--install_path libdoc="" --install_path bindoc=""';],
111         '-e',
112         q[CPAN::Config->commit;],
113       );
114     }
115
116     chdir($cwd);
117   }
118 }
119
120 use inc::Module::Install;
121
122 name 'local-lib';
123 all_from 'lib/local/lib.pm';
124
125 requires 'ExtUtils::MakeMaker' => '6.31'; # version INSTALL_BASE was added
126 requires 'ExtUtils::Install' => '1.43'; # ditto
127 requires 'ExtUtils::CBuilder'; # this and ParseXS are needed for MB C_support
128 requires 'ExtUtils::ParseXS';
129 requires 'Module::Build' => '0.28'; # lib -> lib/perl5 change
130 my $required_CPAN = '1.82';
131 requires 'CPAN' => $required_CPAN; # sudo support + CPAN::HandleConfig
132
133 # No, really. See
134 # https://rt.cpan.org/Public/Bug/Display.html?id=23735
135 # for why CPAN now sets the CPANPLUS env var.
136 # trouble is this means we can't auto_install(_now) CPAN itself
137 # without this beautiful hack
138
139 my $no_cpanplus_env = !exists $ENV{PERL5_CPANPLUS_IS_RUNNING};
140 my $no_cpan_env = !exists $ENV{PERL5_CPAN_IS_RUNNING};
141 require CPAN;
142 delete $ENV{PERL5_CPANPLUS_IS_RUNNING} if $no_cpanplus_env;
143 delete $ENV{PERL5_CPAN_IS_RUNNING} if $no_cpan_env;
144
145 # and make sure that the user doesn't have any existing CPAN config that'll
146 # cause us problems for the next few steps.
147 {
148     local $@;
149     eval { require CPAN::HandleConfig; };
150     # Need newish CPAN.pm for this, ergo skip it if that version of CPAN isn't
151     # installed yet.
152     # It will already be installed by the time we reach here if bootstrapping,
153     # otherwise, if we're running from CPAN then it will be installed soon
154     # enough, and we'll come back here..
155     if (!$@) {
156         CPAN::HandleConfig->load;
157         for my $eumm_setting ( qw/makepl_arg make_install_arg/ ) {
158             if ($CPAN::Config->{$eumm_setting} =~ /(?:PREFIX|INSTALL_BASE)/) {
159                 die "Possibly invalid config detected in $eumm_setting: " . $CPAN::Config->{$eumm_setting};
160             }
161         }
162
163         for my $mb_setting (qw/mbuild_arg mbuild_install_arg mbuildpl_arg/) {
164             if ($CPAN::Config->{$mb_setting} =~ /(?:--prefix|--install_base)/) {
165                 die "Possibly invalid config detected in $mb_setting: " . $CPAN::Config->{$mb_setting};
166             }
167         }
168     }
169     else {
170         my $error = $@;
171         require CPAN;
172         # Explode if it looks like requiring CPAN::HandleConfig should
173         # have worked, but didn't.
174         die($error) if $CPAN::VERSION >= $required_CPAN;
175     }
176 }
177
178 if ($bootstrapping) {
179   auto_install_now;
180   postamble <<"END";
181 PERL     += $bootstrapping_args
182 FULLPERL += $bootstrapping_args
183 END
184 } else {
185   auto_install;
186 }
187 chdir($cwd);
188 WriteAll;