home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / lib / python2.6 / distutils / sysconfig.py < prev    next >
Encoding:
Python Source  |  2010-12-26  |  22.9 KB  |  621 lines

  1. """Provide access to Python's configuration information.  The specific
  2. configuration variables available depend heavily on the platform and
  3. configuration.  The values may be retrieved using
  4. get_config_var(name), and the list of variables is available via
  5. get_config_vars().keys().  Additional convenience functions are also
  6. available.
  7.  
  8. Written by:   Fred L. Drake, Jr.
  9. Email:        <fdrake@acm.org>
  10. """
  11.  
  12. __revision__ = "$Id: sysconfig.py 83688 2010-08-03 21:18:06Z mark.dickinson $"
  13.  
  14. import os
  15. import re
  16. import string
  17. import sys
  18.  
  19. from distutils.errors import DistutilsPlatformError
  20.  
  21. # These are needed in a couple of spots, so just compute them once.
  22. PREFIX = os.path.normpath(sys.prefix)
  23. EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
  24.  
  25. # Path to the base directory of the project. On Windows the binary may
  26. # live in project/PCBuild9.  If we're dealing with an x64 Windows build,
  27. # it'll live in project/PCbuild/amd64.
  28. project_base = os.path.dirname(os.path.realpath(sys.executable))
  29. if os.name == "nt" and "pcbuild" in project_base[-8:].lower():
  30.     project_base = os.path.abspath(os.path.join(project_base, os.path.pardir))
  31. # PC/VS7.1
  32. if os.name == "nt" and "\\pc\\v" in project_base[-10:].lower():
  33.     project_base = os.path.abspath(os.path.join(project_base, os.path.pardir,
  34.                                                 os.path.pardir))
  35. # PC/AMD64
  36. if os.name == "nt" and "\\pcbuild\\amd64" in project_base[-14:].lower():
  37.     project_base = os.path.abspath(os.path.join(project_base, os.path.pardir,
  38.                                                 os.path.pardir))
  39.  
  40. # python_build: (Boolean) if true, we're either building Python or
  41. # building an extension with an un-installed Python, so we use
  42. # different (hard-wired) directories.
  43. # Setup.local is available for Makefile builds including VPATH builds,
  44. # Setup.dist is available on Windows
  45. def _python_build():
  46.     for fn in ("Setup.dist", "Setup.local"):
  47.         if os.path.isfile(os.path.join(project_base, "Modules", fn)):
  48.             return True
  49.     return False
  50. python_build = _python_build()
  51.  
  52.  
  53. def get_python_version():
  54.     """Return a string containing the major and minor Python version,
  55.     leaving off the patchlevel.  Sample return values could be '1.5'
  56.     or '2.2'.
  57.     """
  58.     return sys.version[:3]
  59.  
  60.  
  61. def get_python_inc(plat_specific=0, prefix=None):
  62.     """Return the directory containing installed Python header files.
  63.  
  64.     If 'plat_specific' is false (the default), this is the path to the
  65.     non-platform-specific header files, i.e. Python.h and so on;
  66.     otherwise, this is the path to platform-specific header files
  67.     (namely pyconfig.h).
  68.  
  69.     If 'prefix' is supplied, use it instead of sys.prefix or
  70.     sys.exec_prefix -- i.e., ignore 'plat_specific'.
  71.     """
  72.     if prefix is None:
  73.         prefix = plat_specific and EXEC_PREFIX or PREFIX
  74.  
  75.     if os.name == "posix":
  76.         if python_build:
  77.             buildir = os.path.dirname(os.path.realpath(sys.executable))
  78.             if plat_specific:
  79.                 # python.h is located in the buildir
  80.                 inc_dir = buildir
  81.             else:
  82.                 # the source dir is relative to the buildir
  83.                 srcdir = os.path.abspath(os.path.join(buildir,
  84.                                          get_config_var('srcdir')))
  85.                 # Include is located in the srcdir
  86.                 inc_dir = os.path.join(srcdir, "Include")
  87.             return inc_dir
  88.         return os.path.join(prefix, "include",
  89.                             "python" + get_python_version() + (sys.pydebug and '_d' or ''))
  90.     elif os.name == "nt":
  91.         return os.path.join(prefix, "include")
  92.     elif os.name == "mac":
  93.         if plat_specific:
  94.             return os.path.join(prefix, "Mac", "Include")
  95.         else:
  96.             return os.path.join(prefix, "Include")
  97.     elif os.name == "os2":
  98.         return os.path.join(prefix, "Include")
  99.     else:
  100.         raise DistutilsPlatformError(
  101.             "I don't know where Python installs its C header files "
  102.             "on platform '%s'" % os.name)
  103.  
  104.  
  105. def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
  106.     """Return the directory containing the Python library (standard or
  107.     site additions).
  108.  
  109.     If 'plat_specific' is true, return the directory containing
  110.     platform-specific modules, i.e. any module from a non-pure-Python
  111.     module distribution; otherwise, return the platform-shared library
  112.     directory.  If 'standard_lib' is true, return the directory
  113.     containing standard Python library modules; otherwise, return the
  114.     directory for site-specific modules.
  115.  
  116.     If 'prefix' is supplied, use it instead of sys.prefix or
  117.     sys.exec_prefix -- i.e., ignore 'plat_specific'.
  118.     """
  119.     is_default_prefix = not prefix or os.path.normpath(prefix) in ('/usr', '/usr/local')
  120.     if prefix is None:
  121.         prefix = plat_specific and EXEC_PREFIX or PREFIX
  122.  
  123.     if os.name == "posix":
  124.         libpython = os.path.join(prefix,
  125.                                  "lib", "python" + get_python_version())
  126.         if standard_lib:
  127.             return libpython
  128.         elif is_default_prefix and 'PYTHONUSERBASE' not in os.environ and 'real_prefix' not in sys.__dict__:
  129.             return os.path.join(libpython, "dist-packages")
  130.         else:
  131.             return os.path.join(libpython, "site-packages")
  132.  
  133.     elif os.name == "nt":
  134.         if standard_lib:
  135.             return os.path.join(prefix, "Lib")
  136.         else:
  137.             if get_python_version() < "2.2":
  138.                 return prefix
  139.             else:
  140.                 return os.path.join(prefix, "Lib", "site-packages")
  141.  
  142.     elif os.name == "mac":
  143.         if plat_specific:
  144.             if standard_lib:
  145.                 return os.path.join(prefix, "Lib", "lib-dynload")
  146.             else:
  147.                 return os.path.join(prefix, "Lib", "site-packages")
  148.         else:
  149.             if standard_lib:
  150.                 return os.path.join(prefix, "Lib")
  151.             else:
  152.                 return os.path.join(prefix, "Lib", "site-packages")
  153.  
  154.     elif os.name == "os2":
  155.         if standard_lib:
  156.             return os.path.join(prefix, "Lib")
  157.         else:
  158.             return os.path.join(prefix, "Lib", "site-packages")
  159.  
  160.     else:
  161.         raise DistutilsPlatformError(
  162.             "I don't know where Python installs its library "
  163.             "on platform '%s'" % os.name)
  164.  
  165.  
  166. def customize_compiler(compiler):
  167.     """Do any platform-specific customization of a CCompiler instance.
  168.  
  169.     Mainly needed on Unix, so we can plug in the information that
  170.     varies across Unices and is stored in Python's Makefile.
  171.     """
  172.     if compiler.compiler_type == "unix":
  173.         (cc, cxx, opt, cflags, opt, extra_cflags, basecflags, ccshared, ldshared, so_ext) = \
  174.             get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
  175.                             'OPT', 'EXTRA_CFLAGS', 'BASECFLAGS',
  176.                             'CCSHARED', 'LDSHARED', 'SO')
  177.  
  178.         if 'CC' in os.environ:
  179.             cc = os.environ['CC']
  180.         if 'CXX' in os.environ:
  181.             cxx = os.environ['CXX']
  182.         if 'LDSHARED' in os.environ:
  183.             ldshared = os.environ['LDSHARED']
  184.         if 'CPP' in os.environ:
  185.             cpp = os.environ['CPP']
  186.         else:
  187.             cpp = cc + " -E"           # not always
  188.         if 'LDFLAGS' in os.environ:
  189.             ldshared = ldshared + ' ' + os.environ['LDFLAGS']
  190.         if 'BASECFLAGS' in os.environ:
  191.             basecflags = os.environ['BASECFLAGS']
  192.         if 'OPT' in os.environ:
  193.             opt = os.environ['OPT']
  194.         cflags = ' '.join(str(x) for x in (basecflags, opt, extra_cflags) if x)
  195.         if 'CFLAGS' in os.environ:
  196.             cflags = ' '.join(str(x) for x in (basecflags, opt, os.environ['CFLAGS'], extra_cflags) if x)
  197.             ldshared = ldshared + ' ' + os.environ['CFLAGS']
  198.         if 'CPPFLAGS' in os.environ:
  199.             cpp = cpp + ' ' + os.environ['CPPFLAGS']
  200.             cflags = cflags + ' ' + os.environ['CPPFLAGS']
  201.             ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
  202.  
  203.         cc_cmd = cc + ' ' + cflags
  204.         compiler.set_executables(
  205.             preprocessor=cpp,
  206.             compiler=cc_cmd,
  207.             compiler_so=cc_cmd + ' ' + ccshared,
  208.             compiler_cxx=cxx,
  209.             linker_so=ldshared,
  210.             linker_exe=cc)
  211.  
  212.         compiler.shared_lib_extension = so_ext
  213.  
  214.  
  215. def get_config_h_filename():
  216.     """Return full pathname of installed pyconfig.h file."""
  217.     if python_build:
  218.         if os.name == "nt":
  219.             inc_dir = os.path.join(project_base, "PC")
  220.         else:
  221.             inc_dir = project_base
  222.     else:
  223.         inc_dir = get_python_inc(plat_specific=1)
  224.     if get_python_version() < '2.2':
  225.         config_h = 'config.h'
  226.     else:
  227.         # The name of the config.h file changed in 2.2
  228.         config_h = 'pyconfig.h'
  229.     return os.path.join(inc_dir, config_h)
  230.  
  231.  
  232. def get_makefile_filename():
  233.     """Return full pathname of installed Makefile from the Python build."""
  234.     if python_build:
  235.         return os.path.join(os.path.dirname(os.path.realpath(sys.executable)),
  236.                             "Makefile")
  237.     lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
  238.     return os.path.join(lib_dir, "config" + (sys.pydebug and "_d" or ""), "Makefile")
  239.  
  240.  
  241. def parse_config_h(fp, g=None):
  242.     """Parse a config.h-style file.
  243.  
  244.     A dictionary containing name/value pairs is returned.  If an
  245.     optional dictionary is passed in as the second argument, it is
  246.     used instead of a new dictionary.
  247.     """
  248.     if g is None:
  249.         g = {}
  250.     define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
  251.     undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n")
  252.     #
  253.     while 1:
  254.         line = fp.readline()
  255.         if not line:
  256.             break
  257.         m = define_rx.match(line)
  258.         if m:
  259.             n, v = m.group(1, 2)
  260.             try: v = int(v)
  261.             except ValueError: pass
  262.             g[n] = v
  263.         else:
  264.             m = undef_rx.match(line)
  265.             if m:
  266.                 g[m.group(1)] = 0
  267.     return g
  268.  
  269.  
  270. # Regexes needed for parsing Makefile (and similar syntaxes,
  271. # like old-style Setup files).
  272. _variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
  273. _findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
  274. _findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
  275.  
  276. def parse_makefile(fn, g=None):
  277.     """Parse a Makefile-style file.
  278.  
  279.     A dictionary containing name/value pairs is returned.  If an
  280.     optional dictionary is passed in as the second argument, it is
  281.     used instead of a new dictionary.
  282.     """
  283.     from distutils.text_file import TextFile
  284.     fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1)
  285.  
  286.     if g is None:
  287.         g = {}
  288.     done = {}
  289.     notdone = {}
  290.  
  291.     while 1:
  292.         line = fp.readline()
  293.         if line is None:  # eof
  294.             break
  295.         m = _variable_rx.match(line)
  296.         if m:
  297.             n, v = m.group(1, 2)
  298.             v = v.strip()
  299.             # `$$' is a literal `$' in make
  300.             tmpv = v.replace('$$', '')
  301.  
  302.             if "$" in tmpv:
  303.                 notdone[n] = v
  304.             else:
  305.                 try:
  306.                     v = int(v)
  307.                 except ValueError:
  308.                     # insert literal `$'
  309.                     done[n] = v.replace('$$', '$')
  310.                 else:
  311.                     done[n] = v
  312.  
  313.     # do variable interpolation here
  314.     while notdone:
  315.         for name in notdone.keys():
  316.             value = notdone[name]
  317.             m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
  318.             if m:
  319.                 n = m.group(1)
  320.                 found = True
  321.                 if n in done:
  322.                     item = str(done[n])
  323.                 elif n in notdone:
  324.                     # get it on a subsequent round
  325.                     found = False
  326.                 elif n in os.environ:
  327.                     # do it like make: fall back to environment
  328.                     item = os.environ[n]
  329.                 else:
  330.                     done[n] = item = ""
  331.                 if found:
  332.                     after = value[m.end():]
  333.                     value = value[:m.start()] + item + after
  334.                     if "$" in after:
  335.                         notdone[name] = value
  336.                     else:
  337.                         try: value = int(value)
  338.                         except ValueError:
  339.                             done[name] = value.strip()
  340.                         else:
  341.                             done[name] = value
  342.                         del notdone[name]
  343.             else:
  344.                 # bogus variable reference; just drop it since we can't deal
  345.                 del notdone[name]
  346.  
  347.     fp.close()
  348.  
  349.     # save the results in the global dictionary
  350.     g.update(done)
  351.     return g
  352.  
  353.  
  354. def expand_makefile_vars(s, vars):
  355.     """Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
  356.     'string' according to 'vars' (a dictionary mapping variable names to
  357.     values).  Variables not present in 'vars' are silently expanded to the
  358.     empty string.  The variable values in 'vars' should not contain further
  359.     variable expansions; if 'vars' is the output of 'parse_makefile()',
  360.     you're fine.  Returns a variable-expanded version of 's'.
  361.     """
  362.  
  363.     # This algorithm does multiple expansion, so if vars['foo'] contains
  364.     # "${bar}", it will expand ${foo} to ${bar}, and then expand
  365.     # ${bar}... and so forth.  This is fine as long as 'vars' comes from
  366.     # 'parse_makefile()', which takes care of such expansions eagerly,
  367.     # according to make's variable expansion semantics.
  368.  
  369.     while 1:
  370.         m = _findvar1_rx.search(s) or _findvar2_rx.search(s)
  371.         if m:
  372.             (beg, end) = m.span()
  373.             s = s[0:beg] + vars.get(m.group(1)) + s[end:]
  374.         else:
  375.             break
  376.     return s
  377.  
  378.  
  379. _config_vars = None
  380.  
  381. def _init_posix():
  382.     """Initialize the module as appropriate for POSIX systems."""
  383.     g = {}
  384.     # load the installed Makefile:
  385.     try:
  386.         filename = get_makefile_filename()
  387.         parse_makefile(filename, g)
  388.     except IOError, msg:
  389.         my_msg = "invalid Python installation: unable to open %s" % filename
  390.         if hasattr(msg, "strerror"):
  391.             my_msg = my_msg + " (%s)" % msg.strerror
  392.  
  393.         raise DistutilsPlatformError(my_msg)
  394.  
  395.     # load the installed pyconfig.h:
  396.     try:
  397.         filename = get_config_h_filename()
  398.         parse_config_h(file(filename), g)
  399.     except IOError, msg:
  400.         my_msg = "invalid Python installation: unable to open %s" % filename
  401.         if hasattr(msg, "strerror"):
  402.             my_msg = my_msg + " (%s)" % msg.strerror
  403.  
  404.         raise DistutilsPlatformError(my_msg)
  405.  
  406.     # On MacOSX we need to check the setting of the environment variable
  407.     # MACOSX_DEPLOYMENT_TARGET: configure bases some choices on it so
  408.     # it needs to be compatible.
  409.     # If it isn't set we set it to the configure-time value
  410.     if sys.platform == 'darwin' and 'MACOSX_DEPLOYMENT_TARGET' in g:
  411.         cfg_target = g['MACOSX_DEPLOYMENT_TARGET']
  412.         cur_target = os.getenv('MACOSX_DEPLOYMENT_TARGET', '')
  413.         if cur_target == '':
  414.             cur_target = cfg_target
  415.             os.putenv('MACOSX_DEPLOYMENT_TARGET', cfg_target)
  416.         elif map(int, cfg_target.split('.')) > map(int, cur_target.split('.')):
  417.             my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: now "%s" but "%s" during configure'
  418.                 % (cur_target, cfg_target))
  419.             raise DistutilsPlatformError(my_msg)
  420.  
  421.     # On AIX, there are wrong paths to the linker scripts in the Makefile
  422.     # -- these paths are relative to the Python source, but when installed
  423.     # the scripts are in another directory.
  424.     if python_build:
  425.         g['LDSHARED'] = g['BLDSHARED']
  426.  
  427.     elif get_python_version() < '2.1':
  428.         # The following two branches are for 1.5.2 compatibility.
  429.         if sys.platform == 'aix4':          # what about AIX 3.x ?
  430.             # Linker script is in the config directory, not in Modules as the
  431.             # Makefile says.
  432.             python_lib = get_python_lib(standard_lib=1)
  433.             ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
  434.             python_exp = os.path.join(python_lib, 'config', 'python.exp')
  435.  
  436.             g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp)
  437.  
  438.         elif sys.platform == 'beos':
  439.             # Linker script is in the config directory.  In the Makefile it is
  440.             # relative to the srcdir, which after installation no longer makes
  441.             # sense.
  442.             python_lib = get_python_lib(standard_lib=1)
  443.             linkerscript_path = string.split(g['LDSHARED'])[0]
  444.             linkerscript_name = os.path.basename(linkerscript_path)
  445.             linkerscript = os.path.join(python_lib, 'config',
  446.                                         linkerscript_name)
  447.  
  448.             # XXX this isn't the right place to do this: adding the Python
  449.             # library to the link, if needed, should be in the "build_ext"
  450.             # command.  (It's also needed for non-MS compilers on Windows, and
  451.             # it's taken care of for them by the 'build_ext.get_libraries()'
  452.             # method.)
  453.             g['LDSHARED'] = ("%s -L%s/lib -lpython%s" %
  454.                              (linkerscript, PREFIX, get_python_version()))
  455.  
  456.     global _config_vars
  457.     _config_vars = g
  458.  
  459.  
  460. def _init_nt():
  461.     """Initialize the module as appropriate for NT"""
  462.     g = {}
  463.     # set basic install directories
  464.     g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
  465.     g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
  466.  
  467.     # XXX hmmm.. a normal install puts include files here
  468.     g['INCLUDEPY'] = get_python_inc(plat_specific=0)
  469.  
  470.     g['SO'] = '.pyd'
  471.     g['EXE'] = ".exe"
  472.     g['VERSION'] = get_python_version().replace(".", "")
  473.     g['BINDIR'] = os.path.dirname(os.path.realpath(sys.executable))
  474.  
  475.     global _config_vars
  476.     _config_vars = g
  477.  
  478.  
  479. def _init_mac():
  480.     """Initialize the module as appropriate for Macintosh systems"""
  481.     g = {}
  482.     # set basic install directories
  483.     g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
  484.     g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
  485.  
  486.     # XXX hmmm.. a normal install puts include files here
  487.     g['INCLUDEPY'] = get_python_inc(plat_specific=0)
  488.  
  489.     import MacOS
  490.     if not hasattr(MacOS, 'runtimemodel'):
  491.         g['SO'] = '.ppc.slb'
  492.     else:
  493.         g['SO'] = '.%s.slb' % MacOS.runtimemodel
  494.  
  495.     # XXX are these used anywhere?
  496.     g['install_lib'] = os.path.join(EXEC_PREFIX, "Lib")
  497.     g['install_platlib'] = os.path.join(EXEC_PREFIX, "Mac", "Lib")
  498.  
  499.     # These are used by the extension module build
  500.     g['srcdir'] = ':'
  501.     global _config_vars
  502.     _config_vars = g
  503.  
  504.  
  505. def _init_os2():
  506.     """Initialize the module as appropriate for OS/2"""
  507.     g = {}
  508.     # set basic install directories
  509.     g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
  510.     g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
  511.  
  512.     # XXX hmmm.. a normal install puts include files here
  513.     g['INCLUDEPY'] = get_python_inc(plat_specific=0)
  514.  
  515.     g['SO'] = '.pyd'
  516.     g['EXE'] = ".exe"
  517.  
  518.     global _config_vars
  519.     _config_vars = g
  520.  
  521.  
  522. def get_config_vars(*args):
  523.     """With no arguments, return a dictionary of all configuration
  524.     variables relevant for the current platform.  Generally this includes
  525.     everything needed to build extensions and install both pure modules and
  526.     extensions.  On Unix, this means every variable defined in Python's
  527.     installed Makefile; on Windows and Mac OS it's a much smaller set.
  528.  
  529.     With arguments, return a list of values that result from looking up
  530.     each argument in the configuration variable dictionary.
  531.     """
  532.     global _config_vars
  533.     if _config_vars is None:
  534.         func = globals().get("_init_" + os.name)
  535.         if func:
  536.             func()
  537.         else:
  538.             _config_vars = {}
  539.  
  540.         # Normalized versions of prefix and exec_prefix are handy to have;
  541.         # in fact, these are the standard versions used most places in the
  542.         # Distutils.
  543.         _config_vars['prefix'] = PREFIX
  544.         _config_vars['exec_prefix'] = EXEC_PREFIX
  545.  
  546.         if sys.platform == 'darwin':
  547.             kernel_version = os.uname()[2] # Kernel version (8.4.3)
  548.             major_version = int(kernel_version.split('.')[0])
  549.  
  550.             if major_version < 8:
  551.                 # On Mac OS X before 10.4, check if -arch and -isysroot
  552.                 # are in CFLAGS or LDFLAGS and remove them if they are.
  553.                 # This is needed when building extensions on a 10.3 system
  554.                 # using a universal build of python.
  555.                 for key in ('LDFLAGS', 'BASECFLAGS', 'LDSHARED',
  556.                         # a number of derived variables. These need to be
  557.                         # patched up as well.
  558.                         'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
  559.                     flags = _config_vars[key]
  560.                     flags = re.sub('-arch\s+\w+\s', ' ', flags)
  561.                     flags = re.sub('-isysroot [^ \t]*', ' ', flags)
  562.                     _config_vars[key] = flags
  563.  
  564.             else:
  565.  
  566.                 # Allow the user to override the architecture flags using
  567.                 # an environment variable.
  568.                 # NOTE: This name was introduced by Apple in OSX 10.5 and
  569.                 # is used by several scripting languages distributed with
  570.                 # that OS release.
  571.  
  572.                 if 'ARCHFLAGS' in os.environ:
  573.                     arch = os.environ['ARCHFLAGS']
  574.                     for key in ('LDFLAGS', 'BASECFLAGS', 'LDSHARED',
  575.                         # a number of derived variables. These need to be
  576.                         # patched up as well.
  577.                         'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
  578.  
  579.                         flags = _config_vars[key]
  580.                         flags = re.sub('-arch\s+\w+\s', ' ', flags)
  581.                         flags = flags + ' ' + arch
  582.                         _config_vars[key] = flags
  583.  
  584.                 # If we're on OSX 10.5 or later and the user tries to
  585.                 # compiles an extension using an SDK that is not present
  586.                 # on the current machine it is better to not use an SDK
  587.                 # than to fail.
  588.                 #
  589.                 # The major usecase for this is users using a Python.org
  590.                 # binary installer  on OSX 10.6: that installer uses
  591.                 # the 10.4u SDK, but that SDK is not installed by default
  592.                 # when you install Xcode.
  593.                 #
  594.                 m = re.search('-isysroot\s+(\S+)', _config_vars['CFLAGS'])
  595.                 if m is not None:
  596.                     sdk = m.group(1)
  597.                     if not os.path.exists(sdk):
  598.                         for key in ('LDFLAGS', 'BASECFLAGS', 'LDSHARED',
  599.                              # a number of derived variables. These need to be
  600.                              # patched up as well.
  601.                             'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
  602.  
  603.                             flags = _config_vars[key]
  604.                             flags = re.sub('-isysroot\s+\S+(\s|$)', ' ', flags)
  605.                             _config_vars[key] = flags
  606.  
  607.     if args:
  608.         vals = []
  609.         for name in args:
  610.             vals.append(_config_vars.get(name))
  611.         return vals
  612.     else:
  613.         return _config_vars
  614.  
  615. def get_config_var(name):
  616.     """Return the value of a single variable using the dictionary
  617.     returned by 'get_config_vars()'.  Equivalent to
  618.     get_config_vars().get(name)
  619.     """
  620.     return get_config_vars().get(name)
  621.