2 use warnings FATAL => 'all';
3 use ExtUtils::MakeMaker;
4 (do 'maint/Makefile.PL.include' or die $@) unless -f 'META.yml';
6 my %WriteMakefileArgs = (
7 NAME => 'JSON::MaybeXS',
8 VERSION_FROM => 'lib/JSON/MaybeXS.pm',
11 'meta-spec' => { version => 2 },
15 url => 'https://github.com/karenetheridge/JSON-MaybeXS.git',
16 web => 'https://github.com/karenetheridge/JSON-MaybeXS',
20 mailto => 'bug-JSON-MaybeXS@rt.cpan.org',
21 web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=JSON-MaybeXS',
30 'ExtUtils::MakeMaker' => '0',
31 'ExtUtils::CBuilder' => '0.27',
38 'JSON::PP' => '2.27202',
39 # we may also add a runtime prereq for Cpanel::JSON::XS, on the
43 recommends => { 'Cpanel::JSON::XS' => '2.3310' },
47 'Test::Without::Module' => '0.17',
48 'Test::More' => '0.88',
54 realclean => { FILES => [ 'Distar/', 'MANIFEST*' ] },
57 my $eumm_version = eval $ExtUtils::MakeMaker::VERSION;
59 for (qw(configure build test runtime)) {
60 my $key = $_ eq 'runtime' ? 'PREREQ_PM' : uc $_.'_REQUIRES';
61 next unless exists $WriteMakefileArgs{META_ADD}{prereqs}{$_}
62 or exists $WriteMakefileArgs{$key};
63 my $r = $WriteMakefileArgs{$key} = {
64 %{$WriteMakefileArgs{META_ADD}{prereqs}{$_}{requires} || {}},
65 %{delete $WriteMakefileArgs{$key} || {}},
67 defined $r->{$_} or delete $r->{$_} for keys %$r;
70 # we require Cpanel::JSON::XS, except if JSON::XS is already installed.
71 # (we also always recommend Cpanel::JSON::XS, just to make sure.)
72 $WriteMakefileArgs{PREREQ_PM}{'Cpanel::JSON::XS'} = '2.3310'
73 if can_xs() && !eval { require JSON::XS; 1; };
75 $WriteMakefileArgs{MIN_PERL_VERSION} = delete $WriteMakefileArgs{PREREQ_PM}{perl} || 0;
77 $WriteMakefileArgs{BUILD_REQUIRES} = {
78 %{$WriteMakefileArgs{BUILD_REQUIRES} || {}},
79 %{delete $WriteMakefileArgs{TEST_REQUIRES}}
80 } if $eumm_version < 6.63_03;
82 $WriteMakefileArgs{PREREQ_PM} = {
83 %{$WriteMakefileArgs{PREREQ_PM}},
84 %{delete $WriteMakefileArgs{BUILD_REQUIRES}}
85 } if $eumm_version < 6.55_01;
87 delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
88 if $eumm_version < 6.51_03;
90 delete $WriteMakefileArgs{MIN_PERL_VERSION}
91 if $eumm_version < 6.48;
93 delete @WriteMakefileArgs{qw(META_ADD META_MERGE)}
94 if $eumm_version < 6.46;
96 delete $WriteMakefileArgs{LICENSE}
97 if $eumm_version < 6.31;
99 WriteMakefile(%WriteMakefileArgs);
101 # can we locate a (the) C compiler
103 my @chunks = split(/ /, $Config::Config{cc}) or return;
105 # $Config{cc} may contain args; try to find out the program part
107 return can_run("@chunks") || (pop(@chunks), next);
113 # check if we can run some command
117 return $cmd if -x $cmd;
118 if (my $found_cmd = MM->maybe_command($cmd)) {
123 for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
125 my $abs = File::Spec->catfile($dir, $cmd);
126 return $abs if (-x $abs or $abs = MM->maybe_command($abs));
132 # Can our C compiler environment build XS files
134 # Do we have the configure_requires checker?
136 eval "require ExtUtils::CBuilder; ExtUtils::CBuilder->VERSION(0.27)";
138 # They don't obey configure_requires, so it is
139 # someone old and delicate. Try to avoid hurting
140 # them by falling back to an older simpler test.
144 # Do we have a working C compiler
145 my $builder = ExtUtils::CBuilder->new(
148 unless ( $builder->have_compiler ) {
149 # No working C compiler
153 # Write a C file representative of what XS becomes
155 my ( $FH, $tmpfile ) = File::Temp::tempfile(
165 int main(int argc, char **argv) {
176 # Can the C compiler access the same headers XS does
181 $object = $builder->compile(
184 @libs = $builder->link(
186 module_name => 'sanexs',
189 my $result = $@ ? 0 : 1;
191 # Clean up all the build files
192 foreach ( $tmpfile, $object, @libs ) {
193 next unless defined $_;