libgmp: Link to the correct shared library.
[gnulib.git] / m4 / libgmp.m4
blob7a8742e0c42653f64134bc0a0b0431bd060b5599
1 # libgmp.m4 serial 2
2 # Configure the GMP library or a replacement.
3 dnl Copyright 2020 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 Searches for an installed libgmp.
10 dnl If found, it sets and AC_SUBSTs HAVE_LIBGMP=yes and the LIBGMP and LTLIBGMP
11 dnl variables, and augments the CPPFLAGS variable, and #defines HAVE_LIBGMP
12 dnl and HAVE_GMP to 1.
13 dnl Otherwise, it sets and AC_SUBSTs 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   case "$with_libgmp" in
23     no)
24       HAVE_LIBGMP=no
25       LIBGMP=
26       LTLIBGMP=
27       ;;
28     *)
29       AC_LIB_HAVE_LINKFLAGS([gmp], [],
30         [#include <gmp.h>],
31         [static const mp_limb_t x[2] = { 0x73, 0x55 };
32          mpz_t tmp;
33          mpz_roinit_n (tmp, x, 2);
34         ],
35         [no])
36       if test $HAVE_LIBGMP = no; then
37         case "$with_libgmp" in
38           yes)
39             AC_MSG_ERROR([GMP not found, although --with-libgmp was specified. Try specifying --with-libgmp-prefix=DIR.])
40             ;;
41         esac
42       fi
43       ;;
44   esac
45   if test $HAVE_LIBGMP = yes; then
46     GMP_H=
47     dnl This is redundant, as HAVE_LIBGMP is also defined to 1.
48     AC_DEFINE([HAVE_GMP], [1],
49       [Define to 1 if you have the GMP library instead of just the
50        mini-gmp replacement.])
51   else
52     GMP_H=gmp.h
53   fi
54   AC_SUBST([GMP_H])
55   AM_CONDITIONAL([GL_GENERATE_GMP_H], [test -n "$GMP_H"])
57   dnl For backward compatibility.
58   LIB_GMP="$LIBGMP"
59   AC_SUBST([LIB_GMP])