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 import argparse
     5         kx import importlib._bootstrap
     5         kx import importlib.machinery
     5         kx import importlib.util
     5         kx import logging
     5         kx import os
     5         kx import re
     5         kx import sys
     5         kx import sysconfig
     5         kx import warnings
     5         kx from glob import glob, escape
     5         kx import _osx_support
     5         kx 
     5         kx 
     5         kx try:
     5         kx     import subprocess
     5         kx     del subprocess
     5         kx     SUBPROCESS_BOOTSTRAP = False
     5         kx except ImportError:
     5         kx     # Bootstrap Python: distutils.spawn uses subprocess to build C extensions,
     5         kx     # subprocess requires C extensions built by setup.py like _posixsubprocess.
     5         kx     #
     5         kx     # Use _bootsubprocess which only uses the os module.
     5         kx     #
     5         kx     # It is dropped from sys.modules as soon as all C extension modules
     5         kx     # are built.
     5         kx     import _bootsubprocess
     5         kx     sys.modules['subprocess'] = _bootsubprocess
     5         kx     del _bootsubprocess
     5         kx     SUBPROCESS_BOOTSTRAP = True
     5         kx 
     5         kx 
     5         kx with warnings.catch_warnings():
     5         kx     # bpo-41282 (PEP 632) deprecated distutils but setup.py still uses it
     5         kx     warnings.filterwarnings(
     5         kx         "ignore",
     5         kx         "The distutils package is deprecated",
     5         kx         DeprecationWarning
     5         kx     )
     5         kx     warnings.filterwarnings(
     5         kx         "ignore",
     5         kx         "The distutils.sysconfig module is deprecated, use sysconfig instead",
     5         kx         DeprecationWarning
     5         kx     )
     5         kx 
     5         kx     from distutils.command.build_ext import build_ext
     5         kx     from distutils.command.build_scripts import build_scripts
     5         kx     from distutils.command.install import install
     5         kx     from distutils.command.install_lib import install_lib
     5         kx     from distutils.core import Extension, setup
     5         kx     from distutils.errors import CCompilerError, DistutilsError
     5         kx     from distutils.spawn import find_executable
     5         kx 
     5         kx 
     5         kx # Compile extensions used to test Python?
     5         kx TEST_EXTENSIONS = (sysconfig.get_config_var('TEST_MODULES') == 'yes')
     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 # --list-module-names option used by Tools/scripts/generate_module_names.py
     5         kx LIST_MODULE_NAMES = False
     5         kx 
     5         kx 
     5         kx logging.basicConfig(format='%(message)s', level=logging.INFO)
     5         kx log = logging.getLogger('setup')
     5         kx 
     5         kx 
     5         kx def get_platform():
     5         kx     # Cross compiling
     5         kx     if "_PYTHON_HOST_PLATFORM" in os.environ:
     5         kx         return os.environ["_PYTHON_HOST_PLATFORM"]
     5         kx 
     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 
     5         kx 
     5         kx CROSS_COMPILING = ("_PYTHON_HOST_PLATFORM" in os.environ)
     5         kx HOST_PLATFORM = get_platform()
     5         kx MS_WINDOWS = (HOST_PLATFORM == 'win32')
     5         kx CYGWIN = (HOST_PLATFORM == 'cygwin')
     5         kx MACOS = (HOST_PLATFORM == 'darwin')
     5         kx AIX = (HOST_PLATFORM.startswith('aix'))
     5         kx VXWORKS = ('vxworks' in HOST_PLATFORM)
     5         kx CC = os.environ.get("CC")
     5         kx if not CC:
     5         kx     CC = sysconfig.get_config_var("CC")
     5         kx 
     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, 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 
     5         kx def run_command(cmd):
     5         kx     status = os.system(cmd)
     5         kx     return os.waitstatus_to_exitcode(status)
     5         kx 
     5         kx 
     5         kx # Set common compiler and linker flags derived from the Makefile,
     5         kx # reserved for building the interpreter and the stdlib modules.
     5         kx # See bpo-21121 and bpo-35257
     5         kx def set_compiler_flags(compiler_flags, compiler_py_flags_nodist):
     5         kx     flags = sysconfig.get_config_var(compiler_flags)
     5         kx     py_flags_nodist = sysconfig.get_config_var(compiler_py_flags_nodist)
     5         kx     sysconfig.get_config_vars()[compiler_flags] = flags + ' ' + py_flags_nodist
     5         kx 
     5         kx 
     5         kx def add_dir_to_list(dirlist, dir):
     5         kx     """Add the directory 'dir' to the list 'dirlist' (after any relative
     5         kx     directories) if:
     5         kx 
     5         kx     1) 'dir' is not already in 'dirlist'
     5         kx     2) 'dir' actually exists, and is a directory.
     5         kx     """
     5         kx     if dir is None or not os.path.isdir(dir) or dir in dirlist:
     5         kx         return
     5         kx     for i, path in enumerate(dirlist):
     5         kx         if not os.path.isabs(path):
     5         kx             dirlist.insert(i + 1, dir)
     5         kx             return
     5         kx     dirlist.insert(0, dir)
     5         kx 
     5         kx 
     5         kx def sysroot_paths(make_vars, subdirs):
     5         kx     """Get the paths of sysroot sub-directories.
     5         kx 
     5         kx     * make_vars: a sequence of names of variables of the Makefile where
     5         kx       sysroot may be set.
     5         kx     * subdirs: a sequence of names of subdirectories used as the location for
     5         kx       headers or libraries.
     5         kx     """
     5         kx 
     5         kx     dirs = []
     5         kx     for var_name in make_vars:
     5         kx         var = sysconfig.get_config_var(var_name)
     5         kx         if var is not None:
     5         kx             m = re.search(r'--sysroot=([^"]\S*|"[^"]+")', var)
     5         kx             if m is not None:
     5         kx                 sysroot = m.group(1).strip('"')
     5         kx                 for subdir in subdirs:
     5         kx                     if os.path.isabs(subdir):
     5         kx                         subdir = subdir[1:]
     5         kx                     path = os.path.join(sysroot, subdir)
     5         kx                     if os.path.isdir(path):
     5         kx                         dirs.append(path)
     5         kx                 break
     5         kx     return dirs
     5         kx 
     5         kx 
     5         kx MACOS_SDK_ROOT = None
     5         kx MACOS_SDK_SPECIFIED = 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     Also sets MACOS_SDK_SPECIFIED for use by macosx_sdk_specified().
     5         kx     """
     5         kx     global MACOS_SDK_ROOT, MACOS_SDK_SPECIFIED
     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         MACOS_SDK_SPECIFIED = MACOS_SDK_ROOT != '/'
     5         kx     else:
     5         kx         MACOS_SDK_ROOT = _osx_support._default_sysroot(
     5         kx             sysconfig.get_config_var('CC'))
     5         kx         MACOS_SDK_SPECIFIED = False
     5         kx 
     5         kx     return MACOS_SDK_ROOT
     5         kx 
     5         kx 
     5         kx def macosx_sdk_specified():
     5         kx     """Returns true if an SDK was explicitly configured.
     5         kx 
     5         kx     True if an SDK was selected at configure time, either by specifying
     5         kx     --enable-universalsdk=(something other than no or /) or by adding a
     5         kx     -isysroot option to CFLAGS.  In some cases, like when making
     5         kx     decisions about macOS Tk framework paths, we need to be able to
     5         kx     know whether the user explicitly asked to build with an SDK versus
     5         kx     the implicit use of an SDK when header files are no longer
     5         kx     installed on a running system by the Command Line Tools.
     5         kx     """
     5         kx     global MACOS_SDK_SPECIFIED
     5         kx 
     5         kx     # If already called, return cached result.
     5         kx     if MACOS_SDK_SPECIFIED:
     5         kx         return MACOS_SDK_SPECIFIED
     5         kx 
     5         kx     # Find the sdk root and set MACOS_SDK_SPECIFIED
     5         kx     macosx_sdk_root()
     5         kx     return MACOS_SDK_SPECIFIED
     5         kx 
     5         kx 
     5         kx def is_macosx_sdk_path(path):
     5         kx     """
     5         kx     Returns True if 'path' can be located in a macOS SDK
     5         kx     """
     5         kx     return ( (path.startswith('/usr/') and not path.startswith('/usr/local'))
     5         kx                 or path.startswith('/System/Library')
     5         kx                 or path.startswith('/System/iOSSupport') )
     5         kx 
     5         kx 
     5         kx def grep_headers_for(function, headers):
     5         kx     for header in headers:
     5         kx         with open(header, 'r', errors='surrogateescape') as f:
     5         kx             if function in f.read():
     5         kx                 return True
     5         kx     return False
     5         kx 
     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 MACOS:
     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 MACOS 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 MACOS 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 
     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 MACOS:
     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 MACOS 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 MACOS 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 
     5         kx def validate_tzpath():
     5         kx     base_tzpath = sysconfig.get_config_var('TZPATH')
     5         kx     if not base_tzpath:
     5         kx         return
     5         kx 
     5         kx     tzpaths = base_tzpath.split(os.pathsep)
     5         kx     bad_paths = [tzpath for tzpath in tzpaths if not os.path.isabs(tzpath)]
     5         kx     if bad_paths:
     5         kx         raise ValueError('TZPATH must contain only absolute paths, '
     5         kx                          + f'found:\n{tzpaths!r}\nwith invalid paths:\n'
     5         kx                          + f'{bad_paths!r}')
     5         kx 
     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     dirs = find_file(module, [], dirlist)
     5         kx     if not dirs:
     5         kx         return module
     5         kx     if len(dirs) > 1:
     5         kx         log.info(f"WARNING: multiple copies of {module} found")
     5         kx     return os.path.join(dirs[0], module)
     5         kx 
     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.srcdir = None
     5         kx         self.lib_dirs = None
     5         kx         self.inc_dirs = None
     5         kx         self.config_h_vars = None
     5         kx         self.failed = []
     5         kx         self.failed_on_import = []
     5         kx         self.missing = []
     5         kx         self.disabled_configure = []
     5         kx         if '-j' in os.environ.get('MAKEFLAGS', ''):
     5         kx             self.parallel = True
     5         kx 
     5         kx     def add(self, ext):
     5         kx         self.extensions.append(ext)
     5         kx 
     5         kx     def set_srcdir(self):
     5         kx         self.srcdir = sysconfig.get_config_var('srcdir')
     5         kx         if not self.srcdir:
     5         kx             # Maybe running on Windows but not using CYGWIN?
     5         kx             raise ValueError("No source directory; cannot proceed.")
     5         kx         self.srcdir = os.path.abspath(self.srcdir)
     5         kx 
     5         kx     def remove_disabled(self):
     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     def update_sources_depends(self):
     5         kx         # Fix up the autodetected modules, prefixing all the source files
     5         kx         # with Modules/.
     5         kx         moddirlist = [os.path.join(self.srcdir, 'Modules')]
     5         kx 
     5         kx         # Fix up the paths for scripts, too
     5         kx         self.distribution.scripts = [os.path.join(self.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(escape(sysconfig.get_path('include')), "*.h"))
     5         kx 
     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     def remove_configured_extensions(self):
     5         kx         # The sysconfig variables built by makesetup that list the already
     5         kx         # built modules and the disabled modules as configured by the Setup
     5         kx         # files.
     5         kx         sysconf_built = sysconfig.get_config_var('MODBUILT_NAMES').split()
     5         kx         sysconf_dis = sysconfig.get_config_var('MODDISABLED_NAMES').split()
     5         kx 
     5         kx         mods_built = []
     5         kx         mods_disabled = []
     5         kx         for ext in self.extensions:
     5         kx             # If a module has already been built or has been disabled in the
     5         kx             # Setup files, don't build it here.
     5         kx             if ext.name in sysconf_built:
     5         kx                 mods_built.append(ext)
     5         kx             if ext.name in sysconf_dis:
     5         kx                 mods_disabled.append(ext)
     5         kx 
     5         kx         mods_configured = mods_built + mods_disabled
     5         kx         if mods_configured:
     5         kx             self.extensions = [x for x in self.extensions if x not in
     5         kx                                mods_configured]
     5         kx             # Remove the shared libraries built by a previous build.
     5         kx             for ext in mods_configured:
     5         kx                 fullpath = self.get_ext_fullpath(ext.name)
     5         kx                 if os.path.exists(fullpath):
     5         kx                     os.unlink(fullpath)
     5         kx 
     5         kx         return (mods_built, mods_disabled)
     5         kx 
     5         kx     def set_compiler_executables(self):
     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     def build_extensions(self):
     5         kx         self.set_srcdir()
     5         kx         self.set_compiler_executables()
     5         kx         self.configure_compiler()
     5         kx         self.init_inc_lib_dirs()
     5         kx 
     5         kx         # Detect which modules should be compiled
     5         kx         self.detect_modules()
     5         kx 
     5         kx         if not LIST_MODULE_NAMES:
     5         kx             self.remove_disabled()
     5         kx 
     5         kx         self.update_sources_depends()
     5         kx         mods_built, mods_disabled = self.remove_configured_extensions()
     5         kx 
     5         kx         if LIST_MODULE_NAMES:
     5         kx             for ext in self.extensions:
     5         kx                 print(ext.name)
     5         kx             for name in self.missing:
     5         kx                 print(name)
     5         kx             return
     5         kx 
     5         kx         build_ext.build_extensions(self)
     5         kx 
     5         kx         if SUBPROCESS_BOOTSTRAP:
     5         kx             # Drop our custom subprocess module:
     5         kx             # use the newly built subprocess module
     5         kx             del sys.modules['subprocess']
     5         kx 
     5         kx         for ext in self.extensions:
     5         kx             self.check_extension_import(ext)
     5         kx 
     5         kx         self.summary(mods_built, mods_disabled)
     5         kx 
     5         kx     def summary(self, mods_built, mods_disabled):
     5         kx         longest = max([len(e.name) for e in self.extensions], default=0)
     5         kx         if self.failed or self.failed_on_import:
     5         kx             all_failed = self.failed + self.failed_on_import
     5         kx             longest = max(longest, max([len(name) for name in all_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 self.missing:
     5         kx             print()
     5         kx             print("The necessary bits to build these optional modules were not "
     5         kx                   "found:")
     5         kx             print_three_column(self.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 mods_built:
     5         kx             print()
     5         kx             print("The following modules found by detect_modules() in"
     5         kx             " setup.py, have been")
     5         kx             print("built by the Makefile instead, as configured by the"
     5         kx             " Setup files:")
     5         kx             print_three_column([ext.name for ext in mods_built])
     5         kx             print()
     5         kx 
     5         kx         if mods_disabled:
     5         kx             print()
     5         kx             print("The following modules found by detect_modules() in"
     5         kx             " setup.py have not")
     5         kx             print("been built, they are *disabled* in the Setup files:")
     5         kx             print_three_column([ext.name for ext in mods_disabled])
     5         kx             print()
     5         kx 
     5         kx         if self.disabled_configure:
     5         kx             print()
     5         kx             print("The following modules found by detect_modules() in"
     5         kx             " setup.py have not")
     5         kx             print("been built, they are *disabled* by configure:")
     5         kx             print_three_column(self.disabled_configure)
     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         if self.failed_on_import:
     5         kx             failed = self.failed_on_import[:]
     5         kx             print()
     5         kx             print("Following modules built successfully"
     5         kx                   " but were removed because they could not be imported:")
     5         kx             print_three_column(failed)
     5         kx             print()
     5         kx 
     5         kx         if any('_ssl' in l
     5         kx                for l in (self.missing, self.failed, self.failed_on_import)):
     5         kx             print()
     5         kx             print("Could not build the ssl module!")
     5         kx             print("Python requires a OpenSSL 1.1.1 or newer")
     5         kx             if sysconfig.get_config_var("OPENSSL_LDFLAGS"):
     5         kx                 print("Custom linker flags may require --with-openssl-rpath=auto")
     5         kx             print()
     5         kx 
     5         kx         if os.environ.get("PYTHONSTRICTEXTENSIONBUILD") and (self.failed or self.failed_on_import):
     5         kx             raise RuntimeError("Failed to build some stdlib modules")
     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                 self.failed.append(ext.name)
     5         kx                 return
     5         kx 
     5         kx         try:
     5         kx             build_ext.build_extension(self, ext)
     5         kx         except (CCompilerError, DistutilsError) as why:
     5         kx             self.announce('WARNING: building of extension "%s" failed: %s' %
     5         kx                           (ext.name, why))
     5         kx             self.failed.append(ext.name)
     5         kx             return
     5         kx 
     5         kx     def check_extension_import(self, ext):
     5         kx         # Don't try to import an extension that has failed to compile
     5         kx         if ext.name in self.failed:
     5         kx             self.announce(
     5         kx                 'WARNING: skipping import check for failed build "%s"' %
     5         kx                 ext.name, level=1)
     5         kx             return
     5         kx 
     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 MACOS and (
     5         kx                 sys.maxsize > 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 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         # If the build directory didn't exist when setup.py was
     5         kx         # started, sys.path_importer_cache has a negative result
     5         kx         # cached.  Clear that cache before trying to import.
     5         kx         sys.path_importer_cache.clear()
     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         loader = importlib.machinery.ExtensionFileLoader(ext.name, ext_filename)
     5         kx         spec = importlib.util.spec_from_file_location(ext.name, ext_filename,
     5         kx                                                       loader=loader)
     5         kx         try:
     5         kx             importlib._bootstrap._load(spec)
     5         kx         except ImportError as why:
     5         kx             self.failed_on_import.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         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         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 = run_command(
     5         kx             '%s -print-multiarch > %s 2> /dev/null' % (CC, tmpfile))
     5         kx         multiarch_path_component = ''
     5         kx         try:
     5         kx             if ret == 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/lib32/' + 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 = run_command(
     5         kx             'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null' %
     5         kx             (opt, tmpfile))
     5         kx         try:
     5         kx             if ret == 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/lib32/' + 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_wrcc_search_dirs(self):
     5         kx         # add library search path by wr-cc, the compiler wrapper
     5         kx 
     5         kx         def convert_mixed_path(path):
     5         kx             # convert path like C:\folder1\folder2/folder3/folder4
     5         kx             # to msys style /c/folder1/folder2/folder3/folder4
     5         kx             drive = path[0].lower()
     5         kx             left = path[2:].replace("\\", "/")
     5         kx             return "/" + drive + left
     5         kx 
     5         kx         def add_search_path(line):
     5         kx             # On Windows building machine, VxWorks does
     5         kx             # cross builds under msys2 environment.
     5         kx             pathsep = (";" if sys.platform == "msys" else ":")
     5         kx             for d in line.strip().split("=")[1].split(pathsep):
     5         kx                 d = d.strip()
     5         kx                 if sys.platform == "msys":
     5         kx                     # On Windows building machine, compiler
     5         kx                     # returns mixed style path like:
     5         kx                     # C:\folder1\folder2/folder3/folder4
     5         kx                     d = convert_mixed_path(d)
     5         kx                 d = os.path.normpath(d)
     5         kx                 add_dir_to_list(self.compiler.library_dirs, d)
     5         kx 
     5         kx         tmpfile = os.path.join(self.build_temp, 'wrccpaths')
     5         kx         os.makedirs(self.build_temp, exist_ok=True)
     5         kx         try:
     5         kx             ret = run_command('%s --print-search-dirs >%s' % (CC, tmpfile))
     5         kx             if ret:
     5         kx                 return
     5         kx             with open(tmpfile) as fp:
     5         kx                 # Parse paths in libraries line. The line is like:
     5         kx                 # On Linux, "libraries: = path1:path2:path3"
     5         kx                 # On Windows, "libraries: = path1;path2;path3"
     5         kx                 for line in fp:
     5         kx                     if not line.startswith("libraries"):
     5         kx                         continue
     5         kx                     add_search_path(line)
     5         kx         finally:
     5         kx             try:
     5         kx                 os.unlink(tmpfile)
     5         kx             except OSError:
     5         kx                 pass
     5         kx 
     5         kx     def add_cross_compiling_paths(self):
     5         kx         tmpfile = os.path.join(self.build_temp, 'ccpaths')
     5         kx         if not os.path.exists(self.build_temp):
     5         kx             os.makedirs(self.build_temp)
     5         kx         # bpo-38472: With a German locale, GCC returns "gcc-Version 9.1.0
     5         kx         # (GCC)", whereas it returns "gcc version 9.1.0" with the C locale.
     5         kx         ret = run_command('LC_ALL=C %s -E -v - </dev/null 2>%s 1>/dev/null' % (CC, tmpfile))
     5         kx         is_gcc = False
     5         kx         is_clang = False
     5         kx         in_incdirs = False
     5         kx         try:
     5         kx             if ret == 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("clang version"):
     5         kx                             is_clang = 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 or is_clang) 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 or is_clang) and in_incdirs and '/gcc/' not in line and '/clang/' 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         if VXWORKS:
     5         kx             self.add_wrcc_search_dirs()
     5         kx 
     5         kx     def add_ldflags_cppflags(self):
     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                 parser = argparse.ArgumentParser()
     5         kx                 parser.add_argument(arg_name, dest="dirs", action="append")
     5         kx 
     5         kx                 # To prevent argparse from raising an exception about any
     5         kx                 # options in env_val that it mistakes for known option, we
     5         kx                 # strip out all double dashes and any dashes followed by a
     5         kx                 # character 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                 options, _ = parser.parse_known_args(env_val.split())
     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     def configure_compiler(self):
     5         kx         # Ensure that /usr/local is always used, but the local build
     5         kx         # directories (i.e. '.' and 'Include') must be first.  See issue
     5         kx         # 10520.
     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         # only change this for cross builds for 3.3, issues on Mageia
     5         kx         if CROSS_COMPILING:
     5         kx             self.add_cross_compiling_paths()
     5         kx             self.add_multiarch_paths()
     5         kx             self.add_ldflags_cppflags()
     5         kx 
     5         kx     def init_inc_lib_dirs(self):
     5         kx         if (not CROSS_COMPILING and
     5         kx                 os.path.normpath(sys.base_prefix) != '/usr' and
     5         kx                 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         system_lib_dirs = ['/lib64', '/usr/lib64', '/lib', '/usr/lib']
     5         kx         system_include_dirs = ['/usr/include']
     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         if not CROSS_COMPILING:
     5         kx             self.lib_dirs = self.compiler.library_dirs + system_lib_dirs
     5         kx             self.inc_dirs = self.compiler.include_dirs + system_include_dirs
     5         kx         else:
     5         kx             # Add the sysroot paths. 'sysroot' is a compiler option used to
     5         kx             # set the logical path of the standard system headers and
     5         kx             # libraries.
     5         kx             self.lib_dirs = (self.compiler.library_dirs +
     5         kx                              sysroot_paths(('LDFLAGS', 'CC'), system_lib_dirs))
     5         kx             self.inc_dirs = (self.compiler.include_dirs +
     5         kx                              sysroot_paths(('CPPFLAGS', 'CFLAGS', 'CC'),
     5         kx                                            system_include_dirs))
     5         kx 
     5         kx         config_h = sysconfig.get_config_h_filename()
     5         kx         with open(config_h) as file:
     5         kx             self.config_h_vars = sysconfig.parse_config_h(file)
     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             self.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             self.lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32']
     5         kx 
     5         kx         if MACOS:
     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             #
     5         kx             # NOTE: using shlex.split would technically be more correct, but
     5         kx             # also gives a bootstrap problem. Let's hope nobody uses
     5         kx             # directories 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                     self.inc_dirs.append(item[2:])
     5         kx 
     5         kx             for item in ldflags.split():
     5         kx                 if item.startswith('-L'):
     5         kx                     self.lib_dirs.append(item[2:])
     5         kx 
     5         kx         # Insert libraries and headers from embedded root file system (RFS)
     5         kx         if 'RFS' in os.environ:
     5         kx             self.lib_dirs += [os.environ['RFS'] + '/usr/lib32']
     5         kx             self.inc_dirs += [os.environ['RFS'] + '/usr/include']
     5         kx 
     5         kx     def detect_simple_extensions(self):
     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         # array objects
     5         kx         self.add(Extension('array', ['arraymodule.c'],
     5         kx                            extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
     5         kx 
     5         kx         # Context Variables
     5         kx         self.add(Extension('_contextvars', ['_contextvarsmodule.c']))
     5         kx 
     5         kx         shared_math = 'Modules/_math.o'
     5         kx 
     5         kx         # math library functions, e.g. sin()
     5         kx         self.add(Extension('math',  ['mathmodule.c'],
     5         kx                            extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
     5         kx                            extra_objects=[shared_math],
     5         kx                            depends=['_math.h', shared_math],
     5         kx                            libraries=['m']))
     5         kx 
     5         kx         # complex math library functions
     5         kx         self.add(Extension('cmath', ['cmathmodule.c'],
     5         kx                            extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
     5         kx                            extra_objects=[shared_math],
     5         kx                            depends=['_math.h', shared_math],
     5         kx                            libraries=['m']))
     5         kx 
     5         kx         # time libraries: librt may be needed for clock_gettime()
     5         kx         time_libs = []
     5         kx         lib = sysconfig.get_config_var('TIMEMODULE_LIB')
     5         kx         if lib:
     5         kx             time_libs.append(lib)
     5         kx 
     5         kx         # time operations and variables
     5         kx         self.add(Extension('time', ['timemodule.c'],
     5         kx                            libraries=time_libs))
     5         kx         # libm is needed by delta_new() that uses round() and by accum() that
     5         kx         # uses modf().
     5         kx         self.add(Extension('_datetime', ['_datetimemodule.c'],
     5         kx                            libraries=['m'],
     5         kx                            extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
     5         kx         # zoneinfo module
     5         kx         self.add(Extension('_zoneinfo', ['_zoneinfo.c'],
     5         kx                            extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
     5         kx         # random number generator implemented in C
     5         kx         self.add(Extension("_random", ["_randommodule.c"],
     5         kx                            extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
     5         kx         # bisect
     5         kx         self.add(Extension("_bisect", ["_bisectmodule.c"]))
     5         kx         # heapq
     5         kx         self.add(Extension("_heapq", ["_heapqmodule.c"],
     5         kx                            extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
     5         kx         # C-optimized pickle replacement
     5         kx         self.add(Extension("_pickle", ["_pickle.c"],
     5         kx                            extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
     5         kx         # _json speedups
     5         kx         self.add(Extension("_json", ["_json.c"],
     5         kx                            extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
     5         kx 
     5         kx         # profiler (_lsprof is for cProfile.py)
     5         kx         self.add(Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']))
     5         kx         # static Unicode character database
     5         kx         self.add(Extension('unicodedata', ['unicodedata.c'],
     5         kx                            depends=['unicodedata_db.h', 'unicodename_db.h'],
     5         kx                            extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
     5         kx         # _opcode module
     5         kx         self.add(Extension('_opcode', ['_opcode.c']))
     5         kx         # asyncio speedups
     5         kx         self.add(Extension("_asyncio", ["_asynciomodule.c"],
     5         kx                            extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
     5         kx         # _abc speedups
     5         kx         self.add(Extension("_abc", ["_abc.c"],
     5         kx                            extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
     5         kx         # _queue module
     5         kx         self.add(Extension("_queue", ["_queuemodule.c"],
     5         kx                            extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
     5         kx         # _statistics module
     5         kx         self.add(Extension("_statistics", ["_statisticsmodule.c"]))
     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 (self.config_h_vars.get('FLOCK_NEEDS_LIBBSD', False)):
     5         kx             # May be necessary on AIX for flock function
     5         kx             libs = ['bsd']
     5         kx         self.add(Extension('fcntl', ['fcntlmodule.c'],
     5         kx                            libraries=libs))
     5         kx         # pwd(3)
     5         kx         self.add(Extension('pwd', ['pwdmodule.c']))
     5         kx         # grp(3)
     5         kx         if not VXWORKS:
     5         kx             self.add(Extension('grp', ['grpmodule.c']))
     5         kx         # spwd, shadow passwords
     5         kx         if (self.config_h_vars.get('HAVE_GETSPNAM', False) or
     5         kx                 self.config_h_vars.get('HAVE_GETSPENT', False)):
     5         kx             self.add(Extension('spwd', ['spwdmodule.c']))
     5         kx         # AIX has shadow passwords, but access is not via getspent(), etc.
     5         kx         # module support is not expected so it not 'missing'
     5         kx         elif not AIX:
     5         kx             self.missing.append('spwd')
     5         kx 
     5         kx         # select(2); not on ancient System V
     5         kx         self.add(Extension('select', ['selectmodule.c']))
     5         kx 
     5         kx         # Memory-mapped files (also works on Win32).
     5         kx         self.add(Extension('mmap', ['mmapmodule.c']))
     5         kx 
     5         kx         # Lance Ellinghaus's syslog module
     5         kx         # syslog daemon interface
     5         kx         self.add(Extension('syslog', ['syslogmodule.c']))
     5         kx 
     5         kx         # Python interface to subinterpreter C-API.
     5         kx         self.add(Extension('_xxsubinterpreters', ['_xxsubinterpretersmodule.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         #
     5         kx         # audioop needs libm for floor() in multiple functions.
     5         kx         self.add(Extension('audioop', ['audioop.c'],
     5         kx                            libraries=['m']))
     5         kx 
     5         kx         # CSV files
     5         kx         self.add(Extension('_csv', ['_csv.c']))
     5         kx 
     5         kx         # POSIX subprocess module helper.
     5         kx         self.add(Extension('_posixsubprocess', ['_posixsubprocess.c'],
     5         kx                            extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
     5         kx 
     5         kx     def detect_test_extensions(self):
     5         kx         # Python C API test module
     5         kx         self.add(Extension('_testcapi', ['_testcapimodule.c'],
     5         kx                            depends=['testcapi_long.h']))
     5         kx 
     5         kx         # Python Internal C API test module
     5         kx         self.add(Extension('_testinternalcapi', ['_testinternalcapi.c'],
     5         kx                            extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
     5         kx 
     5         kx         # Python PEP-3118 (buffer protocol) test module
     5         kx         self.add(Extension('_testbuffer', ['_testbuffer.c']))
     5         kx 
     5         kx         # Test loading multiple modules from one compiled file (https://bugs.python.org/issue16421)
     5         kx         self.add(Extension('_testimportmultiple', ['_testimportmultiple.c']))
     5         kx 
     5         kx         # Test multi-phase extension module init (PEP 489)
     5         kx         self.add(Extension('_testmultiphase', ['_testmultiphase.c']))
     5         kx 
     5         kx         # Fuzz tests.
     5         kx         self.add(Extension('_xxtestfuzz',
     5         kx                            ['_xxtestfuzz/_xxtestfuzz.c',
     5         kx                             '_xxtestfuzz/fuzzer.c']))
     5         kx 
     5         kx     def detect_readline_curses(self):
     5         kx         # readline
     5         kx         readline_termcap_library = ""
     5         kx         curses_library = ""
     5         kx         # Cannot use os.popen here in py3k.
     5         kx         tmpfile = os.path.join(self.build_temp, 'readline_termcap_lib')
     5         kx         if not os.path.exists(self.build_temp):
     5         kx             os.makedirs(self.build_temp)
     5         kx         # Determine if readline is already linked against curses or tinfo.
     5         kx         if sysconfig.get_config_var('HAVE_LIBREADLINE'):
     5         kx             if sysconfig.get_config_var('WITH_EDITLINE'):
     5         kx                 readline_lib = 'edit'
     5         kx             else:
     5         kx                 readline_lib = 'readline'
     5         kx             do_readline = self.compiler.find_library_file(self.lib_dirs,
     5         kx                 readline_lib)
     5         kx             if CROSS_COMPILING:
     5         kx                 ret = run_command("%s -d %s | grep '(NEEDED)' > %s"
     5         kx                                 % (sysconfig.get_config_var('READELF'),
     5         kx                                    do_readline, tmpfile))
     5         kx             elif find_executable('ldd'):
     5         kx                 ret = run_command("ldd %s > %s" % (do_readline, tmpfile))
     5         kx             else:
     5         kx                 ret = 1
     5         kx             if ret == 0:
     5         kx                 with open(tmpfile) as fp:
     5         kx                     for ln in fp:
     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                         # termcap interface split out from ncurses
     5         kx                         if 'tinfo' in ln:
     5         kx                             readline_termcap_library = 'tinfo'
     5         kx                             break
     5         kx             if os.path.exists(tmpfile):
     5         kx                 os.unlink(tmpfile)
     5         kx         else:
     5         kx             do_readline = False
     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(self.lib_dirs, 'ncursesw'):
     5         kx             curses_library = 'ncursesw'
     5         kx         # Issue 36210: OSS provided ncurses does not link on AIX
     5         kx         # Use IBM supplied 'curses' for successful build of _curses
     5         kx         elif AIX and self.compiler.find_library_file(self.lib_dirs, 'curses'):
     5         kx             curses_library = 'curses'
     5         kx         elif self.compiler.find_library_file(self.lib_dirs, 'ncurses'):
     5         kx             curses_library = 'ncurses'
     5         kx         elif self.compiler.find_library_file(self.lib_dirs, 'curses'):
     5         kx             curses_library = 'curses'
     5         kx 
     5         kx         if MACOS:
     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', self.inc_dirs, []) is None:
     5         kx                     do_readline = False
     5         kx         if do_readline:
     5         kx             if MACOS 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_lib]
     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(self.lib_dirs +
     5         kx                                                      ['/usr/lib32/termcap'],
     5         kx                                                      'termcap'):
     5         kx                 readline_libs.append('termcap')
     5         kx             self.add(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             self.missing.append('readline')
     5         kx 
     5         kx         # Curses support, requiring the System V version of curses, often
     5         kx         # provided by the ncurses library.
     5         kx         curses_defines = []
     5         kx         curses_includes = []
     5         kx         panel_library = 'panel'
     5         kx         if curses_library == 'ncursesw':
     5         kx             curses_defines.append(('HAVE_NCURSESW', '1'))
     5         kx             if not CROSS_COMPILING:
     5         kx                 curses_includes.append('/usr/include/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             if MACOS:
     5         kx                 # On OS X, there is no separate /usr/lib/libncursesw nor
     5         kx                 # libpanelw.  If we are here, we found a locally-supplied
     5         kx                 # version of libncursesw.  There should also be a
     5         kx                 # libpanelw.  _XOPEN_SOURCE defines are usually excluded
     5         kx                 # for OS X but we need _XOPEN_SOURCE_EXTENDED here for
     5         kx                 # ncurses wide char support
     5         kx                 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
     5         kx         elif MACOS and curses_library == 'ncurses':
     5         kx             # Building with the system-suppied combined libncurses/libpanel
     5         kx             curses_defines.append(('HAVE_NCURSESW', '1'))
     5         kx             curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
     5         kx 
     5         kx         curses_enabled = True
     5         kx         if curses_library.startswith('ncurses'):
     5         kx             curses_libs = [curses_library]
     5         kx             self.add(Extension('_curses', ['_cursesmodule.c'],
     5         kx                                extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
     5         kx                                include_dirs=curses_includes,
     5         kx                                define_macros=curses_defines,
     5         kx                                libraries=curses_libs))
     5         kx         elif curses_library == 'curses' and not MACOS:
     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(self.lib_dirs, 'terminfo')):
     5         kx                 curses_libs = ['curses', 'terminfo']
     5         kx             elif (self.compiler.find_library_file(self.lib_dirs, 'termcap')):
     5         kx                 curses_libs = ['curses', 'termcap']
     5         kx             else:
     5         kx                 curses_libs = ['curses']
     5         kx 
     5         kx             self.add(Extension('_curses', ['_cursesmodule.c'],
     5         kx                                extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
     5         kx                                define_macros=curses_defines,
     5         kx                                libraries=curses_libs))
     5         kx         else:
     5         kx             curses_enabled = False
     5         kx             self.missing.append('_curses')
     5         kx 
     5         kx         # If the curses module is enabled, check for the panel module
     5         kx         # _curses_panel needs some form of ncurses
     5         kx         skip_curses_panel = True if AIX else False
     5         kx         if (curses_enabled and not skip_curses_panel and
     5         kx                 self.compiler.find_library_file(self.lib_dirs, panel_library)):
     5         kx             self.add(Extension('_curses_panel', ['_curses_panel.c'],
     5         kx                            include_dirs=curses_includes,
     5         kx                            define_macros=curses_defines,
     5         kx                            libraries=[panel_library, *curses_libs]))
     5         kx         elif not skip_curses_panel:
     5         kx             self.missing.append('_curses_panel')
     5         kx 
     5         kx     def detect_crypt(self):
     5         kx         # crypt module.
     5         kx         if VXWORKS:
     5         kx             # bpo-31904: crypt() function is not provided by VxWorks.
     5         kx             # DES_crypt() OpenSSL provides is too weak to implement
     5         kx             # the encryption.
     5         kx             self.missing.append('_crypt')
     5         kx             return
     5         kx 
     5         kx         if self.compiler.find_library_file(self.lib_dirs, 'crypt'):
     5         kx             libs = ['crypt']
     5         kx         else:
     5         kx             libs = []
     5         kx 
     5         kx         self.add(Extension('_crypt', ['_cryptmodule.c'], libraries=libs))
     5         kx 
     5         kx     def detect_socket(self):
     5         kx         # socket(2)
     5         kx         kwargs = {'depends': ['socketmodule.h']}
     5         kx         if MACOS:
     5         kx             # Issue #35569: Expose RFC 3542 socket options.
     5         kx             kwargs['extra_compile_args'] = ['-D__APPLE_USE_RFC_3542']
     5         kx 
     5         kx         self.add(Extension('_socket', ['socketmodule.c'], **kwargs))
     5         kx 
     5         kx     def detect_dbm_gdbm(self):
     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 dbm/__init__.py provides an
     5         kx         # implementation independent wrapper for these; dbm/dumb.py provides
     5         kx         # similar functionality (but slower of course) implemented in Python.
     5         kx 
     5         kx         # Sleepycat^WOracle Berkeley DB interface.
     5         kx         #  https://www.oracle.com/database/technologies/related/berkeleydb.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 = (3, 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             return True
     5         kx 
     5         kx         def gen_db_minor_ver_nums(major):
     5         kx             if major == 4:
     5         kx                 for x in range(max_db_ver[1]+1):
     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 (https://www.finkproject.org/)
     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 (https://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 self.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 MACOS:
     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 self.inc_dirs + db_inc_paths:
     5         kx                 f = os.path.join(d, "db.h")
     5         kx                 if MACOS 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                     with open(f, 'rb') as file:
     5         kx                         f = file.read()
     5         kx                     m = re.search(br"#define\WDB_VERSION_MAJOR\W(\d+)", f)
     5         kx                     if m:
     5         kx                         db_major = int(m.group(1))
     5         kx                         m = re.search(br"#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(br"#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                                       "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 = list(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 not MACOS:
     5         kx                     db_dirs_to_check = list(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                     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 + self.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             dblibs = [dblib]
     5         kx             # Only add the found library and include directories if they aren't
     5         kx             # already being searched. This avoids an explicit runtime library
     5         kx             # dependency.
     5         kx             if db_incdir in self.inc_dirs:
     5         kx                 db_incs = None
     5         kx             else:
     5         kx                 db_incs = [db_incdir]
     5         kx             if dblib_dir[0] in self.lib_dirs:
     5         kx                 dblib_dir = None
     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 
     5         kx         dbm_setup_debug = False   # verbose debug prints from this script?
     5         kx         dbm_order = ['gdbm']
     5         kx         # The standard Unix dbm module:
     5         kx         if not 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", self.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(self.lib_dirs,
     5         kx                                                                'ndbm'):
     5         kx                             ndbm_libs = ['ndbm']
     5         kx                         elif self.compiler.find_library_file(self.lib_dirs,
     5         kx                                                              'gdbm_compat'):
     5         kx                             ndbm_libs = ['gdbm_compat']
     5         kx                         else:
     5         kx                             ndbm_libs = []
     5         kx                         if dbm_setup_debug: 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(self.lib_dirs, 'gdbm'):
     5         kx                         gdbm_libs = ['gdbm']
     5         kx                         if self.compiler.find_library_file(self.lib_dirs,
     5         kx                                                                'gdbm_compat'):
     5         kx                             gdbm_libs.append('gdbm_compat')
     5         kx                         if find_file("gdbm/ndbm.h", self.inc_dirs, []) is not None:
     5         kx                             if dbm_setup_debug: 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", self.inc_dirs, []) is not None:
     5         kx                             if dbm_setup_debug: 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 dblibs:
     5         kx                         if dbm_setup_debug: 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                 self.add(dbmext)
     5         kx             else:
     5         kx                 self.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(self.lib_dirs, 'gdbm')):
     5         kx             self.add(Extension('_gdbm', ['_gdbmmodule.c'],
     5         kx                                libraries=['gdbm']))
     5         kx         else:
     5         kx             self.missing.append('_gdbm')
     5         kx 
     5         kx     def detect_sqlite(self):
     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         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, 7, 15)  # Issue 40810
     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 MACOS:
     5         kx             sysroot = macosx_sdk_root()
     5         kx 
     5         kx         for d_ in self.inc_dirs + sqlite_inc_paths:
     5         kx             d = d_
     5         kx             if MACOS 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                 with open(f) as file:
     5         kx                     incf = file.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 %s 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 + self.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             sqlite_defines = []
     5         kx 
     5         kx             # Enable support for loadable extensions in the sqlite3 module
     5         kx             # if --enable-loadable-sqlite-extensions configure option is used.
     5         kx             if '--enable-loadable-sqlite-extensions' not in sysconfig.get_config_var("CONFIG_ARGS"):
     5         kx                 sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))
     5         kx             elif MACOS and sqlite_incdir == os.path.join(MACOS_SDK_ROOT, "usr/include"):
     5         kx                 raise DistutilsError("System version of SQLite does not support loadable extensions")
     5         kx 
     5         kx             if MACOS:
     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             include_dirs = ["Modules/_sqlite"]
     5         kx             # Only include the directory where sqlite was found if it does
     5         kx             # not already exist in set include directories, otherwise you
     5         kx             # can end up with a bad search path order.
     5         kx             if sqlite_incdir not in self.compiler.include_dirs:
     5         kx                 include_dirs.append(sqlite_incdir)
     5         kx             # avoid a runtime library path for a system library dir
     5         kx             if sqlite_libdir and sqlite_libdir[0] in self.lib_dirs:
     5         kx                 sqlite_libdir = None
     5         kx             self.add(Extension('_sqlite3', sqlite_srcs,
     5         kx                                define_macros=sqlite_defines,
     5         kx                                include_dirs=include_dirs,
     5         kx                                library_dirs=sqlite_libdir,
     5         kx                                extra_link_args=sqlite_extra_link_args,
     5         kx                                libraries=["sqlite3",]))
     5         kx         else:
     5         kx             self.missing.append('_sqlite3')
     5         kx 
     5         kx     def detect_platform_specific_exts(self):
     5         kx         # Unix-only modules
     5         kx         if not MS_WINDOWS:
     5         kx             if not VXWORKS:
     5         kx                 # Steen Lumholt's termios module
     5         kx                 self.add(Extension('termios', ['termios.c']))
     5         kx                 # Jeremy Hylton's rlimit interface
     5         kx             self.add(Extension('resource', ['resource.c']))
     5         kx         else:
     5         kx             self.missing.extend(['resource', 'termios'])
     5         kx 
     5         kx         # Platform-specific libraries
     5         kx         if HOST_PLATFORM.startswith(('linux', 'freebsd', 'gnukfreebsd')):
     5         kx             self.add(Extension('ossaudiodev', ['ossaudiodev.c']))
     5         kx         elif HOST_PLATFORM.startswith(('netbsd')):
     5         kx             self.add(Extension('ossaudiodev', ['ossaudiodev.c'],
     5         kx                                libraries=["ossaudio"]))
     5         kx         elif not AIX:
     5         kx             self.missing.append('ossaudiodev')
     5         kx 
     5         kx         if MACOS:
     5         kx             self.add(Extension('_scproxy', ['_scproxy.c'],
     5         kx                                extra_link_args=[
     5         kx                                    '-framework', 'SystemConfiguration',
     5         kx                                    '-framework', 'CoreFoundation']))
     5         kx 
     5         kx     def detect_compress_exts(self):
     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', [], self.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 MACOS and is_macosx_sdk_path(zlib_h):
     5         kx                 zlib_h = os.path.join(macosx_sdk_root(), zlib_h[1:])
     5         kx             with open(zlib_h) as fp:
     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(self.lib_dirs, 'z')):
     5         kx                     if MACOS:
     5         kx                         zlib_extra_link_args = ('-Wl,-search_paths_first',)
     5         kx                     else:
     5         kx                         zlib_extra_link_args = ()
     5         kx                     self.add(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                     self.missing.append('zlib')
     5         kx             else:
     5         kx                 self.missing.append('zlib')
     5         kx         else:
     5         kx             self.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         self.add(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(self.lib_dirs, 'bz2')):
     5         kx             if MACOS:
     5         kx                 bz2_extra_link_args = ('-Wl,-search_paths_first',)
     5         kx             else:
     5         kx                 bz2_extra_link_args = ()
     5         kx             self.add(Extension('_bz2', ['_bz2module.c'],
     5         kx                                libraries=['bz2'],
     5         kx                                extra_link_args=bz2_extra_link_args))
     5         kx         else:
     5         kx             self.missing.append('_bz2')
     5         kx 
     5         kx         # LZMA compression support.
     5         kx         if self.compiler.find_library_file(self.lib_dirs, 'lzma'):
     5         kx             self.add(Extension('_lzma', ['_lzmamodule.c'],
     5         kx                                libraries=['lzma']))
     5         kx         else:
     5         kx             self.missing.append('_lzma')
     5         kx 
     5         kx     def detect_expat_elementtree(self):
     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             extra_compile_args = []
     5         kx             expat_lib = ['expat']
     5         kx             expat_sources = []
     5         kx             expat_depends = []
     5         kx         else:
     5         kx             expat_inc = [os.path.join(self.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             extra_compile_args = []
     5         kx             # bpo-44394: libexpat uses isnan() of math.h and needs linkage
     5         kx             # against the libm
     5         kx             expat_lib = ['m']
     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             cc = sysconfig.get_config_var('CC').split()[0]
     5         kx             ret = run_command(
     5         kx                       '"%s" -Werror -Wno-unreachable-code -E -xc /dev/null >/dev/null 2>&1' % cc)
     5         kx             if ret == 0:
     5         kx                 extra_compile_args.append('-Wno-unreachable-code')
     5         kx 
     5         kx         self.add(Extension('pyexpat',
     5         kx                            define_macros=define_macros,
     5         kx                            extra_compile_args=extra_compile_args,
     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         # 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(self.srcdir, 'Modules', '_elementtree.c')):
     5         kx             define_macros.append(('USE_PYEXPAT_CAPI', None))
     5         kx             self.add(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         else:
     5         kx             self.missing.append('_elementtree')
     5         kx 
     5         kx     def detect_multibytecodecs(self):
     5         kx         # Hye-Shik Chang's CJKCodecs modules.
     5         kx         self.add(Extension('_multibytecodec',
     5         kx                            ['cjkcodecs/multibytecodec.c']))
     5         kx         for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'):
     5         kx             self.add(Extension('_codecs_%s' % loc,
     5         kx                                ['cjkcodecs/_codecs_%s.c' % loc]))
     5         kx 
     5         kx     def detect_multiprocessing(self):
     5         kx         # Richard Oudkerk's multiprocessing module
     5         kx         if MS_WINDOWS:
     5         kx             multiprocessing_srcs = ['_multiprocessing/multiprocessing.c',
     5         kx                                     '_multiprocessing/semaphore.c']
     5         kx         else:
     5         kx             multiprocessing_srcs = ['_multiprocessing/multiprocessing.c']
     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         self.add(Extension('_multiprocessing', multiprocessing_srcs,
     5         kx                            include_dirs=["Modules/_multiprocessing"]))
     5         kx 
     5         kx         if (not MS_WINDOWS and
     5         kx            sysconfig.get_config_var('HAVE_SHM_OPEN') and
     5         kx            sysconfig.get_config_var('HAVE_SHM_UNLINK')):
     5         kx             posixshmem_srcs = ['_multiprocessing/posixshmem.c']
     5         kx             libs = []
     5         kx             if sysconfig.get_config_var('SHM_NEEDS_LIBRT'):
     5         kx                 # need to link with librt to get shm_open()
     5         kx                 libs.append('rt')
     5         kx             self.add(Extension('_posixshmem', posixshmem_srcs,
     5         kx                                define_macros={},
     5         kx                                libraries=libs,
     5         kx                                include_dirs=["Modules/_multiprocessing"]))
     5         kx         else:
     5         kx             self.missing.append('_posixshmem')
     5         kx 
     5         kx     def detect_uuid(self):
     5         kx         # Build the _uuid module if possible
     5         kx         uuid_h = sysconfig.get_config_var("HAVE_UUID_H")
     5         kx         uuid_uuid_h = sysconfig.get_config_var("HAVE_UUID_UUID_H")
     5         kx         if uuid_h or uuid_uuid_h:
     5         kx             if sysconfig.get_config_var("HAVE_LIBUUID"):
     5         kx                 uuid_libs = ["uuid"]
     5         kx             else:
     5         kx                 uuid_libs = []
     5         kx             self.add(Extension('_uuid', ['_uuidmodule.c'],
     5         kx                                libraries=uuid_libs))
     5         kx         else:
     5         kx             self.missing.append('_uuid')
     5         kx 
     5         kx     def detect_modules(self):
     5         kx         self.detect_simple_extensions()
     5         kx         if TEST_EXTENSIONS:
     5         kx             self.detect_test_extensions()
     5         kx         self.detect_readline_curses()
     5         kx         self.detect_crypt()
     5         kx         self.detect_socket()
     5         kx         self.detect_openssl_hashlib()
     5         kx         self.detect_hash_builtins()
     5         kx         self.detect_dbm_gdbm()
     5         kx         self.detect_sqlite()
     5         kx         self.detect_platform_specific_exts()
     5         kx         self.detect_nis()
     5         kx         self.detect_compress_exts()
     5         kx         self.detect_expat_elementtree()
     5         kx         self.detect_multibytecodecs()
     5         kx         self.detect_decimal()
     5         kx         self.detect_ctypes()
     5         kx         self.detect_multiprocessing()
     5         kx         if not self.detect_tkinter():
     5         kx             self.missing.append('_tkinter')
     5         kx         self.detect_uuid()
     5         kx 
     5         kx ##         # Uncomment these lines if you want to play with xxmodule.c
     5         kx ##         self.add(Extension('xx', ['xxmodule.c']))
     5         kx 
     5         kx         # The limited C API is not compatible with the Py_TRACE_REFS macro.
     5         kx         if not sysconfig.get_config_var('Py_TRACE_REFS'):
     5         kx             self.add(Extension('xxlimited', ['xxlimited.c']))
     5         kx             self.add(Extension('xxlimited_35', ['xxlimited_35.c']))
     5         kx 
     5         kx     def detect_tkinter_fromenv(self):
     5         kx         # Build _tkinter using the Tcl/Tk locations specified by
     5         kx         # the _TCLTK_INCLUDES and _TCLTK_LIBS environment variables.
     5         kx         # This method is meant to be invoked by detect_tkinter().
     5         kx         #
     5         kx         # The variables can be set via one of the following ways.
     5         kx         #
     5         kx         # - Automatically, at configuration time, by using pkg-config.
     5         kx         #   The tool is called by the configure script.
     5         kx         #   Additional pkg-config configuration paths can be set via the
     5         kx         #   PKG_CONFIG_PATH environment variable.
     5         kx         #
     5         kx         #     PKG_CONFIG_PATH=".../lib/pkgconfig" ./configure ...
     5         kx         #
     5         kx         # - Explicitly, at configuration time by setting both
     5         kx         #   --with-tcltk-includes and --with-tcltk-libs.
     5         kx         #
     5         kx         #     ./configure ... \
     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         #  - Explicitly, at compile time, by passing TCLTK_INCLUDES and
     5         kx         #    TCLTK_LIBS to the make target.
     5         kx         #    This will override any configuration-time option.
     5         kx         #
     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 False
     5         kx 
     5         kx         extra_compile_args = tcltk_includes.split()
     5         kx         extra_link_args = tcltk_libs.split()
     5         kx         self.add(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         return True
     5         kx 
     5         kx     def detect_tkinter_darwin(self):
     5         kx         # Build default _tkinter on macOS using Tcl and Tk frameworks.
     5         kx         # This method is meant to be invoked by detect_tkinter().
     5         kx         #
     5         kx         # The macOS native Tk (AKA Aqua Tk) and Tcl are most commonly
     5         kx         # built and installed as macOS framework bundles.  However,
     5         kx         # for several reasons, we cannot take full advantage of the
     5         kx         # Apple-supplied compiler chain's -framework options here.
     5         kx         # Instead, we need to find and pass to the compiler the
     5         kx         # absolute paths of the Tcl and Tk headers files we want to use
     5         kx         # and the absolute path to the directory containing the Tcl
     5         kx         # and Tk frameworks for linking.
     5         kx         #
     5         kx         # We want to handle here two common use cases on macOS:
     5         kx         # 1. Build and link with system-wide third-party or user-built
     5         kx         #    Tcl and Tk frameworks installed in /Library/Frameworks.
     5         kx         # 2. Build and link using a user-specified macOS SDK so that the
     5         kx         #    built Python can be exported to other systems.  In this case,
     5         kx         #    search only the SDK's /Library/Frameworks (normally empty)
     5         kx         #    and /System/Library/Frameworks.
     5         kx         #
     5         kx         # Any other use cases are handled either by detect_tkinter_fromenv(),
     5         kx         # or detect_tkinter(). The former handles non-standard locations of
     5         kx         # Tcl/Tk, defined via the _TCLTK_INCLUDES and _TCLTK_LIBS environment
     5         kx         # variables. The latter handles any Tcl/Tk versions installed in
     5         kx         # standard Unix directories.
     5         kx         #
     5         kx         # It would be desirable to also handle here the case where
     5         kx         # you want to build and link with a framework build of Tcl and Tk
     5         kx         # that is not in /Library/Frameworks, say, in your private
     5         kx         # $HOME/Library/Frameworks directory or elsewhere. It turns
     5         kx         # out to be difficult to make that work automatically here
     5         kx         # without bringing into play more tools and magic. That case
     5         kx         # can be handled using a recipe with the right arguments
     5         kx         # to detect_tkinter_fromenv().
     5         kx         #
     5         kx         # Note also that the fallback case here is to try to use the
     5         kx         # Apple-supplied Tcl and Tk frameworks in /System/Library but
     5         kx         # be forewarned that they are deprecated by Apple and typically
     5         kx         # out-of-date and buggy; their use should be avoided if at
     5         kx         # all possible by installing a newer version of Tcl and Tk in
     5         kx         # /Library/Frameworks before building Python without
     5         kx         # an explicit SDK or by configuring build arguments explicitly.
     5         kx 
     5         kx         from os.path import join, exists
     5         kx 
     5         kx         sysroot = macosx_sdk_root() # path to the SDK or '/'
     5         kx 
     5         kx         if macosx_sdk_specified():
     5         kx             # Use case #2: an SDK other than '/' was specified.
     5         kx             # Only search there.
     5         kx             framework_dirs = [
     5         kx                 join(sysroot, 'Library', 'Frameworks'),
     5         kx                 join(sysroot, 'System', 'Library', 'Frameworks'),
     5         kx             ]
     5         kx         else:
     5         kx             # Use case #1: no explicit SDK selected.
     5         kx             # Search the local system-wide /Library/Frameworks,
     5         kx             # not the one in the default SDK, otherwise fall back to
     5         kx             # /System/Library/Frameworks whose header files may be in
     5         kx             # the default SDK or, on older systems, actually installed.
     5         kx             framework_dirs = [
     5         kx                 join('/', 'Library', 'Frameworks'),
     5         kx                 join(sysroot, 'System', 'Library', 'Frameworks'),
     5         kx             ]
     5         kx 
     5         kx         # Find the directory that contains the Tcl.framework and
     5         kx         # Tk.framework bundles.
     5         kx         for F in framework_dirs:
     5         kx             # both Tcl.framework and Tk.framework should be present
     5         kx             for fw in 'Tcl', 'Tk':
     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. Continue
     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 False
     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',)
     5         kx         ]
     5         kx 
     5         kx         # Add the base framework directory as well
     5         kx         compile_args = ['-F', F]
     5         kx 
     5         kx         # Do not build tkinter for archs that this Tk was not built with.
     5         kx         cflags = sysconfig.get_config_vars('CFLAGS')[0]
     5         kx         archs = re.findall(r'-arch\s+(\w+)', cflags)
     5         kx 
     5         kx         tmpfile = os.path.join(self.build_temp, 'tk.arch')
     5         kx         if not os.path.exists(self.build_temp):
     5         kx             os.makedirs(self.build_temp)
     5         kx 
     5         kx         run_command(
     5         kx             "file {}/Tk.framework/Tk | grep 'for architecture' > {}".format(F, tmpfile)
     5         kx         )
     5         kx         with open(tmpfile) as fp:
     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         os.unlink(tmpfile)
     5         kx 
     5         kx         arch_args = []
     5         kx         for a in detected_archs:
     5         kx             arch_args.append('-arch')
     5         kx             arch_args.append(a)
     5         kx 
     5         kx         compile_args += arch_args
     5         kx         link_args = [','.join(['-Wl', '-F', F, '-framework', 'Tcl', '-framework', 'Tk']), *arch_args]
     5         kx 
     5         kx         # The X11/xlib.h file bundled in the Tk sources can cause function
     5         kx         # prototype warnings from the compiler. Since we cannot easily fix
     5         kx         # that, suppress the warnings here instead.
     5         kx         if '-Wstrict-prototypes' in cflags.split():
     5         kx             compile_args.append('-Wno-strict-prototypes')
     5         kx 
     5         kx         self.add(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=compile_args,
     5         kx                            extra_link_args=link_args))
     5         kx         return True
     5         kx 
     5         kx     def detect_tkinter(self):
     5         kx         # The _tkinter module.
     5         kx         #
     5         kx         # Detection of Tcl/Tk is attempted in the following order:
     5         kx         #   - Through environment variables.
     5         kx         #   - Platform specific detection of Tcl/Tk (currently only macOS).
     5         kx         #   - Search of various standard Unix header/library paths.
     5         kx         #
     5         kx         # Detection stops at the first successful method.
     5         kx 
     5         kx         # Check for Tcl and Tk at the locations indicated by _TCLTK_INCLUDES
     5         kx         # and _TCLTK_LIBS environment variables.
     5         kx         if self.detect_tkinter_fromenv():
     5         kx             return True
     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 (MACOS and self.detect_tkinter_darwin()):
     5         kx             return True
     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(self.lib_dirs,
     5         kx                                                         'tk' + version)
     5         kx             tcllib = self.compiler.find_library_file(self.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 self.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', self.inc_dirs, tcl_include_sub)
     5         kx             tk_includes = find_file('tk.h', self.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 False
     5         kx 
     5         kx         # OK... everything seems to be present for Tcl/Tk.
     5         kx 
     5         kx         include_dirs = []
     5         kx         libs = []
     5         kx         defs = []
     5         kx         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 CYGWIN:
     5         kx             x11_inc = find_file('X11/Xlib.h', [], include_dirs)
     5         kx             if x11_inc is None:
     5         kx                 return False
     5         kx 
     5         kx         # Check for BLT extension
     5         kx         if self.compiler.find_library_file(self.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(self.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         # Finally, link with the X11 libraries (not appropriate on cygwin)
     5         kx         if not CYGWIN:
     5         kx             libs.append('X11')
     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         self.add(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         return True
     5         kx 
     5         kx     def configure_ctypes(self, ext):
     5         kx         return True
     5         kx 
     5         kx     def detect_ctypes(self):
     5         kx         # Thomas Heller's _ctypes module
     5         kx 
     5         kx         if (not sysconfig.get_config_var("LIBFFI_INCLUDEDIR") and MACOS):
     5         kx             self.use_system_libffi = True
     5         kx         else:
     5         kx             self.use_system_libffi = '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS")
     5         kx 
     5         kx         include_dirs = []
     5         kx         extra_compile_args = ['-DPy_BUILD_CORE_MODULE']
     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 MACOS:
     5         kx             sources.append('_ctypes/malloc_closure.c')
     5         kx             extra_compile_args.append('-DUSING_MALLOC_CLOSURE_DOT_C=1')
     5         kx             extra_compile_args.append('-DMACOSX')
     5         kx             include_dirs.append('_ctypes/darwin')
     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         self.add(ext)
     5         kx         if TEST_EXTENSIONS:
     5         kx             # function my_sqrt() needs libm for sqrt()
     5         kx             self.add(Extension('_ctypes_test',
     5         kx                                sources=['_ctypes/_ctypes_test.c'],
     5         kx                                libraries=['m']))
     5         kx 
     5         kx         ffi_inc = sysconfig.get_config_var("LIBFFI_INCLUDEDIR")
     5         kx         ffi_lib = None
     5         kx 
     5         kx         ffi_inc_dirs = self.inc_dirs.copy()
     5         kx         if MACOS:
     5         kx             ffi_in_sdk = os.path.join(macosx_sdk_root(), "usr/include/ffi")
     5         kx 
     5         kx             if not ffi_inc:
     5         kx                 if os.path.exists(ffi_in_sdk):
     5         kx                     ext.extra_compile_args.append("-DUSING_APPLE_OS_LIBFFI=1")
     5         kx                     ffi_inc = ffi_in_sdk
     5         kx                     ffi_lib = 'ffi'
     5         kx                 else:
     5         kx                     # OS X 10.5 comes with libffi.dylib; the include files are
     5         kx                     # in /usr/include/ffi
     5         kx                     ffi_inc_dirs.append('/usr/include/ffi')
     5         kx 
     5         kx         if not ffi_inc:
     5         kx             found = find_file('ffi.h', [], ffi_inc_dirs)
     5         kx             if found:
     5         kx                 ffi_inc = found[0]
     5         kx         if ffi_inc:
     5         kx             ffi_h = ffi_inc + '/ffi.h'
     5         kx             if not os.path.exists(ffi_h):
     5         kx                 ffi_inc = None
     5         kx                 print('Header file {} does not exist'.format(ffi_h))
     5         kx         if ffi_lib is None and ffi_inc:
     5         kx             for lib_name in ('ffi', 'ffi_pic'):
     5         kx                 if (self.compiler.find_library_file(self.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             ffi_headers = glob(os.path.join(ffi_inc, '*.h'))
     5         kx             if grep_headers_for('ffi_prep_cif_var', ffi_headers):
     5         kx                 ext.extra_compile_args.append("-DHAVE_FFI_PREP_CIF_VAR=1")
     5         kx             if grep_headers_for('ffi_prep_closure_loc', ffi_headers):
     5         kx                 ext.extra_compile_args.append("-DHAVE_FFI_PREP_CLOSURE_LOC=1")
     5         kx             if grep_headers_for('ffi_closure_alloc', ffi_headers):
     5         kx                 ext.extra_compile_args.append("-DHAVE_FFI_CLOSURE_ALLOC=1")
     5         kx 
     5         kx             ext.include_dirs.append(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_decimal(self):
     5         kx         # Stefan Krah's _decimal module
     5         kx         extra_compile_args = []
     5         kx         undef_macros = []
     5         kx         if '--with-system-libmpdec' in sysconfig.get_config_var("CONFIG_ARGS"):
     5         kx             include_dirs = []
     5         kx             libraries = ['mpdec']
     5         kx             sources = ['_decimal/_decimal.c']
     5         kx             depends = ['_decimal/docstrings.h']
     5         kx         else:
     5         kx             include_dirs = [os.path.abspath(os.path.join(self.srcdir,
     5         kx                                                          'Modules',
     5         kx                                                          '_decimal',
     5         kx                                                          'libmpdec'))]
     5         kx             libraries = ['m']
     5         kx             sources = [
     5         kx               '_decimal/_decimal.c',
     5         kx               '_decimal/libmpdec/basearith.c',
     5         kx               '_decimal/libmpdec/constants.c',
     5         kx               '_decimal/libmpdec/context.c',
     5         kx               '_decimal/libmpdec/convolute.c',
     5         kx               '_decimal/libmpdec/crt.c',
     5         kx               '_decimal/libmpdec/difradix2.c',
     5         kx               '_decimal/libmpdec/fnt.c',
     5         kx               '_decimal/libmpdec/fourstep.c',
     5         kx               '_decimal/libmpdec/io.c',
     5         kx               '_decimal/libmpdec/mpalloc.c',
     5         kx               '_decimal/libmpdec/mpdecimal.c',
     5         kx               '_decimal/libmpdec/numbertheory.c',
     5         kx               '_decimal/libmpdec/sixstep.c',
     5         kx               '_decimal/libmpdec/transpose.c',
     5         kx               ]
     5         kx             depends = [
     5         kx               '_decimal/docstrings.h',
     5         kx               '_decimal/libmpdec/basearith.h',
     5         kx               '_decimal/libmpdec/bits.h',
     5         kx               '_decimal/libmpdec/constants.h',
     5         kx               '_decimal/libmpdec/convolute.h',
     5         kx               '_decimal/libmpdec/crt.h',
     5         kx               '_decimal/libmpdec/difradix2.h',
     5         kx               '_decimal/libmpdec/fnt.h',
     5         kx               '_decimal/libmpdec/fourstep.h',
     5         kx               '_decimal/libmpdec/io.h',
     5         kx               '_decimal/libmpdec/mpalloc.h',
     5         kx               '_decimal/libmpdec/mpdecimal.h',
     5         kx               '_decimal/libmpdec/numbertheory.h',
     5         kx               '_decimal/libmpdec/sixstep.h',
     5         kx               '_decimal/libmpdec/transpose.h',
     5         kx               '_decimal/libmpdec/typearith.h',
     5         kx               '_decimal/libmpdec/umodarith.h',
     5         kx               ]
     5         kx 
     5         kx         config = {
     5         kx           'x64':     [('CONFIG_64','1'), ('ASM','1')],
     5         kx           'uint128': [('CONFIG_64','1'), ('ANSI','1'), ('HAVE_UINT128_T','1')],
     5         kx           'ansi64':  [('CONFIG_64','1'), ('ANSI','1')],
     5         kx           'ppro':    [('CONFIG_32','1'), ('PPRO','1'), ('ASM','1')],
     5         kx           'ansi32':  [('CONFIG_32','1'), ('ANSI','1')],
     5         kx           'ansi-legacy': [('CONFIG_32','1'), ('ANSI','1'),
     5         kx                           ('LEGACY_COMPILER','1')],
     5         kx           'universal':   [('UNIVERSAL','1')]
     5         kx         }
     5         kx 
     5         kx         cc = sysconfig.get_config_var('CC')
     5         kx         sizeof_size_t = sysconfig.get_config_var('SIZEOF_SIZE_T')
     5         kx         machine = os.environ.get('PYTHON_DECIMAL_WITH_MACHINE')
     5         kx 
     5         kx         if machine:
     5         kx             # Override automatic configuration to facilitate testing.
     5         kx             define_macros = config[machine]
     5         kx         elif MACOS:
     5         kx             # Universal here means: build with the same options Python
     5         kx             # was built with.
     5         kx             define_macros = config['universal']
     5         kx         elif sizeof_size_t == 8:
     5         kx             if sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X64'):
     5         kx                 define_macros = config['x64']
     5         kx             elif sysconfig.get_config_var('HAVE_GCC_UINT128_T'):
     5         kx                 define_macros = config['uint128']
     5         kx             else:
     5         kx                 define_macros = config['ansi64']
     5         kx         elif sizeof_size_t == 4:
     5         kx             ppro = sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X87')
     5         kx             if ppro and ('gcc' in cc or 'clang' in cc) and \
     5         kx                not 'sunos' in HOST_PLATFORM:
     5         kx                 # solaris: problems with register allocation.
     5         kx                 # icc >= 11.0 works as well.
     5         kx                 define_macros = config['ppro']
     5         kx                 extra_compile_args.append('-Wno-unknown-pragmas')
     5         kx             else:
     5         kx                 define_macros = config['ansi32']
     5         kx         else:
     5         kx             raise DistutilsError("_decimal: unsupported architecture")
     5         kx 
     5         kx         # Workarounds for toolchain bugs:
     5         kx         if sysconfig.get_config_var('HAVE_IPA_PURE_CONST_BUG'):
     5         kx             # Some versions of gcc miscompile inline asm:
     5         kx             # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491
     5         kx             # https://gcc.gnu.org/ml/gcc/2010-11/msg00366.html
     5         kx             extra_compile_args.append('-fno-ipa-pure-const')
     5         kx         if sysconfig.get_config_var('HAVE_GLIBC_MEMMOVE_BUG'):
     5         kx             # _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect:
     5         kx             # https://sourceware.org/ml/libc-alpha/2010-12/msg00009.html
     5         kx             undef_macros.append('_FORTIFY_SOURCE')
     5         kx 
     5         kx         # Uncomment for extra functionality:
     5         kx         #define_macros.append(('EXTRA_FUNCTIONALITY', 1))
     5         kx         self.add(Extension('_decimal',
     5         kx                            include_dirs=include_dirs,
     5         kx                            libraries=libraries,
     5         kx                            define_macros=define_macros,
     5         kx                            undef_macros=undef_macros,
     5         kx                            extra_compile_args=extra_compile_args,
     5         kx                            sources=sources,
     5         kx                            depends=depends))
     5         kx 
     5         kx     def detect_openssl_hashlib(self):
     5         kx         # Detect SSL support for the socket module (via _ssl)
     5         kx         config_vars = sysconfig.get_config_vars()
     5         kx 
     5         kx         def split_var(name, sep):
     5         kx             # poor man's shlex, the re module is not available yet.
     5         kx             value = config_vars.get(name)
     5         kx             if not value:
     5         kx                 return ()
     5         kx             # This trick works because ax_check_openssl uses --libs-only-L,
     5         kx             # --libs-only-l, and --cflags-only-I.
     5         kx             value = ' ' + value
     5         kx             sep = ' ' + sep
     5         kx             return [v.strip() for v in value.split(sep) if v.strip()]
     5         kx 
     5         kx         openssl_includes = split_var('OPENSSL_INCLUDES', '-I')
     5         kx         openssl_libdirs = split_var('OPENSSL_LDFLAGS', '-L')
     5         kx         openssl_libs = split_var('OPENSSL_LIBS', '-l')
     5         kx         openssl_rpath = config_vars.get('OPENSSL_RPATH')
     5         kx         if not openssl_libs:
     5         kx             # libssl and libcrypto not found
     5         kx             self.missing.extend(['_ssl', '_hashlib'])
     5         kx             return None, None
     5         kx 
     5         kx         # Find OpenSSL includes
     5         kx         ssl_incs = find_file(
     5         kx             'openssl/ssl.h', self.inc_dirs, openssl_includes
     5         kx         )
     5         kx         if ssl_incs is None:
     5         kx             self.missing.extend(['_ssl', '_hashlib'])
     5         kx             return None, None
     5         kx 
     5         kx         if openssl_rpath == 'auto':
     5         kx             runtime_library_dirs = openssl_libdirs[:]
     5         kx         elif not openssl_rpath:
     5         kx             runtime_library_dirs = []
     5         kx         else:
     5         kx             runtime_library_dirs = [openssl_rpath]
     5         kx 
     5         kx         openssl_extension_kwargs = dict(
     5         kx             include_dirs=openssl_includes,
     5         kx             library_dirs=openssl_libdirs,
     5         kx             libraries=openssl_libs,
     5         kx             runtime_library_dirs=runtime_library_dirs,
     5         kx         )
     5         kx 
     5         kx         # This static linking is NOT OFFICIALLY SUPPORTED.
     5         kx         # Requires static OpenSSL build with position-independent code. Some
     5         kx         # features like DSO engines or external OSSL providers don't work.
     5         kx         # Only tested on GCC and clang on X86_64.
     5         kx         if os.environ.get("PY_UNSUPPORTED_OPENSSL_BUILD") == "static":
     5         kx             extra_linker_args = []
     5         kx             for lib in openssl_extension_kwargs["libraries"]:
     5         kx                 # link statically
     5         kx                 extra_linker_args.append(f"-l:lib{lib}.a")
     5         kx                 # don't export symbols
     5         kx                 extra_linker_args.append(f"-Wl,--exclude-libs,lib{lib}.a")
     5         kx             openssl_extension_kwargs["extra_link_args"] = extra_linker_args
     5         kx             # don't link OpenSSL shared libraries.
     5         kx             # include libz for OpenSSL build flavors with compression support
     5         kx             openssl_extension_kwargs["libraries"] = ["z"]
     5         kx 
     5         kx         self.add(
     5         kx             Extension(
     5         kx                 '_ssl',
     5         kx                 ['_ssl.c'],
     5         kx                 depends=[
     5         kx                     'socketmodule.h',
     5         kx                     '_ssl.h',
     5         kx                     '_ssl/debughelpers.c',
     5         kx                     '_ssl/misc.c',
     5         kx                     '_ssl/cert.c',
     5         kx                 ],
     5         kx                 **openssl_extension_kwargs
     5         kx             )
     5         kx         )
     5         kx         self.add(
     5         kx             Extension(
     5         kx                 '_hashlib',
     5         kx                 ['_hashopenssl.c'],
     5         kx                 depends=['hashlib.h'],
     5         kx                 **openssl_extension_kwargs,
     5         kx             )
     5         kx         )
     5         kx 
     5         kx     def detect_hash_builtins(self):
     5         kx         # By default we always compile these even when OpenSSL is available
     5         kx         # (issue #14693). It's harmless and the object code is tiny
     5         kx         # (40-50 KiB per module, only loaded when actually used).  Modules can
     5         kx         # be disabled via the --with-builtin-hashlib-hashes configure flag.
     5         kx         supported = {"md5", "sha1", "sha256", "sha512", "sha3", "blake2"}
     5         kx 
     5         kx         configured = sysconfig.get_config_var("PY_BUILTIN_HASHLIB_HASHES")
     5         kx         configured = configured.strip('"').lower()
     5         kx         configured = {
     5         kx             m.strip() for m in configured.split(",")
     5         kx         }
     5         kx 
     5         kx         self.disabled_configure.extend(
     5         kx             sorted(supported.difference(configured))
     5         kx         )
     5         kx 
     5         kx         if "sha256" in configured:
     5         kx             self.add(Extension(
     5         kx                 '_sha256', ['sha256module.c'],
     5         kx                 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
     5         kx                 depends=['hashlib.h']
     5         kx             ))
     5         kx 
     5         kx         if "sha512" in configured:
     5         kx             self.add(Extension(
     5         kx                 '_sha512', ['sha512module.c'],
     5         kx                 extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
     5         kx                 depends=['hashlib.h']
     5         kx             ))
     5         kx 
     5         kx         if "md5" in configured:
     5         kx             self.add(Extension(
     5         kx                 '_md5', ['md5module.c'],
     5         kx                 depends=['hashlib.h']
     5         kx             ))
     5         kx 
     5         kx         if "sha1" in configured:
     5         kx             self.add(Extension(
     5         kx                 '_sha1', ['sha1module.c'],
     5         kx                 depends=['hashlib.h']
     5         kx             ))
     5         kx 
     5         kx         if "blake2" in configured:
     5         kx             blake2_deps = glob(
     5         kx                 os.path.join(escape(self.srcdir), 'Modules/_blake2/impl/*')
     5         kx             )
     5         kx             blake2_deps.append('hashlib.h')
     5         kx             self.add(Extension(
     5         kx                 '_blake2',
     5         kx                 [
     5         kx                     '_blake2/blake2module.c',
     5         kx                     '_blake2/blake2b_impl.c',
     5         kx                     '_blake2/blake2s_impl.c'
     5         kx                 ],
     5         kx                 depends=blake2_deps
     5         kx             ))
     5         kx 
     5         kx         if "sha3" in configured:
     5         kx             sha3_deps = glob(
     5         kx                 os.path.join(escape(self.srcdir), 'Modules/_sha3/kcp/*')
     5         kx             )
     5         kx             sha3_deps.append('hashlib.h')
     5         kx             self.add(Extension(
     5         kx                 '_sha3',
     5         kx                 ['_sha3/sha3module.c'],
     5         kx                 depends=sha3_deps
     5         kx             ))
     5         kx 
     5         kx     def detect_nis(self):
     5         kx         if MS_WINDOWS or CYGWIN or HOST_PLATFORM == 'qnx6':
     5         kx             self.missing.append('nis')
     5         kx             return
     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', self.inc_dirs,
     5         kx             [os.path.join(inc_dir, 'nsl') for inc_dir in self.inc_dirs]
     5         kx         )
     5         kx         rpc_inc = find_file(
     5         kx             'rpc/rpc.h', self.inc_dirs,
     5         kx             [os.path.join(inc_dir, 'tirpc') for inc_dir in self.inc_dirs]
     5         kx         )
     5         kx         if rpcsvc_inc is None or rpc_inc is None:
     5         kx             # not found
     5         kx             self.missing.append('nis')
     5         kx             return
     5         kx         includes_dirs.extend(rpcsvc_inc)
     5         kx         includes_dirs.extend(rpc_inc)
     5         kx 
     5         kx         if self.compiler.find_library_file(self.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 self.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(self.lib_dirs, 'tirpc'):
     5         kx             libs.append('tirpc')
     5         kx 
     5         kx         self.add(Extension('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 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     # Customize subcommands to not install an egg-info file for Python
     5         kx     sub_commands = [('install_lib', install.has_lib),
     5         kx                     ('install_headers', install.has_headers),
     5         kx                     ('install_scripts', install.has_scripts),
     5         kx                     ('install_data', install.has_data)]
     5         kx 
     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     # this is works for EXT_SUFFIX too, which ends with SHLIB_SUFFIX
     5         kx     shlib_suffix = sysconfig.get_config_var("SHLIB_SUFFIX")
     5         kx 
     5         kx     def install(self):
     5         kx         outfiles = install_lib.install(self)
     5         kx         self.set_file_modes(outfiles, 0o644, 0o755)
     5         kx         self.set_dir_modes(self.install_dir, 0o755)
     5         kx         return outfiles
     5         kx 
     5         kx     def set_file_modes(self, files, defaultMode, sharedLibMode):
     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.shlib_suffix): 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         for dirpath, dirnames, fnames in os.walk(dirname):
     5         kx             if os.path.islink(dirpath):
     5         kx                 continue
     5         kx             log.info("changing mode of %s to %o", dirpath, mode)
     5         kx             if not self.dry_run: os.chmod(dirpath, mode)
     5         kx 
     5         kx 
     5         kx class PyBuildScripts(build_scripts):
     5         kx     def copy_scripts(self):
     5         kx         outfiles, updated_files = build_scripts.copy_scripts(self)
     5         kx         fullversion = '-{0[0]}.{0[1]}'.format(sys.version_info)
     5         kx         minoronly = '.{0[1]}'.format(sys.version_info)
     5         kx         newoutfiles = []
     5         kx         newupdated_files = []
     5         kx         for filename in outfiles:
     5         kx             if filename.endswith('2to3'):
     5         kx                 newfilename = filename + fullversion
     5         kx             else:
     5         kx                 newfilename = filename + minoronly
     5         kx             log.info(f'renaming {filename} to {newfilename}')
     5         kx             os.rename(filename, newfilename)
     5         kx             newoutfiles.append(newfilename)
     5         kx             if filename in updated_files:
     5         kx                 newupdated_files.append(newfilename)
     5         kx         return newoutfiles, newupdated_files
     5         kx 
     5         kx 
     5         kx def main():
     5         kx     global LIST_MODULE_NAMES
     5         kx 
     5         kx     if "--list-module-names" in sys.argv:
     5         kx         LIST_MODULE_NAMES = True
     5         kx         sys.argv.remove("--list-module-names")
     5         kx 
     5         kx     set_compiler_flags('CFLAGS', 'PY_CFLAGS_NODIST')
     5         kx     set_compiler_flags('LDFLAGS', 'PY_LDFLAGS_NODIST')
     5         kx 
     5         kx     class DummyProcess:
     5         kx         """Hack for parallel build"""
     5         kx         ProcessPoolExecutor = None
     5         kx 
     5         kx     sys.modules['concurrent.futures.process'] = DummyProcess
     5         kx     validate_tzpath()
     5         kx 
     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 = "https://www.python.org/%d.%d" % sys.version_info[:2],
     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 = [x for x in CLASSIFIERS.split("\n") if x],
     5         kx           platforms = ["Many"],
     5         kx 
     5         kx           # Build info
     5         kx           cmdclass = {'build_ext': PyBuildExt,
     5         kx                       'build_scripts': PyBuildScripts,
     5         kx                       '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                                  extra_compile_args=['-DPy_BUILD_CORE_MODULE'])],
     5         kx 
     5         kx           # If you change the scripts installed here, you also need to
     5         kx           # check the PyBuildScripts command above, and change the links
     5         kx           # created by the bininstall target in Makefile.pre.in
     5         kx           scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3",
     5         kx                      "Tools/scripts/2to3"]
     5         kx         )
     5         kx 
     5         kx # --install-platlib
     5         kx if __name__ == '__main__':
     5         kx     main()