]> www.ginac.de Git - cln.git/blob - m4/gmp.m4
build: switch to ordinary auto* tools system.
[cln.git] / m4 / gmp.m4
1 dnl -*- Autoconf -*-
2 dnl Copyright (C) 1993-2008 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")
30     LIBS=$SAVELIBS])
31     if test "$cl_cv_new_libgmp" = yes; then
32       LIBS="$LIBS -lgmp"
33     fi
34 ])
35
36 dnl What is sizeof(mp_limb_t)?  (It has to match sizeof(uintD) later.)
37 AC_DEFUN([CL_GMP_SET_UINTD],
38 [AC_CACHE_CHECK([how large gmp demands uintD to be], cl_cv_gmp_set_uintd, [
39     AC_TRY_RUN([#include <gmp.h>
40 #include <stdio.h>
41 int main() {
42     FILE *f=fopen("conftestval", "w");
43     if (!f) return(255);
44     if (sizeof(mp_limb_t) > sizeof(long))
45         fprintf(f, "long long");
46     else if (sizeof(mp_limb_t) == sizeof(long))
47         fprintf(f, "long");
48     else if (sizeof(mp_limb_t) == sizeof(int))
49         fprintf(f, "int");
50     else return(sizeof(mp_limb_t));
51 #if defined(__GMP_BITS_PER_MP_LIMB)
52     /* Is there a nail in a limb? */
53     if (8*sizeof(mp_limb_t)!=__GMP_BITS_PER_MP_LIMB)
54         return(254);
55 #endif
56     return(0);
57 }], cl_cv_gmp_set_uintd=`cat conftestval`
58     cl_gmp_demands="GMP_DEMANDS_UINTD_`echo ${cl_cv_gmp_set_uintd} | sed -e 'y/ gilnot/_GILNOT/'`",
59     gmp_retval="$ac_status"
60     if test x$gmp_retval = "x255"; then AC_MSG_ERROR([error opening output file.]); fi
61     if test x$gmp_retval = "x254"; then AC_MSG_ERROR([nails in MP limbs are unsupported.]); fi
62     AC_MSG_ERROR([Don't know which C-type has sizeof $gmp_retval.]),
63     AC_MSG_ERROR([cross-compiling - cannot determine]))
64 ])
65 AC_DEFINE_UNQUOTED($cl_gmp_demands)
66 ])
67
68 dnl Whether or not to use GMP. Sets CL_USE_GMP.
69 dnl Also sets CPPFLAGS, LDFLAGS if --with-gmp=DIR was specified.
70 AC_DEFUN([CL_LIBGMP],
71 [AC_ARG_WITH(gmp, AS_HELP_STRING([--with-gmp@<:@=DIR@:>@],
72   [use external low-level functions from GNU MP (installed in prefix DIR) @<:@default=yes@:>@.]),[
73     with_gmp="$withval"
74   ],
75   with_gmp="yes")
76 case $with_gmp in
77   yes)
78     dnl --with-gmp
79     CL_GMP_H_VERSION
80     if test "$cl_cv_new_gmp_h" = yes; then
81       CL_GMP_CHECK
82       if test "$cl_cv_new_libgmp" = yes; then
83         CL_GMP_SET_UINTD
84         AC_DEFINE(CL_USE_GMP, 1, [Define if GNU MP library is available])
85       else
86         AC_MSG_WARN([The GNU MP library is too old to be used.])
87       fi
88     else
89       AC_MSG_WARN([The header file <gmp.h> is too old to be used.])
90     fi
91   ;;
92   no)
93     dnl --without-gmp
94   ;;
95   *)
96     dnl --with-gmp=DIR
97     case $withval in
98       [[\\/$]]* | ?:[[\\/]]* )
99       ;;
100       *) AC_MSG_ERROR([expected an absolute directory name for --with-gmp: $withval])
101       ;;
102     esac
103     saved_CPPFLAGS="$CPPFLAGS"
104     CPPFLAGS="$CPPFLAGS -I${withval}/include"
105     saved_LDFLAGS="$LDFLAGS"
106     LDFLAGS="$LDFLAGS -L${withval}/lib"
107     CL_GMP_H_VERSION
108     if test "$cl_cv_new_gmp_h" = yes; then
109       CL_GMP_CHECK
110       if test "$cl_cv_new_libgmp" = yes; then
111         CL_GMP_SET_UINTD
112         AC_DEFINE(CL_USE_GMP)
113       else
114         AC_MSG_WARN([The GNU MP library is too old to be used.])
115         CPPFLAGS="$saved_CPPFLAGS"
116         LDFLAGS="$saved_LDFLAGS"
117       fi
118     else
119       AC_MSG_WARN([The header file <gmp.h> is too old to be used.])
120       CPPFLAGS="$saved_CPPFLAGS"
121       LDFLAGS="$saved_LDFLAGS"
122     fi
123   ;;
124 esac
125 ])