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