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',
39 'JSON::PP' => '2.27202',
40 # we may also add a runtime prereq for Cpanel::JSON::XS, on the
44 recommends => { 'Cpanel::JSON::XS' => '2.3310' },
48 'Test::Without::Module' => '0.17',
49 'Test::More' => '0.88',
56 my $eumm_version = eval $ExtUtils::MakeMaker::VERSION;
58 for (qw(configure build test runtime)) {
59 my $key = $_ eq 'runtime' ? 'PREREQ_PM' : uc $_.'_REQUIRES';
60 next unless exists $WriteMakefileArgs{META_ADD}{prereqs}{$_}
61 or exists $WriteMakefileArgs{$key};
62 my $r = $WriteMakefileArgs{$key} = {
63 %{$WriteMakefileArgs{META_ADD}{prereqs}{$_}{requires} || {}},
64 %{delete $WriteMakefileArgs{$key} || {}},
66 defined $r->{$_} or delete $r->{$_} for keys %$r;
69 # dynamic prereqs get added here.
71 # we require Cpanel::JSON::XS, except if JSON::XS is already installed.
72 # (we also always recommend Cpanel::JSON::XS, just to make sure.)
73 $WriteMakefileArgs{PREREQ_PM}{'Cpanel::JSON::XS'} = '2.3310'
74 if not parse_args()->{PUREPERL_ONLY}
75 and not eval { require JSON::XS; 1; }
78 $WriteMakefileArgs{MIN_PERL_VERSION} = delete $WriteMakefileArgs{PREREQ_PM}{perl} || 0;
80 die 'attention developer: you need to do a sane meta merge here!'
81 if keys %{$WriteMakefileArgs{BUILD_REQUIRES}};
83 $WriteMakefileArgs{BUILD_REQUIRES} = {
84 %{$WriteMakefileArgs{BUILD_REQUIRES} || {}},
85 %{delete $WriteMakefileArgs{TEST_REQUIRES}}
86 } if $eumm_version < 6.63_03;
88 $WriteMakefileArgs{PREREQ_PM} = {
89 %{$WriteMakefileArgs{PREREQ_PM}},
90 %{delete $WriteMakefileArgs{BUILD_REQUIRES}}
91 } if $eumm_version < 6.55_01;
93 delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
94 if $eumm_version < 6.51_03;
96 delete $WriteMakefileArgs{MIN_PERL_VERSION}
97 if $eumm_version < 6.48;
99 delete @WriteMakefileArgs{qw(META_ADD META_MERGE)}
100 if $eumm_version < 6.46;
102 delete $WriteMakefileArgs{LICENSE}
103 if $eumm_version < 6.31;
105 WriteMakefile(%WriteMakefileArgs);
110 require ExtUtils::MakeMaker;
111 require Text::ParseWords;
112 ExtUtils::MakeMaker::parse_args(
114 Text::ParseWords::shellwords($ENV{PERL_MM_OPT} || ''),
117 return $tmp->{ARGS} || {};
120 # can we locate a (the) C compiler
122 my @chunks = split(/ /, $Config::Config{cc}) or return;
124 # $Config{cc} may contain args; try to find out the program part
126 return can_run("@chunks") || (pop(@chunks), next);
132 # check if we can run some command
136 return $cmd if -x $cmd;
137 if (my $found_cmd = MM->maybe_command($cmd)) {
142 for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
144 my $abs = File::Spec->catfile($dir, $cmd);
145 return $abs if (-x $abs or $abs = MM->maybe_command($abs));
151 # Can our C compiler environment build XS files
153 # Do we have the configure_requires checker?
155 eval "require ExtUtils::CBuilder; ExtUtils::CBuilder->VERSION(0.27)";
157 # They don't obey configure_requires, so it is
158 # someone old and delicate. Try to avoid hurting
159 # them by falling back to an older simpler test.
163 # Do we have a working C compiler
164 my $builder = ExtUtils::CBuilder->new(
167 unless ( $builder->have_compiler ) {
168 # No working C compiler
172 # Write a C file representative of what XS becomes
174 my ( $FH, $tmpfile ) = File::Temp::tempfile(
184 int main(int argc, char **argv) {
195 # Can the C compiler access the same headers XS does
200 $object = $builder->compile(
203 @libs = $builder->link(
205 module_name => 'sanexs',
208 my $result = $@ ? 0 : 1;
210 # Clean up all the build files
211 foreach ( $tmpfile, $object, @libs ) {
212 next unless defined $_;