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 -n
26 'Clinton Gormley <develop@traveljury.com>',
27 'Graham Knop <haarg@haarg.org>',
28 'John SJ Anderson <genehack@genehack.org>',
29 'Karen Etheridge <ether@cpan.org>',
30 'Kieren Diment <diment@gmail.com>',
31 'Matt S Trout <mst@shadowcat.co.uk>',
39 'ExtUtils::MakeMaker' => '0',
40 'ExtUtils::CBuilder' => '0.27',
47 'Scalar::Util' => '0',
49 'JSON::PP' => '2.27300',
50 # we may also add a runtime prereq for Cpanel::JSON::XS, on the
54 recommends => { 'Cpanel::JSON::XS' => '2.3310' },
58 'Test::Without::Module' => '0.17',
59 'Test::More' => '0.88',
66 my $eumm_version = eval $ExtUtils::MakeMaker::VERSION;
68 for (qw(configure build test runtime)) {
69 my $key = $_ eq 'runtime' ? 'PREREQ_PM' : uc $_.'_REQUIRES';
70 next unless exists $WriteMakefileArgs{META_ADD}{prereqs}{$_}
71 or exists $WriteMakefileArgs{$key};
72 my $r = $WriteMakefileArgs{$key} = {
73 %{$WriteMakefileArgs{META_ADD}{prereqs}{$_}{requires} || {}},
74 %{delete $WriteMakefileArgs{$key} || {}},
76 defined $r->{$_} or delete $r->{$_} for keys %$r;
79 # dynamic prereqs get added here.
81 my $args = parse_args();
83 # we require Cpanel::JSON::XS, except if JSON::XS is already installed.
84 # (we also always recommend Cpanel::JSON::XS, just to make sure.)
85 $WriteMakefileArgs{PREREQ_PM}{'Cpanel::JSON::XS'} = '2.3310'
86 if not $args->{PUREPERL_ONLY}
87 and ((eval { require Cpanel::JSON::XS; 1 } and not eval { Cpanel::JSON::XS->VERSION('2.3310'); 1 })
88 or (not eval { require JSON::XS; 1; } and can_xs()));
90 # avoid "JSON::XS::Boolean::* redefined" warnings caused by incompatibilities
91 # between JSON::XS 2.x and 3.0 --
92 # if JSON::XS is installed and < 3.0
93 # and Cpanel::JSON::JSON is (or is about to be) >= 3.0,
94 # then update JSON::XS to eliminate the incompatibility
95 $WriteMakefileArgs{PREREQ_PM}{'JSON::XS'} = '3.00'
96 if not $args->{PUREPERL_ONLY}
97 and eval { require JSON::XS; 1 } and not eval { JSON::XS->VERSION('3.0'); 1 }
98 and (eval { require Cpanel::JSON::XS; Cpanel::JSON::XS->VERSION('3.0'); 1 }
99 # we presume here that if we are installing Cpanel::JSON::XS, we
100 # are installing the latest version
101 or exists $WriteMakefileArgs{PREREQ_PM}{'Cpanel::JSON::XS'});
103 $WriteMakefileArgs{MIN_PERL_VERSION} = delete $WriteMakefileArgs{PREREQ_PM}{perl} || 0;
105 die 'attention developer: you need to do a sane meta merge here!'
106 if keys %{$WriteMakefileArgs{BUILD_REQUIRES}};
108 $WriteMakefileArgs{BUILD_REQUIRES} = {
109 %{$WriteMakefileArgs{BUILD_REQUIRES} || {}},
110 %{delete $WriteMakefileArgs{TEST_REQUIRES}}
111 } if $eumm_version < 6.63_03;
113 $WriteMakefileArgs{PREREQ_PM} = {
114 %{$WriteMakefileArgs{PREREQ_PM}},
115 %{delete $WriteMakefileArgs{BUILD_REQUIRES}}
116 } if $eumm_version < 6.55_01;
118 delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
119 if $eumm_version < 6.51_03;
121 delete $WriteMakefileArgs{MIN_PERL_VERSION}
122 if $eumm_version < 6.48;
124 delete @WriteMakefileArgs{qw(META_ADD META_MERGE)}
125 if $eumm_version < 6.46;
127 delete $WriteMakefileArgs{LICENSE}
128 if $eumm_version < 6.31;
130 WriteMakefile(%WriteMakefileArgs);
135 require ExtUtils::MakeMaker;
136 require Text::ParseWords;
137 ExtUtils::MakeMaker::parse_args(
139 Text::ParseWords::shellwords($ENV{PERL_MM_OPT} || ''),
142 return $tmp->{ARGS} || {};
145 # can we locate a (the) C compiler
147 my @chunks = split(/ /, $Config::Config{cc}) or return;
149 # $Config{cc} may contain args; try to find out the program part
151 return can_run("@chunks") || (pop(@chunks), next);
157 # check if we can run some command
161 return $cmd if -x $cmd;
162 if (my $found_cmd = MM->maybe_command($cmd)) {
167 for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
169 my $abs = File::Spec->catfile($dir, $cmd);
170 return $abs if (-x $abs or $abs = MM->maybe_command($abs));
176 # Can our C compiler environment build XS files
178 # Do we have the configure_requires checker?
180 eval "require ExtUtils::CBuilder; ExtUtils::CBuilder->VERSION(0.27)";
182 # They don't obey configure_requires, so it is
183 # someone old and delicate. Try to avoid hurting
184 # them by falling back to an older simpler test.
188 # Do we have a working C compiler
189 my $builder = ExtUtils::CBuilder->new(
192 unless ( $builder->have_compiler ) {
193 # No working C compiler
197 # Write a C file representative of what XS becomes
199 my ( $FH, $tmpfile ) = File::Temp::tempfile(
209 int main(int argc, char **argv) {
220 # Can the C compiler access the same headers XS does
225 $object = $builder->compile(
228 @libs = $builder->link(
230 module_name => 'sanexs',
233 my $result = $@ ? 0 : 1;
235 # Clean up all the build files
236 foreach ( $tmpfile, $object, @libs ) {
237 next unless defined $_;