From 39637ce7280056c8c15c02f1811e15b9908df534 Mon Sep 17 00:00:00 2001
From: Alexey Pavlov <alexpux@gmail.com>
Date: Fri, 29 Aug 2025 08:50:31 +0300
Subject: [PATCH 126/N] Fix DEBUG build. Add "_d" suffix for lib  and modules
 extension mimic to MSVC

---
 Lib/venv/__init__.py |  1 +
 Makefile.pre.in      |  8 ++++----
 configure.ac         | 11 +++++++----
 mingw_smoketests.py  |  4 +++-
 4 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py
index 86a3486..79a5fdf 100644
--- a/Lib/venv/__init__.py
+++ b/Lib/venv/__init__.py
@@ -13,6 +13,7 @@ import sysconfig
 import types
 import shlex
 
+
 CORE_VENV_DEPS = ('pip',)
 logger = logging.getLogger(__name__)
 
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 0f73ca4..741be73 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -168,8 +168,8 @@ WHEEL_PKG_DIR=	@WHEEL_PKG_DIR@
 # Detailed destination directories
 BINLIBDEST=	@BINLIBDEST@
 LIBDEST=	$(SCRIPTDIR)/python$(VERSION)$(ABI_THREAD)
-INCLUDEPY=	$(INCLUDEDIR)/python$(LDVERSION)
-CONFINCLUDEPY=	$(CONFINCLUDEDIR)/python$(LDVERSION)
+INCLUDEPY=	$(INCLUDEDIR)/python$(VERSION)
+CONFINCLUDEPY=	$(CONFINCLUDEDIR)/python$(VERSION)
 VENVLAUNCHERDIR=	$(BINLIBDEST)/venv/scripts/nt
 
 # Symbols used for using shared libraries
@@ -288,8 +288,8 @@ LIBRARY_DEPS=	@LIBRARY_DEPS@
 LINK_PYTHON_DEPS=@LINK_PYTHON_DEPS@
 PY_ENABLE_SHARED=	@PY_ENABLE_SHARED@
 STATIC_LIBPYTHON=	@STATIC_LIBPYTHON@
-ABI3DLLLIBRARY= libpython3.dll
-ABI3LDLIBRARY=  libpython3.dll.a
+ABI3DLLLIBRARY= libpython3$(ABIFLAGS).dll
+ABI3LDLIBRARY=  libpython3$(ABIFLAGS).dll.a
 
 
 LIBS=		@LIBS@
diff --git a/configure.ac b/configure.ac
index 6253bd9..9818d4f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1875,7 +1875,10 @@ then
   [Define if you want to build an interpreter with many run-time checks.])
   AC_MSG_RESULT([yes]);
   Py_DEBUG='true'
-  ABIFLAGS="${ABIFLAGS}d"
+  case $host in
+      *-*-mingw*)  ABIFLAGS="${ABIFLAGS}_d" ;;
+      *) ABIFLAGS="${ABIFLAGS}d" ;;
+  esac
 else AC_MSG_RESULT([no]); Py_DEBUG='false'
 fi],
 [AC_MSG_RESULT([no])])
@@ -2474,9 +2477,9 @@ _RESTORE_VAR([CFLAGS])
 
 # Optimization messes up debuggers, so turn it off for
 # debug builds.
-PYDEBUG_CFLAGS="-O0"
+PYDEBUG_CFLAGS="-D_DEBUG -O0"
 AS_VAR_IF([ac_cv_cc_supports_og], [yes],
-          [PYDEBUG_CFLAGS="-Og"])
+          [PYDEBUG_CFLAGS="-D_DEBUG -Og"])
 
 # tweak OPT based on compiler and platform, only if the user didn't set
 # it on the command line
@@ -6717,7 +6720,7 @@ fi
 AC_SUBST([EXT_SUFFIX])
 VERSION_NO_DOTS=$(echo $LDVERSION | tr -d .)
 if test -n "${PYD_PLATFORM_TAG}"; then
-  EXT_SUFFIX=".cp${VERSION_NO_DOTS}-${PYD_PLATFORM_TAG}${SHLIB_SUFFIX}"
+  EXT_SUFFIX="${ABIFLAGS}.cp${VERSION_NO_DOTS}-${PYD_PLATFORM_TAG}${SHLIB_SUFFIX}"
 else
   EXT_SUFFIX=.${SOABI}${SHLIB_SUFFIX}
 fi
diff --git a/mingw_smoketests.py b/mingw_smoketests.py
index 5af2764..61508df 100644
--- a/mingw_smoketests.py
+++ b/mingw_smoketests.py
@@ -226,12 +226,14 @@ class Tests(unittest.TestCase):
         self.assertTrue(sysconfig.get_platform().startswith("mingw"))
         self.assertTrue(sysconfig.get_config_var('SOABI').startswith("cpython-"))
         ext_suffix = sysconfig.get_config_var('EXT_SUFFIX')
+        abiflags = sysconfig.get_config_var('ABIFLAGS')
         self.assertTrue(ext_suffix.endswith(".pyd"))
         self.assertTrue("mingw" in ext_suffix)
         self.assertEqual(sysconfig.get_config_var('SHLIB_SUFFIX'), ".pyd")
         ext_suffixes = importlib.machinery.EXTENSION_SUFFIXES
         self.assertTrue(ext_suffix in ext_suffixes)
-        self.assertTrue(".pyd" in ext_suffixes)
+        untagged_ext = abiflags + '.pyd';
+        self.assertTrue(untagged_ext in ext_suffixes)
         if sysconfig.get_platform().startswith('mingw_i686'):
              self.assertEqual(sys.winver, ".".join(map(str, sys.version_info[:2])) + '-32')
         elif sysconfig.get_platform().startswith('mingw_aarch64'):
