diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..034ed13 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +.*.sw? diff --git a/Doc/Makefile b/Doc/Makefile index a435f11..8d6db6b 100644 --- a/Doc/Makefile +++ b/Doc/Makefile @@ -564,14 +564,14 @@ info-$(RELEASE).tar.bz2: info | bzip2 -9 >../$@ latex-$(RELEASE).tgz: - $(PYTHON) $(TOOLSDIR)/mksourcepkg --gzip $(RELEASE) + $(PYTHON) $(TOOLSDIR)/mksourcepkg --gzip $(RELEASE) tags/r252 latex-$(RELEASE).tar.bz2: - $(PYTHON) $(TOOLSDIR)/mksourcepkg --bzip2 $(RELEASE) + $(PYTHON) $(TOOLSDIR)/mksourcepkg --bzip2 $(RELEASE) tags/r252 latex-$(RELEASE).zip: rm -f $@ - $(PYTHON) $(TOOLSDIR)/mksourcepkg --zip $(RELEASE) + $(PYTHON) $(TOOLSDIR)/mksourcepkg --zip $(RELEASE) tags/r252 pdf-$(PAPER)-$(RELEASE).tar: $(PDFFILES) rm -f $@ @@ -700,7 +700,7 @@ pkglist: $(TOOLSDIR)/mkpkglist >pkglist.html distfiles: paperdist edist - $(TOOLSDIR)/mksourcepkg --bzip2 --zip $(RELEASE) + $(TOOLSDIR)/mksourcepkg --bzip2 --zip $(RELEASE) tags/r252 $(TOOLSDIR)/mkpkglist >pkglist.html diff --git a/Include/Python.h b/Include/Python.h index f0be28f..82b16fd 100644 --- a/Include/Python.h +++ b/Include/Python.h @@ -34,6 +34,11 @@ # error "Python.h requires that stdio.h define NULL." #endif +/* For uintptr_t, intptr_t */ +#ifdef HAVE_STDDEF_H +#include +#endif + #include #ifdef HAVE_ERRNO_H #include @@ -43,11 +48,6 @@ #include #endif -/* For uintptr_t, intptr_t */ -#ifdef HAVE_STDDEF_H -#include -#endif - /* CAUTION: Build setups should ensure that NDEBUG is defined on the * compiler command line when building Python in release mode; else * assert() calls won't be removed. diff --git a/Include/errmap.h b/Include/errmap.h new file mode 100644 index 0000000..59aeea1 --- /dev/null +++ b/Include/errmap.h @@ -0,0 +1,78 @@ +/* Generated file. Do not edit. */ +int winerror_to_errno(int winerror) +{ + switch(winerror) { + case 2: return 2; + case 3: return 2; + case 4: return 24; + case 5: return 13; + case 6: return 9; + case 7: return 12; + case 8: return 12; + case 9: return 12; + case 10: return 7; + case 11: return 8; + case 15: return 2; + case 16: return 13; + case 17: return 18; + case 18: return 2; + case 19: return 13; + case 20: return 13; + case 21: return 13; + case 22: return 13; + case 23: return 13; + case 24: return 13; + case 25: return 13; + case 26: return 13; + case 27: return 13; + case 28: return 13; + case 29: return 13; + case 30: return 13; + case 31: return 13; + case 32: return 13; + case 33: return 13; + case 34: return 13; + case 35: return 13; + case 36: return 13; + case 53: return 2; + case 65: return 13; + case 67: return 2; + case 80: return 17; + case 82: return 13; + case 83: return 13; + case 89: return 11; + case 108: return 13; + case 109: return 32; + case 112: return 28; + case 114: return 9; + case 128: return 10; + case 129: return 10; + case 130: return 9; + case 132: return 13; + case 145: return 41; + case 158: return 13; + case 161: return 2; + case 164: return 11; + case 167: return 13; + case 183: return 17; + case 188: return 8; + case 189: return 8; + case 190: return 8; + case 191: return 8; + case 192: return 8; + case 193: return 8; + case 194: return 8; + case 195: return 8; + case 196: return 8; + case 197: return 8; + case 198: return 8; + case 199: return 8; + case 200: return 8; + case 201: return 8; + case 202: return 8; + case 206: return 2; + case 215: return 11; + case 1816: return 12; + default: return EINVAL; + } +} diff --git a/Include/graminit.h b/Include/graminit.h index 9af182a..2fa38c0 100644 --- a/Include/graminit.h +++ b/Include/graminit.h @@ -1,84 +1,84 @@ -#define single_input 256 -#define file_input 257 -#define eval_input 258 -#define decorator 259 -#define decorators 260 -#define funcdef 261 -#define parameters 262 -#define varargslist 263 -#define fpdef 264 -#define fplist 265 -#define stmt 266 -#define simple_stmt 267 -#define small_stmt 268 -#define expr_stmt 269 -#define augassign 270 -#define print_stmt 271 -#define del_stmt 272 -#define pass_stmt 273 -#define flow_stmt 274 -#define break_stmt 275 -#define continue_stmt 276 -#define return_stmt 277 -#define yield_stmt 278 -#define raise_stmt 279 -#define import_stmt 280 -#define import_name 281 -#define import_from 282 -#define import_as_name 283 -#define dotted_as_name 284 -#define import_as_names 285 -#define dotted_as_names 286 -#define dotted_name 287 -#define global_stmt 288 -#define exec_stmt 289 -#define assert_stmt 290 -#define compound_stmt 291 -#define if_stmt 292 -#define while_stmt 293 -#define for_stmt 294 -#define try_stmt 295 -#define with_stmt 296 -#define with_var 297 -#define except_clause 298 -#define suite 299 -#define testlist_safe 300 -#define old_test 301 -#define old_lambdef 302 -#define test 303 -#define or_test 304 -#define and_test 305 -#define not_test 306 -#define comparison 307 -#define comp_op 308 -#define expr 309 -#define xor_expr 310 -#define and_expr 311 -#define shift_expr 312 -#define arith_expr 313 -#define term 314 -#define factor 315 -#define power 316 -#define atom 317 -#define listmaker 318 -#define testlist_gexp 319 -#define lambdef 320 -#define trailer 321 -#define subscriptlist 322 -#define subscript 323 -#define sliceop 324 -#define exprlist 325 -#define testlist 326 -#define dictmaker 327 -#define classdef 328 -#define arglist 329 -#define argument 330 -#define list_iter 331 -#define list_for 332 -#define list_if 333 -#define gen_iter 334 -#define gen_for 335 -#define gen_if 336 -#define testlist1 337 -#define encoding_decl 338 -#define yield_expr 339 +#define single_input 256 +#define file_input 257 +#define eval_input 258 +#define decorator 259 +#define decorators 260 +#define funcdef 261 +#define parameters 262 +#define varargslist 263 +#define fpdef 264 +#define fplist 265 +#define stmt 266 +#define simple_stmt 267 +#define small_stmt 268 +#define expr_stmt 269 +#define augassign 270 +#define print_stmt 271 +#define del_stmt 272 +#define pass_stmt 273 +#define flow_stmt 274 +#define break_stmt 275 +#define continue_stmt 276 +#define return_stmt 277 +#define yield_stmt 278 +#define raise_stmt 279 +#define import_stmt 280 +#define import_name 281 +#define import_from 282 +#define import_as_name 283 +#define dotted_as_name 284 +#define import_as_names 285 +#define dotted_as_names 286 +#define dotted_name 287 +#define global_stmt 288 +#define exec_stmt 289 +#define assert_stmt 290 +#define compound_stmt 291 +#define if_stmt 292 +#define while_stmt 293 +#define for_stmt 294 +#define try_stmt 295 +#define with_stmt 296 +#define with_var 297 +#define except_clause 298 +#define suite 299 +#define testlist_safe 300 +#define old_test 301 +#define old_lambdef 302 +#define test 303 +#define or_test 304 +#define and_test 305 +#define not_test 306 +#define comparison 307 +#define comp_op 308 +#define expr 309 +#define xor_expr 310 +#define and_expr 311 +#define shift_expr 312 +#define arith_expr 313 +#define term 314 +#define factor 315 +#define power 316 +#define atom 317 +#define listmaker 318 +#define testlist_gexp 319 +#define lambdef 320 +#define trailer 321 +#define subscriptlist 322 +#define subscript 323 +#define sliceop 324 +#define exprlist 325 +#define testlist 326 +#define dictmaker 327 +#define classdef 328 +#define arglist 329 +#define argument 330 +#define list_iter 331 +#define list_for 332 +#define list_if 333 +#define gen_iter 334 +#define gen_for 335 +#define gen_if 336 +#define testlist1 337 +#define encoding_decl 338 +#define yield_expr 339 diff --git a/Include/pyerrors.h b/Include/pyerrors.h index 9532e32..816bc9d 100644 --- a/Include/pyerrors.h +++ b/Include/pyerrors.h @@ -58,7 +58,7 @@ typedef struct { PyObject *filename; } PyEnvironmentErrorObject; -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) || defined(__WINE__) || defined(__MINGW32__) typedef struct { PyObject_HEAD PyObject *dict; @@ -155,7 +155,7 @@ PyAPI_DATA(PyObject *) PyExc_UnicodeDecodeError; PyAPI_DATA(PyObject *) PyExc_UnicodeTranslateError; PyAPI_DATA(PyObject *) PyExc_ValueError; PyAPI_DATA(PyObject *) PyExc_ZeroDivisionError; -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) || defined(__WINE__) || defined(__MINGW32__) PyAPI_DATA(PyObject *) PyExc_WindowsError; #endif #ifdef __VMS @@ -192,7 +192,7 @@ PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename( PyAPI_FUNC(PyObject *) PyErr_Format(PyObject *, const char *, ...) Py_GCC_ATTRIBUTE((format(printf, 2, 3))); -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) || defined(__WINE__) || defined(__MINGW32__) PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilenameObject( int, const char *); PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename( diff --git a/Include/pyport.h b/Include/pyport.h index 9ddcbf3..88448f4 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -627,19 +627,19 @@ extern double hypot(double, double); BeOS 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(__BEOS__) || 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(Py_ENABLE_SHARED) || defined(__CYGWIN__) || defined(__MINGW32__) # if defined(HAVE_DECLSPEC_DLL) # ifdef Py_BUILD_CORE # 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 (FIXME: BeOS too?) */ -# if defined(__CYGWIN__) +# if defined(__CYGWIN__) || defined(__MINGW32__) # define PyMODINIT_FUNC __declspec(dllexport) void # else /* __CYGWIN__ */ # define PyMODINIT_FUNC void @@ -649,7 +649,7 @@ extern double hypot(double, double); /* 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__ */ # define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE @@ -734,6 +734,12 @@ typedef struct fd_set { #define INT_MAX 2147483647 #endif +#ifdef __WINE__ /* weird: you have to typecast 0x7fffffffL to long */ +#undef LONG_MAX +#undef LONG_MIN +#define LONG_MAX ((long)0x7FFFFFFFL) +#define LONG_MIN ((long)(-LONG_MAX-1)) +#else #ifndef LONG_MAX #if SIZEOF_LONG == 4 #define LONG_MAX 0X7FFFFFFFL @@ -748,6 +754,8 @@ typedef struct fd_set { #define LONG_MIN (-LONG_MAX-1) #endif +#endif /* __WINE__ */ + #ifndef LONG_BIT #define LONG_BIT (8 * SIZEOF_LONG) #endif diff --git a/Lib/distutils/ccompiler.py b/Lib/distutils/ccompiler.py index 23d2fbd..6d0c13a 100644 --- a/Lib/distutils/ccompiler.py +++ b/Lib/distutils/ccompiler.py @@ -1083,6 +1083,9 @@ def get_default_compiler(osname=None, platform=None): osname = os.name if platform is None: platform = sys.platform + if osname == 'nt' and sys.version.find('mingw') >= 0: + return 'mingw32' + for pattern, compiler in _default_compilers: if re.match(pattern, platform) is not None or \ re.match(pattern, osname) is not None: diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py index f1aeb11..056a398 100644 --- a/Lib/distutils/command/build_ext.py +++ b/Lib/distutils/command/build_ext.py @@ -166,7 +166,7 @@ class build_ext (Command): # for extensions under windows use different directories # for Release and Debug builds. # also Python's library directory must be appended to library_dirs - if os.name == 'nt': + if os.name == 'nt' and sys.version.find('mingw') >= 0: self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs')) if self.debug: self.build_temp = os.path.join(self.build_temp, "Debug") @@ -185,7 +185,9 @@ class build_ext (Command): # for extensions under Cygwin and AtheOS Python's library directory must be # appended to library_dirs - if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos': + if sys.platform[:6] == 'cygwin' or \ + sys.version.find('mingw') >= 0 or \ + sys.platform[:6] == 'atheos': if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")): # building third party extensions self.library_dirs.append(os.path.join(sys.prefix, "lib", @@ -624,7 +626,7 @@ class build_ext (Command): ext_path[len(ext_path) - 1] = ext_path[len(ext_path) - 1][:8] # extensions in debug_mode are named 'module_d.pyd' under windows so_ext = get_config_var('SO') - if os.name == 'nt' and self.debug: + if os.name == 'nt' and sys.version.find('mingw') >= 0 and self.debug: return apply(os.path.join, ext_path) + '_d' + so_ext return apply(os.path.join, ext_path) + so_ext @@ -651,6 +653,13 @@ class build_ext (Command): # to need it mentioned explicitly, though, so that's what we do. # Append '_d' to the python import library on debug builds. if sys.platform == "win32": + if os.name == 'nt' and sys.version.find('gcc') >= 0: + template = "python%d.%d.dll" + pythonlib = (template % + (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) + # don't extend ext.libraries, it may be shared with other + # extensions, it is a reference to the original list + return ext.libraries + [pythonlib] from distutils.msvccompiler import MSVCCompiler if not isinstance(self.compiler, MSVCCompiler): template = "python%d%d" diff --git a/Lib/distutils/cygwinccompiler.py b/Lib/distutils/cygwinccompiler.py index e836cc4..7e3cbff 100644 --- a/Lib/distutils/cygwinccompiler.py +++ b/Lib/distutils/cygwinccompiler.py @@ -66,6 +66,10 @@ class CygwinCCompiler (UnixCCompiler): shared_lib_format = "%s%s" exe_extension = ".exe" + # FIXME: dylib_... = ".dll.a" is not enought for binutils + # loader on win32 platform !!! + dylib_lib_extension = ".dll.a" + def __init__ (self, verbose=0, dry_run=0, force=0): UnixCCompiler.__init__ (self, verbose, dry_run, force) @@ -103,7 +107,14 @@ class CygwinCCompiler (UnixCCompiler): shared_option = "-shared" else: shared_option = "-mdll -static" - + # Next line of code is problem for cross-compiled enviroment: + # NOTE: GCC cross-compiler is prefixed by the - + # and by default binaries are installed in same directory + # as native compiler. + + # FIXME: + # Hard-code may override unix-compiler settings and isn't + # possible to use Makefile variables to pass correct flags ! # Hard-code GCC because that's what this is all about. # XXX optimization, warnings etc. should be customizable. self.set_executables(compiler='gcc -mcygwin -O -Wall', @@ -145,6 +156,7 @@ class CygwinCCompiler (UnixCCompiler): except DistutilsExecError, msg: raise CompileError, msg else: # for other files use the C-compiler + try: self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + extra_postargs) @@ -257,8 +269,14 @@ class CygwinCCompiler (UnixCCompiler): if output_dir is None: output_dir = '' obj_names = [] for src_name in source_filenames: - # use normcase to make sure '.rc' is really '.rc' and not '.RC' - (base, ext) = os.path.splitext (os.path.normcase(src_name)) + # FIXME: "bogus checks for suffix" - as example the commented + # by #BOGUS# code break valid assembler suffix ".S" ! + #BOGUS## use normcase to make sure '.rc' is really '.rc' and not '.RC' + #BOGUS#(base, ext) = os.path.splitext (os.path.normcase(src_name)) + (base, ext) = os.path.splitext (src_name) + ext_normcase = os.path.normcase(ext) + if ext_normcase in ['.rc','.res']: + ext = ext_normcase if ext not in (self.src_extensions + ['.rc','.res']): raise UnknownFileError, \ "unknown file type '%s' (from '%s')" % \ diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py index 652e6fd..a900dc5 100644 --- a/Lib/distutils/sysconfig.py +++ b/Lib/distutils/sysconfig.py @@ -145,7 +145,7 @@ def customize_compiler(compiler): Mainly needed on Unix, so we can plug in the information that varies across Unices and is stored in Python's Makefile. """ - if compiler.compiler_type == "unix": + if compiler.compiler_type in [ "unix", "mingw32"]: (cc, cxx, opt, cflags, ccshared, ldshared, so_ext) = \ get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS', 'CCSHARED', 'LDSHARED', 'SO') @@ -429,6 +429,32 @@ def _init_nt(): g['SO'] = '.pyd' g['EXE'] = ".exe" + g['LDSHARED'] = "-lpython%s" % get_python_version() + + # load the installed Makefile: + try: + filename = get_makefile_filename() + parse_makefile(filename, g) + except IOError, msg: + my_msg = "invalid Python installation: unable to open %s" % filename + if hasattr(msg, "strerror"): + my_msg = my_msg + " (%s)" % msg.strerror + + raise DistutilsPlatformError(my_msg) + + # load the installed pyconfig.h: + try: + prefix = EXEC_PREFIX + prefix = os.path.join(prefix, "PC") + filename = os.path.join(prefix, "pyconfig.h") + parse_config_h(file(filename), g) + except IOError, msg: + my_msg = "invalid Python installation: unable to open %s" % filename + if hasattr(msg, "strerror"): + my_msg = my_msg + " (%s)" % msg.strerror + + raise DistutilsPlatformError(my_msg) + global _config_vars _config_vars = g diff --git a/Lib/site.py b/Lib/site.py index 113f221..f3178ec 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -186,8 +186,17 @@ def addsitepackages(known_paths): "python" + sys.version[:3], "site-packages"), os.path.join(prefix, "lib", "site-python")] + elif sys.platform == 'win32' and sys.version.find('mingw32') >= 0: + sitedirs = [os.path.join(prefix, + "lib", + "python" + sys.version[:3], + "site-packages"), + os.path.join(prefix, "site-packages"), + os.path.join(prefix, "lib", "site-python")] + else: sitedirs = [prefix, os.path.join(prefix, "lib", "site-packages")] + if sys.platform == 'darwin': # for framework builds *only* we add the standard Apple # locations. Currently only per-user, but /Library and diff --git a/Makefile.pre.in b/Makefile.pre.in index 3cd9c67..db2baf9 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -54,10 +54,14 @@ INSTALL_SHARED= ${INSTALL} -m 555 MAKESETUP= $(srcdir)/Modules/makesetup +WINEINCLUDES= @WINEINCLUDES@ +LIBWINE= @LIBWINE@ +win32build= @win32build@ + # Compiler options OPT= @OPT@ BASECFLAGS= @BASECFLAGS@ -CFLAGS= $(BASECFLAGS) $(OPT) $(EXTRA_CFLAGS) +CFLAGS= $(WINEINCLUDES) $(BASECFLAGS) $(OPT) $(EXTRA_CFLAGS) # Both CPPFLAGS and LDFLAGS need to contain the shell's value for setup.py to # be able to build extension modules using the directories specified in the # environment variables @@ -70,7 +74,7 @@ LINKFORSHARED= @LINKFORSHARED@ # Extra C flags added for building the interpreter object files. CFLAGSFORSHARED=@CFLAGSFORSHARED@ # C flags used for building the interpreter object files -PY_CFLAGS= $(CFLAGS) $(CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE +PY_CFLAGS= $(WINEINCLUDES) $(CFLAGS) $(CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE # Machine-dependent subdirectories @@ -169,7 +173,11 @@ THREADOBJ= @THREADOBJ@ DLINCLDIR= @DLINCLDIR@ DYNLOADFILE= @DYNLOADFILE@ MACHDEP_OBJS= @MACHDEP_OBJS@ +PYTHONWINE_OBJS= @PYTHONWINE_OBJS@ +PYTHONEXTRA_OBJS= @PYTHONEXTRA_OBJS@ +MODULEEXTRA_OBJS= @MODULEEXTRA_OBJS@ UNICODE_OBJS= @UNICODE_OBJS@ +GETPATH_OBJS= @GETPATH_OBJS@ PYTHON= python$(EXE) BUILDPYTHON= python$(BUILDEXE) @@ -180,11 +188,10 @@ BUILDPYTHON= python$(BUILDEXE) ########################################################################## # Modules MODULE_OBJS= \ - Modules/config.o \ - Modules/getpath.o \ Modules/main.o \ Modules/gcmodule.o + # Used of signalmodule.o is not available SIGNAL_OBJS= @SIGNAL_OBJS@ @@ -248,7 +255,6 @@ PYTHON_OBJS= \ Python/codecs.o \ Python/errors.o \ Python/frozen.o \ - Python/frozenmain.o \ Python/future.o \ Python/getargs.o \ Python/getcompiler.o \ @@ -275,6 +281,8 @@ PYTHON_OBJS= \ Python/pystrtod.o \ Python/$(DYNLOADFILE) \ $(MACHDEP_OBJS) \ + $(PYTHONWINE_OBJS) \ + $(PYTHONEXTRA_OBJS) \ $(THREADOBJ) @@ -326,6 +334,8 @@ LIBRARY_OBJS= \ $(OBJECT_OBJS) \ $(PYTHON_OBJS) \ $(MODULE_OBJS) \ + $(MODULEEXTRA_OBJS) \ + $(GETPATH_OBJS) \ $(SIGNAL_OBJS) \ $(MODOBJS) @@ -339,7 +349,7 @@ all: $(BUILDPYTHON) oldsharedmods sharedmods $(BUILDPYTHON): Modules/python.o $(LIBRARY) $(LDLIBRARY) $(LINKCC) $(LDFLAGS) $(LINKFORSHARED) -o $@ \ Modules/python.o \ - $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST) + $(BLDLIBRARY) $(LIBS) $(LIBWINE) $(MODLIBS) $(SYSLIBS) $(LDLAST) platform: $(BUILDPYTHON) $(RUNSHARED) ./$(BUILDPYTHON) -E -c 'import sys ; from distutils.util import get_platform ; print get_platform()+"-"+sys.version[0:3]' >platform @@ -361,16 +371,18 @@ $(LIBRARY): $(LIBRARY_OBJS) $(AR) cr $@ $(PARSER_OBJS) $(AR) cr $@ $(OBJECT_OBJS) $(AR) cr $@ $(PYTHON_OBJS) - $(AR) cr $@ $(MODULE_OBJS) $(SIGNAL_OBJS) + $(AR) cr $@ $(MODULE_OBJS) $(SIGNAL_OBJS) $(GETPATH_OBJS) $(AR) cr $@ $(MODOBJS) $(RANLIB) $@ +# $(AR) cr $@ $(LIBRARY_OBJS) +# libpython$(VERSION).so: $(LIBRARY_OBJS) if test $(INSTSONAME) != $(LDLIBRARY); then \ - $(LDSHARED) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM); \ + $(LDSHARED) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBWINE) $(LIBM); \ $(LN) -f $(INSTSONAME) $@; \ else\ - $(LDSHARED) -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM); \ + $(LDSHARED) -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBWINE) $(LIBM); \ fi libpython$(VERSION).sl: $(LIBRARY_OBJS) @@ -413,10 +425,32 @@ $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK): \ # This rule builds the Cygwin Python DLL and import library if configured # for a shared core library; otherwise, this rule is a noop. $(DLLLIBRARY) libpython$(VERSION).dll.a: $(LIBRARY_OBJS) - if test -n "$(DLLLIBRARY)"; then \ - $(LDSHARED) -Wl,--out-implib=$@ -o $(DLLLIBRARY) $^ \ - $(LIBS) $(MODLIBS) $(SYSLIBS); \ - else true; \ + if test -n "$(LIBWINE)"; then \ + if test -n "$(DLLLIBRARY)"; then \ + $(LDSHARED) -o $(DLLLIBRARY) $^ \ + $(LIBS) $(MODLIBS) $(LIBWINE) $(SYSLIBS); \ + else true; \ + fi \ + else\ + if test "$(win32build)" = "yes"; then \ + $(LDSHARED) -o $(DLLLIBRARY) $^ \ + $(LIBS) $(MODLIBS) $(SYSLIBS); \ + echo EXPORTS > python$(VERSION).def; \ + nm $(DLLLIBRARY) | grep ' B _' | sed 's/.* B _//g' | grep "^__Py" >> python$(VERSION).def; \ + nm $(DLLLIBRARY) | grep ' B _' | sed 's/.* B _//g' | grep "^_Py" >> python$(VERSION).def; \ + nm $(DLLLIBRARY) | grep ' B _' | sed 's/.* B _//g' | grep "^Py" >> python$(VERSION).def; \ + nm $(DLLLIBRARY) | grep ' D _' | sed 's/.* D _//g' | grep "^__Py" >> python$(VERSION).def; \ + nm $(DLLLIBRARY) | grep ' D _' | sed 's/.* D _//g' | grep "^_Py" >> python$(VERSION).def; \ + nm $(DLLLIBRARY) | grep ' D _' | sed 's/.* D _//g' | grep "^Py" >> python$(VERSION).def; \ + nm $(DLLLIBRARY) | grep ' T _' | sed 's/.* T _//g' | grep "^init" >> python$(VERSION).def; \ + nm $(DLLLIBRARY) | grep ' T _' | sed 's/.* T _//g' | grep "^_Py" >> python$(VERSION).def; \ + nm $(DLLLIBRARY) | grep ' T _' | sed 's/.* T _//g' | grep "^Py" >> python$(VERSION).def; \ + dlltool --def python$(VERSION).def --dllname $(DLLLIBRARY) \ + --output-lib libpython$(VERSION).dll.a; \ + else true; \ + $(LDSHARED) -Wl,--out-implib=$@ -o $(DLLLIBRARY) $^ \ + $(LIBS) $(MODLIBS) $(SYSLIBS); \ + fi \ fi @@ -455,11 +489,18 @@ Modules/getbuildinfo.o: $(PARSER_OBJS) \ $(OBJECT_OBJS) \ $(PYTHON_OBJS) \ $(MODULE_OBJS) \ + $(GETPATH_OBJS) \ $(SIGNAL_OBJS) \ $(MODOBJS) \ $(srcdir)/Modules/getbuildinfo.c $(CC) -c $(PY_CFLAGS) -DSVNVERSION=\"`LC_ALL=C $(SVNVERSION)`\" -o $@ $(srcdir)/Modules/getbuildinfo.c +Modules/zlibmodule.o: $(srcdir)/Modules/zlibmodule.c Makefile + -@ mkdir -p Modules/zlib + $(CC) -c $(PY_CFLAGS) \ + -I$(srcdir)/Modules/zlib \ + -o $@ $(srcdir)/Modules/zlibmodule.c + Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile $(CC) -c $(PY_CFLAGS) -DPYTHONPATH='"$(PYTHONPATH)"' \ -DPREFIX='"$(prefix)"' \ @@ -497,12 +538,32 @@ Python/compile.o Python/symtable.o: $(GRAMMAR_H) $(AST_H) Python/getplatform.o: $(srcdir)/Python/getplatform.c $(CC) -c $(PY_CFLAGS) -DPLATFORM='"$(MACHDEP)"' -o $@ $(srcdir)/Python/getplatform.c +PC/import_nt.o: $(srcdir)/PC/import_nt.c + mkdir -p PC + $(CC) -c $(PY_CFLAGS) -I$(DLINCLDIR) -I$(srcdir)/Python -o $@ $(srcdir)/PC/import_nt.c + +PC/dl_nt.o: $(srcdir)/PC/dl_nt.c + mkdir -p PC + $(CC) -c $(PY_CFLAGS) -I$(DLINCLDIR) -o $@ $(srcdir)/PC/dl_nt.c + Python/importdl.o: $(srcdir)/Python/importdl.c $(CC) -c $(PY_CFLAGS) -I$(DLINCLDIR) -o $@ $(srcdir)/Python/importdl.c Objects/unicodectype.o: $(srcdir)/Objects/unicodectype.c \ $(srcdir)/Objects/unicodetype_db.h +Modules/cjkcodecs/_codecs_hk.o: $(srcdir)/Modules/cjkcodecs/_codecs_hk.c + mkdir -p Modules/cjkcodecs + $(CC) -c $(PY_CFLAGS) -I$(DLINCLDIR) -I$(srcdir)/Python -o $@ $(srcdir)/Modules/cjkcodecs/_codecs_hk.c + +Modules/cjkcodecs/_codecs_cn.o: $(srcdir)/Modules/cjkcodecs/_codecs_cn.c + mkdir -p Modules/cjkcodecs + $(CC) -c $(PY_CFLAGS) -I$(DLINCLDIR) -I$(srcdir)/Python -o $@ $(srcdir)/Modules/cjkcodecs/_codecs_cn.c + +Modules/cjkcodecs/multibytecodec.o: $(srcdir)/Modules/cjkcodecs/multibytecodec.c + mkdir -p Modules/cjkcodecs + $(CC) -c $(PY_CFLAGS) -I$(DLINCLDIR) -I$(srcdir)/Python -o $@ $(srcdir)/Modules/cjkcodecs/multibytecodec.c + ############################################################################ # Header files diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index aa283e3..db2614a 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -296,7 +296,7 @@ CDataType_in_dll(PyObject *type, PyObject *args) address = (void *)ctypes_dlsym(handle, name); if (!address) { PyErr_Format(PyExc_ValueError, -#ifdef __CYGWIN__ +#if defined(__CYGWIN__) || defined(__MINGW32__) /* dlerror() isn't very helpful on cygwin */ "symbol '%s' not found (%s) ", name, diff --git a/Modules/_ctypes/_ctypes_test.c b/Modules/_ctypes/_ctypes_test.c index c10da0d..f864f10 100644 --- a/Modules/_ctypes/_ctypes_test.c +++ b/Modules/_ctypes/_ctypes_test.c @@ -17,7 +17,7 @@ #include #endif -#if defined(MS_WIN32) || defined(__CYGWIN__) +#if defined(MS_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) #define EXPORT(x) __declspec(dllexport) x #else #define EXPORT(x) x diff --git a/Modules/main.c b/Modules/main.c index 80c0c04..83b16a7 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -9,7 +9,7 @@ #include #endif -#if defined(MS_WINDOWS) || defined(__CYGWIN__) +#if defined(MS_WINDOWS) || defined(__CYGWIN__) || defined(__MINGW32__) #ifdef HAVE_FCNTL_H #include #endif @@ -368,6 +368,20 @@ Py_Main(int argc, char **argv) return 0; } +#if defined(__MINGW32__) + /* something weird with interactive flag - unless interactive + * flag is set when python is _supposed_ to be running in + * interactive mode, Py_FdIsInteractive(stdin) returns FALSE. + * so, we detect no command, no module, no filename, no further + * arguments, or the last argument is "-" as "interactive" + */ + if (command == NULL && module == NULL && _PyOS_optind == argc || + strcmp(argv[_PyOS_optind], "-") == 0) + { + Py_InteractiveFlag++; + } +#endif + if (!saw_inspect_flag && (p = Py_GETENV("PYTHONINSPECT")) && *p != '\0') inspect = 1; @@ -375,55 +389,8 @@ Py_Main(int argc, char **argv) (p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0') unbuffered = 1; - if (command == NULL && module == NULL && _PyOS_optind < argc && - strcmp(argv[_PyOS_optind], "-") != 0) - { -#ifdef __VMS - filename = decc$translate_vms(argv[_PyOS_optind]); - if (filename == (char *)0 || filename == (char *)-1) - filename = argv[_PyOS_optind]; - -#else - filename = argv[_PyOS_optind]; -#endif - if (filename != NULL) { - if ((fp = fopen(filename, "r")) == NULL) { -#ifdef HAVE_STRERROR - fprintf(stderr, "%s: can't open file '%s': [Errno %d] %s\n", - argv[0], filename, errno, strerror(errno)); -#else - fprintf(stderr, "%s: can't open file '%s': Errno %d\n", - argv[0], filename, errno); -#endif - return 2; - } - else if (skipfirstline) { - int ch; - /* Push back first newline so line numbers - remain the same */ - while ((ch = getc(fp)) != EOF) { - if (ch == '\n') { - (void)ungetc(ch, fp); - break; - } - } - } - { - /* XXX: does this work on Win/Win64? (see posix_fstat) */ - struct stat sb; - if (fstat(fileno(fp), &sb) == 0 && - S_ISDIR(sb.st_mode)) { - fprintf(stderr, "%s: '%s' is a directory, cannot continue\n", argv[0], filename); - return 1; - } - } - } - } - - stdin_is_interactive = Py_FdIsInteractive(stdin, (char *)0); - if (unbuffered) { -#if defined(MS_WINDOWS) || defined(__CYGWIN__) +#if defined(MS_WINDOWS) || defined(__CYGWIN__) || defined(__MINGW32__) _setmode(fileno(stdin), O_BINARY); _setmode(fileno(stdout), O_BINARY); #endif @@ -438,7 +405,7 @@ Py_Main(int argc, char **argv) #endif /* !HAVE_SETVBUF */ } else if (Py_InteractiveFlag) { -#ifdef MS_WINDOWS +#ifdef MS_WINDOWS /* Doesn't have to have line-buffered -- use unbuffered */ /* Any set[v]buf(stdin, ...) screws up Tkinter :-( */ setvbuf(stdout, (char *)NULL, _IONBF, BUFSIZ); @@ -473,8 +440,56 @@ Py_Main(int argc, char **argv) #else Py_SetProgramName(argv[0]); #endif + Py_Initialize(); + stdin_is_interactive = Py_FdIsInteractive(stdin, (char *)0); + + if (command == NULL && module == NULL && _PyOS_optind < argc && + strcmp(argv[_PyOS_optind], "-") != 0) + { +#ifdef __VMS + filename = decc$translate_vms(argv[_PyOS_optind]); + if (filename == (char *)0 || filename == (char *)-1) + filename = argv[_PyOS_optind]; + +#else + filename = argv[_PyOS_optind]; +#endif + if (filename != NULL) { + if ((fp = fopen(filename, "r")) == NULL) { +#ifdef HAVE_STRERROR + fprintf(stderr, "%s: can't open file '%s': [Errno %d] %s\n", + argv[0], filename, errno, strerror(errno)); +#else + fprintf(stderr, "%s: can't open file '%s': Errno %d\n", + argv[0], filename, errno); +#endif + return 2; + } + else if (skipfirstline) { + int ch; + /* Push back first newline so line numbers + remain the same */ + while ((ch = getc(fp)) != EOF) { + if (ch == '\n') { + (void)ungetc(ch, fp); + break; + } + } + } + { + /* XXX: does this work on Win/Win64? (see posix_fstat) */ + struct stat sb; + if (fstat(fileno(fp), &sb) == 0 && + S_ISDIR(sb.st_mode)) { + fprintf(stderr, "%s: '%s' is a directory, cannot continue\n", argv[0], filename); + return 1; + } + } + } + } + if (Py_VerboseFlag || (command == NULL && filename == NULL && module == NULL && stdin_is_interactive)) { fprintf(stderr, "Python %s on %s\n", diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 7795827..f75c68d 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -27,6 +27,10 @@ #define PY_SSIZE_T_CLEAN +#if defined(__WINE__) || defined(__MINGW32__) +#include +#endif + #include "Python.h" #include "structseq.h" @@ -103,7 +107,9 @@ corresponding Unix manual entries for more information on calls."); #else #if defined(__WATCOMC__) && !defined(__QNX__) /* Watcom compiler */ #define HAVE_GETCWD 1 +#ifndef __WINE__ #define HAVE_OPENDIR 1 +#endif #define HAVE_SYSTEM 1 #if defined(__OS2__) #define HAVE_EXECV 1 @@ -120,7 +126,7 @@ corresponding Unix manual entries for more information on calls."); #define HAVE_SYSTEM 1 #define HAVE_WAIT 1 #else -#ifdef _MSC_VER /* Microsoft compiler */ +#if defined(_MSC_VER) || defined(__MINGW32__) /* Microsoft / MingW32 compiler */ #define HAVE_GETCWD 1 #define HAVE_SPAWNV 1 #define HAVE_EXECV 1 @@ -147,7 +153,9 @@ corresponding Unix manual entries for more information on calls."); #define HAVE_GETPPID 1 #define HAVE_GETUID 1 #define HAVE_KILL 1 +#if !defined( __WINE__) && !defined(__MINGW32__) #define HAVE_OPENDIR 1 +#endif #define HAVE_PIPE 1 #ifndef __rtems__ #define HAVE_POPEN 1 @@ -156,7 +164,7 @@ corresponding Unix manual entries for more information on calls."); #define HAVE_WAIT 1 #define HAVE_TTYNAME 1 #endif /* PYOS_OS2 && PYCC_GCC && __VMS */ -#endif /* _MSC_VER */ +#endif /* _MSC_VER / MINGW32 */ #endif /* __BORLANDC__ */ #endif /* ! __WATCOMC__ || __QNX__ */ #endif /* ! __IBMC__ */ @@ -176,23 +184,31 @@ extern int mkdir(char *); #if ( defined(__WATCOMC__) || defined(_MSC_VER) ) && !defined(__QNX__) extern int mkdir(const char *); #else +#if !defined( __WINE__) && !defined(__MINGW32__) extern int mkdir(const char *, mode_t); #endif #endif +#endif #if defined(__IBMC__) || defined(__IBMCPP__) extern int chdir(char *); extern int rmdir(char *); #else +#if !defined( __WINE__) && !defined(__MINGW32__) extern int chdir(const char *); extern int rmdir(const char *); #endif -#ifdef __BORLANDC__ +#endif +#if defined(__BORLANDC__) || defined(__WINE__) || defined(__MINGW32__) extern int chmod(const char *, int); #else extern int chmod(const char *, mode_t); #endif +#ifdef HAVE_CHOWN extern int chown(const char *, uid_t, gid_t); +#endif +#if !defined( __WINE__) && !defined(__MINGW32__) extern char *getcwd(char *, int); +#endif extern char *strerror(int); extern int link(const char *, const char *); extern int rename(const char *, const char *); @@ -252,7 +268,7 @@ extern int lstat(const char *, struct stat *); #endif #endif -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__WINE__) || defined(__MINGW32__) #ifdef HAVE_DIRECT_H #include #endif @@ -265,10 +281,11 @@ extern int lstat(const char *, struct stat *); #include "osdefs.h" #define _WIN32_WINNT 0x0400 /* Needed for CryptoAPI on some systems */ #include +#include #include /* for ShellExecute() */ #define popen _popen #define pclose _pclose -#endif /* _MSC_VER */ +#endif /* _MSC_VER / WINE / MINGW32 */ #if defined(PYCC_VACPP) && defined(PYOS_OS2) #include @@ -2328,7 +2345,7 @@ posix_mkdir(PyObject *self, PyObject *args) Py_FileSystemDefaultEncoding, &path, &mode)) return NULL; Py_BEGIN_ALLOW_THREADS -#if ( defined(__WATCOMC__) || defined(PYCC_VACPP) ) && !defined(__QNX__) +#if ( defined(__MINGW32__) || defined(__WATCOMC__) || defined(PYCC_VACPP) ) && !defined(__QNX__) res = mkdir(path); #else res = mkdir(path, mode); @@ -3032,7 +3049,7 @@ posix_spawnv(PyObject *self, PyObject *args) } argvlist[argc] = NULL; -#if defined(PYOS_OS2) && defined(PYCC_GCC) +#if defined(__WINE__) || (defined(PYOS_OS2) && defined(PYCC_GCC)) || defined(__MINGW32__) Py_BEGIN_ALLOW_THREADS spawnval = spawnv(mode, path, argvlist); Py_END_ALLOW_THREADS @@ -3177,7 +3194,7 @@ posix_spawnve(PyObject *self, PyObject *args) } envlist[envc] = 0; -#if defined(PYOS_OS2) && defined(PYCC_GCC) +#if defined(__WINE__) || (defined(PYOS_OS2) && defined(PYCC_GCC)) || defined(__MINGW32__) Py_BEGIN_ALLOW_THREADS spawnval = spawnve(mode, path, argvlist, envlist); Py_END_ALLOW_THREADS @@ -3485,7 +3502,7 @@ posix_fork(PyObject *self, PyObject *noargs) #define DEV_PTY_FILE "/dev/ptmx" #endif -#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_DEV_PTMX) +#if !defined(__MINGW32__) && (defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_DEV_PTMX)) #ifdef HAVE_PTY_H #include #else @@ -3498,7 +3515,7 @@ posix_fork(PyObject *self, PyObject *noargs) #endif #endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_DEV_PTMX */ -#if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) +#if !defined(__MINGW32__) && (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) PyDoc_STRVAR(posix_openpty__doc__, "openpty() -> (master_fd, slave_fd)\n\n\ Open a pseudo-terminal, returning open fd's for both master and slave end.\n"); @@ -8640,7 +8657,11 @@ all_ins(PyObject *d) #else if (ins(d, "P_WAIT", (long)_P_WAIT)) return -1; if (ins(d, "P_NOWAIT", (long)_P_NOWAIT)) return -1; +#ifdef _OLD_P_OVERLAY if (ins(d, "P_OVERLAY", (long)_OLD_P_OVERLAY)) return -1; +#else + if (ins(d, "P_OVERLAY", (long)_P_OVERLAY)) return -1; +#endif if (ins(d, "P_NOWAITO", (long)_P_NOWAITO)) return -1; if (ins(d, "P_DETACH", (long)_P_DETACH)) return -1; #endif @@ -8653,7 +8674,7 @@ all_ins(PyObject *d) } -#if (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__)) && !defined(__QNX__) +#if (defined(__MINGW32__) || defined(__WINE__) || defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__)) && !defined(__QNX__) #define INITFUNC initnt #define MODNAME "nt" diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c index 9e01f48..e8c938d 100644 --- a/Modules/pwdmodule.c +++ b/Modules/pwdmodule.c @@ -5,6 +5,7 @@ #include "structseq.h" #include +#ifndef __MINGW32__ #include static PyStructSequence_Field struct_pwd_type_fields[] = { @@ -31,6 +32,8 @@ static PyStructSequence_Desc struct_pwd_type_desc = { 7, }; +#endif + PyDoc_STRVAR(pwd__doc__, "This module provides access to the Unix password database.\n\ It is available on all Unix versions.\n\ @@ -43,6 +46,7 @@ exception is raised if the entry asked for cannot be found."); static int initialized; +#ifndef __MINGW32__ static PyTypeObject StructPwdType; static void @@ -100,6 +104,7 @@ PyDoc_STRVAR(pwd_getpwuid__doc__, Return the password database entry for the given numeric user ID.\n\ See pwd.__doc__ for more on password database entries."); + static PyObject * pwd_getpwuid(PyObject *self, PyObject *args) { @@ -169,13 +174,17 @@ pwd_getpwall(PyObject *self) } #endif +#endif + static PyMethodDef pwd_methods[] = { +#ifndef __MINGW32__ {"getpwuid", pwd_getpwuid, METH_VARARGS, pwd_getpwuid__doc__}, {"getpwnam", pwd_getpwnam, METH_VARARGS, pwd_getpwnam__doc__}, #ifdef HAVE_GETPWENT {"getpwall", (PyCFunction)pwd_getpwall, METH_NOARGS, pwd_getpwall__doc__}, #endif +#endif {NULL, NULL} /* sentinel */ }; @@ -187,6 +196,7 @@ initpwd(void) if (m == NULL) return; +#ifndef __MINGW32__ if (!initialized) PyStructSequence_InitType(&StructPwdType, &struct_pwd_type_desc); @@ -194,5 +204,6 @@ initpwd(void) PyModule_AddObject(m, "struct_passwd", (PyObject *) &StructPwdType); /* And for b/w compatibility (this was defined by mistake): */ PyModule_AddObject(m, "struct_pwent", (PyObject *) &StructPwdType); +#endif initialized = 1; } diff --git a/Modules/python.c b/Modules/python.c index 2739b8b..f241118 100644 --- a/Modules/python.c +++ b/Modules/python.c @@ -20,5 +20,6 @@ main(int argc, char **argv) m = fpgetmask(); fpsetmask(m & ~FP_X_OFL); #endif + return Py_Main(argc, argv); } diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 9d223d5..4934979 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -75,6 +75,12 @@ static struct { PyObject *func; } Handlers[NSIG]; +#ifdef __WINE__ +/* wine's signal.h doesn't define sig_atomic_t + */ +typedef int sig_atomic_t; +#endif + /* Speed up sigcheck() when none tripped */ static volatile sig_atomic_t is_tripped = 0; diff --git a/Objects/exceptions.c b/Objects/exceptions.c index b73a3f0..ea17ec8 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -739,7 +739,7 @@ MiddlingExtendsException(PyExc_EnvironmentError, OSError, /* * WindowsError extends OSError */ -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) || defined(__WINE__) || defined(__MINGW32__) #include "errmap.h" static int @@ -2013,7 +2013,7 @@ _PyExc_Init(void) PRE_INIT(EnvironmentError) PRE_INIT(IOError) PRE_INIT(OSError) -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) || defined(__WINE__) || defined(__MINGW32__) PRE_INIT(WindowsError) #endif #ifdef __VMS @@ -2079,7 +2079,7 @@ _PyExc_Init(void) POST_INIT(EnvironmentError) POST_INIT(IOError) POST_INIT(OSError) -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) || defined(__WINE__) || defined(__MINGW32__) POST_INIT(WindowsError) #endif #ifdef __VMS diff --git a/PC/_winreg.c b/PC/_winreg.c index 782761b..991c1e7 100644 --- a/PC/_winreg.c +++ b/PC/_winreg.c @@ -17,6 +17,18 @@ #include "structmember.h" #include "malloc.h" /* for alloca */ +#if defined(__MINGW32__) +_CRTIMP size_t __cdecl __MINGW_NOTHROW _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); @@ -1504,7 +1516,9 @@ PyMODINIT_FUNC init_winreg(void) ADD_INT(REG_NOTIFY_CHANGE_ATTRIBUTES); ADD_INT(REG_NOTIFY_CHANGE_LAST_SET); ADD_INT(REG_NOTIFY_CHANGE_SECURITY); +#ifdef REG_LEGAL_CHANGE_FILTER ADD_INT(REG_LEGAL_CHANGE_FILTER); +#endif ADD_INT(REG_NONE); ADD_INT(REG_SZ); ADD_INT(REG_EXPAND_SZ); diff --git a/PC/pyconfig.h b/PC/pyconfig.h index f0abd74..e3b608d 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -67,9 +67,15 @@ MS_CORE_DLL. #define DONT_HAVE_SIG_PAUSE #define LONG_BIT 32 #define WORD_BIT 32 + +/* only define PREFIX when building the core - pyexpat module has a + * typedef for "PREFIX" which this conflicts with otherwise */ +#if defined(__MINGW32__) && defined(Py_BUILD_CORE) #define PREFIX "" #define EXEC_PREFIX "" +#endif + #define MS_WIN32 /* only support win32 and greater. */ #define MS_WINDOWS #ifndef PYTHONPATH @@ -97,7 +103,7 @@ MS_CORE_DLL. /* ------------------------------------------------------------------------*/ /* Microsoft C defines _MSC_VER */ -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__WINE__) || defined(__MINGW32__) /* We want COMPILER to expand to a string containing _MSC_VER's *value*. * This is horridly tricky, because the stringization operator only works @@ -151,14 +157,29 @@ MS_CORE_DLL. #define _W64 #endif +#if defined(__MINGW32__) +#define HAVE_MEMMOVE 1 +#define HAVE_SNPRINTF 1 +#endif + /* Define like size_t, omitting the "unsigned" */ +#if defined(__MINGW32__) +#include +#include +#else +#if defined(__WINE__) +#define _SSIZE_T_DEFINED +#endif #ifdef MS_WIN64 typedef __int64 ssize_t; #else typedef _W64 int ssize_t; #endif +#endif #define HAVE_SSIZE_T 1 + +#if !defined(__MINGW32__) #if defined(MS_WIN32) && !defined(MS_WIN64) #ifdef _M_IX86 #define COMPILER _Py_PASTE_VERSION("32 bit (Intel)") @@ -166,7 +187,11 @@ typedef _W64 int ssize_t; #define COMPILER _Py_PASTE_VERSION("32 bit (Unknown)") #endif #endif /* MS_WIN32 && !MS_WIN64 */ +#endif +#if defined(__WINE__) || defined(__MINGW32__) +#define _PID_T_DEFINED +#endif typedef int pid_t; #define hypot _hypot @@ -231,7 +256,11 @@ typedef int pid_t; #warning "Please use an up-to-date version of gcc! (>2.91 recommended)" #endif +#if defined(__MINGW32__) +#define COMPILER "[gcc-mingw32]" +#else #define COMPILER "[gcc]" +#endif /* __MINGW32__ */ #define hypot _hypot #define PY_LONG_LONG long long #define PY_LLONG_MIN LLONG_MIN @@ -345,6 +374,11 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ #define SIZEOF_DOUBLE 8 #define SIZEOF_FLOAT 4 +#if defined(__WINE__) || defined(__MINGW32__) +#define HAVE_UINTPTR_T 1 +#define HAVE_INTPTR_T 1 +#endif + /* VC 7.1 has them and VC 6.0 does not. VC 6.0 has a version number of 1200. Microsoft eMbedded Visual C++ 4.0 has a version number of 1201 and doesn't define these. @@ -691,4 +725,14 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ socket handles greater than FD_SETSIZE */ #define Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE +#ifdef __WINE__ +/* This is used to fool distutils into noticing the difference + * between wine and msvc. otherwise, setup.py (distutils) tries + * to use MSVCCompiler, on linux. + */ +#define HAVE_WINE 1 + +#define HAVE_SPAWNV +#endif + #endif /* !Py_CONFIG_H */ diff --git a/Python/dynload_win.c b/Python/dynload_win.c index 1c3b3ab..03d22c9 100644 --- a/Python/dynload_win.c +++ b/Python/dynload_win.c @@ -23,7 +23,7 @@ const struct filedescr _PyImport_DynLoadFiletab[] = { /* Case insensitive string compare, to avoid any dependencies on particular C RTL implementations */ -static int strcasecmp (char *string1, char *string2) +static int _strcasecmp (char *string1, char *string2) { int first, second; @@ -238,7 +238,7 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, import_python = GetPythonImport(hDLL); if (import_python && - strcasecmp(buffer,import_python)) { + _strcasecmp(buffer,import_python)) { PyOS_snprintf(buffer, sizeof(buffer), "Module use of %.150s conflicts " "with this version of Python.", diff --git a/Python/errors.c b/Python/errors.c index bc77c3c..7545f7d 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -9,7 +9,7 @@ extern char *strerror(int); #endif #endif -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) || defined(__WINE__) || defined(__MINGW32__) #include "windows.h" #include "winbase.h" #endif @@ -260,6 +260,14 @@ PyErr_NoMemory(void) return NULL; } +#ifdef __WINE__ +/* whoops - wine doesn't provide direct access in stdlib.h to + * these msvcr71 variables + */ +extern int _sys_nerr; +extern char** _sys_errlist; +#endif + PyObject * PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject) { @@ -269,7 +277,7 @@ PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject) #ifdef PLAN9 char errbuf[ERRMAX]; #endif -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) || defined(__WINE__) || defined(__MINGW32__) char *s_buf = NULL; char s_small_buf[28]; /* Room for "Windows Error 0xFFFFFFFF" */ #endif @@ -284,7 +292,7 @@ PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject) if (i == 0) s = "Error"; /* Sometimes errno didn't get set */ else -#ifndef MS_WINDOWS +#if !defined(MS_WINDOWS) && !defined(__WINE__) || defined(__MINGW32__) s = strerror(i); #else { @@ -333,7 +341,7 @@ PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject) PyErr_SetObject(exc, v); Py_DECREF(v); } -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) || defined(__WINE__) || defined(__MINGW32__) LocalFree(s_buf); #endif return NULL; @@ -368,7 +376,7 @@ PyErr_SetFromErrno(PyObject *exc) return PyErr_SetFromErrnoWithFilenameObject(exc, NULL); } -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) || defined(__WINE__) || defined(__MINGW32__) /* Windows specific error code handling */ PyObject *PyErr_SetExcFromWindowsErrWithFilenameObject( PyObject *exc, diff --git a/Python/getargs.c b/Python/getargs.c index d94edce..34f8e28 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -5,6 +5,14 @@ #include +#ifdef __WINE__ +/* wine's #define of INT_MIN slightly faulty... + */ +#undef INT_MIN +#define INT_MIN (-INT_MAX - 1) +#endif + + #ifdef __cplusplus extern "C" { diff --git a/Python/getopt.c b/Python/getopt.c index 659efcf..73b4ec5 100644 --- a/Python/getopt.c +++ b/Python/getopt.c @@ -48,7 +48,7 @@ int _PyOS_GetOpt(int argc, char **argv, char *optstring) if (_PyOS_optind >= argc) return -1; -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) || defined(__MINGW32__) else if (strcmp(argv[_PyOS_optind], "/?") == 0) { ++_PyOS_optind; return 'h'; diff --git a/Wine/pythonlib.spec b/Wine/pythonlib.spec new file mode 100644 index 0000000..f0f9b4c --- /dev/null +++ b/Wine/pythonlib.spec @@ -0,0 +1,2 @@ +@ stdcall Py_Main(long ptr) + diff --git a/configure.in b/configure.in index b014e8f..36ec6ea 100644 --- a/configure.in +++ b/configure.in @@ -36,6 +36,151 @@ VERSION=PYTHON_VERSION AC_SUBST(SOVERSION) SOVERSION=1.0 +AC_SUBST(PYTHONEXTRA_OBJS) +PYTHONEXTRA_OBJS="Python/frozenmain.o" + +# Defined if compiling with Wine + +AC_SUBST(PYTHONWINE_OBJS) +PYTHONWINE_OBJS="" +AC_SUBST(GETPATH_OBJS) +GETPATH_OBJS="Modules/getpath.o" +AC_SUBST(MODULEEXTRA_OBJS) +MODULEEXTRA_OBJS="Modules/config.o" + +AC_SUBST(win32build) + +AC_MSG_CHECKING(for --enable-win32build) +AC_ARG_ENABLE(win32build, + AC_HELP_STRING(--enable-win32build, disable/enable building on win32 platform), +[ case "$enableval" in + yes) + AC_DEFINE(MS_WINDOWS, 1, [Define Win32 Build compiling]) + AC_DEFINE(MS_WIN32, 1, [Define Win32 Build compiling]) + AC_DEFINE(HAVE_FCNTL_H, 1, [Define fcntl.h]) + AC_SUBST(WINEINCLUDES) + AC_SUBST(LIBWINE) + AC_SUBST(THREADOBJ) + THREADOBJ="Python/thread.o" + PYTHONWINE_OBJS="PC/dl_nt.o PC/import_nt.o" + PYTHONEXTRA_OBJS="" + GETPATH_OBJS="PC/getpathp.o" + MODULEEXTRA_OBJS="PC/config.o \ + PC/msvcrtmodule.o \ + PC/_subprocess.o \ + Modules/_bisectmodule.o Modules/_csv.o Modules/_functoolsmodule.o \ + Modules/_heapqmodule.o Modules/_hotshot.o \ + Modules/_localemodule.o Modules/_lsprof.o \ + Modules/_randommodule.o Modules/_struct.o \ + Modules/_weakref.o PC/_winreg.o \ + Modules/stropmodule.o \ + Modules/_sre.o \ + Modules/cjkcodecs/multibytecodec.o \ + Modules/cjkcodecs/_codecs_cn.o \ + Modules/cjkcodecs/_codecs_hk.o \ + Modules/cjkcodecs/_codecs_iso2022.o \ + Modules/cjkcodecs/_codecs_jp.o \ + Modules/cjkcodecs/_codecs_kr.o \ + Modules/cjkcodecs/_codecs_tw.o \ + Modules/arraymodule.o Modules/audioop.o \ + Modules/binascii.o Modules/cPickle.o \ + Modules/cStringIO.o Modules/cmathmodule.o \ + Modules/collectionsmodule.o Modules/datetimemodule.o \ + Modules/mmapmodule.o Modules/operator.o \ + Modules/imageop.o \ + Modules/rotatingtree.o \ + Modules/itertoolsmodule.o Modules/mathmodule.o \ + Modules/md5.o Modules/md5module.o \ + Modules/parsermodule.o Modules/rgbimgmodule.o \ + Modules/sha256module.o Modules/sha512module.o \ + Modules/shamodule.o Modules/timemodule.o \ + Modules/zlib/adler32.o Modules/zlib/compress.o \ + Modules/zlib/crc32.o Modules/zlib/deflate.o\ + Modules/zlib/gzio.o Modules/zlib/infback.o\ + Modules/zlib/inffast.o Modules/zlib/inflate.o\ + Modules/zlib/inftrees.o Modules/zlib/minigzip.o\ + Modules/zlib/trees.o Modules/zlib/uncompr.o\ + Modules/zlib/zutil.o\ + Modules/zlibmodule.o Modules/_codecsmodule.o" + WINEINCLUDES="-I\$(srcdir)/PC " + CFLAGS="$CFLAGS" + win32build=yes + ;; + *) + win32build=no + AC_CHECK_HEADERS(fcntl.h) + ;; + esac ] +) +AC_MSG_RESULT($win32build) + +AC_MSG_CHECKING(for --enable-wine) +AC_ARG_ENABLE(wine, + AC_HELP_STRING(--enable-wine, disable/enable building with Wine), +[ case "$enableval" in + yes) + AC_DEFINE(__WINE__, 1, [Define on Linux to compile with Wine]) + AC_DEFINE(MS_WINDOWS, 1, [Define with Wine compiling]) + AC_DEFINE(MS_WIN32, 1, [Define with Wine compiling]) + AC_DEFINE(HAVE_FCNTL_H, 1, [Define fcntl.h]) + AC_SUBST(WINEINCLUDES) + AC_SUBST(LIBWINE) + PYTHONWINE_OBJS="PC/dl_nt.o PC/import_nt.o" + GETPATH_OBJS="PC/getpathp.o PC/config.o \ + PC/msvcrtmodule.o \ + PC/_subprocess.o \ + Modules/_bisectmodule.o Modules/_csv.o Modules/_functoolsmodule.o \ + Modules/_heapqmodule.o Modules/_hotshot.o \ + Modules/_localemodule.o Modules/_lsprof.o \ + Modules/_randommodule.o Modules/_struct.o \ + Modules/_weakref.o PC/_winreg.o \ + Modules/stropmodule.o \ + Modules/_sre.o \ + Modules/cjkcodecs/multibytecodec.o \ + Modules/cjkcodecs/_codecs_cn.o \ + Modules/cjkcodecs/_codecs_hk.o \ + Modules/cjkcodecs/_codecs_iso2022.o \ + Modules/cjkcodecs/_codecs_jp.o \ + Modules/cjkcodecs/_codecs_kr.o \ + Modules/cjkcodecs/_codecs_tw.o \ + Modules/arraymodule.o Modules/audioop.o \ + Modules/binascii.o Modules/cPickle.o \ + Modules/cStringIO.o Modules/cmathmodule.o \ + Modules/collectionsmodule.o Modules/datetimemodule.o \ + Modules/mmapmodule.o Modules/operator.o \ + Modules/imageop.o \ + Modules/rotatingtree.o \ + Modules/itertoolsmodule.o Modules/mathmodule.o \ + Modules/md5.o Modules/md5module.o \ + Modules/parsermodule.o Modules/rgbimgmodule.o \ + Modules/sha256module.o Modules/sha512module.o \ + Modules/shamodule.o Modules/timemodule.o \ + Modules/zlib/adler32.c Modules/zlib/compress.c \ + Modules/zlib/crc32.c Modules/zlib/deflate.c\ + Modules/zlib/gzio.c Modules/zlib/infback.c\ + Modules/zlib/inffast.c Modules/zlib/inflate.c\ + Modules/zlib/inftrees.c Modules/zlib/minigzip.c\ + Modules/zlib/trees.c Modules/zlib/uncompr.c\ + Modules/zlib/zutil.c\ + Modules/zlibmodule.o Modules/_codecsmodule.o" + WINEINCLUDES="-I\$(srcdir)/PC -I/usr/include/wine/msvcrt -I/usr/include/wine/windows " + CFLAGS="$CFLAGS" + LIBWINE="-lwine -lz -lmsvcrt -lmsvcr71 -lshell32 -L/usr/lib/wine \$(srcdir)/Wine/pythonlib.spec" + wine=yes + win32build=yes + ;; + *) + wine=no + ;; + esac ] +) +AC_MSG_RESULT($wine) + +if test "$win32build" = "no" +then + AC_CHECK_HEADERS(fcntl.h) +fi + # The later defininition of _XOPEN_SOURCE disables certain features # on Linux, so we need _GNU_SOURCE to re-enable them (makedev, tm_zone). AC_DEFINE(_GNU_SOURCE, 1, [Define on Linux to activate all library features]) @@ -518,7 +663,12 @@ AC_SUBST(LIBRARY) AC_MSG_CHECKING(LIBRARY) if test -z "$LIBRARY" then - LIBRARY='libpython$(VERSION).a' + if test "$win32build" = "no" + then + LIBRARY='libpython$(VERSION).a' + else + LIBRARY='' + fi fi AC_MSG_RESULT($LIBRARY) @@ -580,7 +730,7 @@ AC_ARG_ENABLE(shared, if test -z "$enable_shared" then case $ac_sys_system in - CYGWIN* | atheos*) + CYGWIN*|MINGW32_NT* | atheos*) enable_shared="yes";; *) enable_shared="no";; @@ -627,57 +777,57 @@ fi # Other platforms follow if test $enable_shared = "yes"; then AC_DEFINE(Py_ENABLE_SHARED, 1, [Defined if Python is built as a shared library.]) - case $ac_sys_system in - BeOS*) + case $ac_sys_system in + BeOS*) + LDLIBRARY='libpython$(VERSION).so' + ;; + CYGWIN*|MINGW32_NT*) + LDLIBRARY='libpython$(VERSION).dll.a' + DLLLIBRARY='libpython$(VERSION).dll' + ;; + SunOS*) LDLIBRARY='libpython$(VERSION).so' + BLDLIBRARY='-Wl,-R,$(LIBDIR) -L. -lpython$(VERSION)' + RUNSHARED=LD_LIBRARY_PATH=`pwd`:${LD_LIBRARY_PATH} + INSTSONAME="$LDLIBRARY".$SOVERSION + ;; + Linux*|GNU*|NetBSD*|FreeBSD*|DragonFly*) + LDLIBRARY='libpython$(VERSION).so' + BLDLIBRARY='-L. -lpython$(VERSION)' + RUNSHARED=LD_LIBRARY_PATH=`pwd`:${LD_LIBRARY_PATH} + case $ac_sys_system in + FreeBSD*) + SOVERSION=`echo $SOVERSION|cut -d "." -f 1` + ;; + esac + INSTSONAME="$LDLIBRARY".$SOVERSION + ;; + hp*|HP*) + case `uname -m` in + ia64) + LDLIBRARY='libpython$(VERSION).so' + ;; + *) + LDLIBRARY='libpython$(VERSION).sl' + ;; + esac + BLDLIBRARY='-Wl,+b,$(LIBDIR) -L. -lpython$(VERSION)' + RUNSHARED=SHLIB_PATH=`pwd`:${SHLIB_PATH} ;; - CYGWIN*) - LDLIBRARY='libpython$(VERSION).dll.a' - DLLLIBRARY='libpython$(VERSION).dll' + OSF*) + LDLIBRARY='libpython$(VERSION).so' + BLDLIBRARY='-rpath $(LIBDIR) -L. -lpython$(VERSION)' + RUNSHARED=LD_LIBRARY_PATH=`pwd`:${LD_LIBRARY_PATH} ;; - SunOS*) - LDLIBRARY='libpython$(VERSION).so' - BLDLIBRARY='-Wl,-R,$(LIBDIR) -L. -lpython$(VERSION)' - RUNSHARED=LD_LIBRARY_PATH=`pwd`:${LD_LIBRARY_PATH} - INSTSONAME="$LDLIBRARY".$SOVERSION + atheos*) + LDLIBRARY='libpython$(VERSION).so' + BLDLIBRARY='-L. -lpython$(VERSION)' + RUNSHARED=DLL_PATH=`pwd`:${DLL_PATH:-/atheos/sys/libs:/atheos/autolnk/lib} ;; - Linux*|GNU*|NetBSD*|FreeBSD*|DragonFly*) - LDLIBRARY='libpython$(VERSION).so' - BLDLIBRARY='-L. -lpython$(VERSION)' - RUNSHARED=LD_LIBRARY_PATH=`pwd`:${LD_LIBRARY_PATH} - case $ac_sys_system in - FreeBSD*) - SOVERSION=`echo $SOVERSION|cut -d "." -f 1` - ;; - esac - INSTSONAME="$LDLIBRARY".$SOVERSION - ;; - hp*|HP*) - case `uname -m` in - ia64) - LDLIBRARY='libpython$(VERSION).so' - ;; - *) - LDLIBRARY='libpython$(VERSION).sl' - ;; - esac - BLDLIBRARY='-Wl,+b,$(LIBDIR) -L. -lpython$(VERSION)' - RUNSHARED=SHLIB_PATH=`pwd`:${SHLIB_PATH} - ;; - OSF*) - LDLIBRARY='libpython$(VERSION).so' - BLDLIBRARY='-rpath $(LIBDIR) -L. -lpython$(VERSION)' - RUNSHARED=LD_LIBRARY_PATH=`pwd`:${LD_LIBRARY_PATH} - ;; - atheos*) - LDLIBRARY='libpython$(VERSION).so' - BLDLIBRARY='-L. -lpython$(VERSION)' - RUNSHARED=DLL_PATH=`pwd`:${DLL_PATH:-/atheos/sys/libs:/atheos/autolnk/lib} - ;; - esac + esac else # shared is disabled case $ac_sys_system in - CYGWIN*) + CYGWIN*|MINGW32_NT*) BLDLIBRARY='$(LIBRARY)' LDLIBRARY='libpython$(VERSION).dll.a' ;; @@ -714,7 +864,7 @@ AC_SUBST(LN) if test -z "$LN" ; then case $ac_sys_system in BeOS*) LN="ln -s";; - CYGWIN*) LN="ln -s";; + CYGWIN*|MINGW32_NT*) LN="ln -s";; atheos*) LN="ln -s";; *) LN=ln;; esac @@ -904,6 +1054,8 @@ else fi fi +if test "$win32build" = "no" +then # On some compilers, pthreads are available without further options # (e.g. MacOS X). On some of these systems, the compiler will not # complain if unaccepted options are passed (e.g. gcc on Mac OS X). @@ -1398,6 +1550,8 @@ case $ac_sys_system/$ac_sys_release in ;; esac +fi # win32build=no! + # Set info about shared libraries. AC_SUBST(SO) AC_SUBST(LDSHARED) @@ -1409,16 +1563,26 @@ AC_SUBST(LINKFORSHARED) AC_MSG_CHECKING(SO) if test -z "$SO" then - case $ac_sys_system in - hp*|HP*) - case `uname -m` in - ia64) SO=.so;; - *) SO=.sl;; - esac - ;; - CYGWIN*) SO=.dll;; - *) SO=.so;; - esac + case $ac_sys_system in + hp*|HP*) + case `uname -m` in + ia64) SO=.so;; + *) SO=.sl;; + esac + ;; + CYGWIN*) SO=.dll;; + MINGW32_NT*) + #NOTE: see _PyImport_DynLoadFiletab in dynload_win.c + if test "x$Py_DEBUG" = xtrue; then + SO=_d.pyd + else + SO=.pyd + fi + ;; + *) + SO=.so + ;; + esac else # this might also be a termcap variable, see #610332 echo @@ -1547,7 +1711,7 @@ then fi;; SCO_SV*) LDSHARED='$(CC) -Wl,-G,-Bexport';; Monterey*) LDSHARED="cc -G -dy -Bdynamic -Bexport -L/usr/lib/ia64l64";; - CYGWIN*) LDSHARED="gcc -shared -Wl,--enable-auto-image-base";; + CYGWIN*|MINGW32_NT*) LDSHARED="gcc -shared -Wl,--enable-auto-image-base";; atheos*) LDSHARED="gcc -shared";; *) LDSHARED="ld";; esac @@ -1635,7 +1799,7 @@ then LINKFORSHARED="-Xlinker --export-dynamic" fi;; esac;; - CYGWIN*) + CYGWIN*|MINGW32_NT*) if test $enable_shared = "no" then LINKFORSHARED='-Wl,--out-implib=$(LDLIBRARY)' @@ -1649,7 +1813,7 @@ AC_MSG_CHECKING(CFLAGSFORSHARED) if test ! "$LIBRARY" = "$LDLIBRARY" then case $ac_sys_system in - CYGWIN*) + CYGWIN*|MINGW32_NT*) # Cygwin needs CCSHARED when building extension DLLs # but not when building the interpreter DLL. CFLAGSFORSHARED='';; @@ -1676,6 +1840,9 @@ esac AC_MSG_RESULT($SHLIBS) +if test "$win32build" = "no" +then + # checks for libraries AC_CHECK_LIB(dl, dlopen) # Dynamic linking for SunOS/Solaris and SYSV AC_CHECK_LIB(dld, shl_load) # Dynamic linking for HP-UX @@ -1739,6 +1906,8 @@ if test -z "$with_system_ffi" && test "$ac_cv_header_ffi_h" = yes; then fi AC_MSG_RESULT($with_system_ffi) +fi # win31build=no + # Determine if signalmodule should be used. AC_SUBST(USE_SIGNAL_MODULE) AC_SUBST(SIGNAL_OBJS) @@ -1763,6 +1932,8 @@ fi AC_SUBST(USE_THREAD_MODULE) USE_THREAD_MODULE="" +if test "$win32build" = "no" +then AC_MSG_CHECKING(for --with-dec-threads) AC_SUBST(LDLAST) AC_ARG_WITH(dec-threads, @@ -1992,14 +2163,13 @@ if test "$posix_threads" = "yes"; then fi AC_CHECK_FUNCS(pthread_sigmask, [case $ac_sys_system in - CYGWIN*) + CYGWIN*|MINGW32_NT*) AC_DEFINE(HAVE_BROKEN_PTHREAD_SIGMASK, 1, [Define if pthread_sigmask() does not work on your system.]) ;; esac]) fi - # Check for enable-ipv6 AH_TEMPLATE(ENABLE_IPV6, [Define if --enable-ipv6 is specified]) AC_MSG_CHECKING([if --enable-ipv6 is specified]) @@ -2225,13 +2395,18 @@ else AC_MSG_RESULT(no) fi], [AC_MSG_RESULT(no)]) +fi # win32build=no! + # -I${DLINCLDIR} is added to the compile rule for importdl.o AC_SUBST(DLINCLDIR) DLINCLDIR=. +if test "$win32build" = "no" +then # the dlopen() function means we might want to use dynload_shlib.o. some # platforms, such as AIX, have dlopen(), but don't want to use it. AC_CHECK_FUNCS(dlopen) +fi # win32build=no! # DYNLOADFILE specifies which dynload_*.o file we will use for dynamic # loading of modules. @@ -2239,27 +2414,34 @@ AC_SUBST(DYNLOADFILE) AC_MSG_CHECKING(DYNLOADFILE) if test -z "$DYNLOADFILE" then - case $ac_sys_system/$ac_sys_release in - AIX*) # Use dynload_shlib.c and dlopen() if we have it; otherwise dynload_aix.c - if test "$ac_cv_func_dlopen" = yes - then DYNLOADFILE="dynload_shlib.o" - else DYNLOADFILE="dynload_aix.o" - fi - ;; - BeOS*) DYNLOADFILE="dynload_beos.o";; - hp*|HP*) DYNLOADFILE="dynload_hpux.o";; - # Use dynload_next.c only on 10.2 and below, which don't have native dlopen() - Darwin/@<:@0156@:>@\..*) DYNLOADFILE="dynload_next.o";; - atheos*) DYNLOADFILE="dynload_atheos.o";; - *) - # use dynload_shlib.c and dlopen() if we have it; otherwise stub - # out any dynamic loading - if test "$ac_cv_func_dlopen" = yes - then DYNLOADFILE="dynload_shlib.o" - else DYNLOADFILE="dynload_stub.o" - fi - ;; - esac + case $win32build in + yes*) + DYNLOADFILE="dynload_win.o" + ;; + no*) + case $ac_sys_system/$ac_sys_release in + AIX*) # Use dynload_shlib.c and dlopen() if we have it; otherwise dynload_aix.c + if test "$ac_cv_func_dlopen" = yes + then DYNLOADFILE="dynload_shlib.o" + else DYNLOADFILE="dynload_aix.o" + fi + ;; + BeOS*) DYNLOADFILE="dynload_beos.o";; + hp*|HP*) DYNLOADFILE="dynload_hpux.o";; + # Use dynload_next.c only on 10.2 and below, which don't have native dlopen() + Darwin/@<:@0156@:>@\..*) DYNLOADFILE="dynload_next.o";; + atheos*) DYNLOADFILE="dynload_atheos.o";; + *) + # use dynload_shlib.c and dlopen() if we have it; otherwise stub + # out any dynamic loading + if test "$ac_cv_func_dlopen" = yes + then DYNLOADFILE="dynload_shlib.o" + else DYNLOADFILE="dynload_stub.o" + fi + ;; + esac + ;; + esac fi AC_MSG_RESULT($DYNLOADFILE) if test "$DYNLOADFILE" != "dynload_stub.o" @@ -2280,6 +2462,8 @@ else fi AC_MSG_RESULT(MACHDEP_OBJS) +if test "$win32build" = "no" +then # checks for library functions AC_CHECK_FUNCS(alarm bind_textdomain_codeset chown clock confstr ctermid \ execv fork fpathconf ftime ftruncate \ @@ -2998,6 +3182,8 @@ ucs4) unicode_size="4" ;; esac +fi # win32build=no! + AH_TEMPLATE(PY_UNICODE_TYPE, [Define as the integral type used for Unicode representation.]) @@ -3035,6 +3221,9 @@ else AC_MSG_RESULT($PY_UNICODE_TYPE) fi +if test "$win32build" = "no" +then + # check for endianness AC_C_BIGENDIAN AH_VERBATIM([WORDS_BIGENDIAN], @@ -3460,6 +3649,8 @@ AC_CHECK_TYPE(socklen_t,, #endif ]) +fi # end win32build=no! + AC_SUBST(THREADHEADERS) for h in `(cd $srcdir;echo Python/thread_*.h)` diff --git a/pyconfig.h.in b/pyconfig.h.in index fc8d146..b6bd542 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -746,6 +746,12 @@ . */ #undef MAJOR_IN_SYSMACROS +/* Define with Wine compiling */ +#undef MS_WIN32 + +/* Define with Wine compiling */ +#undef MS_WINDOWS + /* Define if mvwdelch in curses.h is an expression. */ #undef MVWDELCH_IS_EXPRESSION @@ -963,6 +969,9 @@ /* Defined on Solaris to see additional function prototypes. */ #undef __EXTENSIONS__ +/* Define on Linux to compile with Wine */ +#undef __WINE__ + /* Define to 'long' if doesn't define. */ #undef clock_t diff --git a/setup.py b/setup.py index 95ba9b6..804c4a1 100644 --- a/setup.py +++ b/setup.py @@ -93,8 +93,12 @@ class PyBuildExt(build_ext): def build_extensions(self): - # Detect which modules should be compiled - self.detect_modules() + platform = self.get_platform() + if platform == 'win32': + self.detect_modules_nt() + else: + self.detect_modules() + # Remove modules that are present on the disabled list self.extensions = [ext for ext in self.extensions @@ -173,6 +177,7 @@ class PyBuildExt(build_ext): # compilers if compiler is not None: (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS') + args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags self.compiler.set_executables(**args) @@ -242,6 +247,871 @@ class PyBuildExt(build_ext): return platform return sys.platform + def detect_modules_nt(self): + # Ensure that /usr/local is always used + #add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') + #add_dir_to_list(self.compiler.include_dirs, '/usr/local/include') + + # Add paths specified in the environment variables LDFLAGS and + # CPPFLAGS for header and library files. + # We must get the values from the Makefile and not the environment + # 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). + for env_var, arg_name, dir_list in ( + ('LDFLAGS', '-L', self.compiler.library_dirs), + ('CPPFLAGS', '-I', self.compiler.include_dirs)): + env_val = sysconfig.get_config_var(env_var) + if env_val: + # To prevent optparse from raising an exception about any + # options in env_val that is doesn't know about we strip out + # all double dashes and any dashes followed by a character + # that is not for the option we are dealing with. + # + # Please note that order of the regex is important! We must + # strip out double-dashes first so that we don't end up with + # substituting "--Long" to "-Long" and thus lead to "ong" being + # used for a library directory. + env_val = re.sub(r'(^|\s+)-(-|(?!%s))' % arg_name[1], + ' ', env_val) + parser = optparse.OptionParser() + # Make sure that allowing args interspersed with options is + # allowed + parser.allow_interspersed_args = True + parser.error = lambda msg: None + parser.add_option(arg_name, dest="dirs", action="append") + options = parser.parse_args(env_val.split())[0] + if options.dirs: + for directory in reversed(options.dirs): + add_dir_to_list(dir_list, directory) + + if os.path.normpath(sys.prefix) != '/usr': + add_dir_to_list(self.compiler.library_dirs, + sysconfig.get_config_var("LIBDIR")) + add_dir_to_list(self.compiler.include_dirs, + sysconfig.get_config_var("INCLUDEDIR")) + + try: + have_unicode = unicode + except NameError: + have_unicode = 0 + + # lib_dirs and inc_dirs are used to search for files; + # if a file is found in one of those directories, it can + # be assumed that no additional -I,-L directives are needed. + lib_dirs = self.compiler.library_dirs + inc_dirs = self.compiler.include_dirs + exts = [] + + config_h = sysconfig.get_config_h_filename() + config_h_vars = sysconfig.parse_config_h(open(config_h)) + + platform = self.get_platform() + (srcdir,) = sysconfig.get_config_vars('srcdir') + + math_libs = ['m'] + + # The following modules are all pretty straightforward, and compile + # on pretty much any POSIXish platform. + # + + # Some modules that are normally always on: + exts.append( Extension('_weakref', ['_weakref.c']) ) + + # array objects + exts.append( Extension('array', ['arraymodule.c']) ) + # complex math library functions + exts.append( Extension('cmath', ['cmathmodule.c'], + libraries=math_libs) ) + + # math library functions, e.g. sin() + exts.append( Extension('math', ['mathmodule.c'], + libraries=math_libs) ) + # fast string operations implemented in C + exts.append( Extension('strop', ['stropmodule.c']) ) + # time operations and variables + exts.append( Extension('time', ['timemodule.c'], + libraries=math_libs) ) + exts.append( Extension('datetime', ['datetimemodule.c', 'timemodule.c'], + libraries=math_libs) ) + # random number generator implemented in C + exts.append( Extension("_random", ["_randommodule.c"]) ) + # fast iterator tools implemented in C + exts.append( Extension("itertools", ["itertoolsmodule.c"]) ) + # high-performance collections + exts.append( Extension("collections", ["collectionsmodule.c"]) ) + # bisect + exts.append( Extension("_bisect", ["_bisectmodule.c"]) ) + # heapq + exts.append( Extension("_heapq", ["_heapqmodule.c"]) ) + # operator.add() and similar goodies + exts.append( Extension('operator', ['operator.c']) ) + # _functools + exts.append( Extension("_functools", ["_functoolsmodule.c"]) ) + # Python C API test module + exts.append( Extension('_testcapi', ['_testcapimodule.c']) ) + # profilers (_lsprof is for cProfile.py) + exts.append( Extension('_hotshot', ['_hotshot.c']) ) + exts.append( Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']) ) + # static Unicode character database + if have_unicode: + exts.append( Extension('unicodedata', ['unicodedata.c']) ) + # access to ISO C locale support + data = open('pyconfig.h').read() + m = re.search(r"#s*define\s+WITH_LIBINTL\s+1\s*", data) + if m is not None: + locale_libs = ['intl'] + else: + locale_libs = [] + locale_extra_link_args = [] + + + exts.append( Extension('_locale', ['_localemodule.c'], + libraries=locale_libs, + extra_link_args=locale_extra_link_args) ) + + # Modules with some UNIX dependencies -- on by default: + # (If you have a really backward UNIX, select and socket may not be + # supported...) + + # fcntl(2) and ioctl(2) + if platform not in ['mac']: + # spwd, shadow passwords + if (config_h_vars.get('HAVE_GETSPNAM', False) or + config_h_vars.get('HAVE_GETSPENT', False)): + exts.append( Extension('spwd', ['spwdmodule.c']) ) + # select(2); not on ancient System V + if platform in ['mingw', 'win32']: + select_libs = ['ws2_32'] + else: + select_libs = [] + exts.append( Extension('select', ['selectmodule.c'], + libraries=select_libs) ) + + # Helper module for various ascii-encoders + exts.append( Extension('binascii', ['binascii.c']) ) + + # Fred Drake's interface to the Python parser + exts.append( Extension('parser', ['parsermodule.c']) ) + + # cStringIO and cPickle + exts.append( Extension('cStringIO', ['cStringIO.c']) ) + exts.append( Extension('cPickle', ['cPickle.c']) ) + + # Memory-mapped files (also works on Win32). + if platform not in ['atheos', 'mac']: + exts.append( Extension('mmap', ['mmapmodule.c']) ) + + # George Neville-Neil's timing module: + # Deprecated in PEP 4 http://www.python.org/peps/pep-0004.html + # http://mail.python.org/pipermail/python-dev/2006-January/060023.html + #exts.append( Extension('timing', ['timingmodule.c']) ) + + # + # Here ends the simple stuff. From here on, modules need certain + # libraries, are platform-specific, or present other surprises. + # + + # Multimedia modules + # These don't work for 64-bit platforms!!! + # These represent audio samples or images as strings: + + # Operations on audio samples + # According to #993173, this one should actually work fine on + # 64-bit platforms. + exts.append( Extension('audioop', ['audioop.c']) ) + + # Disabled on 64-bit platforms + if sys.maxint != 9223372036854775807L: + # Operations on images + exts.append( Extension('imageop', ['imageop.c']) ) + # Read SGI RGB image files (but coded portably) + exts.append( Extension('rgbimg', ['rgbimgmodule.c']) ) + + # readline + do_readline = self.compiler.find_library_file(lib_dirs, 'readline') + if platform == 'darwin': + # MacOSX 10.4 has a broken readline. Don't try to build + # the readline module unless the user has installed a fixed + # readline package + if find_file('readline/rlconf.h', inc_dirs, []) is None: + do_readline = False + if do_readline: + if sys.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. + # This way a staticly linked custom readline gets picked up + # before the (broken) dynamic library in /usr/lib. + readline_extra_link_args = ('-Wl,-search_paths_first',) + else: + readline_extra_link_args = () + + readline_libs = ['readline'] + if self.compiler.find_library_file(lib_dirs, + 'ncursesw'): + readline_libs.append('ncursesw') + elif self.compiler.find_library_file(lib_dirs, + 'ncurses'): + readline_libs.append('ncurses') + elif self.compiler.find_library_file(lib_dirs, 'curses'): + readline_libs.append('curses') + elif self.compiler.find_library_file(lib_dirs + + ['/usr/lib/termcap'], + 'termcap'): + readline_libs.append('termcap') + exts.append( Extension('readline', ['readline.c'], + library_dirs=['/usr/lib/termcap'], + extra_link_args=readline_extra_link_args, + libraries=readline_libs) ) + + # CSV files + exts.append( Extension('_csv', ['_csv.c']) ) + + # socket(2) + if platform in ['mingw', 'win32']: + socket_libs = ['ws2_32'] + else: + socket_libs = [] + exts.append( Extension('_socket', ['socketmodule.c'], + depends = ['socketmodule.h'], + libraries = socket_libs ) ) + # Detect SSL support for the socket module (via _ssl) + search_for_ssl_incs_in = [ + '/usr/local/ssl/include', + '/usr/contrib/ssl/include/' + ] + ssl_incs = find_file('openssl/ssl.h', inc_dirs, + search_for_ssl_incs_in + ) + if ssl_incs is not None: + krb5_h = find_file('krb5.h', inc_dirs, + ['/usr/kerberos/include']) + if krb5_h: + ssl_incs += krb5_h + ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs, + ['/usr/local/ssl/lib', + '/usr/contrib/ssl/lib/' + ] ) + + if (ssl_incs is not None and + ssl_libs is not None): + exts.append( Extension('_ssl', ['_ssl.c'], + include_dirs = ssl_incs, + library_dirs = ssl_libs, + libraries = ['ssl', 'crypto'], + depends = ['socketmodule.h']), ) + + # find out which version of OpenSSL we have + openssl_ver = 0 + openssl_ver_re = re.compile( + '^\s*#\s*define\s+OPENSSL_VERSION_NUMBER\s+(0x[0-9a-fA-F]+)' ) + for ssl_inc_dir in inc_dirs + search_for_ssl_incs_in: + name = os.path.join(ssl_inc_dir, 'openssl', 'opensslv.h') + if os.path.isfile(name): + try: + incfile = open(name, 'r') + for line in incfile: + m = openssl_ver_re.match(line) + if m: + openssl_ver = eval(m.group(1)) + break + except IOError: + pass + + # first version found is what we'll use (as the compiler should) + if openssl_ver: + break + + #print 'openssl_ver = 0x%08x' % openssl_ver + + if (ssl_incs is not None and + ssl_libs is not None and + openssl_ver >= 0x00907000): + # The _hashlib module wraps optimized implementations + # of hash functions from the OpenSSL library. + exts.append( Extension('_hashlib', ['_hashopenssl.c'], + include_dirs = ssl_incs, + library_dirs = ssl_libs, + libraries = ['ssl', 'crypto']) ) + else: + # The _sha module implements the SHA1 hash algorithm. + exts.append( Extension('_sha', ['shamodule.c']) ) + # The _md5 module implements the RSA Data Security, Inc. MD5 + # Message-Digest Algorithm, described in RFC 1321. The + # necessary files md5.c and md5.h are included here. + exts.append( Extension('_md5', + sources = ['md5module.c', 'md5.c'], + depends = ['md5.h']) ) + + if (openssl_ver < 0x00908000): + # OpenSSL doesn't do these until 0.9.8 so we'll bring our own hash + exts.append( Extension('_sha256', ['sha256module.c']) ) + exts.append( Extension('_sha512', ['sha512module.c']) ) + + + # Modules that provide persistent dictionary-like semantics. You will + # probably want to arrange for at least one of them to be available on + # your machine, though none are defined by default because of library + # dependencies. The Python module anydbm.py provides an + # implementation independent wrapper for these; dumbdbm.py provides + # similar functionality (but slower of course) implemented in Python. + + # Sleepycat^WOracle Berkeley DB interface. + # http://www.oracle.com/database/berkeley-db/db/index.html + # + # This requires the Sleepycat^WOracle DB code. The supported versions + # are set below. Visit the URL above to download + # a release. Most open source OSes come with one or more + # versions of BerkeleyDB already installed. + + max_db_ver = (4, 5) + # NOTE: while the _bsddb.c code links against BerkeleyDB 4.6.x + # we leave that version disabled by default as it has proven to be + # quite a buggy library release on many platforms. + min_db_ver = (3, 3) + db_setup_debug = False # verbose debug prints from this script? + + # construct a list of paths to look for the header file in on + # top of the normal inc_dirs. + db_inc_paths = [ + '/usr/include/db4', + '/usr/local/include/db4', + '/opt/sfw/include/db4', + '/sw/include/db4', + '/usr/include/db3', + '/usr/local/include/db3', + '/opt/sfw/include/db3', + '/sw/include/db3', + ] + # 4.x minor number specific paths + for x in range(max_db_ver[1]+1): + db_inc_paths.append('/usr/include/db4%d' % x) + db_inc_paths.append('/usr/include/db4.%d' % x) + db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x) + db_inc_paths.append('/usr/local/include/db4%d' % x) + db_inc_paths.append('/pkg/db-4.%d/include' % x) + db_inc_paths.append('/opt/db-4.%d/include' % x) + # 3.x minor number specific paths + for x in (3,): + db_inc_paths.append('/usr/include/db3%d' % x) + db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x) + db_inc_paths.append('/usr/local/include/db3%d' % x) + db_inc_paths.append('/pkg/db-3.%d/include' % x) + db_inc_paths.append('/opt/db-3.%d/include' % x) + + # Add some common subdirectories for Sleepycat DB to the list, + # based on the standard include directories. This way DB3/4 gets + # picked up when it is installed in a non-standard prefix and + # the user has added that prefix into inc_dirs. + std_variants = [] + for dn in inc_dirs: + std_variants.append(os.path.join(dn, 'db3')) + std_variants.append(os.path.join(dn, 'db4')) + for x in range(max_db_ver[1]+1): + std_variants.append(os.path.join(dn, "db4%d"%x)) + std_variants.append(os.path.join(dn, "db4.%d"%x)) + for x in (2,3): + std_variants.append(os.path.join(dn, "db3%d"%x)) + std_variants.append(os.path.join(dn, "db3.%d"%x)) + + db_inc_paths = std_variants + db_inc_paths + + + db_ver_inc_map = {} + + class db_found(Exception): pass + try: + # See whether there is a Sleepycat header in the standard + # search path. + for d in inc_dirs + db_inc_paths: + f = os.path.join(d, "db.h") + if db_setup_debug: print "db: looking for db.h in", f + if os.path.exists(f): + f = open(f).read() + m = re.search(r"#define\WDB_VERSION_MAJOR\W(\d+)", f) + if m: + db_major = int(m.group(1)) + m = re.search(r"#define\WDB_VERSION_MINOR\W(\d+)", f) + db_minor = int(m.group(1)) + db_ver = (db_major, db_minor) + + # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug + if db_ver == (4, 6): + m = re.search(r"#define\WDB_VERSION_PATCH\W(\d+)", f) + db_patch = int(m.group(1)) + if db_patch < 21: + print "db.h:", db_ver, "patch", db_patch, + print "being ignored (4.6.x must be >= 4.6.21)" + continue + + if ( (not db_ver_inc_map.has_key(db_ver)) and + (db_ver <= max_db_ver and db_ver >= min_db_ver) ): + # save the include directory with the db.h version + # (first occurrance only) + db_ver_inc_map[db_ver] = d + print "db.h: found", db_ver, "in", d + else: + # we already found a header for this library version + if db_setup_debug: print "db.h: ignoring", d + else: + # ignore this header, it didn't contain a version number + if db_setup_debug: print "db.h: unsupported version", db_ver, "in", d + + db_found_vers = db_ver_inc_map.keys() + db_found_vers.sort() + + while db_found_vers: + db_ver = db_found_vers.pop() + db_incdir = db_ver_inc_map[db_ver] + + # check lib directories parallel to the location of the header + db_dirs_to_check = [ + os.path.join(db_incdir, '..', 'lib64'), + os.path.join(db_incdir, '..', 'lib'), + os.path.join(db_incdir, '..', '..', 'lib64'), + os.path.join(db_incdir, '..', '..', 'lib'), + ] + db_dirs_to_check = filter(os.path.isdir, db_dirs_to_check) + + # Look for a version specific db-X.Y before an ambiguoius dbX + # XXX should we -ever- look for a dbX name? Do any + # systems really not name their library by version and + # symlink to more general names? + for dblib in (('db-%d.%d' % db_ver), + ('db%d%d' % db_ver), + ('db%d' % db_ver[0])): + dblib_file = self.compiler.find_library_file( + db_dirs_to_check + lib_dirs, dblib ) + if dblib_file: + dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ] + raise db_found + else: + if db_setup_debug: print "db lib: ", dblib, "not found" + + except db_found: + print "db lib: using", db_ver, dblib + if db_setup_debug: print "db: lib dir", dblib_dir, "inc dir", db_incdir + db_incs = [db_incdir] + dblibs = [dblib] + # We add the runtime_library_dirs argument because the + # BerkeleyDB lib we're linking against often isn't in the + # system dynamic library search path. This is usually + # correct and most trouble free, but may cause problems in + # some unusual system configurations (e.g. the directory + # is on an NFS server that goes away). + exts.append(Extension('_bsddb', ['_bsddb.c'], + library_dirs=dblib_dir, + runtime_library_dirs=dblib_dir, + include_dirs=db_incs, + libraries=dblibs)) + else: + if db_setup_debug: print "db: no appropriate library found" + db_incs = None + dblibs = [] + dblib_dir = None + + # The sqlite interface + sqlite_setup_debug = False # verbose debug prints from this script? + + # We hunt for #define SQLITE_VERSION "n.n.n" + # We need to find >= sqlite version 3.0.8 + sqlite_incdir = sqlite_libdir = None + sqlite_inc_paths = [ '/usr/include', + '/usr/include/sqlite', + '/usr/include/sqlite3', + '/usr/local/include', + '/usr/local/include/sqlite', + '/usr/local/include/sqlite3', + ] + MIN_SQLITE_VERSION_NUMBER = (3, 0, 8) + MIN_SQLITE_VERSION = ".".join([str(x) + for x in MIN_SQLITE_VERSION_NUMBER]) + + # Scan the default include directories before the SQLite specific + # ones. This allows one to override the copy of sqlite on OSX, + # where /usr/include contains an old version of sqlite. + for d in inc_dirs + sqlite_inc_paths: + f = os.path.join(d, "sqlite3.h") + if os.path.exists(f): + if sqlite_setup_debug: print "sqlite: found %s"%f + incf = open(f).read() + m = re.search( + r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"(.*)"', incf) + if m: + sqlite_version = m.group(1) + sqlite_version_tuple = tuple([int(x) + for x in sqlite_version.split(".")]) + if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER: + # we win! + print "%s/sqlite3.h: version %s"%(d, sqlite_version) + sqlite_incdir = d + break + else: + if sqlite_setup_debug: + print "%s: version %d is too old, need >= %s"%(d, + sqlite_version, MIN_SQLITE_VERSION) + elif sqlite_setup_debug: + print "sqlite: %s had no SQLITE_VERSION"%(f,) + + if sqlite_incdir: + sqlite_dirs_to_check = [ + os.path.join(sqlite_incdir, '..', 'lib64'), + os.path.join(sqlite_incdir, '..', 'lib'), + os.path.join(sqlite_incdir, '..', '..', 'lib64'), + os.path.join(sqlite_incdir, '..', '..', 'lib'), + ] + sqlite_libfile = self.compiler.find_library_file( + sqlite_dirs_to_check + lib_dirs, 'sqlite3') + if sqlite_libdir: + sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))] + + if sqlite_incdir and sqlite_libdir: + sqlite_srcs = ['_sqlite/cache.c', + '_sqlite/connection.c', + '_sqlite/cursor.c', + '_sqlite/microprotocols.c', + '_sqlite/module.c', + '_sqlite/prepare_protocol.c', + '_sqlite/row.c', + '_sqlite/statement.c', + '_sqlite/util.c', ] + + sqlite_defines = [] + if sys.platform != "win32": + sqlite_defines.append(('MODULE_NAME', '"sqlite3"')) + else: + sqlite_defines.append(('MODULE_NAME', '\\"sqlite3\\"')) + + + if sys.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. + # This way a staticly linked custom sqlite gets picked up + # before the dynamic library in /usr/lib. + sqlite_extra_link_args = ('-Wl,-search_paths_first',) + else: + sqlite_extra_link_args = () + + exts.append(Extension('_sqlite3', sqlite_srcs, + define_macros=sqlite_defines, + include_dirs=["Modules/_sqlite", + sqlite_incdir], + library_dirs=sqlite_libdir, + runtime_library_dirs=sqlite_libdir, + extra_link_args=sqlite_extra_link_args, + libraries=["sqlite3",])) + + # Look for Berkeley db 1.85. Note that it is built as a different + # module name so it can be included even when later versions are + # available. A very restrictive search is performed to avoid + # accidentally building this module with a later version of the + # underlying db library. May BSD-ish Unixes incorporate db 1.85 + # symbols into libc and place the include file in /usr/include. + # + # If the better bsddb library can be built (db_incs is defined) + # we do not build this one. Otherwise this build will pick up + # the more recent berkeleydb's db.h file first in the include path + # when attempting to compile and it will fail. + f = "/usr/include/db.h" + if os.path.exists(f) and not db_incs: + data = open(f).read() + m = re.search(r"#s*define\s+HASHVERSION\s+2\s*", data) + if m is not None: + # bingo - old version used hash file format version 2 + ### XXX this should be fixed to not be platform-dependent + ### but I don't have direct access to an osf1 platform and + ### seemed to be muffing the search somehow + libraries = platform == "osf1" and ['db'] or None + if libraries is not None: + exts.append(Extension('bsddb185', ['bsddbmodule.c'], + libraries=libraries)) + else: + exts.append(Extension('bsddb185', ['bsddbmodule.c'])) + + # The standard Unix dbm module: + if platform not in ['cygwin']: + if find_file("ndbm.h", inc_dirs, []) is not None: + # Some systems have -lndbm, others don't + if self.compiler.find_library_file(lib_dirs, 'ndbm'): + ndbm_libs = ['ndbm'] + else: + ndbm_libs = [] + exts.append( Extension('dbm', ['dbmmodule.c'], + define_macros=[('HAVE_NDBM_H',None)], + libraries = ndbm_libs ) ) + elif (self.compiler.find_library_file(lib_dirs, 'gdbm') + and find_file("gdbm/ndbm.h", inc_dirs, []) is not None): + exts.append( Extension('dbm', ['dbmmodule.c'], + define_macros=[('HAVE_GDBM_NDBM_H',None)], + libraries = ['gdbm'] ) ) + elif db_incs is not None: + exts.append( Extension('dbm', ['dbmmodule.c'], + library_dirs=dblib_dir, + runtime_library_dirs=dblib_dir, + include_dirs=db_incs, + define_macros=[('HAVE_BERKDB_H',None), + ('DB_DBM_HSEARCH',None)], + libraries=dblibs)) + + # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm: + if (self.compiler.find_library_file(lib_dirs, 'gdbm')): + exts.append( Extension('gdbm', ['gdbmmodule.c'], + libraries = ['gdbm'] ) ) + + # Unix-only modules + if platform not in ['mac', 'win32']: + # Steen Lumholt's termios module + exts.append( Extension('termios', ['termios.c']) ) + # Jeremy Hylton's rlimit interface + if platform not in ['atheos']: + exts.append( Extension('resource', ['resource.c']) ) + + # Sun yellow pages. Some systems have the functions in libc. + if platform not in ['cygwin', 'atheos']: + if (self.compiler.find_library_file(lib_dirs, 'nsl')): + libs = ['nsl'] + else: + libs = [] + exts.append( Extension('nis', ['nismodule.c'], + libraries = libs) ) + + # Curses support, requiring the System V version of curses, often + # provided by the ncurses library. + panel_library = 'panel' + if (self.compiler.find_library_file(lib_dirs, 'ncursesw')): + curses_libs = ['ncursesw'] + # Bug 1464056: If _curses.so links with ncursesw, + # _curses_panel.so must link with panelw. + panel_library = 'panelw' + exts.append( Extension('_curses', ['_cursesmodule.c'], + libraries = curses_libs) ) + elif (self.compiler.find_library_file(lib_dirs, 'ncurses')): + curses_libs = ['ncurses'] + exts.append( Extension('_curses', ['_cursesmodule.c'], + libraries = curses_libs) ) + elif (self.compiler.find_library_file(lib_dirs, 'curses') + and platform != 'darwin'): + # OSX has an old Berkeley curses, not good enough for + # the _curses module. + if (self.compiler.find_library_file(lib_dirs, 'terminfo')): + curses_libs = ['curses', 'terminfo'] + elif (self.compiler.find_library_file(lib_dirs, 'termcap')): + curses_libs = ['curses', 'termcap'] + else: + curses_libs = ['curses'] + + exts.append( Extension('_curses', ['_cursesmodule.c'], + libraries = curses_libs) ) + + # If the curses module is enabled, check for the panel module + if (module_enabled(exts, '_curses') and + self.compiler.find_library_file(lib_dirs, panel_library)): + exts.append( Extension('_curses_panel', ['_curses_panel.c'], + libraries = [panel_library] + curses_libs) ) + + + # Andrew Kuchling's zlib module. Note that some versions of zlib + # 1.1.3 have security problems. See CERT Advisory CA-2002-07: + # http://www.cert.org/advisories/CA-2002-07.html + # + # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to + # patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For + # now, we still accept 1.1.3, because we think it's difficult to + # exploit this in Python, and we'd rather make it RedHat's problem + # than our problem . + # + # You can upgrade zlib to version 1.1.4 yourself by going to + # http://www.gzip.org/zlib/ + zlib_inc = find_file('zlib.h', [], inc_dirs) + if zlib_inc is not None: + zlib_h = zlib_inc[0] + '/zlib.h' + version = '"0.0.0"' + version_req = '"1.1.3"' + fp = open(zlib_h) + while 1: + line = fp.readline() + if not line: + break + if line.startswith('#define ZLIB_VERSION'): + version = line.split()[2] + break + if version >= version_req: + if (self.compiler.find_library_file(lib_dirs, 'z')): + if sys.platform == "darwin": + zlib_extra_link_args = ('-Wl,-search_paths_first',) + else: + zlib_extra_link_args = () + exts.append( Extension('zlib', ['zlibmodule.c'], + libraries = ['z'], + extra_link_args = zlib_extra_link_args)) + + # Gustavo Niemeyer's bz2 module. + if (self.compiler.find_library_file(lib_dirs, 'bz2', debug=1)): + if sys.platform == "darwin": + bz2_extra_link_args = ('-Wl,-search_paths_first',) + else: + bz2_extra_link_args = () + exts.append( Extension('bz2', ['bz2module.c'], + libraries = ['bz2'], + extra_link_args = bz2_extra_link_args) ) + + # Interface to the Expat XML parser + # + # Expat was written by James Clark and is now maintained by a + # group of developers on SourceForge; see www.libexpat.org for + # more information. The pyexpat module was written by Paul + # Prescod after a prototype by Jack Jansen. The Expat source + # is included in Modules/expat/. Usage of a system + # shared libexpat.so/expat.dll is not advised. + # + # More information on Expat can be found at www.libexpat.org. + # + expatinc = os.path.join(os.getcwd(), srcdir, 'Modules', 'expat') + define_macros = [ + ('HAVE_EXPAT_CONFIG_H', '1'), + ] + + exts.append(Extension('pyexpat', + define_macros = define_macros, + include_dirs = [expatinc], + sources = ['pyexpat.c', + 'expat/xmlparse.c', + 'expat/xmlrole.c', + 'expat/xmltok.c', + ], + )) + + # Fredrik Lundh's cElementTree module. Note that this also + # uses expat (via the CAPI hook in pyexpat). + + if os.path.isfile(os.path.join(srcdir, 'Modules', '_elementtree.c')): + define_macros.append(('USE_PYEXPAT_CAPI', None)) + exts.append(Extension('_elementtree', + define_macros = define_macros, + include_dirs = [expatinc], + sources = ['_elementtree.c'], + )) + + # Hye-Shik Chang's CJKCodecs modules. + if have_unicode: + exts.append(Extension('_multibytecodec', + ['cjkcodecs/multibytecodec.c'])) + for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'): + exts.append(Extension('_codecs_' + loc, + ['cjkcodecs/_codecs_%s.c' % loc])) + + # Dynamic loading module + 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']): + exts.append( Extension('dl', ['dlmodule.c']) ) + + # Thomas Heller's _ctypes module + self.detect_ctypes(inc_dirs, lib_dirs) + + # Platform-specific libraries + if platform == 'linux2': + # Linux-specific modules + exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) ) + + if platform in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6', + 'freebsd7'): + exts.append( Extension('ossaudiodev', ['ossaudiodev.c']) ) + + if platform == 'sunos5': + # SunOS specific modules + exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) ) + + if platform == 'darwin' and ("--disable-toolbox-glue" not in + sysconfig.get_config_var("CONFIG_ARGS")): + + if os.uname()[2] > '8.': + # We're on Mac OS X 10.4 or later, the compiler should + # support '-Wno-deprecated-declarations'. This will + # surpress deprecation warnings for the Carbon extensions, + # these extensions wrap the Carbon APIs and even those + # parts that are deprecated. + carbon_extra_compile_args = ['-Wno-deprecated-declarations'] + else: + carbon_extra_compile_args = [] + + # Mac OS X specific modules. + def macSrcExists(name1, name2=''): + if not name1: + return None + names = (name1,) + if name2: + names = (name1, name2) + path = os.path.join(srcdir, 'Mac', 'Modules', *names) + return os.path.exists(path) + + def addMacExtension(name, kwds, extra_srcs=[]): + dirname = '' + if name[0] == '_': + dirname = name[1:].lower() + cname = name + '.c' + cmodulename = name + 'module.c' + # Check for NNN.c, NNNmodule.c, _nnn/NNN.c, _nnn/NNNmodule.c + if macSrcExists(cname): + srcs = [cname] + elif macSrcExists(cmodulename): + srcs = [cmodulename] + elif macSrcExists(dirname, cname): + # XXX(nnorwitz): If all the names ended with module, we + # wouldn't need this condition. ibcarbon is the only one. + srcs = [os.path.join(dirname, cname)] + elif macSrcExists(dirname, cmodulename): + srcs = [os.path.join(dirname, cmodulename)] + else: + raise RuntimeError("%s not found" % name) + + # Here's the whole point: add the extension with sources + exts.append(Extension(name, srcs + extra_srcs, **kwds)) + + # Core Foundation + core_kwds = {'extra_compile_args': carbon_extra_compile_args, + 'extra_link_args': ['-framework', 'CoreFoundation'], + } + addMacExtension('_CF', core_kwds, ['cf/pycfbridge.c']) + addMacExtension('autoGIL', core_kwds) + + # Carbon + carbon_kwds = {'extra_compile_args': carbon_extra_compile_args, + 'extra_link_args': ['-framework', 'Carbon'], + } + CARBON_EXTS = ['ColorPicker', 'gestalt', 'MacOS', 'Nav', + 'OSATerminology', 'icglue', + # All these are in subdirs + '_AE', '_AH', '_App', '_CarbonEvt', '_Cm', '_Ctl', + '_Dlg', '_Drag', '_Evt', '_File', '_Folder', '_Fm', + '_Help', '_Icn', '_IBCarbon', '_List', + '_Menu', '_Mlte', '_OSA', '_Res', '_Qd', '_Qdoffs', + '_Scrap', '_Snd', '_TE', '_Win', + ] + for name in CARBON_EXTS: + addMacExtension(name, carbon_kwds) + + # Application Services & QuickTime + app_kwds = {'extra_compile_args': carbon_extra_compile_args, + 'extra_link_args': ['-framework','ApplicationServices'], + } + addMacExtension('_Launch', app_kwds) + addMacExtension('_CG', app_kwds) + + exts.append( Extension('_Qt', ['qt/_Qtmodule.c'], + extra_compile_args=carbon_extra_compile_args, + extra_link_args=['-framework', 'QuickTime', + '-framework', 'Carbon']) ) + + + self.extensions.extend(exts) + + # Call the method for detecting whether _tkinter can be compiled + self.detect_tkinter(inc_dirs, lib_dirs) + def detect_modules(self): # Ensure that /usr/local is always used add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') @@ -1325,6 +2195,30 @@ class PyBuildExt(build_ext): # -lGL -lGLU -lXext -lXmu \ def configure_ctypes(self, ext): + platform = self.get_platform() + if platform in ['mingw', 'win32']: + # 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']) + ext.extra_compile_args.extend(["-DX86_WIN32"]) + + return True + if not self.use_system_libffi: (srcdir,) = sysconfig.get_config_vars('srcdir') ffi_builddir = os.path.join(self.build_temp, 'libffi') @@ -1406,7 +2300,13 @@ class PyBuildExt(build_ext): libraries=[], sources=sources, depends=depends) + if sys.platform in ['mingw', 'win32']: + 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])