[PPL-devel] Re: ac_check_gmp.m4 in ppl

Bruno Haible bruno at clisp.org
Mon Oct 27 16:58:48 CET 2003


Dear Roberto,

> I must say I
> was aware of the problem but could not find a portable solution (I know too
> little about shared libraries and libtool and so on and never find the time
> to fill this gap).

AC_LIB_LINKFLAGS is meant to be this portable solution.

> I agree the problem is very annoying: for example, if you happen to have
> one libgmp installed into a standard location, but you want to experiment
> with another version of libgmp, our --with-gmp-* options are of little
> help.
>
> Would you be so kind to tell us more about the solution you suggest?
> Is adding AC_LIB_LINKFLAGS(gmpxx, gmp) to configure.ac really all what
> needs to be done?  Shouldn't ac_check_gmp.m4 also be modified so that
> the directory specified with the option --with-gmp-dir can be taken
> into account?

When you do AC_LIB_LINKFLAGS(gmpxx, gmp), the configure script will
automatically accept an option --with-libgmpxx-dir=<someDirectory>
though which the user can specify where he instealled libgmpxx.
In your current scheme, the equivalent options would be

  --with-libgmpxx-includes=<someDirectory>/include \
  --with-libgmpxx-lib=<someDirectory>/lib

The AC_LIB_LINKFLAGS macro also looks in $prefix, i.e. if the user
has specified --prefix=<someDirectory> and does not specify
--with-libgmpxx-dir, then the macros will look in $prefix/include and
$prefix/lib. (Because it's quite common that prerequisites have already
been installed with the same --prefix.)

In ac_check_gmp.m4 you also check whether the library is really present.
I'd order the checks as follows:

  1) [Optional] Call AC_LIB_LINKFLAGS(gmp).
  2) Call AC_LIB_LINKFLAGS(gmpxx, gmp). This sets the variable LIBGMPXX
     and augments CPPFLAGS. If the library isn't found, LIBGMPXX will
     just be "-lgmpxx -lgmp".
  3) Now temporarily augment LIBS
       ac_save_LIBS=$LIBS
       compile and run the test program
       LIBS=$ac_save_LIBS

And in the Makefiles, you add @LTLIBGMPXX@ to the link command line. That's
it.

ac_check_gmp.m4 will then look similar the one below (untested).

> I also guess the position into configure.ac must be chosen carefully.

Yes. Since the macro changes CPPFLAGS, it should come right after the
detection of the C/C++ compiler, before other checks for include files
and libraries.

And you will need a copy of config.rpath in your package. That's needed
since runpath handling is so platform dependent.

Best,
              Bruno


=========================================================================
dnl A function to check for the existence and usability of GMP.
dnl Copyright (C) 2001-2003 Roberto Bagnara <bagnara at cs.unipr.it>
dnl
dnl This file is part of the Parma Polyhedra Library (PPL).
dnl
dnl The PPL is free software; you can redistribute it and/or modify it
dnl under the terms of the GNU General Public License as published by the
dnl Free Software Foundation; either version 2 of the License, or (at your
dnl option) any later version.
dnl
dnl The PPL is distributed in the hope that it will be useful, but WITHOUT
dnl ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dnl FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dnl for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with this program; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
dnl USA.
dnl
dnl For the most up-to-date information see the Parma Polyhedra Library
dnl site: http://www.cs.unipr.it/ppl/ .
dnl
AC_DEFUN([AC_CHECK_GMP],
[
dnl Check how to link with libgmp.
AC_LIB_LINKFLAGS([gmp])

dnl Check how to link with libgmpxx.
AC_LIB_LINKFLAGS([gmpxx], [gmp])

ac_save_LIBS="$LIBS"
LIBS="$LIBS $LIBGMPXX"
AC_LANG_PUSH(C++)

AC_MSG_CHECKING([for the GMP library])
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <gmpxx.h>

using namespace std;

int main() {
  mpz_class pie("3141592653589793238462643383279502884");
  exit(0);
}
]])],
  AC_MSG_RESULT(yes)
  ac_cv_have_gmp=yes,
  AC_MSG_RESULT(no)
  ac_cv_have_gmp=no,
  AC_MSG_RESULT(no)
  ac_cv_have_gmp=no)

have_gmp=${ac_cv_have_gmp}

if test x"$ac_cv_have_gmp" = xyes
then

AC_MSG_CHECKING([size of GMP mp_limb_t])
ac_cv_sizeof_mp_limb_t=none
for size in 2 4 8
do
  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#include <gmp.h>

int main() {
  switch (0) {
  case 0:
  case (sizeof(mp_limb_t) == $size):
    ;
  }
  return 0;
}
]])],
    ac_cv_sizeof_mp_limb_t=$size; break)
done
AC_MSG_RESULT($size)
AC_DEFINE_UNQUOTED(SIZEOF_MP_LIMB_T, $size,
  [Size of GMP's mp_limb_t.])

AC_MSG_CHECKING([whether GMP has been compiled with support for exceptions])
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <gmpxx.h>
#include <new>
#include <cstddef>
#include <cstdlib>

using namespace std;

static void*
x_malloc(size_t) {
  throw bad_alloc();
}

static void*
x_realloc(void*, size_t, size_t) {
  throw bad_alloc();
}

static void
x_free(void*, size_t) {
}

int main() {
  mp_set_memory_functions(x_malloc, x_realloc, x_free);
  try {
    mpz_class pie("3141592653589793238462643383279502884");
  }
  catch (bad_alloc) {
    exit(0);
  }
  exit(1);
}
]])],
  AC_MSG_RESULT(yes)
  ac_cv_gmp_supports_exceptions=yes,
  AC_MSG_RESULT(no)
  ac_cv_gmp_supports_exceptions=no,
  AC_MSG_RESULT(no)
  ac_cv_gmp_supports_exceptions=no)

gmp_supports_exceptions=${ac_cv_gmp_supports_exceptions}
if test x"$gmp_supports_exceptions" = xyes
then
  value=1
else
  value=0
fi
AC_DEFINE_UNQUOTED(GMP_SUPPORTS_EXCEPTIONS, $value,
  [Not zero if GMP has been compiled with support for exceptions.])

fi

AC_LANG_POP(C++)
LIBS="$ac_save_LIBS"

dnl We use libtool, therefore we take $LTLIBGMPXX, not $LIBGMPXX.
gmp_library_option="$LTLIBGMPXX"
])




More information about the PPL-devel mailing list