~ubuntu-branches/ubuntu/trusty/python3.4/trusty-proposed

« back to all changes in this revision

Viewing changes to Lib/distutils/sysconfig.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-11-25 09:44:27 UTC
  • Revision ID: package-import@ubuntu.com-20131125094427-lzxj8ap5w01lmo7f
Tags: upstream-3.4~b1
ImportĀ upstreamĀ versionĀ 3.4~b1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
import os
 
13
import re
 
14
import sys
 
15
 
 
16
from .errors import DistutilsPlatformError
 
17
 
 
18
# These are needed in a couple of spots, so just compute them once.
 
19
PREFIX = os.path.normpath(sys.prefix)
 
20
EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
 
21
BASE_PREFIX = os.path.normpath(sys.base_prefix)
 
22
BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
 
23
 
 
24
# Path to the base directory of the project. On Windows the binary may
 
25
# live in project/PCBuild9.  If we're dealing with an x64 Windows build,
 
26
# it'll live in project/PCbuild/amd64.
 
27
# set for cross builds
 
28
if "_PYTHON_PROJECT_BASE" in os.environ:
 
29
    project_base = os.path.abspath(os.environ["_PYTHON_PROJECT_BASE"])
 
30
else:
 
31
    project_base = os.path.dirname(os.path.abspath(sys.executable))
 
32
if os.name == "nt" and "pcbuild" in project_base[-8:].lower():
 
33
    project_base = os.path.abspath(os.path.join(project_base, os.path.pardir))
 
34
# PC/VS7.1
 
35
if os.name == "nt" and "\\pc\\v" in project_base[-10:].lower():
 
36
    project_base = os.path.abspath(os.path.join(project_base, os.path.pardir,
 
37
                                                os.path.pardir))
 
38
# PC/AMD64
 
39
if os.name == "nt" and "\\pcbuild\\amd64" in project_base[-14:].lower():
 
40
    project_base = os.path.abspath(os.path.join(project_base, os.path.pardir,
 
41
                                                os.path.pardir))
 
42
 
 
43
# python_build: (Boolean) if true, we're either building Python or
 
44
# building an extension with an un-installed Python, so we use
 
45
# different (hard-wired) directories.
 
46
# Setup.local is available for Makefile builds including VPATH builds,
 
47
# Setup.dist is available on Windows
 
48
def _is_python_source_dir(d):
 
49
    for fn in ("Setup.dist", "Setup.local"):
 
50
        if os.path.isfile(os.path.join(d, "Modules", fn)):
 
51
            return True
 
52
    return False
 
53
_sys_home = getattr(sys, '_home', None)
 
54
if _sys_home and os.name == 'nt' and \
 
55
    _sys_home.lower().endswith(('pcbuild', 'pcbuild\\amd64')):
 
56
    _sys_home = os.path.dirname(_sys_home)
 
57
    if _sys_home.endswith('pcbuild'):   # must be amd64
 
58
        _sys_home = os.path.dirname(_sys_home)
 
59
def _python_build():
 
60
    if _sys_home:
 
61
        return _is_python_source_dir(_sys_home)
 
62
    return _is_python_source_dir(project_base)
 
63
python_build = _python_build()
 
64
 
 
65
# Calculate the build qualifier flags if they are defined.  Adding the flags
 
66
# to the include and lib directories only makes sense for an installation, not
 
67
# an in-source build.
 
68
build_flags = ''
 
69
try:
 
70
    if not python_build:
 
71
        build_flags = sys.abiflags
 
72
except AttributeError:
 
73
    # It's not a configure-based build, so the sys module doesn't have
 
74
    # this attribute, which is fine.
 
75
    pass
 
76
 
 
77
def get_python_version():
 
78
    """Return a string containing the major and minor Python version,
 
79
    leaving off the patchlevel.  Sample return values could be '1.5'
 
80
    or '2.2'.
 
81
    """
 
82
    return sys.version[:3]
 
83
 
 
84
 
 
85
def get_python_inc(plat_specific=0, prefix=None):
 
