2 use warnings FATAL => 'all';
4 use ExtUtils::MakeMaker;
5 (do 'maint/Makefile.PL.include' or die $@) unless -f 'META.yml';
7 my %WriteMakefileArgs = (
8 NAME => 'JSON::MaybeXS',
9 VERSION_FROM => 'lib/JSON/MaybeXS.pm',
11 'meta-spec' => { version => 2 },
16 'ExtUtils::MakeMaker' => '0',
17 'ExtUtils::CBuilder' => '0.27',
24 'JSON::PP' => '2.27202',
25 # we may also add a runtime prereq for Cpanel::JSON::XS, on the
29 recommends => { 'Cpanel::JSON::XS' => '2.3310' },
33 'Test::Without::Module' => '0.17',
34 'Test::More' => '0.88',
41 url => 'https://github.com/karenetheridge/JSON-MaybeXS.git',
42 web => 'https://github.com/karenetheridge/JSON-MaybeXS',
46 mailto => 'bug-JSON-MaybeXS@rt.cpan.org',
47 web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=JSON-MaybeXS',
52 realclean => { FILES => [ 'Distar/', 'MANIFEST*' ] },
55 my $eumm_version = eval $ExtUtils::MakeMaker::VERSION;
57 for (qw(configure build test runtime)) {
58 my $key = $_ eq 'runtime' ? 'PREREQ_PM' : uc $_.'_REQUIRES';
59 next unless exists $WriteMakefileArgs{META_ADD}{prereqs}{$_}
60 or exists $WriteMakefileArgs{$key};
61 my $r = $WriteMakefileArgs{$key} = {
62 %{$WriteMakefileArgs{META_ADD}{prereqs}{$_}{requires} || {}},
63 %{delete $WriteMakefileArgs{$key} || {}},
65 defined $r->{$_} or delete $r->{$_} for keys %$r;
68 # we require Cpanel::JSON::XS, except if JSON::XS is already installed.
69 # (we also always recommend Cpanel::JSON::XS, just to make sure.)
70 $WriteMakefileArgs{PREREQ_PM}{'Cpanel::JSON::XS'} = '2.3310'
71 if can_xs() && !eval { require JSON::XS; 1; };
73 $WriteMakefileArgs{MIN_PERL_VERSION} = delete $WriteMakefileArgs{PREREQ_PM}{perl} || 0;
75 $WriteMakefileArgs{BUILD_REQUIRES} = {
76 %{$WriteMakefileArgs{BUILD_REQUIRES} || {}},
77 %{delete $WriteMakefileArgs{TEST_REQUIRES}}
78 } if $eumm_version < 6.63_03;
80 $WriteMakefileArgs{PREREQ_PM} = {
81 %{$WriteMakefileArgs{PREREQ_PM}},
82 %{delete $WriteMakefileArgs{BUILD_REQUIRES}}
83 } if $eumm_version < 6.55_01;
85 delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
86 if $eumm_version < 6.51_03;
88 WriteMakefile(%WriteMakefileArgs);
90 # can we locate a (the) C compiler
92 my @chunks = split(/ /, $Config::Config{cc}) or return;
94 # $Config{cc} may contain args; try to find out the program part
96 return can_run("@chunks") || (pop(@chunks), next);
102 # check if we can run some command
106 return $cmd if -x $cmd;
107 if (my $found_cmd = MM->maybe_command($cmd)) {
112 for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
114 my $abs = File::Spec->catfile($dir, $cmd);
115 return $abs if (-x $abs or $abs = MM->maybe_command($abs));
121 # Can our C compiler environment build XS files
123 # Do we have the configure_requires checker?
125 eval "require ExtUtils::CBuilder; ExtUtils::CBuilder->VERSION(0.27)";
127 # They don't obey configure_requires, so it is
128 # someone old and delicate. Try to avoid hurting
129 # them by falling back to an older simpler test.
133 # Do we have a working C compiler
134 my $builder = ExtUtils::CBuilder->new(
137 unless ( $builder->have_compiler ) {
138 # No working C compiler
142 # Write a C file representative of what XS becomes
144 my ( $FH, $tmpfile ) = File::Temp::tempfile(
154 int main(int argc, char **argv) {
165 # Can the C compiler access the same headers XS does
170 $object = $builder->compile(
173 @libs = $builder->link(
175 module_name => 'sanexs',
178 my $result = $@ ? 0 : 1;
180 # Clean up all the build files
181 foreach ( $tmpfile, $object, @libs ) {
182 next unless defined $_;