don't load CPAN.pm to check its version
[p5sagit/strictures.git] / Makefile.PL
CommitLineData
eae006ee 1use strict;
2use warnings FATAL => 'all';
394c3a46 3use ExtUtils::MakeMaker;
615c05b0 4BEGIN { if ( $^O eq 'cygwin' ) {
5 require ExtUtils::MM_Cygwin;
6 require ExtUtils::MM_Win32;
7 if ( ! defined(&ExtUtils::MM_Cygwin::maybe_command) ) {
8 *ExtUtils::MM_Cygwin::maybe_command = sub {
9 my ($self, $file) = @_;
10 if ($file =~ m{^/cygdrive/}i and ExtUtils::MM_Win32->can('maybe_command')) {
11 ExtUtils::MM_Win32->maybe_command($file);
12 } else {
13 ExtUtils::MM_Unix->maybe_command($file);
14 }
15 }
16 }
17}}
18
394c3a46 19
eae006ee 20(do 'maint/Makefile.PL.include' or die $@) unless -f 'META.yml';
21
27826cd1 22my %extra_prereqs = (
23 indirect => 0,
24 multidimensional => 0,
25 'bareword::filehandles' => 0,
26);
ae3262c9 27
28use Text::ParseWords;
29sub parse_args {
30 # copied from EUMM
31 ExtUtils::MakeMaker::parse_args(
32 my $tmp = {},
33 Text::ParseWords::shellwords($ENV{PERL_MM_OPT} || ''),
34 @ARGV,
35 );
36 return $tmp->{ARGS} || {};
37}
38
27826cd1 39my $have_compiler
ae3262c9 40 = ! parse_args()->{PUREPERL_ONLY}
615c05b0 41 && can_xs();
27826cd1 42
38667eea 43my $support_configure_requires
44 = $ENV{PERL5_CPANM_IS_RUNNING}
45 || !$ENV{PERL5_CPAN_IS_RUNNING}
bb24fbec 46 || do {
47 my ($cpanpm) = grep { -e } map { "$_/CPAN.pm" } @INC;
48 my $v = $cpanpm && MM->parse_version($cpanpm);
49 ($v and $v = eval $v) ? $v > 1.94_55 : 1;
50 };
38667eea 51
52
394c3a46 53WriteMakefile(
54 NAME => 'strictures',
55 VERSION_FROM => 'lib/strictures.pm',
21e2b1b2 56 MIN_PERL_VERSION => '5.006',
de111885 57
dfdfcbae 58 META_MERGE => {
5c109c51 59 'meta-spec' => { version => 2 },
e9258733 60 dynamic_config => 1,
77f9ff76 61
de111885 62 resources => {
63 # r/w: p5sagit@git.shadowcat.co.uk:strictures.git
bfbeb6fd 64 repository => {
65 url => 'git://git.shadowcat.co.uk/p5sagit/strictures.git',
66 web => 'http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit/strictures.git',
67 type => 'git',
68 },
69 bugtracker => {
70 mailto => 'bug-strictures@rt.cpan.org',
71 web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=strictures',
72 },
de111885 73 },
dfdfcbae 74
088e735f 75 prereqs => {
e9258733 76 configure => {
77 requires => {
78 'ExtUtils::CBuilder' => 0,
79 },
80 },
27826cd1 81 runtime => {
38667eea 82 ( $] >= 5.008004 && !($have_compiler && $support_configure_requires)
27826cd1 83 ? ( recommends => \%extra_prereqs ) : () ),
84 },
dfdfcbae 85 },
de111885 86 },
5468e090 87
38667eea 88 ($] >= 5.008004 && $have_compiler && $support_configure_requires
27826cd1 89 ? ( PREREQ_PM => \%extra_prereqs ) : () ),
394c3a46 90);
615c05b0 91
92# can we locate a (the) C compiler
93sub can_cc {
94 my @chunks = split(/ /, $Config::Config{cc}) or return;
95
96 # $Config{cc} may contain args; try to find out the program part
97 while (@chunks) {
98 return can_run("@chunks") || (pop(@chunks), next);
99 }
100
101 return;
102}
103
104# check if we can run some command
105sub can_run {
106 my ($cmd) = @_;
107
108 return $cmd if -x $cmd;
109 if (my $found_cmd = MM->maybe_command($cmd)) {
110 return $found_cmd;
111 }
112
113 require File::Spec;
114 for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
115 next if $dir eq '';
116 my $abs = File::Spec->catfile($dir, $cmd);
117 return $abs if (-x $abs or $abs = MM->maybe_command($abs));
118 }
119
120 return;
121}
122
123# Can our C compiler environment build XS files
124sub can_xs {
125 # Do we have the configure_requires checker?
126 local $@;
127 eval "require ExtUtils::CBuilder; ExtUtils::CBuilder->VERSION(0.27)";
128 if ( $@ ) {
129 # They don't obey configure_requires, so it is
130 # someone old and delicate. Try to avoid hurting
131 # them by falling back to an older simpler test.
132 return can_cc();
133 }
134
135 # Do we have a working C compiler
136 my $builder = ExtUtils::CBuilder->new(
137 quiet => 1,
138 );
139 unless ( $builder->have_compiler ) {
140 # No working C compiler
141 return 0;
142 }
143
144 # Write a C file representative of what XS becomes
145 require File::Temp;
146 my ( $FH, $tmpfile ) = File::Temp::tempfile(
147 "compilexs-XXXXX",
148 SUFFIX => '.c',
149 );
150 binmode $FH;
151 print $FH <<'END_C';
152#include "EXTERN.h"
153#include "perl.h"
154#include "XSUB.h"
155
156int main(int argc, char **argv) {
157 return 0;
158}
159
160int boot_sanexs() {
161 return 1;
162}
163
164END_C
165 close $FH;
166
167 # Can the C compiler access the same headers XS does
168 my @libs = ();
169 my $object = undef;
170 eval {
171 local $^W = 0;
172 $object = $builder->compile(
173 source => $tmpfile,
174 );
175 @libs = $builder->link(
176 objects => $object,
177 module_name => 'sanexs',
178 );
179 };
180 my $result = $@ ? 0 : 1;
181
182 # Clean up all the build files
183 foreach ( $tmpfile, $object, @libs ) {
184 next unless defined $_;
185 1 while unlink;
186 }
187
188 return $result;
189}