git-merge-changelog: Improve last commit.
[gnulib.git] / m4 / libgmp.m4
bloba82a6fa1b71a2cbda5f2b98486f65e0d2d0f9430
1 # libgmp.m4
2 # serial 8
3 # Configure the GMP library or a replacement.
4 dnl Copyright 2020-2024 Free Software Foundation, Inc.
5 dnl This file is free software; the Free Software Foundation
6 dnl gives unlimited permission to copy and/or distribute it,
7 dnl with or without modifications, as long as this notice is preserved.
9 dnl gl_LIBGMP
10 dnl Search for an installed libgmp.
11 dnl If found, set and AC_SUBST HAVE_LIBGMP=yes and the LIBGMP and LTLIBGMP
12 dnl variables, and augment the CPPFLAGS variable, and #define HAVE_LIBGMP to 1.
13 dnl Otherwise, set and AC_SUBST HAVE_LIBGMP=no and LIBGMP and LTLIBGMP to
14 dnl empty.
16 AC_DEFUN([gl_LIBGMP],
18   AC_ARG_WITH([libgmp],
19     [AS_HELP_STRING([[--without-libgmp]],
20        [do not use the GNU Multiple Precision (GMP) library;
21         this is the default on systems lacking libgmp.])])
22   HAVE_LIBGMP=no
23   LIBGMP=
24   LTLIBGMP=
25   AS_IF([test "$with_libgmp" != no],
26     [AC_CHECK_HEADERS([gmp.h gmp/gmp.h], [break])
27      dnl Prefer AC_LIB_HAVE_LINKFLAGS if the havelib module is also in use.
28      AS_IF([test "$ac_cv_header_gmp_h" = yes ||
29             test "$ac_cv_header_gmp_gmp_h" = yes],
30        [m4_ifdef([gl_HAVE_MODULE_HAVELIB],
31           [AC_LIB_HAVE_LINKFLAGS([gmp], [],
32              [#if HAVE_GMP_H
33               # include <gmp.h>
34               #else
35               # include <gmp/gmp.h>
36               #endif],
37              [static const mp_limb_t x[2] = { 0x73, 0x55 };
38               mpz_t tmp;
39               mpz_roinit_n (tmp, x, 2);
40              ],
41              [no])],
42           [gl_saved_LIBS=$LIBS
43            AC_SEARCH_LIBS([__gmpz_roinit_n], [gmp])
44            LIBS=$gl_saved_LIBS
45            case $ac_cv_search___gmpz_roinit_n in
46              'none needed')
47                HAVE_LIBGMP=yes;;
48              -*)
49                HAVE_LIBGMP=yes
50                LIBGMP=$ac_cv_search___gmpz_roinit_n
51                LTLIBGMP=$LIBGMP;;
52            esac
53            AC_SUBST([HAVE_LIBGMP])
54            AC_SUBST([LIBGMP])
55            AC_SUBST([LTLIBGMP])])])
56      if test "$with_libgmp,$HAVE_LIBGMP" = yes,no; then
57        AC_MSG_ERROR(
58          [GMP not found, although --with-libgmp was specified.m4_ifdef(
59             [AC_LIB_HAVE_LINKFLAGS],
60             [ Try specifying --with-libgmp-prefix=DIR.])])
61      fi])
62   if test $HAVE_LIBGMP = yes && test "$ac_cv_header_gmp_h" = yes; then
63     GL_GENERATE_GMP_H=false
64   else
65     GL_GENERATE_GMP_H=true
66   fi
67   gl_CONDITIONAL([GL_GENERATE_MINI_GMP_H],
68     [test $HAVE_LIBGMP != yes])
69   gl_CONDITIONAL([GL_GENERATE_GMP_GMP_H],
70     [test $HAVE_LIBGMP = yes && test "$ac_cv_header_gmp_h" != yes])