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.

141 lines
4.9 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. dnl Note: we don't run any of compiled programs here, so this method
  35. dnl both works for native and cross compilation
  36. cl_gmp_demands="UNKNOWN"
  37. cl_gmp_has_nails="no"
  38. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <gmp.h>
  39. template<bool COND> struct Static_Assert;
  40. template<> struct Static_Assert<true> { };
  41. #if defined(__GMP_BITS_PER_MP_LIMB)
  42. Static_Assert<8*sizeof(mp_limb_t) == __GMP_BITS_PER_MP_LIMB> check;
  43. #endif]], [[]])], [], [cl_gmp_has_nails="yes"])
  44. if test "x$cl_gmp_has_nails" = "xyes"; then
  45. AC_MSG_ERROR([nails in MP libms are unsupported.])
  46. fi
  47. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <gmp.h>
  48. template<bool COND> struct Static_Assert;
  49. template<> struct Static_Assert<true> { };
  50. Static_Assert<(sizeof(mp_limb_t) > sizeof(long))> check;]], [[]])],
  51. [cl_gmp_demands='GMP_DEMANDS_UINTD_LONG_LONG'], [])
  52. if test "x$cl_gmp_demands" = "xUNKNOWN"; then
  53. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <gmp.h>
  54. template<bool COND> struct Static_Assert;
  55. template<> struct Static_Assert<true> { };
  56. Static_Assert<sizeof(mp_limb_t) == sizeof(long)> check;]], [[]])],
  57. [cl_gmp_demands='GMP_DEMANDS_UINTD_LONG'], [])
  58. fi
  59. if test "x$cl_gmp_demands" = "xUNKNOWN"; then
  60. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  61. #include <gmp.h>
  62. template<bool COND> struct Static_Assert;
  63. template<> struct Static_Assert<true> { };
  64. Static_Assert<sizeof(mp_limb_t) == sizeof(int)> check;]], [[]])],
  65. [cl_gmp_demands='GMP_DEMANDS_UINTD_INT'], [])
  66. fi
  67. if test "x$cl_gmp_demands" = "xUNKNOWN"; then
  68. AC_MSG_ERROR([Don't know which C-type has sizeof(mp_limb_t)])
  69. else
  70. cl_cv_gmp_set_uintd="$cl_gmp_demands"
  71. fi
  72. ])
  73. AC_DEFINE_UNQUOTED($cl_cv_gmp_set_uintd)
  74. ])
  75. dnl Whether or not to use GMP. Sets CL_USE_GMP.
  76. dnl Also sets CPPFLAGS, LDFLAGS if --with-gmp=DIR was specified.
  77. AC_DEFUN([CL_LIBGMP],
  78. [AC_ARG_WITH(gmp, AS_HELP_STRING([--with-gmp@<:@=DIR@:>@],
  79. [use external low-level functions from GNU MP (installed in prefix DIR) @<:@default=yes@:>@.]),[
  80. with_gmp="$withval"
  81. ],
  82. with_gmp="yes")
  83. case $with_gmp in
  84. yes)
  85. dnl --with-gmp
  86. CL_GMP_H_VERSION
  87. if test "$cl_cv_new_gmp_h" = yes; then
  88. CL_GMP_CHECK
  89. if test "$cl_cv_new_libgmp" = yes; then
  90. CL_GMP_SET_UINTD
  91. AC_DEFINE(CL_USE_GMP, 1, [Define if GNU MP library is available])
  92. else
  93. AC_MSG_WARN([The GNU MP library is too old to be used.])
  94. fi
  95. else
  96. AC_MSG_WARN([The header file <gmp.h> is too old to be used.])
  97. fi
  98. ;;
  99. no)
  100. dnl --without-gmp
  101. ;;
  102. *)
  103. dnl --with-gmp=DIR
  104. case $withval in
  105. [[\\/$]]* | ?:[[\\/]]* )
  106. ;;
  107. *) AC_MSG_ERROR([expected an absolute directory name for --with-gmp: $withval])
  108. ;;
  109. esac
  110. saved_CPPFLAGS="$CPPFLAGS"
  111. CPPFLAGS="$CPPFLAGS -I${withval}/include"
  112. saved_LDFLAGS="$LDFLAGS"
  113. LDFLAGS="$LDFLAGS -L${withval}/lib"
  114. AC_LIB_LINKFLAGS_FROM_LIBS([GMP_RPATH_CFG], [$LDFLAGS])
  115. LDFLAGS="$GMP_RPATH_CFG $LDFLAGS"
  116. AC_MSG_NOTICE([Using "\"$LDFLAGS\"" rpath to link with GMP])
  117. CL_GMP_H_VERSION
  118. if test "$cl_cv_new_gmp_h" = yes; then
  119. CL_GMP_CHECK
  120. if test "$cl_cv_new_libgmp" = yes; then
  121. CL_GMP_SET_UINTD
  122. AC_DEFINE(CL_USE_GMP)
  123. else
  124. AC_MSG_WARN([The GNU MP library is too old to be used.])
  125. CPPFLAGS="$saved_CPPFLAGS"
  126. LDFLAGS="$saved_LDFLAGS"
  127. fi
  128. else
  129. AC_MSG_WARN([The header file <gmp.h> is too old to be used.])
  130. CPPFLAGS="$saved_CPPFLAGS"
  131. LDFLAGS="$saved_LDFLAGS"
  132. fi
  133. ;;
  134. esac
  135. ])