Commit | Line | Data |
44459f01 |
1 | use strict; |
2 | use warnings FATAL => 'all'; |
3 | use 5.008001; |
4 | use ExtUtils::MakeMaker; |
5 | (do 'maint/Makefile.PL.include' or die $@) unless -f 'META.yml'; |
6 | |
8abc9d15 |
7 | my %BUILD_DEPS = ( |
8 | 'Test::Without::Module' => '0.17', |
9 | 'Test::More' => '0.88' |
10 | ); |
11 | |
8b945fac |
12 | # we require Cpanel::JSON::XS, except if JSON::XS is already installed we only |
13 | # reocmmend it. |
14 | my $require_cpanel_json_xs = can_xs() && !eval { require JSON::XS; 1; }; |
15 | |
44459f01 |
16 | WriteMakefile( |
17 | NAME => 'JSON::MaybeXS', |
18 | VERSION_FROM => 'lib/JSON/MaybeXS.pm', |
19 | PREREQ_PM => { |
20 | 'JSON::PP' => '2.27202', |
8b945fac |
21 | ($require_cpanel_json_xs |
44459f01 |
22 | ? ('Cpanel::JSON::XS' => '2.3310') |
8abc9d15 |
23 | : ()), |
24 | %BUILD_DEPS, |
44459f01 |
25 | }, |
8abc9d15 |
26 | BUILD_REQUIRES => \%BUILD_DEPS, |
8b945fac |
27 | META_MERGE => { |
28 | 'meta-spec' => { version => 2 }, |
29 | dynamic_config => 1, |
30 | ($require_cpanel_json_xs |
31 | ? () |
32 | : (prereqs => { runtime => { recommends => { 'Cpanel::JSON::XS' => '2.3310' } } })), |
7d822c70 |
33 | |
34 | resources => { |
35 | repository => { |
36 | url => 'https://github.com/karenetheridge/JSON-MaybeXS.git', |
37 | web => 'https://github.com/karenetheridge/JSON-MaybeXS', |
38 | type => 'git', |
39 | }, |
40 | bugtracker => { |
41 | mailto => 'bug-JSON-MaybeXS@rt.cpan.org', |
42 | web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=JSON-MaybeXS', |
43 | }, |
44 | }, |
8b945fac |
45 | }, |
a0a593bd |
46 | |
47 | realclean => { FILES => 'Distar/' }, |
44459f01 |
48 | ); |
49 | |
50 | # can we locate a (the) C compiler |
51 | sub can_cc { |
52 | my @chunks = split(/ /, $Config::Config{cc}) or return; |
53 | |
54 | # $Config{cc} may contain args; try to find out the program part |
55 | while (@chunks) { |
56 | return can_run("@chunks") || (pop(@chunks), next); |
57 | } |
58 | |
59 | return; |
60 | } |
61 | |
62 | # check if we can run some command |
63 | sub can_run { |
64 | my ($cmd) = @_; |
65 | |
66 | return $cmd if -x $cmd; |
67 | if (my $found_cmd = MM->maybe_command($cmd)) { |
68 | return $found_cmd; |
69 | } |
70 | |
71 | require File::Spec; |
72 | for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') { |
73 | next if $dir eq ''; |
74 | my $abs = File::Spec->catfile($dir, $cmd); |
75 | return $abs if (-x $abs or $abs = MM->maybe_command($abs)); |
76 | } |
77 | |
78 | return; |
79 | } |
80 | |
81 | # Can our C compiler environment build XS files |
82 | sub can_xs { |
83 | # Do we have the configure_requires checker? |
84 | local $@; |
85 | eval "require ExtUtils::CBuilder; ExtUtils::CBuilder->VERSION(0.27)"; |
86 | if ( $@ ) { |
87 | # They don't obey configure_requires, so it is |
88 | # someone old and delicate. Try to avoid hurting |
89 | # them by falling back to an older simpler test. |
90 | return can_cc(); |
91 | } |
92 | |
93 | # Do we have a working C compiler |
94 | my $builder = ExtUtils::CBuilder->new( |
95 | quiet => 1, |
96 | ); |
97 | unless ( $builder->have_compiler ) { |
98 | # No working C compiler |
99 | return 0; |
100 | } |
101 | |
102 | # Write a C file representative of what XS becomes |
103 | require File::Temp; |
104 | my ( $FH, $tmpfile ) = File::Temp::tempfile( |
105 | "compilexs-XXXXX", |
106 | SUFFIX => '.c', |
107 | ); |
108 | binmode $FH; |
109 | print $FH <<'END_C'; |
110 | #include "EXTERN.h" |
111 | #include "perl.h" |
112 | #include "XSUB.h" |
113 | |
114 | int main(int argc, char **argv) { |
115 | return 0; |
116 | } |
117 | |
118 | int boot_sanexs() { |
119 | return 1; |
120 | } |
121 | |
122 | END_C |
123 | close $FH; |
124 | |
125 | # Can the C compiler access the same headers XS does |
126 | my @libs = (); |
127 | my $object = undef; |
128 | eval { |
129 | local $^W = 0; |
130 | $object = $builder->compile( |
131 | source => $tmpfile, |
132 | ); |
133 | @libs = $builder->link( |
134 | objects => $object, |
135 | module_name => 'sanexs', |
136 | ); |
137 | }; |
138 | my $result = $@ ? 0 : 1; |
139 | |
140 | # Clean up all the build files |
141 | foreach ( $tmpfile, $object, @libs ) { |
142 | next unless defined $_; |
143 | 1 while unlink; |
144 | } |
145 | |
146 | return $result; |
147 | } |