86
    """Return the directory containing installed Python header files.
 
87
 
 
88
    If 'plat_specific' is false (the default), this is the path to the
 
89
    non-platform-specific header files, i.e. Python.h and so on;
 
90
    otherwise, this is the path to platform-specific header files
 
91
    (namely pyconfig.h).
 
92
 
 
93
    If 'prefix' is supplied, use it instead of sys.base_prefix or
 
94
    sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
 
95
    """
 
96
    if prefix is None:
 
97
        prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
 
98
    if os.name == "posix":
 
99
        if python_build:
 
100
            # Assume the executable is in the build directory.  The
 
101
            # pyconfig.h file should be in the same directory.  Since
 
102
            # the build directory may not be the source directory, we
 
103
            # must use "srcdir" from the makefile to find the "Include"
 
104
            # directory.
 
105
            base = _sys_home or project_base
 
106
            if plat_specific:
 
107
                return base
 
108
            if _sys_home:
 
109
                incdir = os.path.join(_sys_home, get_config_var('AST_H_DIR'))
 
110
            else:
 
111
                incdir = os.path.join(get_config_var('srcdir'), 'Include')
 
112
            return os.path.normpath(incdir)
 
113
        python_dir = 'python' + get_python_version() + build_flags
 
114
        return os.path.join(prefix, "include", python_dir)
 
115
    elif os.name == "nt":
 
116
        return os.path.join(prefix, "include")
 
117
    else:
 
118
        raise DistutilsPlatformError(
 
119
            "I don't know where Python installs its C header files "
 
120
            "on platform '%s'" % os.name)
 
121
 
 
122
 
 
123
def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
 
124
    """Return the directory containing the Python library (standard or
 
125
    site additions).
 
126
 
 
127
    If 'plat_specific' is true, return the directory containing
 
128
    platform-specific modules, i.e. any module from a non-pure-Python
 
129
    module distribution; otherwise, return the platform-shared library
 
130
    directory.  If 'standard_lib' is true, return the directory
 
131
    containing standard Python library modules; otherwise, return the
 
132
    directory for site-specific modules.
 
133
 
 
134
    If 'prefix' is supplied, use it instead of sys.base_prefix or
 
135
    sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
 
136
    """
 
137
    if prefix is None:
 
138
        if standard_lib:
 
139
            prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
 
140
        else:
 
141
            prefix = plat_specific and EXEC_PREFIX or PREFIX
 
142
 
 
143
    if os.name == "posix":
 
144
        libpython = os.path.join(prefix,
 
145
                                 "lib", "python" + get_python_version())
 
146
        if standard_lib:
 
147
            return libpython
 
148
        else:
 
149
            return os.path.join(libpython, "site-packages")
 
150
    elif os.name == "nt":
 
151
        if standard_lib:
 
152
            return os.path.join(prefix, "Lib")
 
153
        else:
 
154
            if get_python_version() < "2.2":
 
155
                return prefix
 
156
            else:
 
157
                return os.path.join(prefix, "Lib", "site-packages")
 
158
    else:
 
159
        raise DistutilsPlatformError(
 
160
            "I don't know where Python installs its library "
 
161
            "on platform '%s'" % os.name)
 
162
 
 
163
 
 
164
 
 
165
def customize_compiler(compiler):
 
166
    """Do any platform-specific customization of a CCompiler instance.
 
167
 
 
168
    Mainly needed on Unix, so we can plug in the information that
 
169
    varies across Unices and is stored in Python's Makefile.
 
170
    """
 
171
    if compiler.compiler_type == "unix":
 
172
        if sys.platform == "darwin":
 
173
            # Perform first-time customization of compiler-related
 
174
            # config vars on OS X now that we know we need a compiler.
 
175
            # This is primarily to support Pythons from binary
 
176
            # installers.  The kind and paths to build tools on
 
177
            # the user system may vary significantly from the system
 
178
            # that Python itself was built on.  Also the user OS
 
179
            # version and build tools may not support the same set
 
180
            # of CPU architectures for universal builds.
 
181
            global _config_vars
 
182
            if not _config_vars.get('CUSTOMIZED_OSX_COMPILER', ''):
 
