From 480c0f118613dde8fd28eca1b959469903986ae0 Mon Sep 17 00:00:00 2001 From: Yaksh Bariya Date: Sat, 7 Mar 2026 01:49:19 +0530 Subject: [PATCH 1/6] GH-138800: fix variable substitution in python3.pc for Android Essentially a revert of the part where LIBPYTHON is made to use BLDLIBRARY in 7f5e3f04f838686d65f1053a5e47f5d3faf0b228. We can't use BLDLIBRARY as it adds `-L.`, which is not expected behaviour. Part of downstream distribution of Termux porting Python 3.13 to Termux (Android). This is the revised version after proper review and fixes --- .../next/Build/2026-03-07-02-09-57.gh-issue-138800.VD8qbz.rst | 1 + configure | 2 +- configure.ac | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Build/2026-03-07-02-09-57.gh-issue-138800.VD8qbz.rst diff --git a/Misc/NEWS.d/next/Build/2026-03-07-02-09-57.gh-issue-138800.VD8qbz.rst b/Misc/NEWS.d/next/Build/2026-03-07-02-09-57.gh-issue-138800.VD8qbz.rst new file mode 100644 index 000000000000000..b04da2e2c6852f9 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-03-07-02-09-57.gh-issue-138800.VD8qbz.rst @@ -0,0 +1 @@ +fix LIBPYTHON substitution in python3.pc on Android diff --git a/configure b/configure index eca5f03cdcfb2d7..0fac5a47f460c89 100755 --- a/configure +++ b/configure @@ -27085,7 +27085,7 @@ LIBPYTHON='' # On Android and Cygwin the shared libraries must be linked with libpython. if test "$PY_ENABLE_SHARED" = "1" && ( test -n "$ANDROID_API_LEVEL" || test "$MACHDEP" = "cygwin"); then MODULE_DEPS_SHARED="$MODULE_DEPS_SHARED \$(LDLIBRARY)" - LIBPYTHON="\$(BLDLIBRARY)" + LIBPYTHON="-lpython${VERSION}${ABIFLAGS}" fi # On iOS the shared libraries must be linked with the Python framework diff --git a/configure.ac b/configure.ac index c21024a1e774337..8e7c741f3d37ce9 100644 --- a/configure.ac +++ b/configure.ac @@ -6488,7 +6488,7 @@ LIBPYTHON='' # On Android and Cygwin the shared libraries must be linked with libpython. if test "$PY_ENABLE_SHARED" = "1" && ( test -n "$ANDROID_API_LEVEL" || test "$MACHDEP" = "cygwin"); then MODULE_DEPS_SHARED="$MODULE_DEPS_SHARED \$(LDLIBRARY)" - LIBPYTHON="\$(BLDLIBRARY)" + LIBPYTHON="-lpython${VERSION}${ABIFLAGS}" fi # On iOS the shared libraries must be linked with the Python framework From 43e0d0445068f1fc2eca4a76eb1f8dbb823b695d Mon Sep 17 00:00:00 2001 From: Yaksh Bariya Date: Sat, 7 Mar 2026 02:24:49 +0530 Subject: [PATCH 2/6] fix: use BLDLIBRARY instead of LIBPYTHON whne building libraries patch based off of https://github.com/msys2-contrib/cpython-mingw/commit/e719663e07d6655e042f9c48910c65606cc4ae5e --- Modules/makesetup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/makesetup b/Modules/makesetup index 104c824b846540e..4d0ef59edeca83e 100755 --- a/Modules/makesetup +++ b/Modules/makesetup @@ -277,7 +277,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | ;; esac rule="$file: $objs \$(MODULE_${mods_upper}_LDEPS)" - rule="$rule; \$(BLDSHARED) $objs $libs \$(LIBPYTHON) -o $file" + rule="$rule; \$(BLDSHARED) $objs $libs \$(BLDLIBRARY) -o $file" echo "$rule" >>$rulesf done done From 7e8aa89e827e5cc09cf2fa1a14be96abb30ab271 Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Thu, 30 Jul 2026 16:35:24 +0100 Subject: [PATCH 3/6] Move `-L.` to makesetup, since that's the only place it's needed --- .../next/Build/2026-03-07-02-09-57.gh-issue-138800.VD8qbz.rst | 2 +- Modules/makesetup | 2 +- configure | 2 +- configure.ac | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Misc/NEWS.d/next/Build/2026-03-07-02-09-57.gh-issue-138800.VD8qbz.rst b/Misc/NEWS.d/next/Build/2026-03-07-02-09-57.gh-issue-138800.VD8qbz.rst index b04da2e2c6852f9..54b084d9d61277f 100644 --- a/Misc/NEWS.d/next/Build/2026-03-07-02-09-57.gh-issue-138800.VD8qbz.rst +++ b/Misc/NEWS.d/next/Build/2026-03-07-02-09-57.gh-issue-138800.VD8qbz.rst @@ -1 +1 @@ -fix LIBPYTHON substitution in python3.pc on Android +Fix library name in python3.pc on Android. diff --git a/Modules/makesetup b/Modules/makesetup index 4d0ef59edeca83e..f27897ca5e337ee 100755 --- a/Modules/makesetup +++ b/Modules/makesetup @@ -277,7 +277,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | ;; esac rule="$file: $objs \$(MODULE_${mods_upper}_LDEPS)" - rule="$rule; \$(BLDSHARED) $objs $libs \$(BLDLIBRARY) -o $file" + rule="$rule; \$(BLDSHARED) $objs $libs -L. \$(LIBPYTHON) -o $file" echo "$rule" >>$rulesf done done diff --git a/configure b/configure index f74191ac3061797..63be963f8d730bd 100755 --- a/configure +++ b/configure @@ -28001,7 +28001,7 @@ LIBPYTHON='' # On Android and Cygwin the shared libraries must be linked with libpython. if test "$PY_ENABLE_SHARED" = "1" && ( test -n "$ANDROID_API_LEVEL" || test "$MACHDEP" = "cygwin"); then MODULE_DEPS_SHARED="$MODULE_DEPS_SHARED \$(LDLIBRARY)" - LIBPYTHON="-lpython${VERSION}${ABIFLAGS}" + LIBPYTHON="-lpython${LDVERSION}" fi # On iOS the shared libraries must be linked with the Python framework diff --git a/configure.ac b/configure.ac index 1af9cef3de3e8df..f5229769324ffe6 100644 --- a/configure.ac +++ b/configure.ac @@ -6680,7 +6680,7 @@ LIBPYTHON='' # On Android and Cygwin the shared libraries must be linked with libpython. if test "$PY_ENABLE_SHARED" = "1" && ( test -n "$ANDROID_API_LEVEL" || test "$MACHDEP" = "cygwin"); then MODULE_DEPS_SHARED="$MODULE_DEPS_SHARED \$(LDLIBRARY)" - LIBPYTHON="-lpython${VERSION}${ABIFLAGS}" + LIBPYTHON="-lpython${LDVERSION}" fi # On iOS the shared libraries must be linked with the Python framework From efc7c5fd75b7e77106f38ae2bd65868964ebd8a0 Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Thu, 30 Jul 2026 16:41:26 +0100 Subject: [PATCH 4/6] Fix substitution --- configure | 2 +- configure.ac | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 63be963f8d730bd..f74191ac3061797 100755 --- a/configure +++ b/configure @@ -28001,7 +28001,7 @@ LIBPYTHON='' # On Android and Cygwin the shared libraries must be linked with libpython. if test "$PY_ENABLE_SHARED" = "1" && ( test -n "$ANDROID_API_LEVEL" || test "$MACHDEP" = "cygwin"); then MODULE_DEPS_SHARED="$MODULE_DEPS_SHARED \$(LDLIBRARY)" - LIBPYTHON="-lpython${LDVERSION}" + LIBPYTHON="-lpython${VERSION}${ABIFLAGS}" fi # On iOS the shared libraries must be linked with the Python framework diff --git a/configure.ac b/configure.ac index f5229769324ffe6..1af9cef3de3e8df 100644 --- a/configure.ac +++ b/configure.ac @@ -6680,7 +6680,7 @@ LIBPYTHON='' # On Android and Cygwin the shared libraries must be linked with libpython. if test "$PY_ENABLE_SHARED" = "1" && ( test -n "$ANDROID_API_LEVEL" || test "$MACHDEP" = "cygwin"); then MODULE_DEPS_SHARED="$MODULE_DEPS_SHARED \$(LDLIBRARY)" - LIBPYTHON="-lpython${LDVERSION}" + LIBPYTHON="-lpython${VERSION}${ABIFLAGS}" fi # On iOS the shared libraries must be linked with the Python framework From 3f0e18b589d0dae151da542249b1da1a89bfb6b3 Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Fri, 31 Jul 2026 13:10:25 +0100 Subject: [PATCH 5/6] Move `-L.` to a conditional Makefile variable --- Makefile.pre.in | 1 + Modules/makesetup | 2 +- configure | 9 ++++++--- configure.ac | 9 ++++++--- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index 465981f8fd4deda..fe8e4c51786e70c 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -44,6 +44,7 @@ ABIFLAGS= @ABIFLAGS@ ABI_THREAD= @ABI_THREAD@ LDVERSION= @LDVERSION@ LIBPYTHON=@LIBPYTHON@ +MODULE_LDFLAGS_SHARED=$(if $(LIBPYTHON),-L. $(LIBPYTHON)) GITVERSION= @GITVERSION@ GITTAG= @GITTAG@ GITBRANCH= @GITBRANCH@ diff --git a/Modules/makesetup b/Modules/makesetup index f27897ca5e337ee..8b28946608b5762 100755 --- a/Modules/makesetup +++ b/Modules/makesetup @@ -277,7 +277,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | ;; esac rule="$file: $objs \$(MODULE_${mods_upper}_LDEPS)" - rule="$rule; \$(BLDSHARED) $objs $libs -L. \$(LIBPYTHON) -o $file" + rule="$rule; \$(BLDSHARED) $objs $libs \$(MODULE_LDFLAGS_SHARED) -o $file" echo "$rule" >>$rulesf done done diff --git a/configure b/configure index f74191ac3061797..836eb88e4cdb6e5 100755 --- a/configure +++ b/configure @@ -27990,15 +27990,18 @@ LDVERSION='$(VERSION)$(ABIFLAGS)' printf "%s\n" "$LDVERSION" >&6; } # Configure the flags and dependencies used when compiling shared modules. -# Do not rename LIBPYTHON - it's accessed via sysconfig by package build -# systems (e.g. Meson) to decide whether to link extension modules against -# libpython. MODULE_DEPS_SHARED='$(MODULE_DEPS_STATIC) $(EXPORTSYMS)' + +# On most platforms, extension modules aren't linked against libpython, so +# LIBPYTHON must be empty. LIBPYTHON='' # On Android and Cygwin the shared libraries must be linked with libpython. +# LIBPYTHON is used by python-config, python3.pc, the commands for building the +# stdlib's own extension modules, and external package build systems via +# sysconfig, so its value must be suitable for all those contexts. if test "$PY_ENABLE_SHARED" = "1" && ( test -n "$ANDROID_API_LEVEL" || test "$MACHDEP" = "cygwin"); then MODULE_DEPS_SHARED="$MODULE_DEPS_SHARED \$(LDLIBRARY)" LIBPYTHON="-lpython${VERSION}${ABIFLAGS}" diff --git a/configure.ac b/configure.ac index 1af9cef3de3e8df..3a9841b1e7d0747 100644 --- a/configure.ac +++ b/configure.ac @@ -6669,15 +6669,18 @@ LDVERSION='$(VERSION)$(ABIFLAGS)' AC_MSG_RESULT([$LDVERSION]) # Configure the flags and dependencies used when compiling shared modules. -# Do not rename LIBPYTHON - it's accessed via sysconfig by package build -# systems (e.g. Meson) to decide whether to link extension modules against -# libpython. AC_SUBST([MODULE_DEPS_SHARED]) AC_SUBST([LIBPYTHON]) MODULE_DEPS_SHARED='$(MODULE_DEPS_STATIC) $(EXPORTSYMS)' + +# On most platforms, extension modules aren't linked against libpython, so +# LIBPYTHON must be empty. LIBPYTHON='' # On Android and Cygwin the shared libraries must be linked with libpython. +# LIBPYTHON is used by python-config, python3.pc, the commands for building the +# stdlib's own extension modules, and external package build systems via +# sysconfig, so its value must be suitable for all those contexts. if test "$PY_ENABLE_SHARED" = "1" && ( test -n "$ANDROID_API_LEVEL" || test "$MACHDEP" = "cygwin"); then MODULE_DEPS_SHARED="$MODULE_DEPS_SHARED \$(LDLIBRARY)" LIBPYTHON="-lpython${VERSION}${ABIFLAGS}" From 920a1fc9757f15ee8213f8271c5b4e1c1b939dae Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Fri, 31 Jul 2026 15:49:16 +0100 Subject: [PATCH 6/6] Use BLDLIBRARY as single source of truth for flags within Python's own build process --- Makefile.pre.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index fe8e4c51786e70c..46fa26e01572cc2 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -44,7 +44,6 @@ ABIFLAGS= @ABIFLAGS@ ABI_THREAD= @ABI_THREAD@ LDVERSION= @LDVERSION@ LIBPYTHON=@LIBPYTHON@ -MODULE_LDFLAGS_SHARED=$(if $(LIBPYTHON),-L. $(LIBPYTHON)) GITVERSION= @GITVERSION@ GITTAG= @GITTAG@ GITBRANCH= @GITBRANCH@ @@ -286,6 +285,7 @@ DIST= $(DISTFILES) $(DISTDIRS) LIBRARY= @LIBRARY@ LDLIBRARY= @LDLIBRARY@ BLDLIBRARY= @BLDLIBRARY@ +MODULE_LDFLAGS_SHARED=$(if $(LIBPYTHON),$(BLDLIBRARY)) PY3LIBRARY= @PY3LIBRARY@ DLLLIBRARY= @DLLLIBRARY@ LDLIBRARYDIR= @LDLIBRARYDIR@