blob: be91f92c3634b61eff236a0b16bcfacbd278be83 [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:
Vinay Sajipae7d7fa2010-09-20 10:29:54 +000075 # 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)
Tarek Ziadé36797272010-07-22 12:50:05 +000086 return os.path.join(prefix, "include", "python" + get_python_version())
87 elif os.name == "nt":
88 return os.path.join(prefix, "include")
Tarek Ziadé36797272010-07-22 12:50:05 +000089 elif os.name == "os2":
90 return os.path.join(prefix, "Include")
Greg Ward7d73b9e2000-03-09 03:16:05 +000091 else:
Tarek Ziadé36797272010-07-22 12:50:05 +000092 raise DistutilsPlatformError(
93 "I don't know where Python installs its C header files "
94 "on platform '%s'" % os.name)
Greg Ward7d73b9e2000-03-09 03:16:05 +000095
96
Tarek Ziadé36797272010-07-22 12:50:05 +000097def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
98 """Return the directory containing the Python library (standard or
Fred Drakec1ee39a2000-03-09 15:54:52 +000099 site additions).
Greg Ward7d73b9e2000-03-09 03:16:05 +0000100
Fred Drakec1ee39a2000-03-09 15:54:52 +0000101 If 'plat_specific' is true, return the directory containing
102 platform-specific modules, i.e. any module from a non-pure-Python
103 module distribution; otherwise, return the platform-shared library
104 directory. If 'standard_lib' is true, return the directory
105 containing standard Python library modules; otherwise, return the
106 directory for site-specific modules.
107
Greg Wardd38e6f72000-04-10 01:17:49 +0000108 If 'prefix' is supplied, use it instead of sys.prefix or
109 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakec1ee39a2000-03-09 15:54:52 +0000110 """
Tarek Ziadé36797272010-07-22 12:50:05 +0000111 if prefix is None:
112 prefix = plat_specific and EXEC_PREFIX or PREFIX
113
114 if os.name == "posix":
115 libpython = os.path.join(prefix,
116 "lib", "python" + get_python_version())
117 if standard_lib:
118 return libpython
Greg Ward7d73b9e2000-03-09 03:16:05 +0000119 else:
Tarek Ziadé36797272010-07-22 12:50:05 +0000120 return os.path.join(libpython, "site-packages")
121 elif os.name == "nt":
122 if standard_lib:
123 return os.path.join(prefix, "Lib")
Marc-André Lemburg2544f512002-01-31 18:56:00 +0000124 else:
Tarek Ziadé36797272010-07-22 12:50:05 +0000125 if get_python_version() < "2.2":
126 return prefix
127 else:
128 return os.path.join(prefix, "Lib", "site-packages")
Tarek Ziadé36797272010-07-22 12:50:05 +0000129 elif os.name == "os2":
130 if standard_lib:
131 return os.path.join(prefix, "Lib")
132 else:
133 return os.path.join(prefix, "Lib", "site-packages")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000134 else:
Tarek Ziadé36797272010-07-22 12:50:05 +0000135 raise DistutilsPlatformError(
136 "I don't know where Python installs its library "
137 "on platform '%s'" % os.name)
138
139
140def customize_compiler(compiler):
141 """Do any platform-specific customization of a CCompiler instance.
142
143 Mainly needed on Unix, so we can plug in the information that
144 varies across Unices and is stored in Python's Makefile.
145 """
146 if compiler.compiler_type == "unix":
147 (cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \
148 get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
149 'CCSHARED', 'LDSHARED', 'SO', 'AR', 'ARFLAGS')
150
151 if 'CC' in os.environ:
152 cc = os.environ['CC']
153 if 'CXX' in os.environ:
154 cxx = os.environ['CXX']
155 if 'LDSHARED' in os.environ:
156 ldshared = os.environ['LDSHARED']
157 if 'CPP' in os.environ:
158 cpp = os.environ['CPP']
Andrew M. Kuchling29c86232002-11-04 19:53:24 +0000159 else:
Tarek Ziadé36797272010-07-22 12:50:05 +0000160 cpp = cc + " -E" # not always
161 if 'LDFLAGS' in os.environ:
162 ldshared = ldshared + ' ' + os.environ['LDFLAGS']
163 if 'CFLAGS' in os.environ:
164 cflags = opt + ' ' + os.environ['CFLAGS']
165 ldshared = ldshared + ' ' + os.environ['CFLAGS']
166 if 'CPPFLAGS' in os.environ:
167 cpp = cpp + ' ' + os.environ['CPPFLAGS']
168 cflags = cflags + ' ' + os.environ['CPPFLAGS']
169 ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
170 if 'AR' in os.environ:
171 ar = os.environ['AR']
172 if 'ARFLAGS' in os.environ:
173 archiver = ar + ' ' + os.environ['ARFLAGS']
174 else:
175 archiver = ar + ' ' + ar_flags
176
177 cc_cmd = cc + ' ' + cflags
178 compiler.set_executables(
179 preprocessor=cpp,
180 compiler=cc_cmd,
181 compiler_so=cc_cmd + ' ' + ccshared,
182 compiler_cxx=cxx,
183 linker_so=ldshared,
184 linker_exe=cc,
185 archiver=archiver)
186
187 compiler.shared_lib_extension = so_ext
188
189
190def get_config_h_filename():
191 """Return full pathname of installed pyconfig.h file."""
192 if python_build:
193 if os.name == "nt":
194 inc_dir = os.path.join(project_base, "PC")
195 else:
196 inc_dir = project_base
197 else:
198 inc_dir = get_python_inc(plat_specific=1)
199 if get_python_version() < '2.2':
200 config_h = 'config.h'
201 else:
202 # The name of the config.h file changed in 2.2
203 config_h = 'pyconfig.h'
204 return os.path.join(inc_dir, config_h)
205
Greg Ward1190ee31998-12-18 23:46:33 +0000206
Greg Ward9ddaaa11999-01-06 14:46:06 +0000207def get_makefile_filename():
Tarek Ziadé36797272010-07-22 12:50:05 +0000208 """Return full pathname of installed Makefile from the Python build."""
209 if python_build:
210 return os.path.join(os.path.dirname(sys.executable), "Makefile")
211 lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
212 return os.path.join(lib_dir, "config", "Makefile")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000213
Tarek Ziadé36797272010-07-22 12:50:05 +0000214
215def parse_config_h(fp, g=None):
216 """Parse a config.h-style file.
217
218 A dictionary containing name/value pairs is returned. If an
219 optional dictionary is passed in as the second argument, it is
220 used instead of a new dictionary.
Fred Drake522af3a1999-01-06 16:28:34 +0000221 """
Tarek Ziadé36797272010-07-22 12:50:05 +0000222 if g is None:
223 g = {}
224 define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
225 undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n")
226 #
227 while True:
228 line = fp.readline()
229 if not line:
230 break
231 m = define_rx.match(line)
232 if m:
233 n, v = m.group(1, 2)
234 try: v = int(v)
235 except ValueError: pass
236 g[n] = v
237 else:
238 m = undef_rx.match(line)
239 if m:
240 g[m.group(1)] = 0
241 return g
Greg Ward1190ee31998-12-18 23:46:33 +0000242
Greg Wardd283ce72000-09-17 00:53:02 +0000243
244# Regexes needed for parsing Makefile (and similar syntaxes,
245# like old-style Setup files).
246_variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
247_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
248_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
249
Greg Ward3fff8d22000-09-15 00:03:13 +0000250def parse_makefile(fn, g=None):
Tarek Ziadé36797272010-07-22 12:50:05 +0000251 """Parse a Makefile-style file.
Fred Drakec1ee39a2000-03-09 15:54:52 +0000252
253 A dictionary containing name/value pairs is returned. If an
254 optional dictionary is passed in as the second argument, it is
255 used instead of a new dictionary.
Fred Drake522af3a1999-01-06 16:28:34 +0000256 """
Tarek Ziadé36797272010-07-22 12:50:05 +0000257 from distutils.text_file import TextFile
Victor Stinner75d8c5c2010-10-23 17:02:31 +0000258 fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1, errors="surrogateescape")
Tarek Ziadé36797272010-07-22 12:50:05 +0000259
260 if g is None:
261 g = {}
262 done = {}
263 notdone = {}
264
265 while True:
266 line = fp.readline()
267 if line is None: # eof
268 break
269 m = _variable_rx.match(line)
270 if m:
271 n, v = m.group(1, 2)
272 v = v.strip()
273 # `$$' is a literal `$' in make
274 tmpv = v.replace('$$', '')
275
276 if "$" in tmpv:
277 notdone[n] = v
278 else:
279 try:
280 v = int(v)
281 except ValueError:
282 # insert literal `$'
283 done[n] = v.replace('$$', '$')
284 else:
285 done[n] = v
286
Ronald Oussorene8d252d2010-07-23 09:43:17 +0000287 # Variables with a 'PY_' prefix in the makefile. These need to
288 # be made available without that prefix through sysconfig.
289 # Special care is needed to ensure that variable expansion works, even
290 # if the expansion uses the name without a prefix.
291 renamed_variables = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS')
292
Tarek Ziadé36797272010-07-22 12:50:05 +0000293 # do variable interpolation here
294 while notdone:
295 for name in list(notdone):
296 value = notdone[name]
297 m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
298 if m:
299 n = m.group(1)
300 found = True
301 if n in done:
302 item = str(done[n])
303 elif n in notdone:
304 # get it on a subsequent round
305 found = False
306 elif n in os.environ:
307 # do it like make: fall back to environment
308 item = os.environ[n]
Ronald Oussorene8d252d2010-07-23 09:43:17 +0000309
310 elif n in renamed_variables:
311 if name.startswith('PY_') and name[3:] in renamed_variables:
312 item = ""
313
314 elif 'PY_' + n in notdone:
315 found = False
316
317 else:
318 item = str(done['PY_' + n])
Tarek Ziadé36797272010-07-22 12:50:05 +0000319 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]
Ronald Oussorene8d252d2010-07-23 09:43:17 +0000333
334 if name.startswith('PY_') \
335 and name[3:] in renamed_variables:
336
337 name = name[3:]
338 if name not in done:
339 done[name] = value
Tarek Ziadé36797272010-07-22 12:50:05 +0000340 else:
341 # bogus variable reference; just drop it since we can't deal
342 del notdone[name]
343
344 fp.close()
345
Antoine Pitroudbec7802010-10-10 09:37:12 +0000346 # strip spurious spaces
347 for k, v in done.items():
348 if isinstance(v, str):
349 done[k] = v.strip()
350
Tarek Ziadé36797272010-07-22 12:50:05 +0000351 # save the results in the global dictionary
352 g.update(done)
353 return g
354
Greg Ward1190ee31998-12-18 23:46:33 +0000355
Greg Wardd283ce72000-09-17 00:53:02 +0000356def expand_makefile_vars(s, vars):
Tarek Ziadé36797272010-07-22 12:50:05 +0000357 """Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
Greg Wardd283ce72000-09-17 00:53:02 +0000358 'string' according to 'vars' (a dictionary mapping variable names to
359 values). Variables not present in 'vars' are silently expanded to the
360 empty string. The variable values in 'vars' should not contain further
361 variable expansions; if 'vars' is the output of 'parse_makefile()',
362 you're fine. Returns a variable-expanded version of 's'.
363 """
364
365 # This algorithm does multiple expansion, so if vars['foo'] contains
366 # "${bar}", it will expand ${foo} to ${bar}, and then expand
367 # ${bar}... and so forth. This is fine as long as 'vars' comes from
368 # 'parse_makefile()', which takes care of such expansions eagerly,
369 # according to make's variable expansion semantics.
370
Collin Winter5b7e9d72007-08-30 03:52:21 +0000371 while True:
Greg Wardd283ce72000-09-17 00:53:02 +0000372 m = _findvar1_rx.search(s) or _findvar2_rx.search(s)
373 if m:
Greg Wardd283ce72000-09-17 00:53:02 +0000374 (beg, end) = m.span()
375 s = s[0:beg] + vars.get(m.group(1)) + s[end:]
376 else:
377 break
378 return s
Tarek Ziadé36797272010-07-22 12:50:05 +0000379
380
381_config_vars = None
382
383def _init_posix():
384 """Initialize the module as appropriate for POSIX systems."""
385 g = {}
386 # load the installed Makefile:
387 try:
388 filename = get_makefile_filename()
389 parse_makefile(filename, g)
390 except IOError as msg:
391 my_msg = "invalid Python installation: unable to open %s" % filename
392 if hasattr(msg, "strerror"):
393 my_msg = my_msg + " (%s)" % msg.strerror
394
395 raise DistutilsPlatformError(my_msg)
396
397 # load the installed pyconfig.h:
398 try:
399 filename = get_config_h_filename()
Brett Cannon5c035c02010-10-29 22:36:08 +0000400 with open(filename) as file:
401 parse_config_h(file, g)
Tarek Ziadé36797272010-07-22 12:50:05 +0000402 except IOError as msg:
403 my_msg = "invalid Python installation: unable to open %s" % filename
404 if hasattr(msg, "strerror"):
405 my_msg = my_msg + " (%s)" % msg.strerror
406
407 raise DistutilsPlatformError(my_msg)
408
409 # On MacOSX we need to check the setting of the environment variable
410 # MACOSX_DEPLOYMENT_TARGET: configure bases some choices on it so
411 # it needs to be compatible.
412 # If it isn't set we set it to the configure-time value
413 if sys.platform == 'darwin' and 'MACOSX_DEPLOYMENT_TARGET' in g:
414 cfg_target = g['MACOSX_DEPLOYMENT_TARGET']
415 cur_target = os.getenv('MACOSX_DEPLOYMENT_TARGET', '')
416 if cur_target == '':
417 cur_target = cfg_target
418 os.putenv('MACOSX_DEPLOYMENT_TARGET', cfg_target)
419 elif [int(x) for x in cfg_target.split('.')] > [int(x) for x in cur_target.split('.')]:
420 my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: now "%s" but "%s" during configure'
421 % (cur_target, cfg_target))
422 raise DistutilsPlatformError(my_msg)
423
424 # On AIX, there are wrong paths to the linker scripts in the Makefile
425 # -- these paths are relative to the Python source, but when installed
426 # the scripts are in another directory.
427 if python_build:
428 g['LDSHARED'] = g['BLDSHARED']
429
430 elif get_python_version() < '2.1':
431 # The following two branches are for 1.5.2 compatibility.
432 if sys.platform == 'aix4': # what about AIX 3.x ?
433 # Linker script is in the config directory, not in Modules as the
434 # Makefile says.
435 python_lib = get_python_lib(standard_lib=1)
436 ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
437 python_exp = os.path.join(python_lib, 'config', 'python.exp')
438
439 g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp)
440
441 global _config_vars
442 _config_vars = g
443
444
445def _init_nt():
446 """Initialize the module as appropriate for NT"""
447 g = {}
448 # set basic install directories
449 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
450 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
451
452 # XXX hmmm.. a normal install puts include files here
453 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
454
455 g['SO'] = '.pyd'
456 g['EXE'] = ".exe"
457 g['VERSION'] = get_python_version().replace(".", "")
458 g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
459
460 global _config_vars
461 _config_vars = g
462
463
Tarek Ziadé36797272010-07-22 12:50:05 +0000464def _init_os2():
465 """Initialize the module as appropriate for OS/2"""
466 g = {}
467 # set basic install directories
468 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
469 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
470
471 # XXX hmmm.. a normal install puts include files here
472 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
473
474 g['SO'] = '.pyd'
475 g['EXE'] = ".exe"
476
477 global _config_vars
478 _config_vars = g
479
480
481def get_config_vars(*args):
482 """With no arguments, return a dictionary of all configuration
483 variables relevant for the current platform. Generally this includes
484 everything needed to build extensions and install both pure modules and
485 extensions. On Unix, this means every variable defined in Python's
486 installed Makefile; on Windows and Mac OS it's a much smaller set.
487
488 With arguments, return a list of values that result from looking up
489 each argument in the configuration variable dictionary.
490 """
491 global _config_vars
492 if _config_vars is None:
493 func = globals().get("_init_" + os.name)
494 if func:
495 func()
496 else:
497 _config_vars = {}
498
499 # Normalized versions of prefix and exec_prefix are handy to have;
500 # in fact, these are the standard versions used most places in the
501 # Distutils.
502 _config_vars['prefix'] = PREFIX
503 _config_vars['exec_prefix'] = EXEC_PREFIX
504
505 # Convert srcdir into an absolute path if it appears necessary.
506 # Normally it is relative to the build directory. However, during
507 # testing, for example, we might be running a non-installed python
508 # from a different directory.
509 if python_build and os.name == "posix":
510 base = os.path.dirname(os.path.abspath(sys.executable))
511 if (not os.path.isabs(_config_vars['srcdir']) and
512 base != os.getcwd()):
513 # srcdir is relative and we are not in the same directory
514 # as the executable. Assume executable is in the build
515 # directory and make srcdir absolute.
516 srcdir = os.path.join(base, _config_vars['srcdir'])
517 _config_vars['srcdir'] = os.path.normpath(srcdir)
518
519 if sys.platform == 'darwin':
520 kernel_version = os.uname()[2] # Kernel version (8.4.3)
521 major_version = int(kernel_version.split('.')[0])
522
523 if major_version < 8:
524 # On Mac OS X before 10.4, check if -arch and -isysroot
525 # are in CFLAGS or LDFLAGS and remove them if they are.
526 # This is needed when building extensions on a 10.3 system
527 # using a universal build of python.
528 for key in ('LDFLAGS', 'BASECFLAGS',
529 # a number of derived variables. These need to be
530 # patched up as well.
531 'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
532 flags = _config_vars[key]
533 flags = re.sub('-arch\s+\w+\s', ' ', flags, re.ASCII)
534 flags = re.sub('-isysroot [^ \t]*', ' ', flags)
535 _config_vars[key] = flags
536
537 else:
538
539 # Allow the user to override the architecture flags using
540 # an environment variable.
541 # NOTE: This name was introduced by Apple in OSX 10.5 and
542 # is used by several scripting languages distributed with
543 # that OS release.
544
545 if 'ARCHFLAGS' in os.environ:
546 arch = os.environ['ARCHFLAGS']
547 for key in ('LDFLAGS', 'BASECFLAGS',
548 # a number of derived variables. These need to be
549 # patched up as well.
550 'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
551
552 flags = _config_vars[key]
553 flags = re.sub('-arch\s+\w+\s', ' ', flags)
554 flags = flags + ' ' + arch
555 _config_vars[key] = flags
556
557 if args:
558 vals = []
559 for name in args:
560 vals.append(_config_vars.get(name))
561 return vals
562 else:
563 return _config_vars
564
565def get_config_var(name):
566 """Return the value of a single variable using the dictionary
567 returned by 'get_config_vars()'. Equivalent to
568 get_config_vars().get(name)
569 """
570 return get_config_vars().get(name)