Commit | Line | Data |
3a42a9c3 |
1 | use strict; |
9ed74472 |
2 | use warnings FATAL => 'all'; |
3 | use 5.006; |
4 | |
5 | my %META = ( |
6 | name => 'Devel-GlobalDestruction', |
7 | license => 'perl_5', |
8 | prereqs => { |
9 | configure => { requires => { |
10 | 'ExtUtils::MakeMaker' => 0, |
11 | 'ExtUtils::CBuilder' => 0.27, |
12 | } }, |
13 | runtime => { |
14 | requires => { |
15 | 'Sub::Exporter::Progressive' => '0.001011', |
16 | 'perl' => 5.006, |
17 | }, |
18 | }, |
19 | }, |
20 | resources => { |
21 | homepage => 'https://metacpan.org/release/Devel-GlobalDestruction', |
22 | repository => { |
23 | url => 'git://git.shadowcat.co.uk/p5sagit/Devel-GlobalDestruction.git', |
24 | web => 'http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit/Devel-GlobalDestruction.git', |
25 | type => 'git', |
26 | }, |
27 | bugtracker => { |
28 | web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=Devel-GlobalDestruction', |
29 | mailto => 'bug-Devel-GlobalDestruction@rt.cpan.org', |
30 | }, |
31 | license => [ 'http://dev.perl.org/licenses/' ], |
32 | }, |
33 | no_index => { |
34 | directory => [ 't', 'xt' ] |
35 | }, |
36 | ); |
9aaf3646 |
37 | |
9ed74472 |
38 | my %MM_ARGS = ( |
39 | PREREQ_PM => { |
40 | ( (defined ${^GLOBAL_PHASE} or parse_args()->{PUREPERL_ONLY} or !can_xs() ) |
41 | ? () |
42 | : ('Devel::GlobalDestruction::XS' => 0) |
43 | ), |
44 | }, |
45 | ); |
3a42a9c3 |
46 | |
47 | use ExtUtils::MakeMaker; |
9aaf3646 |
48 | BEGIN { if ( $^O eq 'cygwin' ) { |
49 | require ExtUtils::MM_Cygwin; |
50 | require ExtUtils::MM_Win32; |
51 | if ( ! defined(&ExtUtils::MM_Cygwin::maybe_command) ) { |
52 | *ExtUtils::MM_Cygwin::maybe_command = sub { |
53 | my ($self, $file) = @_; |
54 | if ($file =~ m{^/cygdrive/}i and ExtUtils::MM_Win32->can('maybe_command')) { |
55 | ExtUtils::MM_Win32->maybe_command($file); |
56 | } else { |
57 | ExtUtils::MM_Unix->maybe_command($file); |
58 | } |
59 | } |
60 | } |
61 | }} |
62 | |
e00dea6c |
63 | use Text::ParseWords; |
64 | |
65 | sub parse_args { |
66 | # copied from EUMM |
67 | ExtUtils::MakeMaker::parse_args( |
68 | my $tmp = {}, |
69 | Text::ParseWords::shellwords($ENV{PERL_MM_OPT} || ''), |
70 | @ARGV, |
71 | ); |
72 | return $tmp->{ARGS} || {}; |
219ca4f9 |
73 | } |
74 | |
3d084a8c |
75 | if (eval { require Devel::GlobalDestruction } |
76 | && Devel::GlobalDestruction->VERSION < 0.10) { |
77 | package MY; |
78 | no warnings 'once'; |
79 | |
80 | *install = sub { |
81 | my $self = shift; |
82 | return ' |
83 | pure_site_install :: |
84 | $(NOECHO) $(RM_F) ' . $self->quote_literal( |
85 | $self->catfile('$(DESTINSTALLSITEARCH)', 'Devel', 'GlobalDestruction.pm') |
86 | ) . "\n" . $self->SUPER::install; |
87 | }; |
88 | } |
89 | |
9aaf3646 |
90 | # can we locate a (the) C compiler |
91 | sub can_cc { |
92 | my @chunks = split(/ /, $Config::Config{cc}) or return; |
93 | |
94 | # $Config{cc} may contain args; try to find out the program part |
95 | while (@chunks) { |
96 | return can_run("@chunks") || (pop(@chunks), next); |
97 | } |
98 | |
99 | return; |
100 | } |
101 | |
102 | # check if we can run some command |
103 | sub can_run { |
104 | my ($cmd) = @_; |
105 | |
106 | return $cmd if -x $cmd; |
107 | if (my $found_cmd = MM->maybe_command($cmd)) { |
108 | return $found_cmd; |
109 | } |
110 | |
111 | require File::Spec; |
112 | for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') { |
113 | next if $dir eq ''; |
114 | my $abs = File::Spec->catfile($dir, $cmd); |
115 | return $abs if (-x $abs or $abs = MM->maybe_command($abs)); |
116 | } |
117 | |
118 | return; |
119 | } |
120 | |
121 | # Can our C compiler environment build XS files |
122 | sub can_xs { |
123 | # Do we have the configure_requires checker? |
124 | local $@; |
125 | eval "require ExtUtils::CBuilder; ExtUtils::CBuilder->VERSION(0.27)"; |
126 | if ( $@ ) { |
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. |
130 | return can_cc(); |
131 | } |
132 | |
133 | # Do we have a working C compiler |
134 | my $builder = ExtUtils::CBuilder->new( |
135 | quiet => 1, |
136 | ); |
137 | unless ( $builder->have_compiler ) { |
138 | # No working C compiler |
139 | return 0; |
140 | } |
141 | |
142 | # Write a C file representative of what XS becomes |
143 | require File::Temp; |
144 | my ( $FH, $tmpfile ) = File::Temp::tempfile( |
145 | "compilexs-XXXXX", |
146 | SUFFIX => '.c', |
147 | ); |
148 | binmode $FH; |
149 | print $FH <<'END_C'; |
150 | #include "EXTERN.h" |
151 | #include "perl.h" |
152 | #include "XSUB.h" |
153 | |
154 | int main(int argc, char **argv) { |
155 | return 0; |
156 | } |
157 | |
158 | int boot_sanexs() { |
159 | return 1; |
160 | } |
161 | |
162 | END_C |
163 | close $FH; |
164 | |
165 | # Can the C compiler access the same headers XS does |
166 | my @libs = (); |
167 | my $object = undef; |
168 | eval { |
169 | local $^W = 0; |
170 | $object = $builder->compile( |
171 | source => $tmpfile, |
172 | ); |
173 | @libs = $builder->link( |
174 | objects => $object, |
175 | module_name => 'sanexs', |
176 | ); |
177 | }; |
178 | my $result = $@ ? 0 : 1; |
179 | |
180 | # Clean up all the build files |
181 | foreach ( $tmpfile, $object, @libs ) { |
182 | next unless defined $_; |
183 | 1 while unlink; |
184 | } |
185 | |
186 | return $result; |
187 | } |
9ed74472 |
188 | |
734ce277 |
189 | ## BOILERPLATE ############################################################### |
9ed74472 |
190 | require ExtUtils::MakeMaker; |
191 | (do 'maint/Makefile.PL.include' or die $@) unless -f 'META.yml'; |
192 | |
193 | # have to do this since old EUMM dev releases miss the eval $VERSION line |
194 | my $eumm_version = eval $ExtUtils::MakeMaker::VERSION; |
195 | my $mymeta = $eumm_version >= 6.57_02; |
196 | my $mymeta_broken = $mymeta && $eumm_version < 6.57_07; |
197 | |
198 | ($MM_ARGS{NAME} = $META{name}) =~ s/-/::/g; |
199 | ($MM_ARGS{VERSION_FROM} = "lib/$MM_ARGS{NAME}.pm") =~ s{::}{/}g; |
734ce277 |
200 | $META{license} = [ $META{license} ] |
201 | if $META{license} && !ref $META{license}; |
202 | $MM_ARGS{LICENSE} = $META{license}[0] |
203 | if $META{license} && $eumm_version >= 6.30; |
9ed74472 |
204 | $MM_ARGS{NO_MYMETA} = 1 |
205 | if $mymeta_broken; |
206 | $MM_ARGS{META_ADD} = { 'meta-spec' => { version => 2 }, %META } |
207 | unless -f 'META.yml'; |
208 | |
209 | for (qw(configure build test runtime)) { |
210 | my $key = $_ eq 'runtime' ? 'PREREQ_PM' : uc $_.'_REQUIRES'; |
211 | my $r = $MM_ARGS{$key} = { |
212 | %{$META{prereqs}{$_}{requires} || {}}, |
213 | %{delete $MM_ARGS{$key} || {}}, |
214 | }; |
215 | defined $r->{$_} or delete $r->{$_} for keys %$r; |
216 | } |
217 | |
218 | $MM_ARGS{MIN_PERL_VERSION} = delete $MM_ARGS{PREREQ_PM}{perl} || 0; |
219 | |
220 | delete $MM_ARGS{MIN_PERL_VERSION} |
221 | if $eumm_version < 6.47_01; |
222 | $MM_ARGS{BUILD_REQUIRES} = {%{$MM_ARGS{BUILD_REQUIRES}}, %{delete $MM_ARGS{TEST_REQUIRES}}} |
223 | if $eumm_version < 6.63_03; |
224 | $MM_ARGS{PREREQ_PM} = {%{$MM_ARGS{PREREQ_PM}}, %{delete $MM_ARGS{BUILD_REQUIRES}}} |
225 | if $eumm_version < 6.55_01; |
226 | delete $MM_ARGS{CONFIGURE_REQUIRES} |
227 | if $eumm_version < 6.51_03; |
228 | |
229 | ExtUtils::MakeMaker::WriteMakefile(%MM_ARGS); |
734ce277 |
230 | ## END BOILERPLATE ########################################################### |