183
                import _osx_support
 
184
                _osx_support.customize_compiler(_config_vars)
 
185
                _config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'
 
186
 
 
187
        (cc, cxx, opt, cflags, ccshared, ldshared, shlib_suffix, ar, ar_flags) = \
 
188
            get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
 
189
                            'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS')
 
190
 
 
191
        if 'CC' in os.environ:
 
192
            newcc = os.environ['CC']
 
193
            if (sys.platform == 'darwin'
 
194
                    and 'LDSHARED' not in os.environ
 
195
                    and ldshared.startswith(cc)):
 
196
                # On OS X, if CC is overridden, use that as the default
 
197
                #       command for LDSHARED as well
 
198
                ldshared = newcc + ldshared[len(cc):]
 
199
            cc = newcc
 
200
        if 'CXX' in os.environ:
 
201
            cxx = os.environ['CXX']
 
202
        if 'LDSHARED' in os.environ:
 
203
            ldshared = os.environ['LDSHARED']
 
204
        if 'CPP' in os.environ:
 
205
            cpp = os.environ['CPP']
 
206
        else:
 
207
            cpp = cc + " -E"           # not always
 
208
        if 'LDFLAGS' in os.environ:
 
209
            ldshared = ldshared + ' ' + os.environ['LDFLAGS']
 
210
        if 'CFLAGS' in os.environ:
 
211
            cflags = opt + ' ' + os.environ['CFLAGS']
 
212
            ldshared = ldshared + ' ' + os.environ['CFLAGS']
 
213
        if 'CPPFLAGS' in os.environ:
 
214
            cpp = cpp + ' ' + os.environ['CPPFLAGS']
 
215
            cflags = cflags + ' ' + os.environ['CPPFLAGS']
 
216
            ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
 
217
        if 'AR' in os.environ:
 
218
            ar = os.environ['AR']
 
219
        if 'ARFLAGS' in os.environ:
 
220
            archiver = ar + ' ' + os.environ['ARFLAGS']
 
221
        else:
 
222
            archiver = ar + ' ' + ar_flags
 
223
 
 
224
        cc_cmd = cc + ' ' + cflags
 
225
        compiler.set_executables(
 
226
            preprocessor=cpp,
 
227
            compiler=cc_cmd,
 
228
            compiler_so=cc_cmd + ' ' + ccshared,
 
229
            compiler_cxx=cxx,
 
230
            linker_so=ldshared,
 
231
            linker_exe=cc,
 
232
            archiver=archiver)
 
233
 
 
234
        compiler.shared_lib_extension = shlib_suffix
 
235
 
 
236
 
 
237
def get_config_h_filename():
 
238
    """Return full pathname of installed pyconfig.h file."""
 
239
    if python_build:
 
240
        if os.name == "nt":
 
241
            inc_dir = os.path.join(_sys_home or project_base, "PC")
 
242
        else:
 
243
            inc_dir = _sys_home or project_base
 
244
    else:
 
245
        inc_dir = get_python_inc(plat_specific=1)
 
246
    if get_python_version() < '2.2':
 
247
        config_h = 'config.h'
 
248
    else:
 
249
        # The name of the config.h file changed in 2.2
 
250
        config_h = 'pyconfig.h'
 
251
    return os.path.join(inc_dir, config_h)
 
252
 
 
253
 
 
254
def get_makefile_filename():
 
255
    """Return full pathname of installed Makefile from the Python build."""
 
256
    if python_build:
 
257
        return os.path.join(_sys_home or project_base, "Makefile")
 
258
    lib_dir = get_python_lib(plat_specific=0, standard_lib=1)
 
259
    config_file = 'config-{}{}'.format(get_python_version(), build_flags)
 
260
    return os.path.join(lib_dir, config_file, 'Makefile')
 
261
 
 
262
 
 
263
def parse_config_h(fp, g=None):
 
264
    """Parse a config.h-style file.
 
265
 
 
266
    A dictionary containing name/value pairs is returned.  If an
 
267
    optional dictionary is passed in as the second argument, it is
 
268
    used instead of a new dictionary.
 
269
    """
 
