Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/distutils/sysconfig.py

    r13 r391  
    1010"""
    1111
    12 __revision__ = "$Id: sysconfig.py 76739 2009-12-10 10:29:05Z ronald.oussoren $"
     12__revision__ = "$Id$"
    1313
    1414import os
     
    3838                                                os.path.pardir))
    3939
     40# set for cross builds
     41if "_PYTHON_PROJECT_BASE" in os.environ:
     42    # this is the build directory, at least for posix
     43    project_base = os.path.normpath(os.environ["_PYTHON_PROJECT_BASE"])
     44
    4045# python_build: (Boolean) if true, we're either building Python or
    4146# building an extension with an un-installed Python, so we use
     
    7277    if prefix is None:
    7378        prefix = plat_specific and EXEC_PREFIX or PREFIX
     79
    7480    if os.name == "posix":
    7581        if python_build:
    76             base = os.path.dirname(os.path.abspath(sys.executable))
     82            buildir = os.path.dirname(sys.executable)
    7783            if plat_specific:
    78                 inc_dir = base
     84                # python.h is located in the buildir
     85                inc_dir = buildir
    7986            else:
    80                 inc_dir = os.path.join(base, "Include")
    81                 if not os.path.exists(inc_dir):
    82                     inc_dir = os.path.join(os.path.dirname(base), "Include")
     87                # the source dir is relative to the buildir
     88                srcdir = os.path.abspath(os.path.join(buildir,
     89                                         get_config_var('srcdir')))
     90                # Include is located in the srcdir
     91                inc_dir = os.path.join(srcdir, "Include")
    8392            return inc_dir
    8493        return os.path.join(prefix, "include", "python" + get_python_version())
    8594    elif os.name == "nt":
    8695        return os.path.join(prefix, "include")
    87     elif os.name == "mac":
    88         if plat_specific:
    89             return os.path.join(prefix, "Mac", "Include")
    90         else:
    91             return os.path.join(prefix, "Include")
    9296    elif os.name == "os2":
    9397        if python_build:
     
    141145                return os.path.join(prefix, "Lib", "site-packages")
    142146
    143     elif os.name == "mac":
    144         if plat_specific:
    145             if standard_lib:
    146                 return os.path.join(prefix, "Lib", "lib-dynload")
    147             else:
    148                 return os.path.join(prefix, "Lib", "site-packages")
    149         else:
    150             if standard_lib:
    151                 return os.path.join(prefix, "Lib")
    152             else:
    153                 return os.path.join(prefix, "Lib", "site-packages")
    154 
    155147    elif os.name == "os2":
    156148        libpython = os.path.join(prefix,
     
    167159
    168160
     161
    169162def customize_compiler(compiler):
    170163    """Do any platform-specific customization of a CCompiler instance.
     
    174167    """
    175168    if compiler.compiler_type == "unix" or compiler.compiler_type == "emx":
    176         (cc, cxx, opt, cflags, ccshared, ldshared, so_ext) = \
     169        if sys.platform == "darwin":
     170            # Perform first-time customization of compiler-related
     171            # config vars on OS X now that we know we need a compiler.
     172            # This is primarily to support Pythons from binary
     173            # installers.  The kind and paths to build tools on
     174            # the user system may vary significantly from the system
     175            # that Python itself was built on.  Also the user OS
     176            # version and build tools may not support the same set
     177            # of CPU architectures for universal builds.
     178            global _config_vars
     179            if not _config_vars.get('CUSTOMIZED_OSX_COMPILER', ''):
     180                import _osx_support
     181                _osx_support.customize_compiler(_config_vars)
     182                _config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'
     183
     184        (cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \
    177185            get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
    178                             'CCSHARED', 'LDSHARED', 'SO')
     186                            'CCSHARED', 'LDSHARED', 'SO', 'AR',
     187                            'ARFLAGS')
    179188
    180189        if 'CC' in os.environ:
    181             cc = os.environ['CC']
     190            newcc = os.environ['CC']
     191            if (sys.platform == 'darwin'
     192                    and 'LDSHARED' not in os.environ
     193                    and ldshared.startswith(cc)):
     194                # On OS X, if CC is overridden, use that as the default
     195                #       command for LDSHARED as well
     196                ldshared = newcc + ldshared[len(cc):]
     197            cc = newcc
    182198        if 'CXX' in os.environ:
    183199            cxx = os.environ['CXX']
     
    197213            cflags = cflags + ' ' + os.environ['CPPFLAGS']
    198214            ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
     215        if 'AR' in os.environ:
     216            ar = os.environ['AR']
     217        if 'ARFLAGS' in os.environ:
     218            archiver = ar + ' ' + os.environ['ARFLAGS']
     219        else:
     220            archiver = ar + ' ' + ar_flags
    199221
    200222        cc_cmd = cc + ' ' + cflags
     
    205227            compiler_cxx=cxx,
    206228            linker_so=ldshared,
    207             linker_exe=cc)
     229            linker_exe=cc,
     230            archiver=archiver)
    208231
    209232        compiler.shared_lib_extension = so_ext
     
    230253    """Return full pathname of installed Makefile from the Python build."""
    231254    if python_build:
    232         return os.path.join(os.path.dirname(sys.executable), "Makefile")
     255        return os.path.join(project_base, "Makefile")
    233256    lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
    234257    return os.path.join(lib_dir, "config", "Makefile")
     
    343366    fp.close()
    344367
     368    # strip spurious spaces
     369    for k, v in done.items():
     370        if isinstance(v, str):
     371            done[k] = v.strip()
     372
    345373    # save the results in the global dictionary
    346374    g.update(done)
     
    377405def _init_posix():
    378406    """Initialize the module as appropriate for POSIX systems."""
    379     g = {}
    380     # load the installed Makefile:
    381     try:
    382         filename = get_makefile_filename()
    383         parse_makefile(filename, g)
    384     except IOError, msg:
    385         my_msg = "invalid Python installation: unable to open %s" % filename
    386         if hasattr(msg, "strerror"):
    387             my_msg = my_msg + " (%s)" % msg.strerror
    388 
    389         raise DistutilsPlatformError(my_msg)
    390 
    391     # load the installed pyconfig.h:
    392     try:
    393         filename = get_config_h_filename()
    394         parse_config_h(file(filename), g)
    395     except IOError, msg:
    396         my_msg = "invalid Python installation: unable to open %s" % filename
    397         if hasattr(msg, "strerror"):
    398             my_msg = my_msg + " (%s)" % msg.strerror
    399 
    400         raise DistutilsPlatformError(my_msg)
    401 
    402     # On MacOSX we need to check the setting of the environment variable
    403     # MACOSX_DEPLOYMENT_TARGET: configure bases some choices on it so
    404     # it needs to be compatible.
    405     # If it isn't set we set it to the configure-time value
    406     if sys.platform == 'darwin' and 'MACOSX_DEPLOYMENT_TARGET' in g:
    407         cfg_target = g['MACOSX_DEPLOYMENT_TARGET']
    408         cur_target = os.getenv('MACOSX_DEPLOYMENT_TARGET', '')
    409         if cur_target == '':
    410             cur_target = cfg_target
    411             os.putenv('MACOSX_DEPLOYMENT_TARGET', cfg_target)
    412         elif map(int, cfg_target.split('.')) > map(int, cur_target.split('.')):
    413             my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: now "%s" but "%s" during configure'
    414                 % (cur_target, cfg_target))
    415             raise DistutilsPlatformError(my_msg)
    416 
    417     # On AIX, there are wrong paths to the linker scripts in the Makefile
    418     # -- these paths are relative to the Python source, but when installed
    419     # the scripts are in another directory.
    420     if python_build:
    421         g['LDSHARED'] = g['BLDSHARED']
    422 
    423     elif get_python_version() < '2.1':
    424         # The following two branches are for 1.5.2 compatibility.
    425         if sys.platform == 'aix4':          # what about AIX 3.x ?
    426             # Linker script is in the config directory, not in Modules as the
    427             # Makefile says.
    428             python_lib = get_python_lib(standard_lib=1)
    429             ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
    430             python_exp = os.path.join(python_lib, 'config', 'python.exp')
    431 
    432             g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp)
    433 
    434         elif sys.platform == 'beos':
    435             # Linker script is in the config directory.  In the Makefile it is
    436             # relative to the srcdir, which after installation no longer makes
    437             # sense.
    438             python_lib = get_python_lib(standard_lib=1)
    439             linkerscript_path = string.split(g['LDSHARED'])[0]
    440             linkerscript_name = os.path.basename(linkerscript_path)
    441             linkerscript = os.path.join(python_lib, 'config',
    442                                         linkerscript_name)
    443 
    444             # XXX this isn't the right place to do this: adding the Python
    445             # library to the link, if needed, should be in the "build_ext"
    446             # command.  (It's also needed for non-MS compilers on Windows, and
    447             # it's taken care of for them by the 'build_ext.get_libraries()'
    448             # method.)
    449             g['LDSHARED'] = ("%s -L%s/lib -lpython%s" %
    450                              (linkerscript, PREFIX, get_python_version()))
    451 
     407    # _sysconfigdata is generated at build time, see the sysconfig module
     408    from _sysconfigdata import build_time_vars
    452409    global _config_vars
    453     _config_vars = g
     410    _config_vars = {}
     411    _config_vars.update(build_time_vars)
    454412
    455413
     
    469427    g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
    470428
    471     global _config_vars
    472     _config_vars = g
    473 
    474 
    475 def _init_mac():
    476     """Initialize the module as appropriate for Macintosh systems"""
    477     g = {}
    478     # set basic install directories
    479     g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
    480     g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
    481 
    482     # XXX hmmm.. a normal install puts include files here
    483     g['INCLUDEPY'] = get_python_inc(plat_specific=0)
    484 
    485     import MacOS
    486     if not hasattr(MacOS, 'runtimemodel'):
    487         g['SO'] = '.ppc.slb'
    488     else:
    489         g['SO'] = '.%s.slb' % MacOS.runtimemodel
    490 
    491     # XXX are these used anywhere?
    492     g['install_lib'] = os.path.join(EXEC_PREFIX, "Lib")
    493     g['install_platlib'] = os.path.join(EXEC_PREFIX, "Mac", "Lib")
    494 
    495     # These are used by the extension module build
    496     g['srcdir'] = ':'
    497429    global _config_vars
    498430    _config_vars = g
     
    570502        _config_vars['exec_prefix'] = EXEC_PREFIX
    571503
     504        # OS X platforms require special customization to handle
     505        # multi-architecture, multi-os-version installers
    572506        if sys.platform == 'darwin':
    573             kernel_version = os.uname()[2] # Kernel version (8.4.3)
    574             major_version = int(kernel_version.split('.')[0])
    575 
    576             if major_version < 8:
    577                 # On Mac OS X before 10.4, check if -arch and -isysroot
    578                 # are in CFLAGS or LDFLAGS and remove them if they are.
    579                 # This is needed when building extensions on a 10.3 system
    580                 # using a universal build of python.
    581                 for key in ('LDFLAGS', 'BASECFLAGS', 'LDSHARED',
    582                         # a number of derived variables. These need to be
    583                         # patched up as well.
    584                         'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
    585                     flags = _config_vars[key]
    586                     flags = re.sub('-arch\s+\w+\s', ' ', flags)
    587                     flags = re.sub('-isysroot [^ \t]*', ' ', flags)
    588                     _config_vars[key] = flags
    589 
    590             else:
    591 
    592                 # Allow the user to override the architecture flags using
    593                 # an environment variable.
    594                 # NOTE: This name was introduced by Apple in OSX 10.5 and
    595                 # is used by several scripting languages distributed with
    596                 # that OS release.
    597 
    598                 if 'ARCHFLAGS' in os.environ:
    599                     arch = os.environ['ARCHFLAGS']
    600                     for key in ('LDFLAGS', 'BASECFLAGS', 'LDSHARED',
    601                         # a number of derived variables. These need to be
    602                         # patched up as well.
    603                         'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
    604 
    605                         flags = _config_vars[key]
    606                         flags = re.sub('-arch\s+\w+\s', ' ', flags)
    607                         flags = flags + ' ' + arch
    608                         _config_vars[key] = flags
    609 
    610                 # If we're on OSX 10.5 or later and the user tries to
    611                 # compiles an extension using an SDK that is not present
    612                 # on the current machine it is better to not use an SDK
    613                 # than to fail.
    614                 #
    615                 # The major usecase for this is users using a Python.org
    616                 # binary installer  on OSX 10.6: that installer uses
    617                 # the 10.4u SDK, but that SDK is not installed by default
    618                 # when you install Xcode.
    619                 #
    620                 m = re.search('-isysroot\s+(\S+)', _config_vars['CFLAGS'])
    621                 if m is not None:
    622                     sdk = m.group(1)
    623                     if not os.path.exists(sdk):
    624                         for key in ('LDFLAGS', 'BASECFLAGS', 'LDSHARED',
    625                              # a number of derived variables. These need to be
    626                              # patched up as well.
    627                             'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
    628 
    629                             flags = _config_vars[key]
    630                             flags = re.sub('-isysroot\s+\S+(\s|$)', ' ', flags)
    631                             _config_vars[key] = flags
     507            import _osx_support
     508            _osx_support.customize_config_vars(_config_vars)
    632509
    633510    if args:
Note: See TracChangeset for help on using the changeset viewer.