diff options
author | Waldemar Brodkorb <wbx@openadk.org> | 2011-10-10 21:43:59 +0200 |
---|---|---|
committer | Waldemar Brodkorb <wbx@openadk.org> | 2011-10-10 21:43:59 +0200 |
commit | 123ac5fa80c94080c531fb4bf69d7eff6db1f4d0 (patch) | |
tree | 46d3352725a20c0c7b514e3721091c2cc65ffc0d /package/python2 | |
parent | 7d7d0ad0d61e22e7fd5c938f2aaf90b00416e6b7 (diff) |
add fix from python upstream to allow host build on ubuntu
Diffstat (limited to 'package/python2')
-rw-r--r-- | package/python2/Makefile | 3 | ||||
-rw-r--r-- | package/python2/files/setup.py | 2076 |
2 files changed, 2079 insertions, 0 deletions
diff --git a/package/python2/Makefile b/package/python2/Makefile index 6ab804935..53e770f2d 100644 --- a/package/python2/Makefile +++ b/package/python2/Makefile @@ -42,6 +42,8 @@ CONFIGURE_ARGS:= --with-threads \ --without-cxx-main post-extract: + $(CP) ${WRKBUILD}/setup.py ${WRKBUILD}/setup.py.sav + $(CP) ./files/setup.py ${WRKBUILD}/setup.py $(CP) ./files/posixmodule.c ${WRKBUILD}/Modules/posixmodule.c $(CP) ./files/python-config.in ${WRKBUILD}/Misc/python-config.in (cd ${WRKBUILD}; rm -rf config.{cache,status} ; \ @@ -56,6 +58,7 @@ post-extract: ${CP} ${WRKBUILD}/Parser/pgen ${WRKBUILD}/Parser/hostpgen ${CP} ${WRKBUILD}/python ${WRKBUILD}/hostpython $(MAKE) -C ${WRKBUILD} distclean + $(CP) ${WRKBUILD}/setup.py.sav ${WRKBUILD}/setup.py pre-configure: $(SED) "s#@@CPU_ARCH@@#$(CPU_ARCH)#" ${WRKBUILD}/configure diff --git a/package/python2/files/setup.py b/package/python2/files/setup.py new file mode 100644 index 000000000..baf694e16 --- /dev/null +++ b/package/python2/files/setup.py @@ -0,0 +1,2076 @@ +# Autodetecting setup.py script for building the Python extensions +# + +__version__ = "$Revision: 86041 $" + +import sys, os, imp, re, optparse +from glob import glob +from platform import machine as platform_machine +import sysconfig + +from distutils import log +from distutils import text_file +from distutils.errors import * +from distutils.core import Extension, setup +from distutils.command.build_ext import build_ext +from distutils.command.install import install +from distutils.command.install_lib import install_lib +from distutils.spawn import find_executable + +# Were we compiled --with-pydebug or with #define Py_DEBUG? +COMPILED_WITH_PYDEBUG = hasattr(sys, 'gettotalrefcount') + +# This global variable is used to hold the list of modules to be disabled. +disabled_module_list = [] + +def add_dir_to_list(dirlist, dir): + """Add the directory 'dir' to the list 'dirlist' (at the front) if + 1) 'dir' is not already in 'dirlist' + 2) 'dir' actually exists, and is a directory.""" + if dir is not None and os.path.isdir(dir) and dir not in dirlist: + dirlist.insert(0, dir) + +def macosx_sdk_root(): + """ + Return the directory of the current OSX SDK, + or '/' if no SDK was specified. + """ + cflags = sysconfig.get_config_var('CFLAGS') + m = re.search(r'-isysroot\s+(\S+)', cflags) + if m is None: + sysroot = '/' + else: + sysroot = m.group(1) + return sysroot + +def is_macosx_sdk_path(path): + """ + Returns True if 'path' can be located in an OSX SDK + """ + return (path.startswith('/usr/') and not path.startswith('/usr/local')) or path.startswith('/System/') + +def find_file(filename, std_dirs, paths): + """Searches for the directory where a given file is located, + and returns a possibly-empty list of additional directories, or None + if the file couldn't be found at all. + + 'filename' is the name of a file, such as readline.h or libcrypto.a. + 'std_dirs' is the list of standard system directories; if the + file is found in one of them, no additional directives are needed. + 'paths' is a list of additional locations to check; if the file is + found in one of them, the resulting list will contain the directory. + """ + if sys.platform == 'darwin': + # Honor the MacOSX SDK setting when one was specified. + # An SDK is a directory with the same structure as a real + # system, but with only header files and libraries. + sysroot = macosx_sdk_root() + + # Check the standard locations + for dir in std_dirs: + f = os.path.join(dir, filename) + + if sys.platform == 'darwin' and is_macosx_sdk_path(dir): + f = os.path.join(sysroot, dir[1:], filename) + + if os.path.exists(f): return [] + + # Check the additional directories + for dir in paths: + f = os.path.join(dir, filename) + + if sys.platform == 'darwin' and is_macosx_sdk_path(dir): + f = os.path.join(sysroot, dir[1:], filename) + + if os.path.exists(f): + return [dir] + + # Not found anywhere + return None + +def find_library_file(compiler, libname, std_dirs, paths): + result = compiler.find_library_file(std_dirs + paths, libname) + if result is None: + return None + + if sys.platform == 'darwin': + sysroot = macosx_sdk_root() + + # Check whether the found file is in one of the standard directories + dirname = os.path.dirname(result) + for p in std_dirs: + # Ensure path doesn't end with path separator + p = p.rstrip(os.sep) + + if sys.platform == 'darwin' and is_macosx_sdk_path(p): + if os.path.join(sysroot, p[1:]) == dirname: + return [ ] + + if p == dirname: + return [ ] + + # Otherwise, it must have been in one of the additional directories, + # so we have to figure out which one. + for p in paths: + # Ensure path doesn't end with path separator + p = p.rstrip(os.sep) + + if sys.platform == 'darwin' and is_macosx_sdk_path(p): + if os.path.join(sysroot, p[1:]) == dirname: + return [ p ] + + if p == dirname: + return [p] + else: + assert False, "Internal error: Path not found in std_dirs or paths" + +def module_enabled(extlist, modname): + """Returns whether the module 'modname' is present in the list + of extensions 'extlist'.""" + extlist = [ext for ext in extlist if ext.name == modname] + return len(extlist) + +def find_module_file(module, dirlist): + """Find a module in a set of possible folders. If it is not found + return the unadorned filename""" + list = find_file(module, [], dirlist) + if not list: + return module + if len(list) > 1: + log.info("WARNING: multiple copies of %s found"%module) + return os.path.join(list[0], module) + +class PyBuildExt(build_ext): + + def __init__(self, dist): + build_ext.__init__(self, dist) + self.failed = [] + + def build_extensions(self): + + # Detect which modules should be compiled + missing = self.detect_modules() + + # Remove modules that are present on the disabled list + extensions = [ext for ext in self.extensions + if ext.name not in disabled_module_list] + # move ctypes to the end, it depends on other modules + ext_map = dict((ext.name, i) for i, ext in enumerate(extensions)) + if "_ctypes" in ext_map: + ctypes = extensions.pop(ext_map["_ctypes"]) + extensions.append(ctypes) + self.extensions = extensions + + # Fix up the autodetected modules, prefixing all the source files + # with Modules/ and adding Python's include directory to the path. + (srcdir,) = sysconfig.get_config_vars('srcdir') + if not srcdir: + # Maybe running on Windows but not using CYGWIN? + raise ValueError("No source directory; cannot proceed.") + srcdir = os.path.abspath(srcdir) + moddirlist = [os.path.join(srcdir, 'Modules')] + + # Platform-dependent module source and include directories + incdirlist = [] + platform = self.get_platform() + if platform == 'darwin' and ("--disable-toolbox-glue" not in + sysconfig.get_config_var("CONFIG_ARGS")): + # Mac OS X also includes some mac-specific modules + macmoddir = os.path.join(srcdir, 'Mac/Modules') + moddirlist.append(macmoddir) + incdirlist.append(os.path.join(srcdir, 'Mac/Include')) + + # Fix up the paths for scripts, too + self.distribution.scripts = [os.path.join(srcdir, filename) + for filename in self.distribution.scripts] + + # Python header files + headers = [sysconfig.get_config_h_filename()] + headers += glob(os.path.join(sysconfig.get_path('platinclude'), "*.h")) + for ext in self.extensions[:]: + ext.sources = [ find_module_file(filename, moddirlist) + for filename in ext.sources ] + if ext.depends is not None: + ext.depends = [find_module_file(filename, moddirlist) + for filename in ext.depends] + else: + ext.depends = [] + # re-compile extensions if a header file has been changed + ext.depends.extend(headers) + + # platform specific include directories + ext.include_dirs.extend(incdirlist) + + # If a module has already been built statically, + # don't build it here + if ext.name in sys.builtin_module_names: + self.extensions.remove(ext) + + # Parse Modules/Setup and Modules/Setup.local to figure out which + # modules are turned on in the file. + remove_modules = [] + for filename in ('Modules/Setup', 'Modules/Setup.local'): + input = text_file.TextFile(filename, join_lines=1) + while 1: + line = input.readline() + if not line: break + line = line.split() + remove_modules.append(line[0]) + input.close() + + for ext in self.extensions[:]: + if ext.name in remove_modules: + self.extensions.remove(ext) + + # When you run "make CC=altcc" or something similar, you really want + # those environment variables passed into the setup.py phase. Here's + # a small set of useful ones. + compiler = os.environ.get('CC') + args = {} + # unfortunately, distutils doesn't let us provide separate C and C++ + # 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) + + build_ext.build_extensions(self) + + longest = max([len(e.name) for e in self.extensions]) + if self.failed: + longest = max(longest, max([len(name) for name in self.failed])) + + def print_three_column(lst): + lst.sort(key=str.lower) + # guarantee zip() doesn't drop anything + while len(lst) % 3: + lst.append("") + for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]): + print "%-*s %-*s %-*s" % (longest, e, longest, f, + longest, g) + + if missing: + print + print ("Python build finished, but the necessary bits to build " + "these modules were not found:") + print_three_column(missing) + print ("To find the necessary bits, look in setup.py in" + " detect_modules() for the module's name.") + print + + if self.failed: + failed = self.failed[:] + print + print "Failed to build these modules:" + print_three_column(failed) + print + + def build_extension(self, ext): + + if ext.name == '_ctypes': + if not self.configure_ctypes(ext): + return + + try: + build_ext.build_extension(self, ext) + except (CCompilerError, DistutilsError), why: + self.announce('WARNING: building of extension "%s" failed: %s' % + (ext.name, sys.exc_info()[1])) + self.failed.append(ext.name) + return + # Workaround for Mac OS X: The Carbon-based modules cannot be + # reliably imported into a command-line Python + if 'Carbon' in ext.extra_link_args: + self.announce( + 'WARNING: skipping import check for Carbon-based "%s"' % + ext.name) + return + + if self.get_platform() == 'darwin' and ( + sys.maxint > 2**32 and '-arch' in ext.extra_link_args): + # Don't bother doing an import check when an extension was + # build with an explicit '-arch' flag on OSX. That's currently + # only used to build 32-bit only extensions in a 4-way + # universal build and loading 32-bit code into a 64-bit + # process will fail. + self.announce( + 'WARNING: skipping import check for "%s"' % + ext.name) + return + + # Workaround for Cygwin: Cygwin currently has fork issues when many + # modules have been imported + if self.get_platform() == 'cygwin': + self.announce('WARNING: skipping import check for Cygwin-based "%s"' + % ext.name) + return + ext_filename = os.path.join( + self.build_lib, + self.get_ext_filename(self.get_ext_fullname(ext.name))) + try: + imp.load_dynamic(ext.name, ext_filename) + except ImportError, why: + self.failed.append(ext.name) + self.announce('*** WARNING: renaming "%s" since importing it' + ' failed: %s' % (ext.name, why), level=3) + assert not self.inplace + basename, tail = os.path.splitext(ext_filename) + newname = basename + "_failed" + tail + if os.path.exists(newname): + os.remove(newname) + os.rename(ext_filename, newname) + + # XXX -- This relies on a Vile HACK in + # distutils.command.build_ext.build_extension(). The + # _built_objects attribute is stored there strictly for + # use here. + # If there is a failure, _built_objects may not be there, + # so catch the AttributeError and move on. + try: + for filename in self._built_objects: + os.remove(filename) + except AttributeError: + self.announce('unable to remove files (ignored)') + except: + exc_type, why, tb = sys.exc_info() + self.announce('*** WARNING: importing extension "%s" ' + 'failed with %s: %s' % (ext.name, exc_type, why), + level=3) + self.failed.append(ext.name) + + def get_platform(self): + # Get value of sys.platform + for platform in ['cygwin', 'beos', 'darwin', 'atheos', 'osf1']: + if sys.platform.startswith(platform): + return platform + return sys.platform + + def add_multiarch_paths(self): + # Debian/Ubuntu multiarch support. + # https://wiki.ubuntu.com/MultiarchSpec + if not find_executable('dpkg-architecture'): + return + tmpfile = os.path.join(self.build_temp, 'multiarch') + if not os.path.exists(self.build_temp): + os.makedirs(self.build_temp) + ret = os.system( + 'dpkg-architecture -qDEB_HOST_MULTIARCH > %s 2> /dev/null' % + tmpfile) + try: + if ret >> 8 == 0: + with open(tmpfile) as fp: + multiarch_path_component = fp.readline().strip() + add_dir_to_list(self.compiler.library_dirs, + '/usr/lib/' + multiarch_path_component) + add_dir_to_list(self.compiler.include_dirs, + '/usr/include/' + multiarch_path_component) + finally: + os.unlink(tmpfile) + + def detect_modules(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') + self.add_multiarch_paths() + + # 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', '-R', self.compiler.runtime_library_dirs), + ('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 it 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' \ + and not sysconfig.get_config_var('PYTHONFRAMEWORK'): + # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework + # (PYTHONFRAMEWORK is set) to avoid # linking problems when + # building a framework with different architectures than + # the one that is currently installed (issue #7473) + 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 + [ + '/lib64', '/usr/lib64', + '/lib', '/usr/lib', + ] + inc_dirs = self.compiler.include_dirs + ['/usr/include'] + exts = [] + missing = [] + + 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_var('srcdir') + + # Check for AtheOS which has libraries in non-standard locations + if platform == 'atheos': + lib_dirs += ['/system/libs', '/atheos/autolnk/lib'] + lib_dirs += os.getenv('LIBRARY_PATH', '').split(os.pathsep) + inc_dirs += ['/system/include', '/atheos/autolnk/include'] + inc_dirs += os.getenv('C_INCLUDE_PATH', '').split(os.pathsep) + + # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb) + if platform in ['osf1', 'unixware7', 'openunix8']: + lib_dirs += ['/usr/ccs/lib'] + + if platform == 'darwin': + # This should work on any unixy platform ;-) + # If the user has bothered specifying additional -I and -L flags + # in OPT and LDFLAGS we might as well use them here. + # NOTE: using shlex.split would technically be more correct, but + # also gives a bootstrap problem. Let's hope nobody uses directories + # with whitespace in the name to store libraries. + cflags, ldflags = sysconfig.get_config_vars( + 'CFLAGS', 'LDFLAGS') + for item in cflags.split(): + if item.startswith('-I'): + inc_dirs.append(item[2:]) + + for item in ldflags.split(): + if item.startswith('-L'): + lib_dirs.append(item[2:]) + + # Check for MacOS X, which doesn't need libm.a at all + math_libs = ['m'] + if platform in ['darwin', 'beos']: + math_libs = [] + + # XXX Omitted modules: gl, pure, dl, SGI-specific modules + + # + # 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', '_math.c'], + depends=['_math.h'], + libraries=math_libs) ) + # math library functions, e.g. sin() + exts.append( Extension('math', ['mathmodule.c', '_math.c'], + depends=['_math.h'], + 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) ) + # fast iterator tools implemented in C + exts.append( Extension("itertools", ["itertoolsmodule.c"]) ) + # code that will be builtins in the future, but conflict with the + # current builtins + exts.append( Extension('future_builtins', ['future_builtins.c']) ) + # random number generator implemented in C + exts.append( Extension("_random", ["_randommodule.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']) ) + # Python 3.1 _io library + exts.append( Extension("_io", + ["_io/bufferedio.c", "_io/bytesio.c", "_io/fileio.c", + "_io/iobase.c", "_io/_iomodule.c", "_io/stringio.c", "_io/textio.c"], + depends=["_io/_iomodule.h"], include_dirs=["Modules/_io"])) + # _functools + exts.append( Extension("_functools", ["_functoolsmodule.c"]) ) + # _json speedups + exts.append( Extension("_json", ["_json.c"]) ) + # Python C API test module + exts.append( Extension('_testcapi', ['_testcapimodule.c'], + depends=['testcapi_long.h']) ) + # 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']) ) + else: + missing.append('unicodedata') + # 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 = [] + if platform == 'darwin': + locale_extra_link_args = ['-framework', 'CoreFoundation'] + else: + 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) + libs = [] + if (config_h_vars.get('FLOCK_NEEDS_LIBBSD', False)): + # May be necessary on AIX for flock function + libs = ['bsd'] + exts.append( Extension('fcntl', ['fcntlmodule.c'], libraries=libs) ) + # pwd(3) + exts.append( Extension('pwd', ['pwdmodule.c']) ) + # grp(3) + exts.append( Extension('grp', ['grpmodule.c']) ) + # 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']) ) + else: + missing.append('spwd') + + # select(2); not on ancient System V + exts.append( Extension('select', ['selectmodule.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']: + exts.append( Extension('mmap', ['mmapmodule.c']) ) + else: + missing.append('mmap') + + # Lance Ellinghaus's syslog module + # syslog daemon interface + exts.append( Extension('syslog', ['syslogmodule.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']) ) + else: + missing.extend(['imageop']) + + # readline + do_readline = self.compiler.find_library_file(lib_dirs, 'readline') + readline_termcap_library = "" + curses_library = "" + # Determine if readline is already linked against curses or tinfo. + if do_readline and find_executable('ldd'): + fp = os.popen("ldd %s" % do_readline) + ldd_output = fp.readlines() + ret = fp.close() + if ret is None or ret >> 8 == 0: + for ln in ldd_output: + if 'curses' in ln: + readline_termcap_library = re.sub( + r'.*lib(n?cursesw?)\.so.*', r'\1', ln + ).rstrip() + break + if 'tinfo' in ln: # termcap interface split out from ncurses + readline_termcap_library = 'tinfo' + break + # Issue 7384: If readline is already linked against curses, + # use the same library for the readline and curses modules. + if 'curses' in readline_termcap_library: + curses_library = readline_termcap_library + elif self.compiler.find_library_file(lib_dirs, 'ncursesw'): + curses_library = 'ncursesw' + elif self.compiler.find_library_file(lib_dirs, 'ncurses'): + curses_library = 'ncurses' + elif self.compiler.find_library_file(lib_dirs, 'curses'): + curses_library = 'curses' + + if platform == 'darwin': + os_release = int(os.uname()[2].split('.')[0]) + dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') + if dep_target and dep_target.split('.') < ['10', '5']: + os_release = 8 + if os_release < 9: + # 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 platform == 'darwin' and os_release < 9: + # 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 (possibly broken) dynamic library in /usr/lib. + readline_extra_link_args = ('-Wl,-search_paths_first',) + else: + readline_extra_link_args = () + + readline_libs = ['readline'] + if readline_termcap_library: + pass # Issue 7384: Already linked against curses or tinfo. + elif curses_library: + readline_libs.append(curses_library) + 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) ) + else: + missing.append('readline') + + # crypt module. + + if self.compiler.find_library_file(lib_dirs, 'crypt'): + libs = ['crypt'] + else: + libs = [] + exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) ) + + # CSV files + exts.append( Extension('_csv', ['_csv.c']) ) + + # socket(2) + exts.append( Extension('_socket', ['socketmodule.c'], + depends = ['socketmodule.h']) ) + # 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']), ) + else: + missing.append('_ssl') + + # 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]+)' ) + + # look for the openssl version header on the compiler search path. + opensslv_h = find_file('openssl/opensslv.h', [], + inc_dirs + search_for_ssl_incs_in) + if opensslv_h: + name = os.path.join(opensslv_h[0], 'openssl/opensslv.h') + if sys.platform == 'darwin' and is_macosx_sdk_path(name): + name = os.path.join(macosx_sdk_root(), name[1:]) + try: + incfile = open(name, 'r') + for line in incfile: + m = openssl_ver_re.match(line) + if m: + openssl_ver = eval(m.group(1)) + except IOError, msg: + print "IOError while reading opensshv.h:", msg + pass + + min_openssl_ver = 0x00907000 + have_any_openssl = ssl_incs is not None and ssl_libs is not None + have_usable_openssl = (have_any_openssl and + openssl_ver >= min_openssl_ver) + + if have_any_openssl: + if have_usable_openssl: + # 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: + print ("warning: openssl 0x%08x is too old for _hashlib" % + openssl_ver) + missing.append('_hashlib') + if COMPILED_WITH_PYDEBUG or not have_usable_openssl: + # 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']) ) + + min_sha2_openssl_ver = 0x00908000 + if COMPILED_WITH_PYDEBUG or openssl_ver < min_sha2_openssl_ver: + # 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, 8) + min_db_ver = (4, 1) + db_setup_debug = False # verbose debug prints from this script? + + def allow_db_ver(db_ver): + """Returns a boolean if the given BerkeleyDB version is acceptable. + + Args: + db_ver: A tuple of the version to verify. + """ + if not (min_db_ver <= db_ver <= max_db_ver): + return False + # Use this function to filter out known bad configurations. + if (4, 6) == db_ver[:2]: + # BerkeleyDB 4.6.x is not stable on many architectures. + arch = platform_machine() + if arch not in ('i386', 'i486', 'i586', 'i686', + 'x86_64', 'ia64'): + return False + return True + + def gen_db_minor_ver_nums(major): + if major == 4: + for x in range(max_db_ver[1]+1): + if allow_db_ver((4, x)): + yield x + elif major == 3: + for x in (3,): + if allow_db_ver((3, x)): + yield x + else: + raise ValueError("unknown major BerkeleyDB version", major) + + # 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', + '/usr/include/db3', + '/usr/local/include/db3', + '/opt/sfw/include/db3', + # Fink defaults (http://fink.sourceforge.net/) + '/sw/include/db4', + '/sw/include/db3', + ] + # 4.x minor number specific paths + for x in gen_db_minor_ver_nums(4): + 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) + # MacPorts default (http://www.macports.org/) + db_inc_paths.append('/opt/local/include/db4%d' % x) + # 3.x minor number specific paths + for x in gen_db_minor_ver_nums(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 |