270
    if g is None:
 
271
        g = {}
 
272
    define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
 
273
    undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n")
 
274
    #
 
275
    while True:
 
276
        line = fp.readline()
 
277
        if not line:
 
278
            break
 
279
        m = define_rx.match(line)
 
280
        if m:
 
281
            n, v = m.group(1, 2)
 
282
            try: v = int(v)
 
283
            except ValueError: pass
 
284
            g[n] = v
 
285
        else:
 
286
            m = undef_rx.match(line)
 
287
            if m:
 
288
                g[m.group(1)] = 0
 
289
    return g
 
290
 
 
291
 
 
292
# Regexes needed for parsing Makefile (and similar syntaxes,
 
293
# like old-style Setup files).
 
294
_variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
 
295
_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
 
296
_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
 
297
 
 
298
def parse_makefile(fn, g=None):
 
299
    """Parse a Makefile-style file.
 
300
 
 
301
    A dictionary containing name/value pairs is returned.  If an
 
302
    optional dictionary is passed in as the second argument, it is
 
303
    used instead of a new dictionary.
 
304
    """
 
305
    from distutils.text_file import TextFile
 
306
    fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1, errors="surrogateescape")
 
307
 
 
308
    if g is None:
 
309
        g = {}
 
310
    done = {}
 
311
    notdone = {}
 
312
 
 
313
    while True:
 
314
        line = fp.readline()
 
315
        if line is None: # eof
 
316
            break
 
317
        m = _variable_rx.match(line)
 
318
        if m:
 
319
            n, v = m.group(1, 2)
 
320
            v = v.strip()
 
321
            # `$$' is a literal `$' in make
 
322
            tmpv = v.replace('$$', '')
 
323
 
 
324
            if "$" in tmpv:
 
325
                notdone[n] = v
 
326
            else:
 
327
                try:
 
328
                    v = int(v)
 
329
                except ValueError:
 
330
                    # insert literal `$'
 
331
                    done[n] = v.replace('$$', '$')
 
332
                else:
 
333
                    done[n] = v
 
334
 
 
335
    # Variables with a 'PY_' prefix in the makefile. These need to
 
336
    # be made available without that prefix through sysconfig.
 
337
    # Special care is needed to ensure that variable expansion works, even
 
338
    # if the expansion uses the name without a prefix.
 
339
    renamed_variables = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS')
 
340
 
 
341
    # do variable interpolation here
 
342
    while notdone:
 
343
        for name in list(notdone):
 
344
            value = notdone[name]
 
345
            m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
 
346
            if m:
 
347
                n = m.group(1)
 
348
                found = True
 
349
                if n in done:
 
350
                    item = str(done[n])
 
351
                elif n in notdone:
 
352
                    # get it on a subsequent round
 
353
                    found = False
 
354
                elif n in os.environ:
 
355
                    # do it like make: fall back to environment
 
356
                    item = os.environ[n]
 
357
 
 
358
                elif n in renamed_variables:
 
359
                    if name.startswith('PY_') and name[3:] in renamed_variables:
 
360
                        item = ""
 
361
 
 
362
                    elif 'PY_' + n in notdone:
 
363
                        found = False
 
364
 
 
365
                    else:
 
366
                        item = str(done['PY_' + n])
 
367
                else:
 
368
                    done[n] = item = ""
 
369
                if found:
 
370
                    after = value[m.end():]
 
371
                    value = value[:m.start()] + item + after
 
372
                    if "$" in after:
 
373
                        notdone[name] = value
 
374
                    else:
 
375
                        try: value = int(value)
 
376
                        except ValueError:
 
377
                            done[name] = value.strip()
 
378
                        else:
 
379
                            done[name] = value
 
380
                        del notdone[name]
 
381
 
 
382
                        if name.startswith('PY_') \
 
383
                            and name[3:] in renamed_variables:
 
384
 
 
385
                            name = name[3:]
 
386
                            if name not in done:
 
387
                                done[name] = value
 
388
            else:
 
389
                # bogus variable reference; just drop it since we can't deal
 
