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