diff -rupN --no-dereference Python-3.10.9/configure.ac Python-3.10.9-new/configure.ac --- Python-3.10.9/configure.ac 2022-12-06 19:31:21.000000000 +0100 +++ Python-3.10.9-new/configure.ac 2022-12-08 09:36:55.107024766 +0100 @@ -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 @@ -895,6 +915,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" @@ -1182,6 +1224,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 @@ -1190,6 +1239,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 @@ -2634,6 +2687,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) @@ -2758,6 +2814,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} @@ -3682,6 +3744,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" @@ -5556,6 +5624,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.9/Include/pylifecycle.h Python-3.10.9-new/Include/pylifecycle.h --- Python-3.10.9/Include/pylifecycle.h 2022-12-06 19:31:21.000000000 +0100 +++ Python-3.10.9-new/Include/pylifecycle.h 2022-12-08 09:36:55.107024766 +0100 @@ -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.9/Include/pyport.h Python-3.10.9-new/Include/pyport.h --- Python-3.10.9/Include/pyport.h 2022-12-06 19:31:21.000000000 +0100 +++ Python-3.10.9-new/Include/pyport.h 2022-12-08 09:36:55.108024766 +0100 @@ -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.9/Makefile.pre.in Python-3.10.9-new/Makefile.pre.in --- Python-3.10.9/Makefile.pre.in 2022-12-06 19:31:21.000000000 +0100 +++ Python-3.10.9-new/Makefile.pre.in 2022-12-08 09:36:55.108024766 +0100 @@ -823,6 +823,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.9/Misc/config_mingw Python-3.10.9-new/Misc/config_mingw --- Python-3.10.9/Misc/config_mingw 1970-01-01 01:00:00.000000000 +0100 +++ Python-3.10.9-new/Misc/config_mingw 2022-12-08 09:36:55.108024766 +0100 @@ -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.9/Misc/cross_mingw32 Python-3.10.9-new/Misc/cross_mingw32 --- Python-3.10.9/Misc/cross_mingw32 1970-01-01 01:00:00.000000000 +0100 +++ Python-3.10.9-new/Misc/cross_mingw32 2022-12-08 09:36:55.108024766 +0100 @@ -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.9/Python/dynload_win.c Python-3.10.9-new/Python/dynload_win.c --- Python-3.10.9/Python/dynload_win.c 2022-12-06 19:31:21.000000000 +0100 +++ Python-3.10.9-new/Python/dynload_win.c 2022-12-08 09:36:55.109024766 +0100 @@ -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.9/Python/getplatform.c Python-3.10.9-new/Python/getplatform.c --- Python-3.10.9/Python/getplatform.c 2022-12-06 19:31:21.000000000 +0100 +++ Python-3.10.9-new/Python/getplatform.c 2022-12-08 09:36:55.109024766 +0100 @@ -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.9/Python/initconfig.c Python-3.10.9-new/Python/initconfig.c --- Python-3.10.9/Python/initconfig.c 2022-12-06 19:31:21.000000000 +0100 +++ Python-3.10.9-new/Python/initconfig.c 2022-12-08 09:36:55.109024766 +0100 @@ -141,7 +141,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" @@ -1548,7 +1548,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.9/setup.py Python-3.10.9-new/setup.py --- Python-3.10.9/setup.py 2022-12-06 19:31:21.000000000 +0100 +++ Python-3.10.9-new/setup.py 2022-12-08 09:36:55.110024766 +0100 @@ -474,6 +474,9 @@ class PyBuildExt(build_ext): self.configure_compiler() self.init_inc_lib_dirs() + if HOST_PLATFORM.startswith(('mingw', 'win', 'cygwin')): + self.compiler.define_macro("Py_BUILD_CORE_MODULE") + # Detect which modules should be compiled self.detect_modules()