390
                del notdone[name]
 
391
 
 
392
    fp.close()
 
393
 
 
394
    # strip spurious spaces
 
395
    for k, v in done.items():
 
396
        if isinstance(v, str):
 
397
            done[k] = v.strip()
 
398
 
 
399
    # save the results in the global dictionary
 
400
    g.update(done)
 
401
    return g
 
402
 
 
403
 
 
404
def expand_makefile_vars(s, vars):
 
405
    """Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
 
406
    'string' according to 'vars' (a dictionary mapping variable names to
 
407
    values).  Variables not present in 'vars' are silently expanded to the
 
408
    empty string.  The variable values in 'vars' should not contain further
 
409
    variable expansions; if 'vars' is the output of 'parse_makefile()',
 
410
    you're fine.  Returns a variable-expanded version of 's'.
 
411
    """
 
412
 
 
413
    # This algorithm does multiple expansion, so if vars['foo'] contains
 
414
    # "${bar}", it will expand ${foo} to ${bar}, and then expand
 
415
    # ${bar}... and so forth.  This is fine as long as 'vars' comes from
 
416
    # 'parse_makefile()', which takes care of such expansions eagerly,
 
417
    # according to make's variable expansion semantics.
 
418
 
 
419
    while True:
 
420
        m = _findvar1_rx.search(s) or _findvar2_rx.search(s)
 
421
        if m:
 
422
            (beg, end) = m.span()
 
423
            s = s[0:beg] + vars.get(m.group(1)) + s[end:]
 
424
        else:
 
425
            break
 
426
    return s
 
427
 
 
428
 
 
429
_config_vars = None
 
430
 
 
431
def _init_posix():
 
432
    """Initialize the module as appropriate for POSIX systems."""
 
433
    g = {}
 
434
    # load the installed Makefile:
 
435
    try:
 
436
        filename = get_makefile_filename()
 
437
        parse_makefile(filename, g)
 
438
    except OSError as msg:
 
439
        my_msg = "invalid Python installation: unable to open %s" % filename
 
440
        if hasattr(msg, "strerror"):
 
441
            my_msg = my_msg + " (%s)" % msg.strerror
 
442
 
 
443
        raise DistutilsPlatformError(my_msg)
 
444
 
 
445
    # load the installed pyconfig.h:
 
446
    try:
 
447
        filename = get_config_h_filename()
 
448
        with open(filename) as file:
 
449
            parse_config_h(file, g)
 
450
    except OSError as msg:
 
451
        my_msg = "invalid Python installation: unable to open %s" % filename
 
452
        if hasattr(msg, "strerror"):
 
453
            my_msg = my_msg + " (%s)" % msg.strerror
 
454
 
 
455
        raise DistutilsPlatformError(my_msg)
 
456
 
 
457
    # On AIX, there are wrong paths to the linker scripts in the Makefile
 
458
    # -- these paths are relative to the Python source, but when installed
 
459
    # the scripts are in another directory.
 
460
    if python_build:
 
461
        g['LDSHARED'] = g['BLDSHARED']
 
462
 
 
463
    elif get_python_version() < '2.1':
 
464
        # The following two branches are for 1.5.2 compatibility.
 
465
        if sys.platform == 'aix4':          # what about AIX 3.x ?
 
466
            # Linker script is in the config directory, not in Modules as the
 
467
            # Makefile says.
 
468
            python_lib = get_python_lib(standard_lib=1)
 
469
            ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
 
470
            python_exp = os.path.join(python_lib, 'config', 'python.exp')
 
471
 
 
472
            g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp)
 
473
 
 
474
    global _config_vars
 
475
    _config_vars = g
 
476
 
 
477
 
 
478
def _init_nt():
 
479
    """Initialize the module as appropriate for NT"""
 
480
    g = {}
 
481
    # set basic install directories
 
482
    g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
 
483
    g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
 
484
 
 
485
    # XXX hmmm.. a normal install puts include files here
 
486
    g['INCLUDEPY'] = get_python_inc(plat_specific=0)
 
