gh-115119: Detect _decimal dependencies using pkg-config (#115406)

pkg-config is supported for libmpdec 4.0.0 and newer.
This commit is contained in:
Erlend E. Aasland 2024-04-29 08:58:57 +02:00 committed by GitHub
parent ab6eda0ee5
commit c7e7bfc4ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 211 additions and 104 deletions

View File

@ -389,6 +389,17 @@ Options for third-party dependencies
C compiler and linker flags for ``libffi``, used by :mod:`ctypes` module,
overriding ``pkg-config``.
.. option:: LIBMPDEC_CFLAGS
.. option:: LIBMPDEC_LIBS
C compiler and linker flags for ``libmpdec``, used by :mod:`decimal` module,
overriding ``pkg-config``.
.. note::
These environment variables have no effect unless
:option:`--with-system-libmpdec` is specified.
.. option:: LIBLZMA_CFLAGS
.. option:: LIBLZMA_LIBS
@ -798,6 +809,8 @@ Libraries options
.. versionadded:: 3.3
.. seealso:: :option:`LIBMPDEC_CFLAGS` and :option:`LIBMPDEC_LIBS`.
.. option:: --with-readline=readline|editline
Designate a backend library for the :mod:`readline` module.

View File

@ -0,0 +1,2 @@
:program:`configure` now uses :program:`pkg-config` to detect :mod:`decimal`
dependencies if the :option:`--with-system-libmpdec` option is given.

View File

@ -34,7 +34,19 @@
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_typeobject.h"
#include "complexobject.h"
#include "mpdecimal.h"
#include <mpdecimal.h>
// Reuse config from mpdecimal.h if present.
#if defined(MPD_CONFIG_64)
#ifndef CONFIG_64
#define CONFIG_64 MPD_CONFIG_64
#endif
#elif defined(MPD_CONFIG_32)
#ifndef CONFIG_32
#define CONFIG_32 MPD_CONFIG_32
#endif
#endif
#include <ctype.h> // isascii()
#include <stdlib.h>

165
configure generated vendored
View File

@ -880,6 +880,7 @@ TCLTK_CFLAGS
LIBSQLITE3_LIBS
LIBSQLITE3_CFLAGS
LIBMPDEC_INTERNAL
LIBMPDEC_LIBS
LIBMPDEC_CFLAGS
MODULE__CTYPES_MALLOC_CLOSURE
LIBFFI_LIBS
@ -1148,6 +1149,8 @@ LIBUUID_CFLAGS
LIBUUID_LIBS
LIBFFI_CFLAGS
LIBFFI_LIBS
LIBMPDEC_CFLAGS
LIBMPDEC_LIBS
LIBSQLITE3_CFLAGS
LIBSQLITE3_LIBS
TCLTK_CFLAGS
@ -1969,6 +1972,10 @@ Some influential environment variables:
LIBFFI_CFLAGS
C compiler flags for LIBFFI, overriding pkg-config
LIBFFI_LIBS linker flags for LIBFFI, overriding pkg-config
LIBMPDEC_CFLAGS
C compiler flags for LIBMPDEC, overriding pkg-config
LIBMPDEC_LIBS
linker flags for LIBMPDEC, overriding pkg-config
LIBSQLITE3_CFLAGS
C compiler flags for LIBSQLITE3, overriding pkg-config
LIBSQLITE3_LIBS
@ -14591,28 +14598,92 @@ printf "%s\n" "$with_system_libmpdec" >&6; }
if test "x$with_system_libmpdec" = xyes
then :
LIBMPDEC_CFLAGS=${LIBMPDEC_CFLAGS-""}
LIBMPDEC_LDFLAGS=${LIBMPDEC_LDFLAGS-"-lmpdec"}
LIBMPDEC_INTERNAL=
pkg_failed=no
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for libmpdec" >&5
printf %s "checking for libmpdec... " >&6; }
if test -n "$LIBMPDEC_CFLAGS"; then
pkg_cv_LIBMPDEC_CFLAGS="$LIBMPDEC_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libmpdec\""; } >&5
($PKG_CONFIG --exists --print-errors "libmpdec") 2>&5
ac_status=$?
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
pkg_cv_LIBMPDEC_CFLAGS=`$PKG_CONFIG --cflags "libmpdec" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
fi
else
pkg_failed=untried
fi
if test -n "$LIBMPDEC_LIBS"; then
pkg_cv_LIBMPDEC_LIBS="$LIBMPDEC_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libmpdec\""; } >&5
($PKG_CONFIG --exists --print-errors "libmpdec") 2>&5
ac_status=$?
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
pkg_cv_LIBMPDEC_LIBS=`$PKG_CONFIG --libs "libmpdec" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
fi
else
pkg_failed=untried
fi
if test $pkg_failed = yes; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
_pkg_short_errors_supported=yes
else
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
LIBMPDEC_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libmpdec" 2>&1`
else
LIBMPDEC_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libmpdec" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
echo "$LIBMPDEC_PKG_ERRORS" >&5
LIBMPDEC_CFLAGS=${LIBMPDEC_CFLAGS-""}
LIBMPDEC_LIBS=${LIBMPDEC_LIBS-"-lmpdec -lm"}
LIBMPDEC_INTERNAL=
elif test $pkg_failed = untried; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
LIBMPDEC_CFLAGS=${LIBMPDEC_CFLAGS-""}
LIBMPDEC_LIBS=${LIBMPDEC_LIBS-"-lmpdec -lm"}
LIBMPDEC_INTERNAL=
else
LIBMPDEC_CFLAGS=$pkg_cv_LIBMPDEC_CFLAGS
LIBMPDEC_LIBS=$pkg_cv_LIBMPDEC_LIBS
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
fi
else $as_nop
LIBMPDEC_CFLAGS="-I\$(srcdir)/Modules/_decimal/libmpdec"
LIBMPDEC_LDFLAGS="-lm \$(LIBMPDEC_A)"
LIBMPDEC_INTERNAL="\$(LIBMPDEC_HEADERS) \$(LIBMPDEC_A)"
LIBMPDEC_LIBS="-lm \$(LIBMPDEC_A)"
LIBMPDEC_INTERNAL="\$(LIBMPDEC_HEADERS) \$(LIBMPDEC_A)"
fi
if test "x$with_pydebug" = xyes
# Disable forced inlining in debug builds, see GH-94847
if test "x$with_pydebug" = xyes
then :
as_fn_append LIBMPDEC_CFLAGS " -DTEST_COVERAGE"
as_fn_append LIBMPDEC_CFLAGS " -DTEST_COVERAGE"
fi
fi
# Check whether _decimal should use a coroutine-local or thread-local context
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for --with-decimal-contextvar" >&5
printf %s "checking for --with-decimal-contextvar... " >&6; }
@ -14636,51 +14707,53 @@ fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $with_decimal_contextvar" >&5
printf "%s\n" "$with_decimal_contextvar" >&6; }
# Check for libmpdec machine flavor
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for decimal libmpdec machine" >&5
if test "x$with_system_libmpdec" = xno
then :
# Check for libmpdec machine flavor
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for decimal libmpdec machine" >&5
printf %s "checking for decimal libmpdec machine... " >&6; }
case $ac_sys_system in #(
case $ac_sys_system in #(
Darwin*) :
libmpdec_system=Darwin ;; #(
SunOS*) :
libmpdec_system=sunos ;; #(
*) :
libmpdec_system=other
;;
;;
esac
libmpdec_machine=unknown
if test "$libmpdec_system" = Darwin; then
# universal here means: build libmpdec with the same arch options
# the python interpreter was built with
libmpdec_machine=universal
elif test $ac_cv_sizeof_size_t -eq 8; then
if test "$ac_cv_gcc_asm_for_x64" = yes; then
libmpdec_machine=x64
elif test "$ac_cv_type___uint128_t" = yes; then
libmpdec_machine=uint128
else
libmpdec_machine=ansi64
fi
elif test $ac_cv_sizeof_size_t -eq 4; then
if test "$ac_cv_gcc_asm_for_x87" = yes -a "$libmpdec_system" != sunos; then
case $CC in #(
libmpdec_machine=unknown
if test "$libmpdec_system" = Darwin; then
# universal here means: build libmpdec with the same arch options
# the python interpreter was built with
libmpdec_machine=universal
elif test $ac_cv_sizeof_size_t -eq 8; then
if test "$ac_cv_gcc_asm_for_x64" = yes; then
libmpdec_machine=x64
elif test "$ac_cv_type___uint128_t" = yes; then
libmpdec_machine=uint128
else
libmpdec_machine=ansi64
fi
elif test $ac_cv_sizeof_size_t -eq 4; then
if test "$ac_cv_gcc_asm_for_x87" = yes -a "$libmpdec_system" != sunos; then
case $CC in #(
*gcc*) :
libmpdec_machine=ppro ;; #(
*clang*) :
libmpdec_machine=ppro ;; #(
*) :
libmpdec_machine=ansi32
;;
;;
esac
else
libmpdec_machine=ansi32
fi
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libmpdec_machine" >&5
else
libmpdec_machine=ansi32
fi
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libmpdec_machine" >&5
printf "%s\n" "$libmpdec_machine" >&6; }
case $libmpdec_machine in #(
case $libmpdec_machine in #(
x64) :
as_fn_append LIBMPDEC_CFLAGS " -DCONFIG_64=1 -DASM=1" ;; #(
uint128) :
@ -14697,8 +14770,9 @@ case $libmpdec_machine in #(
as_fn_append LIBMPDEC_CFLAGS " -DUNIVERSAL=1" ;; #(
*) :
as_fn_error $? "_decimal: unsupported architecture" "$LINENO" 5
;;
;;
esac
fi
if test "$have_ipa_pure_const_bug" = yes; then
# Some versions of gcc miscompile inline asm:
@ -14717,6 +14791,9 @@ fi
if test "$ac_sys_system" = "Emscripten" -a -z "$LIBSQLITE3_CFLAGS" -a -z "$LIBSQLITE3_LIBS"
then :
@ -30310,7 +30387,7 @@ fi
then :
as_fn_append MODULE_BLOCK "MODULE__DECIMAL_CFLAGS=$LIBMPDEC_CFLAGS$as_nl"
as_fn_append MODULE_BLOCK "MODULE__DECIMAL_LDFLAGS=$LIBMPDEC_LDFLAGS$as_nl"
as_fn_append MODULE_BLOCK "MODULE__DECIMAL_LDFLAGS=$LIBMPDEC_LIBS$as_nl"
fi
if test "$py_cv_module__decimal" = yes; then

