blob: 0fbd5412bc17ea1e3795e722fa3fc6b1627e7160 [file] [log] [blame]
Fred Drake70b014d2001-07-18 18:39:56 +00001"""Provide access to Python's configuration information. The specific
2configuration variables available depend heavily on the platform and
3configuration. The values may be retrieved using
4get_config_var(name), and the list of variables is available via
5get_config_vars().keys(). Additional convenience functions are also
6available.
Greg Ward1190ee31998-12-18 23:46:33 +00007
8Written by: Fred L. Drake, Jr.
9Email: <fdrake@acm.org>
Greg Ward1190ee31998-12-18 23:46:33 +000010"""
11
Greg Ward82d71ca2000-06-03 00:44:30 +000012__revision__ = "$Id$"
Greg Ward1190ee31998-12-18 23:46:33 +000013
Guido van Rossum63236cf2007-05-25 18:39:29 +000014import io
Greg Ward9ddaaa11999-01-06 14:46:06 +000015import os
16import re
Tarek Ziadé36797272010-07-22 12:50:05 +000017import sys
Greg Ward1190ee31998-12-18 23:46:33 +000018
Tarek Ziadé36797272010-07-22 12:50:05 +000019from .errors import DistutilsPlatformError
Greg Warda0ca3f22000-02-02 00:05:14 +000020
Tarek Ziadé36797272010-07-22 12:50:05 +000021# These are needed in a couple of spots, so just compute them once.
22PREFIX = os.path.normpath(sys.prefix)
23EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
Fred Drakec1ee39a2000-03-09 15:54:52 +000024
Tarek Ziadé36797272010-07-22 12:50:05 +000025# 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.
28project_base = os.path.dirname(os.path.abspath(sys.executable))
29if 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
32if 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
36if 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))
Tarek Ziadé8b441d02010-01-29 11:46:31 +000039
Tarek Ziadé36797272010-07-22 12:50:05 +000040# 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
Christian Heimes2202f872008-02-06 14:31:34 +000045def _python_build():
Tarek Ziadé36797272010-07-22 12:50:05 +000046 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
Christian Heimes2202f872008-02-06 14:31:34 +000050python_build = _python_build()
Fred Drakec916cdc2001-08-02 20:03:12 +000051
Tarek Ziadé36797272010-07-22 12:50:05 +000052def get_python_version():
53 """Return a string containing the major and minor Python version,
54 leaving off the patchlevel. Sample return values could be '1.5'
55 or '2.2'.
56 """
57 return sys.version[:3]
Tarek Ziadéedacea32010-01-29 11:41:03 +000058
Tarek Ziadé36797272010-07-22 12:50:05 +000059
60def get_python_inc(plat_specific=0, prefix=None):
61 """Return the directory containing installed Python header files.
Fred Drakec1ee39a2000-03-09 15:54:52 +000062
63 If 'plat_specific' is false (the default), this is the path to the
64 non-platform-specific header files, i.e. Python.h and so on;
65 otherwise, this is the path to platform-specific header files
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +000066 (namely pyconfig.h).
Fred Drakec1ee39a2000-03-09 15:54:52 +000067
Greg Wardd38e6f72000-04-10 01:17:49 +000068 If 'prefix' is supplied, use it instead of sys.prefix or
69 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakeb94b8492001-12-06 20:51:35 +000070 """
Tarek Ziadé36797272010-07-22 12:50:05 +000071 if prefix is None:
72 prefix = plat_specific and EXEC_PREFIX or PREFIX
73 if os.name == "posix":
74 if python_build:
75 # Assume the executable is in the build directory. The
76 # pyconfig.h file should be in the same directory. Since
77 # the build directory may not be the source directory, we
78 # must use "srcdir" from the makefile to find the "Include"
79 # directory.
80 base = os.path.dirname(os.path.abspath(sys.executable))
81 if plat_specific:
82 return base
83 else:
84 incdir = os.path.join(get_config_var('srcdir'), 'Include')
85 return os.path.normpath(incdir)
86 return os.path.join(prefix, "include", "python" + get_python_version())
87 elif os.name == "nt":
88 return os.path.join(prefix, "include")
89 elif os.name == "mac":
90 if plat_specific:
91 return os.path.join(prefix, "Mac", "Include")
92 else:
93 return os.path.join(prefix, "Include")
94 elif os.name == "os2":
95 return os.path.join(prefix, "Include")
Greg Ward7d73b9e2000-03-09 03:16:05 +000096 else:
Tarek Ziadé36797272010-07-22 12:50:05 +000097 raise DistutilsPlatformError(
98 "I don't know where Python installs its C header files "
99 "on platform '%s'" % os.name)
Greg Ward7d73b9e2000-03-09 03:16:05 +0000100
101
Tarek Ziadé36797272010-07-22 12:50:05 +0000102def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
103 """Return the directory containing the Python library (standard or
Fred Drakec1ee39a2000-03-09 15:54:52 +0000104 site additions).
Greg Ward7d73b9e2000-03-09 03:16:05 +0000105
Fred Drakec1ee39a2000-03-09 15:54:52 +0000106 If 'plat_specific' is true, return the directory containing
107 platform-specific modules, i.e. any module from a non-pure-Python
108 module distribution; otherwise, return the platform-shared library
109 directory. If 'standard_lib' is true, return the directory
110 containing standard Python library modules; otherwise, return the
111 directory for site-specific modules.
112
Greg Wardd38e6f72000-04-10 01:17:49 +0000113 If 'prefix' is supplied, use it instead of sys.prefix or
114 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakec1ee39a2000-03-09 15:54:52 +0000115 """
Tarek Ziadé36797272010-07-22 12:50:05 +0000116 if prefix is None:
117 prefix = plat_specific and EXEC_PREFIX or PREFIX
118
119 if os.name == "posix":
120 libpython = os.path.join(prefix,
121 "lib", "python" + get_python_version())
122 if standard_lib:
123 return libpython
Greg Ward7d73b9e2000-03-09 03:16:05 +0000124 else:
Tarek Ziadé36797272010-07-22 12:50:05 +0000125 return os.path.join(libpython, "site-packages")
126 elif os.name == "nt":
127 if standard_lib:
128 return os.path.join(prefix, "Lib")
Marc-André Lemburg2544f512002-01-31 18:56:00 +0000129 else:
Tarek Ziadé36797272010-07-22 12:50:05 +0000130 if get_python_version() < "2.2":
131 return prefix
132 else:
133 return os.path.join(prefix, "Lib", "site-packages")
134 elif os.name == "mac":
135 if plat_specific:
136 if standard_lib:
137 return os.path.join(prefix, "Lib", "lib-dynload")
138 else:
139 return os.path.join(prefix, "Lib", "site-packages")
140 else:
141 if standard_lib:
142 return os.path.join(prefix, "Lib")
143 else:
144 return os.path.join(prefix, "Lib", "site-packages")
145 elif os.name == "os2":
146 if standard_lib:
147 return os.path.join(prefix, "Lib")
148 else:
149 return os.path.join(prefix, "Lib", "site-packages")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000150 else:
Tarek Ziadé36797272010-07-22 12:50:05 +0000151 raise DistutilsPlatformError(
152 "I don't know where Python installs its library "
153 "on platform '%s'" % os.name)
154
155
156def customize_compiler(compiler):
157 """Do any platform-specific customization of a CCompiler instance.
158
159 Mainly needed on Unix, so we can plug in the information that
160 varies across Unices and is stored in Python's Makefile.
161 """
162 if compiler.compiler_type == "unix":
163 (cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \
164 get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
165 'CCSHARED', 'LDSHARED', 'SO', 'AR', 'ARFLAGS')
166
167 if 'CC' in os.environ:
168 cc = os.environ['CC']
169 if 'CXX' in os.environ:
170 cxx = os.environ['CXX']
171 if 'LDSHARED' in os.environ:
172 ldshared = os.environ['LDSHARED']
173 if 'CPP' in os.environ:
174 cpp = os.environ['CPP']
Andrew M. Kuchling29c86232002-11-04 19:53:24 +0000175 else:
Tarek Ziadé36797272010-07-22 12:50:05 +0000176 cpp = cc + " -E" # not always
177 if 'LDFLAGS' in os.environ:
178 ldshared = ldshared + ' ' + os.environ['LDFLAGS']
179 if 'CFLAGS' in os.environ:
180 cflags = opt + ' ' + os.environ['CFLAGS']
181 ldshared = ldshared + ' ' + os.environ['CFLAGS']
182 if 'CPPFLAGS' in os.environ:
183 cpp = cpp + ' ' + os.environ['CPPFLAGS']
184 cflags = cflags + ' ' + os.environ['CPPFLAGS']
185 ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
186 if 'AR' in os.environ:
187 ar = os.environ['AR']
188 if 'ARFLAGS' in os.environ:
189 archiver = ar + ' ' + os.environ['ARFLAGS']
190 else:
191 archiver = ar + ' ' + ar_flags
192
193 cc_cmd = cc + ' ' + cflags
194 compiler.set_executables(
195 preprocessor=cpp,
196 compiler=cc_cmd,
197 compiler_so=cc_cmd + ' ' + ccshared,
198 compiler_cxx=cxx,
199 linker_so=ldshared,
200 linker_exe=cc,
201 archiver=archiver)
202
203 compiler.shared_lib_extension = so_ext
204
205
206def get_config_h_filename():
207 """Return full pathname of installed pyconfig.h file."""
208 if python_build:
209 if os.name == "nt":
210 inc_dir = os.path.join(project_base, "PC")
211 else:
212 inc_dir = project_base
213 else:
214 inc_dir = get_python_inc(plat_specific=1)
215 if get_python_version() < '2.2':
216 config_h = 'config.h'
217 else:
218 # The name of the config.h file changed in 2.2
219 config_h = 'pyconfig.h'
220 return os.path.join(inc_dir, config_h)
221
Greg Ward1190ee31998-12-18 23:46:33 +0000222
Greg Ward9ddaaa11999-01-06 14:46:06 +0000223def get_makefile_filename():
Tarek Ziadé36797272010-07-22 12:50:05 +0000224 """Return full pathname of installed Makefile from the Python build."""
225 if python_build:
226 return os.path.join(os.path.dirname(sys.executable), "Makefile")
227 lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
228 return os.path.join(lib_dir, "config", "Makefile")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000229
Tarek Ziadé36797272010-07-22 12:50:05 +0000230
231def parse_config_h(fp, g=None):
232 """Parse a config.h-style file.
233
234 A dictionary containing name/value pairs is returned. If an
235 optional dictionary is passed in as the second argument, it is
236 used instead of a new dictionary.
Fred Drake522af3a1999-01-06 16:28:34 +0000237 """
Tarek Ziadé36797272010-07-22 12:50:05 +0000238 if g is None:
239 g = {}
240 define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
241 undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n")
242 #
243 while True:
244 line = fp.readline()
245 if not line:
246 break
247 m = define_rx.match(line)
248 if m:
249 n, v = m.group(1, 2)
250 try: v = int(v)
251 except ValueError: pass
252 g[n] = v
253 else:
254 m = undef_rx.match(line)
255 if m:
256 g[m.group(1)] = 0
257 return g
Greg Ward1190ee31998-12-18 23:46:33 +0000258
Greg Wardd283ce72000-09-17 00:53:02 +0000259
260# Regexes needed for parsing Makefile (and similar syntaxes,
261# like old-style Setup files).
262_variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
263_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
264_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
265
Greg Ward3fff8d22000-09-15 00:03:13 +0000266def parse_makefile(fn, g=None):
Tarek Ziadé36797272010-07-22 12:50:05 +0000267 """Parse a Makefile-style file.
Fred Drakec1ee39a2000-03-09 15:54:52 +0000268
269 A dictionary containing name/value pairs is returned. If an
270 optional dictionary is passed in as the second argument, it is
271 used instead of a new dictionary.
Fred Drake522af3a1999-01-06 16:28:34 +0000272 """
Tarek Ziadé36797272010-07-22 12:50:05 +0000273 from distutils.text_file import TextFile
274 fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1)
275
276 if g is None:
277 g = {}
278 done = {}
279 notdone = {}
280
281 while True:
282 line = fp.readline()
283 if line is None: # eof
284 break
285 m = _variable_rx.match(line)
286 if m:
287 n, v = m.group(1, 2)
288 v = v.strip()
289 # `$$' is a literal `$' in make
290 tmpv = v.replace('$$', '')
291
292 if "$" in tmpv:
293 notdone[n] = v
294 else:
295 try:
296 v = int(v)
297 except ValueError:
298 # insert literal `$'
299 done[n] = v.replace('$$', '$')
300 else:
301 done[n] = v
302
303 # do variable interpolation here
304 while notdone:
305 for name in list(notdone):
306 value = notdone[name]
307 m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
308 if m:
309 n = m.group(1)
310 found = True
311 if n in done:
312 item = str(done[n])
313 elif n in notdone:
314 # get it on a subsequent round
315 found = False
316 elif n in os.environ:
317 # do it like make: fall back to environment
318 item = os.environ[n]
319 else:
320 done[n] = item = ""
321 if found:
322 after = value[m.end():]
323 value = value[:m.start()] + item + after
324 if "$" in after:
325 notdone[name] = value
326 else:
327 try: value = int(value)
328 except ValueError:
329 done[name] = value.strip()
330 else:
331 done[name] = value
332 del notdone[name]
333 else:
334 # bogus variable reference; just drop it since we can't deal
335 del notdone[name]
336
337 fp.close()
338
339 # save the results in the global dictionary
340 g.update(done)
341 return g
342
Greg Ward1190ee31998-12-18 23:46:33 +0000343
Greg Wardd283ce72000-09-17 00:53:02 +0000344def expand_makefile_vars(s, vars):
Tarek Ziadé36797272010-07-22 12:50:05 +0000345 """Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
Greg Wardd283ce72000-09-17 00:53:02 +0000346 'string' according to 'vars' (a dictionary mapping variable names to
347 values). Variables not present in 'vars' are silently expanded to the
348 empty string. The variable values in 'vars' should not contain further
349 variable expansions; if 'vars' is the output of 'parse_makefile()',
350 you're fine. Returns a variable-expanded version of 's'.
351 """
352
353 # This algorithm does multiple expansion, so if vars['foo'] contains
354 # "${bar}", it will expand ${foo} to ${bar}, and then expand
355 # ${bar}... and so forth. This is fine as long as 'vars' comes from
356 # 'parse_makefile()', which takes care of such expansions eagerly,
357 # according to make's variable expansion semantics.
358
Collin Winter5b7e9d72007-08-30 03:52:21 +0000359 while True:
Greg Wardd283ce72000-09-17 00:53:02 +0000360 m = _findvar1_rx.search(s) or _findvar2_rx.search(s)
361 if m:
Greg Wardd283ce72000-09-17 00:53:02 +0000362 (beg, end) = m.span()
363 s = s[0:beg] + vars.get(m.group(1)) + s[end:]
364 else:
365 break
366 return s
Tarek Ziadé36797272010-07-22 12:50:05 +0000367
368
369_config_vars = None
370
371def _init_posix():
372 """Initialize the module as appropriate for POSIX systems."""
373 g = {}
374 # load the installed Makefile:
375 try:
376 filename = get_makefile_filename()
377 parse_makefile(filename, g)
378 except IOError as msg:
379 my_msg = "invalid Python installation: unable to open %s" % filename
380 if hasattr(msg, "strerror"):
381 my_msg = my_msg + " (%s)" % msg.strerror
382
383 raise DistutilsPlatformError(my_msg)
384
385 # load the installed pyconfig.h:
386 try:
387 filename = get_config_h_filename()
388 parse_config_h(io.open(filename), g)
389 except IOError as msg:
390 my_msg = "invalid Python installation: unable to open %s" % filename
391 if hasattr(msg, "strerror"):
392 my_msg = my_msg + " (%s)" % msg.strerror
393
394 raise DistutilsPlatformError(my_msg)
395
396 # On MacOSX we need to check the setting of the environment variable
397 # MACOSX_DEPLOYMENT_TARGET: configure bases some choices on it so
398 # it needs to be compatible.
399 # If it isn't set we set it to the configure-time value
400 if sys.platform == 'darwin' and 'MACOSX_DEPLOYMENT_TARGET' in g:
401 cfg_target = g['MACOSX_DEPLOYMENT_TARGET']
402 cur_target = os.getenv('MACOSX_DEPLOYMENT_TARGET', '')
403 if cur_target == '':
404 cur_target = cfg_target
405 os.putenv('MACOSX_DEPLOYMENT_TARGET', cfg_target)
406 elif [int(x) for x in cfg_target.split('.')] > [int(x) for x in cur_target.split('.')]:
407 my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: now "%s" but "%s" during configure'
408 % (cur_target, cfg_target))
409 raise DistutilsPlatformError(my_msg)
410
411 # On AIX, there are wrong paths to the linker scripts in the Makefile
412 # -- these paths are relative to the Python source, but when installed
413 # the scripts are in another directory.
414 if python_build:
415 g['LDSHARED'] = g['BLDSHARED']
416
417 elif get_python_version() < '2.1':
418 # The following two branches are for 1.5.2 compatibility.
419 if sys.platform == 'aix4': # what about AIX 3.x ?
420 # Linker script is in the config directory, not in Modules as the
421 # Makefile says.
422 python_lib = get_python_lib(standard_lib=1)
423 ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
424 python_exp = os.path.join(python_lib, 'config', 'python.exp')
425
426 g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp)
427
428 global _config_vars
429 _config_vars = g
430
431
432def _init_nt():
433 """Initialize the module as appropriate for NT"""
434 g = {}
435 # set basic install directories
436 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
437 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
438
439 # XXX hmmm.. a normal install puts include files here
440 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
441
442 g['SO'] = '.pyd'
443 g['EXE'] = ".exe"
444 g['VERSION'] = get_python_version().replace(".", "")
445 g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
446
447 global _config_vars
448 _config_vars = g
449
450
451def _init_mac():
452 """Initialize the module as appropriate for Macintosh systems"""
453 g = {}
454 # set basic install directories
455 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
456 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
457
458 # XXX hmmm.. a normal install puts include files here
459 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
460
461 import MacOS
462 if not hasattr(MacOS, 'runtimemodel'):
463 g['SO'] = '.ppc.slb'
464 else:
465 g['SO'] = '.%s.slb' % MacOS.runtimemodel
466
467 # XXX are these used anywhere?
468 g['install_lib'] = os.path.join(EXEC_PREFIX, "Lib")
469 g['install_platlib'] = os.path.join(EXEC_PREFIX, "Mac", "Lib")
470
471 # These are used by the extension module build
472 g['srcdir'] = ':'
473 global _config_vars
474 _config_vars = g
475
476
477def _init_os2():
478 """Initialize the module as appropriate for OS/2"""
479 g = {}
480 # set basic install directories
481 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
482 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
483
484 # XXX hmmm.. a normal install puts include files here
485 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
486
487 g['SO'] = '.pyd'
488 g['EXE'] = ".exe"
489
490 global _config_vars
491 _config_vars = g
492
493
494def get_config_vars(*args):
495 """With no arguments, return a dictionary of all configuration
496 variables relevant for the current platform. Generally this includes
497 everything needed to build extensions and install both pure modules and
498 extensions. On Unix, this means every variable defined in Python's
499 installed Makefile; on Windows and Mac OS it's a much smaller set.
500
501 With arguments, return a list of values that result from looking up
502 each argument in the configuration variable dictionary.
503 """
504 global _config_vars
505 if _config_vars is None:
506 func = globals().get("_init_" + os.name)
507 if func:
508 func()
509 else:
510 _config_vars = {}
511
512 # Normalized versions of prefix and exec_prefix are handy to have;
513 # in fact, these are the standard versions used most places in the
514 # Distutils.
515 _config_vars['prefix'] = PREFIX
516 _config_vars['exec_prefix'] = EXEC_PREFIX
517
518 # Convert srcdir into an absolute path if it appears necessary.
519 # Normally it is relative to the build directory. However, during
520 # testing, for example, we might be running a non-installed python
521 # from a different directory.
522 if python_build and os.name == "posix":
523 base = os.path.dirname(os.path.abspath(sys.executable))
524 if (not os.path.isabs(_config_vars['srcdir']) and
525 base != os.getcwd()):
526 # srcdir is relative and we are not in the same directory
527 # as the executable. Assume executable is in the build
528 # directory and make srcdir absolute.
529 srcdir = os.path.join(base, _config_vars['srcdir'])
530 _config_vars['srcdir'] = os.path.normpath(srcdir)
531
532 if sys.platform == 'darwin':
533 kernel_version = os.uname()[2] # Kernel version (8.4.3)
534 major_version = int(kernel_version.split('.')[0])
535
536 if major_version < 8:
537 # On Mac OS X before 10.4, check if -arch and -isysroot
538 # are in CFLAGS or LDFLAGS and remove them if they are.
539 # This is needed when building extensions on a 10.3 system
540 # using a universal build of python.
541 for key in ('LDFLAGS', 'BASECFLAGS',
542 # a number of derived variables. These need to be
543 # patched up as well.
544 'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
545 flags = _config_vars[key]
546 flags = re.sub('-arch\s+\w+\s', ' ', flags, re.ASCII)
547 flags = re.sub('-isysroot [^ \t]*', ' ', flags)
548 _config_vars[key] = flags
549
550 else:
551
552 # Allow the user to override the architecture flags using
553 # an environment variable.
554 # NOTE: This name was introduced by Apple in OSX 10.5 and
555 # is used by several scripting languages distributed with
556 # that OS release.
557
558 if 'ARCHFLAGS' in os.environ:
559 arch = os.environ['ARCHFLAGS']
560 for key in ('LDFLAGS', 'BASECFLAGS',
561 # a number of derived variables. These need to be
562 # patched up as well.
563 'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
564
565 flags = _config_vars[key]
566 flags = re.sub('-arch\s+\w+\s', ' ', flags)
567 flags = flags + ' ' + arch
568 _config_vars[key] = flags
569
570 if args:
571 vals = []
572 for name in args:
573 vals.append(_config_vars.get(name))
574 return vals
575 else:
576 return _config_vars
577
578def get_config_var(name):
579 """Return the value of a single variable using the dictionary
580 returned by 'get_config_vars()'. Equivalent to
581 get_config_vars().get(name)
582 """
583 return get_config_vars().get(name)