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