File Coverage

File:config/auto/gmp.pm
Coverage:95.1%

linestmtbrancondsubcode
1# Copyright (C) 2001-2004, Parrot Foundation.
2
3 - 20
=head1 NAME

config/auto/gmp.pm - Test for GNU MP (GMP) Math library

=head1 DESCRIPTION

Determines whether the platform supports GMP.

From L<http://gmplib.org/>:  "GMP is a free library for arbitrary precision
arithmetic, operating on signed integers, rational numbers, and floating point
numbers. There is no practical limit to the precision except the ones implied
by the available memory in the machine GMP runs on. ..."

"The main target applications for GMP are cryptography applications and
research, Internet security applications, algebra systems, computational
algebra research, etc."

=cut
21
22package auto::gmp;
23
24
2
2
2
use strict;
25
2
2
2
use warnings;
26
27
2
2
2
use base qw(Parrot::Configure::Step);
28
29
2
2
2
use Parrot::Configure::Utils ':auto';
30
31sub _init {
32
4
    my $self = shift;
33
4
    my %data;
34
4
    $data{description} = q{Does your platform support GMP};
35
4
    $data{result} = q{};
36
4
    $data{cc_run_expected} =
37"6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151 0\n";
38
39
4
    return \%data;
40}
41
42sub runstep {
43
2
    my ( $self, $conf ) = @_;
44
45
2
    my $without = $conf->options->get( qw| without-gmp | );
46
47
2
    if ($without) {
48
1
        $conf->data->set( has_gmp => 0 );
49
1
        $self->set_result('no');
50
1
        return 1;
51    }
52
53
1
    my $osname = $conf->data->get('osname');
54
55
1
    my $extra_libs = $self->_select_lib( {
56        conf => $conf,
57        osname => $osname,
58        cc => $conf->data->get('cc'),
59        win32_nongcc => 'gmp.lib',
60        default => '-lgmp',
61    } );
62
63
1
    $conf->cc_gen('config/auto/gmp/gmp_c.in');
64
1
1
    eval { $conf->cc_build( q{}, $extra_libs); };
65
1
    my $has_gmp = 0;
66
1
    if ( !$@ ) {
67
1
        my $test = $conf->cc_run();
68
1
        $has_gmp = $self->_evaluate_cc_run( $conf, $test, $has_gmp );
69    }
70
1
    if ($has_gmp) {
71
1
        $conf->data->add( ' ', libs => $extra_libs );
72    }
73
1
    $self->set_result($has_gmp ? 'yes' : 'no');
74
75
1
    return 1;
76}
77
78sub _evaluate_cc_run {
79
4
    my ($self, $conf, $test, $has_gmp) = @_;
80
4
    if ( $test eq $self->{cc_run_expected} ) {
81
3
        $has_gmp = 1;
82
3
        $conf->debug(" (yes) ");
83
3
        $self->set_result('yes');
84
85
3
        $conf->data->set(
86            gmp => 'define',
87            HAS_GMP => $has_gmp,
88        );
89    }
90
4
    return $has_gmp;
91}
92
931;
94
95# Local Variables:
96# mode: cperl
97# cperl-indent-level: 4
98# fill-column: 100
99# End:
100# vim: expandtab shiftwidth=4: