]> www.ginac.de Git - cln.git/blob - m4/gmp.m4
Rework of autoconfiscation infrastructure
[cln.git] / m4 / gmp.m4
1 dnl -*- Autoconf -*-
2 dnl Copyright (C) 1993-2003 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License.  As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
8
9 dnl From Richard B. Kreckel.
10
11 AC_PREREQ(2.13)
12
13 dnl Is the gmp header file new enough? (should be implemented with an argument)
14 AC_DEFUN(CL_GMP_H_VERSION,
15 [AC_CACHE_CHECK([for recent enough gmp.h], cl_cv_new_gmp_h, [
16   AC_TRY_CPP([#include <gmp.h>
17 #if !defined(__GNU_MP_VERSION) || (__GNU_MP_VERSION < 3)
18  #error "ancient gmp.h"
19 #endif],
20 cl_cv_new_gmp_h="yes", cl_cv_new_gmp_h="no")
21 ])])dnl
22
23 dnl Does libgmp provide some functionality introduced in version 3.0?
24 AC_DEFUN(CL_GMP_CHECK,
25 [AC_CACHE_CHECK([for working libgmp], cl_cv_new_libgmp, [
26     SAVELIBS=$LIBS
27     LIBS="$LIBS -lgmp"
28     AC_TRY_LINK([#include <gmp.h>],[mpn_divexact_by3(0,0,0)],
29 cl_cv_new_libgmp="yes", cl_cv_new_libgmp="no"; LIBS=$SAVELIBS)
30 ])])
31
32 dnl What is sizeof(mp_limb_t)?  (It has to match sizeof(uintD) later.)
33 AC_DEFUN(CL_GMP_SET_UINTD,
34 [AC_CACHE_CHECK([how large gmp demands uintD to be], cl_cv_gmp_set_uintd, [
35     AC_TRY_RUN([#include <stdio.h>
36 #include <gmp.h>
37 int main() {
38     FILE *f=fopen("conftestval", "w");
39     if (!f) return(255);
40     if (sizeof(mp_limb_t) > sizeof(long))
41         fprintf(f, "long long");
42     else if (sizeof(mp_limb_t) == sizeof(long))
43         fprintf(f, "long");
44     else if (sizeof(mp_limb_t) == sizeof(int))
45         fprintf(f, "int");
46     else return(sizeof(mp_limb_t));
47 #if defined(__GMP_BITS_PER_MP_LIMB)
48     /* Is there a nail in a limb? */
49     if (8*sizeof(mp_limb_t)!=__GMP_BITS_PER_MP_LIMB)
50         return(254);
51 #endif
52     return(0);
53 }], cl_cv_gmp_set_uintd=`cat conftestval`
54     cl_gmp_demands="GMP_DEMANDS_UINTD_`echo ${cl_cv_gmp_set_uintd} | sed -e 'y/ gilnot/_GILNOT/'`",
55     gmp_retval="$ac_status"
56     if test x$gmp_retval = "x255"; then AC_MSG_ERROR([error opening output file.]); fi
57     if test x$gmp_retval = "x254"; then AC_MSG_ERROR([nails in MP limbs are unsupported.]); fi
58     AC_MSG_ERROR([Don't know which C-type has sizeof $gmp_retval.]),
59     AC_MSG_ERROR([cross-compiling - cannot determine]))
60 ])
61 AC_DEFINE_UNQUOTED($cl_gmp_demands)
62 ])