Skip to content

Commit 7996604

Browse files
committed
Autotools: Add pkg-config for GMP library
GMP has pkg-config integration since 2019-08-22 (version ~6.2.0). This optionally finds the GMP library using pkg-config or falls back to find library on the system or with the provided configure option argument (--with-gmp=DIR). When using DIR argument, the pkg-config check is silently skipped. When not using DIR argument, the GMP_CFLAGS and GMP_LIBS can be also used to find the GMP library: ./configure --with-gmp \ GMP_CFLAGS=-I/path/to/gmp/include \ GMP_LIBS="-L/path/to/gmp -lgmp"
1 parent 1251901 commit 7996604

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

ext/gmp/config.m4

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
11
PHP_ARG_WITH([gmp],
22
[for GNU MP support],
33
[AS_HELP_STRING([[--with-gmp[=DIR]]],
4-
[Include GNU MP support])])
4+
[Include GNU MP support. Optional DIR is the library installation directory.
5+
Also, the GMP_CFLAGS and GMP_LIBS environment variables can be used instead
6+
of the DIR argument to customize the GMP paths.])])
57

68
if test "$PHP_GMP" != "no"; then
7-
if test "$PHP_GMP" = "yes"; then
8-
PHP_CHECK_LIBRARY([gmp], [__gmpz_rootrem],
9-
[],
10-
[AC_MSG_FAILURE([GNU MP Library version 4.2 or greater required.])])
9+
gmp_found=no
10+
AS_VAR_IF([PHP_GMP], [yes],
11+
[PKG_CHECK_MODULES([GMP], [gmp >= 4.2], [gmp_found=yes], [:])])
1112

12-
PHP_ADD_LIBRARY([gmp],, [GMP_SHARED_LIBADD])
13-
else
14-
if test ! -f $PHP_GMP/include/gmp.h; then
15-
AC_MSG_ERROR([Unable to locate gmp.h])
16-
fi
13+
AS_VAR_IF([gmp_found], [no], [AS_VAR_IF([PHP_GMP], [yes], [GMP_LIBS=-lgmp], [
14+
GMP_LIBS="-L$PHP_GMP/$PHP_LIBDIR -lgmp"
15+
GMP_CFLAGS="-I$PHP_GMP/include"
16+
])])
1717

18-
PHP_CHECK_LIBRARY([gmp], [__gmpz_rootrem],
19-
[],
20-
[AC_MSG_FAILURE([GNU MP Library version 4.2 or greater required.])],
21-
[-L$PHP_GMP/$PHP_LIBDIR])
18+
dnl Sanity check.
19+
CFLAGS_SAVED=$CFLAGS
20+
LIBS_SAVED=$LIBS
21+
CFLAGS="$CFLAGS $GMP_CFLAGS"
22+
LIBS="$LIBS $GMP_LIBS"
23+
gmp_check=
24+
AC_CHECK_HEADER([gmp.h], [AC_CHECK_FUNC([__gmpz_rootrem], [gmp_check=ok])])
25+
CFLAGS=$CFLAGS_SAVED
26+
LIBS=$LIBS_SAVED
2227

23-
PHP_ADD_LIBRARY_WITH_PATH([gmp],
24-
[$PHP_GMP/$PHP_LIBDIR],
25-
[GMP_SHARED_LIBADD])
26-
PHP_ADD_INCLUDE([$PHP_GMP/include])
27-
fi
28+
AS_VAR_IF([gmp_check], [ok],, [AC_MSG_ERROR([
29+
GNU MP library check failed. GNU MP Library version 4.2 or greater required.
30+
Please, check config.log for details.
31+
])])
32+
33+
PHP_EVAL_LIBLINE([$GMP_LIBS], [GMP_SHARED_LIBADD])
34+
PHP_EVAL_INCLINE([$GMP_CFLAGS])
2835

2936
PHP_INSTALL_HEADERS([ext/gmp], [php_gmp_int.h])
3037

0 commit comments

Comments
 (0)