From d6665e5343d10e45decec51da0c8e052087a10f1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?=
 <alexey.pawlow@gmail.com>
Date: Thu, 17 Jun 2021 18:51:38 +0530
Subject: [PATCH 017/N] sysconfig: treat MINGW builds as POSIX builds
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Алексей <alexey.pawlow@gmail.com>
Co-authored-by: Naveen M K <naveen521kk@gmail.com>
---
 Lib/sysconfig.py | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py
index ed24aeb..e05a67d 100644
--- a/Lib/sysconfig.py
+++ b/Lib/sysconfig.py
@@ -99,13 +99,18 @@ _INSTALL_SCHEMES = {
         },
     }
 
+# GCC[mingw*] use posix build system
+_POSIX_BUILD = os.name == 'posix' or \
+    (os.name == "nt" and 'GCC' in sys.version)
+
 # For the OS-native venv scheme, we essentially provide an alias:
-if os.name == 'nt':
+if os.name == 'nt' and not _POSIX_BUILD:
     _INSTALL_SCHEMES['venv'] = _INSTALL_SCHEMES['nt_venv']
 else:
     _INSTALL_SCHEMES['venv'] = _INSTALL_SCHEMES['posix_venv']
 
 
+
 # NOTE: site.py has copy of this function.
 # Sync it when modify this function.
 def _getuserbase():
@@ -120,7 +125,7 @@ def _getuserbase():
     def joinuser(*args):
         return os.path.expanduser(os.path.join(*args))
 
-    if os.name == "nt":
+    if os.name == "nt" and not _POSIX_BUILD:
         base = os.environ.get("APPDATA") or "~"
         return joinuser(base, "Python")
 
@@ -288,7 +293,7 @@ def _expand_vars(scheme, vars):
 
 
 def _get_preferred_schemes():
-    if os.name == 'nt':
+    if os.name == 'nt' and not _POSIX_BUILD:
         return {
             'prefix': 'nt',
             'home': 'posix_home',
@@ -622,7 +627,7 @@ def parse_config_h(fp, vars=None):
 def get_config_h_filename():
     """Return the path of pyconfig.h."""
     if _PYTHON_BUILD:
-        if os.name == "nt":
+        if os.name == "nt" and not _POSIX_BUILD:
             inc_dir = os.path.join(_PROJECT_BASE, "PC")
         else:
             inc_dir = _PROJECT_BASE
@@ -690,10 +695,10 @@ def _init_config_vars():
     except AttributeError:
         _CONFIG_VARS['py_version_nodot_plat'] = ''
 
-    if os.name == 'nt':
+    if os.name == 'nt' and not _POSIX_BUILD:
         _init_non_posix(_CONFIG_VARS)
         _CONFIG_VARS['VPATH'] = sys._vpath
-    if os.name == 'posix':
+    if _POSIX_BUILD:
         _init_posix(_CONFIG_VARS)
     if _HAS_USER_BASE:
         # Setting 'userbase' is done below the call to the
@@ -703,7 +708,7 @@ def _init_config_vars():
 
     # Always convert srcdir to an absolute path
     srcdir = _CONFIG_VARS.get('srcdir', _PROJECT_BASE)
-    if os.name == 'posix':
+    if _POSIX_BUILD:
         if _PYTHON_BUILD:
             # If srcdir is a relative path (typically '.' or '..')
             # then it should be interpreted relative to the directory
