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