2 use warnings FATAL => 'all';
4 use ExtUtils::MakeMaker;
5 (do 'maint/Makefile.PL.include' or die $@) unless -f 'META.yml';
7 # we require Cpanel::JSON::XS, except if JSON::XS is already installed.
8 # (we also always recommend Cpanel::JSON::XS, just to make sure.)
9 my $require_cpanel_json_xs = can_xs() && !eval { require JSON::XS; 1; };
11 my %WriteMakefileArgs = (
12 NAME => 'JSON::MaybeXS',
13 VERSION_FROM => 'lib/JSON/MaybeXS.pm',
15 'JSON::PP' => '2.27202',
16 ($require_cpanel_json_xs
17 ? ('Cpanel::JSON::XS' => '2.3310')
22 'Test::Without::Module' => '0.17',
23 'Test::More' => '0.88'
27 'meta-spec' => { version => 2 },
29 prereqs => { runtime => { recommends => { 'Cpanel::JSON::XS' => '2.3310' } } },
33 url => 'https://github.com/karenetheridge/JSON-MaybeXS.git',
34 web => 'https://github.com/karenetheridge/JSON-MaybeXS',
38 mailto => 'bug-JSON-MaybeXS@rt.cpan.org',
39 web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=JSON-MaybeXS',
44 realclean => { FILES => 'Distar/' },
47 my $eumm_version = eval $ExtUtils::MakeMaker::VERSION;
48 $WriteMakefileArgs{MIN_PERL_VERSION} = delete $WriteMakefileArgs{PREREQ_PM}{perl} || 0;
49 $WriteMakefileArgs{BUILD_REQUIRES} = {
50 %{$WriteMakefileArgs{BUILD_REQUIRES} || {}},
51 %{delete $WriteMakefileArgs{TEST_REQUIRES}}
52 } if $eumm_version < 6.63_03;
53 $WriteMakefileArgs{PREREQ_PM} = {
54 %{$WriteMakefileArgs{PREREQ_PM}},
55 %{delete $WriteMakefileArgs{BUILD_REQUIRES}}
56 } if $eumm_version < 6.55_01;
58 WriteMakefile(%WriteMakefileArgs);
60 # can we locate a (the) C compiler
62 my @chunks = split(/ /, $Config::Config{cc}) or return;
64 # $Config{cc} may contain args; try to find out the program part
66 return can_run("@chunks") || (pop(@chunks), next);
72 # check if we can run some command
76 return $cmd if -x $cmd;
77 if (my $found_cmd = MM->maybe_command($cmd)) {
82 for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
84 my $abs = File::Spec->catfile($dir, $cmd);
85 return $abs if (-x $abs or $abs = MM->maybe_command($abs));
91 # Can our C compiler environment build XS files
93 # Do we have the configure_requires checker?
95 eval "require ExtUtils::CBuilder; ExtUtils::CBuilder->VERSION(0.27)";
97 # They don't obey configure_requires, so it is
98 # someone old and delicate. Try to avoid hurting
99 # them by falling back to an older simpler test.
103 # Do we have a working C compiler
104 my $builder = ExtUtils::CBuilder->new(
107 unless ( $builder->have_compiler ) {
108 # No working C compiler
112 # Write a C file representative of what XS becomes
114 my ( $FH, $tmpfile ) = File::Temp::tempfile(
124 int main(int argc, char **argv) {
135 # Can the C compiler access the same headers XS does
140 $object = $builder->compile(
143 @libs = $builder->link(
145 module_name => 'sanexs',
148 my $result = $@ ? 0 : 1;
150 # Clean up all the build files
151 foreach ( $tmpfile, $object, @libs ) {
152 next unless defined $_;