- Fix Win32 / Cygwin detection (emazep).
[p5sagit/local-lib.git] / Makefile.PL
CommitLineData
391107e5 1use strict;
2use warnings;
c4dbb66c 3use File::Spec;
4use Cwd;
5use vars qw($bootstrapping $bootstrapping_args);
53699c99 6use Config;
86f54d7f 7
c4dbb66c 8my $cwd;
86f54d7f 9BEGIN {
c4dbb66c 10 $cwd = Cwd::cwd();
d4dbe584 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';
19WHOA THERE! It looks like you've got some fancy dashes in your commandline!
20These are *not* the traditional -- dashes that software recognizes. You
21probably got these by copy-pasting from the perldoc for this module as
22rendered by a UTF8-capable formatter. This most typically happens on an OS X
23terminal, but can happen elsewhere too. Please try again after replacing the
24dashes with normal minus signs.
25DEATH
26 }
c2447f35 27 if (my ($x) = grep { /^--bootstrap(?:=.*)?$/ } @ARGV) {
28 @ARGV = grep { !/^--bootstrap(?:=.*)?$/ } @ARGV;
86f54d7f 29 $bootstrapping = 1;
c4dbb66c 30 my ($path) = $x =~ /^--bootstrap(?:=(.*))?$/;
31 my @args = $path ? $path : ();
86f54d7f 32
33 {
34 local @INC = @INC;
35 unshift(@INC, 'lib');
36 require local::lib;
37 }
38
39 local::lib->import(@args);
40
53699c99 41 my @libs = map { "-I$_" } split $Config{path_sep}, $ENV{PERL5LIB};
c4dbb66c 42 $bootstrapping_args = "@libs";
86f54d7f 43 push(@ARGV,$ENV{PERL_MM_OPT});
c4dbb66c 44 push(@ARGV, @libs);
86f54d7f 45
46 system($^X, '-MExtUtils::MakeMaker 6.31', '-e1');
b57052ce 47 my $eumm = $? >> 8;
48
e9227729 49 system($^X, '-MExtUtils::Install 1.43', '-e1');
50 my $eui = $? >> 8;
51
b57052ce 52 system($^X, '-MCPAN 1.80', '-e1');
53 my $cpan = $? >> 8;
54 my $cpan_command = '';
86f54d7f 55
715c31a0 56 system($^X, '-MCPAN', '-e',
279e9381 57 'my $done; require ExtUtils::MakeMaker;
58 my $orig = ExtUtils::MakeMaker->can("prompt");
b143d045 59 *ExtUtils::MakeMaker::prompt = sub ($;$) {
279e9381 60 if (!$done && $_[0] =~ /manual configuration/) {
61 $done++;
62 return "no";
63 }
64 return $orig->(@_);
65 };
66 CPAN::Config->load;
67 unless ($done || -w $CPAN::Config->{keep_source_where}) {
715c31a0 68 my $save = $CPAN::Config->{urllist};
69 delete @{$CPAN::Config}{keys %$CPAN::Config};
70 $CPAN::Config->{urllist} = $save;
71 CPAN::Config->init;
72 }'
73 );
74
279e9381 75 $ENV{PERL_MM_USE_DEFAULT} = 1;
76
86f54d7f 77 # XXX - remove the force on EUMM once its test suite survive PERL_MM_OPT
78
b57052ce 79 if ($eumm) { # non-zero exit
80 $cpan_command .= 'force("install","ExtUtils::MakeMaker"); ';
81 }
e9227729 82 if ($eui) {
83 $cpan_command .= 'install("ExtUtils::Install"); ';
84 }
b57052ce 85 if ($cpan) {
c2447f35 86 $cpan_command .= 'force("install","CPAN"); ';
b57052ce 87 }
88 if(length $cpan_command) {
89 system($^X, '-MCPAN', '-e', $cpan_command);
86f54d7f 90 }
715c31a0 91 if ($cpan) {
92 system($^X, '-MCPAN', '-e', 'CPAN::Config->load; CPAN::Config->commit;');
93 }
c4dbb66c 94
95 chdir($cwd);
86f54d7f 96 }
97}
98
391107e5 99use inc::Module::Install;
100
101name 'local-lib';
102all_from 'lib/local/lib.pm';
103
104requires 'ExtUtils::MakeMaker' => '6.31'; # version INSTALL_BASE was added
e9227729 105requires 'ExtUtils::Install' => '1.43'; # ditto
86f54d7f 106requires 'ExtUtils::CBuilder'; # this and ParseXS are needed for MB C_support
107requires 'ExtUtils::ParseXS';
391107e5 108requires 'Module::Build' => '0.28'; # lib -> lib/perl5 change
6d74e2d7 109my $required_CPAN = '1.80';
110requires 'CPAN' => $required_CPAN; # sudo support + CPAN::HandleConfig
86f54d7f 111
10fcef9b 112# No, really. See
113# https://rt.cpan.org/Public/Bug/Display.html?id=23735
114# for why CPAN now sets the CPANPLUS env var.
115# trouble is this means we can't auto_install(_now) CPAN itself
116# without this beautiful hack
117
118my $no_cpanplus_env = !exists $ENV{PERL5_CPANPLUS_IS_RUNNING};
9a021b2b 119my $no_cpan_env = !exists $ENV{PERL5_CPAN_IS_RUNNING};
10fcef9b 120require CPAN;
121delete $ENV{PERL5_CPANPLUS_IS_RUNNING} if $no_cpanplus_env;
9a021b2b 122delete $ENV{PERL5_CPAN_IS_RUNNING} if $no_cpan_env;
10fcef9b 123
c4dbb66c 124# and make sure that the user doesn't have any existing CPAN config that'll
125# cause us problems for the next few steps.
6d74e2d7 126{
127 local $@;
128 eval { require CPAN::HandleConfig; };
129 # Need newish CPAN.pm for this, ergo skip it if that version of CPAN isn't
130 # installed yet.
131 # It will already be installed by the time we reach here if bootstrapping,
132 # otherwise, if we're running from CPAN then it will be installed soon
133 # enough, and we'll come back here..
134 if (!$@) {
135 CPAN::HandleConfig->load;
136 for my $eumm_setting ( qw/makepl_arg make_install_arg/ ) {
137 if ($CPAN::Config->{$eumm_setting} =~ /(?:PREFIX|INSTALL_BASE)/) {
138 die "Possibly invalid config detected in $eumm_setting: " . $CPAN::Config->{$eumm_setting};
139 }
140 }
141
142 for my $mb_setting (qw/mbuild_arg mbuild_install_arg mbuildpl_arg/) {
143 if ($CPAN::Config->{$mb_setting} =~ /(?:--prefix|--install_base)/) {
144 die "Possibly invalid config detected in $mb_setting: " . $CPAN::Config->{$mb_setting};
145 }
146 }
c4dbb66c 147 }
6d74e2d7 148 else {
149 my $error = $@;
150 require CPAN;
151 # Explode if it looks like requiring CPAN::HandleConfig should
152 # have worked, but didn't.
153 die($error) if $CPAN::VERSION >= $required_CPAN;
c4dbb66c 154 }
155}
156
86f54d7f 157if ($bootstrapping) {
158 auto_install_now;
c4dbb66c 159 postamble <<"END";
160PERL += $bootstrapping_args
161FULLPERL += $bootstrapping_args
162END
86f54d7f 163} else {
164 auto_install;
165}
c4dbb66c 166chdir($cwd);
391107e5 167WriteAll;