View File

@ -3961,23 +3961,21 @@ AC_ARG_WITH(
[with_system_libmpdec="no"])
AC_MSG_RESULT([$with_system_libmpdec])
AS_VAR_IF([with_system_libmpdec], [yes], [
LIBMPDEC_CFLAGS=${LIBMPDEC_CFLAGS-""}
LIBMPDEC_LDFLAGS=${LIBMPDEC_LDFLAGS-"-lmpdec"}
LIBMPDEC_INTERNAL=
], [
LIBMPDEC_CFLAGS="-I\$(srcdir)/Modules/_decimal/libmpdec"
LIBMPDEC_LDFLAGS="-lm \$(LIBMPDEC_A)"
LIBMPDEC_INTERNAL="\$(LIBMPDEC_HEADERS) \$(LIBMPDEC_A)"
AS_VAR_IF(
[with_system_libmpdec], [yes],
[PKG_CHECK_MODULES(
[LIBMPDEC], [libmpdec], [],
[LIBMPDEC_CFLAGS=${LIBMPDEC_CFLAGS-""}
LIBMPDEC_LIBS=${LIBMPDEC_LIBS-"-lmpdec -lm"}
LIBMPDEC_INTERNAL=])],
[LIBMPDEC_CFLAGS="-I\$(srcdir)/Modules/_decimal/libmpdec"
LIBMPDEC_LIBS="-lm \$(LIBMPDEC_A)"
LIBMPDEC_INTERNAL="\$(LIBMPDEC_HEADERS) \$(LIBMPDEC_A)"])
dnl Disable forced inlining in debug builds, see GH-94847
AS_VAR_IF([with_pydebug], [yes], [
AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DTEST_COVERAGE"])
])
])
AC_SUBST([LIBMPDEC_CFLAGS])
AC_SUBST([LIBMPDEC_INTERNAL])
# Disable forced inlining in debug builds, see GH-94847
AS_VAR_IF(
[with_pydebug], [yes],
[AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DTEST_COVERAGE"])])
# Check whether _decimal should use a coroutine-local or thread-local context
AC_MSG_CHECKING([for --with-decimal-contextvar])
@ -3998,50 +3996,52 @@ fi
AC_MSG_RESULT([$with_decimal_contextvar])
# Check for libmpdec machine flavor
AC_MSG_CHECKING([for decimal libmpdec machine])
AS_CASE([$ac_sys_system],
[Darwin*], [libmpdec_system=Darwin],
[SunOS*], [libmpdec_system=sunos],
[libmpdec_system=other]
)
AS_VAR_IF(
[with_system_libmpdec], [no],
[# Check for libmpdec machine flavor
AC_MSG_CHECKING([for decimal libmpdec machine])
AS_CASE([$ac_sys_system],
[Darwin*], [libmpdec_system=Darwin],
[SunOS*], [libmpdec_system=sunos],
[libmpdec_system=other]
)
libmpdec_machine=unknown
if test "$libmpdec_system" = Darwin; then
# universal here means: build libmpdec with the same arch options
# the python interpreter was built with
libmpdec_machine=universal
elif test $ac_cv_sizeof_size_t -eq 8; then
if test "$ac_cv_gcc_asm_for_x64" = yes; then
libmpdec_machine=x64
elif test "$ac_cv_type___uint128_t" = yes; then
libmpdec_machine=uint128
else
libmpdec_machine=ansi64
fi
elif test $ac_cv_sizeof_size_t -eq 4; then
if test "$ac_cv_gcc_asm_for_x87" = yes -a "$libmpdec_system" != sunos; then
AS_CASE([$CC],
[*gcc*], [libmpdec_machine=ppro],
[*clang*], [libmpdec_machine=ppro],
[libmpdec_machine=ansi32]
)
else
libmpdec_machine=ansi32
fi
fi
AC_MSG_RESULT([$libmpdec_machine])
libmpdec_machine=unknown
if test "$libmpdec_system" = Darwin; then
# universal here means: build libmpdec with the same arch options
# the python interpreter was built with
libmpdec_machine=universal
elif test $ac_cv_sizeof_size_t -eq 8; then
if test "$ac_cv_gcc_asm_for_x64" = yes; then
libmpdec_machine=x64
elif test "$ac_cv_type___uint128_t" = yes; then
libmpdec_machine=uint128
else
libmpdec_machine=ansi64
fi
elif test $ac_cv_sizeof_size_t -eq 4; then
if test "$ac_cv_gcc_asm_for_x87" = yes -a "$libmpdec_system" != sunos; then
AS_CASE([$CC],
[*gcc*], [libmpdec_machine=ppro],
[*clang*], [libmpdec_machine=ppro],
[libmpdec_machine=ansi32]
)
else
libmpdec_machine=ansi32
fi
fi
AC_MSG_RESULT([$libmpdec_machine])
AS_CASE([$libmpdec_machine],
[x64], [AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DCONFIG_64=1 -DASM=1"])],
[uint128], [AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DCONFIG_64=1 -DANSI=1 -DHAVE_UINT128_T=1"])],
[ansi64], [AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DCONFIG_64=1 -DANSI=1"])],
[ppro], [AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DCONFIG_32=1 -DANSI=1 -DASM=1 -Wno-unknown-pragmas"])],
[ansi32], [AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DCONFIG_32=1 -DANSI=1"])],
[ansi-legacy], [AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DCONFIG_32=1 -DANSI=1 -DLEGACY_COMPILER=1"])],
[universal], [AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DUNIVERSAL=1"])],
[AC_MSG_ERROR([_decimal: unsupported architecture])]
)
AS_CASE([$libmpdec_machine],
[x64], [AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DCONFIG_64=1 -DASM=1"])],
[uint128], [AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DCONFIG_64=1 -DANSI=1 -DHAVE_UINT128_T=1"])],
[ansi64], [AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DCONFIG_64=1 -DANSI=1"])],
[ppro], [AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DCONFIG_32=1 -DANSI=1 -DASM=1 -Wno-unknown-pragmas"])],
[ansi32], [AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DCONFIG_32=1 -DANSI=1"])],
[ansi-legacy], [AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DCONFIG_32=1 -DANSI=1 -DLEGACY_COMPILER=1"])],
[universal], [AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DUNIVERSAL=1"])],
[AC_MSG_ERROR([_decimal: unsupported architecture])]
)])
if test "$have_ipa_pure_const_bug" = yes; then
# Some versions of gcc miscompile inline asm:
@ -4056,6 +4056,9 @@ if test "$have_glibc_memmove_bug" = yes; then
AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -U_FORTIFY_SOURCE"])
fi
AC_SUBST([LIBMPDEC_CFLAGS])
AC_SUBST([LIBMPDEC_INTERNAL])
dnl detect sqlite3 from Emscripten emport
PY_CHECK_EMSCRIPTEN_PORT([LIBSQLITE3], [-sUSE_SQLITE3])
@ -7643,7 +7646,7 @@ PY_STDLIB_MOD([_curses_panel],
[], [test "$have_panel" != "no"],
[$PANEL_CFLAGS $CURSES_CFLAGS], [$PANEL_LIBS $CURSES_LIBS]
)
PY_STDLIB_MOD([_decimal], [], [], [$LIBMPDEC_CFLAGS], [$LIBMPDEC_LDFLAGS])
PY_STDLIB_MOD([_decimal], [], [], [$LIBMPDEC_CFLAGS], [$LIBMPDEC_LIBS])
PY_STDLIB_MOD([_dbm],
[test -n "$with_dbmliborder"], [test "$have_dbm" != "no"],
[$DBM_CFLAGS], [$DBM_LIBS])