diff -rupN --no-dereference Python-3.10.0rc1/configure.ac Python-3.10.0rc1-new/configure.ac
--- Python-3.10.0rc1/configure.ac 2021-08-02 21:53:59.000000000 +0200
+++ Python-3.10.0rc1-new/configure.ac 2021-08-04 16:36:56.010391643 +0200
@@ -383,6 +383,15 @@ AC_DEFINE_UNQUOTED(_PYTHONFRAMEWORK, "${
# Set name for machine-dependent library files
AC_ARG_VAR([MACHDEP], [name for machine-dependent library files])
AC_MSG_CHECKING(MACHDEP)
+case $host in
+ *-*-mingw*)
+ test -z "$MACHDEP" && MACHDEP=win32
+
+ dnl Configuration will be based only on "host triplet" as build
+ dnl must not depend from posix compatible environement.
+ ac_sys_system=ignore
+ ;;
+esac
if test -z "$MACHDEP"
then
# avoid using uname for cross builds
@@ -452,12 +461,23 @@ if test "$cross_compiling" = yes; then
*-*-vxworks*)
_host_cpu=$host_cpu
;;
+ *-*-mingw*)
+ _host_cpu=
+ ;;
*)
# for now, limit cross builds to known configurations
MACHDEP="unknown"
AC_MSG_ERROR([cross build not supported for $host])
esac
_PYTHON_HOST_PLATFORM="$MACHDEP${_host_cpu:+-$_host_cpu}"
+
+ case "$host_os" in
+ mingw*)
+ # As sys.platform() return 'win32' to build python and extantions
+ # we will use 'mingw' (in setup.py and etc.)
+ _PYTHON_HOST_PLATFORM=mingw
+ ;;
+ esac
fi
# Some systems cannot stand _XOPEN_SOURCE being defined at all; they
@@ -888,6 +908,28 @@ if test x$MULTIARCH != x; then
fi
AC_SUBST(MULTIARCH_CPPFLAGS)
+# initialize default configuration
+py_config=
+case $host in
+ *-*-mingw*) py_config=mingw ;;
+esac
+if test -n "$py_config" ; then
+ AC_MSG_NOTICE([loading configure defaults from .../Misc/config_$py_config"])
+ . "$srcdir/Misc/config_$py_config"
+fi
+
+# initialize defaults for cross-builds
+if test "$cross_compiling" = yes; then
+ py_config=$host_os
+ case $py_config in
+ mingw32*) py_config=mingw32 ;;
+ esac
+ if test -f "$srcdir/Misc/cross_$py_config" ; then
+ AC_MSG_NOTICE([loading cross defaults from .../Misc/cross_$py_config"])
+ . "$srcdir/Misc/cross_$py_config"
+ fi
+fi
+
AC_MSG_CHECKING([for -Wl,--no-as-needed])
save_LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS -Wl,--no-as-needed"
@@ -1175,6 +1217,13 @@ if test $enable_shared = "yes"; then
;;
esac
+ case $host in
+ *-*-mingw*)
+ LDLIBRARY='libpython$(LDVERSION).dll.a'
+ DLLLIBRARY='libpython$(LDVERSION).dll'
+ BLDLIBRARY='-L. -lpython$(LDVERSION)'
+ ;;
+ esac
else # shared is disabled
PY_ENABLE_SHARED=0
case $ac_sys_system in
@@ -1183,6 +1232,10 @@ else # shared is disabled
LDLIBRARY='libpython$(LDVERSION).dll.a'
;;
esac
+ case $host in
+ *-*-mingw*)
+ LDLIBRARY='libpython$(LDVERSION).a';;
+ esac
fi
if test "$cross_compiling" = yes; then
@@ -2584,6 +2637,9 @@ if test -z "$SHLIB_SUFFIX"; then
CYGWIN*) SHLIB_SUFFIX=.dll;;
*) SHLIB_SUFFIX=.so;;
esac
+ case $host_os in
+ mingw*) SHLIB_SUFFIX=.dll;;
+ esac
fi
AC_MSG_RESULT($SHLIB_SUFFIX)
@@ -2708,6 +2764,12 @@ then
LDCXXSHARED="g++ -shared -Wl,--enable-auto-image-base";;
*) LDSHARED="ld";;
esac
+ case $host in
+ *-*-mingw*)
+ LDSHARED='$(CC) -shared -Wl,--enable-auto-image-base'
+ LDCXXSHARED='$(CXX) -shared -Wl,--enable-auto-image-base'
+ ;;
+ esac
fi
AC_MSG_RESULT($LDSHARED)
LDCXXSHARED=${LDCXXSHARED-$LDSHARED}
@@ -3654,6 +3716,12 @@ then
fi
;;
esac
+ case $host in
+ *-*-mingw*)
+ DYNLOADFILE="dynload_win.o"
+ extra_machdep_objs="$extra_machdep_objs PC/dl_nt.o"
+ ;;
+ esac
fi
AC_MSG_RESULT($DYNLOADFILE)
if test "$DYNLOADFILE" != "dynload_stub.o"
@@ -5528,6 +5596,12 @@ case "$ac_cv_computed_gotos" in yes*)
AC_DEFINE(HAVE_COMPUTED_GOTOS, 1,
[Define if the C compiler supports computed gotos.])
esac
+case $host_os in
+ mingw*)
+ dnl Synchronized with _PyImport_DynLoadFiletab (dynload_win.c)
+ dnl Do not use more then one dot on this platform !
+ EXT_SUFFIX=-$SOABI$SHLIB_SUFFIX;;
+esac
case $ac_sys_system in
AIX*)
diff -rupN --no-dereference Python-3.10.0rc1/Include/pylifecycle.h Python-3.10.0rc1-new/Include/pylifecycle.h
--- Python-3.10.0rc1/Include/pylifecycle.h 2021-08-02 21:53:59.000000000 +0200
+++ Python-3.10.0rc1-new/Include/pylifecycle.h 2021-08-04 16:36:56.010391643 +0200
@@ -46,7 +46,7 @@ PyAPI_FUNC(wchar_t *) Py_GetPrefix(void)
PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void);
PyAPI_FUNC(wchar_t *) Py_GetPath(void);
PyAPI_FUNC(void) Py_SetPath(const wchar_t *);
-#ifdef MS_WINDOWS
+#ifdef _MSC_VER
int _Py_CheckPython3(void);
#endif
diff -rupN --no-dereference Python-3.10.0rc1/Include/pyport.h Python-3.10.0rc1-new/Include/pyport.h
--- Python-3.10.0rc1/Include/pyport.h 2021-08-02 21:53:59.000000000 +0200
+++ Python-3.10.0rc1-new/Include/pyport.h 2021-08-04 16:36:56.010391643 +0200
@@ -26,6 +26,21 @@
#endif
+#ifdef __MINGW32__
+/* Translate GCC[mingw*] platform specific defines to those
+ * used in python code.
+ */
+#if !defined(MS_WIN64) && defined(_WIN64)
+# define MS_WIN64
+#endif
+#if !defined(MS_WIN32) && defined(_WIN32)
+# define MS_WIN32
+#endif
+#if !defined(MS_WINDOWS) && defined(MS_WIN32)
+# define MS_WINDOWS
+#endif
+#endif /* __MINGW32__*/
+
/**************************************************************************
Symbols and macros to supply platform-independent interfaces to basic
C language & library operations whose spellings vary across platforms.
@@ -654,12 +669,12 @@ extern char * _getpty(int *, int, mode_t
*/
/*
- All windows ports, except cygwin, are handled in PC/pyconfig.h.
+ Only MSVC windows ports is handled in PC/pyconfig.h.
- Cygwin is the only other autoconf platform requiring special
+ Cygwin and Mingw is the only other autoconf platform requiring special
linkage handling and it uses __declspec().
*/
-#if defined(__CYGWIN__)
+#if defined(__CYGWIN__) || defined(__MINGW32__)
# define HAVE_DECLSPEC_DLL
#endif
@@ -672,21 +687,23 @@ extern char * _getpty(int *, int, mode_t
# define PyAPI_FUNC(RTYPE) Py_EXPORTED_SYMBOL RTYPE
# define PyAPI_DATA(RTYPE) extern Py_EXPORTED_SYMBOL RTYPE
/* module init functions inside the core need no external linkage */
- /* except for Cygwin to handle embedding */
-# if defined(__CYGWIN__)
+ /* except for Cygwin/Mingw to handle embedding */
+# if defined(__CYGWIN__) || defined(__MINGW32__)
# define PyMODINIT_FUNC Py_EXPORTED_SYMBOL PyObject*
-# else /* __CYGWIN__ */
+# else /* __CYGWIN__ || __MINGW32__*/
# define PyMODINIT_FUNC PyObject*
-# endif /* __CYGWIN__ */
+# endif /* __CYGWIN__ || __MINGW32__*/
# else /* Py_BUILD_CORE */
/* Building an extension module, or an embedded situation */
/* public Python functions and data are imported */
/* Under Cygwin, auto-import functions to prevent compilation */
/* failures similar to those described at the bottom of 4.1: */
/* http://docs.python.org/extending/windows.html#a-cookbook-approach */
-# if !defined(__CYGWIN__)
+# if defined(__CYGWIN__) || defined(__MINGW32__)
+# define PyAPI_FUNC(RTYPE) RTYPE
+# else
# define PyAPI_FUNC(RTYPE) Py_IMPORTED_SYMBOL RTYPE
-# endif /* !__CYGWIN__ */
+# endif /* __CYGWIN__ || __MINGW32__*/
# define PyAPI_DATA(RTYPE) extern Py_IMPORTED_SYMBOL RTYPE
/* module init functions outside the core must be exported */
# if defined(__cplusplus)
diff -rupN --no-dereference Python-3.10.0rc1/Makefile.pre.in Python-3.10.0rc1-new/Makefile.pre.in
--- Python-3.10.0rc1/Makefile.pre.in 2021-08-02 21:53:59.000000000 +0200
+++ Python-3.10.0rc1-new/Makefile.pre.in 2021-08-04 16:36:56.011391633 +0200
@@ -824,6 +824,12 @@ Python/dynload_hpux.o: $(srcdir)/Python/
-DSHLIB_EXT='"$(EXT_SUFFIX)"' \
-o $@ $(srcdir)/Python/dynload_hpux.c
+Python/dynload_win.o: $(srcdir)/Python/dynload_win.c Makefile
+ $(CC) -c $(PY_CORE_CFLAGS) \
+ -DSHLIB_SUFFIX='"$(SHLIB_SUFFIX)"' \
+ -DEXT_SUFFIX='"$(EXT_SUFFIX)"' \
+ -o $@ $(srcdir)/Python/dynload_win.c
+
Python/sysmodule.o: $(srcdir)/Python/sysmodule.c Makefile $(srcdir)/Include/pydtrace.h
$(CC) -c $(PY_CORE_CFLAGS) \
-DABIFLAGS='"$(ABIFLAGS)"' \
diff -rupN --no-dereference Python-3.10.0rc1/Misc/config_mingw Python-3.10.0rc1-new/Misc/config_mingw
--- Python-3.10.0rc1/Misc/config_mingw 1970-01-01 01:00:00.000000000 +0100
+++ Python-3.10.0rc1-new/Misc/config_mingw 2021-08-04 16:36:56.011391633 +0200
@@ -0,0 +1,12 @@
+# configure defaults for mingw* hosts
+
+# mingw functions to ignore
+ac_cv_func_ftruncate=ignore # implement it as _chsize
+
+# mingw-w64 functions to ignore
+ac_cv_func_truncate=ignore
+ac_cv_func_alarm=ignore
+
+# files to ignore
+ac_cv_file__dev_ptmx=ignore #NOTE: under MSYS environment device exist
+ac_cv_file__dev_ptc=no
diff -rupN --no-dereference Python-3.10.0rc1/Misc/cross_mingw32 Python-3.10.0rc1-new/Misc/cross_mingw32
--- Python-3.10.0rc1/Misc/cross_mingw32 1970-01-01 01:00:00.000000000 +0100
+++ Python-3.10.0rc1-new/Misc/cross_mingw32 2021-08-04 16:36:56.011391633 +0200
@@ -0,0 +1,11 @@
+# configure defaults for mingw32 host if cross-build
+
+ac_cv_little_endian_double=yes
+ac_cv_big_endian_double=no
+ac_cv_mixed_endian_double=no
+
+ac_cv_tanh_preserves_zero_sign=yes
+
+ac_cv_wchar_t_signed=no
+
+ac_cv_have_size_t_format=no
diff -rupN --no-dereference Python-3.10.0rc1/Python/dynload_win.c Python-3.10.0rc1-new/Python/dynload_win.c
--- Python-3.10.0rc1/Python/dynload_win.c 2021-08-02 21:53:59.000000000 +0200
+++ Python-3.10.0rc1-new/Python/dynload_win.c 2021-08-04 16:36:56.011391633 +0200
@@ -27,6 +27,12 @@
#define PYD_UNTAGGED_SUFFIX PYD_DEBUG_SUFFIX ".pyd"
const char *_PyImport_DynLoadFiletab[] = {
+#ifdef EXT_SUFFIX
+ EXT_SUFFIX, /* include SOABI flags where is encoded debug */
+#endif
+#ifdef SHLIB_SUFFIX
+ "-abi" PYTHON_ABI_STRING SHLIB_SUFFIX,
+#endif
PYD_TAGGED_SUFFIX,
PYD_UNTAGGED_SUFFIX,
NULL
@@ -167,7 +173,9 @@ dl_funcptr _PyImport_FindSharedFuncptrWi
dl_funcptr p;
char funcname[258], *import_python;
+#ifdef _MSC_VER
_Py_CheckPython3();
+#endif
#if USE_UNICODE_WCHAR_CACHE
const wchar_t *wpathname = _PyUnicode_AsUnicode(pathname);
diff -rupN --no-dereference Python-3.10.0rc1/Python/getplatform.c Python-3.10.0rc1-new/Python/getplatform.c
--- Python-3.10.0rc1/Python/getplatform.c 2021-08-02 21:53:59.000000000 +0200
+++ Python-3.10.0rc1-new/Python/getplatform.c 2021-08-04 16:36:56.011391633 +0200
@@ -1,6 +1,12 @@
#include "Python.h"
+#ifdef __MINGW32__
+# undef PLATFORM
+/* see PC/pyconfig.h */
+# define PLATFORM "win32"
+#endif
+
#ifndef PLATFORM
#define PLATFORM "unknown"
#endif
diff -rupN --no-dereference Python-3.10.0rc1/Python/initconfig.c Python-3.10.0rc1-new/Python/initconfig.c
--- Python-3.10.0rc1/Python/initconfig.c 2021-08-02 21:53:59.000000000 +0200
+++ Python-3.10.0rc1-new/Python/initconfig.c 2021-08-04 16:36:56.012391623 +0200
@@ -133,7 +133,7 @@ static const char usage_6[] =
"PYTHONPYCACHEPREFIX: root directory for bytecode cache (pyc) files.\n"
"PYTHONWARNDEFAULTENCODING: enable opt-in EncodingWarning for 'encoding=None'.\n";
-#if defined(MS_WINDOWS)
+#if defined(_MSC_VER)
# define PYTHONHOMEHELP "<prefix>\\python{major}{minor}"
#else
# define PYTHONHOMEHELP "<prefix>/lib/pythonX.X"
@@ -1536,7 +1536,7 @@ config_init_program_name(PyConfig *confi
}
/* Last fall back: hardcoded name */
-#ifdef MS_WINDOWS
+#ifdef _MSC_VER
const wchar_t *default_program_name = L"python";
#else
const wchar_t *default_program_name = L"python3";
diff -rupN --no-dereference Python-3.10.0rc1/setup.py Python-3.10.0rc1-new/setup.py
--- Python-3.10.0rc1/setup.py 2021-08-02 21:53:59.000000000 +0200
+++ Python-3.10.0rc1-new/setup.py 2021-08-04 16:36:56.012391623 +0200
@@ -468,6 +468,9 @@ class PyBuildExt(build_ext):
def build_extensions(self):
self.set_srcdir()
+ if HOST_PLATFORM.startswith(('mingw', 'win', 'cygwin')):
+ self.compiler.define_macro("Py_BUILD_CORE_MODULE")
+
# Detect which modules should be compiled
self.detect_modules()