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 },
14 # r/w: p5sagit@git.shadowcat.co.uk:JSON-MaybeXS.git
16 url => 'git://git.shadowcat.co.uk/p5sagit/JSON-MaybeXS.git',
17 web => 'http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit/JSON-MaybeXS.git',
21 mailto => 'bug-JSON-MaybeXS@rt.cpan.org',
22 web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=JSON-MaybeXS',
31 'ExtUtils::MakeMaker' => '0',
32 'ExtUtils::CBuilder' => '0.27',
39 'Scalar::Util' => '0',
41 'JSON::PP' => '2.27202',
42 # we may also add a runtime prereq for Cpanel::JSON::XS, on the
46 recommends => { 'Cpanel::JSON::XS' => '2.3310' },
50 'Test::Without::Module' => '0.17',
51 'Test::More' => '0.88',
58 my $eumm_version = eval $ExtUtils::MakeMaker::VERSION;
60 for (qw(configure build test runtime)) {
61 my $key = $_ eq 'runtime' ? 'PREREQ_PM' : uc $_.'_REQUIRES';
62 next unless exists $WriteMakefileArgs{META_ADD}{prereqs}{$_}
63 or exists $WriteMakefileArgs{$key};
64 my $r = $WriteMakefileArgs{$key} = {
65 %{$WriteMakefileArgs{META_ADD}{prereqs}{$_}{requires} || {}},
66 %{delete $WriteMakefileArgs{$key} || {}},
68 defined $r->{$_} or delete $r->{$_} for keys %$r;
71 # dynamic prereqs get added here.
73 # we require Cpanel::JSON::XS, except if JSON::XS is already installed.
74 # (we also always recommend Cpanel::JSON::XS, just to make sure.)
75 $WriteMakefileArgs{PREREQ_PM}{'Cpanel::JSON::XS'} = '2.3310'
76 if not parse_args()->{PUREPERL_ONLY}
77 and not eval { require JSON::XS; 1; }
80 $WriteMakefileArgs{MIN_PERL_VERSION} = delete $WriteMakefileArgs{PREREQ_PM}{perl} || 0;
82 die 'attention developer: you need to do a sane meta merge here!'
83 if keys %{$WriteMakefileArgs{BUILD_REQUIRES}};
85 $WriteMakefileArgs{BUILD_REQUIRES} = {
86 %{$WriteMakefileArgs{BUILD_REQUIRES} || {}},
87 %{delete $WriteMakefileArgs{TEST_REQUIRES}}
88 } if $eumm_version < 6.63_03;
90 $WriteMakefileArgs{PREREQ_PM} = {
91 %{$WriteMakefileArgs{PREREQ_PM}},
92 %{delete $WriteMakefileArgs{BUILD_REQUIRES}}
93 } if $eumm_version < 6.55_01;
95 delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
96 if $eumm_version < 6.51_03;
98 delete $WriteMakefileArgs{MIN_PERL_VERSION}
99 if $eumm_version < 6.48;
101 delete @WriteMakefileArgs{qw(META_ADD META_MERGE)}
102 if $eumm_version < 6.46;
104 delete $WriteMakefileArgs{LICENSE}
105 if $eumm_version < 6.31;
107 WriteMakefile(%WriteMakefileArgs);
112 require ExtUtils::MakeMaker;
113 require Text::ParseWords;
114 ExtUtils::MakeMaker::parse_args(
116 Text::ParseWords::shellwords($ENV{PERL_MM_OPT} || ''),
119 return $tmp->{ARGS} || {};
122 # can we locate a (the) C compiler
124 my @chunks = split(/ /, $Config::Config{cc}) or return;
126 # $Config{cc} may contain args; try to find out the program part
128 return can_run("@chunks") || (pop(@chunks), next);
134 # check if we can run some command
138 return $cmd if -x $cmd;
139 if (my $found_cmd = MM->maybe_command($cmd)) {
144 for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
146 my $abs = File::Spec->catfile($dir, $cmd);
147 return $abs if (-x $abs or $abs = MM->maybe_command($abs));
153 # Can our C compiler environment build XS files
155 # Do we have the configure_requires checker?
157 eval "require ExtUtils::CBuilder; ExtUtils::CBuilder->VERSION(0.27)";
159 # They don't obey configure_requires, so it is
160 # someone old and delicate. Try to avoid hurting
161 # them by falling back to an older simpler test.
165 # Do we have a working C compiler
166 my $builder = ExtUtils::CBuilder->new(
169 unless ( $builder->have_compiler ) {
170 # No working C compiler
174 # Write a C file representative of what XS becomes
176 my ( $FH, $tmpfile ) = File::Temp::tempfile(
186 int main(int argc, char **argv) {
197 # Can the C compiler access the same headers XS does
202 $object = $builder->compile(
205 @libs = $builder->link(
207 module_name => 'sanexs',
210 my $result = $@ ? 0 : 1;
212 # Clean up all the build files
213 foreach ( $tmpfile, $object, @libs ) {
214 next unless defined $_;