move repository to https://github.com/Perl-Toolchain-Gang/local-lib
[p5sagit/local-lib.git] / Makefile.PL
CommitLineData
391107e5 1use strict;
2use warnings;
c4dbb66c 3use File::Spec;
4use Cwd;
b9c94c15 5use vars qw($bootstrapping $bootstrapping_args $no_manpages);
53699c99 6use Config;
86f54d7f 7
1c9cde8e 8# Solaris (and possibly other Unices) have a tar in /usr/bin that, among
8522f4d5 9# other things, does not understand @LongLink. This can cause
1c9cde8e 10# extraction to look like it succeeded, but it actually failed (because
11# the error message for the @LongLink failure scrolled offscreen).
12# Therefore, given the fact that GNU tar is the most widespread tar available,
13# and it actually supports the feature we want (I'd bet it originated in GNU
14# tar, but I digress), we'll look for GNU tar. If we don't find it, and the
15# user hasn't pointed us to a suitable tar, we'll bomb and tell them what to
16# do.
17
18my $have_gtar = 0;
19if($^O eq 'solaris') {
20 $have_gtar = 0;
21 for my $env_path (split /:/, $ENV{PATH}) {
22 $have_gtar = 1 if -x File::Spec->catfile($env_path, 'gtar');
23 }
24} else {
25 $have_gtar = 1;
26}
27if(exists $ENV{PERL_LL_TAR}) {
28 $have_gtar ||= -x $ENV{PERL_LL_TAR};
29}
30
c27d9c94 31die <<'DEATH' unless $have_gtar;
1c9cde8e 32You are using Solaris (or another traditional Unix) that does not provide a sane
33tar, capable of dealing with the output of GNU tar. Please either set the
34PERL_LL_TAR environment variable to the location of a version of tar that
35understands the @LongLink convention or put a binary named gtar somewhere on
36your PATH.
37DEATH
38
c4dbb66c 39my $cwd;
86f54d7f 40BEGIN {
c4dbb66c 41 $cwd = Cwd::cwd();
d4dbe584 42 # watch out for fancy dashes. these can wind up in our @ARGV if the user is
43 # copypasting the bootstrap command from the POD displayed e.g. by perldoc
44 # on a Mac OS X terminal. since no software recognizes and handles these
45 # dashes, it's better to die loudly telling the user exactly what happened
46 # so they don't make the same mistake again rather than being the only
47 # program in the universe that works with them.
5eff9c24 48 # the fancy dash is U+2212 or \xE2\x88\x92
49 if(grep { /\xE2\x88\x92/ } @ARGV or grep { /−/ } @ARGV) {
d4dbe584 50 die <<'DEATH';
51WHOA THERE! It looks like you've got some fancy dashes in your commandline!
52These are *not* the traditional -- dashes that software recognizes. You
53probably got these by copy-pasting from the perldoc for this module as
54rendered by a UTF8-capable formatter. This most typically happens on an OS X
55terminal, but can happen elsewhere too. Please try again after replacing the
56dashes with normal minus signs.
57DEATH
58 }
c2447f35 59 if (my ($x) = grep { /^--bootstrap(?:=.*)?$/ } @ARGV) {
60 @ARGV = grep { !/^--bootstrap(?:=.*)?$/ } @ARGV;
86f54d7f 61 $bootstrapping = 1;
b9c94c15 62 if(my ($x) = grep { /^--no-manpages/ } @ARGV) {
63 $no_manpages = 1;
64 @ARGV = grep { !/^--no-manpages/ } @ARGV;
65 }
c4dbb66c 66 my ($path) = $x =~ /^--bootstrap(?:=(.*))?$/;
67 my @args = $path ? $path : ();
86f54d7f 68
69 {
70 local @INC = @INC;
71 unshift(@INC, 'lib');
72 require local::lib;
73 }
74
75 local::lib->import(@args);
76
53699c99 77 my @libs = map { "-I$_" } split $Config{path_sep}, $ENV{PERL5LIB};
c4dbb66c 78 $bootstrapping_args = "@libs";
86f54d7f 79 push(@ARGV,$ENV{PERL_MM_OPT});
c4dbb66c 80 push(@ARGV, @libs);
86f54d7f 81
1c9cde8e 82 # <mst> GODDAMN makepl_arg INSTALLDIRS=site
83 # <mst> we must set PERL_AUTOINSTALL_PREFER_CPAN too
84 $ENV{PERL_AUTOINSTALL_PREFER_CPAN} = 1;
85
18717831 86 system($^X, '-MExtUtils::MakeMaker 6.74', '-e1');
b57052ce 87 my $eumm = $? >> 8;
88
e9227729 89 system($^X, '-MExtUtils::Install 1.43', '-e1');
90 my $eui = $? >> 8;
91
135193f4 92 system($^X, '-MModule::Build 0.36', '-e1');
93 my $mb = $? >> 8;
94
d2185901 95 system($^X, '-MCPAN 1.82', '-e1');
b57052ce 96 my $cpan = $? >> 8;
97 my $cpan_command = '';
86f54d7f 98
528fa9be 99 my $did_cpan_config = 0;
100 my $cpan_config_command =
279e9381 101 'my $done; require ExtUtils::MakeMaker;
102 my $orig = ExtUtils::MakeMaker->can("prompt");
b143d045 103 *ExtUtils::MakeMaker::prompt = sub ($;$) {
279e9381 104 if (!$done && $_[0] =~ /manual configuration/) {
105 $done++;
106 return "no";
107 }
108 return $orig->(@_);
109 };
8522f4d5 110 # not yet -- apeiron, 2010-03-10
da6e3c2d 111 #$CPAN::Config->{urllist} = ["http://cpan.shadowcatprojects.net"];
1c9cde8e 112 # <mst> all bootstrapped fine on one DH account
113 # <mst> on another, it tries to install man stuff into /usr/local
114 # <mst> cannot for the life of me figure out why
115 # <mst> (same fucking server as well)
116 # <mst> GOT THE BASTARD
117 # <mst> ExtUtils::ParseXS uses Module::Build
118 # <mst> but Module::Build depends on it
119 # <mst> so you need to set prefer_installer MM
f48dec31 120 # <mst> so cpan uses EU::ParseXS Makefile.PL
1c9cde8e 121 # <mst> since we already got EUMM, *that* works
122 $CPAN::Config->{prefer_installer} = "EUMM";
279e9381 123 CPAN::Config->load;
124 unless ($done || -w $CPAN::Config->{keep_source_where}) {
715c31a0 125 my $save = $CPAN::Config->{urllist};
126 delete @{$CPAN::Config}{keys %$CPAN::Config};
127 $CPAN::Config->{urllist} = $save;
128 CPAN::Config->init;
528fa9be 129 }';
715c31a0 130
279e9381 131 $ENV{PERL_MM_USE_DEFAULT} = 1;
132
86f54d7f 133 # XXX - remove the force on EUMM once its test suite survive PERL_MM_OPT
134
b57052ce 135 if ($eumm) { # non-zero exit
136 $cpan_command .= 'force("install","ExtUtils::MakeMaker"); ';
137 }
e9227729 138 if ($eui) {
139 $cpan_command .= 'install("ExtUtils::Install"); ';
140 }
135193f4 141 if ($mb) {
142 $cpan_command .= 'install("Module::Build"); ';
143 }
b57052ce 144 if ($cpan) {
c2447f35 145 $cpan_command .= 'force("install","CPAN"); ';
b57052ce 146 }
147 if(length $cpan_command) {
528fa9be 148 system($^X, '-MCPAN', '-e', $cpan_config_command);
149 $did_cpan_config++;
b57052ce 150 system($^X, '-MCPAN', '-e', $cpan_command);
86f54d7f 151 }
715c31a0 152 if ($cpan) {
153 system($^X, '-MCPAN', '-e', 'CPAN::Config->load; CPAN::Config->commit;');
154 }
b9c94c15 155 if($no_manpages) {
156 # if we call this code directly, the changes get written to
157 # $BOOTSTRAP/lib/perl5/CPAN/Config.pm, not where the user expects them to
158 # be in their ~/.cpan/CPAN/MyConfig.pm.
528fa9be 159 system($^X, '-MCPAN', '-e', $cpan_config_command)
160 unless $did_cpan_config;
b9c94c15 161 system($^X, '-MCPAN',
8522f4d5 162 '-e',
b9c94c15 163 q[CPAN::HandleConfig->load;],
8522f4d5 164 '-e',
165 q[$CPAN::Config->{makepl_arg} = ] .
b9c94c15 166 q['INSTALLMAN1DIR=none INSTALLMAN3DIR=none';],
167 '-e',
168 q[$CPAN::Config->{buildpl_arg} = ] .
169 q['--install_path libdoc="" --install_path bindoc=""';],
170 '-e',
171 q[CPAN::Config->commit;],
172 );
173 }
c4dbb66c 174
175 chdir($cwd);
86f54d7f 176 }
177}
178
72a295ed 179require ExtUtils::MakeMaker;
180ExtUtils::MakeMaker->import;
181(do 'maint/Makefile.PL.include' or die $@) unless -f 'META.yml';
391107e5 182
72a295ed 183my %CONFIGURE_DEPS = ();
184my %BUILD_DEPS = ();
185my %TEST_DEPS = (
186 'Test::More' => 0,
187);
188my %RUN_DEPS = (
189 'ExtUtils::MakeMaker' => '6.74', # version PERL_MM_OPT is shell parsed
190 'ExtUtils::Install' => '1.43', # version INSTALL_BASE was added
191 'Module::Build' => '0.36', # PERL_MB_OPT
845ea876 192 'CPAN' => '1.82', # sudo support + CPAN::HandleConfig
72a295ed 193);
194
195my %extra_info = (
196 'meta-spec' => { version => 2 },
197 resources => {
198 repository => {
80ee6ea4 199 url => 'git://github.com/Perl-Toolchain-Gang/local-lib',
200 web => 'https://github.com/Perl-Toolchain-Gang/local-lib',
72a295ed 201 type => 'git',
202 },
203 x_IRC => 'irc://irc.perl.org/#local-lib',
204 bugtracker => {
205 web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=local-lib',
206 mailto => 'bug-local-lib@rt.cpan.org',
207 },
208 license => [ 'http://dev.perl.org/licenses/' ],
209 },
210 prereqs => {
d514312f 211 runtime => { requires => { perl => '5.6.0' } },
72a295ed 212 },
213);
391107e5 214
72a295ed 215if ($bootstrapping) {
216 no warnings 'once';
217*MY::postamble = sub {
218 <<"END";
219PERL += $bootstrapping_args
220FULLPERL += $bootstrapping_args
221END
222 }
223}
ca889d42 224
225# don't bother fixing CPAN.pm if bootstrapped from cpanminus
845ea876 226if ($ENV{PERL5_CPANM_IS_RUNNING}) {
227 delete $RUN_DEPS{CPAN};
228}
229else {
ca889d42 230 # No, really. See
231 # https://rt.cpan.org/Public/Bug/Display.html?id=23735
232 # for why CPAN now sets the CPANPLUS env var.
233 # trouble is this means we can't auto_install(_now) CPAN itself
234 # without this beautiful hack
235
236 my $no_cpanplus_env = !exists $ENV{PERL5_CPANPLUS_IS_RUNNING};
237 my $no_cpan_env = !exists $ENV{PERL5_CPAN_IS_RUNNING};
238 require CPAN;
239 delete $ENV{PERL5_CPANPLUS_IS_RUNNING} if $no_cpanplus_env;
240 delete $ENV{PERL5_CPAN_IS_RUNNING} if $no_cpan_env;
241
242 # and make sure that the user doesn't have any existing CPAN config that'll
243 # cause us problems for the next few steps.
6d74e2d7 244 local $@;
245 eval { require CPAN::HandleConfig; };
246 # Need newish CPAN.pm for this, ergo skip it if that version of CPAN isn't
247 # installed yet.
248 # It will already be installed by the time we reach here if bootstrapping,
249 # otherwise, if we're running from CPAN then it will be installed soon
250 # enough, and we'll come back here..
59b1a634 251 if (!$@ ) {
252 CPAN::HandleConfig->require_myconfig_or_config;
253 if ( $CPAN::Config ) {
f168ffdf 254 for my $setting (qw(
255 makepl_arg make_install_arg
256 mbuild_arg mbuild_install_arg mbuildpl_arg
257 )) {
258 my $value = $CPAN::Config->{$setting} or next;
259 if ($setting =~ /^make/
260 ? $value =~ /(?:PREFIX|INSTALL_BASE)/
298c2bbe 261 : $value =~ /(?:--prefix|--install_base)/
f168ffdf 262 ) {
59b1a634 263 die <<"DEATH";
f168ffdf 264WHOA THERE! It looks like you've got $CPAN::Config->{$setting} set in
119c1818 265your CPAN config. This is known to cause problems with local::lib. Please
266either remove this setting or clear out your .cpan directory.
359329d3 267DEATH
59b1a634 268 }
6d74e2d7 269 }
270 }
c4dbb66c 271 }
6d74e2d7 272 else {
273 my $error = $@;
274 require CPAN;
275 # Explode if it looks like requiring CPAN::HandleConfig should
276 # have worked, but didn't.
845ea876 277 die($error) if $CPAN::VERSION >= $RUN_DEPS{CPAN};
c4dbb66c 278 }
279}
72a295ed 280chdir($cwd);
c4dbb66c 281
845ea876 282@{$extra_info{prereqs}{runtime}{requires}}{keys %RUN_DEPS} = values %RUN_DEPS;
283
72a295ed 284# have to do this since old EUMM dev releases miss the eval $VERSION line
3c5f2fc2 285my $eumm_version = eval $ExtUtils::MakeMaker::VERSION;
286my $mymeta_works = $eumm_version >= 6.57_07;
287my $mymeta = $eumm_version >= 6.57_02;
72a295ed 288
3c5f2fc2 289my $has_test_requires = $eumm_version >= 6.63_03;
72a295ed 290
3c5f2fc2 291my $has_meta_v2 = $eumm_version >= 6.57_10;
72a295ed 292if (! $has_meta_v2) {
293 %extra_info = ();
294}
295if (not $has_test_requires) {
296 %BUILD_DEPS = (%BUILD_DEPS, %TEST_DEPS);
297 %TEST_DEPS = ();
298}
299if (not $mymeta_works) {
300 %RUN_DEPS = (%RUN_DEPS, %BUILD_DEPS);
301 %BUILD_DEPS = ();
86f54d7f 302}
43a7f565 303
72a295ed 304WriteMakefile(
305 NAME => 'local::lib',
306 VERSION_FROM => 'lib/local/lib.pm',
307 CONFIGURE_REQUIRES => \%CONFIGURE_DEPS,
308 PREREQ_PM => {
309 %RUN_DEPS,
310 },
a9b2fc02 311 BUILD_REQUIRES => \%BUILD_DEPS,
312 TEST_REQUIRES => \%TEST_DEPS,
72a295ed 313 META_ADD => \%extra_info,
314 META_MERGE => {
315 no_index => {
316 directory => [ 'xt' ]
317 },
318 },
319 ($mymeta && !$mymeta_works ? (NO_MYMETA => 1) : ()),
320 LICENSE => 'perl',
43a7f565 321);