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