From ed23e6e0d4a095b752a9219d6620b838a38099eb Mon Sep 17 00:00:00 2001 From: Roumen Petrov Date: Sat, 2 Feb 2013 02:01:43 +0200 Subject: [PATCH 03/24] issue6672-v2: Add Mingw recognition to pyport.h to allow building extensions see for reference _testimportmultiple.c --- Include/pyport.h | 28 +++++++++++++++------------- setup.py | 3 +++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Include/pyport.h b/Include/pyport.h index 8f5f28f..e91b3a6 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -747,37 +747,39 @@ extern pid_t forkpty(int *, char *, struct termios *, struct winsize *); */ /* - 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 are autoconf platforms requiring special linkage handling and it uses __declspec(). */ -#if defined(__CYGWIN__) +#if defined(__CYGWIN__) || defined(__MINGW32__) # define HAVE_DECLSPEC_DLL #endif /* only get special linkage if built as shared or platform is Cygwin */ #if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__) # if defined(HAVE_DECLSPEC_DLL) -# ifdef Py_BUILD_CORE +# if defined(Py_BUILD_CORE) || defined(Py_BUILD_CORE_MODULE) # define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE # define PyAPI_DATA(RTYPE) extern __declspec(dllexport) 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 __declspec(dllexport) PyObject* -# else /* __CYGWIN__ */ +# else # define PyMODINIT_FUNC PyObject* -# endif /* __CYGWIN__ */ -# else /* Py_BUILD_CORE */ +# endif +# 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 */ + /* Under Cygwin/Mingw, 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) __declspec(dllimport) RTYPE -# endif /* !__CYGWIN__ */ +# endif # define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE /* module init functions outside the core must be exported */ # if defined(__cplusplus) @@ -785,7 +787,7 @@ extern pid_t forkpty(int *, char *, struct termios *, struct winsize *); # else /* __cplusplus */ # define PyMODINIT_FUNC __declspec(dllexport) PyObject* # endif /* __cplusplus */ -# endif /* Py_BUILD_CORE */ +# endif /* Py_BUILD_CORE... */ # endif /* HAVE_DECLSPEC */ #endif /* Py_ENABLE_SHARED */ diff --git a/setup.py b/setup.py index dcaa804..f12302e 100644 --- a/setup.py +++ b/setup.py @@ -168,6 +168,9 @@ class PyBuildExt(build_ext): def build_extensions(self): + if host_platform.startswith(('mingw', 'win', 'cygwin')): + self.compiler.define_macro("Py_BUILD_CORE_MODULE") + # Detect which modules should be compiled missing = self.detect_modules() -- 1.7.12.1