--- ./PC/_winreg.c.MINGW 2008-08-06 23:36:36.000000000 +0300 +++ ./PC/_winreg.c 2008-09-05 02:49:13.000000000 +0300 @@ -17,6 +17,18 @@ #include "malloc.h" /* for alloca */ #include "windows.h" +#if defined(__MINGW32__) +_CRTIMP size_t __cdecl _mbstrlen(const char *s); +#endif + +#if !defined(REG_LEGAL_CHANGE_FILTER) +#define REG_LEGAL_CHANGE_FILTER \ + (REG_NOTIFY_CHANGE_NAME |\ + REG_NOTIFY_CHANGE_ATTRIBUTES |\ + REG_NOTIFY_CHANGE_LAST_SET |\ + REG_NOTIFY_CHANGE_SECURITY) +#endif + static BOOL PyHKEY_AsHKEY(PyObject *ob, HKEY *pRes, BOOL bNoneOK); static PyObject *PyHKEY_FromHKEY(HKEY h); static BOOL PyHKEY_Close(PyObject *obHandle); --- ./PC/msvcrtmodule.c.MINGW 2008-08-06 23:36:36.000000000 +0300 +++ ./PC/msvcrtmodule.c 2008-09-14 21:08:14.000000000 +0300 @@ -22,6 +22,30 @@ #include #include +#if defined(__MINGW32__) +#if __MSVCRT_VERSION__ >= 0x0700 +/* FIXME: Up to version 3.14 mingw don't define next functions. + * Also it require module to be linked at least with msvcr70. + * The build process has to be improved to accept version + * for msvcrt and to define __MSVCRT_VERSION__ and + * specify library according given value. + * To use those functions you may run configure with: + * CPPFLAGS=-D__MSVCRT_VERSION__= 0x0700 + * LDFLAGS=-lmsvcr70 + * Also note that NT5.1(XP) is shiped with msvcrt version 7.0 + * contain those functions, but libary name is msvcrt.dll. + * If you link with -lmsvcr70 you executable willn't run + * since msvcr70.dll is missing. + * This isn't problem for native binary distrbution that + * contain a copy of requred microsoft C runtime. + */ +# define _WCONIO_DEFINED +_CRTIMP wint_t __cdecl __MINGW_NOTHROW _getwch (void); +_CRTIMP wint_t __cdecl __MINGW_NOTHROW _getwche (void); +_CRTIMP wint_t __cdecl __MINGW_NOTHROW _putwch (wchar_t); +#endif +#endif + // Force the malloc heap to clean itself up, and free unused blocks // back to the OS. (According to the docs, only works on NT.) static PyObject * --- ./Python/dynload_win.c.MINGW 2008-08-06 23:36:03.000000000 +0300 +++ ./Python/dynload_win.c 2008-09-09 23:31:18.000000000 +0300 @@ -21,6 +21,10 @@ }; +#if defined(__MINGW32__) +/* strcasecmp fail to compile on gcc(mingw32 special) */ +# define strcasecmp fake_strcasecmp +#endif /* Case insensitive string compare, to avoid any dependencies on particular C RTL implementations */ --- ./Python/fileblocks.c.MINGW 2008-09-01 21:37:41.000000000 +0300 +++ ./Python/fileblocks.c 2008-09-01 21:45:09.000000000 +0300 @@ -0,0 +1,17 @@ +/* +-- Macro: AC_STRUCT_ST_BLOCKS + If `struct stat' contains an `st_blocks' member, define + `HAVE_STRUCT_STAT_ST_BLOCKS'. Otherwise, require an `AC_LIBOBJ' + replacement of `fileblocks'. +*/ + +#if !HAVE_STRUCT_STAT_ST_BLOCKS +/* If necessary you may see gnulib for replacement function: +off_t st_blocks (off_t size) +You may found code available under GPL2 or GPL3. +*/ +#else +/* This declaration is solely to ensure that after preprocessing + this file is never empty. */ +typedef int textutils_fileblocks_unused; +#endif --- ./Include/pymath.h.MINGW 2008-08-24 20:46:42.000000000 +0300 +++ ./Include/pymath.h 2008-09-14 21:09:44.000000000 +0300 @@ -102,6 +102,8 @@ * it really can't be implemented correctly (& easily) before C99. * Override in pyconfig.h if you have a better spelling on your platform. * Note: PC/pyconfig.h defines Py_IS_INFINITY as _isinf + * FIXME: PC/pyconfig.h defines Py_IS_INFINITY as (!_finite(X) && !_isnan(X)) + * so that above note isn't correct !!! */ #ifndef Py_IS_INFINITY #ifdef HAVE_ISINF --- ./Include/pyport.h.MINGW 2008-08-06 23:36:05.000000000 +0300 +++ ./Include/pyport.h 2008-09-12 02:58:58.000000000 +0300 @@ -502,6 +502,123 @@ #endif /* 0 */ +#ifdef __MINGW32__ +/* FIXME: some of next definitions specific to gcc(mingw build) can be + generalized on definitions of _WIN32 or WIN32 and to be common for + all windows build instead explicitly to define only for non-autotools + based builds (see PC/pyconfig.h for details). */ +#if defined(_WIN64) +# define MS_WIN64 +#endif +#if !defined(MS_WIN32) && defined(_WIN32) +# define MS_WIN32 +#endif +#if !defined(MS_WIN32) && defined(_WIN32) +# define MS_WIN32 +#endif +#if !defined(MS_WINDOWS) && defined(MS_WIN32) +# define MS_WINDOWS +#endif + +#ifndef PYTHONPATH +# define PYTHONPATH ".\\DLLs;.\\lib;.\\lib\\plat-win;.\\lib\\lib-tk" +#endif + +/* python 2.6+ requires Windows 2000 or greater. */ +#define Py_WINVER 0x0500 + +#if defined(Py_BUILD_CORE) || defined(Py_BUILD_CORE_MODULE) +/* FIXME if NTDDI_xxx is in use by mingw (see PC/pyconfig.h) */ +#ifndef WINVER +# define WINVER Py_WINVER +#endif +#ifndef _WIN32_WINNT +# define _WIN32_WINNT Py_WINVER +#endif +#endif + +#ifdef PLATFORM +/*NOTE: if compile getplatform.c PLATFORM is set to MACHDEP that is + "win" for mingw build (see respective comment in configure.in). */ +# undef PLATFORM +#endif +/* always set to "win32" - see PC/pyconfig.h */ +#define PLATFORM "win32" + +#if defined(MS_WIN64) +# define SIZEOF_HKEY 8 +#elif defined(MS_WIN32) +# define SIZEOF_HKEY 4 +#endif + +/*NOTE: mingw has isinf as macro defined in math.h. + Since PC/pyconfig.h define Py_IS_INFINITY(X) that cover HAVE_ISINF + here for Py_IS_INFINITY we define same as native build. + This makes HAVE_ISINF needless. + Also see commants in configure.in and pymath.h. */ +#define Py_IS_INFINITY(X) (!_finite(X) && !_isnan(X)) + +#ifndef HAVE_LARGEFILE_SUPPORT +/* +FIXME: on windows platforms: + - Python use PY_LONG_LONG for Py_off_t (_fileio.c); + - HAVE_LARGEFILE_SUPPORT is defined in PC/pyconfig.h; + - PC/pyconfig.h define 4 for SIZEOF_OFF_T and 8 for SIZEOF_FPOS_T; + - If HAVE_LARGEFILE_SUPPORT isn't defined python will use off_t + for Py_off_t (see fileobjects.c and bz2module.c). +Since for mingw configure detect 4 for size of "off_t" and 8 - for "fpos_t" +we has to define HAVE_LARGEFILE_SUPPORT too. +TODO: to test with AC_SYS_LARGEFILE and appropriate updates in python code. +*/ +# define HAVE_LARGEFILE_SUPPORT +#endif + +#if defined(Py_ENABLE_SHARED) +# define MS_COREDLL 1 /* deprecated old symbol, but still in use for windows code */ +#else +# define MS_NO_COREDLL 1 +#endif + +#if Py_UNICODE_SIZE == 2 +/* For mingw is 2 but FIXME: What about to raise error in configure if + unicode size isn't two ? Did python windows code support ucs4 ? */ +# define Py_WIN_WIDE_FILENAMES +#endif + +/* NOTE: Don't define HAVE_STDDEF_H. + * It is defined by PC/pyconfig.h and used by Include/Python.h + * (with comment For size_t?) but isn't required for mingw */ +#define Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE + +/* All other defines from PC/pyconfig.h are in autoconf generated pyconfig.h */ +#if 0 +/* +FIXME: +MSDN: + "The getaddrinfo function was added to the ws2_32.dll on Windows XP and later." +mingw: + getaddrinfo and getnameinfo is defined for WINVER >= 0x0501. +PC/pyconfig.h: + "Python 2.6+ requires Windows 2000 or greater" +So far so good but socketmodule.h define HAVE_GETADDRINFO and HAVE_GETNAMEINFO +under very specific condition : + # ifdef SIO_GET_MULTICAST_FILTER + # include +So the question is "Separate SDKs" required for w2k in native build ? +TODO: resolve later, may by configure :-/. For now python code will use +fake implementation and if user define appropriate value for WINVER - +the functionas from C runtime. + */ +#ifndef HAVE_GETADDRINFO +# define HAVE_GETADDRINFO +#endif +#ifndef HAVE_GETNAMEINFO +# define HAVE_GETNAMEINFO +#endif +#endif + +#endif /*def __MINGW32__*/ + /* On 4.4BSD-descendants, ctype functions serves the whole range of * wchar_t character set rather than single byte code points only. * This characteristic can break some operations of string object @@ -546,17 +663,17 @@ */ /* - All windows ports, except cygwin, are handled in PC/pyconfig.h. + All windows ports, except cygwin and mingw32, are handled in PC/pyconfig.h. - BeOS and cygwin are the only other autoconf platform requiring special + BeOS, mingw32 and cygwin are the only other autoconf platform requiring special linkage handling and both of these use __declspec(). */ -#if defined(__CYGWIN__) || defined(__BEOS__) +#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BEOS__) # define HAVE_DECLSPEC_DLL #endif -/* only get special linkage if built as shared or platform is Cygwin */ -#if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__) +/* only get special linkage if built as shared or platform is Cygwin, Mingw32 */ +#if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__) || defined(__MINGW32__) # if defined(HAVE_DECLSPEC_DLL) # ifdef Py_BUILD_CORE # define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE @@ -569,14 +686,21 @@ # define PyMODINIT_FUNC void # endif /* __CYGWIN__ */ # else /* Py_BUILD_CORE */ + /* FIXME: FAQ.html#3.24 link below is no longer valid */ /* 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 http://python.org/doc/FAQ.html#3.24 */ -# if !defined(__CYGWIN__) +# if !defined(__CYGWIN__) && !defined(__MINGW32__) # define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE -# endif /* !__CYGWIN__ */ +# else +# define PyAPI_FUNC(RTYPE) RTYPE +# endif /* !__CYGWIN__ !__MINGW32__ */ +# if !defined(__MINGW32__) # define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE +# else +# define PyAPI_DATA(RTYPE) extern RTYPE +# endif /* !__MINGW32__ */ /* module init functions outside the core must be exported */ # if defined(__cplusplus) # define PyMODINIT_FUNC extern "C" __declspec(dllexport) void --- ./Makefile.pre.in.MINGW 2008-09-09 01:00:47.000000000 +0300 +++ ./Makefile.pre.in 2008-09-09 03:58:41.000000000 +0300 @@ -180,6 +180,10 @@ PROFILE_TASK= Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck #PROFILE_TASK= Lib/test/regrtest.py +# Don't define HOST_OS as makefile variable ! +@CROSS_ON@RUNPYTHON= HOST_OS=@HOST_OS@ @SYSPYTHON@ +@CROSS_OFF@RUNPYTHON= $(RUNSHARED) ./$(BUILDPYTHON) + # === Definitions added by makesetup === @@ -187,7 +191,7 @@ # Modules MODULE_OBJS= \ Modules/config.o \ - Modules/getpath.o \ + @MODULE_GETPATH@ \ Modules/main.o \ Modules/gcmodule.o @@ -259,7 +263,7 @@ Python/codecs.o \ Python/errors.o \ Python/frozen.o \ - Python/frozenmain.o \ + @PYTHON_OBJS_FROZENMAIN@ \ Python/future.o \ Python/getargs.o \ Python/getcompiler.o \ @@ -387,15 +391,21 @@ Modules/python.o \ $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST) +# FIXME: next produce incorrect result if cross-compiling platform: $(BUILDPYTHON) - $(RUNSHARED) ./$(BUILDPYTHON) -E -c 'import sys ; from distutils.util import get_platform ; print get_platform()+"-"+sys.version[0:3]' >platform + $(RUNPYTHON) -E -c 'import sys ; from distutils.util import get_platform ; print get_platform()+"-"+sys.version[0:3]' >platform # Build the shared modules +# FIXME: in cross-compilation env. (mingw on linux) how to select correct +# compiler/linker ? +# The current py-code will created modules with .so suffix and environment +# variable setting SO=$(SO) don't help. +# Also it link modules with gcc instead mingw... sharedmods: $(BUILDPYTHON) @case $$MAKEFLAGS in \ - *s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \ - *) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \ + *s*) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' $(RUNPYTHON) -E $(srcdir)/setup.py -q build @PYMOD_BUILDOPT@;; \ + *) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' $(RUNPYTHON) -E $(srcdir)/setup.py build @PYMOD_BUILDOPT@;; \ esac # Build static library @@ -494,6 +504,7 @@ $(srcdir)/Modules/getbuildinfo.c $(CC) -c $(PY_CFLAGS) -DSVNVERSION=\"`LC_ALL=C $(SVNVERSION)`\" -o $@ $(srcdir)/Modules/getbuildinfo.c +# default sys.path calculations Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile $(CC) -c $(PY_CFLAGS) -DPYTHONPATH='"$(PYTHONPATH)"' \ -DPREFIX='"$(prefix)"' \ @@ -502,10 +513,15 @@ -DVPATH='"$(VPATH)"' \ -o $@ $(srcdir)/Modules/getpath.c +# default sys.path calculations for windows platforms +PC/getpathp.o: $(srcdir)/PC/getpathp.c + $(CC) -c $(PY_CFLAGS) -o $@ $(srcdir)/PC/getpathp.c + Modules/python.o: $(srcdir)/Modules/python.c $(MAINCC) -c $(PY_CFLAGS) -o $@ $(srcdir)/Modules/python.c +# FIXME: next may fail in cross-compilation environment $(GRAMMAR_H) $(GRAMMAR_C): $(PGEN) $(GRAMMAR_INPUT) -@$(INSTALL) -d Include -$(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C) @@ -663,6 +679,7 @@ TESTOPTS= -l $(EXTRATESTOPTS) TESTPROG= $(srcdir)/Lib/test/regrtest.py +# FIXME: next test may fail in cross-compilation environment TESTPYTHON= $(RUNSHARED) ./$(BUILDPYTHON) -E -tt test: all platform -find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f @@ -873,24 +890,24 @@ done; \ done $(INSTALL_DATA) $(srcdir)/LICENSE $(DESTDIR)$(LIBDEST)/LICENSE.txt - PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ - ./$(BUILDPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \ + PYTHONPATH=$(DESTDIR)$(LIBDEST) \ + $(RUNPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \ -d $(LIBDEST) -f \ -x 'bad_coding|badsyntax|site-packages' $(DESTDIR)$(LIBDEST) - PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ - ./$(BUILDPYTHON) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \ + PYTHONPATH=$(DESTDIR)$(LIBDEST) \ + $(RUNPYTHON) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \ -d $(LIBDEST) -f \ -x 'bad_coding|badsyntax|site-packages' $(DESTDIR)$(LIBDEST) - -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ - ./$(BUILDPYTHON) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \ + -PYTHONPATH=$(DESTDIR)$(LIBDEST) \ + $(RUNPYTHON) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \ -d $(LIBDEST)/site-packages -f \ -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages - -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ - ./$(BUILDPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \ + -PYTHONPATH=$(DESTDIR)$(LIBDEST) \ + $(RUNPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \ -d $(LIBDEST)/site-packages -f \ -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages - -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ - ./$(BUILDPYTHON) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()" + -PYTHONPATH=$(DESTDIR)$(LIBDEST) \ + $(RUNPYTHON) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()" # Create the PLATDIR source directory, if one wasn't distributed.. $(srcdir)/Lib/$(PLATDIR): @@ -988,7 +1005,7 @@ # Install the dynamically loadable modules # This goes into $(exec_prefix) sharedinstall: - $(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \ + $(RUNPYTHON) -E $(srcdir)/setup.py install \ --prefix=$(prefix) \ --install-scripts=$(BINDIR) \ --install-platlib=$(DESTSHARED) \ @@ -1026,7 +1043,7 @@ fi; \ done $(LN) -fsn include/python$(VERSION) $(DESTDIR)$(prefix)/Headers - sed 's/%VERSION%/'"`$(RUNSHARED) ./$(BUILDPYTHON) -c 'import platform; print platform.python_version()'`"'/g' < $(RESSRCDIR)/Info.plist > $(DESTDIR)$(prefix)/Resources/Info.plist + sed 's/%VERSION%/'"`$(RUNPYTHON) -c 'import platform; print platform.python_version()'`"'/g' < $(RESSRCDIR)/Info.plist > $(DESTDIR)$(prefix)/Resources/Info.plist $(LN) -fsn $(VERSION) $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Versions/Current $(LN) -fsn Versions/Current/$(PYTHONFRAMEWORK) $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/$(PYTHONFRAMEWORK) $(LN) -fsn Versions/Current/Headers $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers @@ -1067,8 +1084,8 @@ # This installs a few of the useful scripts in Tools/scripts scriptsinstall: - SRCDIR=$(srcdir) $(RUNSHARED) \ - ./$(BUILDPYTHON) $(srcdir)/Tools/scripts/setup.py install \ + SRCDIR=$(srcdir) \ + $(RUNPYTHON) $(srcdir)/Tools/scripts/setup.py install \ --prefix=$(prefix) \ --install-scripts=$(BINDIR) \ --root=/$(DESTDIR) @@ -1186,7 +1203,7 @@ # Perform some verification checks on any modified files. patchcheck: - $(RUNSHARED) ./$(BUILDPYTHON) $(srcdir)/Tools/scripts/patchcheck.py + $(RUNPYTHON) $(srcdir)/Tools/scripts/patchcheck.py # Dependencies --- ./setup.py.MINGW 2008-08-06 23:38:07.000000000 +0300 +++ ./setup.py 2008-09-12 01:35:20.000000000 +0300 @@ -196,8 +196,26 @@ if compiler is not None: (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS') args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags + + # FIXME: Is next correct ? + # To link modules we need LDSHARED passed to setup.py otherwise + # distutils will use linker from build system if cross-compiling. + linker_so = os.environ.get('LDSHARED') + if linker_so is not None: + args['linker_so'] = linker_so + self.compiler.set_executables(**args) + if platform == 'mingw': + # FIXME: best way to pass just build python library to the modules + self.compiler.library_dirs.insert(0, '.') + data = open('pyconfig.h').read() + m = re.search(r"#s*define\s+Py_DEBUG\s+1\s*", data) + if m is not None: + self.compiler.libraries.append("python" + str(sysconfig.get_config_var('VERSION')) + "_d") + else: + self.compiler.libraries.append("python" + str(sysconfig.get_config_var('VERSION'))) + build_ext.build_extensions(self) longest = max([len(e.name) for e in self.extensions]) @@ -267,6 +285,10 @@ self.announce('WARNING: skipping import check for Cygwin-based "%s"' % ext.name) return + if os.environ.get('HOST_OS') is not None: + self.announce('WARNING: skipping import check for cross-compiled "%s"' + % ext.name) + return ext_filename = os.path.join( self.build_lib, self.get_ext_filename(self.get_ext_fullname(ext.name))) @@ -302,6 +324,19 @@ self.failed.append(ext.name) def get_platform(self): + # Get value of host platform (set only if cross-compile) + host_os=os.environ.get('HOST_OS') + if host_os is not None: + # FIXME: extend for other host platforms. + # Until isn't confirmed that we can use 'win32' in all places + # where 'mingw' is use alone this method has to return 'mingw' + # otherwise uncomment next two lines: + #if host_os.startswith('mingw'): + # return 'win32' + for platform in ['mingw', 'cygwin', 'beos', 'darwin', 'atheos', 'osf1']: + if host_os.startswith(platform): + return platform + return host_os # Get value of sys.platform for platform in ['cygwin', 'beos', 'darwin', 'atheos', 'osf1']: if sys.platform.startswith(platform): @@ -319,6 +354,9 @@ # directly since an inconsistently reproducible issue comes up where # the environment variable is not set even though the value were passed # into configure and stored in the Makefile (issue found on OS X 10.3). + # In cross-compilation environment python for build system + # is linked in top build directory under name syspython to get + # above to work (distutils hack). for env_var, arg_name, dir_list in ( ('LDFLAGS', '-L', self.compiler.library_dirs), ('CPPFLAGS', '-I', self.compiler.include_dirs)): @@ -392,6 +430,7 @@ # NOTE: using shlex.split would technically be more correct, but # also gives a bootstrap problem. Let's hope nobody uses directories # with whitespace in the name to store libraries. + # FIXME: Why LDFLAGS again ? cflags, ldflags = sysconfig.get_config_vars( 'CFLAGS', 'LDFLAGS') for item in cflags.split(): @@ -404,7 +443,7 @@ # Check for MacOS X, which doesn't need libm.a at all math_libs = ['m'] - if platform in ['darwin', 'beos', 'mac']: + if platform in ['darwin', 'beos', 'mac', 'mingw']: math_libs = [] # XXX Omitted modules: gl, pure, dl, SGI-specific modules @@ -488,8 +527,11 @@ # supported...) # fcntl(2) and ioctl(2) + if platform not in ['mingw']: exts.append( Extension('fcntl', ['fcntlmodule.c']) ) - if platform not in ['mac']: + else: + missing.append('fcntl') + if platform not in ['mac', 'mingw']: # pwd(3) exts.append( Extension('pwd', ['pwdmodule.c']) ) # grp(3) @@ -504,7 +546,12 @@ missing.extend(['pwd', 'grp', 'spwd']) # select(2); not on ancient System V - exts.append( Extension('select', ['selectmodule.c']) ) + if platform in ['mingw']: + select_libs = ['ws2_32'] + else: + select_libs = [] + exts.append( Extension('select', ['selectmodule.c'], + libraries=select_libs) ) # Fred Drake's interface to the Python parser exts.append( Extension('parser', ['parsermodule.c']) ) @@ -520,7 +567,7 @@ missing.append('mmap') # Lance Ellinghaus's syslog module - if platform not in ['mac']: + if platform not in ['mac', 'mingw']: # syslog daemon interface exts.append( Extension('syslog', ['syslogmodule.c']) ) else: @@ -554,6 +601,11 @@ # readline do_readline = self.compiler.find_library_file(lib_dirs, 'readline') + if platform in ['mingw']: + # Windows native builds don't use readline. + # In cross-compilation environment readline check will + # find libraries on build system. + do_readline = False if platform == 'darwin': # and os.uname()[2] < '9.': # MacOSX 10.4 has a broken readline. Don't try to build # the readline module unless the user has installed a fixed @@ -563,7 +615,7 @@ if find_file('readline/rlconf.h', inc_dirs, []) is None: do_readline = False if do_readline: - if sys.platform == 'darwin': + if platform == 'darwin': # In every directory on the search path search for a dynamic # library and then a static library, instead of first looking # for dynamic libraries on the entiry path. @@ -593,7 +645,7 @@ else: missing.append('readline') - if platform not in ['mac']: + if platform not in ['mac', 'mingw']: # crypt module. if self.compiler.find_library_file(lib_dirs, 'crypt'): @@ -608,7 +660,12 @@ exts.append( Extension('_csv', ['_csv.c']) ) # socket(2) + if platform in ['mingw']: + socket_libs = ['ws2_32'] + else: + socket_libs = [] exts.append( Extension('_socket', ['socketmodule.c'], + libraries=socket_libs, depends = ['socketmodule.h']) ) # Detect SSL support for the socket module (via _ssl) search_for_ssl_incs_in = [ @@ -630,10 +687,13 @@ if (ssl_incs is not None and ssl_libs is not None): + ssl_libs = ['ssl', 'crypto'] + if platform in ['mingw']: + ssl_libs.append('ws2_32') exts.append( Extension('_ssl', ['_ssl.c'], include_dirs = ssl_incs, library_dirs = ssl_libs, - libraries = ['ssl', 'crypto'], + libraries = ssl_libs, depends = ['socketmodule.h']), ) else: missing.append('_ssl') @@ -707,6 +767,27 @@ min_db_ver = (3, 3) db_setup_debug = False # verbose debug prints from this script? + # Modules with some Windows dependencies: + if platform == 'mingw': + (srcdir,) = sysconfig.get_config_vars('srcdir') + pc_srcdir = os.path.abspath(os.path.join(srcdir, 'PC')) + + exts.append( Extension('msvcrt', [os.path.join(pc_srcdir, p) + for p in ['msvcrtmodule.c']]) ) + + exts.append( Extension('_msi', [os.path.join(pc_srcdir, p) + for p in ['_msi.c']]) ) + + exts.append( Extension('_subprocess', [os.path.join(pc_srcdir, p) + for p in ['_subprocess.c']]) ) + + exts.append( Extension('_winreg', [os.path.join(pc_srcdir, p) + for p in ['_winreg.c']]) ) + + exts.append( Extension('winsound', [os.path.join(pc_srcdir, p) + for p in ['winsound.c']], + libraries=['winmm']) ) + def allow_db_ver(db_ver): """Returns a boolean if the given BerkeleyDB version is acceptable. @@ -948,13 +1029,13 @@ '_sqlite/util.c', ] sqlite_defines = [] - if sys.platform != "win32": + if platform != "win32": sqlite_defines.append(('MODULE_NAME', '"sqlite3"')) else: sqlite_defines.append(('MODULE_NAME', '\\"sqlite3\\"')) - if sys.platform == 'darwin': + if platform == 'darwin': # In every directory on the search path search for a dynamic # library and then a static library, instead of first looking # for dynamic libraries on the entiry path. @@ -1034,14 +1115,15 @@ missing.append('dbm') # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm: - if (self.compiler.find_library_file(lib_dirs, 'gdbm')): + if (platform not in ['mingw'] and + self.compiler.find_library_file(lib_dirs, 'gdbm')): exts.append( Extension('gdbm', ['gdbmmodule.c'], libraries = ['gdbm'] ) ) else: missing.append('gdbm') # Unix-only modules - if platform not in ['mac', 'win32']: + if platform not in ['mac', 'win32', 'mingw']: # Steen Lumholt's termios module exts.append( Extension('termios', ['termios.c']) ) # Jeremy Hylton's rlimit interface @@ -1066,6 +1148,8 @@ # Curses support, requiring the System V version of curses, often # provided by the ncurses library. panel_library = 'panel' + # FIXME: skip next tests on 'mingw' since in cross-compilation + # environment the code will find libraries from build system. if (self.compiler.find_library_file(lib_dirs, 'ncursesw')): curses_libs = ['ncursesw'] # Bug 1464056: If _curses.so links with ncursesw, @@ -1129,7 +1213,7 @@ break if version >= version_req: if (self.compiler.find_library_file(lib_dirs, 'z')): - if sys.platform == "darwin": + if platform == "darwin": zlib_extra_link_args = ('-Wl,-search_paths_first',) else: zlib_extra_link_args = () @@ -1161,7 +1245,7 @@ # Gustavo Niemeyer's bz2 module. if (self.compiler.find_library_file(lib_dirs, 'bz2')): - if sys.platform == "darwin": + if platform == "darwin": bz2_extra_link_args = ('-Wl,-search_paths_first',) else: bz2_extra_link_args = () @@ -1226,7 +1310,7 @@ if sys.maxint == 0x7fffffff: # This requires sizeof(int) == sizeof(long) == sizeof(char*) dl_inc = find_file('dlfcn.h', [], inc_dirs) - if (dl_inc is not None) and (platform not in ['atheos']): + if (dl_inc is not None) and (platform not in ['atheos', 'mingw']): exts.append( Extension('dl', ['dlmodule.c']) ) else: missing.append('dl') @@ -1237,7 +1321,7 @@ self.detect_ctypes(inc_dirs, lib_dirs) # Richard Oudkerk's multiprocessing module - if platform == 'win32': # Windows + if platform in ['win32', 'mingw']: # Windows macros = dict() libraries = ['ws2_32'] @@ -1277,7 +1361,7 @@ ) libraries = ['rt'] - if platform == 'win32': + if platform in ['win32', 'mingw']: multiprocessing_srcs = [ '_multiprocessing/multiprocessing.c', '_multiprocessing/semaphore.c', '_multiprocessing/pipe_connection.c', @@ -1293,7 +1377,9 @@ if macros.get('HAVE_SEM_OPEN', False): multiprocessing_srcs.append('_multiprocessing/semaphore.c') + #FIXME: why above set libraries aren't used ? exts.append ( Extension('_multiprocessing', multiprocessing_srcs, + libraries=libraries, define_macros=macros.items(), include_dirs=["Modules/_multiprocessing"])) # End multiprocessing @@ -1321,6 +1407,7 @@ if platform == 'darwin' and ("--disable-toolbox-glue" not in sysconfig.get_config_var("CONFIG_ARGS")): + #FIXME: next fail in cross-compilation environment if os.uname()[2] > '8.': # We're on Mac OS X 10.4 or later, the compiler should # support '-Wno-deprecated-declarations'. This will @@ -1523,7 +1610,7 @@ # Check for the include files on Debian and {Free,Open}BSD, where # they're put in /usr/include/{tcl,tk}X.Y dotversion = version - if '.' not in dotversion and "bsd" in sys.platform.lower(): + if '.' not in dotversion and "bsd" in platform.lower(): # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a, # but the include subdirs are named like .../include/tcl8.3. dotversion = dotversion[:-1] + '.' + dotversion[-1] @@ -1639,8 +1726,29 @@ return True def configure_ctypes(self, ext): + platform = self.get_platform() + if platform == 'mingw': + # win32 platform use own sources and includes + # from Modules/_ctypes/libffi_msvc/ + (srcdir,) = sysconfig.get_config_vars('srcdir') + ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules', + '_ctypes', 'libffi_msvc')) + #FIXME: _ctypes/libffi_msvc/win64.asm ? + sources = [os.path.join(ffi_srcdir, p) + for p in ['ffi.c', + 'prep_cif.c', + 'win32.S', + ]] + self.compiler.src_extensions.append('.S') + ext.include_dirs.append(ffi_srcdir) + ext.sources.extend(sources) + ext.libraries.extend(['ole32', 'oleaut32', 'uuid']) + #AdditionalOptions="/EXPORT:DllGetClassObject,PRIVATE /EXPORT:DllCanUnloadNow,PRIVATE" + ext.export_symbols.extend(['DllGetClassObject PRIVATE', + 'DllCanUnloadNow PRIVATE']) + return True if not self.use_system_libffi: - if sys.platform == 'darwin': + if platform == 'darwin': return self.configure_ctypes_darwin(ext) (srcdir,) = sysconfig.get_config_vars('srcdir') @@ -1699,14 +1807,15 @@ '_ctypes/malloc_closure.c'] depends = ['_ctypes/ctypes.h'] - if sys.platform == 'darwin': + platform = self.get_platform() + if platform == 'darwin': sources.append('_ctypes/darwin/dlfcn_simple.c') extra_compile_args.append('-DMACOSX') include_dirs.append('_ctypes/darwin') # XXX Is this still needed? ## extra_link_args.extend(['-read_only_relocs', 'warning']) - elif sys.platform == 'sunos5': + elif platform == 'sunos5': # XXX This shouldn't be necessary; it appears that some # of the assembler code is non-PIC (i.e. it has relocations # when it shouldn't. The proper fix would be to rewrite @@ -1717,7 +1826,7 @@ # finding some -z option for the Sun compiler. extra_link_args.append('-mimpure-text') - elif sys.platform.startswith('hp-ux'): + elif platform.startswith('hp-ux'): extra_link_args.append('-fPIC') ext = Extension('_ctypes', @@ -1727,14 +1836,19 @@ libraries=[], sources=sources, depends=depends) + if platform == 'mingw': + ctypes_test_libs = ['oleaut32'] + else: + ctypes_test_libs = [] ext_test = Extension('_ctypes_test', + libraries=ctypes_test_libs, sources=['_ctypes/_ctypes_test.c']) self.extensions.extend([ext, ext_test]) if not '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS"): return - if sys.platform == 'darwin': + if platform == 'darwin': # OS X 10.5 comes with libffi.dylib; the include files are # in /usr/include/ffi inc_dirs.append('/usr/include/ffi') --- ./configure.in.MINGW 2008-09-09 01:09:26.000000000 +0300 +++ ./configure.in 2008-09-12 03:00:39.000000000 +0300 @@ -45,6 +45,7 @@ AC_SUBST(CROSS_ON) AC_SUBST(CROSS_OFF) +AC_PROG_LN_S if test "x$cross_compiling" = xyes; then AC_MSG_WARN([cross-compilation is incomplete]) @@ -56,10 +57,33 @@ if test "x$PYTHON" = xnone; then AC_MSG_ERROR([python program is required in cross-compilation environment]) fi + SYSPYOSNAME=`${SYSPYTHON} -c "import os; print os.name"` + case $SYSPYOSNAME in + posix) + dnl On posix distutils read variables from installed makefile. + dnl We will do some hacks based on distutils internals to overcome + dnl this limitation: + dnl - we link system python in build directory so that it will + dnl read generated file. + dnl As result from sysconfig.get_config_vars we will get our + dnl setting (for the host system) like SO, CFLAGS, CPPFLAGS, + dnl LDFLAGS instead those for the build system. + rm -f syspython + ${LN_S} ${SYSPYTHON} syspython + SYSPYTHON=./syspython + esac fi AC_SUBST(VERSION) +case $host in + *-*-mingw*) + dnl To be compatible with native build. +VERSION=`echo PYTHON_VERSION | sed -e 's|\.||g'` + ;; + *) VERSION=PYTHON_VERSION + ;; +esac AC_SUBST(SOVERSION) SOVERSION=1.0 @@ -271,6 +295,22 @@ dnl point of view but same for python. if test -z "$MACHDEP" then + dnl set MACHDEP only on certain host systems + case $host in + *-*-mingw*) + dnl we use only case based on "host triplet" + ac_sys_system=ignore + dnl FIXME: what is correct: + dnl - PLATFORM is always "win32" (see define in PC/pyconfig.h ) + dnl - getplatform.o is build with -DPLATFORM='"$(MACHDEP)"' + dnl - the platform specific files go in plat-$(MACHDEP) + dnl - but an item in PYTHONPATH is "plat-win" !!! oops + MACHDEP=win + ;; + esac +fi +if test -z "$MACHDEP" +then ac_sys_system=`uname -s` if test "$ac_sys_system" = "AIX" -o "$ac_sys_system" = "Monterey64" \ -o "$ac_sys_system" = "UnixWare" -o "$ac_sys_system" = "OpenUNIX"; then @@ -421,6 +461,16 @@ fi AC_MSG_RESULT($MACHDEP) +AC_MSG_CHECKING([for init system calls]) +AC_SUBST(INITSYS) +case $host in + # FIXME: May configure lack detection for os2 host system ? + #?#*-*-os2*) INITSYS=os2;; + *-*-mingw*) INITSYS=nt;; + *) INITSYS=posix;; +esac +AC_MSG_RESULT([$INITSYS]) + # And add extra plat-mac for darwin AC_SUBST(EXTRAPLATDIR) AC_SUBST(EXTRAMACHDEPPATH) @@ -711,6 +761,10 @@ *) enable_shared="no";; esac + case $host in + *-*-mingw*) + enable_shared="yes";; + esac fi AC_MSG_RESULT($enable_shared) @@ -802,6 +856,14 @@ RUNSHARED=DLL_PATH=`pwd`:${DLL_PATH:-/atheos/sys/libs:/atheos/autolnk/lib} ;; esac + case $host in + *-*-mingw*) + LDLIBRARY='libpython$(VERSION).dll.a' + DLLLIBRARY='libpython$(VERSION).dll' + dnl setup.py add it for mingw host + dnl BLDLIBRARY='-L. -lpython$(VERSION)' + ;; + esac else # shared is disabled case $ac_sys_system in CYGWIN*) @@ -809,6 +871,10 @@ LDLIBRARY='libpython$(VERSION).dll.a' ;; esac + case $host in + *-*-mingw*) + LDLIBRARY='libpython$(VERSION).dll.a';; + esac fi AC_MSG_RESULT($LDLIBRARY) @@ -860,6 +926,33 @@ else AC_MSG_RESULT(no); Py_DEBUG='false' fi], [AC_MSG_RESULT(no)]) +if test "x$Py_DEBUG" = xtrue; then + case $host in + dnl Same as in PC/pyconfig.h but order in opposite. + *-*-mingw*) CPPFLAGS="-D_DEBUG $CPPFLAGS";; + esac +fi +# FIXME: We define BUILDEXEEXT and LDLIBRARY above but: +# Native windows build prepend suffix by '_d' for debug versions. +# If we will support this convention we may modify distutils +# To support different build directories too and is good +# --with-pydebug has to be earlier in the script. +if test "x$Py_DEBUG" = xtrue; then + case $host in + # Since Makefile.pre.in may isn't suitable for now we will not + # change LDLIBRARY. + *-*-mingw*) + BUILDEXEEXT=_d$BUILDEXEEXT + if test $enable_shared = "yes"; then + #LDLIBRARY='libpython$(VERSION)_d.dll.a' + DLLLIBRARY='libpython$(VERSION)_d.dll' + else # shared is disabled + #LDLIBRARY='libpython$(VERSION)_d.dll.a';; + : + fi + ;; + esac +fi # XXX Shouldn't the code above that fiddles with BASECFLAGS and OPT be # merged with this chunk of code? @@ -1231,6 +1324,20 @@ AC_MSG_RESULT($ac_cv_pthread) fi +if test "x$ac_cv_kpthread" = xno && \ + test "x$ac_cv_kthread" = xno && \ + test "x$ac_cv_pthread" = xno && \ + test "x$ac_cv_pthread_is_default" = xno +then + AC_MSG_CHECKING(for NT threads) + AC_CACHE_VAL(ac_cv_ntthread, + [AC_LINK_IFELSE( + AC_LANG_PROGRAM([], [_beginthread(0, 0, 0);]), + ac_cv_ntthread=yes, + ac_cv_ntthread=no)]) + AC_MSG_RESULT([$ac_cv_ntthread]) +fi + # If we have set a CC compiler flag for thread support then # check if it works for CXX, too. ac_cv_cxx_thread=no @@ -1251,6 +1358,9 @@ then CXX="$CXX -pthread" ac_cv_cxx_thread=yes +elif test "x$ac_cv_ntthread" = xyes +then + ac_cv_cxx_thread=always fi if test $ac_cv_cxx_thread = yes @@ -1292,7 +1402,7 @@ sys/termio.h sys/time.h \ sys/times.h sys/types.h sys/un.h sys/utsname.h sys/wait.h pty.h libutil.h \ sys/resource.h netpacket/packet.h sysexits.h bluetooth.h \ -bluetooth/bluetooth.h linux/tipc.h) +bluetooth/bluetooth.h linux/tipc.h winsock2.h) AC_HEADER_DIRENT AC_HEADER_MAJOR @@ -1644,6 +1754,16 @@ CYGWIN*) SO=.dll;; *) SO=.so;; esac + case $host in + *-*-mingw*) + #NOTE: see _PyImport_DynLoadFiletab in dynload_win.c + if test "x$Py_DEBUG" = xtrue; then + SO=_d.pyd + else + SO=.pyd + fi + ;; + esac else # this might also be a termcap variable, see #610332 echo @@ -1767,6 +1887,11 @@ atheos*) LDSHARED="gcc -shared";; *) LDSHARED="ld";; esac + case $host in + *-*-mingw*) + LDSHARED='$(CC) -shared -Wl,--enable-auto-image-base' + ;; + esac fi AC_MSG_RESULT($LDSHARED) BLDSHARED=${BLDSHARED-$LDSHARED} @@ -1864,6 +1989,12 @@ # when running test_compile.py. LINKFORSHARED='-Wl,-E -N 2048K';; esac + case $host in + *-*-mingw*) + if test $enable_shared = "no"; then + LINKFORSHARED='-Wl,--out-implib=$(LDLIBRARY)' + fi;; + esac fi AC_MSG_RESULT($LINKFORSHARED) @@ -1880,6 +2011,12 @@ *) CFLAGSFORSHARED='$(CCSHARED)' esac + case $host in + *-*-mingw) + # TODO mingw needs CCSHARED when building extension DLLs + # but not when building the interpreter DLL. + CFLAGSFORSHARED='';; + esac fi AC_MSG_RESULT($CFLAGSFORSHARED) @@ -2054,6 +2191,13 @@ AC_DEFINE(WITH_THREAD) posix_threads=yes THREADOBJ="Python/thread.o" +elif test "x$ac_cv_ntthread" = xyes +then + AC_DEFINE(WITH_THREAD) + posix_threads=no + THREADOBJ="Python/thread.o" + AC_DEFINE(NT_THREADS, 1, + [Define to 1 if you want to use native NT threads]) else if test ! -z "$with_threads" -a -d "$with_threads" then LDFLAGS="$LDFLAGS -L$with_threads" @@ -2484,6 +2628,14 @@ fi ;; esac + case $host in + *-*-mingw*) + # FIXME: it is good to use portable "$OBJEXT" instead "o" but + # python build isn't yet ready to use it (see Makefile.pre.in) + #DYNLOADFILE="dynload_win.$OBJEXT" + DYNLOADFILE="dynload_win.o" + ;; + esac fi AC_MSG_RESULT($DYNLOADFILE) if test "$DYNLOADFILE" != "dynload_stub.o" @@ -2496,6 +2648,11 @@ AC_SUBST(MACHDEP_OBJS) AC_MSG_CHECKING(MACHDEP_OBJS) +case $host in + *-*-mingw*) + extra_machdep_objs="PC/dl_nt.o PC/getpathp.o PC/import_nt.o" + ;; +esac if test -z "$MACHDEP_OBJS" then MACHDEP_OBJS=$extra_machdep_objs @@ -2522,6 +2679,17 @@ sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \ truncate uname unsetenv utimes waitpid wait3 wait4 wcscoll _getpty) +dnl FIXME: On windows platform some functions aren't C functions and require +dnl additional non-standard decoration and may be libraries. +dnl As example winsocket2 functions, although are based on berkeley sockets +dnl use stdcall convention. Also they require an additional library ws2_32. +dnl One of those functions is "getpeername" (see list above) +dnl and can't be detected by script. Now this impact mingw host platforms. +dnl Since this function is used only by socketmodule and this module +dnl include necessary headers and is linked with requred libs (see +dnl setup.py) windows exception will be handled in module code. +dnl If you don't like this, write appropriate check here. + # For some functions, having a definition is not sufficient, since # we want to take their address. AC_MSG_CHECKING(for chroot) @@ -2916,8 +3084,18 @@ buggygetaddrinfo=yes, AC_MSG_RESULT(buggy) buggygetaddrinfo=yes)], [ -AC_MSG_RESULT(no) +case $host in + #FIXME: mingw define getaddinfo if WINVER >= 0x501, i.e. XP or greater. + #TODO: mingw require additional check. + #*-*-mingw*) + # AC_MSG_RESULT([yes]) + # buggygetaddrinfo=no + # ;; + *) + AC_MSG_RESULT([no]) buggygetaddrinfo=yes + ;; +esac ]) if test "$buggygetaddrinfo" = "yes"; then @@ -2969,20 +3147,31 @@ AC_MSG_CHECKING(for addrinfo) AC_CACHE_VAL(ac_cv_struct_addrinfo, AC_TRY_COMPILE([ -# include ], +#ifdef HAVE_WINSOCK2_H +# include +#else +# include +#endif], [struct addrinfo a], ac_cv_struct_addrinfo=yes, ac_cv_struct_addrinfo=no)) AC_MSG_RESULT($ac_cv_struct_addrinfo) if test $ac_cv_struct_addrinfo = yes; then - AC_DEFINE(HAVE_ADDRINFO, 1, [struct addrinfo (netdb.h)]) + AC_DEFINE(HAVE_ADDRINFO, 1, [struct addrinfo]) fi AC_MSG_CHECKING(for sockaddr_storage) AC_CACHE_VAL(ac_cv_struct_sockaddr_storage, AC_TRY_COMPILE([ +#ifdef HAVE_SYS_TYPES_H # include -# include ], +#endif +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +#ifdef HAVE_WINSOCK2_H +#include +#endif], [struct sockaddr_storage s], ac_cv_struct_sockaddr_storage=yes, ac_cv_struct_sockaddr_storage=no)) @@ -3172,11 +3361,16 @@ # check for --with-libm=... AC_SUBST(LIBM) +dnl obsolete style to set libraries for a system case $ac_sys_system in Darwin) ;; BeOS) ;; *) LIBM=-lm esac +dnl new style to set libraries for host system +case $host in + *-*-mingw*) LIBM=;; +esac AC_MSG_CHECKING(for --with-libm=STRING) AC_ARG_WITH(libm, AC_HELP_STRING(--with-libm=STRING, math library), @@ -3242,6 +3436,13 @@ AC_REPLACE_FUNCS(hypot) +dnl FIXME: For mingw "isinf" is a macro defined in and cann't be +dnl detected as function. Also PC/pyconfig.h define HAVE_ISINF but it is +dnl useless since header define Py_IS_INFINITY as (!_finite(X) && !_isnan(X)) +dnl Note that comment in pymath.h that PC/pyconfig.h define _isinf +dnl isn't correct. +dnl For mingw to keep compatibility with native build we will +dnl define Py_IS_INFINITY in pyport.h. AC_CHECK_FUNCS(acosh asinh atanh copysign expm1 finite isinf isnan log1p) LIBS=$LIBS_SAVE @@ -3289,7 +3490,10 @@ ], ac_cv_wchar_t_signed=yes, ac_cv_wchar_t_signed=no, - ac_cv_wchar_t_signed=yes)]) + [case $host in + *-*-mingw*) ac_cv_wchar_t_signed=no;; + *) ac_cv_wchar_t_signed=yes;; + esac])]) AC_MSG_RESULT($ac_cv_wchar_t_signed) fi @@ -3782,9 +3986,12 @@ AC_DEFINE(PY_FORMAT_SIZE_T, "z", [Define to printf format modifier for Py_ssize_t])], AC_MSG_RESULT(no), [case $host in + *-*-mingw*) AC_MSG_RESULT(no);; *) AC_MSG_RESULT(cross-compiling, unknown);; esac]) +dnl Note check is incorrect for win host systems, i.e. mingw and etc., +dnl but on those systems socklen_t is defined in ws2tcpip.h as int ;) AC_CHECK_TYPE(socklen_t,, AC_DEFINE(socklen_t,int, Define to `int' if does not define.),[ @@ -3803,6 +4010,35 @@ THREADHEADERS="$THREADHEADERS \$(srcdir)/$h" done +# FIXME: in cross-compilation env. (mingw on linux) how to select correct compiler ? +# The current py-code will created modules with .so suffix and environment +# variable setting SO=$(SO) don't help +# set output of: python setup.py build --help-compiler +AC_SUBST(PYMOD_BUILDOPT) +case $host in + *-*-mingw*) PYMOD_BUILDOPT="--compiler mingw32";; +esac + +dnl Objects for python and modules +# Python interpreter main program for frozen scripts +AC_SUBST(PYTHON_OBJS_FROZENMAIN) +PYTHON_OBJS_FROZENMAIN="Python/frozenmain.o" +# MODULE_GETPATH - default sys.path calculations +AC_SUBST(MODULE_GETPATH) +MODULE_GETPATH=Modules/getpath.o +case $host in + *-*-mingw*) + dnl "PC" is project sub-directory and we has to prepend user defined flags + CPPFLAGS="-I\$(srcdir)/Python -I\$(srcdir)/PC $CPPFLAGS" + SRCDIRS="$SRCDIRS PC" + + # FIXME: why windows builds don't use PC/frozen_dllmain.o ? + PYTHON_OBJS_FROZENMAIN="" + # default sys.path calculations for windows platforms + MODULE_GETPATH=PC/getpathp.o + ;; +esac + AC_SUBST(SRCDIRS) SRCDIRS="Parser Grammar Objects Python Modules Mac" AC_MSG_CHECKING(for build directories) --- ./pyconfig.h.in.MINGW 2008-09-09 01:22:20.000000000 +0300 +++ ./pyconfig.h.in 2008-09-09 02:18:59.000000000 +0300 @@ -37,7 +37,7 @@ /* Define to 1 if you have the `acosh' function. */ #undef HAVE_ACOSH -/* struct addrinfo (netdb.h) */ +/* struct addrinfo */ #undef HAVE_ADDRINFO /* Define to 1 if you have the `alarm' function. */ @@ -803,6 +803,9 @@ /* Define to 1 if you have the `wcscoll' function. */ #undef HAVE_WCSCOLL +/* Define to 1 if you have the header file. */ +#undef HAVE_WINSOCK2_H + /* Define if tzset() actually switches the local timezone in a meaningful way. */ #undef HAVE_WORKING_TZSET @@ -830,6 +833,9 @@ /* Define if mvwdelch in curses.h is an expression. */ #undef MVWDELCH_IS_EXPRESSION +/* Define to 1 if you want to use native NT threads */ +#undef NT_THREADS + /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT --- ./Modules/getnameinfo.c.MINGW 2008-08-06 23:38:06.000000000 +0300 +++ ./Modules/getnameinfo.c 2008-09-05 03:34:59.000000000 +0300 @@ -48,6 +48,14 @@ #include "addrinfo.h" #endif +#ifndef IN_EXPERIMENTAL +#define IN_EXPERIMENTAL(i) (((i) & 0xe0000000U) == 0xe0000000U) +#endif + +#ifndef IN_LOOPBACKNET +#define IN_LOOPBACKNET 127 +#endif + #define SUCCESS 0 #define YES 1 #define NO 0 --- ./Modules/Setup.config.in.MINGW 2008-08-06 23:38:07.000000000 +0300 +++ ./Modules/Setup.config.in 2008-09-02 02:13:53.000000000 +0300 @@ -3,6 +3,9 @@ # The purpose of this file is to conditionally enable certain modules # based on configure-time options. +# init system calls(posix/nt/...) for INITFUNC (used by makesetup) +@INITSYS@ posixmodule.c + # Threading @USE_THREAD_MODULE@thread threadmodule.c --- ./Modules/Setup.dist.MINGW 2008-08-06 23:38:06.000000000 +0300 +++ ./Modules/Setup.dist 2008-09-05 01:07:00.000000000 +0300 @@ -112,9 +112,10 @@ # This only contains the minimal set of modules required to run the # setup.py script in the root of the Python source tree. -posix posixmodule.c # posix (UNIX) system calls errno errnomodule.c # posix (UNIX) errno values -pwd pwdmodule.c # this is needed to find out the user's home dir +#FIXME: setup.py detect this module along with grp and spwd. +#FIXME: why do n't comment ? +#pwd pwdmodule.c # this is needed to find out the user's home dir # if $HOME is not set _sre _sre.c # Fredrik Lundh's new regular expressions _codecs _codecsmodule.c # access to the builtin codecs and codec registry --- ./Modules/getaddrinfo.c.MINGW 2008-08-06 23:38:07.000000000 +0300 +++ ./Modules/getaddrinfo.c 2008-09-09 02:46:52.000000000 +0300 @@ -232,6 +232,9 @@ return YES; } +#ifndef EAI_BADHINTS +# define EAI_BADHINTS EAI_BADFLAGS +#endif int getaddrinfo(const char*hostname, const char*servname, const struct addrinfo *hints, struct addrinfo **res) --- ./Modules/posixmodule.c.MINGW 2008-08-25 00:36:20.000000000 +0300 +++ ./Modules/posixmodule.c 2008-09-09 03:31:12.000000000 +0300 @@ -25,6 +25,12 @@ #endif /* __APPLE__ */ +#ifdef __MINGW32__ +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +#endif /* __MINGW32__ */ + #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -130,6 +136,16 @@ #define HAVE_CWAIT 1 #define HAVE_FSYNC 1 #define fsync _commit +#elif defined(__MINGW32__) /* GCC (mingw special) compiler */ +/*#define HAVE_GETCWD 1 - detected by configure*/ +#define HAVE_SPAWNV 1 +/*#define HAVE_EXECV 1 - detected by configure*/ +#define HAVE_PIPE 1 +#define HAVE_POPEN 1 +#define HAVE_SYSTEM 1 +#define HAVE_CWAIT 1 +#define HAVE_FSYNC 1 +#define fsync _commit #else #if defined(PYOS_OS2) && defined(PYCC_GCC) || defined(__VMS) /* Everything needed is defined in PC/os2emx/pyconfig.h or vms/pyconfig.h */ @@ -258,7 +274,7 @@ #endif #endif -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__MINGW32__) #ifdef HAVE_DIRECT_H #include #endif @@ -273,7 +289,7 @@ #include /* for ShellExecute() */ #define popen _popen #define pclose _pclose -#endif /* _MSC_VER */ +#endif /* _MSC_VER || __MINGW32__ */ #if defined(PYCC_VACPP) && defined(PYOS_OS2) #include @@ -350,7 +366,7 @@ */ #include static char **environ; -#elif !defined(_MSC_VER) && ( !defined(__WATCOMC__) || defined(__QNX__) ) +#elif !defined(_MSC_VER) && !defined(__MINGW32__) && ( !defined(__WATCOMC__) || defined(__QNX__) ) extern char **environ; #endif /* !_MSC_VER */ @@ -8185,6 +8201,9 @@ #endif #ifdef MS_WINDOWS +#ifdef __MINGW32__ +# include +#endif PyDoc_STRVAR(win32_urandom__doc__, "urandom(n) -> str\n\n\ @@ -8891,7 +8910,7 @@ } -#if (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__)) && !defined(__QNX__) +#if (defined(_MSC_VER) || defined (__MINGW32__) || defined(__WATCOMC__) || defined(__BORLANDC__)) && !defined(__QNX__) #define INITFUNC initnt #define MODNAME "nt" --- ./Modules/socketmodule.c.MINGW 2008-08-18 22:39:26.000000000 +0300 +++ ./Modules/socketmodule.c 2008-09-11 01:45:27.000000000 +0300 @@ -91,6 +91,14 @@ #endif #include "Python.h" +#ifndef HAVE_GETPEERNAME +/* FIXME: see comments in configure.in. Also PC/pyconfig.h define it. + * Since only this module use getpeername why not remove declaration + * from PC/pyconfig.h and define hare if is defined MS_WIN32 ? */ +#ifdef __MINGW32__ +# define HAVE_GETPEERNAME +#endif +#endif /* ndef HAVE_GETPEERNAME */ #include "structmember.h" #undef MAX @@ -312,6 +320,23 @@ /* Do not include addrinfo.h for MSVC7 or greater. 'addrinfo' and * EAI_* constants are defined in (the already included) ws2tcpip.h. */ +#elif defined(__MINGW32__) +/* FIXME: getaddrinfo(HAVE_GETADDRINFO) depend from WINVER + TODO: resolve later(see comments in pyport.h) */ +# define EAI_ADDRFAMILY +# include "addrinfo.h" +#if 0 +/* For version before 0x0501 we may define functions below + and mingw linker will link binary. + TODO: to test result binary on w2k ! */ +#if (_WIN32_WINNT < 0x0501) +void WSAAPI freeaddrinfo (struct addrinfo*); +int WSAAPI getaddrinfo (const char*,const char*,const struct addrinfo*, + struct addrinfo**); +int WSAAPI getnameinfo(const struct sockaddr*,socklen_t,char*,DWORD, + char*,DWORD,int); +#endif +#endif #else # include "addrinfo.h" #endif @@ -349,6 +374,12 @@ #if !defined(HAVE_GETADDRINFO) /* avoid clashes with the C library definition of the symbol. */ #define getaddrinfo fake_getaddrinfo +#ifdef gai_strerror +/* As example mingw define gai_strerror to gai_strerror{A|W}. + FIXME: Since we use own function to suppress warnign we may undef ? + */ +# undef gai_strerror +#endif #define gai_strerror fake_gai_strerror #define freeaddrinfo fake_freeaddrinfo #include "getaddrinfo.c" @@ -2827,7 +2858,20 @@ Shut down the reading side of the socket (flag == SHUT_RD), the writing side\n\ of the socket (flag == SHUT_WR), or both ends (flag == SHUT_RDWR)."); +#ifndef SIO_RCVALL +#ifdef __MINGW32__ +/* defined in mstcpip.h, also note "Separate SDKs" required for w2k */ +# define SIO_RCVALL 0x98000001 +# define RCVALL_OFF 0 +# define RCVALL_ON 1 + /* NOTE: MSDN - this feature is not implemented */ +# define RCVALL_SOCKETLEVELONLY 2 +#endif +#endif #if defined(MS_WINDOWS) && defined(SIO_RCVALL) +/* If isn't defined test_socket.py fail with: +AttributeError: type object '_socket.socket' has no attribute 'ioctl' +*/ static PyObject* sock_ioctl(PySocketSockObject *s, PyObject *arg) { --- ./Objects/fileobject.c.MINGW 2008-08-18 22:39:20.000000000 +0300 +++ ./Objects/fileobject.c 2008-09-08 23:07:19.000000000 +0300 @@ -9,9 +9,15 @@ #endif /* HAVE_SYS_TYPES_H */ #ifdef MS_WINDOWS +#if !defined(__MINGW32__) +/* avoid 'warning: "fileno" redefined' */ #define fileno _fileno +#endif /* can simulate truncate with Win32 API functions; see file_truncate */ +#ifndef HAVE_FTRUNCATE +/* note autotool based build check and set it */ #define HAVE_FTRUNCATE +#endif #define WIN32_LEAN_AND_MEAN #include #endif