File 0002-Fix-cross-building-Python-3.9.10.patch of Package mingw64-python3

From 23cb7c05a0c29f540dded2514a752ead8dd82a9a Mon Sep 17 00:00:00 2001
From: Ralf Habacker <ralf.habacker@freenet.de>
Date: Tue, 30 Aug 2022 12:30:24 +0200
Subject: [PATCH 02/12] Fix cross building Python 3.9.10

---
 CMakeLists.txt                  | 13 ++++++++-----
 cmake/ConfigureChecks.cmake     | 25 +++++++++++++++++--------
 cmake/Extensions.cmake          |  2 +-
 cmake/config-mingw/pyconfig.h   | 23 ++++++++++++++---------
 cmake/extensions/CMakeLists.txt |  4 ++--
 5 files changed, 42 insertions(+), 25 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index be183d7..7406798 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -428,7 +428,7 @@ include(cmake/ConfigureChecks.cmake)
 
 # Set PYTHONHOME
 set(LIBDIR "Lib") # See Lib/distutils/sysconfig.py - function 'get_python_lib'
-if(UNIX)
+if(UNIX OR MINGW)
     set(LIBDIR "lib")
 endif()
 if(USE_LIB64)
@@ -488,14 +488,17 @@ if(UNIX)
     set(PYCONFIG_BUILD_DIR ${BIN_BUILD_DIR})
     configure_file(cmake/config-unix/pyconfig.h.in
                    ${PYCONFIG_BUILD_DIR}/pyconfig.h)
-elseif(WIN32)
+elseif(MINGW)
+    set(PYCONFIG_BUILD_DIR ${BIN_BUILD_DIR})
+    configure_file(cmake/config-mingw/pyconfig.h
+        ${PYCONFIG_BUILD_DIR}/pyconfig.h @ONLY)
+    configure_file(${SRC_DIR}/PC/errmap.h
+        ${PYCONFIG_BUILD_DIR}/errmap.h COPYONLY)
+else()
     set(PYCONFIG_BUILD_DIR ${SRC_DIR}/PC) # In a windows build tree, 'pyconfig.h' is NOT required to
                                           # live along side the python executable.
                                           # See function '_init_posix()' and '_init_non_posix()'
                                           # in 'Lib/sysconfig.py'
-    if(MINGW)
-      set(PYCONFIG_BUILD_DIR cmake/config-mingw)
-    endif()
 endif()
 
 # Install 'pyconfig.h'
diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake
index e600a16..0b022c2 100644
--- a/cmake/ConfigureChecks.cmake
+++ b/cmake/ConfigureChecks.cmake
@@ -155,7 +155,7 @@ find_library(TIRPC_LIBRARY tirpc)
 
 find_library(UUID_LIBRARY uuid)
 
-if(WIN32)
+if(WIN32 AND NOT MINGW)
   set(M_LIBRARIES )
   set(HAVE_LIBM 1)
   # From PC/pyconfig.h: 
@@ -204,12 +204,19 @@ if(WITH_PYMALLOC AND PY_VERSION VERSION_LESS "3.8")
 endif()
 message(STATUS "${_msg} - ${ABIFLAGS}")
 
-set(_msg "Checking SOABI")
-try_run(PLATFORM_RUN PLATFORM_COMPILE
-        ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/platform.c
-        RUN_OUTPUT_VARIABLE PLATFORM_TRIPLET)
-if(NOT PLATFORM_COMPILE)
-  message(FATAL_ERROR "We could not determine the platform. Please clean the ${CMAKE_PROJECT_NAME} environment and try again...")
+if(MINGW)
+    execute_process(
+        COMMAND ${CMAKE_C_COMPILER} -dumpmachine
+        OUTPUT_VARIABLE PLATFORM_TRIPLET
+    )
+else()
+    set(_msg "Checking SOABI")
+    try_run(PLATFORM_RUN PLATFORM_COMPILE
+            ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/platform.c
+            RUN_OUTPUT_VARIABLE PLATFORM_TRIPLET)
+    if(NOT PLATFORM_COMPILE)
+      message(FATAL_ERROR "We could not determine the platform. Please clean the ${CMAKE_PROJECT_NAME} environment and try again...")
+    endif()
 endif()
 set(SOABI "cpython-${PY_VERSION_MAJOR}${PY_VERSION_MINOR}${ABIFLAGS}-${PLATFORM_TRIPLET}")
 
@@ -430,7 +437,9 @@ endif()
 find_library(HAVE_LIBTERMCAP termcap)
 
 set(LIBUTIL_LIBRARIES )
