bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Bruno Haible <bruno@clisp.org>
Cc: bug-gnulib@gnu.org, jemarch@gnu.org
Subject: Re: libgmp: link to the correct shared library
Date: Sun, 26 Jul 2020 10:23:11 -0700	[thread overview]
Message-ID: <9bb81c43-ca8a-cccd-5d8e-a463fcd861ff@cs.ucla.edu> (raw)
In-Reply-To: <8009390.Ai7DkcWk9P@omega>

[-- Attachment #1: Type: text/plain, Size: 2063 bytes --]

On 7/23/20 5:00 PM, Bruno Haible wrote:

> GNU poke is likely to use GMP soon. When it does that, it will of course use
> the module 'libgmp'. And this package happens to use libtool.

That's fine, all I'm asking for is the ability to use libgmp without using 
havelib. A package that uses havelib shouldn't be affected.

> You can. For uses of system-wide installed GMP, nothing changes. For users who
> built GMP on their own, there is the configure option --with-libgmp-prefix. If
> there is a problem with it, you can redirect the reports to bug-gnulib or me.

That --with-libgmp-prefix worries me, for Emacs in particular. The Emacs folks 
are already somewhat resistent to Gnulib and want to minimize the attendant 
configury. I doubt whether they'd like to add instructions for 
--with-libgmp-prefix, --with-libxyz-prefix, etc. to their documentation. 
Instead, they use pkg-config for many libraries, and this works reasonably well 
for them. I'd rather not add yet another way to do libraries.

I can envision another problem with the havelib approach. For a program like 
Emacs that links many libraries, there is a performance overhead to having a 
long -rpath, so it makes sense to have a single directory (/home/eggert/lib, 
say) for all my personal libraries. But if I do that, then GNU coreutils 
'factor' will have /home/eggert/lib in its rpath whereas 'sort' won't (because 
'sort' doesn't use GMP). And then if I improve glibc and place an improved 
version into /home/eggert/lib, this will affect 'factor' but not 'sort' because 
'factor' is linked with $(LIBGMP) but 'sort' is not. This will be confusing.

There is an irreducible amount of complexity in dynamic linking. I don't much 
like the traditional approach of using -Wl,-rpath in LDFLAGS, and I don't much 
like pkg-config either. It is a pain no matter what we do.

To work around the immediate problem (since this is blocking gnulib integration 
into Emacs) I installed the attached patches into Gnulib. (The first one should 
be routine.) Perhaps we can think of something better.

[-- Attachment #2: 0001-libgmp-remove-HAVE_GMP-LIB_GMP.patch --]
[-- Type: text/x-patch, Size: 2361 bytes --]

From 6e9f94e9b4478b6f32f2da10891239187aed5ea2 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sat, 25 Jul 2020 17:42:18 -0700
Subject: [PATCH 1/2] libgmp: remove HAVE_GMP, LIB_GMP
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* m4/libgmp.m4 (gl_LIBGMP): Do not define HAVE_GMP and LIB_GMP, as
they’re redundant.  I’ll adjust GNU Coreutils accordingly.
---
 ChangeLog    |  6 ++++++
 m4/libgmp.m4 | 13 ++-----------
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0db10799c..44ce5301b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2020-07-26  Paul Eggert  <eggert@cs.ucla.edu>
+
+	libgmp: remove HAVE_GMP, LIB_GMP
+	* m4/libgmp.m4 (gl_LIBGMP): Do not define HAVE_GMP and LIB_GMP, as
+	they’re redundant.  I’ll adjust GNU Coreutils accordingly.
+
 2020-07-26  Bruno Haible  <bruno@clisp.org>
 
 	inttypes: Remove support for AIX 4.
diff --git a/m4/libgmp.m4 b/m4/libgmp.m4
index 7a8742e0c..e48b5c2c2 100644
--- a/m4/libgmp.m4
+++ b/m4/libgmp.m4
@@ -1,4 +1,4 @@
-# libgmp.m4 serial 2
+# libgmp.m4 serial 3
 # Configure the GMP library or a replacement.
 dnl Copyright 2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
@@ -8,8 +8,7 @@ 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 variables, and augments the CPPFLAGS variable, and #defines HAVE_LIBGMP.
 dnl Otherwise, it sets and AC_SUBSTs HAVE_LIBGMP=no and LIBGMP and LTLIBGMP to
 dnl empty.
 
@@ -44,17 +43,9 @@ AC_DEFUN([gl_LIBGMP],
   esac
   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([GMP_H])
   AM_CONDITIONAL([GL_GENERATE_GMP_H], [test -n "$GMP_H"])
-
-  dnl For backward compatibility.
-  LIB_GMP="$LIBGMP"
-  AC_SUBST([LIB_GMP])
 ])
-- 
2.17.1


[-- Attachment #3: 0002-libgmp-remove-dependency-on-havelib.patch --]
[-- Type: text/x-patch, Size: 4857 bytes --]

From b1384cb6d48be0ad007bac61aba6f1557937f130 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sun, 26 Jul 2020 09:57:47 -0700
Subject: [PATCH 2/2] libgmp: remove dependency on havelib

* m4/libgmp.m4 (gl_LIBGMP): If gl_HAVE_MODULE_HAVELIB is not defined,
use the more-traditional AC_SEARCH_LIBS approach.
This should work better with GNU Emacs configuration,
which uses pkg-config instead of a havelib-style approach.
* modules/havelib (gl_HAVE_MODULE_HAVELIB): New witness macro.
* modules/libgmp (Depends-on): Remove havelib.
---
 ChangeLog       |  8 ++++++++
 m4/libgmp.m4    | 52 ++++++++++++++++++++++++++++++++-----------------
 modules/havelib |  1 +
 modules/libgmp  |  1 -
 4 files changed, 43 insertions(+), 19 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 44ce5301b..aee21afed 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2020-07-26  Paul Eggert  <eggert@cs.ucla.edu>
 
+	libgmp: remove dependency on havelib
+	* m4/libgmp.m4 (gl_LIBGMP): If gl_HAVE_MODULE_HAVELIB is not defined,
+	use the more-traditional AC_SEARCH_LIBS approach.
+	This should work better with GNU Emacs configuration,
+	which uses pkg-config instead of a havelib-style approach.
+	* modules/havelib (gl_HAVE_MODULE_HAVELIB): New witness macro.
+	* modules/libgmp (Depends-on): Remove havelib.
+
 	libgmp: remove HAVE_GMP, LIB_GMP
 	* m4/libgmp.m4 (gl_LIBGMP): Do not define HAVE_GMP and LIB_GMP, as
 	they’re redundant.  I’ll adjust GNU Coreutils accordingly.
diff --git a/m4/libgmp.m4 b/m4/libgmp.m4
index e48b5c2c2..82c065e2c 100644
--- a/m4/libgmp.m4
+++ b/m4/libgmp.m4
@@ -1,4 +1,4 @@
-# libgmp.m4 serial 3
+# libgmp.m4 serial 4
 # Configure the GMP library or a replacement.
 dnl Copyright 2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
@@ -6,10 +6,10 @@ 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 Otherwise, it sets and AC_SUBSTs HAVE_LIBGMP=no and LIBGMP and LTLIBGMP to
+dnl Search for an installed libgmp.
+dnl If found, set and AC_SUBST HAVE_LIBGMP=yes and the LIBGMP and LTLIBGMP
+dnl variables, and augment the CPPFLAGS variable, and #define HAVE_LIBGMP to 1.
+dnl Otherwise, set and AC_SUBST HAVE_LIBGMP=no and LIBGMP and LTLIBGMP to
 dnl empty.
 
 AC_DEFUN([gl_LIBGMP],
@@ -25,19 +25,35 @@ AC_DEFUN([gl_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
+      dnl Prefer AC_LIB_HAVE_LINKFLAGS if the havelib module is also in use.
+      m4_ifdef([gl_HAVE_MODULE_HAVELIB],
+        [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])],
+        [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')
+             HAVE_LIBGMP=yes LIBGMP=;;
+           -*)
+             HAVE_LIBGMP=yes LIBGMP=$ac_cv_search___gmpz_roinit_n;;
+           *)
+             HAVE_LIBGMP=no LIBGMP=;;
+         esac
+         LTLIBGMP=$LIBGMP
+         AC_SUBST([HAVE_LIBGMP])
+         AC_SUBST([LIBGMP])
+         AC_SUBST([LTLIBGMP])])
+      if test "$with_libgmp,$HAVE_LIBGMP" = yes,no; then
+        AC_MSG_ERROR(
+          [GMP not found, although --with-libgmp was specified.m4_ifdef(
+             [AC_LIB_HAVE_LINKFLAGS],
+             [ Try specifying --with-libgmp-prefix=DIR.])])
       fi
       ;;
   esac
diff --git a/modules/havelib b/modules/havelib
index e47dbfc11..2d8dd57f5 100644
--- a/modules/havelib
+++ b/modules/havelib
@@ -11,6 +11,7 @@ build-aux/config.rpath
 Depends-on:
 
 configure.ac:
+AC_DEFUN([gl_HAVE_MODULE_HAVELIB])
 
 Makefile.am:
 
diff --git a/modules/libgmp b/modules/libgmp
index 70f20cf70..a0c77056d 100644
--- a/modules/libgmp
+++ b/modules/libgmp
@@ -8,7 +8,6 @@ lib/mini-gmp.h
 m4/libgmp.m4
 
 Depends-on:
-havelib
 
 configure.ac:
 gl_LIBGMP
-- 
2.17.1


  reply	other threads:[~2020-07-26 17:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-07  2:03 [PATCH] libgmp: new module Paul Eggert
2020-07-12 20:30 ` Bruno Haible
2020-07-12 20:57 ` libgmp tests: Add some safety checks Bruno Haible
2020-07-12 21:48   ` libgmp: link to the correct shared library Bruno Haible
2020-07-23 22:13     ` Paul Eggert
2020-07-23 22:30       ` Bruno Haible
2020-07-23 23:23         ` Paul Eggert
2020-07-24  0:00           ` Bruno Haible
2020-07-26 17:23             ` Paul Eggert [this message]
2020-07-26 17:54             ` Paul Eggert
2020-07-12 21:57 ` libgmp: Avoid warning when --without-libgmp is used Bruno Haible

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9bb81c43-ca8a-cccd-5d8e-a463fcd861ff@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=jemarch@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).