2 use warnings FATAL => 'all';
3 use ExtUtils::MakeMaker;
4 (do 'maint/Makefile.PL.include' or die $@) unless -f 'META.yml';
6 my %WriteMakefileArgs = (
7 NAME => 'JSON::MaybeXS',
8 VERSION_FROM => 'lib/JSON/MaybeXS.pm',
11 'meta-spec' => { version => 2 },
14 # r/w: p5sagit@git.shadowcat.co.uk:JSON-MaybeXS.git
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',
21 mailto => 'bug-JSON-MaybeXS@rt.cpan.org',
22 web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=JSON-MaybeXS',
25 x_contributors => { # manually added, from git shortlog -e -s
26 'Clinton Gormley <develop@traveljury.com>',
27 'Graham Knop <haarg@haarg.org>',
28 'Karen Etheridge <ether@cpan.org>',
29 'Kieren Diment <diment@gmail.com>',
30 'Matt S Trout <mst@shadowcat.co.uk>',
38 'ExtUtils::MakeMaker' => '0',
39 'ExtUtils::CBuilder' => '0.27',
46 'Scalar::Util' => '0',
48 'JSON::PP' => '2.27202',
49 # we may also add a runtime prereq for Cpanel::JSON::XS, on the
53 recommends => { 'Cpanel::JSON::XS' => '2.3310' },
57 'Test::Without::Module' => '0.17',
58 'Test::More' => '0.88',
65 my $eumm_version = eval $ExtUtils::MakeMaker::VERSION;
67 for (qw(configure build test runtime)) {
68 my $key = $_ eq 'runtime' ? 'PREREQ_PM' : uc $_.'_REQUIRES';
69 next unless exists $WriteMakefileArgs{META_ADD}{prereqs}{$_}
70 or exists $WriteMakefileArgs{$key};
71 my $r = $WriteMakefileArgs{$key} = {
72 %{$WriteMakefileArgs{META_ADD}{prereqs}{$_}{requires} || {}},
73 %{delete $WriteMakefileArgs{$key} || {}},
75 defined $r->{$_} or delete $r->{$_} for keys %$r;
78 # dynamic prereqs get added here.
80 # we require Cpanel::JSON::XS, except if JSON::XS is already installed.
81 # (we also always recommend Cpanel::JSON::XS, just to make sure.)
82 $WriteMakefileArgs{PREREQ_PM}{'Cpanel::JSON::XS'} = '2.3310'
83 if not parse_args()->{PUREPERL_ONLY}
84 and ((eval { require Cpanel::JSON::XS; 1 } and not eval { Cpanel::JSON::XS->VERSION('2.3310'); 1 })
85 or (not eval { require JSON::XS; 1; } and can_xs()));
87 # avoid "JSON::XS::Boolean::* redefined" warnings caused by incompatibilities
88 # between JSON::XS 2.x and 3.0 --
89 # if JSON::XS is installed and < 3.0
90 # and Cpanel::JSON::JSON is (or is about to be) >= 3.0,
91 # then update JSON::XS to eliminate the incompatibility
92 $WriteMakefileArgs{PREREQ_PM}{'JSON::XS'} = '3.00'
93 if not parse_args()->{PUREPERL_ONLY}
94 and eval { require JSON::XS; 1 } and not eval { JSON::XS->VERSION('3.0'); 1 }
95 and (eval { require Cpanel::JSON::XS; Cpanel::JSON::XS->VERSION('3.0'); 1 }
96 # we presume here that if we are installing Cpanel::JSON::XS, we
97 # are installing the latest version
98 or exists $WriteMakefileArgs{PREREQ_PM}{'Cpanel::JSON::XS'});
100 $WriteMakefileArgs{MIN_PERL_VERSION} = delete $WriteMakefileArgs{PREREQ_PM}{perl} || 0;
102 die 'attention developer: you need to do a sane meta merge here!'
103 if keys %{$WriteMakefileArgs{BUILD_REQUIRES}};
105 $WriteMakefileArgs{BUILD_REQUIRES} = {
106 %{$WriteMakefileArgs{BUILD_REQUIRES} || {}},
107 %{delete $WriteMakefileArgs{TEST_REQUIRES}}
108 } if $eumm_version < 6.63_03;
110 $WriteMakefileArgs{PREREQ_PM} = {
111 %{$WriteMakefileArgs{PREREQ_PM}},
112 %{delete $WriteMakefileArgs{BUILD_REQUIRES}}
113 } if $eumm_version < 6.55_01;
115 delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
116 if $eumm_version < 6.51_03;
118 delete $WriteMakefileArgs{MIN_PERL_VERSION}
119 if $eumm_version < 6.48;
121 delete @WriteMakefileArgs{qw(META_ADD META_MERGE)}
122 if $eumm_version < 6.46;
124 delete $WriteMakefileArgs{LICENSE}
125 if $eumm_version < 6.31;
127 WriteMakefile(%WriteMakefileArgs);
132 require ExtUtils::MakeMaker;
133 require Text::ParseWords;
134 ExtUtils::MakeMaker::parse_args(
136 Text::ParseWords::shellwords($ENV{PERL_MM_OPT} || ''),
139 return $tmp->{ARGS} || {};
142 # can we locate a (the) C compiler
144 my @chunks = split(/ /, $Config::Config{cc}) or return;
146 # $Config{cc} may contain args; try to find out the program part
148 return can_run("@chunks") || (pop(@chunks), next);
154 # check if we can run some command
158 return $cmd if -x $cmd;
159 if (my $found_cmd = MM->maybe_command($cmd)) {
164 for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
166 my $abs = File::Spec->catfile($dir, $cmd);
167 return $abs if (-x $abs or $abs = MM->maybe_command($abs));
173 # Can our C compiler environment build XS files
175 # Do we have the configure_requires checker?
177 eval "require ExtUtils::CBuilder; ExtUtils::CBuilder->VERSION(0.27)";
179 # They don't obey configure_requires, so it is
180 # someone old and delicate. Try to avoid hurting
181 # them by falling back to an older simpler test.
185 # Do we have a working C compiler
186 my $builder = ExtUtils::CBuilder->new(
189 unless ( $builder->have_compiler ) {
190 # No working C compiler
194 # Write a C file representative of what XS becomes
196 my ( $FH, $tmpfile ) = File::Temp::tempfile(
206 int main(int argc, char **argv) {
217 # Can the C compiler access the same headers XS does
222 $object = $builder->compile(
225 @libs = $builder->link(
227 module_name => 'sanexs',
230 my $result = $@ ? 0 : 1;
232 # Clean up all the build files
233 foreach ( $tmpfile, $object, @libs ) {
234 next unless defined $_;