-set(LIBUTIL_EXPECTED 1)
+if(NOT MINGW)
+    set(LIBUTIL_EXPECTED 1)
+endif()
 
 if(CMAKE_SYSTEM MATCHES "VxWorks\\-7$")
   set(LIBUTIL_EXPECTED 0)
diff --git a/cmake/Extensions.cmake b/cmake/Extensions.cmake
index d9adc80..32475c9 100644
--- a/cmake/Extensions.cmake
+++ b/cmake/Extensions.cmake
@@ -178,7 +178,7 @@ function(add_python_extension name)
             if(require_limited_api STREQUAL "")
               list(APPEND ADD_PYTHON_EXTENSION_LIBRARIES libpython-shared)
             else()
-              list(APPEND ADD_PYTHON_EXTENSION_LIBRARIES libpython3-shared)
+              list(APPEND ADD_PYTHON_EXTENSION_LIBRARIES libpython-shared)
             endif()
         endif()
 
diff --git a/cmake/config-mingw/pyconfig.h b/cmake/config-mingw/pyconfig.h
index 5af0378..987cd53 100644
--- a/cmake/config-mingw/pyconfig.h
+++ b/cmake/config-mingw/pyconfig.h
@@ -86,16 +86,12 @@ WIN32 is still required for the locale module.
 /* set the version macros for the windows headers */
 #ifdef MS_WINX64
 /* 64 bit only runs on XP or greater */
-#  define Py_WINVER _WIN32_WINNT_WINXP
-#  define Py_NTDDI NTDDI_WINXP
+#  define Py_WINVER _WIN32_WINNT_WIN7
+#  define Py_NTDDI NTDDI_WIN7
 #else
 /* Python 2.6+ requires Windows 2000 or greater */
-#  ifdef _WIN32_WINNT_WIN2K
-#    define Py_WINVER _WIN32_WINNT_WIN2K
-#  else
-#    define Py_WINVER 0x0500
-#  endif
-#  define Py_NTDDI NTDDI_WIN2KSP4
+#  define Py_WINVER _WIN32_WINNT_WIN7
+#  define Py_NTDDI NTDDI_WIN7
 #endif
 
 /* We only set these values when building Python - we don't want to force
@@ -382,7 +378,7 @@ Py_NO_ENABLE_SHARED to find out.  Also support MS_NO_COREDLL for b/w compat */
 
 /* Define as the size of the unicode type. */
 /* This is enough for unicodeobject.h to do the "right thing" on Windows. */
-#define Py_UNICODE_SIZE 2
+/* #undef Py_UNICODE_SIZE */
 
 /* Use Python's own small-block memory-allocator. */
 #define WITH_PYMALLOC 1
@@ -563,4 +559,13 @@ Py_NO_ENABLE_SHARED to find out.  Also support MS_NO_COREDLL for b/w compat */
    least significant byte first */
 #define DOUBLE_IS_LITTLE_ENDIAN_IEEE754 1
 
+/* The size of `wchar_t', as computed by sizeof. */
+#cmakedefine SIZEOF_WCHAR_T @SIZEOF_WCHAR_T@
+
+#define PLATLIBDIR "lib"
+/* framework name [Python 3.7] */
+#define _PYTHONFRAMEWORK "@PYTHONFRAMEWORK@"
+
+#cmakedefine SIZEOF__BOOL @SIZEOF__BOOL@
+
 #endif /* !Py_CONFIG_H */
diff --git a/cmake/extensions/CMakeLists.txt b/cmake/extensions/CMakeLists.txt
index 5c66802..ec6f8c7 100644
--- a/cmake/extensions/CMakeLists.txt
+++ b/cmake/extensions/CMakeLists.txt
@@ -556,8 +556,8 @@ add_python_extension(_decimal
     ${_decimal_LIBRARIES}
     ${_decimal_INCLUDEDIRS}
 )
-if(_decimal_compile_flags AND ENABLE_DECIMAL AND NOT BUILTIN_DECIMAL)
-    set_target_properties(extension_decimal PROPERTIES COMPILE_FLAGS ${_decimal_compile_flags})
+if(TARGET extension_decimal AND _decimal_compile_flags AND ENABLE_DECIMAL AND NOT BUILTIN_DECIMAL)
+    set_target_properties(extension_decimal PROPERTIES COMPILE_FLAGS "${_decimal_compile_flags}")
 endif()
 
 endif()
-- 
2.35.3

openSUSE Build Service is sponsored by