make bump
[p5sagit/JSON-MaybeXS.git] / Makefile.PL
CommitLineData
44459f01 1use strict;
2use warnings FATAL => 'all';
44459f01 3use ExtUtils::MakeMaker;
4(do 'maint/Makefile.PL.include' or die $@) unless -f 'META.yml';
5
81b819d6 6my %WriteMakefileArgs = (
44459f01 7 NAME => 'JSON::MaybeXS',
8 VERSION_FROM => 'lib/JSON/MaybeXS.pm',
bd6b85ee 9
10 META_MERGE => {
8b945fac 11 'meta-spec' => { version => 2 },
12 dynamic_config => 1,
bd6b85ee 13 resources => {
dd6a8d22 14 # r/w: p5sagit@git.shadowcat.co.uk:JSON-MaybeXS.git
bd6b85ee 15 repository => {
dd6a8d22 16 url => 'git://git.shadowcat.co.uk/p5sagit/JSON-MaybeXS.git',
17 web => 'http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit/JSON-MaybeXS.git',
bd6b85ee 18 type => 'git',
19 },
20 bugtracker => {
21 mailto => 'bug-JSON-MaybeXS@rt.cpan.org',
22 web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=JSON-MaybeXS',
23 },
24 },
25 },
26
27 META_ADD => {
037386f7 28 prereqs => {
29 configure => {
30 requires => {
731cdb1c 31 'ExtUtils::MakeMaker' => '0',
037386f7 32 'ExtUtils::CBuilder' => '0.27',
33 'File::Spec' => '0',
34 'File::Temp' => '0',
35 },
36 },
37 runtime => {
38 requires => {
8e911b7e 39 'Scalar::Util' => '0',
c397f194 40 'Carp' => '0',
037386f7 41 'JSON::PP' => '2.27202',
42 # we may also add a runtime prereq for Cpanel::JSON::XS, on the
43 # installer's machine
44 perl => '5.006',
45 },
46 recommends => { 'Cpanel::JSON::XS' => '2.3310' },
47 },
48 test => {
49 requires => {
50 'Test::Without::Module' => '0.17',
51 'Test::More' => '0.88',
52 },
53 },
54 },
8b945fac 55 },
44459f01 56);
57
81b819d6 58my $eumm_version = eval $ExtUtils::MakeMaker::VERSION;
037386f7 59
60for (qw(configure build test runtime)) {
61 my $key = $_ eq 'runtime' ? 'PREREQ_PM' : uc $_.'_REQUIRES';
62 next unless exists $WriteMakefileArgs{META_ADD}{prereqs}{$_}
63 or exists $WriteMakefileArgs{$key};
64 my $r = $WriteMakefileArgs{$key} = {
65 %{$WriteMakefileArgs{META_ADD}{prereqs}{$_}{requires} || {}},
66 %{delete $WriteMakefileArgs{$key} || {}},
67 };
68 defined $r->{$_} or delete $r->{$_} for keys %$r;
69}
70
b207f99e 71# dynamic prereqs get added here.
72
037386f7 73# we require Cpanel::JSON::XS, except if JSON::XS is already installed.
74# (we also always recommend Cpanel::JSON::XS, just to make sure.)
75$WriteMakefileArgs{PREREQ_PM}{'Cpanel::JSON::XS'} = '2.3310'
6f3c496c 76 if not parse_args()->{PUREPERL_ONLY}
63b80fbc 77 and ((eval { require Cpanel::JSON::XS; 1 } and not eval { Cpanel::JSON::XS->VERSION('2.3310'); 1 })
78 or (not eval { require JSON::XS; 1; } and can_xs()));
037386f7 79
14a1801c 80# avoid "JSON::XS::Boolean::* redefined" warnings caused by incompatibilities
81# between JSON::XS 2.x and 3.0 --
82# if JSON::XS is installed and < 3.0
83# and Cpanel::JSON::JSON is (or is about to be) >= 3.0,
84# then update JSON::XS to eliminate the incompatibility
85$WriteMakefileArgs{PREREQ_PM}{'JSON::XS'} = '3.00'
86 if not parse_args()->{PUREPERL_ONLY}
87 and eval { require JSON::XS; 1 } and not eval { JSON::XS->VERSION('3.0'); 1 }
88 and (eval { require Cpanel::JSON::XS; Cpanel::JSON::XS->VERSION('3.0'); 1 }
89 # we presume here that if we are installing Cpanel::JSON::XS, we
90 # are installing the latest version
91 or exists $WriteMakefileArgs{PREREQ_PM}{'Cpanel::JSON::XS'});
92
81b819d6 93$WriteMakefileArgs{MIN_PERL_VERSION} = delete $WriteMakefileArgs{PREREQ_PM}{perl} || 0;
c4e0d79f 94
b207f99e 95die 'attention developer: you need to do a sane meta merge here!'
96 if keys %{$WriteMakefileArgs{BUILD_REQUIRES}};
97
81b819d6 98$WriteMakefileArgs{BUILD_REQUIRES} = {
86f2a3a5 99 %{$WriteMakefileArgs{BUILD_REQUIRES} || {}},
81b819d6 100 %{delete $WriteMakefileArgs{TEST_REQUIRES}}
101} if $eumm_version < 6.63_03;
c4e0d79f 102
81b819d6 103$WriteMakefileArgs{PREREQ_PM} = {
104 %{$WriteMakefileArgs{PREREQ_PM}},
105 %{delete $WriteMakefileArgs{BUILD_REQUIRES}}
106} if $eumm_version < 6.55_01;
107
c4e0d79f 108delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
109 if $eumm_version < 6.51_03;
110
a73f6fe1 111delete $WriteMakefileArgs{MIN_PERL_VERSION}
112 if $eumm_version < 6.48;
113
114delete @WriteMakefileArgs{qw(META_ADD META_MERGE)}
115 if $eumm_version < 6.46;
116
117delete $WriteMakefileArgs{LICENSE}
118 if $eumm_version < 6.31;
119
81b819d6 120WriteMakefile(%WriteMakefileArgs);
121
6f3c496c 122
123sub parse_args {
124 # copied from EUMM
125 require ExtUtils::MakeMaker;
126 require Text::ParseWords;
127 ExtUtils::MakeMaker::parse_args(
128 my $tmp = {},
129 Text::ParseWords::shellwords($ENV{PERL_MM_OPT} || ''),
130 @ARGV,
131 );
132 return $tmp->{ARGS} || {};
133}
134
44459f01 135# can we locate a (the) C compiler
136sub can_cc {
137 my @chunks = split(/ /, $Config::Config{cc}) or return;
138
139 # $Config{cc} may contain args; try to find out the program part
140 while (@chunks) {
141 return can_run("@chunks") || (pop(@chunks), next);
142 }
143
144 return;
145}
146
147# check if we can run some command
148sub can_run {
149 my ($cmd) = @_;
150
151 return $cmd if -x $cmd;
152 if (my $found_cmd = MM->maybe_command($cmd)) {
153 return $found_cmd;
154 }
155
156 require File::Spec;
157 for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
158 next if $dir eq '';
159 my $abs = File::Spec->catfile($dir, $cmd);
160 return $abs if (-x $abs or $abs = MM->maybe_command($abs));
161 }
162
163 return;
164}
165
166# Can our C compiler environment build XS files
167sub can_xs {
168 # Do we have the configure_requires checker?
169 local $@;
170 eval "require ExtUtils::CBuilder; ExtUtils::CBuilder->VERSION(0.27)";
171 if ( $@ ) {
172 # They don't obey configure_requires, so it is
173 # someone old and delicate. Try to avoid hurting
174 # them by falling back to an older simpler test.
175 return can_cc();
176 }
177
178 # Do we have a working C compiler
179 my $builder = ExtUtils::CBuilder->new(
180 quiet => 1,
181 );
182 unless ( $builder->have_compiler ) {
183 # No working C compiler
184 return 0;
185 }
186
187 # Write a C file representative of what XS becomes
188 require File::Temp;
189 my ( $FH, $tmpfile ) = File::Temp::tempfile(
190 "compilexs-XXXXX",
191 SUFFIX => '.c',
192 );
193 binmode $FH;
194 print $FH <<'END_C';
195#include "EXTERN.h"
196#include "perl.h"
197#include "XSUB.h"
198
199int main(int argc, char **argv) {
200 return 0;
201}
202
203int boot_sanexs() {
204 return 1;
205}
206
207END_C
208 close $FH;
209
210 # Can the C compiler access the same headers XS does
211 my @libs = ();
212 my $object = undef;
213 eval {
214 local $^W = 0;
215 $object = $builder->compile(
216 source => $tmpfile,
217 );
218 @libs = $builder->link(
219 objects => $object,
220 module_name => 'sanexs',
221 );
222 };
223 my $result = $@ ? 0 : 1;
224
225 # Clean up all the build files
226 foreach ( $tmpfile, $object, @libs ) {
227 next unless defined $_;
228 1 while unlink;
229 }
230
231 return $result;
232}