Algorithm-ConsistentHash-Ketama
view release on metacpan or search on metacpan
inc/Module/Install/XSUtil.pm view on Meta::CPAN
if(!$self->cc_available()){
warn "This distribution requires a C compiler, but it's not available, stopped.\n";
exit;
}
$self->configure_requires(%ConfigureRequires);
$self->build_requires(%BuildRequires);
$self->requires(%Requires);
$self->makemaker_args->{OBJECT} = '$(O_FILES)';
$self->clean_files('$(O_FILES)');
$self->clean_files('*.stackdump') if $^O eq 'cygwin';
if($self->_xs_debugging()){
# override $Config{optimize}
if(_is_msvc()){
$self->makemaker_args->{OPTIMIZE} = '-Zi';
}
else{
$self->makemaker_args->{OPTIMIZE} = '-g -ggdb -g3';
}
$self->cc_define('-DXS_ASSERT');
}
}
return;
}
# GNU C Compiler
sub _is_gcc{
return $Config{gccversion};
}
# Microsoft Visual C++ Compiler (cl.exe)
sub _is_msvc{
return $Config{cc} =~ /\A cl \b /xmsi;
}
{
my $cc_available;
sub cc_available {
return defined $cc_available ?
$cc_available :
($cc_available = shift->can_cc())
;
}
# cf. https://github.com/sjn/toolchain-site/blob/219db464af9b2f19b04fec05547ac10180a469f3/lancaster-consensus.md
my $want_xs;
sub want_xs {
my($self, $default) = @_;
return $want_xs if defined $want_xs;
# you're using this module, you must want XS by default
# unless PERL_ONLY is true.
$default = !$ENV{PERL_ONLY} if not defined $default;
foreach my $arg(@ARGV){
my ($k, $v) = split '=', $arg; # MM-style named args
if ($k eq 'PUREPERL_ONLY' && defined $v) {
return $want_xs = !$v;
}
elsif($arg eq '--pp'){ # old-style
return $want_xs = 0;
}
elsif($arg eq '--xs'){
return $want_xs = 1;
}
}
if ($ENV{PERL_MM_OPT}) {
my($v) = $ENV{PERL_MM_OPT} =~ /\b PUREPERL_ONLY = (\S+) /xms;
if (defined $v) {
return $want_xs = !$v;
}
}
return $want_xs = $default;
}
}
sub use_ppport{
my($self, $dppp_version) = @_;
return if $self->{_ppport_ok}++;
$self->_xs_initialize();
my $filename = 'ppport.h';
$dppp_version ||= 3.19; # the more, the better
$self->configure_requires('Devel::PPPort' => $dppp_version);
$self->build_requires('Devel::PPPort' => $dppp_version);
print "Writing $filename\n";
my $e = do{
local $@;
eval qq{
use Devel::PPPort;
Devel::PPPort::WriteFile(q{$filename});
};
$@;
};
if($e){
print "Cannot create $filename because: $@\n";
}
if(-e $filename){
$self->clean_files($filename);
$self->cc_define('-DUSE_PPPORT');
$self->cc_append_to_inc('.');
}
return;
}
sub use_xshelper {
my($self, $opt) = @_;
$self->_xs_initialize();
$self->use_ppport();
my $file = 'xshelper.h';
open my $fh, '>', $file or die "Cannot open $file for writing: $!";
print $fh $self->_xshelper_h();
inc/Module/Install/XSUtil.pm view on Meta::CPAN
}
}
return;
}
sub _gccversion {
my $res = `$Config{cc} --version`;
my ($version) = $res =~ /\(GCC\) ([0-9.]+)/;
no warnings 'numeric', 'uninitialized';
return sprintf '%g', $version;
}
sub cc_warnings{
my($self) = @_;
$self->_xs_initialize();
if(_is_gcc()){
$self->cc_append_to_ccflags(qw(-Wall));
my $gccversion = _gccversion();
if($gccversion >= 4.0){
$self->cc_append_to_ccflags(qw(-Wextra));
if(!($UseC99 or $UseCplusplus)) {
# Note: MSVC++ doesn't support C99,
# so -Wdeclaration-after-statement helps
# ensure C89 specs.
$self->cc_append_to_ccflags(qw(-Wdeclaration-after-statement));
}
if($gccversion >= 4.1 && !$UseCplusplus) {
$self->cc_append_to_ccflags(qw(-Wc++-compat));
}
}
else{
$self->cc_append_to_ccflags(qw(-W -Wno-comment));
}
}
elsif(_is_msvc()){
$self->cc_append_to_ccflags(qw(-W3));
}
else{
# TODO: support other compilers
}
return;
}
sub c99_available {
my($self) = @_;
return 0 if not $self->cc_available();
require File::Temp;
require File::Basename;
my $tmpfile = File::Temp->new(SUFFIX => '.c');
$tmpfile->print(<<'C99');
// include a C99 header
#include <stdbool.h>
inline // a C99 keyword with C99 style comments
int test_c99() {
int i = 0;
i++;
int j = i - 1; // another C99 feature: declaration after statement
return j;
}
C99
$tmpfile->close();
system "$Config{cc} -c " . $tmpfile->filename;
(my $objname = File::Basename::basename($tmpfile->filename)) =~ s/\Q.c\E$/$Config{_o}/;
unlink $objname or warn "Cannot unlink $objname (ignored): $!";
return $? == 0;
}
sub requires_c99 {
my($self) = @_;
if(!$self->c99_available) {
warn "This distribution requires a C99 compiler, but $Config{cc} seems not to support C99, stopped.\n";
exit;
}
$self->_xs_initialize();
$UseC99 = 1;
return;
}
sub requires_cplusplus {
my($self) = @_;
if(!$self->cc_available) {
warn "This distribution requires a C++ compiler, but $Config{cc} seems not to support C++, stopped.\n";
exit;
}
$self->_xs_initialize();
$UseCplusplus = 1;
return;
}
sub cc_append_to_inc{
my($self, @dirs) = @_;
$self->_xs_initialize();
for my $dir(@dirs){
unless(-d $dir){
warn("'$dir' not found: $!\n");
}
_verbose "inc: -I$dir" if _VERBOSE;
}
my $mm = $self->makemaker_args;
my $paths = join q{ }, map{ s{\\}{\\\\}g; qq{"-I$_"} } @dirs;
if($mm->{INC}){
$mm->{INC} .= q{ } . $paths;
}
else{
( run in 0.534 second using v1.01-cache-2.11-cpan-39bf76dae61 )