1999-01-06 16:28:34 +00:00
|
|
|
"""Provide access to Python's configuration information. The specific names
|
|
|
|
defined in the module depend heavily on the platform and configuration.
|
1998-12-18 23:46:33 +00:00
|
|
|
|
|
|
|
Written by: Fred L. Drake, Jr.
|
|
|
|
Email: <fdrake@acm.org>
|
|
|
|
Initial date: 17-Dec-1998
|
|
|
|
"""
|
|
|
|
|
2000-06-03 00:44:30 +00:00
|
|
|
__revision__ = "$Id$"
|
1998-12-18 23:46:33 +00:00
|
|
|
|
1999-01-06 14:46:06 +00:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import string
|
|
|
|
import sys
|
1998-12-18 23:46:33 +00:00
|
|
|
|
2000-03-09 15:54:52 +00:00
|
|
|
from errors import DistutilsPlatformError
|
2000-02-02 00:05:14 +00:00
|
|
|
|
1998-12-18 23:46:33 +00:00
|
|
|
|
2000-04-10 01:15:06 +00:00
|
|
|
PREFIX = os.path.normpath(sys.prefix)
|
|
|
|
EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
|
2000-03-09 15:54:52 +00:00
|
|
|
|
|
|
|
|
2000-04-10 01:17:49 +00:00
|
|
|
def get_python_inc(plat_specific=0, prefix=None):
|
2000-03-09 03:16:05 +00:00
|
|
|
"""Return the directory containing installed Python header files.
|
2000-03-09 15:54:52 +00:00
|
|
|
|
|
|
|
If 'plat_specific' is false (the default), this is the path to the
|
|
|
|
non-platform-specific header files, i.e. Python.h and so on;
|
|
|
|
otherwise, this is the path to platform-specific header files
|
|
|
|
(namely config.h).
|
|
|
|
|
2000-04-10 01:17:49 +00:00
|
|
|
If 'prefix' is supplied, use it instead of sys.prefix or
|
|
|
|
sys.exec_prefix -- i.e., ignore 'plat_specific'.
|
2000-03-09 15:54:52 +00:00
|
|
|
"""
|
2000-04-10 01:17:49 +00:00
|
|
|
if prefix is None:
|
|
|
|
prefix = (plat_specific and EXEC_PREFIX or PREFIX)
|
2000-03-09 03:16:05 +00:00
|
|
|
if os.name == "posix":
|
2000-04-10 01:15:06 +00:00
|
|
|
return os.path.join(prefix, "include", "python" + sys.version[:3])
|
2000-03-09 03:16:05 +00:00
|
|
|
elif os.name == "nt":
|
2000-04-10 01:15:06 +00:00
|
|
|
return os.path.join(prefix, "Include") # include or Include?
|
2000-03-09 03:16:05 +00:00
|
|
|
elif os.name == "mac":
|
2000-04-10 01:15:06 +00:00
|
|
|
return os.path.join(prefix, "Include")
|
2000-03-09 03:16:05 +00:00
|
|
|
else:
|
|
|
|
raise DistutilsPlatformError, \
|
|
|
|
("I don't know where Python installs its C header files " +
|
|
|
|
"on platform '%s'") % os.name
|
|
|
|
|
|
|
|
|
2000-04-10 01:17:49 +00:00
|
|
|
def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
|
2000-03-09 03:16:05 +00:00
|
|
|
"""Return the directory containing the Python library (standard or
|
2000-03-09 15:54:52 +00:00
|
|
|
site additions).
|
|
|
|
|
|
|
|
If 'plat_specific' is true, return the directory containing
|
|
|
|
platform-specific modules, i.e. any module from a non-pure-Python
|
|
|
|
module distribution; otherwise, return the platform-shared library
|
|
|
|
directory. If 'standard_lib' is true, return the directory
|
|
|
|
containing standard Python library modules; otherwise, return the
|
|
|
|
directory for site-specific modules.
|
2000-03-09 03:16:05 +00:00
|
|
|
|
2000-04-10 01:17:49 +00:00
|
|
|
If 'prefix' is supplied, use it instead of sys.prefix or
|
|
|
|
sys.exec_prefix -- i.e., ignore 'plat_specific'.
|
2000-03-09 15:54:52 +00:00
|
|
|
"""
|
2000-04-10 01:17:49 +00:00
|
|
|
if prefix is None:
|
|
|
|
prefix = (plat_specific and EXEC_PREFIX or PREFIX)
|
2000-03-09 03:16:05 +00:00
|
|
|
|
|
|
|
if os.name == "posix":
|
2000-04-10 01:15:06 +00:00
|
|
|
libpython = os.path.join(prefix,
|
2000-03-09 15:54:52 +00:00
|
|
|
"lib", "python" + sys.version[:3])
|
2000-03-09 03:16:05 +00:00
|
|
|
if standard_lib:
|
|
|
|
return libpython
|
|
|
|
else:
|
2000-03-09 15:54:52 +00:00
|
|
|
return os.path.join(libpython, "site-packages")
|
2000-03-09 03:16:05 +00:00
|
|
|
|
|
|
|
elif os.name == "nt":
|
|
|
|
if standard_lib:
|
2000-04-10 01:15:06 +00:00
|
|
|
return os.path.join(PREFIX, "Lib")
|
2000-03-09 03:16:05 +00:00
|
|
|
else:
|
2000-04-10 01:15:06 +00:00
|
|
|
return prefix
|
2000-03-09 03:16:05 +00:00
|
|
|
|
|
|
|
elif os.name == "mac":
|
2000-08-02 01:49:40 +00:00
|
|
|
if plat_specific:
|
2000-03-09 03:16:05 +00:00
|
|
|
if standard_lib:
|
2000-04-10 01:15:06 +00:00
|
|
|
return os.path.join(EXEC_PREFIX, "Mac", "Plugins")
|
2000-03-09 03:16:05 +00:00
|
|
|
else:
|
|
|
|
raise DistutilsPlatformError, \
|
|
|
|
"OK, where DO site-specific extensions go on the Mac?"
|
|
|
|
else:
|
|
|
|
if standard_lib:
|
2000-04-10 01:15:06 +00:00
|
|
|
return os.path.join(PREFIX, "Lib")
|
2000-03-09 03:16:05 +00:00
|
|
|
else:
|
|
|
|
raise DistutilsPlatformError, \
|
|
|
|
"OK, where DO site-specific modules go on the Mac?"
|
|
|
|
else:
|
|
|
|
raise DistutilsPlatformError, \
|
|
|
|
("I don't know where Python installs its library " +
|
|
|
|
"on platform '%s'") % os.name
|
|
|
|
|
2000-03-09 15:54:52 +00:00
|
|
|
# get_python_lib()
|
2000-03-09 03:16:05 +00:00
|
|
|
|
|
|
|
|
2000-06-25 02:09:14 +00:00
|
|
|
def customize_compiler (compiler):
|
|
|
|
"""Do any platform-specific customization of the CCompiler instance
|
|
|
|
'compiler'. Mainly needed on Unix, so we can plug in the information
|
|
|
|
that varies across Unices and is stored in Python's Makefile.
|
|
|
|
"""
|
|
|
|
if compiler.compiler_type == "unix":
|
|
|
|
cc_cmd = CC + ' ' + OPT
|
|
|
|
compiler.set_executables(
|
|
|
|
preprocessor=CC + " -E", # not always!
|
|
|
|
compiler=cc_cmd,
|
|
|
|
compiler_so=cc_cmd + ' ' + CCSHARED,
|
|
|
|
linker_so=LDSHARED,
|
|
|
|
linker_exe=CC)
|
|
|
|
|
|
|
|
compiler.shared_lib_extension = SO
|
|
|
|
|
|
|
|
|
1999-01-06 14:46:06 +00:00
|
|
|
def get_config_h_filename():
|
1999-01-06 16:28:34 +00:00
|
|
|
"""Return full pathname of installed config.h file."""
|
2000-03-09 15:54:52 +00:00
|
|
|
inc_dir = get_python_inc(plat_specific=1)
|
|
|
|
return os.path.join(inc_dir, "config.h")
|
2000-03-09 03:16:05 +00:00
|
|
|
|
1998-12-18 23:46:33 +00:00
|
|
|
|
1999-01-06 14:46:06 +00:00
|
|
|
def get_makefile_filename():
|
1999-01-06 16:28:34 +00:00
|
|
|
"""Return full pathname of installed Makefile from the Python build."""
|
2000-03-09 15:54:52 +00:00
|
|
|
lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
|
|
|
|
return os.path.join(lib_dir, "config", "Makefile")
|
2000-03-09 03:16:05 +00:00
|
|
|
|
1998-12-18 23:46:33 +00:00
|
|
|
|
1999-01-06 14:46:06 +00:00
|
|
|
def parse_config_h(fp, g=None):
|
2000-03-09 15:54:52 +00:00
|
|
|
"""Parse a config.h-style file.
|
|
|
|
|
|
|
|
A dictionary containing name/value pairs is returned. If an
|
|
|
|
optional dictionary is passed in as the second argument, it is
|
|
|
|
used instead of a new dictionary.
|
1999-01-06 16:28:34 +00:00
|
|
|
"""
|
1999-01-06 14:46:06 +00:00
|
|
|
if g is None:
|
|
|
|
g = {}
|
1998-12-18 23:46:33 +00:00
|
|
|
define_rx = re.compile("#define ([A-Z][A-Z0-9_]+) (.*)\n")
|
|
|
|
undef_rx = re.compile("/[*] #undef ([A-Z][A-Z0-9_]+) [*]/\n")
|
1999-01-06 14:46:06 +00:00
|
|
|
#
|
1998-12-18 23:46:33 +00:00
|
|
|
while 1:
|
|
|
|
line = fp.readline()
|
|
|
|
if not line:
|
|
|
|
break
|
|
|
|
m = define_rx.match(line)
|
|
|
|
if m:
|
|
|
|
n, v = m.group(1, 2)
|
1998-12-22 12:42:04 +00:00
|
|
|
try: v = string.atoi(v)
|
|
|
|
except ValueError: pass
|
|
|
|
g[n] = v
|
1998-12-18 23:46:33 +00:00
|
|
|
else:
|
|
|
|
m = undef_rx.match(line)
|
|
|
|
if m:
|
|
|
|
g[m.group(1)] = 0
|
1999-01-06 14:46:06 +00:00
|
|
|
return g
|
1998-12-18 23:46:33 +00:00
|
|
|
|
1999-01-06 14:46:06 +00:00
|
|
|
def parse_makefile(fp, g=None):
|
2000-03-09 15:54:52 +00:00
|
|
|
"""Parse a Makefile-style file.
|
|
|
|
|
|
|
|
A dictionary containing name/value pairs is returned. If an
|
|
|
|
optional dictionary is passed in as the second argument, it is
|
|
|
|
used instead of a new dictionary.
|
|
|
|
|
1999-01-06 16:28:34 +00:00
|
|
|
"""
|
1999-01-06 14:46:06 +00:00
|
|
|
if g is None:
|
|
|
|
g = {}
|
1998-12-18 23:46:33 +00:00
|
|
|
variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)\n")
|
|
|
|
done = {}
|
|
|
|
notdone = {}
|
1999-01-06 14:46:06 +00:00
|
|
|
#
|
1998-12-18 23:46:33 +00:00
|
|
|
while 1:
|
|
|
|
line = fp.readline()
|
|
|
|
if not line:
|
|
|
|
break
|
|
|
|
m = variable_rx.match(line)
|
|
|
|
if m:
|
|
|
|
n, v = m.group(1, 2)
|
1998-12-22 12:42:04 +00:00
|
|
|
v = string.strip(v)
|
1998-12-18 23:46:33 +00:00
|
|
|
if "$" in v:
|
|
|
|
notdone[n] = v
|
|
|
|
else:
|
1998-12-22 12:42:04 +00:00
|
|
|
try: v = string.atoi(v)
|
|
|
|
except ValueError: pass
|
1998-12-18 23:46:33 +00:00
|
|
|
done[n] = v
|
|
|
|
|
|
|
|
# do variable interpolation here
|
|
|
|
findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
|
|
|
|
findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
|
|
|
|
while notdone:
|
|
|
|
for name in notdone.keys():
|
|
|
|
value = notdone[name]
|
|
|
|
m = findvar1_rx.search(value)
|
|
|
|
if not m:
|
|
|
|
m = findvar2_rx.search(value)
|
|
|
|
if m:
|
|
|
|
n = m.group(1)
|
|
|
|
if done.has_key(n):
|
|
|
|
after = value[m.end():]
|
|
|
|
value = value[:m.start()] + done[n] + after
|
|
|
|
if "$" in after:
|
|
|
|
notdone[name] = value
|
|
|
|
else:
|
1998-12-22 12:42:04 +00:00
|
|
|
try: value = string.atoi(value)
|
|
|
|
except ValueError: pass
|
|
|
|
done[name] = string.strip(value)
|
1998-12-18 23:46:33 +00:00
|
|
|
del notdone[name]
|
|
|
|
elif notdone.has_key(n):
|
|
|
|
# get it on a subsequent round
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
done[n] = ""
|
|
|
|
after = value[m.end():]
|
|
|
|
value = value[:m.start()] + after
|
|
|
|
if "$" in after:
|
|
|
|
notdone[name] = value
|
|
|
|
else:
|
1998-12-22 12:42:04 +00:00
|
|
|
try: value = string.atoi(value)
|
|
|
|
except ValueError: pass
|
|
|
|
done[name] = string.strip(value)
|
1998-12-18 23:46:33 +00:00
|
|
|
del notdone[name]
|
|
|
|
else:
|
1998-12-22 12:42:04 +00:00
|
|
|
# bogus variable reference; just drop it since we can't deal
|
1998-12-18 23:46:33 +00:00
|
|
|
del notdone[name]
|
|
|
|
|
|
|
|
# save the results in the global dictionary
|
|
|
|
g.update(done)
|
1999-01-06 14:46:06 +00:00
|
|
|
return g
|
1998-12-18 23:46:33 +00:00
|
|
|
|
|
|
|
|
1999-01-06 14:46:06 +00:00
|
|
|
def _init_posix():
|
1999-01-06 16:28:34 +00:00
|
|
|
"""Initialize the module as appropriate for POSIX systems."""
|
1999-01-06 14:46:06 +00:00
|
|
|
g = globals()
|
2000-02-02 00:05:14 +00:00
|
|
|
# load the installed Makefile:
|
2000-05-23 23:14:00 +00:00
|
|
|
try:
|
|
|
|
filename = get_makefile_filename()
|
|
|
|
file = open(filename)
|
|
|
|
except IOError, msg:
|
|
|
|
my_msg = "invalid Python installation: unable to open %s" % filename
|
|
|
|
if hasattr(msg, "strerror"):
|
|
|
|
my_msg = my_msg + " (%s)" % msg.strerror
|
|
|
|
|
|
|
|
raise DistutilsPlatformError, my_msg
|
|
|
|
|
|
|
|
parse_makefile(file, g)
|
2000-06-27 01:59:06 +00:00
|
|
|
|
|
|
|
# On AIX, there are wrong paths to the linker scripts in the Makefile
|
|
|
|
# -- these paths are relative to the Python source, but when installed
|
|
|
|
# the scripts are in another directory.
|
2000-06-27 01:59:43 +00:00
|
|
|
if sys.platform == 'aix4': # what about AIX 3.x ?
|
2000-06-27 01:59:06 +00:00
|
|
|
# Linker script is in the config directory, not in Modules as the
|
|
|
|
# Makefile says.
|
|
|
|
python_lib = get_python_lib(standard_lib=1)
|
|
|
|
ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
|
|
|
|
python_exp = os.path.join(python_lib, 'config', 'python.exp')
|
|
|
|
|
|
|
|
g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp)
|
1999-01-06 14:46:06 +00:00
|
|
|
|
2000-09-01 01:23:26 +00:00
|
|
|
if sys.platform == 'beos':
|
|
|
|
|
|
|
|
# Linker script is in the config directory. In the Makefile it is
|
|
|
|
# relative to the srcdir, which after installation no longer makes
|
|
|
|
# sense.
|
|
|
|
python_lib = get_python_lib(standard_lib=1)
|
|
|
|
linkerscript_name = os.path.basename(string.split(g['LDSHARED'])[0])
|
|
|
|
linkerscript = os.path.join(python_lib, 'config', linkerscript_name)
|
|
|
|
|
|
|
|
# XXX this isn't the right place to do this: adding the Python
|
|
|
|
# library to the link, if needed, should be in the "build_ext"
|
|
|
|
# command. (It's also needed for non-MS compilers on Windows, and
|
|
|
|
# it's taken care of for them by the 'build_ext.get_libraries()'
|
|
|
|
# method.)
|
|
|
|
g['LDSHARED'] = ("%s -L%s/lib -lpython%s" %
|
|
|
|
(linkerscript, sys.prefix, sys.version[0:3]))
|
|
|
|
|
1999-01-06 14:46:06 +00:00
|
|
|
|
1999-06-08 01:58:36 +00:00
|
|
|
def _init_nt():
|
|
|
|
"""Initialize the module as appropriate for NT"""
|
2000-02-08 15:55:42 +00:00
|
|
|
g = globals()
|
1999-06-08 01:58:36 +00:00
|
|
|
# set basic install directories
|
2000-03-09 15:54:52 +00:00
|
|
|
g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
|
|
|
|
g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
|
1999-06-08 01:58:36 +00:00
|
|
|
|
1999-08-29 18:22:13 +00:00
|
|
|
# XXX hmmm.. a normal install puts include files here
|
2000-03-09 15:54:52 +00:00
|
|
|
g['INCLUDEPY'] = get_python_inc(plat_specific=0)
|
1999-08-29 18:22:13 +00:00
|
|
|
|
2000-02-08 15:55:42 +00:00
|
|
|
g['SO'] = '.pyd'
|
2000-06-03 00:44:30 +00:00
|
|
|
g['EXE'] = ".exe"
|
2000-08-02 01:09:11 +00:00
|
|
|
g['exec_prefix'] = EXEC_PREFIX
|
2000-06-03 00:44:30 +00:00
|
|
|
|
2000-02-08 15:55:42 +00:00
|
|
|
|
2000-03-07 03:30:09 +00:00
|
|
|
def _init_mac():
|
|
|
|
"""Initialize the module as appropriate for Macintosh systems"""
|
|
|
|
g = globals()
|
|
|
|
# set basic install directories
|
2000-03-09 15:54:52 +00:00
|
|
|
g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
|
|
|
|
g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
|
2000-03-07 03:30:09 +00:00
|
|
|
|
|
|
|
# XXX hmmm.. a normal install puts include files here
|
2000-03-09 15:54:52 +00:00
|
|
|
g['INCLUDEPY'] = get_python_inc(plat_specific=0)
|
2000-03-07 03:30:09 +00:00
|
|
|
|
|
|
|
g['SO'] = '.ppc.slb'
|
2000-04-10 01:15:06 +00:00
|
|
|
g['exec_prefix'] = EXEC_PREFIX
|
|
|
|
print sys.prefix, PREFIX
|
2000-03-09 03:16:05 +00:00
|
|
|
|
|
|
|
# XXX are these used anywhere?
|
2000-04-10 01:15:06 +00:00
|
|
|
g['install_lib'] = os.path.join(EXEC_PREFIX, "Lib")
|
|
|
|
g['install_platlib'] = os.path.join(EXEC_PREFIX, "Mac", "Lib")
|
2000-03-07 03:30:09 +00:00
|
|
|
|
|
|
|
|
1999-01-06 14:46:06 +00:00
|
|
|
try:
|
|
|
|
exec "_init_" + os.name
|
|
|
|
except NameError:
|
|
|
|
# not needed for this platform
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
exec "_init_%s()" % os.name
|
|
|
|
|
2000-02-08 15:55:42 +00:00
|
|
|
|
1998-12-18 23:46:33 +00:00
|
|
|
del _init_posix
|
1999-06-08 01:58:36 +00:00
|
|
|
del _init_nt
|
2000-03-07 03:30:09 +00:00
|
|
|
del _init_mac
|