Skip to content

Autotools: Add pkg-config for GMP library #15166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions UPGRADING.INTERNALS
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ PHP 8.4 INTERNALS UPGRADE NOTES
used instead of the pkg-config search.
- Added pkg-config support to find unixODBC and iODBC for the pdo_odbc
extension.
- Added pkg-config support to find GNU MP library. As a fallback default
system paths are searched. When a directory argument is provided
(--with-gmp=DIR), it will be used instead of the pkg-config.
- Removed BC enable_pear variable check due to --enable-pear configure option
once used (use with_pear variable name).
- Cache variables synced to php_cv_* naming scheme. If you use them for
Expand Down
44 changes: 25 additions & 19 deletions ext/gmp/config.m4
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
PHP_ARG_WITH([gmp],
[for GNU MP support],
[AS_HELP_STRING([[--with-gmp[=DIR]]],
[Include GNU MP support])])
[Include GNU MP support. Use PKG_CONFIG_PATH (or GMP_CFLAGS and GMP_LIBS)
environment variables, or alternatively the optional DIR argument to
customize where to look for the GNU MP library.])])

if test "$PHP_GMP" != "no"; then
if test "$PHP_GMP" = "yes"; then
PHP_CHECK_LIBRARY([gmp], [__gmpz_rootrem],
[],
[AC_MSG_FAILURE([GNU MP Library version 4.2 or greater required.])])
gmp_found=no
AS_VAR_IF([PHP_GMP], [yes],
[PKG_CHECK_MODULES([GMP], [gmp >= 4.2], [gmp_found=yes], [:])])

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

PHP_CHECK_LIBRARY([gmp], [__gmpz_rootrem],
[],
[AC_MSG_FAILURE([GNU MP Library version 4.2 or greater required.])],
[-L$PHP_GMP/$PHP_LIBDIR])
dnl Sanity check.
CFLAGS_SAVED=$CFLAGS
LIBS_SAVED=$LIBS
CFLAGS="$CFLAGS $GMP_CFLAGS"
LIBS="$LIBS $GMP_LIBS"
gmp_check=no
AC_CHECK_HEADER([gmp.h], [AC_CHECK_FUNC([__gmpz_rootrem], [gmp_check=yes])])
CFLAGS=$CFLAGS_SAVED
LIBS=$LIBS_SAVED

PHP_ADD_LIBRARY_WITH_PATH([gmp],
[$PHP_GMP/$PHP_LIBDIR],
[GMP_SHARED_LIBADD])
PHP_ADD_INCLUDE([$PHP_GMP/include])
fi
AS_VAR_IF([gmp_check], [no], [AC_MSG_FAILURE([
The required GNU MP library version 4.2 or greater not found.
])])

PHP_EVAL_LIBLINE([$GMP_LIBS], [GMP_SHARED_LIBADD])
PHP_EVAL_INCLINE([$GMP_CFLAGS])

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

Expand Down
Loading