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