Radix cross Linux

The main Radix cross Linux repository contains the build scripts of packages, which have the most complete and common functionality for desktop machines

452 Commits   2 Branches   1 Tag
     5         kx # Autodetecting setup.py script for building the Python extensions
     5         kx #
     5         kx 
     5         kx __version__ = "$Revision$"
     5         kx 
     5         kx import sys, os, imp, re, optparse
     5         kx from glob import glob
     5         kx from platform import machine as platform_machine
     5         kx import sysconfig
     5         kx 
     5         kx from distutils import log
     5         kx from distutils import text_file
     5         kx from distutils.errors import *
     5         kx from distutils.core import Extension, setup
     5         kx from distutils.command.build_ext import build_ext
     5         kx from distutils.command.install import install
     5         kx from distutils.command.install_lib import install_lib
     5         kx from distutils.spawn import find_executable
     5         kx 
     5         kx cross_compiling = "_PYTHON_HOST_PLATFORM" in os.environ
     5         kx 
     5         kx def get_platform():
     5         kx     # cross build
     5         kx     if "_PYTHON_HOST_PLATFORM" in os.environ:
     5         kx         return os.environ["_PYTHON_HOST_PLATFORM"]
     5         kx     # Get value of sys.platform
     5         kx     if sys.platform.startswith('osf1'):
     5         kx         return 'osf1'
     5         kx     return sys.platform
     5         kx host_platform = get_platform()
     5         kx 
     5         kx # Were we compiled --with-pydebug or with #define Py_DEBUG?
     5         kx COMPILED_WITH_PYDEBUG = ('--with-pydebug' in sysconfig.get_config_var("CONFIG_ARGS"))
     5         kx 
     5         kx # This global variable is used to hold the list of modules to be disabled.
     5         kx disabled_module_list = []
     5         kx 
     5         kx def add_dir_to_list(dirlist, dir):
     5         kx     """Add the directory 'dir' to the list 'dirlist' (at the front) if
     5         kx     1) 'dir' is not already in 'dirlist'
     5         kx     2) 'dir' actually exists, and is a directory."""
     5         kx     if dir is not None and dir not in dirlist:
     5         kx         if host_platform == 'darwin' and is_macosx_sdk_path(dir):
     5         kx             # If in a macOS SDK path, check relative to the SDK root
     5         kx             dir_exists = os.path.isdir(
     5         kx                 os.path.join(macosx_sdk_root(), dir[1:]))
     5         kx         else:
     5         kx             dir_exists = os.path.isdir(dir)
     5         kx         if dir_exists:
     5         kx             dirlist.insert(0, dir)
     5         kx 
     5         kx MACOS_SDK_ROOT = None
     5         kx 
     5         kx def macosx_sdk_root():
     5         kx     """Return the directory of the current macOS SDK.
     5         kx 
     5         kx     If no SDK was explicitly configured, call the compiler to find which
     5         kx     include files paths are being searched by default.  Use '/' if the
     5         kx     compiler is searching /usr/include (meaning system header files are
     5         kx     installed) or use the root of an SDK if that is being searched.
     5         kx     (The SDK may be supplied via Xcode or via the Command Line Tools).
     5         kx     The SDK paths used by Apple-supplied tool chains depend on the
     5         kx     setting of various variables; see the xcrun man page for more info.
     5         kx     """
     5         kx     global MACOS_SDK_ROOT
     5         kx 
     5         kx     # If already called, return cached result.
     5         kx     if MACOS_SDK_ROOT:
     5         kx         return MACOS_SDK_ROOT
     5         kx 
     5         kx     cflags = sysconfig.get_config_var('CFLAGS')
     5         kx     m = re.search(r'-isysroot\s+(\S+)', cflags)
     5         kx     if m is not None:
     5         kx         MACOS_SDK_ROOT = m.group(1)
     5         kx     else:
     5         kx         MACOS_SDK_ROOT = '/'
     5         kx         cc = sysconfig.get_config_var('CC')
     5         kx         tmpfile = '/tmp/setup_sdk_root.%d' % os.getpid()
     5         kx         try:
     5         kx             os.unlink(tmpfile)
     5         kx         except:
     5         kx             pass
     5         kx         ret = os.system('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc, tmpfile))
     5         kx         in_incdirs = False
     5         kx         try:
     5         kx             if ret >> 8 == 0:
     5         kx                 with open(tmpfile) as fp:
     5         kx                     for line in fp.readlines():
     5         kx                         if line.startswith("#include <...>"):
     5         kx                             in_incdirs = True
     5         kx                         elif line.startswith("End of search list"):
     5         kx                             in_incdirs = False
     5         kx                         elif in_incdirs:
     5         kx                             line = line.strip()
     5         kx                             if line == '/usr/include':
     5         kx                                 MACOS_SDK_ROOT = '/'
     5         kx                             elif line.endswith(".sdk/usr/include"):
     5         kx                                 MACOS_SDK_ROOT = line[:-12]
     5         kx         finally:
     5         kx             os.unlink(tmpfile)
     5         kx 
     5         kx     return MACOS_SDK_ROOT
     5         kx 
     5         kx def is_macosx_sdk_path(path):
     5         kx     """
     5         kx     Returns True if 'path' can be located in an OSX SDK
     5         kx     """
     5         kx     return ( (path.startswith('/usr/') and not path.startswith('/usr/local'))
     5         kx                 or path.startswith('/System/')
     5         kx                 or path.startswith('/Library/') )
     5         kx 
     5         kx def find_file(filename, std_dirs, paths):
     5         kx     """Searches for the directory where a given file is located,
     5         kx     and returns a possibly-empty list of additional directories, or None
     5         kx     if the file couldn't be found at all.
     5         kx 
     5         kx     'filename' is the name of a file, such as readline.h or libcrypto.a.
     5         kx     'std_dirs' is the list of standard system directories; if the
     5         kx         file is found in one of them, no additional directives are needed.
     5         kx     'paths' is a list of additional locations to check; if the file is
     5         kx         found in one of them, the resulting list will contain the directory.
     5         kx     """
     5         kx     if host_platform == 'darwin':
     5         kx         # Honor the MacOSX SDK setting when one was specified.
     5         kx         # An SDK is a directory with the same structure as a real
     5         kx         # system, but with only header files and libraries.
     5         kx         sysroot = macosx_sdk_root()
     5         kx 
     5         kx     # Check the standard locations
     5         kx     for dir in std_dirs:
     5         kx         f = os.path.join(dir, filename)
     5         kx 
     5         kx         if host_platform == 'darwin' and is_macosx_sdk_path(dir):
     5         kx             f = os.path.join(sysroot, dir[1:], filename)
     5         kx 
     5         kx         if os.path.exists(f): return []
     5         kx 
     5         kx     # Check the additional directories
     5         kx     for dir in paths:
     5         kx         f = os.path.join(dir, filename)
     5         kx 
     5         kx         if host_platform == 'darwin' and is_macosx_sdk_path(dir):
     5         kx             f = os.path.join(sysroot, dir[1:], filename)
     5         kx 
     5         kx         if os.path.exists(f):
     5         kx             return [dir]
     5         kx 
     5         kx     # Not found anywhere
     5         kx     return None
     5         kx 
     5         kx def find_library_file(compiler, libname, std_dirs, paths):
     5         kx     result = compiler.find_library_file(std_dirs + paths, libname)
     5         kx     if result is None:
     5         kx         return None
     5         kx 
     5         kx     if host_platform == 'darwin':
     5         kx         sysroot = macosx_sdk_root()
     5         kx 
     5         kx     # Check whether the found file is in one of the standard directories
     5         kx     dirname = os.path.dirname(result)
     5         kx     for p in std_dirs:
     5         kx         # Ensure path doesn't end with path separator
     5         kx         p = p.rstrip(os.sep)
     5         kx 
     5         kx         if host_platform == 'darwin' and is_macosx_sdk_path(p):
     5         kx             # Note that, as of Xcode 7, Apple SDKs may contain textual stub
     5         kx             # libraries with .tbd extensions rather than the normal .dylib
     5         kx             # shared libraries installed in /.  The Apple compiler tool
     5         kx             # chain handles this transparently but it can cause problems
     5         kx             # for programs that are being built with an SDK and searching
     5         kx             # for specific libraries.  Distutils find_library_file() now
     5         kx             # knows to also search for and return .tbd files.  But callers
     5         kx             # of find_library_file need to keep in mind that the base filename
     5         kx             # of the returned SDK library file might have a different extension
     5         kx             # from that of the library file installed on the running system,
     5         kx             # for example:
     5         kx             #   /Applications/Xcode.app/Contents/Developer/Platforms/
     5         kx             #       MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/
     5         kx             #       usr/lib/libedit.tbd
     5         kx             # vs
     5         kx             #   /usr/lib/libedit.dylib
     5         kx             if os.path.join(sysroot, p[1:]) == dirname:
     5         kx                 return [ ]
     5         kx 
     5         kx         if p == dirname:
     5         kx             return [ ]
     5         kx 
     5         kx     # Otherwise, it must have been in one of the additional directories,
     5         kx     # so we have to figure out which one.
     5         kx     for p in paths:
     5         kx         # Ensure path doesn't end with path separator
     5         kx         p = p.rstrip(os.sep)
     5         kx 
     5         kx         if host_platform == 'darwin' and is_macosx_sdk_path(p):
     5         kx             if os.path.join(sysroot, p[1:]) == dirname:
     5         kx                 return [ p ]
     5         kx 
     5         kx         if p == dirname:
     5         kx             return [p]
     5         kx     else:
     5         kx         assert False, "Internal error: Path not found in std_dirs or paths"
     5         kx 
     5         kx def module_enabled(extlist, modname):
     5         kx     """Returns whether the module 'modname' is present in the list
     5         kx     of extensions 'extlist'."""
     5         kx     extlist = [ext for ext in extlist if ext.name == modname]
     5         kx     return len(extlist)
     5         kx 
     5         kx def find_module_file(module, dirlist):
     5         kx     """Find a module in a set of possible folders. If it is not found
     5         kx     return the unadorned filename"""
     5         kx     list = find_file(module, [], dirlist)
     5         kx     if not list:
     5         kx         return module
     5         kx     if len(list) > 1:
     5         kx         log.info("WARNING: multiple copies of %s found"%module)
     5         kx     return os.path.join(list[0], module)
     5         kx 
     5         kx class PyBuildExt(build_ext):
     5         kx 
     5         kx     def __init__(self, dist):
     5         kx         build_ext.__init__(self, dist)
     5         kx         self.failed = []
     5         kx 
     5         kx     def build_extensions(self):
     5         kx 
     5         kx         # Detect which modules should be compiled
     5         kx         missing = self.detect_modules()
     5         kx 
     5         kx         # Remove modules that are present on the disabled list
     5         kx         extensions = [ext for ext in self.extensions
     5         kx                       if ext.name not in disabled_module_list]
     5         kx         # move ctypes to the end, it depends on other modules
     5         kx         ext_map = dict((ext.name, i) for i, ext in enumerate(extensions))
     5         kx         if "_ctypes" in ext_map:
     5         kx             ctypes = extensions.pop(ext_map["_ctypes"])
     5         kx             extensions.append(ctypes)
     5         kx         self.extensions = extensions
     5         kx 
     5         kx         # Fix up the autodetected modules, prefixing all the source files
     5         kx         # with Modules/ and adding Python's include directory to the path.
     5         kx         (srcdir,) = sysconfig.get_config_vars('srcdir')
     5         kx         if not srcdir:
     5         kx             # Maybe running on Windows but not using CYGWIN?
     5         kx             raise ValueError("No source directory; cannot proceed.")
     5         kx         srcdir = os.path.abspath(srcdir)
     5         kx         moddirlist = [os.path.join(srcdir, 'Modules')]
     5         kx 
     5         kx         # Platform-dependent module source and include directories
     5         kx         incdirlist = []
     5         kx 
     5         kx         if host_platform == 'darwin' and ("--disable-toolbox-glue" not in
     5         kx             sysconfig.get_config_var("CONFIG_ARGS")):
     5         kx             # Mac OS X also includes some mac-specific modules
     5         kx             macmoddir = os.path.join(srcdir, 'Mac/Modules')
     5         kx             moddirlist.append(macmoddir)
     5         kx             incdirlist.append(os.path.join(srcdir, 'Mac/Include'))
     5         kx 
     5         kx         # Fix up the paths for scripts, too
     5         kx         self.distribution.scripts = [os.path.join(srcdir, filename)
     5         kx                                      for filename in self.distribution.scripts]
     5         kx 
     5         kx         # Python header files
     5         kx         headers = [sysconfig.get_config_h_filename()]
     5         kx         headers += glob(os.path.join(sysconfig.get_path('include'), "*.h"))
     5         kx         for ext in self.extensions[:]:
     5         kx             ext.sources = [ find_module_file(filename, moddirlist)
     5         kx                             for filename in ext.sources ]
     5         kx             if ext.depends is not None:
     5         kx                 ext.depends = [find_module_file(filename, moddirlist)
     5         kx                                for filename in ext.depends]
     5         kx             else:
     5         kx                 ext.depends = []
     5         kx             # re-compile extensions if a header file has been changed
     5         kx             ext.depends.extend(headers)
     5         kx 
     5         kx             # platform specific include directories
     5         kx             ext.include_dirs.extend(incdirlist)
     5         kx 
     5         kx             # If a module has already been built statically,
     5         kx             # don't build it here
     5         kx             if ext.name in sys.builtin_module_names:
     5         kx                 self.extensions.remove(ext)
     5         kx 
     5         kx         # Parse Modules/Setup and Modules/Setup.local to figure out which
     5         kx         # modules are turned on in the file.
     5         kx         remove_modules = []
     5         kx         for filename in ('Modules/Setup', 'Modules/Setup.local'):
     5         kx             input = text_file.TextFile(filename, join_lines=1)
     5         kx             while 1:
     5         kx                 line = input.readline()
     5         kx                 if not line: break
     5         kx                 line = line.split()
     5         kx                 remove_modules.append(line[0])
     5         kx             input.close()
     5         kx 
     5         kx         for ext in self.extensions[:]:
     5         kx             if ext.name in remove_modules:
     5         kx                 self.extensions.remove(ext)
     5         kx 
     5         kx         # When you run "make CC=altcc" or something similar, you really want
     5         kx         # those environment variables passed into the setup.py phase.  Here's
     5         kx         # a small set of useful ones.
     5         kx         compiler = os.environ.get('CC')
     5         kx         args = {}
     5         kx         # unfortunately, distutils doesn't let us provide separate C and C++
     5         kx         # compilers
     5         kx         if compiler is not None:
     5         kx             (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS')
     5         kx             args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags
     5         kx         self.compiler.set_executables(**args)
     5         kx 
     5         kx         build_ext.build_extensions(self)
     5         kx 
     5         kx         longest = 0
     5         kx         if self.extensions:
     5         kx             longest = max([len(e.name) for e in self.extensions])
     5         kx         if self.failed:
     5         kx             longest = max(longest, max([len(name) for name in self.failed]))
     5         kx 
     5         kx         def print_three_column(lst):
     5         kx             lst.sort(key=str.lower)
     5         kx             # guarantee zip() doesn't drop anything
     5         kx             while len(lst) % 3:
     5         kx                 lst.append("")
     5         kx             for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]):
     5         kx                 print "%-*s   %-*s   %-*s" % (longest, e, longest, f,
     5         kx                                               longest, g)
     5         kx 
     5         kx         if missing:
     5         kx             print
     5         kx             print ("Python build finished, but the necessary bits to build "
     5         kx                    "these modules were not found:")
     5         kx             print_three_column(missing)
     5         kx             print ("To find the necessary bits, look in setup.py in"
     5         kx                    " detect_modules() for the module's name.")
     5         kx             print
     5         kx 
     5         kx         if self.failed:
     5         kx             failed = self.failed[:]
     5         kx             print
     5         kx             print "Failed to build these modules:"
     5         kx             print_three_column(failed)
     5         kx             print
     5         kx 
     5         kx     def build_extension(self, ext):
     5         kx 
     5         kx         if ext.name == '_ctypes':
     5         kx             if not self.configure_ctypes(ext):
     5         kx                 return
     5         kx 
     5         kx         try:
     5         kx             build_ext.build_extension(self, ext)
     5         kx         except (CCompilerError, DistutilsError), why:
     5         kx             self.announce('WARNING: building of extension "%s" failed: %s' %
     5         kx                           (ext.name, sys.exc_info()[1]))
     5         kx             self.failed.append(ext.name)
     5         kx             return
     5         kx         # Workaround for Mac OS X: The Carbon-based modules cannot be
     5         kx         # reliably imported into a command-line Python
     5         kx         if 'Carbon' in ext.extra_link_args:
     5         kx             self.announce(
     5         kx                 'WARNING: skipping import check for Carbon-based "%s"' %
     5         kx                 ext.name)
     5         kx             return
     5         kx 
     5         kx         if host_platform == 'darwin' and (
     5         kx                 sys.maxint > 2**32 and '-arch' in ext.extra_link_args):
     5         kx             # Don't bother doing an import check when an extension was
     5         kx             # build with an explicit '-arch' flag on OSX. That's currently
     5         kx             # only used to build 32-bit only extensions in a 4-way
     5         kx             # universal build and loading 32-bit code into a 64-bit
     5         kx             # process will fail.
     5         kx             self.announce(
     5         kx                 'WARNING: skipping import check for "%s"' %
     5         kx                 ext.name)
     5         kx             return
     5         kx 
     5         kx         # Workaround for Cygwin: Cygwin currently has fork issues when many
     5         kx         # modules have been imported
     5         kx         if host_platform == 'cygwin':
     5         kx             self.announce('WARNING: skipping import check for Cygwin-based "%s"'
     5         kx                 % ext.name)
     5         kx             return
     5         kx         ext_filename = os.path.join(
     5         kx             self.build_lib,
     5         kx             self.get_ext_filename(self.get_ext_fullname(ext.name)))
     5         kx 
     5         kx         # Don't try to load extensions for cross builds
     5         kx         if cross_compiling:
     5         kx             return
     5         kx 
     5         kx         try:
     5         kx             imp.load_dynamic(ext.name, ext_filename)
     5         kx         except ImportError, why:
     5         kx             self.failed.append(ext.name)
     5         kx             self.announce('*** WARNING: renaming "%s" since importing it'
     5         kx                           ' failed: %s' % (ext.name, why), level=3)
     5         kx             assert not self.inplace
     5         kx             basename, tail = os.path.splitext(ext_filename)
     5         kx             newname = basename + "_failed" + tail
     5         kx             if os.path.exists(newname):
     5         kx                 os.remove(newname)
     5         kx             os.rename(ext_filename, newname)
     5         kx 
     5         kx             # XXX -- This relies on a Vile HACK in
     5         kx             # distutils.command.build_ext.build_extension().  The
     5         kx             # _built_objects attribute is stored there strictly for
     5         kx             # use here.
     5         kx             # If there is a failure, _built_objects may not be there,
     5         kx             # so catch the AttributeError and move on.
     5         kx             try:
     5         kx                 for filename in self._built_objects:
     5         kx                     os.remove(filename)
     5         kx             except AttributeError:
     5         kx                 self.announce('unable to remove files (ignored)')
     5         kx         except:
     5         kx             exc_type, why, tb = sys.exc_info()
     5         kx             self.announce('*** WARNING: importing extension "%s" '
     5         kx                           'failed with %s: %s' % (ext.name, exc_type, why),
     5         kx                           level=3)
     5         kx             self.failed.append(ext.name)
     5         kx 
     5         kx     def add_multiarch_paths(self):
     5         kx         # Debian/Ubuntu multiarch support.
     5         kx         # https://wiki.ubuntu.com/MultiarchSpec
     5         kx         cc = sysconfig.get_config_var('CC')
     5         kx         tmpfile = os.path.join(self.build_temp, 'multiarch')
     5         kx         if not os.path.exists(self.build_temp):
     5         kx             os.makedirs(self.build_temp)
     5         kx         ret = os.system(
     5         kx             '%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile))
     5         kx         multiarch_path_component = ''
     5         kx         try:
     5         kx             if ret >> 8 == 0:
     5         kx                 with open(tmpfile) as fp:
     5         kx                     multiarch_path_component = fp.readline().strip()
     5         kx         finally:
     5         kx             os.unlink(tmpfile)
     5         kx 
     5         kx         if multiarch_path_component != '':
     5         kx             add_dir_to_list(self.compiler.library_dirs,
     5         kx                             '/usr/lib/' + multiarch_path_component)
     5         kx             add_dir_to_list(self.compiler.include_dirs,
     5         kx                             '/usr/include/' + multiarch_path_component)
     5         kx             return
     5         kx 
     5         kx         if not find_executable('dpkg-architecture'):
     5         kx             return
     5         kx         opt = ''
     5         kx         if cross_compiling:
     5         kx             opt = '-t' + sysconfig.get_config_var('HOST_GNU_TYPE')
     5         kx         tmpfile = os.path.join(self.build_temp, 'multiarch')
     5         kx         if not os.path.exists(self.build_temp):
     5         kx             os.makedirs(self.build_temp)
     5         kx         ret = os.system(
     5         kx             'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null' %
     5         kx             (opt, tmpfile))
     5         kx         try:
     5         kx             if ret >> 8 == 0:
     5         kx                 with open(tmpfile) as fp:
     5         kx                     multiarch_path_component = fp.readline().strip()
     5         kx                 add_dir_to_list(self.compiler.library_dirs,
     5         kx                                 '/usr/lib/' + multiarch_path_component)
     5         kx                 add_dir_to_list(self.compiler.include_dirs,
     5         kx                                 '/usr/include/' + multiarch_path_component)
     5         kx         finally:
     5         kx             os.unlink(tmpfile)
     5         kx 
     5         kx     def add_gcc_paths(self):
     5         kx         gcc = sysconfig.get_config_var('CC')
     5         kx         tmpfile = os.path.join(self.build_temp, 'gccpaths')
     5         kx         if not os.path.exists(self.build_temp):
     5         kx             os.makedirs(self.build_temp)
     5         kx         ret = os.system('%s -E -v - </dev/null 2>%s 1>/dev/null' % (gcc, tmpfile))
     5         kx         is_gcc = False
     5         kx         in_incdirs = False
     5         kx         inc_dirs = []
     5         kx         lib_dirs = []
     5         kx         try:
     5         kx             if ret >> 8 == 0:
     5         kx                 with open(tmpfile) as fp:
     5         kx                     for line in fp.readlines():
     5         kx                         if line.startswith("gcc version"):
     5         kx                             is_gcc = True
     5         kx                         elif line.startswith("#include <...>"):
     5         kx                             in_incdirs = True
     5         kx                         elif line.startswith("End of search list"):
     5         kx                             in_incdirs = False
     5         kx                         elif is_gcc and line.startswith("LIBRARY_PATH"):
     5         kx                             for d in line.strip().split("=")[1].split(":"):
     5         kx                                 d = os.path.normpath(d)
     5         kx                                 if '/gcc/' not in d:
     5         kx                                     add_dir_to_list(self.compiler.library_dirs,
     5         kx                                                     d)
     5         kx                         elif is_gcc and in_incdirs and '/gcc/' not in line:
     5         kx                             add_dir_to_list(self.compiler.include_dirs,
     5         kx                                             line.strip())
     5         kx         finally:
     5         kx             os.unlink(tmpfile)
     5         kx 
     5         kx     def detect_modules(self):
     5         kx         # Ensure that /usr/local is always used
     5         kx         if not cross_compiling:
     5         kx             add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib32')
     5         kx             add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
     5         kx         if cross_compiling:
     5         kx             self.add_gcc_paths()
     5         kx         self.add_multiarch_paths()
     5         kx 
     5         kx         # Add paths specified in the environment variables LDFLAGS and
     5         kx         # CPPFLAGS for header and library files.
     5         kx         # We must get the values from the Makefile and not the environment
     5         kx         # directly since an inconsistently reproducible issue comes up where
     5         kx         # the environment variable is not set even though the value were passed
     5         kx         # into configure and stored in the Makefile (issue found on OS X 10.3).
     5         kx         for env_var, arg_name, dir_list in (
     5         kx                 ('LDFLAGS', '-R', self.compiler.runtime_library_dirs),
     5         kx                 ('LDFLAGS', '-L', self.compiler.library_dirs),
     5         kx                 ('CPPFLAGS', '-I', self.compiler.include_dirs)):
     5         kx             env_val = sysconfig.get_config_var(env_var)
     5         kx             if env_val:
     5         kx                 # To prevent optparse from raising an exception about any
     5         kx                 # options in env_val that it doesn't know about we strip out
     5         kx                 # all double dashes and any dashes followed by a character
     5         kx                 # that is not for the option we are dealing with.
     5         kx                 #
     5         kx                 # Please note that order of the regex is important!  We must
     5         kx                 # strip out double-dashes first so that we don't end up with
     5         kx                 # substituting "--Long" to "-Long" and thus lead to "ong" being
     5         kx                 # used for a library directory.
     5         kx                 env_val = re.sub(r'(^|\s+)-(-|(?!%s))' % arg_name[1],
     5         kx                                  ' ', env_val)
     5         kx                 parser = optparse.OptionParser()
     5         kx                 # Make sure that allowing args interspersed with options is
     5         kx                 # allowed
     5         kx                 parser.allow_interspersed_args = True
     5         kx                 parser.error = lambda msg: None
     5         kx                 parser.add_option(arg_name, dest="dirs", action="append")
     5         kx                 options = parser.parse_args(env_val.split())[0]
     5         kx                 if options.dirs:
     5         kx                     for directory in reversed(options.dirs):
     5         kx                         add_dir_to_list(dir_list, directory)
     5         kx 
     5         kx         if os.path.normpath(sys.prefix) != '/usr' \
     5         kx                 and not sysconfig.get_config_var('PYTHONFRAMEWORK'):
     5         kx             # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework
     5         kx             # (PYTHONFRAMEWORK is set) to avoid # linking problems when
     5         kx             # building a framework with different architectures than
     5         kx             # the one that is currently installed (issue #7473)
     5         kx             add_dir_to_list(self.compiler.library_dirs,
     5         kx                             sysconfig.get_config_var("LIBDIR"))
     5         kx             add_dir_to_list(self.compiler.include_dirs,
     5         kx                             sysconfig.get_config_var("INCLUDEDIR"))
     5         kx 
     5         kx         try:
     5         kx             have_unicode = unicode
     5         kx         except NameError:
     5         kx             have_unicode = 0
     5         kx 
     5         kx         # lib_dirs and inc_dirs are used to search for files;
     5         kx         # if a file is found in one of those directories, it can
     5         kx         # be assumed that no additional -I,-L directives are needed.
     5         kx         inc_dirs = self.compiler.include_dirs[:]
     5         kx         lib_dirs = self.compiler.library_dirs[:]
     5         kx         if not cross_compiling:
     5         kx             for d in (
     5         kx                 '/usr/include',
     5         kx                 ):
     5         kx                 add_dir_to_list(inc_dirs, d)
     5         kx             for d in (
     5         kx                 '/lib64', '/usr/lib64',
     5         kx                 '/lib', '/usr/lib',
     5         kx                 ):
     5         kx                 add_dir_to_list(lib_dirs, d)
     5         kx         exts = []
     5         kx         missing = []
     5         kx 
     5         kx         config_h = sysconfig.get_config_h_filename()
     5         kx         config_h_vars = sysconfig.parse_config_h(open(config_h))
     5         kx 
     5         kx         srcdir = sysconfig.get_config_var('srcdir')
     5         kx 
     5         kx         # Check for AtheOS which has libraries in non-standard locations
     5         kx         if host_platform == 'atheos':
     5         kx             lib_dirs += ['/system/libs', '/atheos/autolnk/lib']
     5         kx             lib_dirs += os.getenv('LIBRARY_PATH', '').split(os.pathsep)
     5         kx             inc_dirs += ['/system/include', '/atheos/autolnk/include']
     5         kx             inc_dirs += os.getenv('C_INCLUDE_PATH', '').split(os.pathsep)
     5         kx 
     5         kx         # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
     5         kx         if host_platform in ['osf1', 'unixware7', 'openunix8']:
     5         kx             lib_dirs += ['/usr/ccs/lib']
     5         kx 
     5         kx         # HP-UX11iv3 keeps files in lib/hpux folders.
     5         kx         if host_platform == 'hp-ux11':
     5         kx             lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32']
     5         kx 
     5         kx         if host_platform == 'darwin':
     5         kx             # This should work on any unixy platform ;-)
     5         kx             # If the user has bothered specifying additional -I and -L flags
     5         kx             # in OPT and LDFLAGS we might as well use them here.
     5         kx             #   NOTE: using shlex.split would technically be more correct, but
     5         kx             # also gives a bootstrap problem. Let's hope nobody uses directories
     5         kx             # with whitespace in the name to store libraries.
     5         kx             cflags, ldflags = sysconfig.get_config_vars(
     5         kx                     'CFLAGS', 'LDFLAGS')
     5         kx             for item in cflags.split():
     5         kx                 if item.startswith('-I'):
     5         kx                     inc_dirs.append(item[2:])
     5         kx 
     5         kx             for item in ldflags.split():
     5         kx                 if item.startswith('-L'):
     5         kx                     lib_dirs.append(item[2:])
     5         kx 
     5         kx         # Check for MacOS X, which doesn't need libm.a at all
     5         kx         math_libs = ['m']
     5         kx         if host_platform in ['darwin', 'beos']:
     5         kx             math_libs = []
     5         kx 
     5         kx         # XXX Omitted modules: gl, pure, dl, SGI-specific modules
     5         kx 
     5         kx         #
     5         kx         # The following modules are all pretty straightforward, and compile
     5         kx         # on pretty much any POSIXish platform.
     5         kx         #
     5         kx 
     5         kx         # Some modules that are normally always on:
     5         kx         #exts.append( Extension('_weakref', ['_weakref.c']) )
     5         kx 
     5         kx         # array objects
     5         kx         exts.append( Extension('array', ['arraymodule.c']) )
     5         kx 
     5         kx         shared_math = 'Modules/_math.o'
     5         kx         # complex math library functions
     5         kx         exts.append( Extension('cmath', ['cmathmodule.c'],
     5         kx                                extra_objects=[shared_math],
     5         kx                                depends=['_math.h', shared_math],
     5         kx                                libraries=math_libs) )
     5         kx         # math library functions, e.g. sin()
     5         kx         exts.append( Extension('math',  ['mathmodule.c'],
     5         kx                                extra_objects=[shared_math],
     5         kx                                depends=['_math.h', shared_math],
     5         kx                                libraries=math_libs) )
     5         kx         # fast string operations implemented in C
     5         kx         exts.append( Extension('strop', ['stropmodule.c']) )
     5         kx         # time operations and variables
     5         kx         exts.append( Extension('time', ['timemodule.c'],
     5         kx                                libraries=math_libs) )
     5         kx         exts.append( Extension('datetime', ['datetimemodule.c', 'timemodule.c'],
     5         kx                                libraries=math_libs) )
     5         kx         # fast iterator tools implemented in C
     5         kx         exts.append( Extension("itertools", ["itertoolsmodule.c"]) )
     5         kx         # code that will be builtins in the future, but conflict with the
     5         kx         #  current builtins
     5         kx         exts.append( Extension('future_builtins', ['future_builtins.c']) )
     5         kx         # random number generator implemented in C
     5         kx         exts.append( Extension("_random", ["_randommodule.c"]) )
     5         kx         # high-performance collections
     5         kx         exts.append( Extension("_collections", ["_collectionsmodule.c"]) )
     5         kx         # bisect
     5         kx         exts.append( Extension("_bisect", ["_bisectmodule.c"]) )
     5         kx         # heapq
     5         kx         exts.append( Extension("_heapq", ["_heapqmodule.c"]) )
     5         kx         # operator.add() and similar goodies
     5         kx         exts.append( Extension('operator', ['operator.c']) )
     5         kx         # Python 3.1 _io library
     5         kx         exts.append( Extension("_io",
     5         kx             ["_io/bufferedio.c", "_io/bytesio.c", "_io/fileio.c",
     5         kx              "_io/iobase.c", "_io/_iomodule.c", "_io/stringio.c", "_io/textio.c"],
     5         kx              depends=["_io/_iomodule.h"], include_dirs=["Modules/_io"]))
     5         kx         # _functools
     5         kx         exts.append( Extension("_functools", ["_functoolsmodule.c"]) )
     5         kx         # _json speedups
     5         kx         exts.append( Extension("_json", ["_json.c"]) )
     5         kx         # Python C API test module
     5         kx         exts.append( Extension('_testcapi', ['_testcapimodule.c'],
     5         kx                                depends=['testcapi_long.h']) )
     5         kx         # profilers (_lsprof is for cProfile.py)
     5         kx         exts.append( Extension('_hotshot', ['_hotshot.c']) )
     5         kx         exts.append( Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']) )
     5         kx         # static Unicode character database
     5         kx         if have_unicode:
     5         kx             exts.append( Extension('unicodedata', ['unicodedata.c']) )
     5         kx         else:
     5         kx             missing.append('unicodedata')
     5         kx         # access to ISO C locale support
     5         kx         data = open('pyconfig.h').read()
     5         kx         m = re.search(r"#s*define\s+WITH_LIBINTL\s+1\s*", data)
     5         kx         if m is not None:
     5         kx             locale_libs = ['intl']
     5         kx         else:
     5         kx             locale_libs = []
     5         kx         if host_platform == 'darwin':
     5         kx             locale_extra_link_args = ['-framework', 'CoreFoundation']
     5         kx         else:
     5         kx             locale_extra_link_args = []
     5         kx 
     5         kx 
     5         kx         exts.append( Extension('_locale', ['_localemodule.c'],
     5         kx                                libraries=locale_libs,
     5         kx                                extra_link_args=locale_extra_link_args) )
     5         kx 
     5         kx         # Modules with some UNIX dependencies -- on by default:
     5         kx         # (If you have a really backward UNIX, select and socket may not be
     5         kx         # supported...)
     5         kx 
     5         kx         # fcntl(2) and ioctl(2)
     5         kx         libs = []
     5         kx         if (config_h_vars.get('FLOCK_NEEDS_LIBBSD', False)):
     5         kx             # May be necessary on AIX for flock function
     5         kx             libs = ['bsd']
     5         kx         exts.append( Extension('fcntl', ['fcntlmodule.c'], libraries=libs) )
     5         kx         # pwd(3)
     5         kx         exts.append( Extension('pwd', ['pwdmodule.c']) )
     5         kx         # grp(3)
     5         kx         exts.append( Extension('grp', ['grpmodule.c']) )
     5         kx         # spwd, shadow passwords
     5         kx         if (config_h_vars.get('HAVE_GETSPNAM', False) or
     5         kx                 config_h_vars.get('HAVE_GETSPENT', False)):
     5         kx             exts.append( Extension('spwd', ['spwdmodule.c']) )
     5         kx         else:
     5         kx             missing.append('spwd')
     5         kx 
     5         kx         # select(2); not on ancient System V
     5         kx         exts.append( Extension('select', ['selectmodule.c']) )
     5         kx 
     5         kx         # Fred Drake's interface to the Python parser
     5         kx         exts.append( Extension('parser', ['parsermodule.c']) )
     5         kx 
     5         kx         # cStringIO and cPickle
     5         kx         exts.append( Extension('cStringIO', ['cStringIO.c']) )
     5         kx         exts.append( Extension('cPickle', ['cPickle.c']) )
     5         kx 
     5         kx         # Memory-mapped files (also works on Win32).
     5         kx         if host_platform not in ['atheos']:
     5         kx             exts.append( Extension('mmap', ['mmapmodule.c']) )
     5         kx         else:
     5         kx             missing.append('mmap')
     5         kx 
     5         kx         # Lance Ellinghaus's syslog module
     5         kx         # syslog daemon interface
     5         kx         exts.append( Extension('syslog', ['syslogmodule.c']) )
     5         kx 
     5         kx         # George Neville-Neil's timing module:
     5         kx         # Deprecated in PEP 4 http://www.python.org/peps/pep-0004.html
     5         kx         # http://mail.python.org/pipermail/python-dev/2006-January/060023.html
     5         kx         #exts.append( Extension('timing', ['timingmodule.c']) )
     5         kx 
     5         kx         #
     5         kx         # Here ends the simple stuff.  From here on, modules need certain
     5         kx         # libraries, are platform-specific, or present other surprises.
     5         kx         #
     5         kx 
     5         kx         # Multimedia modules
     5         kx         # These don't work for 64-bit platforms!!!
     5         kx         # These represent audio samples or images as strings:
     5         kx 
     5         kx         # Operations on audio samples
     5         kx         # According to #993173, this one should actually work fine on
     5         kx         # 64-bit platforms.
     5         kx         exts.append( Extension('audioop', ['audioop.c']) )
     5         kx 
     5         kx         # Disabled on 64-bit platforms
     5         kx         if sys.maxsize != 9223372036854775807L:
     5         kx             # Operations on images
     5         kx             exts.append( Extension('imageop', ['imageop.c']) )
     5         kx         else:
     5         kx             missing.extend(['imageop'])
     5         kx 
     5         kx         # readline
     5         kx         do_readline = self.compiler.find_library_file(lib_dirs, 'readline')
     5         kx         readline_termcap_library = ""
     5         kx         curses_library = ""
     5         kx         # Determine if readline is already linked against curses or tinfo.
     5         kx         if do_readline and find_executable('ldd'):
     5         kx             fp = os.popen("ldd %s" % do_readline)
     5         kx             ldd_output = fp.readlines()
     5         kx             ret = fp.close()
     5         kx             if ret is None or ret >> 8 == 0:
     5         kx                 for ln in ldd_output:
     5         kx                     if 'curses' in ln:
     5         kx                         readline_termcap_library = re.sub(
     5         kx                             r'.*lib(n?cursesw?)\.so.*', r'\1', ln
     5         kx                         ).rstrip()
     5         kx                         break
     5         kx                     if 'tinfo' in ln: # termcap interface split out from ncurses
     5         kx                         readline_termcap_library = 'tinfo'
     5         kx                         break
     5         kx         # Issue 7384: If readline is already linked against curses,
     5         kx         # use the same library for the readline and curses modules.
     5         kx         if 'curses' in readline_termcap_library:
     5         kx             curses_library = readline_termcap_library
     5         kx         elif self.compiler.find_library_file(lib_dirs, 'ncursesw'):
     5         kx             curses_library = 'ncursesw'
     5         kx         elif self.compiler.find_library_file(lib_dirs, 'ncurses'):
     5         kx             curses_library = 'ncurses'
     5         kx         elif self.compiler.find_library_file(lib_dirs, 'curses'):
     5         kx             curses_library = 'curses'
     5         kx 
     5         kx         if host_platform == 'darwin':
     5         kx             os_release = int(os.uname()[2].split('.')[0])
     5         kx             dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
     5         kx             if (dep_target and
     5         kx                     (tuple(int(n) for n in dep_target.split('.')[0:2])
     5         kx                         < (10, 5) ) ):
     5         kx                 os_release = 8
     5         kx             if os_release < 9:
     5         kx                 # MacOSX 10.4 has a broken readline. Don't try to build
     5         kx                 # the readline module unless the user has installed a fixed
     5         kx                 # readline package
     5         kx                 if find_file('readline/rlconf.h', inc_dirs, []) is None:
     5         kx                     do_readline = False
     5         kx         if do_readline:
     5         kx             if host_platform == 'darwin' and os_release < 9:
     5         kx                 # In every directory on the search path search for a dynamic
     5         kx                 # library and then a static library, instead of first looking
     5         kx                 # for dynamic libraries on the entire path.
     5         kx                 # This way a statically linked custom readline gets picked up
     5         kx                 # before the (possibly broken) dynamic library in /usr/lib.
     5         kx                 readline_extra_link_args = ('-Wl,-search_paths_first',)
     5         kx             else:
     5         kx                 readline_extra_link_args = ()
     5         kx 
     5         kx             readline_libs = ['readline']
     5         kx             if readline_termcap_library:
     5         kx                 pass # Issue 7384: Already linked against curses or tinfo.
     5         kx             elif curses_library:
     5         kx                 readline_libs.append(curses_library)
     5         kx             elif self.compiler.find_library_file(lib_dirs +
     5         kx                                                      ['/usr/lib32/termcap'],
     5         kx                                                      'termcap'):
     5         kx                 readline_libs.append('termcap')
     5         kx             exts.append( Extension('readline', ['readline.c'],
     5         kx                                    library_dirs=['/usr/lib32/termcap'],
     5         kx                                    extra_link_args=readline_extra_link_args,
     5         kx                                    libraries=readline_libs) )
     5         kx         else:
     5         kx             missing.append('readline')
     5         kx 
     5         kx         # crypt module.
     5         kx 
     5         kx         if self.compiler.find_library_file(lib_dirs, 'crypt'):
     5         kx             libs = ['crypt']
     5         kx         else:
     5         kx             libs = []
     5         kx         exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
     5         kx 
     5         kx         # CSV files
     5         kx         exts.append( Extension('_csv', ['_csv.c']) )
     5         kx 
     5         kx         # socket(2)
     5         kx         exts.append( Extension('_socket', ['socketmodule.c', 'timemodule.c'],
     5         kx                                depends=['socketmodule.h'],
     5         kx                                libraries=math_libs) )
     5         kx         # Detect SSL support for the socket module (via _ssl)
     5         kx         search_for_ssl_incs_in = [
     5         kx                               '/usr/local/ssl/include',
     5         kx                               '/usr/contrib/ssl/include/'
     5         kx                              ]
     5         kx         ssl_incs = find_file('openssl/ssl.h', inc_dirs,
     5         kx                              search_for_ssl_incs_in
     5         kx                              )
     5         kx         if ssl_incs is not None:
     5         kx             krb5_h = find_file('krb5.h', inc_dirs,
     5         kx                                ['/usr/kerberos/include'])
     5         kx             if krb5_h:
     5         kx                 ssl_incs += krb5_h
     5         kx         ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
     5         kx                                      ['/usr/local/ssl/lib32',
     5         kx                                       '/usr/contrib/ssl/lib32/'
     5         kx                                      ] )
     5         kx 
     5         kx         if (ssl_incs is not None and
     5         kx             ssl_libs is not None):
     5         kx             exts.append( Extension('_ssl', ['_ssl.c'],
     5         kx                                    include_dirs = ssl_incs,
     5         kx                                    library_dirs = ssl_libs,
     5         kx                                    libraries = ['ssl', 'crypto'],
     5         kx                                    depends = ['socketmodule.h']), )
     5         kx         else:
     5         kx             missing.append('_ssl')
     5         kx 
     5         kx         # find out which version of OpenSSL we have
     5         kx         openssl_ver = 0
     5         kx         openssl_ver_re = re.compile(
     5         kx             '^\s*#\s*define\s+OPENSSL_VERSION_NUMBER\s+(0x[0-9a-fA-F]+)' )
     5         kx 
     5         kx         # look for the openssl version header on the compiler search path.
     5         kx         opensslv_h = find_file('openssl/opensslv.h', [],
     5         kx                 inc_dirs + search_for_ssl_incs_in)
     5         kx         if opensslv_h:
     5         kx             name = os.path.join(opensslv_h[0], 'openssl/opensslv.h')
     5         kx             if host_platform == 'darwin' and is_macosx_sdk_path(name):
     5         kx                 name = os.path.join(macosx_sdk_root(), name[1:])
     5         kx             try:
     5         kx                 incfile = open(name, 'r')
     5         kx                 for line in incfile:
     5         kx                     m = openssl_ver_re.match(line)
     5         kx                     if m:
     5         kx                         openssl_ver = eval(m.group(1))
     5         kx             except IOError, msg:
     5         kx                 print "IOError while reading opensshv.h:", msg
     5         kx                 pass
     5         kx 
     5         kx         min_openssl_ver = 0x00907000
     5         kx         have_any_openssl = ssl_incs is not None and ssl_libs is not None
     5         kx         have_usable_openssl = (have_any_openssl and
     5         kx                                openssl_ver >= min_openssl_ver)
     5         kx 
     5         kx         if have_any_openssl:
     5         kx             if have_usable_openssl:
     5         kx                 # The _hashlib module wraps optimized implementations
     5         kx                 # of hash functions from the OpenSSL library.
     5         kx                 exts.append( Extension('_hashlib', ['_hashopenssl.c'],
     5         kx                                        include_dirs = ssl_incs,
     5         kx                                        library_dirs = ssl_libs,
     5         kx                                        libraries = ['ssl', 'crypto']) )
     5         kx             else:
     5         kx                 print ("warning: openssl 0x%08x is too old for _hashlib" %
     5         kx                        openssl_ver)
     5         kx                 missing.append('_hashlib')
     5         kx         if COMPILED_WITH_PYDEBUG or not have_usable_openssl:
     5         kx             # The _sha module implements the SHA1 hash algorithm.
     5         kx             exts.append( Extension('_sha', ['shamodule.c']) )
     5         kx             # The _md5 module implements the RSA Data Security, Inc. MD5
     5         kx             # Message-Digest Algorithm, described in RFC 1321.  The
     5         kx             # necessary files md5.c and md5.h are included here.
     5         kx             exts.append( Extension('_md5',
     5         kx                             sources = ['md5module.c', 'md5.c'],
     5         kx                             depends = ['md5.h']) )
     5         kx 
     5         kx         min_sha2_openssl_ver = 0x00908000
     5         kx         if COMPILED_WITH_PYDEBUG or openssl_ver < min_sha2_openssl_ver:
     5         kx             # OpenSSL doesn't do these until 0.9.8 so we'll bring our own hash
     5         kx             exts.append( Extension('_sha256', ['sha256module.c']) )
     5         kx             exts.append( Extension('_sha512', ['sha512module.c']) )
     5         kx 
     5         kx         # Modules that provide persistent dictionary-like semantics.  You will
     5         kx         # probably want to arrange for at least one of them to be available on
     5         kx         # your machine, though none are defined by default because of library
     5         kx         # dependencies.  The Python module anydbm.py provides an
     5         kx         # implementation independent wrapper for these; dumbdbm.py provides
     5         kx         # similar functionality (but slower of course) implemented in Python.
     5         kx 
     5         kx         # Sleepycat^WOracle Berkeley DB interface.
     5         kx         #  http://www.oracle.com/database/berkeley-db/db/index.html
     5         kx         #
     5         kx         # This requires the Sleepycat^WOracle DB code. The supported versions
     5         kx         # are set below.  Visit the URL above to download
     5         kx         # a release.  Most open source OSes come with one or more
     5         kx         # versions of BerkeleyDB already installed.
     5         kx 
     5         kx         max_db_ver = (5, 3)
     5         kx         min_db_ver = (4, 3)
     5         kx         db_setup_debug = False   # verbose debug prints from this script?
     5         kx 
     5         kx         def allow_db_ver(db_ver):
     5         kx             """Returns a boolean if the given BerkeleyDB version is acceptable.
     5         kx 
     5         kx             Args:
     5         kx               db_ver: A tuple of the version to verify.
     5         kx             """
     5         kx             if not (min_db_ver <= db_ver <= max_db_ver):
     5         kx                 return False
     5         kx             # Use this function to filter out known bad configurations.
     5         kx             if (4, 6) == db_ver[:2]:
     5         kx                 # BerkeleyDB 4.6.x is not stable on many architectures.
     5         kx                 arch = platform_machine()
     5         kx                 if arch not in ('i386', 'i486', 'i586', 'i686',
     5         kx                                 'x86_64', 'ia64'):
     5         kx                     return False
     5         kx             return True
     5         kx 
     5         kx         def gen_db_minor_ver_nums(major):
     5         kx             if major == 5:
     5         kx                 for x in range(max_db_ver[1]+1):
     5         kx                     if allow_db_ver((5, x)):
     5         kx                         yield x
     5         kx             elif major == 4:
     5         kx                 for x in range(9):
     5         kx                     if allow_db_ver((4, x)):
     5         kx                         yield x
     5         kx             elif major == 3:
     5         kx                 for x in (3,):
     5         kx                     if allow_db_ver((3, x)):
     5         kx                         yield x
     5         kx             else:
     5         kx                 raise ValueError("unknown major BerkeleyDB version", major)
     5         kx 
     5         kx         # construct a list of paths to look for the header file in on
     5         kx         # top of the normal inc_dirs.
     5         kx         db_inc_paths = [
     5         kx             '/usr/include/db4',
     5         kx             '/usr/local/include/db4',
     5         kx             '/opt/sfw/include/db4',
     5         kx             '/usr/include/db3',
     5         kx             '/usr/local/include/db3',
     5         kx             '/opt/sfw/include/db3',
     5         kx             # Fink defaults (http://fink.sourceforge.net/)
     5         kx             '/sw/include/db4',
     5         kx             '/sw/include/db3',
     5         kx         ]
     5         kx         # 4.x minor number specific paths
     5         kx         for x in gen_db_minor_ver_nums(4):
     5         kx             db_inc_paths.append('/usr/include/db4%d' % x)
     5         kx             db_inc_paths.append('/usr/include/db4.%d' % x)
     5         kx             db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x)
     5         kx             db_inc_paths.append('/usr/local/include/db4%d' % x)
     5         kx             db_inc_paths.append('/pkg/db-4.%d/include' % x)
     5         kx             db_inc_paths.append('/opt/db-4.%d/include' % x)
     5         kx             # MacPorts default (http://www.macports.org/)
     5         kx             db_inc_paths.append('/opt/local/include/db4%d' % x)
     5         kx         # 3.x minor number specific paths
     5         kx         for x in gen_db_minor_ver_nums(3):
     5         kx             db_inc_paths.append('/usr/include/db3%d' % x)
     5         kx             db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x)
     5         kx             db_inc_paths.append('/usr/local/include/db3%d' % x)
     5         kx             db_inc_paths.append('/pkg/db-3.%d/include' % x)
     5         kx             db_inc_paths.append('/opt/db-3.%d/include' % x)
     5         kx 
     5         kx         if cross_compiling:
     5         kx             db_inc_paths = []
     5         kx 
     5         kx         # Add some common subdirectories for Sleepycat DB to the list,
     5         kx         # based on the standard include directories. This way DB3/4 gets
     5         kx         # picked up when it is installed in a non-standard prefix and
     5         kx         # the user has added that prefix into inc_dirs.
     5         kx         std_variants = []
     5         kx         for dn in inc_dirs:
     5         kx             std_variants.append(os.path.join(dn, 'db3'))
     5         kx             std_variants.append(os.path.join(dn, 'db4'))
     5         kx             for x in gen_db_minor_ver_nums(4):
     5         kx                 std_variants.append(os.path.join(dn, "db4%d"%x))
     5         kx                 std_variants.append(os.path.join(dn, "db4.%d"%x))
     5         kx             for x in gen_db_minor_ver_nums(3):
     5         kx                 std_variants.append(os.path.join(dn, "db3%d"%x))
     5         kx                 std_variants.append(os.path.join(dn, "db3.%d"%x))
     5         kx 
     5         kx         db_inc_paths = std_variants + db_inc_paths
     5         kx         db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)]
     5         kx 
     5         kx         db_ver_inc_map = {}
     5         kx 
     5         kx         if host_platform == 'darwin':
     5         kx             sysroot = macosx_sdk_root()
     5         kx 
     5         kx         class db_found(Exception): pass
     5         kx         try:
     5         kx             # See whether there is a Sleepycat header in the standard
     5         kx             # search path.
     5         kx             for d in inc_dirs + db_inc_paths:
     5         kx                 f = os.path.join(d, "db.h")
     5         kx 
     5         kx                 if host_platform == 'darwin' and is_macosx_sdk_path(d):
     5         kx                     f = os.path.join(sysroot, d[1:], "db.h")
     5         kx 
     5         kx                 if db_setup_debug: print "db: looking for db.h in", f
     5         kx                 if os.path.exists(f):
     5         kx                     f = open(f).read()
     5         kx                     m = re.search(r"#define\WDB_VERSION_MAJOR\W(\d+)", f)
     5         kx                     if m:
     5         kx                         db_major = int(m.group(1))
     5         kx                         m = re.search(r"#define\WDB_VERSION_MINOR\W(\d+)", f)
     5         kx                         db_minor = int(m.group(1))
     5         kx                         db_ver = (db_major, db_minor)
     5         kx 
     5         kx                         # Avoid 4.6 prior to 4.6.21 due to a BerkeleyDB bug
     5         kx                         if db_ver == (4, 6):
     5         kx                             m = re.search(r"#define\WDB_VERSION_PATCH\W(\d+)", f)
     5         kx                             db_patch = int(m.group(1))
     5         kx                             if db_patch < 21:
     5         kx                                 print "db.h:", db_ver, "patch", db_patch,
     5         kx                                 print "being ignored (4.6.x must be >= 4.6.21)"
     5         kx                                 continue
     5         kx 
     5         kx                         if ( (db_ver not in db_ver_inc_map) and
     5         kx                             allow_db_ver(db_ver) ):
     5         kx                             # save the include directory with the db.h version
     5         kx                             # (first occurrence only)
     5         kx                             db_ver_inc_map[db_ver] = d
     5         kx                             if db_setup_debug:
     5         kx                                 print "db.h: found", db_ver, "in", d
     5         kx                         else:
     5         kx                             # we already found a header for this library version
     5         kx                             if db_setup_debug: print "db.h: ignoring", d
     5         kx                     else:
     5         kx                         # ignore this header, it didn't contain a version number
     5         kx                         if db_setup_debug:
     5         kx                             print "db.h: no version number version in", d
     5         kx 
     5         kx             db_found_vers = db_ver_inc_map.keys()
     5         kx             db_found_vers.sort()
     5         kx 
     5         kx             while db_found_vers:
     5         kx                 db_ver = db_found_vers.pop()
     5         kx                 db_incdir = db_ver_inc_map[db_ver]
     5         kx 
     5         kx                 # check lib directories parallel to the location of the header
     5         kx                 db_dirs_to_check = [
     5         kx                     db_incdir.replace("include", 'lib64'),
     5         kx                     db_incdir.replace("include", 'lib'),
     5         kx                 ]
     5         kx 
     5         kx                 if host_platform != 'darwin':
     5         kx                     db_dirs_to_check = filter(os.path.isdir, db_dirs_to_check)
     5         kx 
     5         kx                 else:
     5         kx                     # Same as other branch, but takes OSX SDK into account
     5         kx                     tmp = []
     5         kx                     for dn in db_dirs_to_check:
     5         kx                         if is_macosx_sdk_path(dn):
     5         kx                             if os.path.isdir(os.path.join(sysroot, dn[1:])):
     5         kx                                 tmp.append(dn)
     5         kx                         else:
     5         kx                             if os.path.isdir(dn):
     5         kx                                 tmp.append(dn)
     5         kx                     db_dirs_to_check = tmp
     5         kx 
     5         kx                 # Look for a version specific db-X.Y before an ambiguous dbX
     5         kx                 # XXX should we -ever- look for a dbX name?  Do any
     5         kx                 # systems really not name their library by version and
     5         kx                 # symlink to more general names?
     5         kx                 for dblib in (('db-%d.%d' % db_ver),
     5         kx                               ('db%d%d' % db_ver),
     5         kx                               ('db%d' % db_ver[0])):
     5         kx                     dblib_file = self.compiler.find_library_file(
     5         kx                                     db_dirs_to_check + lib_dirs, dblib )
     5         kx                     if dblib_file:
     5         kx                         dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ]
     5         kx                         raise db_found
     5         kx                     else:
     5         kx                         if db_setup_debug: print "db lib: ", dblib, "not found"
     5         kx 
     5         kx         except db_found:
     5         kx             if db_setup_debug:
     5         kx                 print "bsddb using BerkeleyDB lib:", db_ver, dblib
     5         kx                 print "bsddb lib dir:", dblib_dir, " inc dir:", db_incdir
     5         kx             db_incs = [db_incdir]
     5         kx             dblibs = [dblib]
     5         kx             # We add the runtime_library_dirs argument because the
     5         kx             # BerkeleyDB lib we're linking against often isn't in the
     5         kx             # system dynamic library search path.  This is usually
     5         kx             # correct and most trouble free, but may cause problems in
     5         kx             # some unusual system configurations (e.g. the directory
     5         kx             # is on an NFS server that goes away).
     5         kx             exts.append(Extension('_bsddb', ['_bsddb.c'],
     5         kx                                   depends = ['bsddb.h'],
     5         kx                                   library_dirs=dblib_dir,
     5         kx                                   runtime_library_dirs=dblib_dir,
     5         kx                                   include_dirs=db_incs,
     5         kx                                   libraries=dblibs))
     5         kx         else:
     5         kx             if db_setup_debug: print "db: no appropriate library found"
     5         kx             db_incs = None
     5         kx             dblibs = []
     5         kx             dblib_dir = None
     5         kx             missing.append('_bsddb')
     5         kx 
     5         kx         # The sqlite interface
     5         kx         sqlite_setup_debug = False   # verbose debug prints from this script?
     5         kx 
     5         kx         # We hunt for #define SQLITE_VERSION "n.n.n"
     5         kx         # We need to find >= sqlite version 3.0.8
     5         kx         sqlite_incdir = sqlite_libdir = None
     5         kx         sqlite_inc_paths = [ '/usr/include',
     5         kx                              '/usr/include/sqlite',
     5         kx                              '/usr/include/sqlite3',
     5         kx                              '/usr/local/include',
     5         kx                              '/usr/local/include/sqlite',
     5         kx                              '/usr/local/include/sqlite3',
     5         kx                            ]
     5         kx         if cross_compiling:
     5         kx             sqlite_inc_paths = []
     5         kx         MIN_SQLITE_VERSION_NUMBER = (3, 0, 8)
     5         kx         MIN_SQLITE_VERSION = ".".join([str(x)
     5         kx                                     for x in MIN_SQLITE_VERSION_NUMBER])
     5         kx 
     5         kx         # Scan the default include directories before the SQLite specific
     5         kx         # ones. This allows one to override the copy of sqlite on OSX,
     5         kx         # where /usr/include contains an old version of sqlite.
     5         kx         if host_platform == 'darwin':
     5         kx             sysroot = macosx_sdk_root()
     5         kx 
     5         kx         for d_ in inc_dirs + sqlite_inc_paths:
     5         kx             d = d_
     5         kx             if host_platform == 'darwin' and is_macosx_sdk_path(d):
     5         kx                 d = os.path.join(sysroot, d[1:])
     5         kx 
     5         kx             f = os.path.join(d, "sqlite3.h")
     5         kx             if os.path.exists(f):
     5         kx                 if sqlite_setup_debug: print "sqlite: found %s"%f
     5         kx                 incf = open(f).read()
     5         kx                 m = re.search(
     5         kx                     r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"([\d\.]*)"', incf)
     5         kx                 if m:
     5         kx                     sqlite_version = m.group(1)
     5         kx                     sqlite_version_tuple = tuple([int(x)
     5         kx                                         for x in sqlite_version.split(".")])
     5         kx                     if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER:
     5         kx                         # we win!
     5         kx                         if sqlite_setup_debug:
     5         kx                             print "%s/sqlite3.h: version %s"%(d, sqlite_version)
     5         kx                         sqlite_incdir = d
     5         kx                         break
     5         kx                     else:
     5         kx                         if sqlite_setup_debug:
     5         kx                             print "%s: version %d is too old, need >= %s"%(d,
     5         kx                                         sqlite_version, MIN_SQLITE_VERSION)
     5         kx                 elif sqlite_setup_debug:
     5         kx                     print "sqlite: %s had no SQLITE_VERSION"%(f,)
     5         kx 
     5         kx         if sqlite_incdir:
     5         kx             sqlite_dirs_to_check = [
     5         kx                 os.path.join(sqlite_incdir, '..', 'lib64'),
     5         kx                 os.path.join(sqlite_incdir, '..', 'lib'),
     5         kx                 os.path.join(sqlite_incdir, '..', '..', 'lib64'),
     5         kx                 os.path.join(sqlite_incdir, '..', '..', 'lib'),
     5         kx             ]
     5         kx             sqlite_libfile = self.compiler.find_library_file(
     5         kx                                 sqlite_dirs_to_check + lib_dirs, 'sqlite3')
     5         kx             if sqlite_libfile:
     5         kx                 sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))]
     5         kx 
     5         kx         if sqlite_incdir and sqlite_libdir:
     5         kx             sqlite_srcs = ['_sqlite/cache.c',
     5         kx                 '_sqlite/connection.c',
     5         kx                 '_sqlite/cursor.c',
     5         kx                 '_sqlite/microprotocols.c',
     5         kx                 '_sqlite/module.c',
     5         kx                 '_sqlite/prepare_protocol.c',
     5         kx                 '_sqlite/row.c',
     5         kx                 '_sqlite/statement.c',
     5         kx                 '_sqlite/util.c', ]
     5         kx 
     5         kx             sqlite_defines = []
     5         kx             if host_platform != "win32":
     5         kx                 sqlite_defines.append(('MODULE_NAME', '"sqlite3"'))
     5         kx             else:
     5         kx                 sqlite_defines.append(('MODULE_NAME', '\\"sqlite3\\"'))
     5         kx 
     5         kx             # Comment this out if you want the sqlite3 module to be able to load extensions.
     5         kx             sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))
     5         kx 
     5         kx             if host_platform == 'darwin':
     5         kx                 # In every directory on the search path search for a dynamic
     5         kx                 # library and then a static library, instead of first looking
     5         kx                 # for dynamic libraries on the entire path.
     5         kx                 # This way a statically linked custom sqlite gets picked up
     5         kx                 # before the dynamic library in /usr/lib.
     5         kx                 sqlite_extra_link_args = ('-Wl,-search_paths_first',)
     5         kx             else:
     5         kx                 sqlite_extra_link_args = ()
     5         kx 
     5         kx             exts.append(Extension('_sqlite3', sqlite_srcs,
     5         kx                                   define_macros=sqlite_defines,
     5         kx                                   include_dirs=["Modules/_sqlite",
     5         kx                                                 sqlite_incdir],
     5         kx                                   library_dirs=sqlite_libdir,
     5         kx                                   extra_link_args=sqlite_extra_link_args,
     5         kx                                   libraries=["sqlite3",]))
     5         kx         else:
     5         kx             missing.append('_sqlite3')
     5         kx 
     5         kx         # Look for Berkeley db 1.85.   Note that it is built as a different
     5         kx         # module name so it can be included even when later versions are
     5         kx         # available.  A very restrictive search is performed to avoid
     5         kx         # accidentally building this module with a later version of the
     5         kx         # underlying db library.  May BSD-ish Unixes incorporate db 1.85
     5         kx         # symbols into libc and place the include file in /usr/include.
     5         kx         #
     5         kx         # If the better bsddb library can be built (db_incs is defined)
     5         kx         # we do not build this one.  Otherwise this build will pick up
     5         kx         # the more recent berkeleydb's db.h file first in the include path
     5         kx         # when attempting to compile and it will fail.
     5         kx         f = "/usr/include/db.h"
     5         kx 
     5         kx         if host_platform == 'darwin':
     5         kx             if is_macosx_sdk_path(f):
     5         kx                 sysroot = macosx_sdk_root()
     5         kx                 f = os.path.join(sysroot, f[1:])
     5         kx 
     5         kx         if os.path.exists(f) and not db_incs:
     5         kx             data = open(f).read()
     5         kx             m = re.search(r"#s*define\s+HASHVERSION\s+2\s*", data)
     5         kx             if m is not None:
     5         kx                 # bingo - old version used hash file format version 2
     5         kx                 ### XXX this should be fixed to not be platform-dependent
     5         kx                 ### but I don't have direct access to an osf1 platform and
     5         kx                 ### seemed to be muffing the search somehow
     5         kx                 libraries = host_platform == "osf1" and ['db'] or None
     5         kx                 if libraries is not None:
     5         kx                     exts.append(Extension('bsddb185', ['bsddbmodule.c'],
     5         kx                                           libraries=libraries))
     5         kx                 else:
     5         kx                     exts.append(Extension('bsddb185', ['bsddbmodule.c']))
     5         kx             else:
     5         kx                 missing.append('bsddb185')
     5         kx         else:
     5         kx             missing.append('bsddb185')
     5         kx 
     5         kx         dbm_order = ['gdbm']
     5         kx         # The standard Unix dbm module:
     5         kx         if host_platform not in ['cygwin']:
     5         kx             config_args = [arg.strip("'")
     5         kx                            for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
     5         kx             dbm_args = [arg for arg in config_args
     5         kx                         if arg.startswith('--with-dbmliborder=')]
     5         kx             if dbm_args:
     5         kx                 dbm_order = [arg.split('=')[-1] for arg in dbm_args][-1].split(":")
     5         kx             else:
     5         kx                 dbm_order = "ndbm:gdbm:bdb".split(":")
     5         kx             dbmext = None
     5         kx             for cand in dbm_order:
     5         kx                 if cand == "ndbm":
     5         kx                     if find_file("ndbm.h", inc_dirs, []) is not None:
     5         kx                         # Some systems have -lndbm, others have -lgdbm_compat,
     5         kx                         # others don't have either
     5         kx                         if self.compiler.find_library_file(lib_dirs,
     5         kx                                                                'ndbm'):
     5         kx                             ndbm_libs = ['ndbm']
     5         kx                         elif self.compiler.find_library_file(lib_dirs,
     5         kx                                                              'gdbm_compat'):
     5         kx                             ndbm_libs = ['gdbm_compat']
     5         kx                         else:
     5         kx                             ndbm_libs = []
     5         kx                         print "building dbm using ndbm"
     5         kx                         dbmext = Extension('dbm', ['dbmmodule.c'],
     5         kx                                            define_macros=[
     5         kx                                                ('HAVE_NDBM_H',None),
     5         kx                                                ],
     5         kx                                            libraries=ndbm_libs)
     5         kx                         break
     5         kx 
     5         kx                 elif cand == "gdbm":
     5         kx                     if self.compiler.find_library_file(lib_dirs, 'gdbm'):
     5         kx                         gdbm_libs = ['gdbm']
     5         kx                         if self.compiler.find_library_file(lib_dirs,
     5         kx                                                                'gdbm_compat'):
     5         kx                             gdbm_libs.append('gdbm_compat')
     5         kx                         if find_file("gdbm/ndbm.h", inc_dirs, []) is not None:
     5         kx                             print "building dbm using gdbm"
     5         kx                             dbmext = Extension(
     5         kx                                 'dbm', ['dbmmodule.c'],
     5         kx                                 define_macros=[
     5         kx                                     ('HAVE_GDBM_NDBM_H', None),
     5         kx                                     ],
     5         kx                                 libraries = gdbm_libs)
     5         kx                             break
     5         kx                         if find_file("gdbm-ndbm.h", inc_dirs, []) is not None:
     5         kx                             print "building dbm using gdbm"
     5         kx                             dbmext = Extension(
     5         kx                                 'dbm', ['dbmmodule.c'],
     5         kx                                 define_macros=[
     5         kx                                     ('HAVE_GDBM_DASH_NDBM_H', None),
     5         kx                                     ],
     5         kx                                 libraries = gdbm_libs)
     5         kx                             break
     5         kx                 elif cand == "bdb":
     5         kx                     if db_incs is not None:
     5         kx                         print "building dbm using bdb"
     5         kx                         dbmext = Extension('dbm', ['dbmmodule.c'],
     5         kx                                            library_dirs=dblib_dir,
     5         kx                                            runtime_library_dirs=dblib_dir,
     5         kx                                            include_dirs=db_incs,
     5         kx                                            define_macros=[
     5         kx                                                ('HAVE_BERKDB_H', None),
     5         kx                                                ('DB_DBM_HSEARCH', None),
     5         kx                                                ],
     5         kx                                            libraries=dblibs)
     5         kx                         break
     5         kx             if dbmext is not None:
     5         kx                 exts.append(dbmext)
     5         kx             else:
     5         kx                 missing.append('dbm')
     5         kx 
     5         kx         # Anthony Baxter's gdbm module.  GNU dbm(3) will require -lgdbm:
     5         kx         if ('gdbm' in dbm_order and
     5         kx             self.compiler.find_library_file(lib_dirs, 'gdbm')):
     5         kx             exts.append( Extension('gdbm', ['gdbmmodule.c'],
     5         kx                                    libraries = ['gdbm'] ) )
     5         kx         else:
     5         kx             missing.append('gdbm')
     5         kx 
     5         kx         # Unix-only modules
     5         kx         if host_platform not in ['win32']:
     5         kx             # Steen Lumholt's termios module
     5         kx             exts.append( Extension('termios', ['termios.c']) )
     5         kx             # Jeremy Hylton's rlimit interface
     5         kx             if host_platform not in ['atheos']:
     5         kx                 exts.append( Extension('resource', ['resource.c']) )
     5         kx             else:
     5         kx                 missing.append('resource')
     5         kx 
     5         kx             nis = self._detect_nis(inc_dirs, lib_dirs)
     5         kx             if nis is not None:
     5         kx                 exts.append(nis)
     5         kx             else:
     5         kx                 missing.append('nis')
     5         kx 
     5         kx         # Curses support, requiring the System V version of curses, often
     5         kx         # provided by the ncurses library.
     5         kx         panel_library = 'panel'
     5         kx         curses_incs = None
     5         kx         if curses_library.startswith('ncurses'):
     5         kx             if curses_library == 'ncursesw':
     5         kx                 # Bug 1464056: If _curses.so links with ncursesw,
     5         kx                 # _curses_panel.so must link with panelw.
     5         kx                 panel_library = 'panelw'
     5         kx             curses_libs = [curses_library]
     5         kx             curses_incs = find_file('curses.h', inc_dirs,
     5         kx                                     [os.path.join(d, 'ncursesw') for d in inc_dirs])
     5         kx             exts.append( Extension('_curses', ['_cursesmodule.c'],
     5         kx                                    include_dirs = curses_incs,
     5         kx                                    libraries = curses_libs) )
     5         kx         elif curses_library == 'curses' and host_platform != 'darwin':
     5         kx                 # OSX has an old Berkeley curses, not good enough for
     5         kx                 # the _curses module.
     5         kx             if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
     5         kx                 curses_libs = ['curses', 'terminfo']
     5         kx             elif (self.compiler.find_library_file(lib_dirs, 'termcap')):
     5         kx                 curses_libs = ['curses', 'termcap']
     5         kx             else:
     5         kx                 curses_libs = ['curses']
     5         kx 
     5         kx             exts.append( Extension('_curses', ['_cursesmodule.c'],
     5         kx                                    libraries = curses_libs) )
     5         kx         else:
     5         kx             missing.append('_curses')
     5         kx 
     5         kx         # If the curses module is enabled, check for the panel module
     5         kx         if (module_enabled(exts, '_curses') and
     5         kx             self.compiler.find_library_file(lib_dirs, panel_library)):
     5         kx             exts.append( Extension('_curses_panel', ['_curses_panel.c'],
     5         kx                                    include_dirs = curses_incs,
     5         kx                                    libraries = [panel_library] + curses_libs) )
     5         kx         else:
     5         kx             missing.append('_curses_panel')
     5         kx 
     5         kx         # Andrew Kuchling's zlib module.  Note that some versions of zlib
     5         kx         # 1.1.3 have security problems.  See CERT Advisory CA-2002-07:
     5         kx         # http://www.cert.org/advisories/CA-2002-07.html
     5         kx         #
     5         kx         # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to
     5         kx         # patch its zlib 1.1.3 package instead of upgrading to 1.1.4.  For
     5         kx         # now, we still accept 1.1.3, because we think it's difficult to
     5         kx         # exploit this in Python, and we'd rather make it RedHat's problem
     5         kx         # than our problem <wink>.
     5         kx         #
     5         kx         # You can upgrade zlib to version 1.1.4 yourself by going to
     5         kx         # http://www.gzip.org/zlib/
     5         kx         zlib_inc = find_file('zlib.h', [], inc_dirs)
     5         kx         have_zlib = False
     5         kx         if zlib_inc is not None:
     5         kx             zlib_h = zlib_inc[0] + '/zlib.h'
     5         kx             version = '"0.0.0"'
     5         kx             version_req = '"1.1.3"'
     5         kx             if host_platform == 'darwin' and is_macosx_sdk_path(zlib_h):
     5         kx                 zlib_h = os.path.join(macosx_sdk_root(), zlib_h[1:])
     5         kx             fp = open(zlib_h)
     5         kx             while 1:
     5         kx                 line = fp.readline()
     5         kx                 if not line:
     5         kx                     break
     5         kx                 if line.startswith('#define ZLIB_VERSION'):
     5         kx                     version = line.split()[2]
     5         kx                     break
     5         kx             if version >= version_req:
     5         kx                 if (self.compiler.find_library_file(lib_dirs, 'z')):
     5         kx                     if host_platform == "darwin":
     5         kx                         zlib_extra_link_args = ('-Wl,-search_paths_first',)
     5         kx                     else:
     5         kx                         zlib_extra_link_args = ()
     5         kx                     exts.append( Extension('zlib', ['zlibmodule.c'],
     5         kx                                            libraries = ['z'],
     5         kx                                            extra_link_args = zlib_extra_link_args))
     5         kx                     have_zlib = True
     5         kx                 else:
     5         kx                     missing.append('zlib')
     5         kx             else:
     5         kx                 missing.append('zlib')
     5         kx         else:
     5         kx             missing.append('zlib')
     5         kx 
     5         kx         # Helper module for various ascii-encoders.  Uses zlib for an optimized
     5         kx         # crc32 if we have it.  Otherwise binascii uses its own.
     5         kx         if have_zlib:
     5         kx             extra_compile_args = ['-DUSE_ZLIB_CRC32']
     5         kx             libraries = ['z']
     5         kx             extra_link_args = zlib_extra_link_args
     5         kx         else:
     5         kx             extra_compile_args = []
     5         kx             libraries = []
     5         kx             extra_link_args = []
     5         kx         exts.append( Extension('binascii', ['binascii.c'],
     5         kx                                extra_compile_args = extra_compile_args,
     5         kx                                libraries = libraries,
     5         kx                                extra_link_args = extra_link_args) )
     5         kx 
     5         kx         # Gustavo Niemeyer's bz2 module.
     5         kx         if (self.compiler.find_library_file(lib_dirs, 'bz2')):
     5         kx             if host_platform == "darwin":
     5         kx                 bz2_extra_link_args = ('-Wl,-search_paths_first',)
     5         kx             else:
     5         kx                 bz2_extra_link_args = ()
     5         kx             exts.append( Extension('bz2', ['bz2module.c'],
     5         kx                                    libraries = ['bz2'],
     5         kx                                    extra_link_args = bz2_extra_link_args) )
     5         kx         else:
     5         kx             missing.append('bz2')
     5         kx 
     5         kx         # Interface to the Expat XML parser
     5         kx         #
     5         kx         # Expat was written by James Clark and is now maintained by a group of
     5         kx         # developers on SourceForge; see www.libexpat.org for more information.
     5         kx         # The pyexpat module was written by Paul Prescod after a prototype by
     5         kx         # Jack Jansen.  The Expat source is included in Modules/expat/.  Usage
     5         kx         # of a system shared libexpat.so is possible with --with-system-expat
     5         kx         # configure option.
     5         kx         #
     5         kx         # More information on Expat can be found at www.libexpat.org.
     5         kx         #
     5         kx         if '--with-system-expat' in sysconfig.get_config_var("CONFIG_ARGS"):
     5         kx             expat_inc = []
     5         kx             define_macros = []
     5         kx             expat_lib = ['expat']
     5         kx             expat_sources = []
     5         kx             expat_depends = []
     5         kx         else:
     5         kx             expat_inc = [os.path.join(os.getcwd(), srcdir, 'Modules', 'expat')]
     5         kx             define_macros = [
     5         kx                 ('HAVE_EXPAT_CONFIG_H', '1'),
     5         kx                 # bpo-30947: Python uses best available entropy sources to
     5         kx                 # call XML_SetHashSalt(), expat entropy sources are not needed
     5         kx                 ('XML_POOR_ENTROPY', '1'),
     5         kx             ]
     5         kx             expat_lib = []
     5         kx             expat_sources = ['expat/xmlparse.c',
     5         kx                              'expat/xmlrole.c',
     5         kx                              'expat/xmltok.c']
     5         kx             expat_depends = ['expat/ascii.h',
     5         kx                              'expat/asciitab.h',
     5         kx                              'expat/expat.h',
     5         kx                              'expat/expat_config.h',
     5         kx                              'expat/expat_external.h',
     5         kx                              'expat/internal.h',
     5         kx                              'expat/latin1tab.h',
     5         kx                              'expat/utf8tab.h',
     5         kx                              'expat/xmlrole.h',
     5         kx                              'expat/xmltok.h',
     5         kx                              'expat/xmltok_impl.h'
     5         kx                              ]
     5         kx 
     5         kx         exts.append(Extension('pyexpat',
     5         kx                               define_macros = define_macros,
     5         kx                               include_dirs = expat_inc,
     5         kx                               libraries = expat_lib,
     5         kx                               sources = ['pyexpat.c'] + expat_sources,
     5         kx                               depends = expat_depends,
     5         kx                               ))
     5         kx 
     5         kx         # Fredrik Lundh's cElementTree module.  Note that this also
     5         kx         # uses expat (via the CAPI hook in pyexpat).
     5         kx 
     5         kx         if os.path.isfile(os.path.join(srcdir, 'Modules', '_elementtree.c')):
     5         kx             define_macros.append(('USE_PYEXPAT_CAPI', None))
     5         kx             exts.append(Extension('_elementtree',
     5         kx                                   define_macros = define_macros,
     5         kx                                   include_dirs = expat_inc,
     5         kx                                   libraries = expat_lib,
     5         kx                                   sources = ['_elementtree.c'],
     5         kx                                   depends = ['pyexpat.c'] + expat_sources +
     5         kx                                       expat_depends,
     5         kx                                   ))
     5         kx         else:
     5         kx             missing.append('_elementtree')
     5         kx 
     5         kx         # Hye-Shik Chang's CJKCodecs modules.
     5         kx         if have_unicode:
     5         kx             exts.append(Extension('_multibytecodec',
     5         kx                                   ['cjkcodecs/multibytecodec.c']))
     5         kx             for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'):
     5         kx                 exts.append(Extension('_codecs_%s' % loc,
     5         kx                                       ['cjkcodecs/_codecs_%s.c' % loc]))
     5         kx         else:
     5         kx             missing.append('_multibytecodec')
     5         kx             for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'):
     5         kx                 missing.append('_codecs_%s' % loc)
     5         kx 
     5         kx         # Dynamic loading module
     5         kx         if sys.maxint == 0x7fffffff:
     5         kx             # This requires sizeof(int) == sizeof(long) == sizeof(char*)
     5         kx             dl_inc = find_file('dlfcn.h', [], inc_dirs)
     5         kx             if (dl_inc is not None) and (host_platform not in ['atheos']):
     5         kx                 exts.append( Extension('dl', ['dlmodule.c']) )
     5         kx             else:
     5         kx                 missing.append('dl')
     5         kx         else:
     5         kx             missing.append('dl')
     5         kx 
     5         kx         # Thomas Heller's _ctypes module
     5         kx         self.detect_ctypes(inc_dirs, lib_dirs)
     5         kx 
     5         kx         # Richard Oudkerk's multiprocessing module
     5         kx         if host_platform == 'win32':             # Windows
     5         kx             macros = dict()
     5         kx             libraries = ['ws2_32']
     5         kx 
     5         kx         elif host_platform == 'darwin':          # Mac OSX
     5         kx             macros = dict()
     5         kx             libraries = []
     5         kx 
     5         kx         elif host_platform == 'cygwin':          # Cygwin
     5         kx             macros = dict()
     5         kx             libraries = []
     5         kx 
     5         kx         elif host_platform in ('freebsd4', 'freebsd5', 'freebsd6', 'freebsd7', 'freebsd8'):
     5         kx             # FreeBSD's P1003.1b semaphore support is very experimental
     5         kx             # and has many known problems. (as of June 2008)
     5         kx             macros = dict()
     5         kx             libraries = []
     5         kx 
     5         kx         elif host_platform.startswith('openbsd'):
     5         kx             macros = dict()
     5         kx             libraries = []
     5         kx 
     5         kx         elif host_platform.startswith('netbsd'):
     5         kx             macros = dict()
     5         kx             libraries = []
     5         kx 
     5         kx         else:                                   # Linux and other unices
     5         kx             macros = dict()
     5         kx             libraries = ['rt']
     5         kx 
     5         kx         if host_platform == 'win32':
     5         kx             multiprocessing_srcs = [ '_multiprocessing/multiprocessing.c',
     5         kx                                      '_multiprocessing/semaphore.c',
     5         kx                                      '_multiprocessing/pipe_connection.c',
     5         kx                                      '_multiprocessing/socket_connection.c',
     5         kx                                      '_multiprocessing/win32_functions.c'
     5         kx                                    ]
     5         kx 
     5         kx         else:
     5         kx             multiprocessing_srcs = [ '_multiprocessing/multiprocessing.c',
     5         kx                                      '_multiprocessing/socket_connection.c'
     5         kx                                    ]
     5         kx             if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not
     5         kx                 sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')):
     5         kx                 multiprocessing_srcs.append('_multiprocessing/semaphore.c')
     5         kx 
     5         kx         if sysconfig.get_config_var('WITH_THREAD'):
     5         kx             exts.append ( Extension('_multiprocessing', multiprocessing_srcs,
     5         kx                                     define_macros=macros.items(),
     5         kx                                     include_dirs=["Modules/_multiprocessing"]))
     5         kx         else:
     5         kx             missing.append('_multiprocessing')
     5         kx 
     5         kx         # End multiprocessing
     5         kx 
     5         kx 
     5         kx         # Platform-specific libraries
     5         kx         if host_platform == 'linux2':
     5         kx             # Linux-specific modules
     5         kx             exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
     5         kx         else:
     5         kx             missing.append('linuxaudiodev')
     5         kx 
     5         kx         if (host_platform in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6',
     5         kx                         'freebsd7', 'freebsd8')
     5         kx             or host_platform.startswith("gnukfreebsd")):
     5         kx             exts.append( Extension('ossaudiodev', ['ossaudiodev.c']) )
     5         kx         else:
     5         kx             missing.append('ossaudiodev')
     5         kx 
     5         kx         if host_platform == 'sunos5':
     5         kx             # SunOS specific modules
     5         kx             exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
     5         kx         else:
     5         kx             missing.append('sunaudiodev')
     5         kx 
     5         kx         if host_platform == 'darwin':
     5         kx             # _scproxy
     5         kx             exts.append(Extension("_scproxy", [os.path.join(srcdir, "Mac/Modules/_scproxy.c")],
     5         kx                 extra_link_args= [
     5         kx                     '-framework', 'SystemConfiguration',
     5         kx                     '-framework', 'CoreFoundation'
     5         kx                 ]))
     5         kx 
     5         kx 
     5         kx         if host_platform == 'darwin' and ("--disable-toolbox-glue" not in
     5         kx                 sysconfig.get_config_var("CONFIG_ARGS")):
     5         kx 
     5         kx             if int(os.uname()[2].split('.')[0]) >= 8:
     5         kx                 # We're on Mac OS X 10.4 or later, the compiler should
     5         kx                 # support '-Wno-deprecated-declarations'. This will
     5         kx                 # suppress deprecation warnings for the Carbon extensions,
     5         kx                 # these extensions wrap the Carbon APIs and even those
     5         kx                 # parts that are deprecated.
     5         kx                 carbon_extra_compile_args = ['-Wno-deprecated-declarations']
     5         kx             else:
     5         kx                 carbon_extra_compile_args = []
     5         kx 
     5         kx             # Mac OS X specific modules.
     5         kx             def macSrcExists(name1, name2=''):
     5         kx                 if not name1:
     5         kx                     return None
     5         kx                 names = (name1,)
     5         kx                 if name2:
     5         kx                     names = (name1, name2)
     5         kx                 path = os.path.join(srcdir, 'Mac', 'Modules', *names)
     5         kx                 return os.path.exists(path)
     5         kx 
     5         kx             def addMacExtension(name, kwds, extra_srcs=[]):
     5         kx                 dirname = ''
     5         kx                 if name[0] == '_':
     5         kx                     dirname = name[1:].lower()
     5         kx                 cname = name + '.c'
     5         kx                 cmodulename = name + 'module.c'
     5         kx                 # Check for NNN.c, NNNmodule.c, _nnn/NNN.c, _nnn/NNNmodule.c
     5         kx                 if macSrcExists(cname):
     5         kx                     srcs = [cname]
     5         kx                 elif macSrcExists(cmodulename):
     5         kx                     srcs = [cmodulename]
     5         kx                 elif macSrcExists(dirname, cname):
     5         kx                     # XXX(nnorwitz): If all the names ended with module, we
     5         kx                     # wouldn't need this condition.  ibcarbon is the only one.
     5         kx                     srcs = [os.path.join(dirname, cname)]
     5         kx                 elif macSrcExists(dirname, cmodulename):
     5         kx                     srcs = [os.path.join(dirname, cmodulename)]
     5         kx                 else:
     5         kx                     raise RuntimeError("%s not found" % name)
     5         kx 
     5         kx                 # Here's the whole point:  add the extension with sources
     5         kx                 exts.append(Extension(name, srcs + extra_srcs, **kwds))
     5         kx 
     5         kx             # Core Foundation
     5         kx             core_kwds = {'extra_compile_args': carbon_extra_compile_args,
     5         kx                          'extra_link_args': ['-framework', 'CoreFoundation'],
     5         kx                         }
     5         kx             addMacExtension('_CF', core_kwds, ['cf/pycfbridge.c'])
     5         kx             addMacExtension('autoGIL', core_kwds)
     5         kx 
     5         kx 
     5         kx 
     5         kx             # Carbon
     5         kx             carbon_kwds = {'extra_compile_args': carbon_extra_compile_args,
     5         kx                            'extra_link_args': ['-framework', 'Carbon'],
     5         kx                           }
     5         kx             CARBON_EXTS = ['ColorPicker', 'gestalt', 'MacOS', 'Nav',
     5         kx                            'OSATerminology', 'icglue',
     5         kx                            # All these are in subdirs
     5         kx                            '_AE', '_AH', '_App', '_CarbonEvt', '_Cm', '_Ctl',
     5         kx                            '_Dlg', '_Drag', '_Evt', '_File', '_Folder', '_Fm',
     5         kx                            '_Help', '_Icn', '_IBCarbon', '_List',
     5         kx                            '_Menu', '_Mlte', '_OSA', '_Res', '_Qd', '_Qdoffs',
     5         kx                            '_Scrap', '_Snd', '_TE',
     5         kx                           ]
     5         kx             for name in CARBON_EXTS:
     5         kx                 addMacExtension(name, carbon_kwds)
     5         kx 
     5         kx             # Workaround for a bug in the version of gcc shipped with Xcode 3.
     5         kx             # The _Win extension should build just like the other Carbon extensions, but
     5         kx             # this actually results in a hard crash of the linker.
     5         kx             #
     5         kx             if '-arch ppc64' in cflags and '-arch ppc' in cflags:
     5         kx                 win_kwds = {'extra_compile_args': carbon_extra_compile_args + ['-arch', 'i386', '-arch', 'ppc'],
     5         kx                                'extra_link_args': ['-framework', 'Carbon', '-arch', 'i386', '-arch', 'ppc'],
     5         kx                            }
     5         kx                 addMacExtension('_Win', win_kwds)
     5         kx             else:
     5         kx                 addMacExtension('_Win', carbon_kwds)
     5         kx 
     5         kx 
     5         kx             # Application Services & QuickTime
     5         kx             app_kwds = {'extra_compile_args': carbon_extra_compile_args,
     5         kx                         'extra_link_args': ['-framework','ApplicationServices'],
     5         kx                        }
     5         kx             addMacExtension('_Launch', app_kwds)
     5         kx             addMacExtension('_CG', app_kwds)
     5         kx 
     5         kx             exts.append( Extension('_Qt', ['qt/_Qtmodule.c'],
     5         kx                         extra_compile_args=carbon_extra_compile_args,
     5         kx                         extra_link_args=['-framework', 'QuickTime',
     5         kx                                      '-framework', 'Carbon']) )
     5         kx 
     5         kx 
     5         kx         self.extensions.extend(exts)
     5         kx 
     5         kx         # Call the method for detecting whether _tkinter can be compiled
     5         kx         self.detect_tkinter(inc_dirs, lib_dirs)
     5         kx 
     5         kx         if '_tkinter' not in [e.name for e in self.extensions]:
     5         kx             missing.append('_tkinter')
     5         kx 
     5         kx ##         # Uncomment these lines if you want to play with xxmodule.c
     5         kx ##         ext = Extension('xx', ['xxmodule.c'])
     5         kx ##         self.extensions.append(ext)
     5         kx 
     5         kx         return missing
     5         kx 
     5         kx     def detect_tkinter_explicitly(self):
     5         kx         # Build _tkinter using explicit locations for Tcl/Tk.
     5         kx         #
     5         kx         # This is enabled when both arguments are given to ./configure:
     5         kx         #
     5         kx         #     --with-tcltk-includes="-I/path/to/tclincludes \
     5         kx         #                            -I/path/to/tkincludes"
     5         kx         #     --with-tcltk-libs="-L/path/to/tcllibs -ltclm.n \
     5         kx         #                        -L/path/to/tklibs -ltkm.n"
     5         kx         #
     5         kx         # These values can also be specified or overridden via make:
     5         kx         #    make TCLTK_INCLUDES="..." TCLTK_LIBS="..."
     5         kx         #
     5         kx         # This can be useful for building and testing tkinter with multiple
     5         kx         # versions of Tcl/Tk.  Note that a build of Tk depends on a particular
     5         kx         # build of Tcl so you need to specify both arguments and use care when
     5         kx         # overriding.
     5         kx 
     5         kx         # The _TCLTK variables are created in the Makefile sharedmods target.
     5         kx         tcltk_includes = os.environ.get('_TCLTK_INCLUDES')
     5         kx         tcltk_libs = os.environ.get('_TCLTK_LIBS')
     5         kx         if not (tcltk_includes and tcltk_libs):
     5         kx             # Resume default configuration search.
     5         kx             return 0
     5         kx 
     5         kx         extra_compile_args = tcltk_includes.split()
     5         kx         extra_link_args = tcltk_libs.split()
     5         kx         ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
     5         kx                         define_macros=[('WITH_APPINIT', 1)],
     5         kx                         extra_compile_args = extra_compile_args,
     5         kx                         extra_link_args = extra_link_args,
     5         kx                         )
     5         kx         self.extensions.append(ext)
     5         kx         return 1
     5         kx 
     5         kx     def detect_tkinter_darwin(self, inc_dirs, lib_dirs):
     5         kx         # The _tkinter module, using frameworks. Since frameworks are quite
     5         kx         # different the UNIX search logic is not sharable.
     5         kx         from os.path import join, exists
     5         kx         framework_dirs = [
     5         kx             '/Library/Frameworks',
     5         kx             '/System/Library/Frameworks/',
     5         kx             join(os.getenv('HOME'), '/Library/Frameworks')
     5         kx         ]
     5         kx 
     5         kx         sysroot = macosx_sdk_root()
     5         kx 
     5         kx         # Find the directory that contains the Tcl.framework and Tk.framework
     5         kx         # bundles.
     5         kx         # XXX distutils should support -F!
     5         kx         for F in framework_dirs:
     5         kx             # both Tcl.framework and Tk.framework should be present
     5         kx 
     5         kx 
     5         kx             for fw in 'Tcl', 'Tk':
     5         kx                 if is_macosx_sdk_path(F):
     5         kx                     if not exists(join(sysroot, F[1:], fw + '.framework')):
     5         kx                         break
     5         kx                 else:
     5         kx                     if not exists(join(F, fw + '.framework')):
     5         kx                         break
     5         kx             else:
     5         kx                 # ok, F is now directory with both frameworks. Continure
     5         kx                 # building
     5         kx                 break
     5         kx         else:
     5         kx             # Tk and Tcl frameworks not found. Normal "unix" tkinter search
     5         kx             # will now resume.
     5         kx             return 0
     5         kx 
     5         kx         # For 8.4a2, we must add -I options that point inside the Tcl and Tk
     5         kx         # frameworks. In later release we should hopefully be able to pass
     5         kx         # the -F option to gcc, which specifies a framework lookup path.
     5         kx         #
     5         kx         include_dirs = [
     5         kx             join(F, fw + '.framework', H)
     5         kx             for fw in 'Tcl', 'Tk'
     5         kx             for H in 'Headers', 'Versions/Current/PrivateHeaders'
     5         kx         ]
     5         kx 
     5         kx         # For 8.4a2, the X11 headers are not included. Rather than include a
     5         kx         # complicated search, this is a hard-coded path. It could bail out
     5         kx         # if X11 libs are not found...
     5         kx         include_dirs.append('/usr/X11R6/include')
     5         kx         frameworks = ['-framework', 'Tcl', '-framework', 'Tk']
     5         kx 
     5         kx         # All existing framework builds of Tcl/Tk don't support 64-bit
     5         kx         # architectures.
     5         kx         cflags = sysconfig.get_config_vars('CFLAGS')[0]
     5         kx         archs = re.findall('-arch\s+(\w+)', cflags)
     5         kx 
     5         kx         if is_macosx_sdk_path(F):
     5         kx             fp = os.popen("file %s/Tk.framework/Tk | grep 'for architecture'"%(os.path.join(sysroot, F[1:]),))
     5         kx         else:
     5         kx             fp = os.popen("file %s/Tk.framework/Tk | grep 'for architecture'"%(F,))
     5         kx 
     5         kx         detected_archs = []
     5         kx         for ln in fp:
     5         kx             a = ln.split()[-1]
     5         kx             if a in archs:
     5         kx                 detected_archs.append(ln.split()[-1])
     5         kx         fp.close()
     5         kx 
     5         kx         for a in detected_archs:
     5         kx             frameworks.append('-arch')
     5         kx             frameworks.append(a)
     5         kx 
     5         kx         ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
     5         kx                         define_macros=[('WITH_APPINIT', 1)],
     5         kx                         include_dirs = include_dirs,
     5         kx                         libraries = [],
     5         kx                         extra_compile_args = frameworks[2:],
     5         kx                         extra_link_args = frameworks,
     5         kx                         )
     5         kx         self.extensions.append(ext)
     5         kx         return 1
     5         kx 
     5         kx     def detect_tkinter(self, inc_dirs, lib_dirs):
     5         kx         # The _tkinter module.
     5         kx 
     5         kx         # Check whether --with-tcltk-includes and --with-tcltk-libs were
     5         kx         # configured or passed into the make target.  If so, use these values
     5         kx         # to build tkinter and bypass the searches for Tcl and TK in standard
     5         kx         # locations.
     5         kx         if self.detect_tkinter_explicitly():
     5         kx             return
     5         kx 
     5         kx         # Rather than complicate the code below, detecting and building
     5         kx         # AquaTk is a separate method. Only one Tkinter will be built on
     5         kx         # Darwin - either AquaTk, if it is found, or X11 based Tk.
     5         kx         if (host_platform == 'darwin' and
     5         kx             self.detect_tkinter_darwin(inc_dirs, lib_dirs)):
     5         kx             return
     5         kx 
     5         kx         # Assume we haven't found any of the libraries or include files
     5         kx         # The versions with dots are used on Unix, and the versions without
     5         kx         # dots on Windows, for detection by cygwin.
     5         kx         tcllib = tklib = tcl_includes = tk_includes = None
     5         kx         for version in ['8.6', '86', '8.5', '85', '8.4', '84', '8.3', '83',
     5         kx                         '8.2', '82', '8.1', '81', '8.0', '80']:
     5         kx             tklib = self.compiler.find_library_file(lib_dirs,
     5         kx                                                         'tk' + version)
     5         kx             tcllib = self.compiler.find_library_file(lib_dirs,
     5         kx                                                          'tcl' + version)
     5         kx             if tklib and tcllib:
     5         kx                 # Exit the loop when we've found the Tcl/Tk libraries
     5         kx                 break
     5         kx 
     5         kx         # Now check for the header files
     5         kx         if tklib and tcllib:
     5         kx             # Check for the include files on Debian and {Free,Open}BSD, where
     5         kx             # they're put in /usr/include/{tcl,tk}X.Y
     5         kx             dotversion = version
     5         kx             if '.' not in dotversion and "bsd" in host_platform.lower():
     5         kx                 # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a,
     5         kx                 # but the include subdirs are named like .../include/tcl8.3.
     5         kx                 dotversion = dotversion[:-1] + '.' + dotversion[-1]
     5         kx             tcl_include_sub = []
     5         kx             tk_include_sub = []
     5         kx             for dir in inc_dirs:
     5         kx                 tcl_include_sub += [dir + os.sep + "tcl" + dotversion]
     5         kx                 tk_include_sub += [dir + os.sep + "tk" + dotversion]
     5         kx             tk_include_sub += tcl_include_sub
     5         kx             tcl_includes = find_file('tcl.h', inc_dirs, tcl_include_sub)
     5         kx             tk_includes = find_file('tk.h', inc_dirs, tk_include_sub)
     5         kx 
     5         kx         if (tcllib is None or tklib is None or
     5         kx             tcl_includes is None or tk_includes is None):
     5         kx             self.announce("INFO: Can't locate Tcl/Tk libs and/or headers", 2)
     5         kx             return
     5         kx 
     5         kx         # OK... everything seems to be present for Tcl/Tk.
     5         kx 
     5         kx         include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
     5         kx         for dir in tcl_includes + tk_includes:
     5         kx             if dir not in include_dirs:
     5         kx                 include_dirs.append(dir)
     5         kx 
     5         kx         # Check for various platform-specific directories
     5         kx         if host_platform == 'sunos5':
     5         kx             include_dirs.append('/usr/openwin/include')
     5         kx             added_lib_dirs.append('/usr/openwin/lib')
     5         kx         elif os.path.exists('/usr/X11R6/include'):
     5         kx             include_dirs.append('/usr/X11R6/include')
     5         kx             added_lib_dirs.append('/usr/X11R6/lib64')
     5         kx             added_lib_dirs.append('/usr/X11R6/lib')
     5         kx         elif os.path.exists('/usr/X11R5/include'):
     5         kx             include_dirs.append('/usr/X11R5/include')
     5         kx             added_lib_dirs.append('/usr/X11R5/lib')
     5         kx         else:
     5         kx             # Assume default location for X11
     5         kx             include_dirs.append('/usr/X11/include')
     5         kx             added_lib_dirs.append('/usr/X11/lib')
     5         kx 
     5         kx         # If Cygwin, then verify that X is installed before proceeding
     5         kx         if host_platform == 'cygwin':
     5         kx             x11_inc = find_file('X11/Xlib.h', [], include_dirs)
     5         kx             if x11_inc is None:
     5         kx                 return
     5         kx 
     5         kx         # Check for BLT extension
     5         kx         if self.compiler.find_library_file(lib_dirs + added_lib_dirs,
     5         kx                                                'BLT8.0'):
     5         kx             defs.append( ('WITH_BLT', 1) )
     5         kx             libs.append('BLT8.0')
     5         kx         elif self.compiler.find_library_file(lib_dirs + added_lib_dirs,
     5         kx                                                 'BLT'):
     5         kx             defs.append( ('WITH_BLT', 1) )
     5         kx             libs.append('BLT')
     5         kx 
     5         kx         # Add the Tcl/Tk libraries
     5         kx         libs.append('tk'+ version)
     5         kx         libs.append('tcl'+ version)
     5         kx 
     5         kx         if host_platform in ['aix3', 'aix4']:
     5         kx             libs.append('ld')
     5         kx 
     5         kx         # Finally, link with the X11 libraries (not appropriate on cygwin)
     5         kx         if host_platform != "cygwin":
     5         kx             libs.append('X11')
     5         kx 
     5         kx         ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
     5         kx                         define_macros=[('WITH_APPINIT', 1)] + defs,
     5         kx                         include_dirs = include_dirs,
     5         kx                         libraries = libs,
     5         kx                         library_dirs = added_lib_dirs,
     5         kx                         )
     5         kx         self.extensions.append(ext)
     5         kx 
     5         kx         # XXX handle these, but how to detect?
     5         kx         # *** Uncomment and edit for PIL (TkImaging) extension only:
     5         kx         #       -DWITH_PIL -I../Extensions/Imaging/libImaging  tkImaging.c \
     5         kx         # *** Uncomment and edit for TOGL extension only:
     5         kx         #       -DWITH_TOGL togl.c \
     5         kx         # *** Uncomment these for TOGL extension only:
     5         kx         #       -lGL -lGLU -lXext -lXmu \
     5         kx 
     5         kx     def configure_ctypes_darwin(self, ext):
     5         kx         # Darwin (OS X) uses preconfigured files, in
     5         kx         # the Modules/_ctypes/libffi_osx directory.
     5         kx         srcdir = sysconfig.get_config_var('srcdir')
     5         kx         ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules',
     5         kx                                                   '_ctypes', 'libffi_osx'))
     5         kx         sources = [os.path.join(ffi_srcdir, p)
     5         kx                    for p in ['ffi.c',
     5         kx                              'x86/darwin64.S',
     5         kx                              'x86/x86-darwin.S',
     5         kx                              'x86/x86-ffi_darwin.c',
     5         kx                              'x86/x86-ffi64.c',
     5         kx                              'powerpc/ppc-darwin.S',
     5         kx                              'powerpc/ppc-darwin_closure.S',
     5         kx                              'powerpc/ppc-ffi_darwin.c',
     5         kx                              'powerpc/ppc64-darwin_closure.S',
     5         kx                              ]]
     5         kx 
     5         kx         # Add .S (preprocessed assembly) to C compiler source extensions.
     5         kx         self.compiler.src_extensions.append('.S')
     5         kx 
     5         kx         include_dirs = [os.path.join(ffi_srcdir, 'include'),
     5         kx                         os.path.join(ffi_srcdir, 'powerpc')]
     5         kx         ext.include_dirs.extend(include_dirs)
     5         kx         ext.sources.extend(sources)
     5         kx         return True
     5         kx 
     5         kx     def configure_ctypes(self, ext):
     5         kx         if not self.use_system_libffi:
     5         kx             if host_platform == 'darwin':
     5         kx                 return self.configure_ctypes_darwin(ext)
     5         kx 
     5         kx             srcdir = sysconfig.get_config_var('srcdir')
     5         kx             ffi_builddir = os.path.join(self.build_temp, 'libffi')
     5         kx             ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules',
     5         kx                                          '_ctypes', 'libffi'))
     5         kx             ffi_configfile = os.path.join(ffi_builddir, 'fficonfig.py')
     5         kx 
     5         kx             from distutils.dep_util import newer_group
     5         kx 
     5         kx             config_sources = [os.path.join(ffi_srcdir, fname)
     5         kx                               for fname in os.listdir(ffi_srcdir)
     5         kx                               if os.path.isfile(os.path.join(ffi_srcdir, fname))]
     5         kx             if self.force or newer_group(config_sources,
     5         kx                                          ffi_configfile):
     5         kx                 from distutils.dir_util import mkpath
     5         kx                 mkpath(ffi_builddir)
     5         kx                 config_args = [arg for arg in sysconfig.get_config_var("CONFIG_ARGS").split()
     5         kx                                if (('--host=' in arg) or ('--build=' in arg))]
     5         kx                 if not self.verbose:
     5         kx                     config_args.append("-q")
     5         kx 
     5         kx                 # Pass empty CFLAGS because we'll just append the resulting
     5         kx                 # CFLAGS to Python's; -g or -O2 is to be avoided.
     5         kx                 cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \
     5         kx                       % (ffi_builddir, ffi_srcdir, " ".join(config_args))
     5         kx 
     5         kx                 res = os.system(cmd)
     5         kx                 if res or not os.path.exists(ffi_configfile):
     5         kx                     print "Failed to configure _ctypes module"
     5         kx                     return False
     5         kx 
     5         kx             fficonfig = {}
     5         kx             with open(ffi_configfile) as f:
     5         kx                 exec f in fficonfig
     5         kx 
     5         kx             # Add .S (preprocessed assembly) to C compiler source extensions.
     5         kx             self.compiler.src_extensions.append('.S')
     5         kx 
     5         kx             include_dirs = [os.path.join(ffi_builddir, 'include'),
     5         kx                             ffi_builddir,
     5         kx                             os.path.join(ffi_srcdir, 'src')]
     5         kx             extra_compile_args = fficonfig['ffi_cflags'].split()
     5         kx 
     5         kx             ext.sources.extend(os.path.join(ffi_srcdir, f) for f in
     5         kx                                fficonfig['ffi_sources'])
     5         kx             ext.include_dirs.extend(include_dirs)
     5         kx             ext.extra_compile_args.extend(extra_compile_args)
     5         kx         return True
     5         kx 
     5         kx     def detect_ctypes(self, inc_dirs, lib_dirs):
     5         kx         self.use_system_libffi = False
     5         kx         include_dirs = []
     5         kx         extra_compile_args = []
     5         kx         extra_link_args = []
     5         kx         sources = ['_ctypes/_ctypes.c',
     5         kx                    '_ctypes/callbacks.c',
     5         kx                    '_ctypes/callproc.c',
     5         kx                    '_ctypes/stgdict.c',
     5         kx                    '_ctypes/cfield.c']
     5         kx         depends = ['_ctypes/ctypes.h']
     5         kx 
     5         kx         if host_platform == 'darwin':
     5         kx             sources.append('_ctypes/malloc_closure.c')
     5         kx             sources.append('_ctypes/darwin/dlfcn_simple.c')
     5         kx             extra_compile_args.append('-DMACOSX')
     5         kx             include_dirs.append('_ctypes/darwin')
     5         kx # XXX Is this still needed?
     5         kx ##            extra_link_args.extend(['-read_only_relocs', 'warning'])
     5         kx 
     5         kx         elif host_platform == 'sunos5':
     5         kx             # XXX This shouldn't be necessary; it appears that some
     5         kx             # of the assembler code is non-PIC (i.e. it has relocations
     5         kx             # when it shouldn't. The proper fix would be to rewrite
     5         kx             # the assembler code to be PIC.
     5         kx             # This only works with GCC; the Sun compiler likely refuses
     5         kx             # this option. If you want to compile ctypes with the Sun
     5         kx             # compiler, please research a proper solution, instead of
     5         kx             # finding some -z option for the Sun compiler.
     5         kx             extra_link_args.append('-mimpure-text')
     5         kx 
     5         kx         elif host_platform.startswith('hp-ux'):
     5         kx             extra_link_args.append('-fPIC')
     5         kx 
     5         kx         ext = Extension('_ctypes',
     5         kx                         include_dirs=include_dirs,
     5         kx                         extra_compile_args=extra_compile_args,
     5         kx                         extra_link_args=extra_link_args,
     5         kx                         libraries=[],
     5         kx                         sources=sources,
     5         kx                         depends=depends)
     5         kx         ext_test = Extension('_ctypes_test',
     5         kx                              sources=['_ctypes/_ctypes_test.c'])
     5         kx         self.extensions.extend([ext, ext_test])
     5         kx 
     5         kx         if not '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS"):
     5         kx             return
     5         kx 
     5         kx         if host_platform == 'darwin':
     5         kx             # OS X 10.5 comes with libffi.dylib; the include files are
     5         kx             # in /usr/include/ffi
     5         kx             inc_dirs.append('/usr/include/ffi')
     5         kx 
     5         kx         ffi_inc = [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")]
     5         kx         if not ffi_inc or ffi_inc[0] == '':
     5         kx             ffi_inc = find_file('ffi.h', [], inc_dirs)
     5         kx         if ffi_inc is not None:
     5         kx             ffi_h = ffi_inc[0] + '/ffi.h'
     5         kx             with open(ffi_h) as f:
     5         kx                 for line in f:
     5         kx                     line = line.strip()
     5         kx                     if line.startswith(('#define LIBFFI_H',
     5         kx                                         '#define ffi_wrapper_h')):
     5         kx                         break
     5         kx                 else:
     5         kx                     ffi_inc = None
     5         kx                     print('Header file {} does not define LIBFFI_H or '
     5         kx                           'ffi_wrapper_h'.format(ffi_h))
     5         kx         ffi_lib = None
     5         kx         if ffi_inc is not None:
     5         kx             for lib_name in ('ffi_convenience', 'ffi_pic', 'ffi'):
     5         kx                 if (self.compiler.find_library_file(lib_dirs, lib_name)):
     5         kx                     ffi_lib = lib_name
     5         kx                     break
     5         kx 
     5         kx         if ffi_inc and ffi_lib:
     5         kx             ext.include_dirs.extend(ffi_inc)
     5         kx             ext.libraries.append(ffi_lib)
     5         kx             self.use_system_libffi = True
     5         kx 
     5         kx         if sysconfig.get_config_var('HAVE_LIBDL'):
     5         kx             # for dlopen, see bpo-32647
     5         kx             ext.libraries.append('dl')
     5         kx 
     5         kx     def _detect_nis(self, inc_dirs, lib_dirs):
     5         kx         if host_platform in {'win32', 'cygwin', 'qnx6'}:
     5         kx             return None
     5         kx 
     5         kx         libs = []
     5         kx         library_dirs = []
     5         kx         includes_dirs = []
     5         kx 
     5         kx         # bpo-32521: glibc has deprecated Sun RPC for some time. Fedora 28
     5         kx         # moved headers and libraries to libtirpc and libnsl. The headers
     5         kx         # are in tircp and nsl sub directories.
     5         kx         rpcsvc_inc = find_file(
     5         kx             'rpcsvc/yp_prot.h', inc_dirs,
     5         kx             [os.path.join(inc_dir, 'nsl') for inc_dir in inc_dirs]
     5         kx         )
     5         kx         rpc_inc = find_file(
     5         kx             'rpc/rpc.h', inc_dirs,
     5         kx             [os.path.join(inc_dir, 'tirpc') for inc_dir in inc_dirs]
     5         kx         )
     5         kx         if rpcsvc_inc is None or rpc_inc is None:
     5         kx             # not found
     5         kx             return None
     5         kx         includes_dirs.extend(rpcsvc_inc)
     5         kx         includes_dirs.extend(rpc_inc)
     5         kx 
     5         kx         if self.compiler.find_library_file(lib_dirs, 'nsl'):
     5         kx             libs.append('nsl')
     5         kx         else:
     5         kx             # libnsl-devel: check for libnsl in nsl/ subdirectory
     5         kx             nsl_dirs = [os.path.join(lib_dir, 'nsl') for lib_dir in lib_dirs]
     5         kx             libnsl = self.compiler.find_library_file(nsl_dirs, 'nsl')
     5         kx             if libnsl is not None:
     5         kx                 library_dirs.append(os.path.dirname(libnsl))
     5         kx                 libs.append('nsl')
     5         kx 
     5         kx         if self.compiler.find_library_file(lib_dirs, 'tirpc'):
     5         kx             libs.append('tirpc')
     5         kx 
     5         kx         return Extension(
     5         kx             'nis', ['nismodule.c'],
     5         kx             libraries=libs,
     5         kx             library_dirs=library_dirs,
     5         kx             include_dirs=includes_dirs
     5         kx         )
     5         kx 
     5         kx 
     5         kx class PyBuildInstall(install):
     5         kx     # Suppress the warning about installation into the lib_dynload
     5         kx     # directory, which is not in sys.path when running Python during
     5         kx     # installation:
     5         kx     def initialize_options (self):
     5         kx         install.initialize_options(self)
     5         kx         self.warn_dir=0
     5         kx 
     5         kx class PyBuildInstallLib(install_lib):
     5         kx     # Do exactly what install_lib does but make sure correct access modes get
     5         kx     # set on installed directories and files. All installed files with get
     5         kx     # mode 644 unless they are a shared library in which case they will get
     5         kx     # mode 755. All installed directories will get mode 755.
     5         kx 
     5         kx     so_ext = sysconfig.get_config_var("SO")
     5         kx 
     5         kx     def install(self):
     5         kx         outfiles = install_lib.install(self)
     5         kx         self.set_file_modes(outfiles, 0644, 0755)
     5         kx         self.set_dir_modes(self.install_dir, 0755)
     5         kx         return outfiles
     5         kx 
     5         kx     def set_file_modes(self, files, defaultMode, sharedLibMode):
     5         kx         if not self.is_chmod_supported(): return
     5         kx         if not files: return
     5         kx 
     5         kx         for filename in files:
     5         kx             if os.path.islink(filename): continue
     5         kx             mode = defaultMode
     5         kx             if filename.endswith(self.so_ext): mode = sharedLibMode
     5         kx             log.info("changing mode of %s to %o", filename, mode)
     5         kx             if not self.dry_run: os.chmod(filename, mode)
     5         kx 
     5         kx     def set_dir_modes(self, dirname, mode):
     5         kx         if not self.is_chmod_supported(): return
     5         kx         os.path.walk(dirname, self.set_dir_modes_visitor, mode)
     5         kx 
     5         kx     def set_dir_modes_visitor(self, mode, dirname, names):
     5         kx         if os.path.islink(dirname): return
     5         kx         log.info("changing mode of %s to %o", dirname, mode)
     5         kx         if not self.dry_run: os.chmod(dirname, mode)
     5         kx 
     5         kx     def is_chmod_supported(self):
     5         kx         return hasattr(os, 'chmod')
     5         kx 
     5         kx SUMMARY = """
     5         kx Python is an interpreted, interactive, object-oriented programming
     5         kx language. It is often compared to Tcl, Perl, Scheme or Java.
     5         kx 
     5         kx Python combines remarkable power with very clear syntax. It has
     5         kx modules, classes, exceptions, very high level dynamic data types, and
     5         kx dynamic typing. There are interfaces to many system calls and
     5         kx libraries, as well as to various windowing systems (X11, Motif, Tk,
     5         kx Mac, MFC). New built-in modules are easily written in C or C++. Python
     5         kx is also usable as an extension language for applications that need a
     5         kx programmable interface.
     5         kx 
     5         kx The Python implementation is portable: it runs on many brands of UNIX,
     5         kx on Windows, DOS, OS/2, Mac, Amiga... If your favorite system isn't
     5         kx listed here, it may still be supported, if there's a C compiler for
     5         kx it. Ask around on comp.lang.python -- or just try compiling Python
     5         kx yourself.
     5         kx """
     5         kx 
     5         kx CLASSIFIERS = """
     5         kx Development Status :: 6 - Mature
     5         kx License :: OSI Approved :: Python Software Foundation License
     5         kx Natural Language :: English
     5         kx Programming Language :: C
     5         kx Programming Language :: Python
     5         kx Topic :: Software Development
     5         kx """
     5         kx 
     5         kx def main():
     5         kx     # turn off warnings when deprecated modules are imported
     5         kx     import warnings
     5         kx     warnings.filterwarnings("ignore",category=DeprecationWarning)
     5         kx     setup(# PyPI Metadata (PEP 301)
     5         kx           name = "Python",
     5         kx           version = sys.version.split()[0],
     5         kx           url = "http://www.python.org/%s" % sys.version[:3],
     5         kx           maintainer = "Guido van Rossum and the Python community",
     5         kx           maintainer_email = "python-dev@python.org",
     5         kx           description = "A high-level object-oriented programming language",
     5         kx           long_description = SUMMARY.strip(),
     5         kx           license = "PSF license",
     5         kx           classifiers = filter(None, CLASSIFIERS.split("\n")),
     5         kx           platforms = ["Many"],
     5         kx 
     5         kx           # Build info
     5         kx           cmdclass = {'build_ext':PyBuildExt, 'install':PyBuildInstall,
     5         kx                       'install_lib':PyBuildInstallLib},
     5         kx           # The struct module is defined here, because build_ext won't be
     5         kx           # called unless there's at least one extension module defined.
     5         kx           ext_modules=[Extension('_struct', ['_struct.c'])],
     5         kx 
     5         kx           # Scripts to install
     5         kx           scripts = ['Tools/scripts/pydoc', 'Tools/scripts/idle',
     5         kx                      'Tools/scripts/2to3',
     5         kx                      'Lib/smtpd.py']
     5         kx         )
     5         kx 
     5         kx # --install-platlib
     5         kx if __name__ == '__main__':
     5         kx     main()