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' } } })),
35 realclean => { FILES => 'Distar/' },
38 # can we locate a (the) C compiler
40 my @chunks = split(/ /, $Config::Config{cc}) or return;
42 # $Config{cc} may contain args; try to find out the program part
44 return can_run("@chunks") || (pop(@chunks), next);
50 # check if we can run some command
54 return $cmd if -x $cmd;
55 if (my $found_cmd = MM->maybe_command($cmd)) {
60 for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
62 my $abs = File::Spec->catfile($dir, $cmd);
63 return $abs if (-x $abs or $abs = MM->maybe_command($abs));
69 # Can our C compiler environment build XS files
71 # Do we have the configure_requires checker?
73 eval "require ExtUtils::CBuilder; ExtUtils::CBuilder->VERSION(0.27)";
75 # They don't obey configure_requires, so it is
76 # someone old and delicate. Try to avoid hurting
77 # them by falling back to an older simpler test.
81 # Do we have a working C compiler
82 my $builder = ExtUtils::CBuilder->new(
85 unless ( $builder->have_compiler ) {
86 # No working C compiler
90 # Write a C file representative of what XS becomes
92 my ( $FH, $tmpfile ) = File::Temp::tempfile(
102 int main(int argc, char **argv) {
113 # Can the C compiler access the same headers XS does
118 $object = $builder->compile(
121 @libs = $builder->link(
123 module_name => 'sanexs',
126 my $result = $@ ? 0 : 1;
128 # Clean up all the build files
129 foreach ( $tmpfile, $object, @libs ) {
130 next unless defined $_;