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