blob: 3d369b00ded3a0ad7dff27425b8d60e78048e4d7 [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
Andrew M. Kuchling33635aa2002-11-13 17:03:05 +000017import string
Greg Ward9ddaaa11999-01-06 14:46:06 +000018import 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")
Michael W. Hudson6b7d69d2002-07-12 09:16:44 +000032
33python_build = os.path.isfile(landmark)
34
Fred Drake16c8d702002-06-04 15:28:21 +000035del argv0_path, landmark
Fred Drakec1ee39a2000-03-09 15:54:52 +000036
Fred Drakec916cdc2001-08-02 20:03:12 +000037
Greg Wardd38e6f72000-04-10 01:17:49 +000038def get_python_inc(plat_specific=0, prefix=None):
Greg Ward7d73b9e2000-03-09 03:16:05 +000039 """Return the directory containing installed Python header files.
Fred Drakec1ee39a2000-03-09 15:54:52 +000040
41 If 'plat_specific' is false (the default), this is the path to the
42 non-platform-specific header files, i.e. Python.h and so on;
43 otherwise, this is the path to platform-specific header files
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +000044 (namely pyconfig.h).
Fred Drakec1ee39a2000-03-09 15:54:52 +000045
Greg Wardd38e6f72000-04-10 01:17:49 +000046 If 'prefix' is supplied, use it instead of sys.prefix or
47 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakeb94b8492001-12-06 20:51:35 +000048 """
Greg Wardd38e6f72000-04-10 01:17:49 +000049 if prefix is None:
Fred Drake70b014d2001-07-18 18:39:56 +000050 prefix = plat_specific and EXEC_PREFIX or PREFIX
Greg Ward7d73b9e2000-03-09 03:16:05 +000051 if os.name == "posix":
Andrew M. Kuchlingc14fa302001-01-17 15:16:52 +000052 if python_build:
Fred Drake16c8d702002-06-04 15:28:21 +000053 base = os.path.dirname(os.path.abspath(sys.executable))
54 if plat_specific:
55 inc_dir = base
56 else:
57 inc_dir = os.path.join(base, "Include")
58 if not os.path.exists(inc_dir):
59 inc_dir = os.path.join(os.path.dirname(base), "Include")
60 return inc_dir
Greg Wardcf6bea32000-04-10 01:15:06 +000061 return os.path.join(prefix, "include", "python" + sys.version[:3])
Greg Ward7d73b9e2000-03-09 03:16:05 +000062 elif os.name == "nt":
Fred Drakec916cdc2001-08-02 20:03:12 +000063 return os.path.join(prefix, "include")
Greg Ward7d73b9e2000-03-09 03:16:05 +000064 elif os.name == "mac":
Neal Norwitz80a3e0a2002-06-26 22:05:33 +000065 if plat_specific:
66 return os.path.join(prefix, "Mac", "Include")
67 else:
68 return os.path.join(prefix, "Include")
Marc-André Lemburg2544f512002-01-31 18:56:00 +000069 elif os.name == "os2":
70 return os.path.join(prefix, "Include")
Greg Ward7d73b9e2000-03-09 03:16:05 +000071 else:
Fred Drake70b014d2001-07-18 18:39:56 +000072 raise DistutilsPlatformError(
73 "I don't know where Python installs its C header files "
74 "on platform '%s'" % os.name)
Greg Ward7d73b9e2000-03-09 03:16:05 +000075
76
Greg Wardd38e6f72000-04-10 01:17:49 +000077def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
Greg Ward7d73b9e2000-03-09 03:16:05 +000078 """Return the directory containing the Python library (standard or
Fred Drakec1ee39a2000-03-09 15:54:52 +000079 site additions).
Greg Ward7d73b9e2000-03-09 03:16:05 +000080
Fred Drakec1ee39a2000-03-09 15:54:52 +000081 If 'plat_specific' is true, return the directory containing
82 platform-specific modules, i.e. any module from a non-pure-Python
83 module distribution; otherwise, return the platform-shared library
84 directory. If 'standard_lib' is true, return the directory
85 containing standard Python library modules; otherwise, return the
86 directory for site-specific modules.
87
Greg Wardd38e6f72000-04-10 01:17:49 +000088 If 'prefix' is supplied, use it instead of sys.prefix or
89 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakec1ee39a2000-03-09 15:54:52 +000090 """
Greg Wardd38e6f72000-04-10 01:17:49 +000091 if prefix is None:
Fred Drake70b014d2001-07-18 18:39:56 +000092 prefix = plat_specific and EXEC_PREFIX or PREFIX
Fred Drakec916cdc2001-08-02 20:03:12 +000093
Greg Ward7d73b9e2000-03-09 03:16:05 +000094 if os.name == "posix":
Greg Wardcf6bea32000-04-10 01:15:06 +000095 libpython = os.path.join(prefix,
Fred Drakec1ee39a2000-03-09 15:54:52 +000096 "lib", "python" + sys.version[:3])
Greg Ward7d73b9e2000-03-09 03:16:05 +000097 if standard_lib:
98 return libpython
99 else:
Fred Drakec1ee39a2000-03-09 15:54:52 +0000100 return os.path.join(libpython, "site-packages")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000101
102 elif os.name == "nt":
103 if standard_lib:
Fred Drakec916cdc2001-08-02 20:03:12 +0000104 return os.path.join(prefix, "Lib")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000105 else:
Greg Wardf17efb92001-08-23 20:53:27 +0000106 if sys.version < "2.2":
107 return prefix
108 else:
109 return os.path.join(PREFIX, "Lib", "site-packages")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000110
111 elif os.name == "mac":
Greg Warddc9fe8a2000-08-02 01:49:40 +0000112 if plat_specific:
Greg Ward7d73b9e2000-03-09 03:16:05 +0000113 if standard_lib:
Jack Jansen212a2e12001-09-04 12:01:49 +0000114 return os.path.join(prefix, "Lib", "lib-dynload")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000115 else:
Jack Jansen212a2e12001-09-04 12:01:49 +0000116 return os.path.join(prefix, "Lib", "site-packages")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000117 else:
118 if standard_lib:
Fred Drakec916cdc2001-08-02 20:03:12 +0000119 return os.path.join(prefix, "Lib")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000120 else:
Jack Jansen212a2e12001-09-04 12:01:49 +0000121 return os.path.join(prefix, "Lib", "site-packages")
Marc-André Lemburg2544f512002-01-31 18:56:00 +0000122
123 elif os.name == "os2":
124 if standard_lib:
125 return os.path.join(PREFIX, "Lib")
126 else:
127 return os.path.join(PREFIX, "Lib", "site-packages")
128
Greg Ward7d73b9e2000-03-09 03:16:05 +0000129 else:
Fred Drake70b014d2001-07-18 18:39:56 +0000130 raise DistutilsPlatformError(
131 "I don't know where Python installs its library "
132 "on platform '%s'" % os.name)
Greg Ward7d73b9e2000-03-09 03:16:05 +0000133
Greg Ward7d73b9e2000-03-09 03:16:05 +0000134
Fred Drake70b014d2001-07-18 18:39:56 +0000135def customize_compiler(compiler):
Fred Drakec916cdc2001-08-02 20:03:12 +0000136 """Do any platform-specific customization of a CCompiler instance.
137
138 Mainly needed on Unix, so we can plug in the information that
139 varies across Unices and is stored in Python's Makefile.
Greg Wardbb7baa72000-06-25 02:09:14 +0000140 """
141 if compiler.compiler_type == "unix":
Gustavo Niemeyer6b016852002-11-05 16:12:02 +0000142 (cc, cxx, opt, ccshared, ldshared, so_ext) = \
143 get_config_vars('CC', 'CXX', 'OPT', 'CCSHARED', 'LDSHARED', 'SO')
Greg Wardbb7baa72000-06-25 02:09:14 +0000144
Andrew M. Kuchling29c86232002-11-04 19:53:24 +0000145 if os.environ.has_key('CC'):
146 cc = os.environ['CC']
Gustavo Niemeyer6b016852002-11-05 16:12:02 +0000147 if os.environ.has_key('CXX'):
148 cxx = os.environ['CXX']
Andrew M. Kuchling29c86232002-11-04 19:53:24 +0000149 if os.environ.has_key('CPP'):
150 cpp = os.environ['CPP']
151 else:
152 cpp = cc + " -E" # not always
153 if os.environ.has_key('LDFLAGS'):
154 ldshared = ldshared + ' ' + os.environ['LDFLAGS']
155 if os.environ.has_key('CFLAGS'):
156 opt = opt + ' ' + os.environ['CFLAGS']
157 ldshared = ldshared + ' ' + os.environ['CFLAGS']
158 if os.environ.has_key('CPPFLAGS'):
159 cpp = cpp + ' ' + os.environ['CPPFLAGS']
160 opt = opt + ' ' + os.environ['CPPFLAGS']
161 ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
162
Greg Ward879f0f12000-09-15 01:15:08 +0000163 cc_cmd = cc + ' ' + opt
164 compiler.set_executables(
Andrew M. Kuchling29c86232002-11-04 19:53:24 +0000165 preprocessor=cpp,
Greg Ward879f0f12000-09-15 01:15:08 +0000166 compiler=cc_cmd,
167 compiler_so=cc_cmd + ' ' + ccshared,
Gustavo Niemeyer6b016852002-11-05 16:12:02 +0000168 compiler_cxx=cxx,
Greg Ward879f0f12000-09-15 01:15:08 +0000169 linker_so=ldshared,
170 linker_exe=cc)
171
172 compiler.shared_lib_extension = so_ext
Greg Wardbb7baa72000-06-25 02:09:14 +0000173
174
Greg Ward9ddaaa11999-01-06 14:46:06 +0000175def get_config_h_filename():
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000176 """Return full pathname of installed pyconfig.h file."""
Fred Drakec916cdc2001-08-02 20:03:12 +0000177 if python_build:
178 inc_dir = os.curdir
179 else:
180 inc_dir = get_python_inc(plat_specific=1)
Marc-André Lemburg7cf92fa2001-07-26 18:06:58 +0000181 if sys.version < '2.2':
182 config_h = 'config.h'
183 else:
184 # The name of the config.h file changed in 2.2
185 config_h = 'pyconfig.h'
186 return os.path.join(inc_dir, config_h)
Greg Ward7d73b9e2000-03-09 03:16:05 +0000187
Greg Ward1190ee31998-12-18 23:46:33 +0000188
Greg Ward9ddaaa11999-01-06 14:46:06 +0000189def get_makefile_filename():
Fred Drake522af3a1999-01-06 16:28:34 +0000190 """Return full pathname of installed Makefile from the Python build."""
Andrew M. Kuchlingc14fa302001-01-17 15:16:52 +0000191 if python_build:
Fred Drake16c8d702002-06-04 15:28:21 +0000192 return os.path.join(os.path.dirname(sys.executable), "Makefile")
Fred Drakec1ee39a2000-03-09 15:54:52 +0000193 lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
194 return os.path.join(lib_dir, "config", "Makefile")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000195
Greg Ward1190ee31998-12-18 23:46:33 +0000196
Greg Ward9ddaaa11999-01-06 14:46:06 +0000197def parse_config_h(fp, g=None):
Fred Drakec1ee39a2000-03-09 15:54:52 +0000198 """Parse a config.h-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 Ward9ddaaa11999-01-06 14:46:06 +0000204 if g is None:
205 g = {}
Greg Ward1190ee31998-12-18 23:46:33 +0000206 define_rx = re.compile("#define ([A-Z][A-Z0-9_]+) (.*)\n")
207 undef_rx = re.compile("/[*] #undef ([A-Z][A-Z0-9_]+) [*]/\n")
Greg Ward9ddaaa11999-01-06 14:46:06 +0000208 #
Greg Ward1190ee31998-12-18 23:46:33 +0000209 while 1:
210 line = fp.readline()
211 if not line:
212 break
213 m = define_rx.match(line)
214 if m:
215 n, v = m.group(1, 2)
Jeremy Hyltona5f4c072002-11-05 20:11:08 +0000216 try: v = int(v)
Greg Ward3c8e54b1998-12-22 12:42:04 +0000217 except ValueError: pass
218 g[n] = v
Greg Ward1190ee31998-12-18 23:46:33 +0000219 else:
220 m = undef_rx.match(line)
221 if m:
222 g[m.group(1)] = 0
Greg Ward9ddaaa11999-01-06 14:46:06 +0000223 return g
Greg Ward1190ee31998-12-18 23:46:33 +0000224
Greg Wardd283ce72000-09-17 00:53:02 +0000225
226# Regexes needed for parsing Makefile (and similar syntaxes,
227# like old-style Setup files).
228_variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
229_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
230_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
231
Greg Ward3fff8d22000-09-15 00:03:13 +0000232def parse_makefile(fn, g=None):
Fred Drakec1ee39a2000-03-09 15:54:52 +0000233 """Parse a Makefile-style file.
234
235 A dictionary containing name/value pairs is returned. If an
236 optional dictionary is passed in as the second argument, it is
237 used instead of a new dictionary.
Fred Drake522af3a1999-01-06 16:28:34 +0000238 """
Greg Ward3fff8d22000-09-15 00:03:13 +0000239 from distutils.text_file import TextFile
Greg Wardd283ce72000-09-17 00:53:02 +0000240 fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1)
Greg Ward3fff8d22000-09-15 00:03:13 +0000241
Greg Ward9ddaaa11999-01-06 14:46:06 +0000242 if g is None:
243 g = {}
Greg Ward1190ee31998-12-18 23:46:33 +0000244 done = {}
245 notdone = {}
Greg Ward3fff8d22000-09-15 00:03:13 +0000246
Greg Ward1190ee31998-12-18 23:46:33 +0000247 while 1:
248 line = fp.readline()
Greg Wardd283ce72000-09-17 00:53:02 +0000249 if line is None: # eof
Greg Ward1190ee31998-12-18 23:46:33 +0000250 break
Greg Wardd283ce72000-09-17 00:53:02 +0000251 m = _variable_rx.match(line)
Greg Ward1190ee31998-12-18 23:46:33 +0000252 if m:
253 n, v = m.group(1, 2)
Andrew M. Kuchling33635aa2002-11-13 17:03:05 +0000254 v = string.strip(v)
Greg Ward1190ee31998-12-18 23:46:33 +0000255 if "$" in v:
256 notdone[n] = v
257 else:
Jeremy Hyltona5f4c072002-11-05 20:11:08 +0000258 try: v = int(v)
Greg Ward3c8e54b1998-12-22 12:42:04 +0000259 except ValueError: pass
Greg Ward1190ee31998-12-18 23:46:33 +0000260 done[n] = v
261
262 # do variable interpolation here
Greg Ward1190ee31998-12-18 23:46:33 +0000263 while notdone:
264 for name in notdone.keys():
265 value = notdone[name]
Greg Wardd283ce72000-09-17 00:53:02 +0000266 m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
Greg Ward1190ee31998-12-18 23:46:33 +0000267 if m:
268 n = m.group(1)
269 if done.has_key(n):
270 after = value[m.end():]
Andrew M. Kuchlingb11bd032001-01-16 16:33:28 +0000271 value = value[:m.start()] + str(done[n]) + after
Greg Ward1190ee31998-12-18 23:46:33 +0000272 if "$" in after:
273 notdone[name] = value
274 else:
Jeremy Hyltona5f4c072002-11-05 20:11:08 +0000275 try: value = int(value)
Andrew M. Kuchlingb11bd032001-01-16 16:33:28 +0000276 except ValueError:
Andrew M. Kuchling33635aa2002-11-13 17:03:05 +0000277 done[name] = string.strip(value)
Andrew M. Kuchlingb11bd032001-01-16 16:33:28 +0000278 else:
279 done[name] = value
Greg Ward1190ee31998-12-18 23:46:33 +0000280 del notdone[name]
281 elif notdone.has_key(n):
282 # get it on a subsequent round
283 pass
284 else:
285 done[n] = ""
286 after = value[m.end():]
287 value = value[:m.start()] + after
288 if "$" in after:
289 notdone[name] = value
290 else:
Jeremy Hyltona5f4c072002-11-05 20:11:08 +0000291 try: value = int(value)
Andrew M. Kuchlingb11bd032001-01-16 16:33:28 +0000292 except ValueError:
Andrew M. Kuchling33635aa2002-11-13 17:03:05 +0000293 done[name] = string.strip(value)
Andrew M. Kuchlingb11bd032001-01-16 16:33:28 +0000294 else:
295 done[name] = value
Greg Ward1190ee31998-12-18 23:46:33 +0000296 del notdone[name]
297 else:
Greg Ward3c8e54b1998-12-22 12:42:04 +0000298 # bogus variable reference; just drop it since we can't deal
Greg Ward1190ee31998-12-18 23:46:33 +0000299 del notdone[name]
300
Greg Wardd283ce72000-09-17 00:53:02 +0000301 fp.close()
302
Greg Ward1190ee31998-12-18 23:46:33 +0000303 # save the results in the global dictionary
304 g.update(done)
Greg Ward9ddaaa11999-01-06 14:46:06 +0000305 return g
Greg Ward1190ee31998-12-18 23:46:33 +0000306
307
Greg Wardd283ce72000-09-17 00:53:02 +0000308def expand_makefile_vars(s, vars):
309 """Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
310 'string' according to 'vars' (a dictionary mapping variable names to
311 values). Variables not present in 'vars' are silently expanded to the
312 empty string. The variable values in 'vars' should not contain further
313 variable expansions; if 'vars' is the output of 'parse_makefile()',
314 you're fine. Returns a variable-expanded version of 's'.
315 """
316
317 # This algorithm does multiple expansion, so if vars['foo'] contains
318 # "${bar}", it will expand ${foo} to ${bar}, and then expand
319 # ${bar}... and so forth. This is fine as long as 'vars' comes from
320 # 'parse_makefile()', which takes care of such expansions eagerly,
321 # according to make's variable expansion semantics.
322
323 while 1:
324 m = _findvar1_rx.search(s) or _findvar2_rx.search(s)
325 if m:
Greg Wardd283ce72000-09-17 00:53:02 +0000326 (beg, end) = m.span()
327 s = s[0:beg] + vars.get(m.group(1)) + s[end:]
328 else:
329 break
330 return s
331
332
Greg Ward879f0f12000-09-15 01:15:08 +0000333_config_vars = None
334
Greg Ward9ddaaa11999-01-06 14:46:06 +0000335def _init_posix():
Fred Drake522af3a1999-01-06 16:28:34 +0000336 """Initialize the module as appropriate for POSIX systems."""
Greg Ward879f0f12000-09-15 01:15:08 +0000337 g = {}
Greg Warda0ca3f22000-02-02 00:05:14 +0000338 # load the installed Makefile:
Greg Warda570c052000-05-23 23:14:00 +0000339 try:
340 filename = get_makefile_filename()
Greg Ward3fff8d22000-09-15 00:03:13 +0000341 parse_makefile(filename, g)
Greg Warda570c052000-05-23 23:14:00 +0000342 except IOError, msg:
343 my_msg = "invalid Python installation: unable to open %s" % filename
344 if hasattr(msg, "strerror"):
345 my_msg = my_msg + " (%s)" % msg.strerror
346
Fred Drake70b014d2001-07-18 18:39:56 +0000347 raise DistutilsPlatformError(my_msg)
Fred Drakec916cdc2001-08-02 20:03:12 +0000348
349
Greg Ward4f880282000-06-27 01:59:06 +0000350 # On AIX, there are wrong paths to the linker scripts in the Makefile
351 # -- these paths are relative to the Python source, but when installed
352 # the scripts are in another directory.
Neil Schemenauer1a020862001-02-16 03:31:13 +0000353 if python_build:
Andrew M. Kuchling63357732001-02-28 19:40:27 +0000354 g['LDSHARED'] = g['BLDSHARED']
Fred Drakeb94b8492001-12-06 20:51:35 +0000355
Andrew M. Kuchling045af6f2001-09-05 12:02:59 +0000356 elif sys.version < '2.1':
357 # The following two branches are for 1.5.2 compatibility.
358 if sys.platform == 'aix4': # what about AIX 3.x ?
359 # Linker script is in the config directory, not in Modules as the
360 # Makefile says.
361 python_lib = get_python_lib(standard_lib=1)
362 ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
363 python_exp = os.path.join(python_lib, 'config', 'python.exp')
Greg Ward879f0f12000-09-15 01:15:08 +0000364
Andrew M. Kuchling045af6f2001-09-05 12:02:59 +0000365 g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp)
366
367 elif sys.platform == 'beos':
368 # Linker script is in the config directory. In the Makefile it is
369 # relative to the srcdir, which after installation no longer makes
370 # sense.
371 python_lib = get_python_lib(standard_lib=1)
Andrew M. Kuchling33635aa2002-11-13 17:03:05 +0000372 linkerscript_path = string.split(g['LDSHARED'])[0]
373 linkerscript_name = os.path.basename(linkerscript_path)
Jeremy Hyltona5f4c072002-11-05 20:11:08 +0000374 linkerscript = os.path.join(python_lib, 'config',
375 linkerscript_name)
Fred Drakeb94b8492001-12-06 20:51:35 +0000376
Andrew M. Kuchling045af6f2001-09-05 12:02:59 +0000377 # XXX this isn't the right place to do this: adding the Python
378 # library to the link, if needed, should be in the "build_ext"
379 # command. (It's also needed for non-MS compilers on Windows, and
380 # it's taken care of for them by the 'build_ext.get_libraries()'
381 # method.)
382 g['LDSHARED'] = ("%s -L%s/lib -lpython%s" %
383 (linkerscript, PREFIX, sys.version[0:3]))
Fred Drakeb94b8492001-12-06 20:51:35 +0000384
Greg Ward879f0f12000-09-15 01:15:08 +0000385 global _config_vars
386 _config_vars = g
Greg Ward66e966f2000-09-01 01:23:26 +0000387
Greg Ward9ddaaa11999-01-06 14:46:06 +0000388
Greg Ward4d74d731999-06-08 01:58:36 +0000389def _init_nt():
390 """Initialize the module as appropriate for NT"""
Greg Ward879f0f12000-09-15 01:15:08 +0000391 g = {}
Greg Ward4d74d731999-06-08 01:58:36 +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 Ward4d74d731999-06-08 01:58:36 +0000395
Greg Ward32162e81999-08-29 18:22:13 +0000396 # 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 Ward32162e81999-08-29 18:22:13 +0000398
Fred Drake69e2c6e2000-02-08 15:55:42 +0000399 g['SO'] = '.pyd'
Greg Ward82d71ca2000-06-03 00:44:30 +0000400 g['EXE'] = ".exe"
Greg Ward879f0f12000-09-15 01:15:08 +0000401
402 global _config_vars
403 _config_vars = g
Greg Ward82d71ca2000-06-03 00:44:30 +0000404
Fred Drake69e2c6e2000-02-08 15:55:42 +0000405
Greg Ward0eff87a2000-03-07 03:30:09 +0000406def _init_mac():
407 """Initialize the module as appropriate for Macintosh systems"""
Greg Ward879f0f12000-09-15 01:15:08 +0000408 g = {}
Greg Ward0eff87a2000-03-07 03:30:09 +0000409 # set basic install directories
Fred Drakec1ee39a2000-03-09 15:54:52 +0000410 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
411 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
Greg Ward0eff87a2000-03-07 03:30:09 +0000412
413 # XXX hmmm.. a normal install puts include files here
Fred Drakec1ee39a2000-03-09 15:54:52 +0000414 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
Greg Ward0eff87a2000-03-07 03:30:09 +0000415
Jack Jansendd13a202001-05-17 12:52:01 +0000416 import MacOS
417 if not hasattr(MacOS, 'runtimemodel'):
Guido van Rossum99f9baa2001-05-17 15:03:14 +0000418 g['SO'] = '.ppc.slb'
Jack Jansendd13a202001-05-17 12:52:01 +0000419 else:
420 g['SO'] = '.%s.slb' % MacOS.runtimemodel
Greg Ward7d73b9e2000-03-09 03:16:05 +0000421
422 # XXX are these used anywhere?
Greg Wardcf6bea32000-04-10 01:15:06 +0000423 g['install_lib'] = os.path.join(EXEC_PREFIX, "Lib")
424 g['install_platlib'] = os.path.join(EXEC_PREFIX, "Mac", "Lib")
Greg Ward0eff87a2000-03-07 03:30:09 +0000425
Jack Jansenab5320b2002-06-26 15:42:49 +0000426 # These are used by the extension module build
427 g['srcdir'] = ':'
Greg Ward879f0f12000-09-15 01:15:08 +0000428 global _config_vars
429 _config_vars = g
Greg Ward9ddaaa11999-01-06 14:46:06 +0000430
Fred Drake69e2c6e2000-02-08 15:55:42 +0000431
Marc-André Lemburg2544f512002-01-31 18:56:00 +0000432def _init_os2():
433 """Initialize the module as appropriate for OS/2"""
434 g = {}
435 # set basic install directories
436 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
437 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
438
439 # XXX hmmm.. a normal install puts include files here
440 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
441
442 g['SO'] = '.pyd'
443 g['EXE'] = ".exe"
444
445 global _config_vars
446 _config_vars = g
447
448
Greg Ward879f0f12000-09-15 01:15:08 +0000449def get_config_vars(*args):
450 """With no arguments, return a dictionary of all configuration
451 variables relevant for the current platform. Generally this includes
452 everything needed to build extensions and install both pure modules and
453 extensions. On Unix, this means every variable defined in Python's
454 installed Makefile; on Windows and Mac OS it's a much smaller set.
455
456 With arguments, return a list of values that result from looking up
457 each argument in the configuration variable dictionary.
458 """
459 global _config_vars
460 if _config_vars is None:
Greg Ward879f0f12000-09-15 01:15:08 +0000461 func = globals().get("_init_" + os.name)
462 if func:
463 func()
464 else:
465 _config_vars = {}
466
467 # Normalized versions of prefix and exec_prefix are handy to have;
468 # in fact, these are the standard versions used most places in the
469 # Distutils.
470 _config_vars['prefix'] = PREFIX
471 _config_vars['exec_prefix'] = EXEC_PREFIX
472
473 if args:
474 vals = []
475 for name in args:
476 vals.append(_config_vars.get(name))
477 return vals
478 else:
479 return _config_vars
480
481def get_config_var(name):
482 """Return the value of a single variable using the dictionary
483 returned by 'get_config_vars()'. Equivalent to
Fred Drakec916cdc2001-08-02 20:03:12 +0000484 get_config_vars().get(name)
Greg Ward879f0f12000-09-15 01:15:08 +0000485 """
486 return get_config_vars().get(name)