2 use warnings FATAL => 'all';
4 use ExtUtils::MakeMaker;
5 (do 'maint/Makefile.PL.include' or die $@) unless -f 'META.yml';
8 'Test::Without::Module' => '0.17',
12 # we require Cpanel::JSON::XS, except if JSON::XS is already installed we only
14 my $require_cpanel_json_xs = can_xs() && !eval { require JSON::XS; 1; };
17 NAME => 'JSON::MaybeXS',
18 VERSION_FROM => 'lib/JSON/MaybeXS.pm',
20 'JSON::PP' => '2.27202',
21 ($require_cpanel_json_xs
22 ? ('Cpanel::JSON::XS' => '2.3310')
26 BUILD_REQUIRES => \%BUILD_DEPS,
28 'meta-spec' => { version => 2 },
30 ($require_cpanel_json_xs
32 : (prereqs => { runtime => { recommends => { 'Cpanel::JSON::XS' => '2.3310' } } })),
36 # can we locate a (the) C compiler
38 my @chunks = split(/ /, $Config::Config{cc}) or return;
40 # $Config{cc} may contain args; try to find out the program part
42 return can_run("@chunks") || (pop(@chunks), next);
48 # check if we can run some command
52 return $cmd if -x $cmd;
53 if (my $found_cmd = MM->maybe_command($cmd)) {
58 for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
60 my $abs = File::Spec->catfile($dir, $cmd);
61 return $abs if (-x $abs or $abs = MM->maybe_command($abs));
67 # Can our C compiler environment build XS files
69 # Do we have the configure_requires checker?
71 eval "require ExtUtils::CBuilder; ExtUtils::CBuilder->VERSION(0.27)";
73 # They don't obey configure_requires, so it is
74 # someone old and delicate. Try to avoid hurting
75 # them by falling back to an older simpler test.
79 # Do we have a working C compiler
80 my $builder = ExtUtils::CBuilder->new(
83 unless ( $builder->have_compiler ) {
84 # No working C compiler
88 # Write a C file representative of what XS becomes
90 my ( $FH, $tmpfile ) = File::Temp::tempfile(
100 int main(int argc, char **argv) {
111 # Can the C compiler access the same headers XS does
116 $object = $builder->compile(
119 @libs = $builder->link(
121 module_name => 'sanexs',
124 my $result = $@ ? 0 : 1;
126 # Clean up all the build files
127 foreach ( $tmpfile, $object, @libs ) {
128 next unless defined $_;