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