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