blob: 74394abc5ab57757668fff8eeaac40e02cbbfe46 [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
Fred Drake16c8d702002-06-04 15:28:21 +000026# python_build: (Boolean) if true, we're either building Python or
27# building an extension with an un-installed Python, so we use
28# different (hard-wired) directories.
Andrew M. Kuchlingc14fa302001-01-17 15:16:52 +000029
Fred Drake16c8d702002-06-04 15:28:21 +000030argv0_path = os.path.dirname(os.path.abspath(sys.executable))
31landmark = os.path.join(argv0_path, "Modules", "Setup")
32if not os.path.isfile(landmark):
33 python_build = 0
34elif os.path.isfile(os.path.join(argv0_path, "Lib", "os.py")):
Andrew M. Kuchlingc14fa302001-01-17 15:16:52 +000035 python_build = 1
Fred Drake16c8d702002-06-04 15:28:21 +000036else:
37 python_build = os.path.isfile(os.path.join(os.path.dirname(argv0_path),
38 "Lib", "os.py"))
39del argv0_path, landmark
Fred Drakec1ee39a2000-03-09 15:54:52 +000040
Fred Drakec916cdc2001-08-02 20:03:12 +000041
Greg Wardd38e6f72000-04-10 01:17:49 +000042def get_python_inc(plat_specific=0, prefix=None):
Greg Ward7d73b9e2000-03-09 03:16:05 +000043 """Return the directory containing installed Python header files.
Fred Drakec1ee39a2000-03-09 15:54:52 +000044
45 If 'plat_specific' is false (the default), this is the path to the
46 non-platform-specific header files, i.e. Python.h and so on;
47 otherwise, this is the path to platform-specific header files
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +000048 (namely pyconfig.h).
Fred Drakec1ee39a2000-03-09 15:54:52 +000049
Greg Wardd38e6f72000-04-10 01:17:49 +000050 If 'prefix' is supplied, use it instead of sys.prefix or
51 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakeb94b8492001-12-06 20:51:35 +000052 """
Greg Wardd38e6f72000-04-10 01:17:49 +000053 if prefix is None:
Fred Drake70b014d2001-07-18 18:39:56 +000054 prefix = plat_specific and EXEC_PREFIX or PREFIX
Greg Ward7d73b9e2000-03-09 03:16:05 +000055 if os.name == "posix":
Andrew M. Kuchlingc14fa302001-01-17 15:16:52 +000056 if python_build:
Fred Drake16c8d702002-06-04 15:28:21 +000057 base = os.path.dirname(os.path.abspath(sys.executable))
58 if plat_specific:
59 inc_dir = base
60 else:
61 inc_dir = os.path.join(base, "Include")
62 if not os.path.exists(inc_dir):
63 inc_dir = os.path.join(os.path.dirname(base), "Include")
64 return inc_dir
Greg Wardcf6bea32000-04-10 01:15:06 +000065 return os.path.join(prefix, "include", "python" + sys.version[:3])
Greg Ward7d73b9e2000-03-09 03:16:05 +000066 elif os.name == "nt":
Fred Drakec916cdc2001-08-02 20:03:12 +000067 return os.path.join(prefix, "include")
Greg Ward7d73b9e2000-03-09 03:16:05 +000068 elif os.name == "mac":
Jack Jansenab5320b2002-06-26 15:42:49 +000069 if plat_specific:
70 return os.path.join(prefix, "Mac", "Include")
71 else:
72 return os.path.join(prefix, "Include")
Marc-André Lemburg2544f512002-01-31 18:56:00 +000073 elif os.name == "os2":
74 return os.path.join(prefix, "Include")
Greg Ward7d73b9e2000-03-09 03:16:05 +000075 else:
Fred Drake70b014d2001-07-18 18:39:56 +000076 raise DistutilsPlatformError(
77 "I don't know where Python installs its C header files "
78 "on platform '%s'" % os.name)
Greg Ward7d73b9e2000-03-09 03:16:05 +000079
80
Greg Wardd38e6f72000-04-10 01:17:49 +000081def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
Greg Ward7d73b9e2000-03-09 03:16:05 +000082 """Return the directory containing the Python library (standard or
Fred Drakec1ee39a2000-03-09 15:54:52 +000083 site additions).
Greg Ward7d73b9e2000-03-09 03:16:05 +000084
Fred Drakec1ee39a2000-03-09 15:54:52 +000085 If 'plat_specific' is true, return the directory containing
86 platform-specific modules, i.e. any module from a non-pure-Python
87 module distribution; otherwise, return the platform-shared library
88 directory. If 'standard_lib' is true, return the directory
89 containing standard Python library modules; otherwise, return the
90 directory for site-specific modules.
91
Greg Wardd38e6f72000-04-10 01:17:49 +000092 If 'prefix' is supplied, use it instead of sys.prefix or
93 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakec1ee39a2000-03-09 15:54:52 +000094 """
Greg Wardd38e6f72000-04-10 01:17:49 +000095 if prefix is None:
Fred Drake70b014d2001-07-18 18:39:56 +000096 prefix = plat_specific and EXEC_PREFIX or PREFIX
Fred Drakec916cdc2001-08-02 20:03:12 +000097
Greg Ward7d73b9e2000-03-09 03:16:05 +000098 if os.name == "posix":
Greg Wardcf6bea32000-04-10 01:15:06 +000099 libpython = os.path.join(prefix,
Fred Drakec1ee39a2000-03-09 15:54:52 +0000100 "lib", "python" + sys.version[:3])
Greg Ward7d73b9e2000-03-09 03:16:05 +0000101 if standard_lib:
102 return libpython
103 else:
Fred Drakec1ee39a2000-03-09 15:54:52 +0000104 return os.path.join(libpython, "site-packages")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000105
106 elif os.name == "nt":
107 if standard_lib:
Fred Drakec916cdc2001-08-02 20:03:12 +0000108 return os.path.join(prefix, "Lib")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000109 else:
Greg Wardf17efb92001-08-23 20:53:27 +0000110 if sys.version < "2.2":
111 return prefix
112 else:
113 return os.path.join(PREFIX, "Lib", "site-packages")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000114
115 elif os.name == "mac":
Greg Warddc9fe8a2000-08-02 01:49:40 +0000116 if plat_specific:
Greg Ward7d73b9e2000-03-09 03:16:05 +0000117 if standard_lib:
Jack Jansen212a2e12001-09-04 12:01:49 +0000118 return os.path.join(prefix, "Lib", "lib-dynload")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000119 else:
Jack Jansen212a2e12001-09-04 12:01:49 +0000120 return os.path.join(prefix, "Lib", "site-packages")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000121 else:
122 if standard_lib:
Fred Drakec916cdc2001-08-02 20:03:12 +0000123 return os.path.join(prefix, "Lib")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000124 else:
Jack Jansen212a2e12001-09-04 12:01:49 +0000125 return os.path.join(prefix, "Lib", "site-packages")
Marc-André Lemburg2544f512002-01-31 18:56:00 +0000126
127 elif os.name == "os2":
128 if standard_lib:
129 return os.path.join(PREFIX, "Lib")
130 else:
131 return os.path.join(PREFIX, "Lib", "site-packages")
132
Greg Ward7d73b9e2000-03-09 03:16:05 +0000133 else:
Fred Drake70b014d2001-07-18 18:39:56 +0000134 raise DistutilsPlatformError(
135 "I don't know where Python installs its library "
136 "on platform '%s'" % os.name)
Greg Ward7d73b9e2000-03-09 03:16:05 +0000137
Greg Ward7d73b9e2000-03-09 03:16:05 +0000138
Fred Drake70b014d2001-07-18 18:39:56 +0000139def customize_compiler(compiler):
Fred Drakec916cdc2001-08-02 20:03:12 +0000140 """Do any platform-specific customization of a CCompiler instance.
141
142 Mainly needed on Unix, so we can plug in the information that
143 varies across Unices and is stored in Python's Makefile.
Greg Wardbb7baa72000-06-25 02:09:14 +0000144 """
145 if compiler.compiler_type == "unix":
Greg Ward879f0f12000-09-15 01:15:08 +0000146 (cc, opt, ccshared, ldshared, so_ext) = \
147 get_config_vars('CC', 'OPT', 'CCSHARED', 'LDSHARED', 'SO')
Greg Wardbb7baa72000-06-25 02:09:14 +0000148
Greg Ward879f0f12000-09-15 01:15:08 +0000149 cc_cmd = cc + ' ' + opt
150 compiler.set_executables(
151 preprocessor=cc + " -E", # not always!
152 compiler=cc_cmd,
153 compiler_so=cc_cmd + ' ' + ccshared,
154 linker_so=ldshared,
155 linker_exe=cc)
156
157 compiler.shared_lib_extension = so_ext
Greg Wardbb7baa72000-06-25 02:09:14 +0000158
159
Greg Ward9ddaaa11999-01-06 14:46:06 +0000160def get_config_h_filename():
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000161 """Return full pathname of installed pyconfig.h file."""
Fred Drakec916cdc2001-08-02 20:03:12 +0000162 if python_build:
163 inc_dir = os.curdir
164 else:
165 inc_dir = get_python_inc(plat_specific=1)
Marc-André Lemburg7cf92fa2001-07-26 18:06:58 +0000166 if sys.version < '2.2':
167 config_h = 'config.h'
168 else:
169 # The name of the config.h file changed in 2.2
170 config_h = 'pyconfig.h'
171 return os.path.join(inc_dir, config_h)
Greg Ward7d73b9e2000-03-09 03:16:05 +0000172
Greg Ward1190ee31998-12-18 23:46:33 +0000173
Greg Ward9ddaaa11999-01-06 14:46:06 +0000174def get_makefile_filename():
Fred Drake522af3a1999-01-06 16:28:34 +0000175 """Return full pathname of installed Makefile from the Python build."""
Andrew M. Kuchlingc14fa302001-01-17 15:16:52 +0000176 if python_build:
Fred Drake16c8d702002-06-04 15:28:21 +0000177 return os.path.join(os.path.dirname(sys.executable), "Makefile")
Fred Drakec1ee39a2000-03-09 15:54:52 +0000178 lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
179 return os.path.join(lib_dir, "config", "Makefile")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000180
Greg Ward1190ee31998-12-18 23:46:33 +0000181
Greg Ward9ddaaa11999-01-06 14:46:06 +0000182def parse_config_h(fp, g=None):
Fred Drakec1ee39a2000-03-09 15:54:52 +0000183 """Parse a config.h-style file.
184
185 A dictionary containing name/value pairs is returned. If an
186 optional dictionary is passed in as the second argument, it is
187 used instead of a new dictionary.
Fred Drake522af3a1999-01-06 16:28:34 +0000188 """
Greg Ward9ddaaa11999-01-06 14:46:06 +0000189 if g is None:
190 g = {}
Greg Ward1190ee31998-12-18 23:46:33 +0000191 define_rx = re.compile("#define ([A-Z][A-Z0-9_]+) (.*)\n")
192 undef_rx = re.compile("/[*] #undef ([A-Z][A-Z0-9_]+) [*]/\n")
Greg Ward9ddaaa11999-01-06 14:46:06 +0000193 #
Greg Ward1190ee31998-12-18 23:46:33 +0000194 while 1:
195 line = fp.readline()
196 if not line:
197 break
198 m = define_rx.match(line)
199 if m:
200 n, v = m.group(1, 2)
Greg Ward3c8e54b1998-12-22 12:42:04 +0000201 try: v = string.atoi(v)
202 except ValueError: pass
203 g[n] = v
Greg Ward1190ee31998-12-18 23:46:33 +0000204 else:
205 m = undef_rx.match(line)
206 if m:
207 g[m.group(1)] = 0
Greg Ward9ddaaa11999-01-06 14:46:06 +0000208 return g
Greg Ward1190ee31998-12-18 23:46:33 +0000209
Greg Wardd283ce72000-09-17 00:53:02 +0000210
211# Regexes needed for parsing Makefile (and similar syntaxes,
212# like old-style Setup files).
213_variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
214_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
215_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
216
Greg Ward3fff8d22000-09-15 00:03:13 +0000217def parse_makefile(fn, g=None):
Fred Drakec1ee39a2000-03-09 15:54:52 +0000218 """Parse a Makefile-style file.
219
220 A dictionary containing name/value pairs is returned. If an
221 optional dictionary is passed in as the second argument, it is
222 used instead of a new dictionary.
Fred Drake522af3a1999-01-06 16:28:34 +0000223 """
Greg Ward3fff8d22000-09-15 00:03:13 +0000224 from distutils.text_file import TextFile
Greg Wardd283ce72000-09-17 00:53:02 +0000225 fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1)
Greg Ward3fff8d22000-09-15 00:03:13 +0000226
Greg Ward9ddaaa11999-01-06 14:46:06 +0000227 if g is None:
228 g = {}
Greg Ward1190ee31998-12-18 23:46:33 +0000229 done = {}
230 notdone = {}
Greg Ward3fff8d22000-09-15 00:03:13 +0000231
Greg Ward1190ee31998-12-18 23:46:33 +0000232 while 1:
233 line = fp.readline()
Greg Wardd283ce72000-09-17 00:53:02 +0000234 if line is None: # eof
Greg Ward1190ee31998-12-18 23:46:33 +0000235 break
Greg Wardd283ce72000-09-17 00:53:02 +0000236 m = _variable_rx.match(line)
Greg Ward1190ee31998-12-18 23:46:33 +0000237 if m:
238 n, v = m.group(1, 2)
Greg Ward3c8e54b1998-12-22 12:42:04 +0000239 v = string.strip(v)
Greg Ward1190ee31998-12-18 23:46:33 +0000240 if "$" in v:
241 notdone[n] = v
242 else:
Greg Ward3c8e54b1998-12-22 12:42:04 +0000243 try: v = string.atoi(v)
244 except ValueError: pass
Greg Ward1190ee31998-12-18 23:46:33 +0000245 done[n] = v
246
247 # do variable interpolation here
Greg Ward1190ee31998-12-18 23:46:33 +0000248 while notdone:
249 for name in notdone.keys():
250 value = notdone[name]
Greg Wardd283ce72000-09-17 00:53:02 +0000251 m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
Greg Ward1190ee31998-12-18 23:46:33 +0000252 if m:
253 n = m.group(1)
254 if done.has_key(n):
255 after = value[m.end():]
Andrew M. Kuchlingb11bd032001-01-16 16:33:28 +0000256 value = value[:m.start()] + str(done[n]) + after
Greg Ward1190ee31998-12-18 23:46:33 +0000257 if "$" in after:
258 notdone[name] = value
259 else:
Greg Ward3c8e54b1998-12-22 12:42:04 +0000260 try: value = string.atoi(value)
Andrew M. Kuchlingb11bd032001-01-16 16:33:28 +0000261 except ValueError:
262 done[name] = string.strip(value)
263 else:
264 done[name] = value
Greg Ward1190ee31998-12-18 23:46:33 +0000265 del notdone[name]
266 elif notdone.has_key(n):
267 # get it on a subsequent round
268 pass
269 else:
270 done[n] = ""
271 after = value[m.end():]
272 value = value[:m.start()] + after
273 if "$" in after:
274 notdone[name] = value
275 else:
Greg Ward3c8e54b1998-12-22 12:42:04 +0000276 try: value = string.atoi(value)
Andrew M. Kuchlingb11bd032001-01-16 16:33:28 +0000277 except ValueError:
278 done[name] = string.strip(value)
279 else:
280 done[name] = value
Greg Ward1190ee31998-12-18 23:46:33 +0000281 del notdone[name]
282 else:
Greg Ward3c8e54b1998-12-22 12:42:04 +0000283 # bogus variable reference; just drop it since we can't deal
Greg Ward1190ee31998-12-18 23:46:33 +0000284 del notdone[name]
285
Greg Wardd283ce72000-09-17 00:53:02 +0000286 fp.close()
287
Greg Ward1190ee31998-12-18 23:46:33 +0000288 # save the results in the global dictionary
289 g.update(done)
Greg Ward9ddaaa11999-01-06 14:46:06 +0000290 return g
Greg Ward1190ee31998-12-18 23:46:33 +0000291
292
Greg Wardd283ce72000-09-17 00:53:02 +0000293def expand_makefile_vars(s, vars):
294 """Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
295 'string' according to 'vars' (a dictionary mapping variable names to
296 values). Variables not present in 'vars' are silently expanded to the
297 empty string. The variable values in 'vars' should not contain further
298 variable expansions; if 'vars' is the output of 'parse_makefile()',
299 you're fine. Returns a variable-expanded version of 's'.
300 """
301
302 # This algorithm does multiple expansion, so if vars['foo'] contains
303 # "${bar}", it will expand ${foo} to ${bar}, and then expand
304 # ${bar}... and so forth. This is fine as long as 'vars' comes from
305 # 'parse_makefile()', which takes care of such expansions eagerly,
306 # according to make's variable expansion semantics.
307
308 while 1:
309 m = _findvar1_rx.search(s) or _findvar2_rx.search(s)
310 if m:
Greg Wardd283ce72000-09-17 00:53:02 +0000311 (beg, end) = m.span()
312 s = s[0:beg] + vars.get(m.group(1)) + s[end:]
313 else:
314 break
315 return s
316
317
Greg Ward879f0f12000-09-15 01:15:08 +0000318_config_vars = None
319
Greg Ward9ddaaa11999-01-06 14:46:06 +0000320def _init_posix():
Fred Drake522af3a1999-01-06 16:28:34 +0000321 """Initialize the module as appropriate for POSIX systems."""
Greg Ward879f0f12000-09-15 01:15:08 +0000322 g = {}
Greg Warda0ca3f22000-02-02 00:05:14 +0000323 # load the installed Makefile:
Greg Warda570c052000-05-23 23:14:00 +0000324 try:
325 filename = get_makefile_filename()
Greg Ward3fff8d22000-09-15 00:03:13 +0000326 parse_makefile(filename, g)
Greg Warda570c052000-05-23 23:14:00 +0000327 except IOError, msg:
328 my_msg = "invalid Python installation: unable to open %s" % filename
329 if hasattr(msg, "strerror"):
330 my_msg = my_msg + " (%s)" % msg.strerror
331
Fred Drake70b014d2001-07-18 18:39:56 +0000332 raise DistutilsPlatformError(my_msg)
Fred Drakec916cdc2001-08-02 20:03:12 +0000333
334
Greg Ward4f880282000-06-27 01:59:06 +0000335 # On AIX, there are wrong paths to the linker scripts in the Makefile
336 # -- these paths are relative to the Python source, but when installed
337 # the scripts are in another directory.
Neil Schemenauer1a020862001-02-16 03:31:13 +0000338 if python_build:
Andrew M. Kuchling63357732001-02-28 19:40:27 +0000339 g['LDSHARED'] = g['BLDSHARED']
Fred Drakeb94b8492001-12-06 20:51:35 +0000340
Andrew M. Kuchling045af6f2001-09-05 12:02:59 +0000341 elif sys.version < '2.1':
342 # The following two branches are for 1.5.2 compatibility.
343 if sys.platform == 'aix4': # what about AIX 3.x ?
344 # Linker script is in the config directory, not in Modules as the
345 # Makefile says.
346 python_lib = get_python_lib(standard_lib=1)
347 ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
348 python_exp = os.path.join(python_lib, 'config', 'python.exp')
Greg Ward879f0f12000-09-15 01:15:08 +0000349
Andrew M. Kuchling045af6f2001-09-05 12:02:59 +0000350 g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp)
351
352 elif sys.platform == 'beos':
353 # Linker script is in the config directory. In the Makefile it is
354 # relative to the srcdir, which after installation no longer makes
355 # sense.
356 python_lib = get_python_lib(standard_lib=1)
357 linkerscript_name = os.path.basename(string.split(g['LDSHARED'])[0])
358 linkerscript = os.path.join(python_lib, 'config', linkerscript_name)
Fred Drakeb94b8492001-12-06 20:51:35 +0000359
Andrew M. Kuchling045af6f2001-09-05 12:02:59 +0000360 # XXX this isn't the right place to do this: adding the Python
361 # library to the link, if needed, should be in the "build_ext"
362 # command. (It's also needed for non-MS compilers on Windows, and
363 # it's taken care of for them by the 'build_ext.get_libraries()'
364 # method.)
365 g['LDSHARED'] = ("%s -L%s/lib -lpython%s" %
366 (linkerscript, PREFIX, sys.version[0:3]))
Fred Drakeb94b8492001-12-06 20:51:35 +0000367
Greg Ward879f0f12000-09-15 01:15:08 +0000368 global _config_vars
369 _config_vars = g
Greg Ward66e966f2000-09-01 01:23:26 +0000370
Greg Ward9ddaaa11999-01-06 14:46:06 +0000371
Greg Ward4d74d731999-06-08 01:58:36 +0000372def _init_nt():
373 """Initialize the module as appropriate for NT"""
Greg Ward879f0f12000-09-15 01:15:08 +0000374 g = {}
Greg Ward4d74d731999-06-08 01:58:36 +0000375 # set basic install directories
Fred Drakec1ee39a2000-03-09 15:54:52 +0000376 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
377 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
Greg Ward4d74d731999-06-08 01:58:36 +0000378
Greg Ward32162e81999-08-29 18:22:13 +0000379 # XXX hmmm.. a normal install puts include files here
Fred Drakec1ee39a2000-03-09 15:54:52 +0000380 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
Greg Ward32162e81999-08-29 18:22:13 +0000381
Fred Drake69e2c6e2000-02-08 15:55:42 +0000382 g['SO'] = '.pyd'
Greg Ward82d71ca2000-06-03 00:44:30 +0000383 g['EXE'] = ".exe"
Greg Ward879f0f12000-09-15 01:15:08 +0000384
385 global _config_vars
386 _config_vars = g
Greg Ward82d71ca2000-06-03 00:44:30 +0000387
Fred Drake69e2c6e2000-02-08 15:55:42 +0000388
Greg Ward0eff87a2000-03-07 03:30:09 +0000389def _init_mac():
390 """Initialize the module as appropriate for Macintosh systems"""
Greg Ward879f0f12000-09-15 01:15:08 +0000391 g = {}
Greg Ward0eff87a2000-03-07 03:30:09 +0000392 # set basic install directories
Fred Drakec1ee39a2000-03-09 15:54:52 +0000393 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
394 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
Greg Ward0eff87a2000-03-07 03:30:09 +0000395
396 # XXX hmmm.. a normal install puts include files here
Fred Drakec1ee39a2000-03-09 15:54:52 +0000397 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
Greg Ward0eff87a2000-03-07 03:30:09 +0000398
Jack Jansendd13a202001-05-17 12:52:01 +0000399 import MacOS
400 if not hasattr(MacOS, 'runtimemodel'):
Guido van Rossum99f9baa2001-05-17 15:03:14 +0000401 g['SO'] = '.ppc.slb'
Jack Jansendd13a202001-05-17 12:52:01 +0000402 else:
403 g['SO'] = '.%s.slb' % MacOS.runtimemodel
Greg Ward7d73b9e2000-03-09 03:16:05 +0000404
405 # XXX are these used anywhere?
Greg Wardcf6bea32000-04-10 01:15:06 +0000406 g['install_lib'] = os.path.join(EXEC_PREFIX, "Lib")
407 g['install_platlib'] = os.path.join(EXEC_PREFIX, "Mac", "Lib")
Greg Ward0eff87a2000-03-07 03:30:09 +0000408
Jack Jansenab5320b2002-06-26 15:42:49 +0000409 # These are used by the extension module build
410 g['srcdir'] = ':'
Greg Ward879f0f12000-09-15 01:15:08 +0000411 global _config_vars
412 _config_vars = g
Greg Ward9ddaaa11999-01-06 14:46:06 +0000413
Fred Drake69e2c6e2000-02-08 15:55:42 +0000414
Marc-André Lemburg2544f512002-01-31 18:56:00 +0000415def _init_os2():
416 """Initialize the module as appropriate for OS/2"""
417 g = {}
418 # set basic install directories
419 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
420 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
421
422 # XXX hmmm.. a normal install puts include files here
423 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
424
425 g['SO'] = '.pyd'
426 g['EXE'] = ".exe"
427
428 global _config_vars
429 _config_vars = g
430
431
Greg Ward879f0f12000-09-15 01:15:08 +0000432def get_config_vars(*args):
433 """With no arguments, return a dictionary of all configuration
434 variables relevant for the current platform. Generally this includes
435 everything needed to build extensions and install both pure modules and
436 extensions. On Unix, this means every variable defined in Python's
437 installed Makefile; on Windows and Mac OS it's a much smaller set.
438
439 With arguments, return a list of values that result from looking up
440 each argument in the configuration variable dictionary.
441 """
442 global _config_vars
443 if _config_vars is None:
Greg Ward879f0f12000-09-15 01:15:08 +0000444 func = globals().get("_init_" + os.name)
445 if func:
446 func()
447 else:
448 _config_vars = {}
449
450 # Normalized versions of prefix and exec_prefix are handy to have;
451 # in fact, these are the standard versions used most places in the
452 # Distutils.
453 _config_vars['prefix'] = PREFIX
454 _config_vars['exec_prefix'] = EXEC_PREFIX
455
456 if args:
457 vals = []
458 for name in args:
459 vals.append(_config_vars.get(name))
460 return vals
461 else:
462 return _config_vars
463
464def get_config_var(name):
465 """Return the value of a single variable using the dictionary
466 returned by 'get_config_vars()'. Equivalent to
Fred Drakec916cdc2001-08-02 20:03:12 +0000467 get_config_vars().get(name)
Greg Ward879f0f12000-09-15 01:15:08 +0000468 """
469 return get_config_vars().get(name)