blob: 222648aa74a6e95bbb78f68c4c336efffa46eef5 [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
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
Greg Wardd38e6f72000-04-10 01:17:49 +000037def get_python_inc(plat_specific=0, prefix=None):
Greg Ward7d73b9e2000-03-09 03:16:05 +000038 """Return the directory containing installed Python header files.
Fred Drakec1ee39a2000-03-09 15:54:52 +000039
40 If 'plat_specific' is false (the default), this is the path to the
41 non-platform-specific header files, i.e. Python.h and so on;
42 otherwise, this is the path to platform-specific header files
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +000043 (namely pyconfig.h).
Fred Drakec1ee39a2000-03-09 15:54:52 +000044
Greg Wardd38e6f72000-04-10 01:17:49 +000045 If 'prefix' is supplied, use it instead of sys.prefix or
46 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakeb94b8492001-12-06 20:51:35 +000047 """
Greg Wardd38e6f72000-04-10 01:17:49 +000048 if prefix is None:
Fred Drake70b014d2001-07-18 18:39:56 +000049 prefix = plat_specific and EXEC_PREFIX or PREFIX
Greg Ward7d73b9e2000-03-09 03:16:05 +000050 if os.name == "posix":
Andrew M. Kuchlingc14fa302001-01-17 15:16:52 +000051 if python_build:
Fred Drake16c8d702002-06-04 15:28:21 +000052 base = os.path.dirname(os.path.abspath(sys.executable))
53 if plat_specific:
54 inc_dir = base
55 else:
56 inc_dir = os.path.join(base, "Include")
57 if not os.path.exists(inc_dir):
58 inc_dir = os.path.join(os.path.dirname(base), "Include")
59 return inc_dir
Greg Wardcf6bea32000-04-10 01:15:06 +000060 return os.path.join(prefix, "include", "python" + sys.version[:3])
Greg Ward7d73b9e2000-03-09 03:16:05 +000061 elif os.name == "nt":
Fred Drakec916cdc2001-08-02 20:03:12 +000062 return os.path.join(prefix, "include")
Greg Ward7d73b9e2000-03-09 03:16:05 +000063 elif os.name == "mac":
Neal Norwitz80a3e0a2002-06-26 22:05:33 +000064 if plat_specific:
65 return os.path.join(prefix, "Mac", "Include")
66 else:
67 return os.path.join(prefix, "Include")
Marc-André Lemburg2544f512002-01-31 18:56:00 +000068 elif os.name == "os2":
69 return os.path.join(prefix, "Include")
Greg Ward7d73b9e2000-03-09 03:16:05 +000070 else:
Fred Drake70b014d2001-07-18 18:39:56 +000071 raise DistutilsPlatformError(
72 "I don't know where Python installs its C header files "
73 "on platform '%s'" % os.name)
Greg Ward7d73b9e2000-03-09 03:16:05 +000074
75
Greg Wardd38e6f72000-04-10 01:17:49 +000076def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
Greg Ward7d73b9e2000-03-09 03:16:05 +000077 """Return the directory containing the Python library (standard or
Fred Drakec1ee39a2000-03-09 15:54:52 +000078 site additions).
Greg Ward7d73b9e2000-03-09 03:16:05 +000079
Fred Drakec1ee39a2000-03-09 15:54:52 +000080 If 'plat_specific' is true, return the directory containing
81 platform-specific modules, i.e. any module from a non-pure-Python
82 module distribution; otherwise, return the platform-shared library
83 directory. If 'standard_lib' is true, return the directory
84 containing standard Python library modules; otherwise, return the
85 directory for site-specific modules.
86
Greg Wardd38e6f72000-04-10 01:17:49 +000087 If 'prefix' is supplied, use it instead of sys.prefix or
88 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakec1ee39a2000-03-09 15:54:52 +000089 """
Greg Wardd38e6f72000-04-10 01:17:49 +000090 if prefix is None:
Fred Drake70b014d2001-07-18 18:39:56 +000091 prefix = plat_specific and EXEC_PREFIX or PREFIX
Fred Drakec916cdc2001-08-02 20:03:12 +000092
Greg Ward7d73b9e2000-03-09 03:16:05 +000093 if os.name == "posix":
Greg Wardcf6bea32000-04-10 01:15:06 +000094 libpython = os.path.join(prefix,
Fred Drakec1ee39a2000-03-09 15:54:52 +000095 "lib", "python" + sys.version[:3])
Greg Ward7d73b9e2000-03-09 03:16:05 +000096 if standard_lib:
97 return libpython
98 else:
Fred Drakec1ee39a2000-03-09 15:54:52 +000099 return os.path.join(libpython, "site-packages")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000100
101 elif os.name == "nt":
102 if standard_lib:
Fred Drakec916cdc2001-08-02 20:03:12 +0000103 return os.path.join(prefix, "Lib")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000104 else:
Greg Wardf17efb92001-08-23 20:53:27 +0000105 if sys.version < "2.2":
106 return prefix
107 else:
108 return os.path.join(PREFIX, "Lib", "site-packages")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000109
110 elif os.name == "mac":
Greg Warddc9fe8a2000-08-02 01:49:40 +0000111 if plat_specific:
Greg Ward7d73b9e2000-03-09 03:16:05 +0000112 if standard_lib:
Jack Jansen212a2e12001-09-04 12:01:49 +0000113 return os.path.join(prefix, "Lib", "lib-dynload")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000114 else:
Jack Jansen212a2e12001-09-04 12:01:49 +0000115 return os.path.join(prefix, "Lib", "site-packages")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000116 else:
117 if standard_lib:
Fred Drakec916cdc2001-08-02 20:03:12 +0000118 return os.path.join(prefix, "Lib")
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")
Marc-André Lemburg2544f512002-01-31 18:56:00 +0000121
122 elif os.name == "os2":
123 if standard_lib:
124 return os.path.join(PREFIX, "Lib")
125 else:
126 return os.path.join(PREFIX, "Lib", "site-packages")
127
Greg Ward7d73b9e2000-03-09 03:16:05 +0000128 else:
Fred Drake70b014d2001-07-18 18:39:56 +0000129 raise DistutilsPlatformError(
130 "I don't know where Python installs its library "
131 "on platform '%s'" % os.name)
Greg Ward7d73b9e2000-03-09 03:16:05 +0000132
Greg Ward7d73b9e2000-03-09 03:16:05 +0000133
Fred Drake70b014d2001-07-18 18:39:56 +0000134def customize_compiler(compiler):
Fred Drakec916cdc2001-08-02 20:03:12 +0000135 """Do any platform-specific customization of a CCompiler instance.
136
137 Mainly needed on Unix, so we can plug in the information that
138 varies across Unices and is stored in Python's Makefile.
Greg Wardbb7baa72000-06-25 02:09:14 +0000139 """
140 if compiler.compiler_type == "unix":
Gustavo Niemeyer6b016852002-11-05 16:12:02 +0000141 (cc, cxx, opt, ccshared, ldshared, so_ext) = \
142 get_config_vars('CC', 'CXX', 'OPT', 'CCSHARED', 'LDSHARED', 'SO')
Greg Wardbb7baa72000-06-25 02:09:14 +0000143
Andrew M. Kuchling29c86232002-11-04 19:53:24 +0000144 if os.environ.has_key('CC'):
145 cc = os.environ['CC']
Gustavo Niemeyer6b016852002-11-05 16:12:02 +0000146 if os.environ.has_key('CXX'):
147 cxx = os.environ['CXX']
Andrew M. Kuchling29c86232002-11-04 19:53:24 +0000148 if os.environ.has_key('CPP'):
149 cpp = os.environ['CPP']
150 else:
151 cpp = cc + " -E" # not always
152 if os.environ.has_key('LDFLAGS'):
153 ldshared = ldshared + ' ' + os.environ['LDFLAGS']
154 if os.environ.has_key('CFLAGS'):
155 opt = opt + ' ' + os.environ['CFLAGS']
156 ldshared = ldshared + ' ' + os.environ['CFLAGS']
157 if os.environ.has_key('CPPFLAGS'):
158 cpp = cpp + ' ' + os.environ['CPPFLAGS']
159 opt = opt + ' ' + os.environ['CPPFLAGS']
160 ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
161
Greg Ward879f0f12000-09-15 01:15:08 +0000162 cc_cmd = cc + ' ' + opt
163 compiler.set_executables(
Andrew M. Kuchling29c86232002-11-04 19:53:24 +0000164 preprocessor=cpp,
Greg Ward879f0f12000-09-15 01:15:08 +0000165 compiler=cc_cmd,
166 compiler_so=cc_cmd + ' ' + ccshared,
Gustavo Niemeyer6b016852002-11-05 16:12:02 +0000167 compiler_cxx=cxx,
Greg Ward879f0f12000-09-15 01:15:08 +0000168 linker_so=ldshared,
169 linker_exe=cc)
170
171 compiler.shared_lib_extension = so_ext
Greg Wardbb7baa72000-06-25 02:09:14 +0000172
173
Greg Ward9ddaaa11999-01-06 14:46:06 +0000174def get_config_h_filename():
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000175 """Return full pathname of installed pyconfig.h file."""
Fred Drakec916cdc2001-08-02 20:03:12 +0000176 if python_build:
177 inc_dir = os.curdir
178 else:
179 inc_dir = get_python_inc(plat_specific=1)
Marc-André Lemburg7cf92fa2001-07-26 18:06:58 +0000180 if sys.version < '2.2':
181 config_h = 'config.h'
182 else:
183 # The name of the config.h file changed in 2.2
184 config_h = 'pyconfig.h'
185 return os.path.join(inc_dir, config_h)
Greg Ward7d73b9e2000-03-09 03:16:05 +0000186
Greg Ward1190ee31998-12-18 23:46:33 +0000187
Greg Ward9ddaaa11999-01-06 14:46:06 +0000188def get_makefile_filename():
Fred Drake522af3a1999-01-06 16:28:34 +0000189 """Return full pathname of installed Makefile from the Python build."""
Andrew M. Kuchlingc14fa302001-01-17 15:16:52 +0000190 if python_build:
Fred Drake16c8d702002-06-04 15:28:21 +0000191 return os.path.join(os.path.dirname(sys.executable), "Makefile")
Fred Drakec1ee39a2000-03-09 15:54:52 +0000192 lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
193 return os.path.join(lib_dir, "config", "Makefile")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000194
Greg Ward1190ee31998-12-18 23:46:33 +0000195
Greg Ward9ddaaa11999-01-06 14:46:06 +0000196def parse_config_h(fp, g=None):
Fred Drakec1ee39a2000-03-09 15:54:52 +0000197 """Parse a config.h-style file.
198
199 A dictionary containing name/value pairs is returned. If an
200 optional dictionary is passed in as the second argument, it is
201 used instead of a new dictionary.
Fred Drake522af3a1999-01-06 16:28:34 +0000202 """
Greg Ward9ddaaa11999-01-06 14:46:06 +0000203 if g is None:
204 g = {}
Greg Ward1190ee31998-12-18 23:46:33 +0000205 define_rx = re.compile("#define ([A-Z][A-Z0-9_]+) (.*)\n")
206 undef_rx = re.compile("/[*] #undef ([A-Z][A-Z0-9_]+) [*]/\n")
Greg Ward9ddaaa11999-01-06 14:46:06 +0000207 #
Greg Ward1190ee31998-12-18 23:46:33 +0000208 while 1:
209 line = fp.readline()
210 if not line:
211 break
212 m = define_rx.match(line)
213 if m:
214 n, v = m.group(1, 2)
Jeremy Hyltona5f4c072002-11-05 20:11:08 +0000215 try: v = int(v)
Greg Ward3c8e54b1998-12-22 12:42:04 +0000216 except ValueError: pass
217 g[n] = v
Greg Ward1190ee31998-12-18 23:46:33 +0000218 else:
219 m = undef_rx.match(line)
220 if m:
221 g[m.group(1)] = 0
Greg Ward9ddaaa11999-01-06 14:46:06 +0000222 return g
Greg Ward1190ee31998-12-18 23:46:33 +0000223
Greg Wardd283ce72000-09-17 00:53:02 +0000224
225# Regexes needed for parsing Makefile (and similar syntaxes,
226# like old-style Setup files).
227_variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
228_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
229_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
230
Greg Ward3fff8d22000-09-15 00:03:13 +0000231def parse_makefile(fn, g=None):
Fred Drakec1ee39a2000-03-09 15:54:52 +0000232 """Parse a Makefile-style file.
233
234 A dictionary containing name/value pairs is returned. If an
235 optional dictionary is passed in as the second argument, it is
236 used instead of a new dictionary.
Fred Drake522af3a1999-01-06 16:28:34 +0000237 """
Greg Ward3fff8d22000-09-15 00:03:13 +0000238 from distutils.text_file import TextFile
Greg Wardd283ce72000-09-17 00:53:02 +0000239 fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1)
Greg Ward3fff8d22000-09-15 00:03:13 +0000240
Greg Ward9ddaaa11999-01-06 14:46:06 +0000241 if g is None:
242 g = {}
Greg Ward1190ee31998-12-18 23:46:33 +0000243 done = {}
244 notdone = {}
Greg Ward3fff8d22000-09-15 00:03:13 +0000245
Greg Ward1190ee31998-12-18 23:46:33 +0000246 while 1:
247 line = fp.readline()
Greg Wardd283ce72000-09-17 00:53:02 +0000248 if line is None: # eof
Greg Ward1190ee31998-12-18 23:46:33 +0000249 break
Greg Wardd283ce72000-09-17 00:53:02 +0000250 m = _variable_rx.match(line)
Greg Ward1190ee31998-12-18 23:46:33 +0000251 if m:
252 n, v = m.group(1, 2)
Jeremy Hyltona5f4c072002-11-05 20:11:08 +0000253 v = v.strip()
Greg Ward1190ee31998-12-18 23:46:33 +0000254 if "$" in v:
255 notdone[n] = v
256 else:
Jeremy Hyltona5f4c072002-11-05 20:11:08 +0000257 try: v = int(v)
Greg Ward3c8e54b1998-12-22 12:42:04 +0000258 except ValueError: pass
Greg Ward1190ee31998-12-18 23:46:33 +0000259 done[n] = v
260
261 # do variable interpolation here
Greg Ward1190ee31998-12-18 23:46:33 +0000262 while notdone:
263 for name in notdone.keys():
264 value = notdone[name]
Greg Wardd283ce72000-09-17 00:53:02 +0000265 m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
Greg Ward1190ee31998-12-18 23:46:33 +0000266 if m:
267 n = m.group(1)
268 if done.has_key(n):
269 after = value[m.end():]
Andrew M. Kuchlingb11bd032001-01-16 16:33:28 +0000270 value = value[:m.start()] + str(done[n]) + after
Greg Ward1190ee31998-12-18 23:46:33 +0000271 if "$" in after:
272 notdone[name] = value
273 else:
Jeremy Hyltona5f4c072002-11-05 20:11:08 +0000274 try: value = int(value)
Andrew M. Kuchlingb11bd032001-01-16 16:33:28 +0000275 except ValueError:
Jeremy Hyltona5f4c072002-11-05 20:11:08 +0000276 done[name] = value.strip()
Andrew M. Kuchlingb11bd032001-01-16 16:33:28 +0000277 else:
278 done[name] = value
Greg Ward1190ee31998-12-18 23:46:33 +0000279 del notdone[name]
280 elif notdone.has_key(n):
281 # get it on a subsequent round
282 pass
283 else:
284 done[n] = ""
285 after = value[m.end():]
286 value = value[:m.start()] + after
287 if "$" in after:
288 notdone[name] = value
289 else:
Jeremy Hyltona5f4c072002-11-05 20:11:08 +0000290 try: value = int(value)
Andrew M. Kuchlingb11bd032001-01-16 16:33:28 +0000291 except ValueError:
Jeremy Hyltona5f4c072002-11-05 20:11:08 +0000292 done[name] = value.strip()
Andrew M. Kuchlingb11bd032001-01-16 16:33:28 +0000293 else:
294 done[name] = value
Greg Ward1190ee31998-12-18 23:46:33 +0000295 del notdone[name]
296 else:
Greg Ward3c8e54b1998-12-22 12:42:04 +0000297 # bogus variable reference; just drop it since we can't deal
Greg Ward1190ee31998-12-18 23:46:33 +0000298 del notdone[name]
299
Greg Wardd283ce72000-09-17 00:53:02 +0000300 fp.close()
301
Greg Ward1190ee31998-12-18 23:46:33 +0000302 # save the results in the global dictionary
303 g.update(done)
Greg Ward9ddaaa11999-01-06 14:46:06 +0000304 return g
Greg Ward1190ee31998-12-18 23:46:33 +0000305
306
Greg Wardd283ce72000-09-17 00:53:02 +0000307def expand_makefile_vars(s, vars):
308 """Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
309 'string' according to 'vars' (a dictionary mapping variable names to
310 values). Variables not present in 'vars' are silently expanded to the
311 empty string. The variable values in 'vars' should not contain further
312 variable expansions; if 'vars' is the output of 'parse_makefile()',
313 you're fine. Returns a variable-expanded version of 's'.
314 """
315
316 # This algorithm does multiple expansion, so if vars['foo'] contains
317 # "${bar}", it will expand ${foo} to ${bar}, and then expand
318 # ${bar}... and so forth. This is fine as long as 'vars' comes from
319 # 'parse_makefile()', which takes care of such expansions eagerly,
320 # according to make's variable expansion semantics.
321
322 while 1:
323 m = _findvar1_rx.search(s) or _findvar2_rx.search(s)
324 if m:
Greg Wardd283ce72000-09-17 00:53:02 +0000325 (beg, end) = m.span()
326 s = s[0:beg] + vars.get(m.group(1)) + s[end:]
327 else:
328 break
329 return s
330
331
Greg Ward879f0f12000-09-15 01:15:08 +0000332_config_vars = None
333
Greg Ward9ddaaa11999-01-06 14:46:06 +0000334def _init_posix():
Fred Drake522af3a1999-01-06 16:28:34 +0000335 """Initialize the module as appropriate for POSIX systems."""
Greg Ward879f0f12000-09-15 01:15:08 +0000336 g = {}
Greg Warda0ca3f22000-02-02 00:05:14 +0000337 # load the installed Makefile:
Greg Warda570c052000-05-23 23:14:00 +0000338 try:
339 filename = get_makefile_filename()
Greg Ward3fff8d22000-09-15 00:03:13 +0000340 parse_makefile(filename, g)
Greg Warda570c052000-05-23 23:14:00 +0000341 except IOError, msg:
342 my_msg = "invalid Python installation: unable to open %s" % filename
343 if hasattr(msg, "strerror"):
344 my_msg = my_msg + " (%s)" % msg.strerror
345
Fred Drake70b014d2001-07-18 18:39:56 +0000346 raise DistutilsPlatformError(my_msg)
Fred Drakec916cdc2001-08-02 20:03:12 +0000347
348
Greg Ward4f880282000-06-27 01:59:06 +0000349 # On AIX, there are wrong paths to the linker scripts in the Makefile
350 # -- these paths are relative to the Python source, but when installed
351 # the scripts are in another directory.
Neil Schemenauer1a020862001-02-16 03:31:13 +0000352 if python_build:
Andrew M. Kuchling63357732001-02-28 19:40:27 +0000353 g['LDSHARED'] = g['BLDSHARED']
Fred Drakeb94b8492001-12-06 20:51:35 +0000354
Andrew M. Kuchling045af6f2001-09-05 12:02:59 +0000355 elif sys.version < '2.1':
356 # The following two branches are for 1.5.2 compatibility.
357 if sys.platform == 'aix4': # what about AIX 3.x ?
358 # Linker script is in the config directory, not in Modules as the
359 # Makefile says.
360 python_lib = get_python_lib(standard_lib=1)
361 ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
362 python_exp = os.path.join(python_lib, 'config', 'python.exp')
Greg Ward879f0f12000-09-15 01:15:08 +0000363
Andrew M. Kuchling045af6f2001-09-05 12:02:59 +0000364 g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp)
365
366 elif sys.platform == 'beos':
367 # Linker script is in the config directory. In the Makefile it is
368 # relative to the srcdir, which after installation no longer makes
369 # sense.
370 python_lib = get_python_lib(standard_lib=1)
Jeremy Hyltona5f4c072002-11-05 20:11:08 +0000371 linkerscript_name = os.path.basename(g['LDSHARED'].split()[0])
372 linkerscript = os.path.join(python_lib, 'config',
373 linkerscript_name)
Fred Drakeb94b8492001-12-06 20:51:35 +0000374
Andrew M. Kuchling045af6f2001-09-05 12:02:59 +0000375 # XXX this isn't the right place to do this: adding the Python
376 # library to the link, if needed, should be in the "build_ext"
377 # command. (It's also needed for non-MS compilers on Windows, and
378 # it's taken care of for them by the 'build_ext.get_libraries()'
379 # method.)
380 g['LDSHARED'] = ("%s -L%s/lib -lpython%s" %
381 (linkerscript, PREFIX, sys.version[0:3]))
Fred Drakeb94b8492001-12-06 20:51:35 +0000382
Greg Ward879f0f12000-09-15 01:15:08 +0000383 global _config_vars
384 _config_vars = g
Greg Ward66e966f2000-09-01 01:23:26 +0000385
Greg Ward9ddaaa11999-01-06 14:46:06 +0000386
Greg Ward4d74d731999-06-08 01:58:36 +0000387def _init_nt():
388 """Initialize the module as appropriate for NT"""
Greg Ward879f0f12000-09-15 01:15:08 +0000389 g = {}
Greg Ward4d74d731999-06-08 01:58:36 +0000390 # set basic install directories
Fred Drakec1ee39a2000-03-09 15:54:52 +0000391 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
392 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
Greg Ward4d74d731999-06-08 01:58:36 +0000393
Greg Ward32162e81999-08-29 18:22:13 +0000394 # XXX hmmm.. a normal install puts include files here
Fred Drakec1ee39a2000-03-09 15:54:52 +0000395 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
Greg Ward32162e81999-08-29 18:22:13 +0000396
Fred Drake69e2c6e2000-02-08 15:55:42 +0000397 g['SO'] = '.pyd'
Greg Ward82d71ca2000-06-03 00:44:30 +0000398 g['EXE'] = ".exe"
Greg Ward879f0f12000-09-15 01:15:08 +0000399
400 global _config_vars
401 _config_vars = g
Greg Ward82d71ca2000-06-03 00:44:30 +0000402
Fred Drake69e2c6e2000-02-08 15:55:42 +0000403
Greg Ward0eff87a2000-03-07 03:30:09 +0000404def _init_mac():
405 """Initialize the module as appropriate for Macintosh systems"""
Greg Ward879f0f12000-09-15 01:15:08 +0000406 g = {}
Greg Ward0eff87a2000-03-07 03:30:09 +0000407 # set basic install directories
Fred Drakec1ee39a2000-03-09 15:54:52 +0000408 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
409 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
Greg Ward0eff87a2000-03-07 03:30:09 +0000410
411 # XXX hmmm.. a normal install puts include files here
Fred Drakec1ee39a2000-03-09 15:54:52 +0000412 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
Greg Ward0eff87a2000-03-07 03:30:09 +0000413
Jack Jansendd13a202001-05-17 12:52:01 +0000414 import MacOS
415 if not hasattr(MacOS, 'runtimemodel'):
Guido van Rossum99f9baa2001-05-17 15:03:14 +0000416 g['SO'] = '.ppc.slb'
Jack Jansendd13a202001-05-17 12:52:01 +0000417 else:
418 g['SO'] = '.%s.slb' % MacOS.runtimemodel
Greg Ward7d73b9e2000-03-09 03:16:05 +0000419
420 # XXX are these used anywhere?
Greg Wardcf6bea32000-04-10 01:15:06 +0000421 g['install_lib'] = os.path.join(EXEC_PREFIX, "Lib")
422 g['install_platlib'] = os.path.join(EXEC_PREFIX, "Mac", "Lib")
Greg Ward0eff87a2000-03-07 03:30:09 +0000423
Jack Jansenab5320b2002-06-26 15:42:49 +0000424 # These are used by the extension module build
425 g['srcdir'] = ':'
Greg Ward879f0f12000-09-15 01:15:08 +0000426 global _config_vars
427 _config_vars = g
Greg Ward9ddaaa11999-01-06 14:46:06 +0000428
Fred Drake69e2c6e2000-02-08 15:55:42 +0000429
Marc-André Lemburg2544f512002-01-31 18:56:00 +0000430def _init_os2():
431 """Initialize the module as appropriate for OS/2"""
432 g = {}
433 # set basic install directories
434 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
435 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
436
437 # XXX hmmm.. a normal install puts include files here
438 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
439
440 g['SO'] = '.pyd'
441 g['EXE'] = ".exe"
442
443 global _config_vars
444 _config_vars = g
445
446
Greg Ward879f0f12000-09-15 01:15:08 +0000447def get_config_vars(*args):
448 """With no arguments, return a dictionary of all configuration
449 variables relevant for the current platform. Generally this includes
450 everything needed to build extensions and install both pure modules and
451 extensions. On Unix, this means every variable defined in Python's
452 installed Makefile; on Windows and Mac OS it's a much smaller set.
453
454 With arguments, return a list of values that result from looking up
455 each argument in the configuration variable dictionary.
456 """
457 global _config_vars
458 if _config_vars is None:
Greg Ward879f0f12000-09-15 01:15:08 +0000459 func = globals().get("_init_" + os.name)
460 if func:
461 func()
462 else:
463 _config_vars = {}
464
465 # Normalized versions of prefix and exec_prefix are handy to have;
466 # in fact, these are the standard versions used most places in the
467 # Distutils.
468 _config_vars['prefix'] = PREFIX
469 _config_vars['exec_prefix'] = EXEC_PREFIX
470
471 if args:
472 vals = []
473 for name in args:
474 vals.append(_config_vars.get(name))
475 return vals
476 else:
477 return _config_vars
478
479def get_config_var(name):
480 """Return the value of a single variable using the dictionary
481 returned by 'get_config_vars()'. Equivalent to
Fred Drakec916cdc2001-08-02 20:03:12 +0000482 get_config_vars().get(name)
Greg Ward879f0f12000-09-15 01:15:08 +0000483 """
484 return get_config_vars().get(name)