487
 
 
488
    g['EXT_SUFFIX'] = '.pyd'
 
489
    g['EXE'] = ".exe"
 
490
    g['VERSION'] = get_python_version().replace(".", "")
 
491
    g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
 
492
 
 
493
    global _config_vars
 
494
    _config_vars = g
 
495
 
 
496
 
 
497
def get_config_vars(*args):
 
498
    """With no arguments, return a dictionary of all configuration
 
499
    variables relevant for the current platform.  Generally this includes
 
500
    everything needed to build extensions and install both pure modules and
 
501
    extensions.  On Unix, this means every variable defined in Python's
 
502
    installed Makefile; on Windows it's a much smaller set.
 
503
 
 
504
    With arguments, return a list of values that result from looking up
 
505
    each argument in the configuration variable dictionary.
 
506
    """
 
507
    global _config_vars
 
508
    if _config_vars is None:
 
509
        func = globals().get("_init_" + os.name)
 
510
        if func:
 
511
            func()
 
512
        else:
 
513
            _config_vars = {}
 
514
 
 
515
        # Normalized versions of prefix and exec_prefix are handy to have;
 
516
        # in fact, these are the standard versions used most places in the
 
517
        # Distutils.
 
518
        _config_vars['prefix'] = PREFIX
 
519
        _config_vars['exec_prefix'] = EXEC_PREFIX
 
520
 
 
521
        # For backward compatibility, see issue19555
 
522
        SO = _config_vars.get('EXT_SUFFIX')
 
523
        if SO is not None:
 
524
            _config_vars['SO'] = SO
 
525
 
 
526
        # Always convert srcdir to an absolute path
 
527
        srcdir = _config_vars.get('srcdir', project_base)
 
528
        if os.name == 'posix':
 
529
            if python_build:
 
530
                # If srcdir is a relative path (typically '.' or '..')
 
531
                # then it should be interpreted relative to the directory
 
532
                # containing Makefile.
 
533
                base = os.path.dirname(get_makefile_filename())
 
534
                srcdir = os.path.join(base, srcdir)
 
535
            else:
 
536
                # srcdir is not meaningful since the installation is
 
537
                # spread about the filesystem.  We choose the
 
538
                # directory containing the Makefile since we know it
 
539
                # exists.
 
540
                srcdir = os.path.dirname(get_makefile_filename())
 
541
        _config_vars['srcdir'] = os.path.abspath(os.path.normpath(srcdir))
 
542
 
 
543
        # Convert srcdir into an absolute path if it appears necessary.
 
544
        # Normally it is relative to the build directory.  However, during
 
545
        # testing, for example, we might be running a non-installed python
 
546
        # from a different directory.
 
547
        if python_build and os.name == "posix":
 
548
            base = project_base
 
549
            if (not os.path.isabs(_config_vars['srcdir']) and
 
550
                base != os.getcwd()):
 
551
                # srcdir is relative and we are not in the same directory
 
552
                # as the executable. Assume executable is in the build
 
553
                # directory and make srcdir absolute.
 
554
                srcdir = os.path.join(base, _config_vars['srcdir'])
 
555
                _config_vars['srcdir'] = os.path.normpath(srcdir)
 
556
 
 
557
        # OS X platforms require special customization to handle
 
558
        # multi-architecture, multi-os-version installers
 
559
        if sys.platform == 'darwin':
 
560
            import _osx_support
 
561
            _osx_support.customize_config_vars(_config_vars)
 
562
 
 
563
    if args:
 
564
        vals = []
 
565
        for name in args:
 
566
            vals.append(_config_vars.get(name))
 
567
        return vals
 
568
    else:
 
569
        return _config_vars
 
570
 
 
571
def get_config_var(name):
 
572
    """Return the value of a single variable using the dictionary
 
573
    returned by 'get_config_vars()'.  Equivalent to
 
574
    get_config_vars().get(name)
 
575
    """
 
576
    if name == 'SO':
 
577
        import warnings
 
578
        warnings.warn('SO is deprecated, use EXT_SUFFIX', DeprecationWarning)
 
579
    return get_config_vars().get(name)