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