1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
89
  
90
  
91
  
92
  
93
  
94
  
95
  
96
  
97
  
98
  
99
  
100
  
101
  
102
  
103
  
104
  
105
  
106
  
107
  
108
  
109
  
110
  
111
  
112
  
113
  
114
  
115
  
116
  
117
  
118
  
119
  
AC_INIT(mpz_glue.c) 
AC_CONFIG_HEADER(gmp_machine.h) 
 
AC_MODULE_INIT() 
 
############################################################################# 
 
PIKE_FEATURE_NODEP([Gmp (bignums)]) 
 
PIKE_PKG_CONFIG(libmpfr) 
 
ORIG_CHECK_HEADERS(gmp.h mpfr.h mpf2mpfr.h) 
AC_CHECK_LIB(gmp, main) 
AC_CHECK_LIB(mpfr, mpfr_init) 
AC_TRY_LINK([ 
#include <gmp.h> 
], [mpz_import], [], [ 
  AC_MSG_ERROR([ 
 
Cannot compile bignums without the GMP library. 
Your GMP library is too old (<4.1) or does not work. 
 
To compile Pike you are required to install a working GMP 
library on your system. 
]) 
]) 
 
if test "$ac_cv_header_gmp_h" = "yes" ; then 
 
  echo >>confdefs.h ' 
#include <gmp.h>' 
 
  PIKE_FEATURE_OK([Gmp (bignums)]) 
  AC_CHECK_SIZEOF(mp_limb_t, 0) 
 
  # Side channel secure powm added in 5.0 
  AC_MSG_CHECKING(for mpz_powm_sec) 
  AC_TRY_LINK([], [mpz_powm_sec], [ 
    AC_DEFINE(HAVE_GMP5) 
    AC_MSG_RESULT(yes) 
  ], [AC_MSG_RESULT(no)]) 
 
  # Side channel secure invert added in 6.0 
  AC_MSG_CHECKING(for mpn_sec_invert) 
  AC_TRY_LINK([], [mpn_sec_invert], [ 
    AC_DEFINE(HAVE_GMP6) 
    AC_MSG_RESULT(yes) 
  ], [AC_MSG_RESULT(no)]) 
 
  # Some packages of gmp have a gmp.h that lies about the number 
  # bits in limbs when running with the non-default ABI. 
  # (eg /opt/csw/include/gmp.h on Solaris 10/sparc). 
  AC_MSG_CHECKING(if GMP_NUMB_BITS is valid and lacks nails) 
  AC_CACHE_VAL([pike_cv_gmp_numb_bits_valid], [ 
    AC_TRY_COMPILE([ 
#if GMP_NUMB_BITS != (SIZEOF_MP_LIMB_T * CHAR_BIT) 
#error Cannot cope with GMP using nail bits. 
#error GMP_NUMB_BITS != (SIZEOF_MP_LIMB_T * CHAR_BIT) 
#endif 
    ], [], [pike_cv_gmp_numb_bits_valid=yes], [pike_cv_gmp_numb_bits_valid=no]) 
  ]) 
  AC_MSG_RESULT($pike_cv_gmp_numb_bits_valid) 
 
  if test "x$pike_cv_gmp_numb_bits_valid" = "xno"; then 
    AC_DEFINE(PIKE_GMP_LIMB_BITS_INVALID) 
 
    AC_MSG_CHECKING(for the actual number of numb bits) 
    AC_CACHE_VAL([pike_cv_actual_gmp_numb_bits], [ 
      rm -f confdefs.out.2 
      AC_TRY_RUN([ 
#include <stdio.h> 
 
        int main(int argc, char **argv) 
        { 
          mpz_t mpz; 
          mp_limb_t limb; 
          int bits = 0; 
          FILE *fp = fopen("confdefs.out.2", "w"); 
          /* weird filename to circumvent configure weirdness */ 
          if (!fp) return 1; 
 
          mpz_init(mpz); 
          mpz_set_ui(mpz, 1); 
          limb = mpz_getlimbn(mpz, 0); 
          while ((mpz->_mp_size < 2) || !(mpz_getlimbn(mpz, 1) & 1)) { 
            mpz_mul_2exp(mpz, mpz, 1); 
            bits++; 
          } 
          fprintf(fp, "%d\n", bits); 
          return 0; 
        } 
      ], [ 
        pike_cv_actual_gmp_numb_bits="`cat confdefs.out.2`" 
        rm -f confdefs.out.2 
      ], [ 
        pike_cv_actual_gmp_numb_bits="" 
      ], [ 
        pike_cv_actual_gmp_numb_bits="" 
      ]) 
    ]) 
    if test "x$pike_cv_actual_gmp_numb_bits" = "x"; then 
      AC_MSG_RESULT([unknown - using $ac_cv_sizeof_mp_limb_t * CHAR_BIT]) 
    else 
      AC_MSG_RESULT($pike_cv_actual_gmp_numb_bits) 
      AC_DEFINE_UNQUOTED(PIKE_GMP_NUMB_BITS, $pike_cv_actual_gmp_numb_bits) 
    fi 
  fi 
 
else 
  AC_MSG_ERROR([ 
 
Cannot compile bignums without the GMP library. To 
compile Pike you are required to install a working GMP 
library on your system. 
]) 
fi 
 
AC_OUTPUT(Makefile,echo FOO >stamp-h )