Bail if given fancy dashes due to copypasting from a UTF8-happy POD formatter.
[p5sagit/local-lib.git] / Makefile.PL
1 use strict;
2 use warnings;
3 use vars qw($bootstrapping);
4
5 BEGIN {
6   # watch out for fancy dashes. these can wind up in our @ARGV if the user is
7   # copypasting the bootstrap command from the POD displayed e.g. by perldoc
8   # on a Mac OS X terminal. since no software recognizes and handles these
9   # dashes, it's better to die loudly telling the user exactly what happened
10   # so they don't make the same mistake again rather than being the only
11   # program in the universe that works with them.
12   if(grep { /−/ } @ARGV) {
13       die <<'DEATH';
14 WHOA THERE! It looks like you've got some fancy dashes in your commandline!
15 These are *not* the traditional -- dashes that software recognizes. You
16 probably got these by copy-pasting from the perldoc for this module as
17 rendered by a UTF8-capable formatter. This most typically happens on an OS X
18 terminal, but can happen elsewhere too. Please try again after replacing the
19 dashes with normal minus signs.
20 DEATH
21   }
22   if (my ($x) = grep { /^--bootstrap(?:=.*)?$/ } @ARGV) {
23     @ARGV = grep { !/^--bootstrap(?:=.*)?$/ } @ARGV;
24     $bootstrapping = 1;
25     $x =~ /^--bootstrap(?:=(.*))?$/;
26     my @args = (defined $1 ? ($1) : ());
27
28     {
29       local @INC = @INC;
30       unshift(@INC, 'lib');
31       require local::lib;
32     }
33
34     local::lib->import(@args);
35
36     push(@ARGV,$ENV{PERL_MM_OPT});
37     push(@ARGV, map { "-I$_" } split(':',$ENV{PERL5LIB}));
38
39     system($^X, '-MExtUtils::MakeMaker 6.31', '-e1');
40     my $eumm = $? >> 8;
41
42     system($^X, '-MCPAN 1.80', '-e1');
43     my $cpan = $? >> 8;
44     my $cpan_command = '';
45
46     system($^X, '-MCPAN', '-e',
47       'my $done; require ExtUtils::MakeMaker;
48        my $orig = ExtUtils::MakeMaker->can("prompt");
49        *ExtUtils::MakeMaker::prompt = sub {
50          if (!$done && $_[0] =~ /manual configuration/) {
51            $done++;
52            return "no";
53          }
54          return $orig->(@_);
55        };
56        CPAN::Config->load;
57        unless ($done || -w $CPAN::Config->{keep_source_where}) {
58          my $save = $CPAN::Config->{urllist};
59          delete @{$CPAN::Config}{keys %$CPAN::Config};
60          $CPAN::Config->{urllist} = $save;
61          CPAN::Config->init;
62        }'
63     );
64
65     $ENV{PERL_MM_USE_DEFAULT} = 1;
66
67     # XXX - remove the force on EUMM once its test suite survive PERL_MM_OPT
68
69     if ($eumm) { # non-zero exit
70       $cpan_command .= 'force("install","ExtUtils::MakeMaker"); ';
71     }
72     if ($cpan) {
73       $cpan_command .= 'force("install","CPAN"); ';
74     }
75     if(length $cpan_command) {
76       system($^X, '-MCPAN', '-e', $cpan_command);
77     }
78     if ($cpan) {
79       system($^X, '-MCPAN', '-e', 'CPAN::Config->load; CPAN::Config->commit;');
80     }
81   }
82 }
83
84 use inc::Module::Install;
85
86 name 'local-lib';
87 all_from 'lib/local/lib.pm';
88
89 requires 'ExtUtils::MakeMaker' => '6.31'; # version INSTALL_BASE was added
90 requires 'ExtUtils::CBuilder'; # this and ParseXS are needed for MB C_support
91 requires 'ExtUtils::ParseXS';
92 requires 'Module::Build' => '0.28'; # lib -> lib/perl5 change
93 requires 'CPAN' => '1.80'; # sudo support
94
95 # No, really. See
96 # https://rt.cpan.org/Public/Bug/Display.html?id=23735
97 # for why CPAN now sets the CPANPLUS env var.
98 # trouble is this means we can't auto_install(_now) CPAN itself
99 # without this beautiful hack
100
101 my $no_cpanplus_env = !exists $ENV{PERL5_CPANPLUS_IS_RUNNING};
102 require CPAN;
103 delete $ENV{PERL5_CPANPLUS_IS_RUNNING} if $no_cpanplus_env;
104
105 if ($bootstrapping) {
106   auto_install_now;
107 } else {
108   auto_install;
109 }
110
111 WriteAll;