blob: 935372cd2b43e4305cca7be30276318714c3085d [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>
10Initial date: 17-Dec-1998
11"""
12
Greg Ward82d71ca2000-06-03 00:44:30 +000013__revision__ = "$Id$"
Greg Ward1190ee31998-12-18 23:46:33 +000014
Greg Ward9ddaaa11999-01-06 14:46:06 +000015import os
16import re
17import string
18import sys
Greg Ward1190ee31998-12-18 23:46:33 +000019
Fred Drakec1ee39a2000-03-09 15:54:52 +000020from errors import DistutilsPlatformError
Greg Warda0ca3f22000-02-02 00:05:14 +000021
Greg Ward879f0f12000-09-15 01:15:08 +000022# These are needed in a couple of spots, so just compute them once.
Greg Wardcf6bea32000-04-10 01:15:06 +000023PREFIX = os.path.normpath(sys.prefix)
24EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
Fred Drakec1ee39a2000-03-09 15:54:52 +000025
Andrew M. Kuchlingc14fa302001-01-17 15:16:52 +000026# Boolean; if it's true, we're still building Python, so
27# we use different (hard-wired) directories.
28
29python_build = 0
30
31def set_python_build():
Fred Drakec916cdc2001-08-02 20:03:12 +000032 """Set the python_build flag to true.
33
34 This means that we're building Python itself. Only called from
35 the setup.py script shipped with Python.
Andrew M. Kuchlingc14fa302001-01-17 15:16:52 +000036 """
Andrew M. Kuchlingc14fa302001-01-17 15:16:52 +000037 global python_build
38 python_build = 1
Fred Drakec1ee39a2000-03-09 15:54:52 +000039
Fred Drakec916cdc2001-08-02 20:03:12 +000040
Greg Wardd38e6f72000-04-10 01:17:49 +000041def get_python_inc(plat_specific=0, prefix=None):
Greg Ward7d73b9e2000-03-09 03:16:05 +000042 """Return the directory containing installed Python header files.
Fred Drakec1ee39a2000-03-09 15:54:52 +000043
44 If 'plat_specific' is false (the default), this is the path to the
45 non-platform-specific header files, i.e. Python.h and so on;
46 otherwise, this is the path to platform-specific header files
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +000047 (namely pyconfig.h).
Fred Drakec1ee39a2000-03-09 15:54:52 +000048
Greg Wardd38e6f72000-04-10 01:17:49 +000049 If 'prefix' is supplied, use it instead of sys.prefix or
50 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakec1ee39a2000-03-09 15:54:52 +000051 """
Greg Wardd38e6f72000-04-10 01:17:49 +000052 if prefix is None:
Fred Drake70b014d2001-07-18 18:39:56 +000053 prefix = plat_specific and EXEC_PREFIX or PREFIX
Greg Ward7d73b9e2000-03-09 03:16:05 +000054 if os.name == "posix":
Andrew M. Kuchlingc14fa302001-01-17 15:16:52 +000055 if python_build:
56 return "Include/"
Greg Wardcf6bea32000-04-10 01:15:06 +000057 return os.path.join(prefix, "include", "python" + sys.version[:3])
Greg Ward7d73b9e2000-03-09 03:16:05 +000058 elif os.name == "nt":
Fred Drakec916cdc2001-08-02 20:03:12 +000059 return os.path.join(prefix, "include")
Greg Ward7d73b9e2000-03-09 03:16:05 +000060 elif os.name == "mac":
Greg Wardcf6bea32000-04-10 01:15:06 +000061 return os.path.join(prefix, "Include")
Greg Ward7d73b9e2000-03-09 03:16:05 +000062 else:
Fred Drake70b014d2001-07-18 18:39:56 +000063 raise DistutilsPlatformError(
64 "I don't know where Python installs its C header files "
65 "on platform '%s'" % os.name)
Greg Ward7d73b9e2000-03-09 03:16:05 +000066
67
Greg Wardd38e6f72000-04-10 01:17:49 +000068def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
Greg Ward7d73b9e2000-03-09 03:16:05 +000069 """Return the directory containing the Python library (standard or
Fred Drakec1ee39a2000-03-09 15:54:52 +000070 site additions).
Greg Ward7d73b9e2000-03-09 03:16:05 +000071
Fred Drakec1ee39a2000-03-09 15:54:52 +000072 If 'plat_specific' is true, return the directory containing
73 platform-specific modules, i.e. any module from a non-pure-Python
74 module distribution; otherwise, return the platform-shared library
75 directory. If 'standard_lib' is true, return the directory
76 containing standard Python library modules; otherwise, return the
77 directory for site-specific modules.
78
Greg Wardd38e6f72000-04-10 01:17:49 +000079 If 'prefix' is supplied, use it instead of sys.prefix or
80 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakec1ee39a2000-03-09 15:54:52 +000081 """
Greg Wardd38e6f72000-04-10 01:17:49 +000082 if prefix is None:
Fred Drake70b014d2001-07-18 18:39:56 +000083 prefix = plat_specific and EXEC_PREFIX or PREFIX
Fred Drakec916cdc2001-08-02 20:03:12 +000084
Greg Ward7d73b9e2000-03-09 03:16:05 +000085 if os.name == "posix":
Greg Wardcf6bea32000-04-10 01:15:06 +000086 libpython = os.path.join(prefix,
Fred Drakec1ee39a2000-03-09 15:54:52 +000087 "lib", "python" + sys.version[:3])
Greg Ward7d73b9e2000-03-09 03:16:05 +000088 if standard_lib:
89 return libpython
90 else:
Fred Drakec1ee39a2000-03-09 15:54:52 +000091 return os.path.join(libpython, "site-packages")
Greg Ward7d73b9e2000-03-09 03:16:05 +000092
93 elif os.name == "nt":
94 if standard_lib:
Fred Drakec916cdc2001-08-02 20:03:12 +000095 return os.path.join(prefix, "Lib")
Greg Ward7d73b9e2000-03-09 03:16:05 +000096 else:
Greg Wardf17efb92001-08-23 20:53:27 +000097 if sys.version < "2.2":
98 return prefix
99 else:
100 return os.path.join(PREFIX, "Lib", "site-packages")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000101
102 elif os.name == "mac":
Greg Warddc9fe8a2000-08-02 01:49:40 +0000103 if plat_specific:
Greg Ward7d73b9e2000-03-09 03:16:05 +0000104 if standard_lib:
Jack Jansen212a2e12001-09-04 12:01:49 +0000105 return os.path.join(prefix, "Lib", "lib-dynload")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000106 else:
Jack Jansen212a2e12001-09-04 12:01:49 +0000107 return os.path.join(prefix, "Lib", "site-packages")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000108 else:
109 if standard_lib:
Fred Drakec916cdc2001-08-02 20:03:12 +0000110 return os.path.join(prefix, "Lib")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000111 else:
Jack Jansen212a2e12001-09-04 12:01:49 +0000112 return os.path.join(prefix, "Lib", "site-packages")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000113 else:
Fred Drake70b014d2001-07-18 18:39:56 +0000114 raise DistutilsPlatformError(
115 "I don't know where Python installs its library "
116 "on platform '%s'" % os.name)
Greg Ward7d73b9e2000-03-09 03:16:05 +0000117
Greg Ward7d73b9e2000-03-09 03:16:05 +0000118
Fred Drake70b014d2001-07-18 18:39:56 +0000119def customize_compiler(compiler):
Fred Drakec916cdc2001-08-02 20:03:12 +0000120 """Do any platform-specific customization of a CCompiler instance.
121
122 Mainly needed on Unix, so we can plug in the information that
123 varies across Unices and is stored in Python's Makefile.
Greg Wardbb7baa72000-06-25 02:09:14 +0000124 """
125 if compiler.compiler_type == "unix":
Greg Ward879f0f12000-09-15 01:15:08 +0000126 (cc, opt, ccshared, ldshared, so_ext) = \
127 get_config_vars('CC', 'OPT', 'CCSHARED', 'LDSHARED', 'SO')
Greg Wardbb7baa72000-06-25 02:09:14 +0000128
Greg Ward879f0f12000-09-15 01:15:08 +0000129 cc_cmd = cc + ' ' + opt
130 compiler.set_executables(
131 preprocessor=cc + " -E", # not always!
132 compiler=cc_cmd,
133 compiler_so=cc_cmd + ' ' + ccshared,
134 linker_so=ldshared,
135 linker_exe=cc)
136
137 compiler.shared_lib_extension = so_ext
Greg Wardbb7baa72000-06-25 02:09:14 +0000138
139
Greg Ward9ddaaa11999-01-06 14:46:06 +0000140def get_config_h_filename():
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000141 """Return full pathname of installed pyconfig.h file."""
Fred Drakec916cdc2001-08-02 20:03:12 +0000142 if python_build:
143 inc_dir = os.curdir
144 else:
145 inc_dir = get_python_inc(plat_specific=1)
Marc-André Lemburg7cf92fa2001-07-26 18:06:58 +0000146 if sys.version < '2.2':
147 config_h = 'config.h'
148 else:
149 # The name of the config.h file changed in 2.2
150 config_h = 'pyconfig.h'
151 return os.path.join(inc_dir, config_h)
Greg Ward7d73b9e2000-03-09 03:16:05 +0000152
Greg Ward1190ee31998-12-18 23:46:33 +0000153
Greg Ward9ddaaa11999-01-06 14:46:06 +0000154def get_makefile_filename():
Fred Drake522af3a1999-01-06 16:28:34 +0000155 """Return full pathname of installed Makefile from the Python build."""
Andrew M. Kuchlingc14fa302001-01-17 15:16:52 +0000156 if python_build:
Neil Schemenauer84d14ba2001-01-24 17:17:20 +0000157 return './Makefile'
Fred Drakec1ee39a2000-03-09 15:54:52 +0000158 lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
159 return os.path.join(lib_dir, "config", "Makefile")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000160
Greg Ward1190ee31998-12-18 23:46:33 +0000161
Greg Ward9ddaaa11999-01-06 14:46:06 +0000162def parse_config_h(fp, g=None):
Fred Drakec1ee39a2000-03-09 15:54:52 +0000163 """Parse a config.h-style file.
164
165 A dictionary containing name/value pairs is returned. If an
166 optional dictionary is passed in as the second argument, it is
167 used instead of a new dictionary.
Fred Drake522af3a1999-01-06 16:28:34 +0000168 """
Greg Ward9ddaaa11999-01-06 14:46:06 +0000169 if g is None:
170 g = {}
Greg Ward1190ee31998-12-18 23:46:33 +0000171 define_rx = re.compile("#define ([A-Z][A-Z0-9_]+) (.*)\n")
172 undef_rx = re.compile("/[*] #undef ([A-Z][A-Z0-9_]+) [*]/\n")
Greg Ward9ddaaa11999-01-06 14:46:06 +0000173 #
Greg Ward1190ee31998-12-18 23:46:33 +0000174 while 1:
175 line = fp.readline()
176 if not line:
177 break
178 m = define_rx.match(line)
179 if m:
180 n, v = m.group(1, 2)
Greg Ward3c8e54b1998-12-22 12:42:04 +0000181 try: v = string.atoi(v)
182 except ValueError: pass
183 g[n] = v
Greg Ward1190ee31998-12-18 23:46:33 +0000184 else:
185 m = undef_rx.match(line)
186 if m:
187 g[m.group(1)] = 0
Greg Ward9ddaaa11999-01-06 14:46:06 +0000188 return g
Greg Ward1190ee31998-12-18 23:46:33 +0000189
Greg Wardd283ce72000-09-17 00:53:02 +0000190
191# Regexes needed for parsing Makefile (and similar syntaxes,
192# like old-style Setup files).
193_variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
194_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
195_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
196
Greg Ward3fff8d22000-09-15 00:03:13 +0000197def parse_makefile(fn, g=None):
Fred Drakec1ee39a2000-03-09 15:54:52 +0000198 """Parse a Makefile-style file.
199
200 A dictionary containing name/value pairs is returned. If an
201 optional dictionary is passed in as the second argument, it is
202 used instead of a new dictionary.
Fred Drake522af3a1999-01-06 16:28:34 +0000203 """
Greg Ward3fff8d22000-09-15 00:03:13 +0000204 from distutils.text_file import TextFile
Greg Wardd283ce72000-09-17 00:53:02 +0000205 fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1)
Greg Ward3fff8d22000-09-15 00:03:13 +0000206
Greg Ward9ddaaa11999-01-06 14:46:06 +0000207 if g is None:
208 g = {}
Greg Ward1190ee31998-12-18 23:46:33 +0000209 done = {}
210 notdone = {}
Greg Ward3fff8d22000-09-15 00:03:13 +0000211
Greg Ward1190ee31998-12-18 23:46:33 +0000212 while 1:
213 line = fp.readline()
Greg Wardd283ce72000-09-17 00:53:02 +0000214 if line is None: # eof
Greg Ward1190ee31998-12-18 23:46:33 +0000215 break
Greg Wardd283ce72000-09-17 00:53:02 +0000216 m = _variable_rx.match(line)
Greg Ward1190ee31998-12-18 23:46:33 +0000217 if m:
218 n, v = m.group(1, 2)
Greg Ward3c8e54b1998-12-22 12:42:04 +0000219 v = string.strip(v)
Greg Ward1190ee31998-12-18 23:46:33 +0000220 if "$" in v:
221 notdone[n] = v
222 else:
Greg Ward3c8e54b1998-12-22 12:42:04 +0000223 try: v = string.atoi(v)
224 except ValueError: pass
Greg Ward1190ee31998-12-18 23:46:33 +0000225 done[n] = v
226
227 # do variable interpolation here
Greg Ward1190ee31998-12-18 23:46:33 +0000228 while notdone:
229 for name in notdone.keys():
230 value = notdone[name]
Greg Wardd283ce72000-09-17 00:53:02 +0000231 m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
Greg Ward1190ee31998-12-18 23:46:33 +0000232 if m:
233 n = m.group(1)
234 if done.has_key(n):
235 after = value[m.end():]
Andrew M. Kuchlingb11bd032001-01-16 16:33:28 +0000236 value = value[:m.start()] + str(done[n]) + after
Greg Ward1190ee31998-12-18 23:46:33 +0000237 if "$" in after:
238 notdone[name] = value
239 else:
Greg Ward3c8e54b1998-12-22 12:42:04 +0000240 try: value = string.atoi(value)
Andrew M. Kuchlingb11bd032001-01-16 16:33:28 +0000241 except ValueError:
242 done[name] = string.strip(value)
243 else:
244 done[name] = value
Greg Ward1190ee31998-12-18 23:46:33 +0000245 del notdone[name]
246 elif notdone.has_key(n):
247 # get it on a subsequent round
248 pass
249 else:
250 done[n] = ""
251 after = value[m.end():]
252 value = value[:m.start()] + after
253 if "$" in after:
254 notdone[name] = value
255 else:
Greg Ward3c8e54b1998-12-22 12:42:04 +0000256 try: value = string.atoi(value)
Andrew M. Kuchlingb11bd032001-01-16 16:33:28 +0000257 except ValueError:
258 done[name] = string.strip(value)
259 else:
260 done[name] = value
Greg Ward1190ee31998-12-18 23:46:33 +0000261 del notdone[name]
262 else:
Greg Ward3c8e54b1998-12-22 12:42:04 +0000263 # bogus variable reference; just drop it since we can't deal
Greg Ward1190ee31998-12-18 23:46:33 +0000264 del notdone[name]
265
Greg Wardd283ce72000-09-17 00:53:02 +0000266 fp.close()
267
Greg Ward1190ee31998-12-18 23:46:33 +0000268 # save the results in the global dictionary
269 g.update(done)
Greg Ward9ddaaa11999-01-06 14:46:06 +0000270 return g
Greg Ward1190ee31998-12-18 23:46:33 +0000271
272
Greg Wardd283ce72000-09-17 00:53:02 +0000273def expand_makefile_vars(s, vars):
274 """Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
275 'string' according to 'vars' (a dictionary mapping variable names to
276 values). Variables not present in 'vars' are silently expanded to the
277 empty string. The variable values in 'vars' should not contain further
278 variable expansions; if 'vars' is the output of 'parse_makefile()',
279 you're fine. Returns a variable-expanded version of 's'.
280 """
281
282 # This algorithm does multiple expansion, so if vars['foo'] contains
283 # "${bar}", it will expand ${foo} to ${bar}, and then expand
284 # ${bar}... and so forth. This is fine as long as 'vars' comes from
285 # 'parse_makefile()', which takes care of such expansions eagerly,
286 # according to make's variable expansion semantics.
287
288 while 1:
289 m = _findvar1_rx.search(s) or _findvar2_rx.search(s)
290 if m:
291 name = m.group(1)
292 (beg, end) = m.span()
293 s = s[0:beg] + vars.get(m.group(1)) + s[end:]
294 else:
295 break
296 return s
297
298
Greg Ward879f0f12000-09-15 01:15:08 +0000299_config_vars = None
300
Greg Ward9ddaaa11999-01-06 14:46:06 +0000301def _init_posix():
Fred Drake522af3a1999-01-06 16:28:34 +0000302 """Initialize the module as appropriate for POSIX systems."""
Greg Ward879f0f12000-09-15 01:15:08 +0000303 g = {}
Greg Warda0ca3f22000-02-02 00:05:14 +0000304 # load the installed Makefile:
Greg Warda570c052000-05-23 23:14:00 +0000305 try:
306 filename = get_makefile_filename()
Greg Ward3fff8d22000-09-15 00:03:13 +0000307 parse_makefile(filename, g)
Greg Warda570c052000-05-23 23:14:00 +0000308 except IOError, msg:
309 my_msg = "invalid Python installation: unable to open %s" % filename
310 if hasattr(msg, "strerror"):
311 my_msg = my_msg + " (%s)" % msg.strerror
312
Fred Drake70b014d2001-07-18 18:39:56 +0000313 raise DistutilsPlatformError(my_msg)
Fred Drakec916cdc2001-08-02 20:03:12 +0000314
315
Greg Ward4f880282000-06-27 01:59:06 +0000316 # On AIX, there are wrong paths to the linker scripts in the Makefile
317 # -- these paths are relative to the Python source, but when installed
318 # the scripts are in another directory.
Neil Schemenauer1a020862001-02-16 03:31:13 +0000319 if python_build:
Andrew M. Kuchling63357732001-02-28 19:40:27 +0000320 g['LDSHARED'] = g['BLDSHARED']
Andrew M. Kuchling045af6f2001-09-05 12:02:59 +0000321
322 elif sys.version < '2.1':
323 # The following two branches are for 1.5.2 compatibility.
324 if sys.platform == 'aix4': # what about AIX 3.x ?
325 # Linker script is in the config directory, not in Modules as the
326 # Makefile says.
327 python_lib = get_python_lib(standard_lib=1)
328 ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
329 python_exp = os.path.join(python_lib, 'config', 'python.exp')
Greg Ward879f0f12000-09-15 01:15:08 +0000330
Andrew M. Kuchling045af6f2001-09-05 12:02:59 +0000331 g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp)
332
333 elif sys.platform == 'beos':
334 # Linker script is in the config directory. In the Makefile it is
335 # relative to the srcdir, which after installation no longer makes
336 # sense.
337 python_lib = get_python_lib(standard_lib=1)
338 linkerscript_name = os.path.basename(string.split(g['LDSHARED'])[0])
339 linkerscript = os.path.join(python_lib, 'config', linkerscript_name)
340
341 # XXX this isn't the right place to do this: adding the Python
342 # library to the link, if needed, should be in the "build_ext"
343 # command. (It's also needed for non-MS compilers on Windows, and
344 # it's taken care of for them by the 'build_ext.get_libraries()'
345 # method.)
346 g['LDSHARED'] = ("%s -L%s/lib -lpython%s" %
347 (linkerscript, PREFIX, sys.version[0:3]))
348
Greg Ward879f0f12000-09-15 01:15:08 +0000349 global _config_vars
350 _config_vars = g
Greg Ward66e966f2000-09-01 01:23:26 +0000351
Greg Ward9ddaaa11999-01-06 14:46:06 +0000352
Greg Ward4d74d731999-06-08 01:58:36 +0000353def _init_nt():
354 """Initialize the module as appropriate for NT"""
Greg Ward879f0f12000-09-15 01:15:08 +0000355 g = {}
Greg Ward4d74d731999-06-08 01:58:36 +0000356 # set basic install directories
Fred Drakec1ee39a2000-03-09 15:54:52 +0000357 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
358 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
Greg Ward4d74d731999-06-08 01:58:36 +0000359
Greg Ward32162e81999-08-29 18:22:13 +0000360 # XXX hmmm.. a normal install puts include files here
Fred Drakec1ee39a2000-03-09 15:54:52 +0000361 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
Greg Ward32162e81999-08-29 18:22:13 +0000362
Fred Drake69e2c6e2000-02-08 15:55:42 +0000363 g['SO'] = '.pyd'
Greg Ward82d71ca2000-06-03 00:44:30 +0000364 g['EXE'] = ".exe"
Greg Ward879f0f12000-09-15 01:15:08 +0000365
366 global _config_vars
367 _config_vars = g
Greg Ward82d71ca2000-06-03 00:44:30 +0000368
Fred Drake69e2c6e2000-02-08 15:55:42 +0000369
Greg Ward0eff87a2000-03-07 03:30:09 +0000370def _init_mac():
371 """Initialize the module as appropriate for Macintosh systems"""
Greg Ward879f0f12000-09-15 01:15:08 +0000372 g = {}
Greg Ward0eff87a2000-03-07 03:30:09 +0000373 # set basic install directories
Fred Drakec1ee39a2000-03-09 15:54:52 +0000374 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
375 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
Greg Ward0eff87a2000-03-07 03:30:09 +0000376
377 # XXX hmmm.. a normal install puts include files here
Fred Drakec1ee39a2000-03-09 15:54:52 +0000378 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
Greg Ward0eff87a2000-03-07 03:30:09 +0000379
Jack Jansendd13a202001-05-17 12:52:01 +0000380 import MacOS
381 if not hasattr(MacOS, 'runtimemodel'):
Guido van Rossum99f9baa2001-05-17 15:03:14 +0000382 g['SO'] = '.ppc.slb'
Jack Jansendd13a202001-05-17 12:52:01 +0000383 else:
384 g['SO'] = '.%s.slb' % MacOS.runtimemodel
Greg Ward7d73b9e2000-03-09 03:16:05 +0000385
386 # XXX are these used anywhere?
Greg Wardcf6bea32000-04-10 01:15:06 +0000387 g['install_lib'] = os.path.join(EXEC_PREFIX, "Lib")
388 g['install_platlib'] = os.path.join(EXEC_PREFIX, "Mac", "Lib")
Greg Ward0eff87a2000-03-07 03:30:09 +0000389
Greg Ward879f0f12000-09-15 01:15:08 +0000390 global _config_vars
391 _config_vars = g
Greg Ward9ddaaa11999-01-06 14:46:06 +0000392
Fred Drake69e2c6e2000-02-08 15:55:42 +0000393
Greg Ward879f0f12000-09-15 01:15:08 +0000394def get_config_vars(*args):
395 """With no arguments, return a dictionary of all configuration
396 variables relevant for the current platform. Generally this includes
397 everything needed to build extensions and install both pure modules and
398 extensions. On Unix, this means every variable defined in Python's
399 installed Makefile; on Windows and Mac OS it's a much smaller set.
400
401 With arguments, return a list of values that result from looking up
402 each argument in the configuration variable dictionary.
403 """
404 global _config_vars
405 if _config_vars is None:
Greg Ward879f0f12000-09-15 01:15:08 +0000406 func = globals().get("_init_" + os.name)
407 if func:
408 func()
409 else:
410 _config_vars = {}
411
412 # Normalized versions of prefix and exec_prefix are handy to have;
413 # in fact, these are the standard versions used most places in the
414 # Distutils.
415 _config_vars['prefix'] = PREFIX
416 _config_vars['exec_prefix'] = EXEC_PREFIX
417
418 if args:
419 vals = []
420 for name in args:
421 vals.append(_config_vars.get(name))
422 return vals
423 else:
424 return _config_vars
425
426def get_config_var(name):
427 """Return the value of a single variable using the dictionary
428 returned by 'get_config_vars()'. Equivalent to
Fred Drakec916cdc2001-08-02 20:03:12 +0000429 get_config_vars().get(name)
Greg Ward879f0f12000-09-15 01:15:08 +0000430 """
431 return get_config_vars().get(name)