You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
4.0 KiB

  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. dnl From Richard B. Kreckel.
  9. AC_PREREQ(2.13)
  10. dnl Is the gmp header file new enough? (should be implemented with an argument)
  11. AC_DEFUN([CL_GMP_H_VERSION],
  12. [AC_CACHE_CHECK([for recent enough gmp.h], cl_cv_new_gmp_h, [
  13. AC_TRY_CPP([#include <gmp.h>
  14. #if !defined(__GNU_MP_VERSION) || (__GNU_MP_VERSION < 3)
  15. #error "ancient gmp.h"
  16. #endif],
  17. cl_cv_new_gmp_h="yes", cl_cv_new_gmp_h="no")
  18. ])])dnl
  19. dnl Does libgmp provide some functionality introduced in version 3.0?
  20. AC_DEFUN([CL_GMP_CHECK],
  21. [AC_CACHE_CHECK([for working libgmp], cl_cv_new_libgmp, [
  22. SAVELIBS=$LIBS
  23. LIBS="$LIBS -lgmp"
  24. AC_TRY_LINK([#include <gmp.h>],[mpn_divexact_by3(0,0,0)],
  25. cl_cv_new_libgmp="yes", cl_cv_new_libgmp="no")
  26. LIBS=$SAVELIBS])
  27. if test "$cl_cv_new_libgmp" = yes; then
  28. LIBS="$LIBS -lgmp"
  29. fi
  30. ])
  31. dnl What is sizeof(mp_limb_t)? (It has to match sizeof(uintD) later.)
  32. AC_DEFUN([CL_GMP_SET_UINTD],
  33. [AC_CACHE_CHECK([how large gmp demands uintD to be], cl_cv_gmp_set_uintd, [
  34. AC_TRY_RUN([#include <gmp.h>
  35. #include <stdio.h>
  36. int main() {
  37. FILE *f=fopen("conftestval", "w");
  38. if (!f) return(255);
  39. if (sizeof(mp_limb_t) > sizeof(long))
  40. fprintf(f, "long long");
  41. else if (sizeof(mp_limb_t) == sizeof(long))
  42. fprintf(f, "long");
  43. else if (sizeof(mp_limb_t) == sizeof(int))
  44. fprintf(f, "int");
  45. else return(sizeof(mp_limb_t));
  46. #if defined(__GMP_BITS_PER_MP_LIMB)
  47. /* Is there a nail in a limb? */
  48. if (8*sizeof(mp_limb_t)!=__GMP_BITS_PER_MP_LIMB)
  49. return(254);
  50. #endif
  51. return(0);
  52. }], cl_cv_gmp_set_uintd=`cat conftestval`
  53. cl_gmp_demands="GMP_DEMANDS_UINTD_`echo ${cl_cv_gmp_set_uintd} | sed -e 'y/ gilnot/_GILNOT/'`",
  54. gmp_retval="$ac_status"
  55. if test x$gmp_retval = "x255"; then AC_MSG_ERROR([error opening output file.]); fi
  56. if test x$gmp_retval = "x254"; then AC_MSG_ERROR([nails in MP limbs are unsupported.]); fi
  57. AC_MSG_ERROR([Don't know which C-type has sizeof $gmp_retval.]),
  58. AC_MSG_ERROR([cross-compiling - cannot determine]))
  59. ])
  60. AC_DEFINE_UNQUOTED($cl_gmp_demands)
  61. ])
  62. dnl Whether or not to use GMP. Sets CL_USE_GMP.
  63. dnl Also sets CPPFLAGS, LDFLAGS if --with-gmp=DIR was specified.
  64. AC_DEFUN([CL_LIBGMP],
  65. [AC_ARG_WITH(gmp, AS_HELP_STRING([--with-gmp@<:@=DIR@:>@],
  66. [use external low-level functions from GNU MP (installed in prefix DIR) @<:@default=yes@:>@.]),[
  67. with_gmp="$withval"
  68. ],
  69. with_gmp="yes")
  70. case $with_gmp in
  71. yes)
  72. dnl --with-gmp
  73. CL_GMP_H_VERSION
  74. if test "$cl_cv_new_gmp_h" = yes; then
  75. CL_GMP_CHECK
  76. if test "$cl_cv_new_libgmp" = yes; then
  77. CL_GMP_SET_UINTD
  78. AC_DEFINE(CL_USE_GMP, 1, [Define if GNU MP library is available])
  79. else
  80. AC_MSG_WARN([The GNU MP library is too old to be used.])
  81. fi
  82. else
  83. AC_MSG_WARN([The header file <gmp.h> is too old to be used.])
  84. fi
  85. ;;
  86. no)
  87. dnl --without-gmp
  88. ;;
  89. *)
  90. dnl --with-gmp=DIR
  91. case $withval in
  92. [[\\/$]]* | ?:[[\\/]]* )
  93. ;;
  94. *) AC_MSG_ERROR([expected an absolute directory name for --with-gmp: $withval])
  95. ;;
  96. esac
  97. saved_CPPFLAGS="$CPPFLAGS"
  98. CPPFLAGS="$CPPFLAGS -I${withval}/include"
  99. saved_LDFLAGS="$LDFLAGS"
  100. LDFLAGS="$LDFLAGS -L${withval}/lib"
  101. CL_GMP_H_VERSION
  102. if test "$cl_cv_new_gmp_h" = yes; then
  103. CL_GMP_CHECK
  104. if test "$cl_cv_new_libgmp" = yes; then
  105. CL_GMP_SET_UINTD
  106. AC_DEFINE(CL_USE_GMP)
  107. else
  108. AC_MSG_WARN([The GNU MP library is too old to be used.])
  109. CPPFLAGS="$saved_CPPFLAGS"
  110. LDFLAGS="$saved_LDFLAGS"
  111. fi
  112. else
  113. AC_MSG_WARN([The header file <gmp.h> is too old to be used.])
  114. CPPFLAGS="$saved_CPPFLAGS"
  115. LDFLAGS="$saved_LDFLAGS"
  116. fi
  117. ;;
  118. esac
  119. ])