266f171a3dfe296a84534ff078a8f37876c16a87
[p5sagit/namespace-clean.git] / Makefile.PL
1 use strict;
2 use warnings;
3 use 5.008001;
4
5 use ExtUtils::MakeMaker;
6
7 my $mymeta_works = eval { ExtUtils::MakeMaker->VERSION('6.5707'); 1 };
8 my $mymeta = $mymeta_works || eval { ExtUtils::MakeMaker->VERSION('6.5702'); 1 };
9
10 my %BUILD_DEPS = (
11   'Test::More' => '0.88',
12 );
13
14 my %RUN_DEPS = (
15   'Package::Stash' => '0.23',
16   'B::Hooks::EndOfScope' => '0.12',
17 );
18
19 # a sub-namer is needed if using the debugger on some perls
20 my %OPT_RUN_DEPS = ( (
21   require 'lib/namespace/clean/_Util.pm'
22     and
23   namespace::clean::_Util::DEBUGGER_NEEDS_CV_RENAME()
24     and
25   namespace::clean::_Util::_namer_load_error()
26     and
27   can_xs()
28 )
29   # when changing version, also change $sn_ver in namespace/clean/_Util.pm
30   ? ( 'Sub::Name' => '0.04' )
31   : ()
32 );
33
34 my %META_BITS = (
35   resources => {
36     homepage => 'http://search.cpan.org/dist/namespace-clean',
37
38     # EUMM not supporting nested meta :(
39     #repository => {
40     #  type => 'git',
41     #  url => 'git://git.shadowcat.co.uk/p5sagit/namespace-clean.git',
42     #  web => 'http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit/namespace-clean.git',
43     #}
44     #bugtracker => {
45     #  mailto => 'bug-namespace-clean@rt.cpan.org',
46     #  web => 'http://rt.cpan.org/Public/Dist/Display.html?Name=namespace-clean',
47     #},
48
49     repository => 'git://git.shadowcat.co.uk/p5sagit/namespace-clean.git',
50     bugtracker => 'http://rt.cpan.org/Public/Dist/Display.html?Name=namespace-clean',
51   },
52 );
53
54 my %WriteMakefileArgs = (
55   'NAME' => 'namespace::clean',
56   'VERSION_FROM' => 'lib/namespace/clean.pm',
57   'ABSTRACT' => 'Keep imports and functions out of your namespace',
58   'AUTHOR' => 'Robert \'phaylon\' Sedlacek <rs@474.at>, Florian Ragwitz <rafl@debian.org>, Jesse Luehrs <doy@tozt.net>',
59   'CONFIGURE_REQUIRES' => { 'ExtUtils::CBuilder' => 0.27 },
60    'PREREQ_PM' => {
61     %RUN_DEPS, %OPT_RUN_DEPS,
62     $mymeta_works ? () : (%BUILD_DEPS),
63   },
64
65   $mymeta_works
66     ? ( # BUILD_REQUIRES makes MYMETA right, requires stops META being wrong
67       'BUILD_REQUIRES' => \%BUILD_DEPS,
68       'META_ADD' => {
69         %META_BITS,
70         requires => \%RUN_DEPS,
71       },
72     )
73     : ( # META_ADD both to get META right - only Makefile written
74       'META_ADD' => {
75         %META_BITS,
76         requires => \%RUN_DEPS,
77         build_requires => \%BUILD_DEPS,
78       },
79     )
80   ,
81
82   ($mymeta and !$mymeta_works) ? ( 'NO_MYMETA' => 1 ) : (),
83
84   'LICENSE' => 'perl',
85 );
86
87
88 unless ( eval { ExtUtils::MakeMaker->VERSION('6.56') } ) {
89   my $br = delete $WriteMakefileArgs{BUILD_REQUIRES};
90   my $pp = $WriteMakefileArgs{PREREQ_PM};
91   for my $mod ( keys %$br ) {
92     if ( exists $pp->{$mod} ) {
93       $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod};
94     }
95     else {
96       $pp->{$mod} = $br->{$mod};
97     }
98   }
99 }
100
101 delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
102   unless eval { ExtUtils::MakeMaker->VERSION('6.52') };
103
104 WriteMakefile(%WriteMakefileArgs);
105
106 # Secondary compile testing via ExtUtils::CBuilder
107 sub can_xs {
108   # Do we have the configure_requires checker?
109   local $@;
110   eval "require ExtUtils::CBuilder;";
111   if ( $@ ) {
112     # They don't obey configure_requires, so it is
113     # someone old and delicate. Try to avoid hurting
114     # them by falling back to an older simpler test.
115     return can_cc();
116   }
117
118   return ExtUtils::CBuilder->new( quiet => 1 )->have_compiler;
119 }
120
121 # can we locate a (the) C compiler
122 sub can_cc {
123   my @chunks = split(/ /, $Config::Config{cc}) or return;
124
125   # $Config{cc} may contain args; try to find out the program part
126   while (@chunks) {
127     return can_run("@chunks") || (pop(@chunks), next);
128   }
129
130   return;
131 }
132
133 # check if we can run some command
134 sub can_run {
135   my ($cmd) = @_;
136
137   return $cmd if -x $cmd;
138   if (my $found_cmd = MM->maybe_command($cmd)) {
139     return $found_cmd;
140   }
141
142   for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
143     next if $dir eq '';
144     my $abs = File::Spec->catfile($dir, $cmd);
145     return $abs if (-x $abs or $abs = MM->maybe_command($abs));
146   }
147
148   return;
149 }