distar-ify
[gitmo/Class-C3.git] / Makefile.PL
1 use strict;
2 use warnings FATAL => 'all';
3 use 5.006;
4
5 my %META = (
6   name => 'Class-C3',
7   license => 'perl_5',
8   prereqs => {
9     configure => { requires => {
10       'ExtUtils::MakeMaker'   => 0,
11       'ExtUtils::CBuilder'    => 0.27,
12     } },
13     build => { requires => {
14     } },
15     test => {
16       requires => {
17         'Test::More' => '0.47',
18       },
19     },
20     runtime => {
21       requires => {
22         'Algorithm::C3' => '0.07',
23         'Scalar::Util'  => '0',
24         'perl'          => 5.006,
25       },
26     },
27     develop   => {
28       requires => { map { $_ => 0 } qw(
29         indirect multidimensional bareword::filehandles
30         Moose Mouse namespace::clean namespace::autoclean
31         MooseX::Types::Common::Numeric
32         Type::Tiny
33       ) },
34     },
35   },
36   resources => {
37     repository => {
38       url => 'git://git.shadowcat.co.uk/gitmo/Class-C3.git',
39       web => 'http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo/Class-C3.git',
40       type => 'git',
41     },
42     bugtracker => {
43       web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=Class-C3',
44       mailto => 'bug-Class-C3@rt.cpan.org',
45     },
46     homepage => 'https://metacpan.org/release/Class-C3',
47     license => [ 'http://dev.perl.org/licenses/' ],
48   },
49   no_index => {
50     directory => [ 't', 'xt', 'opt' ]
51   },
52 );
53
54 my %MM_ARGS = (
55   TEST_REQUIRES => {
56     ( $] < 5.009_005 and is_smoker() )
57       ? ( 'Devel::Hide' => 0 ) : ()
58   },
59   PREREQ_PM => {
60     ( $] < 5.009_005 and can_xs() )
61       ? ( 'Class::C3::XS'  => '0.13' ) : ()
62   },
63 );
64
65 ##############################################################################
66 require ExtUtils::MakeMaker;
67 (do 'maint/Makefile.PL.include' or die $@) unless -f 'META.yml';
68
69 # have to do this since old EUMM dev releases miss the eval $VERSION line
70 my $eumm_version  = eval $ExtUtils::MakeMaker::VERSION;
71 my $mymeta        = $eumm_version >= 6.57_02;
72 my $mymeta_broken = $mymeta && $eumm_version < 6.57_07;
73
74 ($MM_ARGS{NAME} = $META{name}) =~ s/-/::/g;
75 ($MM_ARGS{VERSION_FROM} = "lib/$MM_ARGS{NAME}.pm") =~ s{::}{/}g;
76 $MM_ARGS{LICENSE} = $META{license}
77   if $eumm_version >= 6.30;
78 $MM_ARGS{NO_MYMETA} = 1
79   if $mymeta_broken;
80 $MM_ARGS{META_ADD} = { 'meta-spec' => { version => 2 }, %META }
81   unless -f 'META.yml';
82
83 for (qw(configure build test runtime)) {
84   my $key = $_ eq 'runtime' ? 'PREREQ_PM' : uc $_.'_REQUIRES';
85   my $r = $MM_ARGS{$key} = {
86     %{$META{prereqs}{$_}{requires} || {}},
87     %{delete $MM_ARGS{$key} || {}},
88   };
89   defined $r->{$_} or delete $r->{$_} for keys %$r;
90 }
91
92 $MM_ARGS{MIN_PERL_VERSION} = delete $MM_ARGS{PREREQ_PM}{perl} || 0;
93
94 delete $MM_ARGS{MIN_PERL_VERSION}
95   if $eumm_version < 6.47_01;
96 $MM_ARGS{BUILD_REQUIRES} = {%{$MM_ARGS{BUILD_REQUIRES}}, %{delete $MM_ARGS{TEST_REQUIRES}}}
97   if $eumm_version < 6.63_03;
98 $MM_ARGS{PREREQ_PM} = {%{$MM_ARGS{PREREQ_PM}}, %{delete $MM_ARGS{BUILD_REQUIRES}}}
99   if $eumm_version < 6.55_01;
100 delete $MM_ARGS{CONFIGURE_REQUIRES}
101   if $eumm_version < 6.51_03;
102
103 ExtUtils::MakeMaker::WriteMakefile(%MM_ARGS);
104 ##############################################################################
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 }
150
151 sub is_smoker {
152   return ( $ENV{AUTOMATED_TESTING} && ! $ENV{PERL5_CPANM_IS_RUNNING} && ! $ENV{RELEASE_TESTING} )
153 }