Debian Codegraph @

inc/mymm.pl

raw
1 package mymm;
2
3 use strict;
4 use warnings;
5 use Config;
6 use File::Glob qw( bsd_glob );
7 use ExtUtils::MakeMaker ();
8 use IPC::Cmd ();
9 use lib 'inc';
10 use File::Spec;
11 use My::BuildConfig;
12 use My::ShareConfig;
13
14 {
15 my $dh;
16 opendir $dh, 'inc';
17 my @files = map { File::Spec->catfile('inc', $_) } grep /^bad-.*\.pl$/, readdir $dh;
18 close $dh;
19
20 foreach my $badcheck (@files)
21 {
22 system $^X, $badcheck;
23 if($?)
24 {
25 print "bad check $badcheck failed\n";
26 exit;
27 }
28 }
29 }
30
31 sub vcpkg
32 {
33 return unless $Config{ccname} eq 'cl';
34 require Alien::FFI::Vcpkg;
35 !!eval { Alien::FFI::Vcpkg->vcpkg }
36 }
37
38 sub myWriteMakefile
39 {
40 my %args = @_;
41 my $build_config = My::BuildConfig->new;
42 my $share_config = My::ShareConfig->new;
43 my %diag;
44 my %alien;
45
46 ExtUtils::MakeMaker->VERSION('7.12');
47 $build_config->set(version => [ $args{VERSION} =~ /^([0-9]+)\.([0-9]{2})/ ]);
48
49 if(eval { require Alien::FFI; Alien::FFI->VERSION('0.20'); 1 })
50 {
51 print "using already installed Alien::FFI (version @{[ Alien::FFI->VERSION ]})\n";
52 $build_config->set(alien => { class => 'Alien::FFI', mode => 'already-installed' });
53 require Alien::Base::Wrapper;
54 Alien::Base::Wrapper->import( 'Alien::FFI', 'Alien::psapi', '!export' );
55 %alien = Alien::Base::Wrapper->mm_args;
56 }
57 elsif(vcpkg())
58 {
59 print "using vcpkg libffi package\n";
60 $build_config->set(alien => { class => 'Alien::FFI::Vcpkg', mode => 'system' });
61 require Alien::Base::Wrapper;
62 Alien::Base::Wrapper->import( 'Alien::FFI::Vcpkg', '!export');
63 %alien = Alien::Base::Wrapper->mm_args;
64 delete $args{BUILD_REQUIRES}->{'Alien::FFI'};
65 }
66 else
67 {
68 require Alien::FFI::pkgconfig if $^O ne 'MSWin32';
69 require Alien::FFI::PkgConfigPP if $^O eq 'MSWin32';
70
71 my $alien_install_type_unset = !defined $ENV{ALIEN_INSTALL_TYPE};
72
73 if($alien_install_type_unset && $^O eq 'MSWin32' && Alien::FFI::PkgConfigPP->exists)
74 {
75 print "using system libffia via PkgConfigPP\n";
76 $build_config->set(alien => { class => 'Alien::FFI::PkgConfigPP', mode => 'system' });
77 require Alien::Base::Wrapper;
78 Alien::Base::Wrapper->import( 'Alien::FFI::PkgConfigPP', 'Alien::psapi', '!export' );
79 %alien = Alien::Base::Wrapper->mm_args;
80 delete $args{BUILD_REQUIRES}->{'Alien::FFI'};
81 }
82 elsif($alien_install_type_unset && $^O ne 'MSWin32' && Alien::FFI::pkgconfig->exists)
83 {
84 print "using system libffi via @{[ Alien::FFI::pkgconfig->pkg_config_exe ]}\n";
85 $build_config->set(alien => { class => 'Alien::FFI::pkgconfig', mode => 'system' });
86 require Alien::Base::Wrapper;
87 Alien::Base::Wrapper->import( 'Alien::FFI::pkgconfig', 'Alien::psapi', '!export' );
88 %alien = Alien::Base::Wrapper->mm_args;
89 delete $args{BUILD_REQUIRES}->{'Alien::FFI'};
90 }
91 else
92 {
93 print "requiring Alien::FFI in fallback mode.\n";
94 $build_config->set(alien => { class => 'Alien::FFI', mode => 'fallback' });
95 %alien = (
96 CC => '$(FULLPERL) -Iinc -MAlien::Base::Wrapper=Alien::FFI,Alien::psapi -e cc --',
97 LD => '$(FULLPERL) -Iinc -MAlien::Base::Wrapper=Alien::FFI,Alien::psapi -e ld --',
98 );
99 }
100 }
101 $alien{INC} = defined $alien{INC} ? "-Iinclude $alien{INC}" : "-Iinclude";
102
103 %args = (%args, %alien);
104
105 if($ENV{FFI_PLATYPUS_DEBUG_FAKE32} || $Config{uvsize} < 8)
106 {
107 $args{BUILD_REQUIRES}->{'Math::Int64'} = '0.34';
108 }
109
110 if($ENV{FFI_PLATYPUS_DEBUG_FAKE32} && $Config{uvsize} == 8)
111 {
112 print "DEBUG_FAKE32:\n";
113 print " + making Math::Int64 a prereq\n";
114 print " + Using Math::Int64's C API to manipulate 64 bit values\n";
115 $build_config->set(config_debug_fake32 => 1);
116 $diag{config}->{config_debug_fake32} = 1;
117 }
118 if($ENV{FFI_PLATYPUS_NO_ALLOCA})
119 {
120 print "NO_ALLOCA:\n";
121 print " + alloca() will not be used, even if your platform supports it.\n";
122 $build_config->set(config_no_alloca => 1);
123 $diag{config}->{config_no_alloca} = 1;
124 }
125
126 delete $args{PM};
127 $args{XSMULTI} = 1;
128 $args{XSBUILD} = {
129 xs => {
130 'lib/FFI/Platypus' => {
131 OBJECT => 'lib/FFI/Platypus$(OBJ_EXT) ' . join(' ', map { s/\.c$/\$(OBJ_EXT)/; $_ } bsd_glob "xs/*.c"),
132 %alien,
133 },
134 },
135 };
136
137 $args{PREREQ_PM}->{'Math::Int64'} = '0.34'
138 if $ENV{FFI_PLATYPUS_DEBUG_FAKE32} || $Config{uvsize} < 8;
139
140 # dlext as understood by MB and MM
141 my @dlext = ($Config{dlext});
142
143 # extra dlext as understood by the OS
144 push @dlext, 'dll' if $^O =~ /^(cygwin|MSWin32|msys)$/;
145 push @dlext, 'xs.dll' if $^O =~ /^(MSWin32)$/;
146 push @dlext, 'so' if $^O =~ /^(cygwin|darwin)$/;
147 push @dlext, 'bundle', 'dylib' if $^O =~ /^(darwin)$/;
148
149 # uniq'ify it
150 @dlext = do { my %seen; grep { !$seen{$_}++ } @dlext };
151
152 $build_config->set(diag => \%diag);
153 $share_config->set(config_dlext => \@dlext);
154
155 ExtUtils::MakeMaker::WriteMakefile(%args);
156 }
157
158 #package MM;
159 #
160 #sub init_tools
161 #{
162 # my $self = shift;
163 # $self->SUPER::init_tools(@_);
164 #
165 # return if !!$ENV{V};
166 #
167 # my $noecho = $^O eq 'MSWin32' ? 'REM ' : '@';
168 #
169 # foreach my $tool (qw( RM_F RM_RF CP MV ))
170 # {
171 # $self->{$tool} = $noecho . $self->{$tool};
172 # }
173 #
174 # return;
175 #}
176
177 package MY;
178
179 use Config;
180
181 sub dynamic_lib
182 {
183 my($self, @therest) = @_;
184 my $dynamic_lib = $self->SUPER::dynamic_lib(@therest);
185
186 my %h = map { m!include/(.*?)$! && $1 => [$_] } File::Glob::bsd_glob('include/*.h');
187 push @{ $h{"ffi_platypus.h"} }, map { "include/ffi_platypus_$_.h" } qw( config );
188
189 my %targets = (
190 'include/ffi_platypus_config.h' => ['_mm/config'],
191 'lib/FFI/Platypus.c' => [File::Glob::bsd_glob('xs/*.xs'), 'lib/FFI/Platypus.xs', 'lib/FFI/typemap'],
192 );
193
194 foreach my $cfile (File::Glob::bsd_glob('xs/*.c'), 'lib/FFI/Platypus.c')
195 {
196 my $ofile = $cfile;
197 $ofile =~ s/\.c$/\$(OBJ_EXT)/;
198
199 my @deps = ($cfile, '_mm/config');
200
201 if(-d ".git")
202 {
203 # for a development build, lets go ahead and compute the .h
204 # dependencies to make it easier to do a partial rebuild.
205 my $source_file = $cfile;
206 $source_file = 'lib/FFI/Platypus.xs' if $source_file =~ /^lib\/FFI/;
207 my $fh;
208 open $fh, '<', $source_file;
209 while(<$fh>)
210 {
211 if(/^#include [<"](.*?)[>"]/ && $h{$1})
212 {
213 push @deps, @{$h{$1}};
214 }
215 }
216 close $fh;
217 }
218
219 $targets{$ofile} = \@deps;
220 }
221
222 $dynamic_lib .= "\n";
223
224 foreach my $target (sort keys %targets)
225 {
226 $dynamic_lib .= "$target : @{$targets{$target}}\n";
227 }
228
229 $dynamic_lib;
230 }
231
232 sub postamble {
233 my $postamble = '';
234
235 my $noecho = !!$ENV{V} ? '' : '$(NOECHO) ';
236
237 my $sep = $^O eq 'MSWin32' && $Config{make} eq 'nmake'
238 ? '\\'
239 : '/';
240
241 $postamble .=
242 "flags: _mm${sep}flags\n" .
243 "_mm${sep}flags:\n";
244
245 foreach my $key (qw( cc inc ccflags cccdlflags optimize ld ldflags lddlflags ))
246 {
247 $postamble .=
248 sprintf "\t$noecho\$(FULLPERL) inc${sep}mm-config-set.pl %-20s \$(%s)\n", $key, uc $key;
249 }
250
251 $postamble .=
252 "\t$noecho\$(MKPATH) _mm\n" .
253 "\t$noecho\$(TOUCH) _mm${sep}flags\n\n";
254
255 $postamble .=
256 "probe-runner-builder prb: _mm${sep}probe-builder\n" .
257 "_mm${sep}probe-builder: _mm${sep}flags\n" .
258 "\t$noecho\$(FULLPERL) inc${sep}mm-config-pb.pl\n" .
259 "\t$noecho\$(MKPATH) _mm\n" .
260 "\t$noecho\$(TOUCH) _mm${sep}probe-builder\n\n";
261
262 $postamble .=
263 "config :: _mm${sep}config\n" .
264 "_mm${sep}config: _mm${sep}flags _mm${sep}probe-builder\n" .
265 "\t$noecho\$(FULLPERL) inc${sep}mm-config.pl\n" .
266 "\t$noecho\$(MKPATH) _mm\n" .
267 "\t$noecho\$(TOUCH) _mm${sep}config\n\n";
268
269 $postamble .=
270 "pure_all :: ffi\n" .
271 "ffi: _mm${sep}config\n" .
272 "\t$noecho\$(FULLPERL) inc${sep}mm-build.pl\n\n";
273
274 $postamble .=
275 "subdirs-test_dynamic subdirs-test_static subdirs-test :: ffi-test\n" .
276 "ffi-test : _mm${sep}config\n" .
277 "\t$noecho\$(FULLPERL) inc${sep}mm-test.pl\n\n";
278
279 $postamble .=
280 "clean :: mm-clean\n" .
281 "mm-clean :\n" .
282 "\t$noecho\$(FULLPERL) inc${sep}mm-clean.pl\n" .
283 "\t$noecho\$(RM_RF) _mm ffi-probe-*\n" .
284 "\t$noecho\$(RM_RF) .tmp\n" .
285 "\t$noecho\$(RM_RF) corpus${sep}*${sep}*${sep}tmpbuild*\n\n";
286
287 # Workaround for the tireless testers out there
288 # who want to make -jX a thing. For some reason.
289 #
290 # When bsd make is passed -jX it turns off compat
291 # mode, even if the Makefile itself turns off
292 # parallel build. Unfortunately the Makefile
293 # generated by EUMM does not work without compat
294 # mode. So we:
295 $postamble .=
296 # 1. turn off parallel build using the bsd-only
297 # faux rule `.NO_PARALLEL` rather than the
298 # more portable `.NOTPARALLEL`, because this
299 # will allow parallel build with gmake, which
300 # does work.
301 ".NO_PARALLEL:\n\n";
302
303 if($^O eq 'MSWin32' && $Config{ccname} eq 'cl')
304 {
305 # nothing.
306 }
307 else
308 {
309 $postamble .=
310 # 2. turn compat mode back on.
311 ".MAKE.MODE=compat\n\n";
312 }
313
314 $postamble;
315 }
316
317 sub special_targets {
318 my($self, @therest) = @_;
319 my $st = $self->SUPER::special_targets(@therest);
320 $st .= "\n.PHONY: flags probe-runner-builder prb ffi ffi-test\n";
321 $st;
322 }
323
324 1;