Alien-Build
view release on metacpan or search on metacpan
lib/Alien/Build/Plugin/Core/Setup.pm view on Meta::CPAN
elsif($^O =~ /^(VMS)$/)
{
# others probably belong in here...
$hash->{system_type} = lc $^O;
}
else
{
$hash->{system_type} = 'unix';
}
$hash->{cpu}{count} =
exists $ENV{ALIEN_CPU_COUNT} && $ENV{ALIEN_CPU_COUNT} > 0
? $ENV{ALIEN_CPU_COUNT}
: _cpu_count();
$hash->{cpu}{arch} = _cpu_arch(\%Config);
}
# Retrieve number of available CPU cores. Adopted from
# <https://metacpan.org/release/MARIOROY/MCE-1.879/source/lib/MCE/Util.pm#L49>
# which is in turn adopted from Test::Smoke::Util with improvements.
sub _cpu_count {
local $ENV{PATH} = $ENV{PATH};
if( $^O ne 'MSWin32' ) {
$ENV{PATH} = "/usr/sbin:/sbin:/usr/bin:/bin:$ENV{PATH}";
}
$ENV{PATH} =~ /(.*)/; $ENV{PATH} = $1; ## Remove tainted'ness
my $ncpu = 1;
OS_CHECK: {
local $_ = lc $^O;
/linux/ && do {
my ( $count, $fh );
if ( open $fh, '<', '/proc/stat' ) {
$count = grep { /^cpu\d/ } <$fh>;
close $fh;
}
$ncpu = $count if $count;
last OS_CHECK;
};
/bsd|darwin|dragonfly/ && do {
chomp( my @output = `sysctl -n hw.ncpu 2>/dev/null` );
$ncpu = $output[0] if @output;
last OS_CHECK;
};
/aix/ && do {
my @output = `lparstat -i 2>/dev/null | grep "^Online Virtual CPUs"`;
if ( @output ) {
$output[0] =~ /(\d+)\n$/;
$ncpu = $1 if $1;
}
if ( !$ncpu ) {
@output = `pmcycles -m 2>/dev/null`;
if ( @output ) {
$ncpu = scalar @output;
} else {
@output = `lsdev -Cc processor -S Available 2>/dev/null`;
$ncpu = scalar @output if @output;
}
}
last OS_CHECK;
};
/gnu/ && do {
chomp( my @output = `nproc 2>/dev/null` );
$ncpu = $output[0] if @output;
last OS_CHECK;
};
/haiku/ && do {
my @output = `sysinfo -cpu 2>/dev/null | grep "^CPU #"`;
$ncpu = scalar @output if @output;
last OS_CHECK;
};
/hp-?ux/ && do {
my $count = grep { /^processor/ } `ioscan -fkC processor 2>/dev/null`;
$ncpu = $count if $count;
last OS_CHECK;
};
/irix/ && do {
my @out = grep { /\s+processors?$/i } `hinv -c processor 2>/dev/null`;
$ncpu = (split ' ', $out[0])[0] if @out;
last OS_CHECK;
};
/osf|solaris|sunos|svr5|sco/ && do {
if (-x '/usr/sbin/psrinfo') {
my $count = grep { /on-?line/ } `psrinfo 2>/dev/null`;
$ncpu = $count if $count;
}
else {
my @output = grep { /^NumCPU = \d+/ } `uname -X 2>/dev/null`;
$ncpu = (split ' ', $output[0])[2] if @output;
}
last OS_CHECK;
};
/mswin|mingw|msys|cygwin/ && do {
if (exists $ENV{NUMBER_OF_PROCESSORS}) {
$ncpu = $ENV{NUMBER_OF_PROCESSORS};
}
last OS_CHECK;
};
warn "CPU count: unknown operating system";
}
$ncpu = 1 if (!$ncpu || $ncpu < 1);
$ncpu;
}
sub _cpu_arch {
my ($my_config) = @_;
my $arch = {};
my %Config = %$my_config;
die "Config missing archname" unless exists $Config{archname};
die "Config missing ptrsize" unless exists $Config{ptrsize};
if( $Config{archname} =~ m/
\b x64 \b # MSWin32-x64
| \b x86_64 \b # x86_64-linux
| \b amd64 \b # amd64-freebsd
/ix) {
$arch = { name => 'x86_64' };
} elsif( $Config{archname} =~ m/
\b x86 \b # MSWin32-x86
| \b i386 \b # freebsd-i386
| \b i486 \b # i486-linux
| \b i686 \b # i686-cygwin
/ix ) {
$arch = { name => 'x86' };
} elsif( $Config{archname} =~ m/
\b darwin \b
/ix ) {
chomp( my $hw_machine = `sysctl -n hw.machine 2>/dev/null` );
HW_MACHINE:
for($hw_machine) {
( run in 2.096 seconds using v1.01-cache-2.11-cpan-3d66aa2751a )