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