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')
21 CONFIGURE_REQUIRES => {
22 'ExtUtils::CBuilder' => '0.27',
27 'Test::Without::Module' => '0.17',
28 'Test::More' => '0.88'
32 'meta-spec' => { version => 2 },
34 prereqs => { runtime => { recommends => { 'Cpanel::JSON::XS' => '2.3310' } } },
38 url => 'https://github.com/karenetheridge/JSON-MaybeXS.git',
39 web => 'https://github.com/karenetheridge/JSON-MaybeXS',
43 mailto => 'bug-JSON-MaybeXS@rt.cpan.org',
44 web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=JSON-MaybeXS',
49 realclean => { FILES => 'Distar/' },
52 my $eumm_version = eval $ExtUtils::MakeMaker::VERSION;
53 $WriteMakefileArgs{MIN_PERL_VERSION} = delete $WriteMakefileArgs{PREREQ_PM}{perl} || 0;
55 $WriteMakefileArgs{BUILD_REQUIRES} = {
56 %{$WriteMakefileArgs{BUILD_REQUIRES} || {}},
57 %{delete $WriteMakefileArgs{TEST_REQUIRES}}
58 } if $eumm_version < 6.63_03;
60 $WriteMakefileArgs{PREREQ_PM} = {
61 %{$WriteMakefileArgs{PREREQ_PM}},
62 %{delete $WriteMakefileArgs{BUILD_REQUIRES}}
63 } if $eumm_version < 6.55_01;
65 delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
66 if $eumm_version < 6.51_03;
68 WriteMakefile(%WriteMakefileArgs);
70 # can we locate a (the) C compiler
72 my @chunks = split(/ /, $Config::Config{cc}) or return;
74 # $Config{cc} may contain args; try to find out the program part
76 return can_run("@chunks") || (pop(@chunks), next);
82 # check if we can run some command
86 return $cmd if -x $cmd;
87 if (my $found_cmd = MM->maybe_command($cmd)) {
92 for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
94 my $abs = File::Spec->catfile($dir, $cmd);
95 return $abs if (-x $abs or $abs = MM->maybe_command($abs));
101 # Can our C compiler environment build XS files
103 # Do we have the configure_requires checker?
105 eval "require ExtUtils::CBuilder; ExtUtils::CBuilder->VERSION(0.27)";
107 # They don't obey configure_requires, so it is
108 # someone old and delicate. Try to avoid hurting
109 # them by falling back to an older simpler test.
113 # Do we have a working C compiler
114 my $builder = ExtUtils::CBuilder->new(
117 unless ( $builder->have_compiler ) {
118 # No working C compiler
122 # Write a C file representative of what XS becomes
124 my ( $FH, $tmpfile ) = File::Temp::tempfile(
134 int main(int argc, char **argv) {
145 # Can the C compiler access the same headers XS does
150 $object = $builder->compile(
153 @libs = $builder->link(
155 module_name => 'sanexs',
158 my $result = $@ ? 0 : 1;
160 # Clean up all the build files
161 foreach ( $tmpfile, $object, @libs ) {
162 next unless defined $_;