diff --git a/Makefile.PL b/Makefile.PL index b166eea1..227314b4 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,9 +1,13 @@ use ExtUtils::MakeMaker; use lib 'inc'; # load our bundled version of Devel::CheckLib -use Devel::CheckLib; + +my $compiler_available; +BEGIN { + $compiler_available = eval { require Devel::CheckLib; 1 }; +} my %require_mpugmp; -my $have_gmp = check_lib(lib => 'gmp', header => 'gmp.h'); +my $have_gmp = $compiler_available && check_lib(lib => 'gmp', header => 'gmp.h'); if ($have_gmp) { warn "\n It looks like you have the GMP C library.\n"; warn " Adding Math::Prime::Util::GMP to dep list.\n\n"; @@ -63,7 +67,7 @@ WriteMakefile1( # 1.99 fixes the FastCalc SvUV bug, we work around it. 'Math::BigInt' => '1.88', 'Math::BigFloat' => '1.59', - 'Bytes::Random::Secure' => '0.23', + 'Bytes::Random::Secure::Tiny' => 0, # Add in MPU::GMP if we can %require_mpugmp, }, @@ -144,5 +148,11 @@ sub WriteMakefile1 { # Cribbed from eumm-upgrade by Alexandr Ciornii delete $params{ABSTRACT_FROM} if $] < 5.005; delete $params{BINARY_LOCATION} if $] < 5.005; + if (!$compiler_available) { + $params{'OBJECT'} = q<>; + delete $params{'PREREQ_PM'}{'XSLoader'}; + $params{'C'} = []; + } + WriteMakefile(%params); } diff --git a/lib/Math/Prime/Util/RandomPrimes.pm b/lib/Math/Prime/Util/RandomPrimes.pm index 4a029fb2..8df3ffc7 100644 --- a/lib/Math/Prime/Util/RandomPrimes.pm +++ b/lib/Math/Prime/Util/RandomPrimes.pm @@ -86,8 +86,7 @@ sub _set_randf { return if defined $_RANDF; if (!defined $_IRANDF) { # Default irand: BRS nonblocking - require Bytes::Random::Secure; - $_BRS = Bytes::Random::Secure->new(NonBlocking=>1) unless defined $_BRS; + $_BRS ||= _BRS(); $_RANDF_NBIT = sub { my($bits) = int("$_[0]"); return 0 if $bits <= 0; @@ -868,10 +867,7 @@ sub random_shawe_taylor_prime_with_cert { my $seed; my $irandf = prime_get_config->{'irand'}; if (!defined $irandf) { - if (!defined $_BRS) { - require Bytes::Random::Secure; - $_BRS = Bytes::Random::Secure->new(NonBlocking=>1); - } + $_BRS ||= _BRS(); $seed = $_BRS->bytes(512/8); } else { $seed = pack("L*", map { $irandf->() } 0 .. (512>>5)); @@ -1088,6 +1084,21 @@ sub miller_rabin_random { 1; } +my @BRS_CLASSES = qw( + Bytes::Random::Secure + Bytes::Random::Secure::Tiny +); + +sub _BRS { + local $@; + + for my $class ( @BRS_CLASSES ) { + if ( eval "require $class" ) { + return $_BRS = $class->new( NonBlocking => 1 ); + } + } +} + 1; __END__