blob: aa3636f609c1960ac6a42657012a6a5d41bb7a0d [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
Greg Ward9ddaaa11999-01-06 14:46:06 +000014import os
15import re
Andrew M. Kuchling33635aa2002-11-13 17:03:05 +000016import string
Greg Ward9ddaaa11999-01-06 14:46:06 +000017import sys
Greg Ward1190ee31998-12-18 23:46:33 +000018
Fred Drakec1ee39a2000-03-09 15:54:52 +000019from errors import DistutilsPlatformError
Greg Warda0ca3f22000-02-02 00:05:14 +000020
Greg Ward879f0f12000-09-15 01:15:08 +000021# These are needed in a couple of spots, so just compute them once.
Greg Wardcf6bea32000-04-10 01:15:06 +000022PREFIX = os.path.normpath(sys.prefix)
23EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
Fred Drakec1ee39a2000-03-09 15:54:52 +000024
Fred Drake16c8d702002-06-04 15:28:21 +000025# python_build: (Boolean) if true, we're either building Python or
26# building an extension with an un-installed Python, so we use
27# different (hard-wired) directories.
Andrew M. Kuchlingc14fa302001-01-17 15:16:52 +000028
Fred Drake16c8d702002-06-04 15:28:21 +000029argv0_path = os.path.dirname(os.path.abspath(sys.executable))
30landmark = os.path.join(argv0_path, "Modules", "Setup")
Michael W. Hudson6b7d69d2002-07-12 09:16:44 +000031
32python_build = os.path.isfile(landmark)
33
Fred Drake16c8d702002-06-04 15:28:21 +000034del argv0_path, landmark
Fred Drakec1ee39a2000-03-09 15:54:52 +000035
Fred Drakec916cdc2001-08-02 20:03:12 +000036
Andrew M. Kuchling0ff98b92002-11-14 01:43:00 +000037def get_python_version ():
38 """Return a string containing the major and minor Python version,
39 leaving off the patchlevel. Sample return values could be '1.5'
40 or '2.2'.
41 """
42 return sys.version[:3]
43
44
Greg Wardd38e6f72000-04-10 01:17:49 +000045def get_python_inc(plat_specific=0, prefix=None):
Greg Ward7d73b9e2000-03-09 03:16:05 +000046 """Return the directory containing installed Python header files.
Fred Drakec1ee39a2000-03-09 15:54:52 +000047
48 If 'plat_specific' is false (the default), this is the path to the
49 non-platform-specific header files, i.e. Python.h and so on;
50 otherwise, this is the path to platform-specific header files
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +000051 (namely pyconfig.h).
Fred Drakec1ee39a2000-03-09 15:54:52 +000052
Greg Wardd38e6f72000-04-10 01:17:49 +000053 If 'prefix' is supplied, use it instead of sys.prefix or
54 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakeb94b8492001-12-06 20:51:35 +000055 """
Greg Wardd38e6f72000-04-10 01:17:49 +000056 if prefix is None:
Fred Drake70b014d2001-07-18 18:39:56 +000057 prefix = plat_specific and EXEC_PREFIX or PREFIX
Greg Ward7d73b9e2000-03-09 03:16:05 +000058 if os.name == "posix":
Andrew M. Kuchlingc14fa302001-01-17 15:16:52 +000059 if python_build:
Fred Drake16c8d702002-06-04 15:28:21 +000060 base = os.path.dirname(os.path.abspath(sys.executable))
61 if plat_specific:
62 inc_dir = base
63 else:
64 inc_dir = os.path.join(base, "Include")
65 if not os.path.exists(inc_dir):
66 inc_dir = os.path.join(os.path.dirname(base), "Include")
67 return inc_dir
Greg Wardcf6bea32000-04-10 01:15:06 +000068 return os.path.join(prefix, "include", "python" + sys.version[:3])
Greg Ward7d73b9e2000-03-09 03:16:05 +000069 elif os.name == "nt":
Fred Drakec916cdc2001-08-02 20:03:12 +000070 return os.path.join(prefix, "include")
Greg Ward7d73b9e2000-03-09 03:16:05 +000071 elif os.name == "mac":
Neal Norwitz80a3e0a2002-06-26 22:05:33 +000072 if plat_specific:
73 return os.path.join(prefix, "Mac", "Include")
74 else:
75 return os.path.join(prefix, "Include")
Marc-André Lemburg2544f512002-01-31 18:56:00 +000076 elif os.name == "os2":
77 return os.path.join(prefix, "Include")
Greg Ward7d73b9e2000-03-09 03:16:05 +000078 else:
Fred Drake70b014d2001-07-18 18:39:56 +000079 raise DistutilsPlatformError(
80 "I don't know where Python installs its C header files "
81 "on platform '%s'" % os.name)
Greg Ward7d73b9e2000-03-09 03:16:05 +000082
83
Greg Wardd38e6f72000-04-10 01:17:49 +000084def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
Greg Ward7d73b9e2000-03-09 03:16:05 +000085 """Return the directory containing the Python library (standard or
Fred Drakec1ee39a2000-03-09 15:54:52 +000086 site additions).
Greg Ward7d73b9e2000-03-09 03:16:05 +000087
Fred Drakec1ee39a2000-03-09 15:54:52 +000088 If 'plat_specific' is true, return the directory containing
89 platform-specific modules, i.e. any module from a non-pure-Python
90 module distribution; otherwise, return the platform-shared library
91 directory. If 'standard_lib' is true, return the directory
92 containing standard Python library modules; otherwise, return the
93 directory for site-specific modules.
94
Greg Wardd38e6f72000-04-10 01:17:49 +000095 If 'prefix' is supplied, use it instead of sys.prefix or
96 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakec1ee39a2000-03-09 15:54:52 +000097 """
Greg Wardd38e6f72000-04-10 01:17:49 +000098 if prefix is None:
Fred Drake70b014d2001-07-18 18:39:56 +000099 prefix = plat_specific and EXEC_PREFIX or PREFIX
Fred Drakec916cdc2001-08-02 20:03:12 +0000100
Greg Ward7d73b9e2000-03-09 03:16:05 +0000101 if os.name == "posix":
Greg Wardcf6bea32000-04-10 01:15:06 +0000102 libpython = os.path.join(prefix,
Andrew M. Kuchling0ff98b92002-11-14 01:43:00 +0000103 "lib", "python" + get_python_version())
Greg Ward7d73b9e2000-03-09 03:16:05 +0000104 if standard_lib:
105 return libpython
106 else:
Fred Drakec1ee39a2000-03-09 15:54:52 +0000107 return os.path.join(libpython, "site-packages")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000108
109 elif os.name == "nt":
110 if standard_lib:
Fred Drakec916cdc2001-08-02 20:03:12 +0000111 return os.path.join(prefix, "Lib")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000112 else:
Greg Wardf17efb92001-08-23 20:53:27 +0000113 if sys.version < "2.2":
114 return prefix
115 else:
116 return os.path.join(PREFIX, "Lib", "site-packages")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000117
118 elif os.name == "mac":
Greg Warddc9fe8a2000-08-02 01:49:40 +0000119 if plat_specific:
Greg Ward7d73b9e2000-03-09 03:16:05 +0000120 if standard_lib:
Jack Jansen212a2e12001-09-04 12:01:49 +0000121 return os.path.join(prefix, "Lib", "lib-dynload")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000122 else:
Jack Jansen212a2e12001-09-04 12:01:49 +0000123 return os.path.join(prefix, "Lib", "site-packages")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000124 else:
125 if standard_lib:
Fred Drakec916cdc2001-08-02 20:03:12 +0000126 return os.path.join(prefix, "Lib")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000127 else:
Jack Jansen212a2e12001-09-04 12:01:49 +0000128 return os.path.join(prefix, "Lib", "site-packages")
Marc-André Lemburg2544f512002-01-31 18:56:00 +0000129
130 elif os.name == "os2":
131 if standard_lib:
132 return os.path.join(PREFIX, "Lib")
133 else:
134 return os.path.join(PREFIX, "Lib", "site-packages")
135
Greg Ward7d73b9e2000-03-09 03:16:05 +0000136 else:
Fred Drake70b014d2001-07-18 18:39:56 +0000137 raise DistutilsPlatformError(
138 "I don't know where Python installs its library "
139 "on platform '%s'" % os.name)
Greg Ward7d73b9e2000-03-09 03:16:05 +0000140
Greg Ward7d73b9e2000-03-09 03:16:05 +0000141
Fred Drake70b014d2001-07-18 18:39:56 +0000142def customize_compiler(compiler):
Fred Drakec916cdc2001-08-02 20:03:12 +0000143 """Do any platform-specific customization of a CCompiler instance.
144
145 Mainly needed on Unix, so we can plug in the information that
146 varies across Unices and is stored in Python's Makefile.
Greg Wardbb7baa72000-06-25 02:09:14 +0000147 """
148 if compiler.compiler_type == "unix":
Gustavo Niemeyer6b016852002-11-05 16:12:02 +0000149 (cc, cxx, opt, ccshared, ldshared, so_ext) = \
150 get_config_vars('CC', 'CXX', 'OPT', 'CCSHARED', 'LDSHARED', 'SO')
Greg Wardbb7baa72000-06-25 02:09:14 +0000151
Andrew M. Kuchling29c86232002-11-04 19:53:24 +0000152 if os.environ.has_key('CC'):
153 cc = os.environ['CC']
Gustavo Niemeyer6b016852002-11-05 16:12:02 +0000154 if os.environ.has_key('CXX'):
155 cxx = os.environ['CXX']
Andrew M. Kuchling29c86232002-11-04 19:53:24 +0000156 if os.environ.has_key('CPP'):
157 cpp = os.environ['CPP']
158 else:
159 cpp = cc + " -E" # not always
160 if os.environ.has_key('LDFLAGS'):
161 ldshared = ldshared + ' ' + os.environ['LDFLAGS']
162 if os.environ.has_key('CFLAGS'):
163 opt = opt + ' ' + os.environ['CFLAGS']
164 ldshared = ldshared + ' ' + os.environ['CFLAGS']
165 if os.environ.has_key('CPPFLAGS'):
166 cpp = cpp + ' ' + os.environ['CPPFLAGS']
167 opt = opt + ' ' + os.environ['CPPFLAGS']
168 ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
169
Greg Ward879f0f12000-09-15 01:15:08 +0000170 cc_cmd = cc + ' ' + opt
171 compiler.set_executables(
Andrew M. Kuchling29c86232002-11-04 19:53:24 +0000172 preprocessor=cpp,
Greg Ward879f0f12000-09-15 01:15:08 +0000173 compiler=cc_cmd,
174 compiler_so=cc_cmd + ' ' + ccshared,
Gustavo Niemeyer6b016852002-11-05 16:12:02 +0000175 compiler_cxx=cxx,
Greg Ward879f0f12000-09-15 01:15:08 +0000176 linker_so=ldshared,
177 linker_exe=cc)
178
179 compiler.shared_lib_extension = so_ext
Greg Wardbb7baa72000-06-25 02:09:14 +0000180
181
Greg Ward9ddaaa11999-01-06 14:46:06 +0000182def get_config_h_filename():
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000183 """Return full pathname of installed pyconfig.h file."""
Fred Drakec916cdc2001-08-02 20:03:12 +0000184 if python_build:
185 inc_dir = os.curdir
186 else:
187 inc_dir = get_python_inc(plat_specific=1)
Marc-André Lemburg7cf92fa2001-07-26 18:06:58 +0000188 if sys.version < '2.2':
189 config_h = 'config.h'
190 else:
191 # The name of the config.h file changed in 2.2
192 config_h = 'pyconfig.h'
193 return os.path.join(inc_dir, config_h)
Greg Ward7d73b9e2000-03-09 03:16:05 +0000194
Greg Ward1190ee31998-12-18 23:46:33 +0000195
Greg Ward9ddaaa11999-01-06 14:46:06 +0000196def get_makefile_filename():
Fred Drake522af3a1999-01-06 16:28:34 +0000197 """Return full pathname of installed Makefile from the Python build."""
Andrew M. Kuchlingc14fa302001-01-17 15:16:52 +0000198 if python_build:
Fred Drake16c8d702002-06-04 15:28:21 +0000199 return os.path.join(os.path.dirname(sys.executable), "Makefile")
Fred Drakec1ee39a2000-03-09 15:54:52 +0000200 lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
201 return os.path.join(lib_dir, "config", "Makefile")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000202
Greg Ward1190ee31998-12-18 23:46:33 +0000203
Greg Ward9ddaaa11999-01-06 14:46:06 +0000204def parse_config_h(fp, g=None):
Fred Drakec1ee39a2000-03-09 15:54:52 +0000205 """Parse a config.h-style file.
206
207 A dictionary containing name/value pairs is returned. If an
208 optional dictionary is passed in as the second argument, it is
209 used instead of a new dictionary.
Fred Drake522af3a1999-01-06 16:28:34 +0000210 """
Greg Ward9ddaaa11999-01-06 14:46:06 +0000211 if g is None:
212 g = {}
Greg Ward1190ee31998-12-18 23:46:33 +0000213 define_rx = re.compile("#define ([A-Z][A-Z0-9_]+) (.*)\n")
214 undef_rx = re.compile("/[*] #undef ([A-Z][A-Z0-9_]+) [*]/\n")
Greg Ward9ddaaa11999-01-06 14:46:06 +0000215 #
Greg Ward1190ee31998-12-18 23:46:33 +0000216 while 1:
217 line = fp.readline()
218 if not line:
219 break
220 m = define_rx.match(line)
221 if m:
222 n, v = m.group(1, 2)
Jeremy Hyltona5f4c072002-11-05 20:11:08 +0000223 try: v = int(v)
Greg Ward3c8e54b1998-12-22 12:42:04 +0000224 except ValueError: pass
225 g[n] = v
Greg Ward1190ee31998-12-18 23:46:33 +0000226 else:
227 m = undef_rx.match(line)
228 if m:
229 g[m.group(1)] = 0
Greg Ward9ddaaa11999-01-06 14:46:06 +0000230 return g
Greg Ward1190ee31998-12-18 23:46:33 +0000231
Greg Wardd283ce72000-09-17 00:53:02 +0000232
233# Regexes needed for parsing Makefile (and similar syntaxes,
234# like old-style Setup files).
235_variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
236_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
237_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
238
Greg Ward3fff8d22000-09-15 00:03:13 +0000239def parse_makefile(fn, g=None):
Fred Drakec1ee39a2000-03-09 15:54:52 +0000240 """Parse a Makefile-style file.
241
242 A dictionary containing name/value pairs is returned. If an
243 optional dictionary is passed in as the second argument, it is
244 used instead of a new dictionary.
Fred Drake522af3a1999-01-06 16:28:34 +0000245 """
Greg Ward3fff8d22000-09-15 00:03:13 +0000246 from distutils.text_file import TextFile
Greg Wardd283ce72000-09-17 00:53:02 +0000247 fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1)
Greg Ward3fff8d22000-09-15 00:03:13 +0000248
Greg Ward9ddaaa11999-01-06 14:46:06 +0000249 if g is None:
250 g = {}
Greg Ward1190ee31998-12-18 23:46:33 +0000251 done = {}
252 notdone = {}
Greg Ward3fff8d22000-09-15 00:03:13 +0000253
Greg Ward1190ee31998-12-18 23:46:33 +0000254 while 1:
255 line = fp.readline()
Greg Wardd283ce72000-09-17 00:53:02 +0000256 if line is None: # eof
Greg Ward1190ee31998-12-18 23:46:33 +0000257 break
Greg Wardd283ce72000-09-17 00:53:02 +0000258 m = _variable_rx.match(line)
Greg Ward1190ee31998-12-18 23:46:33 +0000259 if m:
260 n, v = m.group(1, 2)
Andrew M. Kuchling33635aa2002-11-13 17:03:05 +0000261 v = string.strip(v)
Greg Ward1190ee31998-12-18 23:46:33 +0000262 if "$" in v:
263 notdone[n] = v
264 else:
Jeremy Hyltona5f4c072002-11-05 20:11:08 +0000265 try: v = int(v)
Greg Ward3c8e54b1998-12-22 12:42:04 +0000266 except ValueError: pass
Greg Ward1190ee31998-12-18 23:46:33 +0000267 done[n] = v
268
269 # do variable interpolation here
Greg Ward1190ee31998-12-18 23:46:33 +0000270 while notdone:
271 for name in notdone.keys():
272 value = notdone[name]
Greg Wardd283ce72000-09-17 00:53:02 +0000273 m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
Greg Ward1190ee31998-12-18 23:46:33 +0000274 if m:
275 n = m.group(1)
276 if done.has_key(n):
277 after = value[m.end():]
Andrew M. Kuchlingb11bd032001-01-16 16:33:28 +0000278 value = value[:m.start()] + str(done[n]) + after
Greg Ward1190ee31998-12-18 23:46:33 +0000279 if "$" in after:
280 notdone[name] = value
281 else:
Jeremy Hyltona5f4c072002-11-05 20:11:08 +0000282 try: value = int(value)
Andrew M. Kuchlingb11bd032001-01-16 16:33:28 +0000283 except ValueError:
Andrew M. Kuchling33635aa2002-11-13 17:03:05 +0000284 done[name] = string.strip(value)
Andrew M. Kuchlingb11bd032001-01-16 16:33:28 +0000285 else:
286 done[name] = value
Greg Ward1190ee31998-12-18 23:46:33 +0000287 del notdone[name]
288 elif notdone.has_key(n):
289 # get it on a subsequent round
290 pass
291 else:
292 done[n] = ""
293 after = value[m.end():]
294 value = value[:m.start()] + after
295 if "$" in after:
296 notdone[name] = value
297 else:
Jeremy Hyltona5f4c072002-11-05 20:11:08 +0000298 try: value = int(value)
Andrew M. Kuchlingb11bd032001-01-16 16:33:28 +0000299 except ValueError:
Andrew M. Kuchling33635aa2002-11-13 17:03:05 +0000300 done[name] = string.strip(value)
Andrew M. Kuchlingb11bd032001-01-16 16:33:28 +0000301 else:
302 done[name] = value
Greg Ward1190ee31998-12-18 23:46:33 +0000303 del notdone[name]
304 else:
Greg Ward3c8e54b1998-12-22 12:42:04 +0000305 # bogus variable reference; just drop it since we can't deal
Greg Ward1190ee31998-12-18 23:46:33 +0000306 del notdone[name]
307
Greg Wardd283ce72000-09-17 00:53:02 +0000308 fp.close()
309
Greg Ward1190ee31998-12-18 23:46:33 +0000310 # save the results in the global dictionary
311 g.update(done)
Greg Ward9ddaaa11999-01-06 14:46:06 +0000312 return g
Greg Ward1190ee31998-12-18 23:46:33 +0000313
314
Greg Wardd283ce72000-09-17 00:53:02 +0000315def expand_makefile_vars(s, vars):
316 """Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
317 'string' according to 'vars' (a dictionary mapping variable names to
318 values). Variables not present in 'vars' are silently expanded to the
319 empty string. The variable values in 'vars' should not contain further
320 variable expansions; if 'vars' is the output of 'parse_makefile()',
321 you're fine. Returns a variable-expanded version of 's'.
322 """
323
324 # This algorithm does multiple expansion, so if vars['foo'] contains
325 # "${bar}", it will expand ${foo} to ${bar}, and then expand
326 # ${bar}... and so forth. This is fine as long as 'vars' comes from
327 # 'parse_makefile()', which takes care of such expansions eagerly,
328 # according to make's variable expansion semantics.
329
330 while 1:
331 m = _findvar1_rx.search(s) or _findvar2_rx.search(s)
332 if m:
Greg Wardd283ce72000-09-17 00:53:02 +0000333 (beg, end) = m.span()
334 s = s[0:beg] + vars.get(m.group(1)) + s[end:]
335 else:
336 break
337 return s
338
339
Greg Ward879f0f12000-09-15 01:15:08 +0000340_config_vars = None
341
Greg Ward9ddaaa11999-01-06 14:46:06 +0000342def _init_posix():
Fred Drake522af3a1999-01-06 16:28:34 +0000343 """Initialize the module as appropriate for POSIX systems."""
Greg Ward879f0f12000-09-15 01:15:08 +0000344 g = {}
Greg Warda0ca3f22000-02-02 00:05:14 +0000345 # load the installed Makefile:
Greg Warda570c052000-05-23 23:14:00 +0000346 try:
347 filename = get_makefile_filename()
Greg Ward3fff8d22000-09-15 00:03:13 +0000348 parse_makefile(filename, g)
Greg Warda570c052000-05-23 23:14:00 +0000349 except IOError, msg:
350 my_msg = "invalid Python installation: unable to open %s" % filename
351 if hasattr(msg, "strerror"):
352 my_msg = my_msg + " (%s)" % msg.strerror
353
Fred Drake70b014d2001-07-18 18:39:56 +0000354 raise DistutilsPlatformError(my_msg)
Fred Drakec916cdc2001-08-02 20:03:12 +0000355
356
Greg Ward4f880282000-06-27 01:59:06 +0000357 # On AIX, there are wrong paths to the linker scripts in the Makefile
358 # -- these paths are relative to the Python source, but when installed
359 # the scripts are in another directory.
Neil Schemenauer1a020862001-02-16 03:31:13 +0000360 if python_build:
Andrew M. Kuchling63357732001-02-28 19:40:27 +0000361 g['LDSHARED'] = g['BLDSHARED']
Fred Drakeb94b8492001-12-06 20:51:35 +0000362
Andrew M. Kuchling045af6f2001-09-05 12:02:59 +0000363 elif sys.version < '2.1':
364 # The following two branches are for 1.5.2 compatibility.
365 if sys.platform == 'aix4': # what about AIX 3.x ?
366 # Linker script is in the config directory, not in Modules as the
367 # Makefile says.
368 python_lib = get_python_lib(standard_lib=1)
369 ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
370 python_exp = os.path.join(python_lib, 'config', 'python.exp')
Greg Ward879f0f12000-09-15 01:15:08 +0000371
Andrew M. Kuchling045af6f2001-09-05 12:02:59 +0000372 g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp)
373
374 elif sys.platform == 'beos':
375 # Linker script is in the config directory. In the Makefile it is
376 # relative to the srcdir, which after installation no longer makes
377 # sense.
378 python_lib = get_python_lib(standard_lib=1)
Andrew M. Kuchling33635aa2002-11-13 17:03:05 +0000379 linkerscript_path = string.split(g['LDSHARED'])[0]
380 linkerscript_name = os.path.basename(linkerscript_path)
Jeremy Hyltona5f4c072002-11-05 20:11:08 +0000381 linkerscript = os.path.join(python_lib, 'config',
382 linkerscript_name)
Fred Drakeb94b8492001-12-06 20:51:35 +0000383
Andrew M. Kuchling045af6f2001-09-05 12:02:59 +0000384 # XXX this isn't the right place to do this: adding the Python
385 # library to the link, if needed, should be in the "build_ext"
386 # command. (It's also needed for non-MS compilers on Windows, and
387 # it's taken care of for them by the 'build_ext.get_libraries()'
388 # method.)
389 g['LDSHARED'] = ("%s -L%s/lib -lpython%s" %
390 (linkerscript, PREFIX, sys.version[0:3]))
Fred Drakeb94b8492001-12-06 20:51:35 +0000391
Greg Ward879f0f12000-09-15 01:15:08 +0000392 global _config_vars
393 _config_vars = g
Greg Ward66e966f2000-09-01 01:23:26 +0000394
Greg Ward9ddaaa11999-01-06 14:46:06 +0000395
Greg Ward4d74d731999-06-08 01:58:36 +0000396def _init_nt():
397 """Initialize the module as appropriate for NT"""
Greg Ward879f0f12000-09-15 01:15:08 +0000398 g = {}
Greg Ward4d74d731999-06-08 01:58:36 +0000399 # set basic install directories
Fred Drakec1ee39a2000-03-09 15:54:52 +0000400 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
401 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
Greg Ward4d74d731999-06-08 01:58:36 +0000402
Greg Ward32162e81999-08-29 18:22:13 +0000403 # XXX hmmm.. a normal install puts include files here
Fred Drakec1ee39a2000-03-09 15:54:52 +0000404 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
Greg Ward32162e81999-08-29 18:22:13 +0000405
Fred Drake69e2c6e2000-02-08 15:55:42 +0000406 g['SO'] = '.pyd'
Greg Ward82d71ca2000-06-03 00:44:30 +0000407 g['EXE'] = ".exe"
Greg Ward879f0f12000-09-15 01:15:08 +0000408
409 global _config_vars
410 _config_vars = g
Greg Ward82d71ca2000-06-03 00:44:30 +0000411
Fred Drake69e2c6e2000-02-08 15:55:42 +0000412
Greg Ward0eff87a2000-03-07 03:30:09 +0000413def _init_mac():
414 """Initialize the module as appropriate for Macintosh systems"""
Greg Ward879f0f12000-09-15 01:15:08 +0000415 g = {}
Greg Ward0eff87a2000-03-07 03:30:09 +0000416 # set basic install directories
Fred Drakec1ee39a2000-03-09 15:54:52 +0000417 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
418 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
Greg Ward0eff87a2000-03-07 03:30:09 +0000419
420 # XXX hmmm.. a normal install puts include files here
Fred Drakec1ee39a2000-03-09 15:54:52 +0000421 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
Greg Ward0eff87a2000-03-07 03:30:09 +0000422
Jack Jansendd13a202001-05-17 12:52:01 +0000423 import MacOS
424 if not hasattr(MacOS, 'runtimemodel'):
Guido van Rossum99f9baa2001-05-17 15:03:14 +0000425 g['SO'] = '.ppc.slb'
Jack Jansendd13a202001-05-17 12:52:01 +0000426 else:
427 g['SO'] = '.%s.slb' % MacOS.runtimemodel
Greg Ward7d73b9e2000-03-09 03:16:05 +0000428
429 # XXX are these used anywhere?
Greg Wardcf6bea32000-04-10 01:15:06 +0000430 g['install_lib'] = os.path.join(EXEC_PREFIX, "Lib")
431 g['install_platlib'] = os.path.join(EXEC_PREFIX, "Mac", "Lib")
Greg Ward0eff87a2000-03-07 03:30:09 +0000432
Jack Jansenab5320b2002-06-26 15:42:49 +0000433 # These are used by the extension module build
434 g['srcdir'] = ':'
Greg Ward879f0f12000-09-15 01:15:08 +0000435 global _config_vars
436 _config_vars = g
Greg Ward9ddaaa11999-01-06 14:46:06 +0000437
Fred Drake69e2c6e2000-02-08 15:55:42 +0000438
Marc-André Lemburg2544f512002-01-31 18:56:00 +0000439def _init_os2():
440 """Initialize the module as appropriate for OS/2"""
441 g = {}
442 # set basic install directories
443 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
444 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
445
446 # XXX hmmm.. a normal install puts include files here
447 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
448
449 g['SO'] = '.pyd'
450 g['EXE'] = ".exe"
451
452 global _config_vars
453 _config_vars = g
454
455
Greg Ward879f0f12000-09-15 01:15:08 +0000456def get_config_vars(*args):
457 """With no arguments, return a dictionary of all configuration
458 variables relevant for the current platform. Generally this includes
459 everything needed to build extensions and install both pure modules and
460 extensions. On Unix, this means every variable defined in Python's
461 installed Makefile; on Windows and Mac OS it's a much smaller set.
462
463 With arguments, return a list of values that result from looking up
464 each argument in the configuration variable dictionary.
465 """
466 global _config_vars
467 if _config_vars is None:
Greg Ward879f0f12000-09-15 01:15:08 +0000468 func = globals().get("_init_" + os.name)
469 if func:
470 func()
471 else:
472 _config_vars = {}
473
474 # Normalized versions of prefix and exec_prefix are handy to have;
475 # in fact, these are the standard versions used most places in the
476 # Distutils.
477 _config_vars['prefix'] = PREFIX
478 _config_vars['exec_prefix'] = EXEC_PREFIX
479
480 if args:
481 vals = []
482 for name in args:
483 vals.append(_config_vars.get(name))
484 return vals
485 else:
486 return _config_vars
487
488def get_config_var(name):
489 """Return the value of a single variable using the dictionary
490 returned by 'get_config_vars()'. Equivalent to
Fred Drakec916cdc2001-08-02 20:03:12 +0000491 get_config_vars().get(name)
Greg Ward879f0f12000-09-15 01:15:08 +0000492 """
493 return get_config_vars().get(name)