PageRenderTime 38ms CodeModel.GetById 26ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/cln-1.3.2/m4/gmp.m4

#
m4 | 141 lines | 129 code | 6 blank | 6 comment | 0 complexity | cdb70461c472b1a1ccef291e1fd5076c MD5 | raw file
Possible License(s): GPL-2.0
  1dnl -*- Autoconf -*-
  2dnl Copyright (C) 1993-2008 Free Software Foundation, Inc.
  3dnl This file is free software, distributed under the terms of the GNU
  4dnl General Public License.  As a special exception to the GNU General
  5dnl Public License, this file may be distributed as part of a program
  6dnl that contains a configuration script generated by Autoconf, under
  7dnl the same distribution terms as the rest of that program.
  8
  9dnl From Richard B. Kreckel.
 10
 11AC_PREREQ(2.13)
 12
 13dnl Is the gmp header file new enough? (should be implemented with an argument)
 14AC_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],
 20cl_cv_new_gmp_h="yes", cl_cv_new_gmp_h="no")
 21])])dnl
 22
 23dnl Does libgmp provide some functionality introduced in version 3.0?
 24AC_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)],
 29cl_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
 36dnl What is sizeof(mp_limb_t)?  (It has to match sizeof(uintD) later.)
 37AC_DEFUN([CL_GMP_SET_UINTD],
 38[AC_CACHE_CHECK([how large gmp demands uintD to be], cl_cv_gmp_set_uintd, [
 39    dnl Note: we don't run any of compiled programs here, so this method
 40    dnl both works for native and cross compilation
 41    cl_gmp_demands="UNKNOWN"
 42    cl_gmp_has_nails="no"
 43    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <gmp.h>
 44	 template<bool COND> struct Static_Assert;
 45	 template<> struct Static_Assert<true> { };
 46	 #if defined(__GMP_BITS_PER_MP_LIMB)
 47         Static_Assert<8*sizeof(mp_limb_t) == __GMP_BITS_PER_MP_LIMB> check;
 48	 #endif]], [[]])], [], [cl_gmp_has_nails="yes"])
 49    if test "x$cl_gmp_has_nails" = "xyes"; then
 50        AC_MSG_ERROR([nails in MP libms are unsupported.])
 51    fi
 52    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <gmp.h>
 53	 template<bool COND> struct Static_Assert;
 54	 template<> struct Static_Assert<true> { };
 55	 Static_Assert<sizeof(mp_limb_t) > sizeof(long)> check;]], [[]])],
 56	 [cl_gmp_demands='GMP_DEMANDS_UINTD_LONG_LONG'], [])
 57    if test "x$cl_gmp_demands" = "xUNKNOWN"; then
 58	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <gmp.h>
 59	     template<bool COND> struct Static_Assert;
 60	     template<> struct Static_Assert<true> { };
 61	     Static_Assert<sizeof(mp_limb_t) == sizeof(long)> check;]], [[]])],
 62	     [cl_gmp_demands='GMP_DEMANDS_UINTD_LONG'], [])
 63    fi
 64    if test "x$cl_gmp_demands" = "xUNKNOWN"; then
 65        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
 66             #include <gmp.h>
 67	     template<bool COND> struct Static_Assert;
 68	     template<> struct Static_Assert<true> { };
 69	     Static_Assert<sizeof(mp_limb_t) == sizeof(int)> check;]], [[]])],
 70	     [cl_gmp_demands='GMP_DEMANDS_UINTD_INT'], [])
 71    fi
 72    if test "x$cl_gmp_demands" = "xUNKNOWN"; then
 73	AC_MSG_ERROR([Don't know which C-type has sizeof(mp_limb_t)])
 74    else
 75        cl_cv_gmp_set_uintd="$cl_gmp_demands"
 76    fi 
 77    ])
 78AC_DEFINE_UNQUOTED($cl_cv_gmp_set_uintd)
 79])
 80
 81dnl Whether or not to use GMP. Sets CL_USE_GMP.
 82dnl Also sets CPPFLAGS, LDFLAGS if --with-gmp=DIR was specified.
 83AC_DEFUN([CL_LIBGMP],
 84[AC_ARG_WITH(gmp, AS_HELP_STRING([--with-gmp@<:@=DIR@:>@],
 85  [use external low-level functions from GNU MP (installed in prefix DIR) @<:@default=yes@:>@.]),[
 86    with_gmp="$withval"
 87  ],
 88  with_gmp="yes")
 89case $with_gmp in
 90  yes)
 91    dnl --with-gmp
 92    CL_GMP_H_VERSION
 93    if test "$cl_cv_new_gmp_h" = yes; then
 94      CL_GMP_CHECK
 95      if test "$cl_cv_new_libgmp" = yes; then
 96        CL_GMP_SET_UINTD
 97        AC_DEFINE(CL_USE_GMP, 1, [Define if GNU MP library is available])
 98      else
 99        AC_MSG_WARN([The GNU MP library is too old to be used.])
100      fi
101    else
102      AC_MSG_WARN([The header file <gmp.h> is too old to be used.])
103    fi
104  ;;
105  no)
106    dnl --without-gmp
107  ;;
108  *)
109    dnl --with-gmp=DIR
110    case $withval in
111      [[\\/$]]* | ?:[[\\/]]* )
112      ;;
113      *) AC_MSG_ERROR([expected an absolute directory name for --with-gmp: $withval])
114      ;;
115    esac
116    saved_CPPFLAGS="$CPPFLAGS"
117    CPPFLAGS="$CPPFLAGS -I${withval}/include"
118    saved_LDFLAGS="$LDFLAGS"
119    LDFLAGS="$LDFLAGS -L${withval}/lib"
120    AC_LIB_LINKFLAGS_FROM_LIBS([GMP_RPATH_CFG], [$LDFLAGS])
121    LDFLAGS="$GMP_RPATH_CFG $LDFLAGS"
122    AC_MSG_NOTICE([Using "\"$LDFLAGS\"" rpath to link with GMP])
123    CL_GMP_H_VERSION
124    if test "$cl_cv_new_gmp_h" = yes; then
125      CL_GMP_CHECK
126      if test "$cl_cv_new_libgmp" = yes; then
127        CL_GMP_SET_UINTD
128        AC_DEFINE(CL_USE_GMP)
129      else
130        AC_MSG_WARN([The GNU MP library is too old to be used.])
131        CPPFLAGS="$saved_CPPFLAGS"
132        LDFLAGS="$saved_LDFLAGS"
133      fi
134    else
135      AC_MSG_WARN([The header file <gmp.h> is too old to be used.])
136      CPPFLAGS="$saved_CPPFLAGS"
137      LDFLAGS="$saved_LDFLAGS"
138    fi
139  ;;
140esac
141])