]> Savannah Git Hosting - gnulib.git/commitdiff
libgmp: Link to the correct shared library.
authorBruno Haible <bruno@clisp.org>
Sun, 12 Jul 2020 21:47:52 +0000 (23:47 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 12 Jul 2020 21:47:52 +0000 (23:47 +0200)
* m4/libgmp.m4 (gl_LIBGMP): Invoke AC_LIB_HAVE_LINKFLAGS.
* modules/libgmp (Depends-on): Add havelib.
(Link): Mention $(LIBGMP) and $(LTLIBGMP).
* modules/libgmp-tests (Makefile.am): Link test-libgmp with $(LIBGMP).

ChangeLog
m4/libgmp.m4
modules/libgmp
modules/libgmp-tests

index 8d71029d30a88035f292e93e19c311739da44970..2b58fa7796b51041873732264f20bff59afa17d5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2020-07-12  Bruno Haible  <bruno@clisp.org>
+
+       libgmp: Link to the correct shared library.
+       * m4/libgmp.m4 (gl_LIBGMP): Invoke AC_LIB_HAVE_LINKFLAGS.
+       * modules/libgmp (Depends-on): Add havelib.
+       (Link): Mention $(LIBGMP) and $(LTLIBGMP).
+       * modules/libgmp-tests (Makefile.am): Link test-libgmp with $(LIBGMP).
+
 2020-07-12  Bruno Haible  <bruno@clisp.org>
 
        libgmp tests: Add some safety checks.
index b569bb7346235c67c297c288dfbc9add056e32f4..7a8742e0c42653f64134bc0a0b0431bd060b5599 100644 (file)
@@ -1,44 +1,60 @@
+# libgmp.m4 serial 2
 # Configure the GMP library or a replacement.
-
 dnl Copyright 2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
 
+dnl gl_LIBGMP
+dnl Searches for an installed libgmp.
+dnl If found, it sets and AC_SUBSTs HAVE_LIBGMP=yes and the LIBGMP and LTLIBGMP
+dnl variables, and augments the CPPFLAGS variable, and #defines HAVE_LIBGMP
+dnl and HAVE_GMP to 1.
+dnl Otherwise, it sets and AC_SUBSTs HAVE_LIBGMP=no and LIBGMP and LTLIBGMP to
+dnl empty.
+
 AC_DEFUN([gl_LIBGMP],
 [
   AC_ARG_WITH([libgmp],
     [AS_HELP_STRING([--without-libgmp],
        [do not use the GNU Multiple Precision (GMP) library;
         this is the default on systems lacking libgmp.])])
-
-  AC_CHECK_HEADERS_ONCE([gmp.h])
-  GMP_H=gmp.h
-  LIB_GMP=
-
-  case $with_libgmp in
-    no) ;;
-    yes) GMP_H= LIB_GMP=-lgmp;;
-    *) if test "$ac_cv_header_gmp_h" = yes; then
-         gl_saved_LIBS=$LIBS
-         AC_SEARCH_LIBS([__gmpz_roinit_n], [gmp])
-         LIBS=$gl_saved_LIBS
-         case $ac_cv_search___gmpz_roinit_n in
-           'none needed')
-             GMP_H=;;
-           -*)
-             GMP_H= LIB_GMP=$ac_cv_search___gmpz_roinit_n;;
-         esac
-       fi;;
+  case "$with_libgmp" in
+    no)
+      HAVE_LIBGMP=no
+      LIBGMP=
+      LTLIBGMP=
+      ;;
+    *)
+      AC_LIB_HAVE_LINKFLAGS([gmp], [],
+        [#include <gmp.h>],
+        [static const mp_limb_t x[2] = { 0x73, 0x55 };
+         mpz_t tmp;
+         mpz_roinit_n (tmp, x, 2);
+        ],
+        [no])
+      if test $HAVE_LIBGMP = no; then
+        case "$with_libgmp" in
+          yes)
+            AC_MSG_ERROR([GMP not found, although --with-libgmp was specified. Try specifying --with-libgmp-prefix=DIR.])
+            ;;
+        esac
+      fi
+      ;;
   esac
-
-  if test -z "$GMP_H"; then
-    AC_DEFINE([HAVE_GMP], 1,
+  if test $HAVE_LIBGMP = yes; then
+    GMP_H=
+    dnl This is redundant, as HAVE_LIBGMP is also defined to 1.
+    AC_DEFINE([HAVE_GMP], [1],
       [Define to 1 if you have the GMP library instead of just the
        mini-gmp replacement.])
+  else
+    GMP_H=gmp.h
   fi
-
-  AC_SUBST([LIB_GMP])
   AC_SUBST([GMP_H])
   AM_CONDITIONAL([GL_GENERATE_GMP_H], [test -n "$GMP_H"])
+
+  dnl For backward compatibility.
+  LIB_GMP="$LIBGMP"
+  AC_SUBST([LIB_GMP])
 ])
index b686717680019f33e972f86ed4682ee04294bd72..70f20cf70c816d25a0f19161823d7cff21a2b1e6 100644 (file)
@@ -8,6 +8,7 @@ lib/mini-gmp.h
 m4/libgmp.m4
 
 Depends-on:
+havelib
 
 configure.ac:
 gl_LIBGMP
@@ -33,7 +34,7 @@ Include:
 <gmp.h>
 
 Link:
-$(LIB_GMP)
+$(LTLIBGMP) when linking with libtool, $(LIBGMP) otherwise
 
 License:
 LGPLv3+ or GPLv2+
index c01b876a10fcc3351b714afc91360adaf9dea502..94faf1cee649977dc8513d8872826685abd2fc7e 100644 (file)
@@ -10,4 +10,4 @@ configure.ac:
 Makefile.am:
 TESTS += test-libgmp
 check_PROGRAMS += test-libgmp
-test_libgmp_LDADD = $(LDADD) @LIB_GMP@
+test_libgmp_LDADD = $(LDADD) @LIBGMP@