diff --git a/Doc/using/configure.rst b/Doc/using/configure.rst index 4d47cf945219dd..7dd0e4d27708b7 100644 --- a/Doc/using/configure.rst +++ b/Doc/using/configure.rst @@ -1396,6 +1396,15 @@ Compiler flags .. versionadded:: 3.2 +.. envvar:: PY_EXTRA_STDMODULE_CFLAGS + + Equivalent flag to :envvar:`CFLAGS_NODIST` but it only applies to **all** builtin extension + modules built as part of the standard library. + + Default: (empty). + + .. versionadded:: next + .. envvar:: PY_BUILTIN_MODULE_CFLAGS Compiler flags to build a standard library extension module as a built-in @@ -1495,6 +1504,15 @@ Linker flags .. versionadded:: 3.8 +.. envvar:: PY_EXTRA_STDMODULE_LDFLAGS + + Equivalent flag to :envvar:`LDLAGS_NODIST` but it only applies to **all** builtin extension + modules built as part of the standard library. + + Default: (empty). + + .. versionadded:: next + .. rubric:: Footnotes diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 767cf9a1f08dc2..dc374b6d128ceb 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -1495,6 +1495,13 @@ Build changes with :c:expr:`Py_NO_LINK_LIB`. (Contributed by Jean-Christophe Fillion-Robin in :gh:`82909`.) +* Two new configure flags are added: :envvar:`CFLAGS_BUILTIN_MODULE` and + :envvar:`LDFLAGS_BUILTIN_MODULE`. These flags allows refistributors to + provide compile and linker flags that only apply to standard library extension + modules. This is particulary useful to provide options such as ``RUNPATH`` and + ``RPATH`` that need to be applied specifically to standard library modules due to + its different relative location. (Contributed by Pablo Galindo in :gh:`131842`.) + .. _whatsnew314-pep761: PEP 761: Discontinuation of PGP signatures diff --git a/Makefile.pre.in b/Makefile.pre.in index 92f3984fa98b31..17a5f1905167a9 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -119,8 +119,11 @@ ARFLAGS= @ARFLAGS@ # Extra C flags added for building the interpreter object files. CFLAGSFORSHARED=@CFLAGSFORSHARED@ # C flags used for building the interpreter object files +PY_EXTRA_STDMODULE_CFLAGS= @PY_EXTRA_STDMODULE_CFLAGS@ +PY_EXTRA_STDMODULE_LDFLAGS= @PY_EXTRA_STDMODULE_LDFLAGS@ PY_STDMODULE_CFLAGS= $(PY_CFLAGS) $(PY_CFLAGS_NODIST) $(PY_CPPFLAGS) $(CFLAGSFORSHARED) -PY_BUILTIN_MODULE_CFLAGS= $(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE_BUILTIN +PY_BUILTIN_MODULE_CFLAGS= $(PY_EXTRA_STDMODULE_CFLAGS) $(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE_BUILTIN +PY_BUILTIN_MODULE_LDFLAGS= $(PY_EXTRA_STDMODULE_LDFLAGS) PY_CORE_CFLAGS= $(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE # Linker flags used for building the interpreter object files PY_CORE_LDFLAGS=$(PY_LDFLAGS) $(PY_LDFLAGS_NODIST) diff --git a/Misc/NEWS.d/next/Build/2025-03-28-15-34-49.gh-issue-131842.HB2qep.rst b/Misc/NEWS.d/next/Build/2025-03-28-15-34-49.gh-issue-131842.HB2qep.rst new file mode 100644 index 00000000000000..157fc86a606551 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2025-03-28-15-34-49.gh-issue-131842.HB2qep.rst @@ -0,0 +1,2 @@ +Allow to pass custom ``CFLAGS`` and ``LDFLAGS`` to the compilation of +builtin extension modules. Patch by Pablo Galindo diff --git a/Modules/makesetup b/Modules/makesetup index 8bb971b152a522..95c9081219010b 100755 --- a/Modules/makesetup +++ b/Modules/makesetup @@ -274,7 +274,8 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | ;; esac rule="$file: $objs" - rule="$rule; \$(BLDSHARED) $objs $libs \$(LIBPYTHON) -o $file" + ldd="\$(BLDSHARED) \$(PY_BUILTIN_MODULE_LDFLAGS)" + rule="$rule; $ldd $objs $libs \$(LIBPYTHON) -o $file" echo "$rule" >>$rulesf done done diff --git a/configure b/configure index a058553480ca5a..237775a9601c5e 100755 --- a/configure +++ b/configure @@ -900,7 +900,9 @@ UNIVERSAL_ARCH_FLAGS WASM_STDLIB WASM_ASSETS_DIR LDFLAGS_NOLTO +PY_EXTRA_STDMODULE_LDFLAGS LDFLAGS_NODIST +PY_EXTRA_STDMODULE_CFLAGS CFLAGS_NODIST BASECFLAGS CFLAGS_ALIASING @@ -9725,6 +9727,8 @@ esac + + # The -arch flags for universal builds on macOS UNIVERSAL_ARCH_FLAGS= diff --git a/configure.ac b/configure.ac index 23bd81ed4431b9..85d765ce3524e0 100644 --- a/configure.ac +++ b/configure.ac @@ -2432,7 +2432,9 @@ AS_CASE([$enable_wasm_dynamic_linking], AC_SUBST([BASECFLAGS]) AC_SUBST([CFLAGS_NODIST]) +AC_SUBST([PY_EXTRA_STDMODULE_CFLAGS]) AC_SUBST([LDFLAGS_NODIST]) +AC_SUBST([PY_EXTRA_STDMODULE_LDFLAGS]) AC_SUBST([LDFLAGS_NOLTO]) AC_SUBST([WASM_ASSETS_DIR]) AC_SUBST([WASM_STDLIB])