From 6b97645e5a529abee15d9fd27780f0130809d16f Mon Sep 17 00:00:00 2001
From: Naveen M K <naveen521kk@gmail.com>
Date: Tue, 14 Feb 2023 20:40:42 +0530
Subject: [PATCH 015/N] Enable some windows specific modules

---
 Modules/Setup.bootstrap.in   |  2 ++
 Modules/Setup.stdlib.in      |  7 +++++++
 Modules/_winapi.c            |  2 ++
 PC/msvcrtmodule.c            |  2 ++
 Python/dynamic_annotations.c |  2 +-
 configure.ac                 | 10 ++++++++++
 6 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/Modules/Setup.bootstrap.in b/Modules/Setup.bootstrap.in
index fe9f168..f0b3b73 100644
--- a/Modules/Setup.bootstrap.in
+++ b/Modules/Setup.bootstrap.in
@@ -39,3 +39,5 @@ _symtable symtablemodule.c
 
 # build-in modules for windows platform:
 @USE_WIN32_MODULE@winreg ../PC/winreg.c
+@MODULE_MSVCRT_TRUE@msvcrt -DPy_BUILD_CORE ../PC/msvcrtmodule.c
+@MODULE__WINAPI_TRUE@_winapi _winapi.c
diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in
index 57b9010..cc7290d 100644
--- a/Modules/Setup.stdlib.in
+++ b/Modules/Setup.stdlib.in
@@ -155,6 +155,13 @@
 # _scproxy needs SystemConfiguration and CoreFoundation framework
 @MODULE__SCPROXY_TRUE@_scproxy _scproxy.c
 
+############################################################################
+# Windows specific modules
+
+@MODULE__OVERLAPPED_TRUE@_overlapped overlapped.c
+@MODULE__MSI_TRUE@_msi ../PC/_msi.c
+@MODULE_WINSOUND_TRUE@winsound ../PC/winsound.c
+
 
 ############################################################################
 # Test modules
diff --git a/Modules/_winapi.c b/Modules/_winapi.c
index d51586e..3c2eb81 100644
--- a/Modules/_winapi.c
+++ b/Modules/_winapi.c
@@ -46,7 +46,9 @@
 #endif
 #include "windows.h"
 #include <winioctl.h>
+#if defined(Py_DEBUG)
 #include <crtdbg.h>
+#endif
 #include "winreparse.h"
 
 #if defined(MS_WIN32) && !defined(MS_WIN64)
diff --git a/PC/msvcrtmodule.c b/PC/msvcrtmodule.c
index b170e06..b4c3f92 100644
--- a/PC/msvcrtmodule.c
+++ b/PC/msvcrtmodule.c
@@ -22,7 +22,9 @@
 #include <io.h>
 #include <conio.h>
 #include <sys/locking.h>
+#ifdef _DEBUG
 #include <crtdbg.h>
+#endif
 #include <windows.h>
 
 #ifdef _MSC_VER
diff --git a/Python/dynamic_annotations.c b/Python/dynamic_annotations.c
index 7febaa0..70d5b3d 100644
--- a/Python/dynamic_annotations.c
+++ b/Python/dynamic_annotations.c
@@ -27,7 +27,7 @@
  * Author: Kostya Serebryany
  */
 
-#ifdef _MSC_VER
+#ifdef MS_WINDOWS
 # include <windows.h>
 #endif
 
diff --git a/configure.ac b/configure.ac
index 234a8dc..f3d7e2e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -8118,6 +8118,16 @@ PY_STDLIB_MOD([_ssl], [], [test "$ac_cv_working_openssl_ssl" = yes],
 PY_STDLIB_MOD([_hashlib], [], [test "$ac_cv_working_openssl_hashlib" = yes],
   [$OPENSSL_INCLUDES], [$OPENSSL_LDFLAGS $OPENSSL_LDFLAGS_RPATH $LIBCRYPTO_LIBS])
 
+dnl windows specific modules
+PY_STDLIB_MOD([msvcrt], [test "$MACHDEP" = "win32"])
+PY_STDLIB_MOD([_winapi], [test "$MACHDEP" = "win32"])
+PY_STDLIB_MOD([_msi], [test "$MACHDEP" = "win32"], [], [],
+  [-lmsi -lcabinet -lrpcrt4])
+PY_STDLIB_MOD([winsound], [test "$MACHDEP" = "win32"], [], [],
+  [-lwinmm])
+PY_STDLIB_MOD([_overlapped], [test "$MACHDEP" = "win32"], [], [],
+  [-lws2_32])
+
 dnl test modules
 PY_STDLIB_MOD([_testcapi],
     [test "$TEST_MODULES" = yes],
