bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] libgmp: add <gmp/gmp.h> support


From: Paul Eggert
Subject: [PATCH] libgmp: add <gmp/gmp.h> support
Date: Thu, 6 Aug 2020 14:53:41 -0700

* m4/libgmp.m4 (gl_LIBGMP):
* modules/libgmp (configure.ac, Makefile.am):
Support platforms requiring ‘#include <gmp/gmp.h>’ instead of
‘#include <gmp.h>’.
---
 ChangeLog      |  8 +++++
 m4/libgmp.m4   | 88 ++++++++++++++++++++++++++------------------------
 modules/libgmp | 11 +++++--
 3 files changed, 63 insertions(+), 44 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 26e33d964..d78accc3e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2020-08-06  Paul Eggert  <eggert@cs.ucla.edu>
+
+       libgmp: add <gmp/gmp.h> support
+       * m4/libgmp.m4 (gl_LIBGMP):
+       * modules/libgmp (configure.ac, Makefile.am):
+       Support platforms requiring ‘#include <gmp/gmp.h>’ instead of
+       ‘#include <gmp.h>’.
+
 2020-08-06  Bruno Haible  <bruno@clisp.org>
 
        Consider that clang defines __OPTIMIZE__ like GCC does.
diff --git a/m4/libgmp.m4 b/m4/libgmp.m4
index 82c065e2c..1025f06a7 100644
--- a/m4/libgmp.m4
+++ b/m4/libgmp.m4
@@ -1,4 +1,4 @@
-# libgmp.m4 serial 4
+# libgmp.m4 serial 5
 # Configure the GMP library or a replacement.
 dnl Copyright 2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
@@ -18,50 +18,54 @@ AC_DEFUN([gl_LIBGMP],
     [AS_HELP_STRING([--without-libgmp],
        [do not use the GNU Multiple Precision (GMP) library;
         this is the default on systems lacking libgmp.])])
-  case "$with_libgmp" in
-    no)
-      HAVE_LIBGMP=no
-      LIBGMP=
-      LTLIBGMP=
-      ;;
-    *)
-      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
-  if test $HAVE_LIBGMP = yes; then
+  HAVE_LIBGMP=no
+  LIBGMP=
+  LTLIBGMP=
+  AS_IF([test "$with_libgmp" != no],
+    [AC_CHECK_HEADERS([gmp.h gmp/gmp.h], [break])
+     dnl Prefer AC_LIB_HAVE_LINKFLAGS if the havelib module is also in use.
+     AS_IF([test "$ac_cv_header_gmp_h" = yes ||
+            test "$ac_cv_header_gmp_gmp_h" = yes],
+       [m4_ifdef([gl_HAVE_MODULE_HAVELIB],
+          [AC_LIB_HAVE_LINKFLAGS([gmp], [],
+             [#if HAVE_GMP_H
+              # include <gmp.h>
+              #else
+              # include <gmp/gmp.h>
+              #endif],
+             [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;;
+             -*)
+               HAVE_LIBGMP=yes
+               LIBGMP=$ac_cv_search___gmpz_roinit_n
+               LTLIBGMP=$LIBGMP;;
+           esac
+           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])
+  if test $HAVE_LIBGMP = yes && test "$ac_cv_header_gmp_h" = yes; then
     GMP_H=
   else
     GMP_H=gmp.h
   fi
   AC_SUBST([GMP_H])
-  AM_CONDITIONAL([GL_GENERATE_GMP_H], [test -n "$GMP_H"])
+  AM_CONDITIONAL([GL_GENERATE_MINI_GMP_H],
+    [test $HAVE_LIBGMP != yes])
+  AM_CONDITIONAL([GL_GENERATE_GMP_GMP_H],
+    [test $HAVE_LIBGMP = yes && test "$ac_cv_header_gmp_h" != yes])
 ])
diff --git a/modules/libgmp b/modules/libgmp
index a0c77056d..bfc62f8d8 100644
--- a/modules/libgmp
+++ b/modules/libgmp
@@ -11,22 +11,29 @@ Depends-on:
 
 configure.ac:
 gl_LIBGMP
-if test -n "$GMP_H"; then
+if test $HAVE_LIBGMP != yes; then
   AC_LIBOBJ([mini-gmp-gnulib])
 fi
 
 Makefile.am:
 BUILT_SOURCES += $(GMP_H)
 
+if GL_GENERATE_MINI_GMP_H
 # Build gmp.h as a wrapper for mini-gmp.h when using mini-gmp.
-if GL_GENERATE_GMP_H
 gmp.h: $(top_builddir)/config.status
        echo '#include "mini-gmp.h"' >$@-t
        mv $@-t $@
 else
+if GL_GENERATE_GMP_GMP_H
+# Build gmp.h as a wrapper for gmp/gmp.h.
+gmp.h: $(top_builddir)/config.status
+       echo '#include <gmp/gmp.h>' >$@-t
+       mv $@-t $@
+else
 gmp.h: $(top_builddir)/config.status
        rm -f $@
 endif
+endif
 MOSTLYCLEANFILES += gmp.h gmp.h-t
 
 Include:
-- 
2.17.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]