Skip to content

Commit 0c3b767

Browse files
authored
Autotools: Add pkg-config for GMP library (#15166)
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 da5362c commit 0c3b767

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

UPGRADING.INTERNALS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ PHP 8.4 INTERNALS UPGRADE NOTES
186186
used instead of the pkg-config search.
187187
- Added pkg-config support to find unixODBC and iODBC for the pdo_odbc
188188
extension.
189+
- Added pkg-config support to find GNU MP library. As a fallback default
190+
system paths are searched. When a directory argument is provided
191+
(--with-gmp=DIR), it will be used instead of the pkg-config.
189192
- Removed BC enable_pear variable check due to --enable-pear configure option
190193
once used (use with_pear variable name).
191194
- Cache variables synced to php_cv_* naming scheme. If you use them for

ext/gmp/config.m4

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
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. Use PKG_CONFIG_PATH (or GMP_CFLAGS and GMP_LIBS)
5+
environment variables, or alternatively the optional DIR argument to
6+
customize where to look for the GNU MP library.])])
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=no
24+
AC_CHECK_HEADER([gmp.h], [AC_CHECK_FUNC([__gmpz_rootrem], [gmp_check=yes])])
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], [no], [AC_MSG_FAILURE([
29+
The required GNU MP library version 4.2 or greater not found.
30+
])])
31+
32+
PHP_EVAL_LIBLINE([$GMP_LIBS], [GMP_SHARED_LIBADD])
33+
PHP_EVAL_INCLINE([$GMP_CFLAGS])
2834

2935
PHP_INSTALL_HEADERS([ext/gmp], [php_gmp_int.h])
3036

0 commit comments

Comments
 (0)