configure.ac: move gmp detection to a separate file
[isl.git] / m4 / ax_detect_gmp.m4
blob7748ff097f67b5c09ef053c526237d7c9c076b87
1 AC_DEFUN([AX_DETECT_GMP], [
2 AX_SUBMODULE(gmp,system|build,system)
3 case "$with_gmp" in
4 system)
5         if test "x$with_gmp_prefix" != "x"; then
6                 isl_configure_args="$isl_configure_args --with-gmp=$with_gmp_prefix"
7                 GMP_CPPFLAGS="-I$with_gmp_prefix/include"
8                 GMP_LDFLAGS="-L$with_gmp_prefix/lib"
9         fi
10         GMP_LIBS=-lgmp
11         SAVE_CPPFLAGS="$CPPFLAGS"
12         SAVE_LDFLAGS="$LDFLAGS"
13         SAVE_LIBS="$LIBS"
14         CPPFLAGS="$GMP_CPPFLAGS $CPPFLAGS"
15         LDFLAGS="$GMP_LDFLAGS $LDFLAGS"
16         LIBS="$GMP_LIBS $LIBS"
17         AC_CHECK_HEADER([gmp.h], [], [AC_ERROR([gmp.h header not found])])
18         AC_CHECK_LIB([gmp], [main], [], [AC_ERROR([gmp library not found])])
19         AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <gmp.h>]], [[
20                 mpz_t n, d;
21                 if (mpz_divisible_p(n, d))
22                         mpz_divexact_ui(n, n, 4);
23         ]])], [], [AC_ERROR([gmp library too old])])
24         CPPFLAGS="$SAVE_CPPFLAGS"
25         LDFLAGS="$SAVE_LDFLAGS"
26         LIBS="$SAVE_LIBS"
27         ;;
28 build)
29         GMP_CPPFLAGS="-I$gmp_srcdir -I$with_gmp_builddir"
30         GMP_LIBS="$with_gmp_builddir/libgmp.la"
31         ;;
32 esac
33 SAVE_CPPFLAGS="$CPPFLAGS"
34 SAVE_LDFLAGS="$LDFLAGS"
35 SAVE_LIBS="$LIBS"
36 CPPFLAGS="$GMP_CPPFLAGS $CPPFLAGS"
37 LDFLAGS="$GMP_LDFLAGS $LDFLAGS"
38 LIBS="$GMP_LIBS $LIBS"
39 need_get_memory_functions=false
40 AC_CHECK_DECLS(mp_get_memory_functions,[],[
41         need_get_memory_functions=true
42 ],[#include <gmp.h>])
43 CPPFLAGS="$SAVE_CPPFLAGS"
44 LDFLAGS="$SAVE_LDFLAGS"
45 LIBS="$SAVE_LIBS"
46 AM_CONDITIONAL(NEED_GET_MEMORY_FUNCTIONS, test x$need_get_memory_functions = xtrue)