diff options
author | Christian Heimes <christian@python.org> | 2021-11-13 12:56:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-13 12:56:16 (GMT) |
commit | 0486570f7b2b5a75812e5a01a8dca58bfadc2437 (patch) | |
tree | 3decd2be9bf1be998e4843ccbf36e5578aaa01d0 | |
parent | 4c792f39e688b11c7c19e411ed4f76a7baa44638 (diff) | |
download | cpython-0486570f7b2b5a75812e5a01a8dca58bfadc2437.zip cpython-0486570f7b2b5a75812e5a01a8dca58bfadc2437.tar.gz cpython-0486570f7b2b5a75812e5a01a8dca58bfadc2437.tar.bz2 |
bpo-45798: Move _decimal build setup into configure (GH-29541)
Settings for :mod:`decimal` internal C extension are now detected by
:program:`configure`. The bundled `libmpdec` library is built in
``Makefile``.
Signed-off-by: Christian Heimes <christian@python.org>
-rw-r--r-- | Makefile.pre.in | 102 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Build/2021-11-13-10-18-22.bpo-45798.IraaTs.rst | 2 | ||||
-rw-r--r-- | Modules/Setup | 3 | ||||
-rwxr-xr-x | Modules/makesetup | 5 | ||||
-rwxr-xr-x | configure | 114 | ||||
-rw-r--r-- | configure.ac | 78 | ||||
-rw-r--r-- | setup.py | 121 |
7 files changed, 313 insertions, 112 deletions
diff --git a/Makefile.pre.in b/Makefile.pre.in index 6968ae4..a17054b 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -496,6 +496,47 @@ LIBRARY_OBJS= \ DTRACE_DEPS = \ Python/ceval.o Python/import.o Python/sysmodule.o Modules/gcmodule.o +########################################################################## +# decimal's libmpdec + +LIBMPDEC_OBJS= \ + Modules/_decimal/libmpdec/basearith.o \ + Modules/_decimal/libmpdec/constants.o \ + Modules/_decimal/libmpdec/context.o \ + Modules/_decimal/libmpdec/convolute.o \ + Modules/_decimal/libmpdec/crt.o \ + Modules/_decimal/libmpdec/difradix2.o \ + Modules/_decimal/libmpdec/fnt.o \ + Modules/_decimal/libmpdec/fourstep.o \ + Modules/_decimal/libmpdec/io.o \ + Modules/_decimal/libmpdec/mpalloc.o \ + Modules/_decimal/libmpdec/mpdecimal.o \ + Modules/_decimal/libmpdec/numbertheory.o \ + Modules/_decimal/libmpdec/sixstep.o \ + Modules/_decimal/libmpdec/transpose.o + # _decimal does not use signaling API + # Modules/_decimal/libmpdec/mpsignal.o + +LIBMPDEC_HEADERS= \ + $(srcdir)/Modules/_decimal/libmpdec/basearith.h \ + $(srcdir)/Modules/_decimal/libmpdec/bits.h \ + $(srcdir)/Modules/_decimal/libmpdec/constants.h \ + $(srcdir)/Modules/_decimal/libmpdec/convolute.h \ + $(srcdir)/Modules/_decimal/libmpdec/crt.h \ + $(srcdir)/Modules/_decimal/libmpdec/difradix2.h \ + $(srcdir)/Modules/_decimal/libmpdec/fnt.h \ + $(srcdir)/Modules/_decimal/libmpdec/fourstep.h \ + $(srcdir)/Modules/_decimal/libmpdec/io.h \ + $(srcdir)/Modules/_decimal/libmpdec/mpalloc.h \ + $(srcdir)/Modules/_decimal/libmpdec/mpdecimal.h \ + $(srcdir)/Modules/_decimal/libmpdec/numbertheory.h \ + $(srcdir)/Modules/_decimal/libmpdec/sixstep.h \ + $(srcdir)/Modules/_decimal/libmpdec/transpose.h \ + $(srcdir)/Modules/_decimal/libmpdec/typearith.h \ + $(srcdir)/Modules/_decimal/libmpdec/umodarith.h + +LIBMPDEC_A= Modules/_decimal/libmpdec/libmpdec.a + ######################################################################### # Rules @@ -647,7 +688,7 @@ $(srcdir)/Modules/_blake2/blake2s_impl.c: $(srcdir)/Modules/_blake2/blake2b_impl # -s, --silent or --quiet is always the first char. # Under BSD make, MAKEFLAGS might be " -s -v x=y". # Ignore macros passed by GNU make, passed after -- -sharedmods: $(BUILDPYTHON) pybuilddir.txt +sharedmods: $(BUILDPYTHON) pybuilddir.txt @LIBMPDEC_INTERNAL@ @case "`echo X $$MAKEFLAGS | sed 's/^X //;s/ -- .*//'`" in \ *\ -s*|s*) quiet="-q";; \ *) quiet="";; \ @@ -729,6 +770,63 @@ $(DLLLIBRARY) libpython$(LDVERSION).dll.a: $(LIBRARY_OBJS) else true; \ fi +########################################################################## +# Build static libmpdec.a +LIBMPDEC_CFLAGS=$(PY_STDMODULE_CFLAGS) $(CCSHARED) @LIBMPDEC_CFLAGS@ + +# for setup.py +DECIMAL_CFLAGS=@LIBMPDEC_CFLAGS@ +DECIMAL_LDFLAGS=@LIBMPDEC_LDFLAGS@ + +# "%.o: %c" is not portable +Modules/_decimal/libmpdec/basearith.o: $(srcdir)/Modules/_decimal/libmpdec/basearith.c $(LIBMPDEC_HEADERS) $(PYTHON_HEADERS) + $(CC) -c $(LIBMPDEC_CFLAGS) -o $@ $(srcdir)/Modules/_decimal/libmpdec/basearith.c + +Modules/_decimal/libmpdec/constants.o: $(srcdir)/Modules/_decimal/libmpdec/constants.c $(LIBMPDEC_HEADERS) $(PYTHON_HEADERS) + $(CC) -c $(LIBMPDEC_CFLAGS) -o $@ $(srcdir)/Modules/_decimal/libmpdec/constants.c + +Modules/_decimal/libmpdec/context.o: $(srcdir)/Modules/_decimal/libmpdec/context.c $(LIBMPDEC_HEADERS) $(PYTHON_HEADERS) + $(CC) -c $(LIBMPDEC_CFLAGS) -o $@ $(srcdir)/Modules/_decimal/libmpdec/context.c + +Modules/_decimal/libmpdec/convolute.o: $(srcdir)/Modules/_decimal/libmpdec/convolute.c $(LIBMPDEC_HEADERS) $(PYTHON_HEADERS) + $(CC) -c $(LIBMPDEC_CFLAGS) -o $@ $(srcdir)/Modules/_decimal/libmpdec/convolute.c + +Modules/_decimal/libmpdec/crt.o: $(srcdir)/Modules/_decimal/libmpdec/crt.c $(LIBMPDEC_HEADERS) $(PYTHON_HEADERS) + $(CC) -c $(LIBMPDEC_CFLAGS) -o $@ $(srcdir)/Modules/_decimal/libmpdec/crt.c + +Modules/_decimal/libmpdec/difradix2.o: $(srcdir)/Modules/_decimal/libmpdec/difradix2.c $(LIBMPDEC_HEADERS) $(PYTHON_HEADERS) + $(CC) -c $(LIBMPDEC_CFLAGS) -o $@ $(srcdir)/Modules/_decimal/libmpdec/difradix2.c + +Modules/_decimal/libmpdec/fnt.o: $(srcdir)/Modules/_decimal/libmpdec/fnt.c $(LIBMPDEC_HEADERS) $(PYTHON_HEADERS) + $(CC) -c $(LIBMPDEC_CFLAGS) -o $@ $(srcdir)/Modules/_decimal/libmpdec/fnt.c + +Modules/_decimal/libmpdec/fourstep.o: $(srcdir)/Modules/_decimal/libmpdec/fourstep.c $(LIBMPDEC_HEADERS) $(PYTHON_HEADERS) + $(CC) -c $(LIBMPDEC_CFLAGS) -o $@ $(srcdir)/Modules/_decimal/libmpdec/fourstep.c + +Modules/_decimal/libmpdec/io.o: $(srcdir)/Modules/_decimal/libmpdec/io.c $(LIBMPDEC_HEADERS) $(PYTHON_HEADERS) + $(CC) -c $(LIBMPDEC_CFLAGS) -o $@ $(srcdir)/Modules/_decimal/libmpdec/io.c + +Modules/_decimal/libmpdec/mpalloc.o: $(srcdir)/Modules/_decimal/libmpdec/mpalloc.c $(LIBMPDEC_HEADERS) $(PYTHON_HEADERS) + $(CC) -c $(LIBMPDEC_CFLAGS) -o $@ $(srcdir)/Modules/_decimal/libmpdec/mpalloc.c + +Modules/_decimal/libmpdec/mpdecimal.o: $(srcdir)/Modules/_decimal/libmpdec/mpdecimal.c $(LIBMPDEC_HEADERS) $(PYTHON_HEADERS) + $(CC) -c $(LIBMPDEC_CFLAGS) -o $@ $(srcdir)/Modules/_decimal/libmpdec/mpdecimal.c + +Modules/_decimal/libmpdec/mpsignal.o: $(srcdir)/Modules/_decimal/libmpdec/mpsignal.c $(LIBMPDEC_HEADERS) $(PYTHON_HEADERS) + $(CC) -c $(LIBMPDEC_CFLAGS) -o $@ $(srcdir)/Modules/_decimal/libmpdec/mpsignal.c + +Modules/_decimal/libmpdec/numbertheory.o: $(srcdir)/Modules/_decimal/libmpdec/numbertheory.c $(LIBMPDEC_HEADERS) $(PYTHON_HEADERS) + $(CC) -c $(LIBMPDEC_CFLAGS) -o $@ $(srcdir)/Modules/_decimal/libmpdec/numbertheory.c + +Modules/_decimal/libmpdec/sixstep.o: $(srcdir)/Modules/_decimal/libmpdec/sixstep.c $(LIBMPDEC_HEADERS) $(PYTHON_HEADERS) + $(CC) -c $(LIBMPDEC_CFLAGS) -o $@ $(srcdir)/Modules/_decimal/libmpdec/sixstep.c + +Modules/_decimal/libmpdec/transpose.o: $(srcdir)/Modules/_decimal/libmpdec/transpose.c $(LIBMPDEC_HEADERS) $(PYTHON_HEADERS) + $(CC) -c $(LIBMPDEC_CFLAGS) -o $@ $(srcdir)/Modules/_decimal/libmpdec/transpose.c + +$(LIBMPDEC_A): $(LIBMPDEC_OBJS) + -rm -f $@ + $(AR) $(ARFLAGS) $@ $(LIBMPDEC_OBJS) # create relative links from build/lib.platform/egg.so to Modules/egg.so # pybuilddir.txt is created too late. We cannot use it in Makefile @@ -2313,7 +2411,7 @@ MODULE_PYEXPAT_DEPS=$(srcdir)/Modules/expat/ascii.h $(srcdir)/Modules/expat/asci MODULE_UNICODEDATA_DEPS=$(srcdir)/Modules/unicodedata_db.h $(srcdir)/Modules/unicodename_db.h MODULE__BLAKE2_DEPS=$(srcdir)/Modules/_blake2/impl/blake2-config.h $(srcdir)/Modules/_blake2/impl/blake2-dispatch.c $(srcdir)/Modules/_blake2/impl/blake2-impl.h $(srcdir)/Modules/_blake2/impl/blake2-kat.h $(srcdir)/Modules/_blake2/impl/blake2.h $(srcdir)/Modules/_blake2/impl/blake2b-load-sse2.h $(srcdir)/Modules/_blake2/impl/blake2b-load-sse41.h $(srcdir)/Modules/_blake2/impl/blake2b-ref.c $(srcdir)/Modules/_blake2/impl/blake2b-round.h $(srcdir)/Modules/_blake2/impl/blake2b-test.c $(srcdir)/Modules/_blake2/impl/blake2b.c $(srcdir)/Modules/_blake2/impl/blake2bp-test.c $(srcdir)/Modules/_blake2/impl/blake2bp.c $(srcdir)/Modules/_blake2/impl/blake2s-load-sse2.h $(srcdir)/Modules/_blake2/impl/blake2s-load-sse41.h $(srcdir)/Modules/_blake2/impl/blake2s-load-xop.h $(srcdir)/Modules/_blake2/impl/blake2s-ref.c $(srcdir)/Modules/_blake2/impl/blake2s-round.h $(srcdir)/Modules/_blake2/impl/blake2s-test.c $(srcdir)/Modules/_blake2/impl/blake2s.c $(srcdir)/Modules/_blake2/impl/blake2sp-test.c $(srcdir)/Modules/_blake2/impl/blake2sp.c $(srcdir)/Modules/hashlib.h MODULE__CTYPES_DEPS=$(srcdir)/Modules/_ctypes/ctypes.h -MODULE__DECIMAL_DEPS=$(srcdir)/Modules/_decimal/docstrings.h $(srcdir)/Modules/_decimal/libmpdec/basearith.h $(srcdir)/Modules/_decimal/libmpdec/bits.h $(srcdir)/Modules/_decimal/libmpdec/constants.h $(srcdir)/Modules/_decimal/libmpdec/convolute.h $(srcdir)/Modules/_decimal/libmpdec/crt.h $(srcdir)/Modules/_decimal/libmpdec/difradix2.h $(srcdir)/Modules/_decimal/libmpdec/fnt.h $(srcdir)/Modules/_decimal/libmpdec/fourstep.h $(srcdir)/Modules/_decimal/libmpdec/io.h $(srcdir)/Modules/_decimal/libmpdec/mpalloc.h $(srcdir)/Modules/_decimal/libmpdec/mpdecimal.h $(srcdir)/Modules/_decimal/libmpdec/numbertheory.h $(srcdir)/Modules/_decimal/libmpdec/sixstep.h $(srcdir)/Modules/_decimal/libmpdec/transpose.h $(srcdir)/Modules/_decimal/libmpdec/typearith.h $(srcdir)/Modules/_decimal/libmpdec/umodarith.h +MODULE__DECIMAL_DEPS=$(srcdir)/Modules/_decimal/docstrings.h $(LIBMPDEC_HEADERS) @LIBMPDEC_INTERNAL@ MODULE__ELEMENTTREE_DEPS=$(srcdir)/Modules/expat/ascii.h $(srcdir)/Modules/expat/asciitab.h $(srcdir)/Modules/expat/expat.h $(srcdir)/Modules/expat/expat_config.h $(srcdir)/Modules/expat/expat_external.h $(srcdir)/Modules/expat/internal.h $(srcdir)/Modules/expat/latin1tab.h $(srcdir)/Modules/expat/utf8tab.h $(srcdir)/Modules/expat/xmlparse.c $(srcdir)/Modules/expat/xmlrole.c $(srcdir)/Modules/expat/xmlrole.h $(srcdir)/Modules/expat/xmltok.c $(srcdir)/Modules/expat/xmltok.h $(srcdir)/Modules/expat/xmltok_impl.h $(srcdir)/Modules/pyexpat.c MODULE__HASHLIB_DEPS=$(srcdir)/Modules/hashlib.h MODULE__IO_DEPS=$(srcdir)/Modules/_io/_iomodule.h diff --git a/Misc/NEWS.d/next/Build/2021-11-13-10-18-22.bpo-45798.IraaTs.rst b/Misc/NEWS.d/next/Build/2021-11-13-10-18-22.bpo-45798.IraaTs.rst new file mode 100644 index 0000000..865d8a0 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2021-11-13-10-18-22.bpo-45798.IraaTs.rst @@ -0,0 +1,2 @@ +Settings for :mod:`decimal` internal C extension are now detected by +``configure``. The bundled ``libmpdec`` library is built in ``Makefile``. diff --git a/Modules/Setup b/Modules/Setup index 49c6903..39dc39d 100644 --- a/Modules/Setup +++ b/Modules/Setup @@ -149,8 +149,7 @@ time timemodule.c #_contextvars _contextvarsmodule.c #_csv _csv.c #_datetime _datetimemodule.c -# UNIVERSAL: let mpdecimal.h detect settings -#_decimal -DUNIVERSAL -I$(srcdir)/Modules/_decimal/libmpdec _decimal/_decimal.c _decimal/libmpdec/basearith.c _decimal/libmpdec/constants.c _decimal/libmpdec/context.c _decimal/libmpdec/convolute.c _decimal/libmpdec/crt.c _decimal/libmpdec/difradix2.c _decimal/libmpdec/fnt.c _decimal/libmpdec/fourstep.c _decimal/libmpdec/io.c _decimal/libmpdec/mpalloc.c _decimal/libmpdec/mpdecimal.c _decimal/libmpdec/numbertheory.c _decimal/libmpdec/sixstep.c _decimal/libmpdec/transpose.c +#_decimal _decimal/_decimal.c $(DECIMAL_CFLAGS) $(DECIMAL_LDFLAGS) #_heapq _heapqmodule.c #_json _json.c #_lsprof _lsprof.c rotatingtree.c diff --git a/Modules/makesetup b/Modules/makesetup index 543992c..a8817ff 100755 --- a/Modules/makesetup +++ b/Modules/makesetup @@ -184,6 +184,11 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | *.c++) srcs="$srcs $arg";; *.cxx) srcs="$srcs $arg";; *.cpp) srcs="$srcs $arg";; + \$\(*_CFLAGS\)) cpps="$cpps $arg";; + \$\(*_INCLUDES\)) cpps="$cpps $arg";; + \$\(*_LIBS\)) libs="$libs $arg";; + \$\(*_LDFLAGS\)) libs="$libs $arg";; + \$\(*_RPATH\)) libs="$libs $arg";; \$*) libs="$libs $arg" cpps="$cpps $arg";; *.*) echo 1>&2 "bad word $arg in $line" @@ -660,6 +660,9 @@ DFLAGS DTRACE TCLTK_LIBS TCLTK_INCLUDES +LIBMPDEC_INTERNAL +LIBMPDEC_LDFLAGS +LIBMPDEC_CFLAGS LIBFFI_INCLUDEDIR TZPATH SHLIBS @@ -1533,7 +1536,8 @@ Optional Features: Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) - --with-pkg-config use pkg-config to detect build options (default is + --with-pkg-config=[yes|no|check] + use pkg-config to detect build options (default is check) --with-universal-archs=ARCH specify the kind of macOS universal binary that @@ -10764,10 +10768,27 @@ else with_system_libmpdec="no" fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_system_libmpdec" >&5 $as_echo "$with_system_libmpdec" >&6; } +if test "x$with_system_libmpdec" = xyes; then : + + LIBMPDEC_CFLAGS="" + LIBMPDEC_LDFLAGS="-lmpdec" + LIBMPDEC_INTERNAL= + +else + + LIBMPDEC_CFLAGS="-I\$(srcdir)/Modules/_decimal/libmpdec" + LIBMPDEC_LDFLAGS="-lm \$(LIBMPDEC_A)" + LIBMPDEC_INTERNAL="\$(LIBMPDEC_A)" + +fi + + + + + # Check whether _decimal should use a coroutine-local or thread-local context { $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-decimal-contextvar" >&5 $as_echo_n "checking for --with-decimal-contextvar... " >&6; } @@ -10790,6 +10811,95 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_decimal_contextvar" >&5 $as_echo "$with_decimal_contextvar" >&6; } +# Check for libmpdec machine flavor +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for decimal libmpdec machine" >&5 +$as_echo_n "checking for decimal libmpdec machine... " >&6; } +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 + case $MACOSX_DEFAULT_ARCH in #( + i386) : + libmpdec_machine=ansi32 ;; #( + ppc) : + libmpdec_machine=ansi32 ;; #( + x86_64) : + libmpdec_machine=x64 ;; #( + ppc64) : + libmpdec_machine=ansi64 ;; #( + arm64) : + libmpdec_machine=ansi64 ;; #( + *) : + libmpdec_machine=universal + ;; +esac +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 +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libmpdec_machine" >&5 +$as_echo "$libmpdec_machine" >&6; } + +case $libmpdec_machine in #( + x64) : + as_fn_append LIBMPDEC_CFLAGS " -DCONFIG_64=1 -DASM=1" ;; #( + uint128) : + as_fn_append LIBMPDEC_CFLAGS " -DCONFIG_64=1 -DANSI=1 -DHAVE_UINT128_T=1" ;; #( + ansi64) : + as_fn_append LIBMPDEC_CFLAGS " -DCONFIG_64=1 -DANSI=1" ;; #( + ppro) : + as_fn_append LIBMPDEC_CFLAGS " -DCONFIG_32=1 -DANSI=1 -DASM=1 -Wno-unknown-pragmas" ;; #( + ansi32) : + as_fn_append LIBMPDEC_CFLAGS " -DCONFIG_32=1 -DANSI=1" ;; #( + ansi-legacy) : + as_fn_append LIBMPDEC_CFLAGS " -DCONFIG_32=1 -DANSI=1 -DLEGACY_COMPILER=1" ;; #( + universal) : + as_fn_append LIBMPDEC_CFLAGS " -DUNIVERSAL=1" ;; #( + *) : + as_fn_error $? "_decimal: unsupported architecture" "$LINENO" 5 + ;; +esac + +if test "$have_ipa_pure_const_bug" = yes; then + # Some versions of gcc miscompile inline asm: + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491 + # https://gcc.gnu.org/ml/gcc/2010-11/msg00366.html + as_fn_append LIBMPDEC_CFLAGS " -fno-ipa-pure-const" +fi + +if test "$have_glibc_memmove_bug" = yes; then + # _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect: + # https://sourceware.org/ml/libc-alpha/2010-12/msg00009.html + as_fn_append LIBMPDEC_CFLAGS " -U_FORTIFY_SOURCE" +fi + # Check for support for loadable sqlite extensions { $as_echo "$as_me:${as_lineno-$LINENO}: checking for --enable-loadable-sqlite-extensions" >&5 $as_echo_n "checking for --enable-loadable-sqlite-extensions... " >&6; } diff --git a/configure.ac b/configure.ac index 5a1ed51..c3b52e3 100644 --- a/configure.ac +++ b/configure.ac @@ -3057,9 +3057,22 @@ AC_ARG_WITH(system_libmpdec, AS_HELP_STRING([--with-system-libmpdec], [build _decimal module using an installed libmpdec library, see Doc/library/decimal.rst (default is no)]), [], [with_system_libmpdec="no"]) - AC_MSG_RESULT($with_system_libmpdec) +AS_VAR_IF([with_system_libmpdec], [yes], [ + LIBMPDEC_CFLAGS="" + LIBMPDEC_LDFLAGS="-lmpdec" + LIBMPDEC_INTERNAL= +], [ + LIBMPDEC_CFLAGS="-I\$(srcdir)/Modules/_decimal/libmpdec" + LIBMPDEC_LDFLAGS="-lm \$(LIBMPDEC_A)" + LIBMPDEC_INTERNAL="\$(LIBMPDEC_A)" +]) + +AC_SUBST([LIBMPDEC_CFLAGS]) +AC_SUBST([LIBMPDEC_LDFLAGS]) +AC_SUBST([LIBMPDEC_INTERNAL]) + # Check whether _decimal should use a coroutine-local or thread-local context AC_MSG_CHECKING(for --with-decimal-contextvar) AC_ARG_WITH(decimal_contextvar, @@ -3075,6 +3088,69 @@ 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] +) + +libmpdec_machine=unknown +if test "$libmpdec_system" = Darwin; then + AS_CASE([$MACOSX_DEFAULT_ARCH], + [i386], [libmpdec_machine=ansi32], + [ppc], [libmpdec_machine=ansi32], + [x86_64], [libmpdec_machine=x64], + [ppc64], [libmpdec_machine=ansi64], + [arm64], [libmpdec_machine=ansi64], + [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])] +) + +if test "$have_ipa_pure_const_bug" = yes; then + # Some versions of gcc miscompile inline asm: + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491 + # https://gcc.gnu.org/ml/gcc/2010-11/msg00366.html + AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -fno-ipa-pure-const"]) +fi + +if test "$have_glibc_memmove_bug" = yes; then + # _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect: + # https://sourceware.org/ml/libc-alpha/2010-12/msg00009.html + AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -U_FORTIFY_SOURCE"]) +fi + # Check for support for loadable sqlite extensions AC_MSG_CHECKING(for --enable-loadable-sqlite-extensions) AC_ARG_ENABLE(loadable-sqlite-extensions, @@ -7,6 +7,7 @@ import importlib.util import logging import os import re +import shlex import sys import sysconfig import warnings @@ -2016,117 +2017,27 @@ class PyBuildExt(build_ext): def detect_decimal(self): # Stefan Krah's _decimal module - extra_compile_args = [] - undef_macros = [] - if '--with-system-libmpdec' in sysconfig.get_config_var("CONFIG_ARGS"): - include_dirs = [] - libraries = ['mpdec'] - sources = ['_decimal/_decimal.c'] - depends = ['_decimal/docstrings.h'] - else: - include_dirs = [os.path.abspath(os.path.join(self.srcdir, - 'Modules', - '_decimal', - 'libmpdec'))] - libraries = ['m'] - sources = [ - '_decimal/_decimal.c', - '_decimal/libmpdec/basearith.c', - '_decimal/libmpdec/constants.c', - '_decimal/libmpdec/context.c', - '_decimal/libmpdec/convolute.c', - '_decimal/libmpdec/crt.c', - '_decimal/libmpdec/difradix2.c', - '_decimal/libmpdec/fnt.c', - '_decimal/libmpdec/fourstep.c', - '_decimal/libmpdec/io.c', - '_decimal/libmpdec/mpalloc.c', - '_decimal/libmpdec/mpdecimal.c', - '_decimal/libmpdec/numbertheory.c', - '_decimal/libmpdec/sixstep.c', - '_decimal/libmpdec/transpose.c', - ] - depends = [ - '_decimal/docstrings.h', - '_decimal/libmpdec/basearith.h', - '_decimal/libmpdec/bits.h', - '_decimal/libmpdec/constants.h', - '_decimal/libmpdec/convolute.h', - '_decimal/libmpdec/crt.h', - '_decimal/libmpdec/difradix2.h', - '_decimal/libmpdec/fnt.h', - '_decimal/libmpdec/fourstep.h', - '_decimal/libmpdec/io.h', - '_decimal/libmpdec/mpalloc.h', - '_decimal/libmpdec/mpdecimal.h', - '_decimal/libmpdec/numbertheory.h', - '_decimal/libmpdec/sixstep.h', - '_decimal/libmpdec/transpose.h', - '_decimal/libmpdec/typearith.h', - '_decimal/libmpdec/umodarith.h', - ] - - config = { - 'x64': [('CONFIG_64','1'), ('ASM','1')], - 'uint128': [('CONFIG_64','1'), ('ANSI','1'), ('HAVE_UINT128_T','1')], - 'ansi64': [('CONFIG_64','1'), ('ANSI','1')], - 'ppro': [('CONFIG_32','1'), ('PPRO','1'), ('ASM','1')], - 'ansi32': [('CONFIG_32','1'), ('ANSI','1')], - 'ansi-legacy': [('CONFIG_32','1'), ('ANSI','1'), - ('LEGACY_COMPILER','1')], - 'universal': [('UNIVERSAL','1')] - } - - cc = sysconfig.get_config_var('CC') - sizeof_size_t = sysconfig.get_config_var('SIZEOF_SIZE_T') - machine = os.environ.get('PYTHON_DECIMAL_WITH_MACHINE') - - if machine: - # Override automatic configuration to facilitate testing. - define_macros = config[machine] - elif MACOS: - # Universal here means: build with the same options Python - # was built with. - define_macros = config['universal'] - elif sizeof_size_t == 8: - if sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X64'): - define_macros = config['x64'] - elif sysconfig.get_config_var('HAVE_GCC_UINT128_T'): - define_macros = config['uint128'] - else: - define_macros = config['ansi64'] - elif sizeof_size_t == 4: - ppro = sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X87') - if ppro and ('gcc' in cc or 'clang' in cc) and \ - not 'sunos' in HOST_PLATFORM: - # solaris: problems with register allocation. - # icc >= 11.0 works as well. - define_macros = config['ppro'] - extra_compile_args.append('-Wno-unknown-pragmas') - else: - define_macros = config['ansi32'] - else: - raise DistutilsError("_decimal: unsupported architecture") - - # Workarounds for toolchain bugs: - if sysconfig.get_config_var('HAVE_IPA_PURE_CONST_BUG'): - # Some versions of gcc miscompile inline asm: - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491 - # https://gcc.gnu.org/ml/gcc/2010-11/msg00366.html - extra_compile_args.append('-fno-ipa-pure-const') - if sysconfig.get_config_var('HAVE_GLIBC_MEMMOVE_BUG'): - # _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect: - # https://sourceware.org/ml/libc-alpha/2010-12/msg00009.html - undef_macros.append('_FORTIFY_SOURCE') + sources = ['_decimal/_decimal.c'] + depends = ['_decimal/docstrings.h'] + define_macros = [] + + cflags = sysconfig.get_config_var("DECIMAL_CFLAGS") + extra_compile_args = shlex.split(cflags) if cflags else None + # ldflags includes either system libmpdec or full path to + # our static libmpdec.a. + ldflags = sysconfig.get_config_var("DECIMAL_LDFLAGS") + extra_link_args = shlex.split(ldflags) if ldflags else None + + libmpdec_a = sysconfig.get_config_var("LIBMPDEC_A") + if libmpdec_a: + depends.append(libmpdec_a) # Uncomment for extra functionality: #define_macros.append(('EXTRA_FUNCTIONALITY', 1)) self.add(Extension('_decimal', - include_dirs=include_dirs, - libraries=libraries, define_macros=define_macros, - undef_macros=undef_macros, extra_compile_args=extra_compile_args, + extra_link_args=extra_link_args, sources=sources, depends=depends)) |