2001-07-18 18:39:56 +00:00
|
|
|
"""Provide access to Python's configuration information. The specific
|
|
|
|
|
configuration variables available depend heavily on the platform and
|
|
|
|
|
configuration. The values may be retrieved using
|
|
|
|
|
get_config_var(name), and the list of variables is available via
|
|
|
|
|
get_config_vars().keys(). Additional convenience functions are also
|
|
|
|
|
available.
|
1998-12-18 23:46:33 +00:00
|
|
|
|
|
|
|
|
Written by: Fred L. Drake, Jr.
|
|
|
|
|
Email: <fdrake@acm.org>
|
|
|
|
|
"""
|
|
|
|
|
|
2014-11-22 12:54:57 -08:00
|
|
|
import _imp
|
1999-01-06 14:46:06 +00:00
|
|
|
import os
|
|
|
|
|
import re
|
2010-07-22 12:50:05 +00:00
|
|
|
import sys
|
1998-12-18 23:46:33 +00:00
|
|
|
|
2010-07-22 12:50:05 +00:00
|
|
|
from .errors import DistutilsPlatformError
|
2000-02-02 00:05:14 +00:00
|
|
|
|
2010-07-22 12:50:05 +00:00
|
|
|
# These are needed in a couple of spots, so just compute them once.
|
|
|
|
|
PREFIX = os.path.normpath(sys.prefix)
|
|
|
|
|
EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
|
2012-05-26 03:45:29 +01:00
|
|
|
BASE_PREFIX = os.path.normpath(sys.base_prefix)
|
|
|
|
|
BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
|
2000-03-09 15:54:52 +00:00
|
|
|
|
2010-07-22 12:50:05 +00:00
|
|
|
# Path to the base directory of the project. On Windows the binary may
|
2017-09-25 18:58:10 +02:00
|
|
|
# live in project/PCbuild/win32 or project/PCbuild/amd64.
|
2013-01-25 14:33:33 +01:00
|
|
|
# set for cross builds
|
|
|
|
|
if "_PYTHON_PROJECT_BASE" in os.environ:
|
|
|
|
|
project_base = os.path.abspath(os.environ["_PYTHON_PROJECT_BASE"])
|
|
|
|
|
else:
|
|
|
|
|
project_base = os.path.dirname(os.path.abspath(sys.executable))
|
2014-11-22 12:54:57 -08:00
|
|
|
if (os.name == 'nt' and
|
|
|
|
|
project_base.lower().endswith(('\\pcbuild\\win32', '\\pcbuild\\amd64'))):
|
|
|
|
|
project_base = os.path.dirname(os.path.dirname(project_base))
|
Merged revisions 59376-59406 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59377 | georg.brandl | 2007-12-06 01:24:23 +0100 (Thu, 06 Dec 2007) | 2 lines
Add another GHOP student to ACKS.
........
r59378 | raymond.hettinger | 2007-12-06 01:56:53 +0100 (Thu, 06 Dec 2007) | 5 lines
Fix Issue 1045.
Factor-out common calling code by simplifying the length_hint API.
Speed-up the function by caching the PyObject_String for the attribute lookup.
........
r59380 | georg.brandl | 2007-12-06 02:52:24 +0100 (Thu, 06 Dec 2007) | 2 lines
Diverse markup fixes.
........
r59383 | georg.brandl | 2007-12-06 10:45:39 +0100 (Thu, 06 Dec 2007) | 2 lines
Better re.split examples.
........
r59386 | christian.heimes | 2007-12-06 14:15:13 +0100 (Thu, 06 Dec 2007) | 2 lines
Fixed get_config_h_filename for Windows. Without the patch it can't find the pyconfig.h file inside a build tree.
Added several small unit tests for sysconfig.
........
r59387 | christian.heimes | 2007-12-06 14:30:11 +0100 (Thu, 06 Dec 2007) | 1 line
Silence more warnings, _CRT_NONSTDC_NO_DEPRECATE is already defined in pyconfig.h but several projects don't include it.
........
r59389 | christian.heimes | 2007-12-06 14:55:01 +0100 (Thu, 06 Dec 2007) | 1 line
Disabled one test that is failing on Unix
........
r59399 | christian.heimes | 2007-12-06 22:13:06 +0100 (Thu, 06 Dec 2007) | 8 lines
Several Windows related cleanups:
* Removed a #define from pyconfig.h. The macro was already defined a few lines higher.
* Fixed path to tix in the build_tkinter.py script
* Changed make_buildinfo.c to use versions of unlink and strcat which are considered safe by Windows (as suggested by MvL).
* Removed two defines from pyproject.vsprops that are no longer required. Both are defined in pyconfig.h and make_buildinfo.c doesn't use the unsafe versions any more (as suggested by MvL).
* Added some more information about PGO and the property files to PCbuild9/readme.txt.
Are you fine with the changes, Martin?
........
r59400 | raymond.hettinger | 2007-12-07 02:53:01 +0100 (Fri, 07 Dec 2007) | 4 lines
Don't have the docs berate themselves. Keep a professional tone.
If a todo is needed, put it in the tracker.
........
r59402 | georg.brandl | 2007-12-07 10:07:10 +0100 (Fri, 07 Dec 2007) | 3 lines
Increase unit test coverage of SimpleXMLRPCServer.
Written for GHOP by Turkay Eren.
........
r59406 | georg.brandl | 2007-12-07 16:16:57 +0100 (Fri, 07 Dec 2007) | 2 lines
Update to windows doc from Robert.
........
2007-12-08 15:33:56 +00:00
|
|
|
|
2010-07-22 12:50:05 +00:00
|
|
|
# python_build: (Boolean) if true, we're either building Python or
|
|
|
|
|
# building an extension with an un-installed Python, so we use
|
|
|
|
|
# different (hard-wired) directories.
|
|
|
|
|
# Setup.local is available for Makefile builds including VPATH builds,
|
|
|
|
|
# Setup.dist is available on Windows
|
2012-05-26 03:45:29 +01:00
|
|
|
def _is_python_source_dir(d):
|
2010-07-22 12:50:05 +00:00
|
|
|
for fn in ("Setup.dist", "Setup.local"):
|
2012-05-26 03:45:29 +01:00
|
|
|
if os.path.isfile(os.path.join(d, "Modules", fn)):
|
2010-07-22 12:50:05 +00:00
|
|
|
return True
|
|
|
|
|
return False
|
2012-05-26 03:45:29 +01:00
|
|
|
_sys_home = getattr(sys, '_home', None)
|
2014-11-22 12:54:57 -08:00
|
|
|
if (_sys_home and os.name == 'nt' and
|
|
|
|
|
_sys_home.lower().endswith(('\\pcbuild\\win32', '\\pcbuild\\amd64'))):
|
|
|
|
|
_sys_home = os.path.dirname(os.path.dirname(_sys_home))
|
2012-05-26 03:45:29 +01:00
|
|
|
def _python_build():
|
|
|
|
|
if _sys_home:
|
|
|
|
|
return _is_python_source_dir(_sys_home)
|
|
|
|
|
return _is_python_source_dir(project_base)
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60568-60598,60600-60616 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60568 | christian.heimes | 2008-02-04 19:48:38 +0100 (Mon, 04 Feb 2008) | 1 line
Increase debugging to investige failing tests on some build bots
........
r60570 | christian.heimes | 2008-02-04 20:30:05 +0100 (Mon, 04 Feb 2008) | 1 line
Small adjustments for test compact freelist test. It's no passing on Windows as well.
........
r60573 | amaury.forgeotdarc | 2008-02-04 21:53:14 +0100 (Mon, 04 Feb 2008) | 2 lines
Correct quotes in NEWS file
........
r60575 | amaury.forgeotdarc | 2008-02-04 22:45:05 +0100 (Mon, 04 Feb 2008) | 13 lines
#1750076: Debugger did not step on every iteration of a while statement.
The mapping between bytecode offsets and source lines (lnotab) did not contain
an entry for the beginning of the loop.
Now it does, and the lnotab can be a bit larger:
in particular, several statements on the same line generate several entries.
However, this does not bother the settrace function, which will trigger only
one 'line' event.
The lnotab seems to be exactly the same as with python2.4.
........
r60584 | amaury.forgeotdarc | 2008-02-05 01:26:21 +0100 (Tue, 05 Feb 2008) | 3 lines
Change r60575 broke test_compile:
there is no need to emit co_lnotab item when both offsets are zeros.
........
r60587 | skip.montanaro | 2008-02-05 03:32:16 +0100 (Tue, 05 Feb 2008) | 1 line
sync with most recent version from python-mode sf project
........
r60588 | lars.gustaebel | 2008-02-05 12:51:40 +0100 (Tue, 05 Feb 2008) | 5 lines
Issue #2004: Use mode 0700 for temporary directories and default
permissions for missing directories.
(will backport to 2.5)
........
r60590 | georg.brandl | 2008-02-05 13:01:24 +0100 (Tue, 05 Feb 2008) | 2 lines
Convert external links to internal links. Fixes #2010.
........
r60592 | marc-andre.lemburg | 2008-02-05 15:50:40 +0100 (Tue, 05 Feb 2008) | 3 lines
Keep distutils Python 2.1 compatible (or even Python 2.4 in this case).
........
r60593 | andrew.kuchling | 2008-02-05 17:06:57 +0100 (Tue, 05 Feb 2008) | 5 lines
Update PEP URL.
(This code is duplicated between pydoc and DocXMLRPCServer; maybe it
should be refactored as a GHOP project.)
2.5.2 backport candidate.
........
r60596 | guido.van.rossum | 2008-02-05 18:32:15 +0100 (Tue, 05 Feb 2008) | 2 lines
In the experimental 'Scanner' feature, the group count was set wrong.
........
r60602 | facundo.batista | 2008-02-05 20:03:32 +0100 (Tue, 05 Feb 2008) | 3 lines
Issue 1951. Converts wave test cases to unittest.
........
r60603 | georg.brandl | 2008-02-05 20:07:10 +0100 (Tue, 05 Feb 2008) | 2 lines
Actually run the test.
........
r60604 | skip.montanaro | 2008-02-05 20:24:30 +0100 (Tue, 05 Feb 2008) | 2 lines
correct object name
........
r60605 | georg.brandl | 2008-02-05 20:58:17 +0100 (Tue, 05 Feb 2008) | 7 lines
* Use the same code to profile for test_profile and test_cprofile.
* Convert both to unittest.
* Use the same unit testing code.
* Include the expected output in both test files.
* Make it possible to regenerate the expected output by running
the file as a script with an '-r' argument.
........
r60613 | raymond.hettinger | 2008-02-06 02:49:00 +0100 (Wed, 06 Feb 2008) | 1 line
Sync-up with Py3k work.
........
r60614 | christian.heimes | 2008-02-06 13:44:34 +0100 (Wed, 06 Feb 2008) | 1 line
Limit free list of method and builtin function objects to 256 entries each.
........
r60616 | christian.heimes | 2008-02-06 14:33:44 +0100 (Wed, 06 Feb 2008) | 7 lines
Unified naming convention for free lists and their limits. All free lists
in Object/ are named ``free_list``, the counter ``numfree`` and the upper
limit is a macro ``PyName_MAXFREELIST`` inside an #ifndef block.
The chances should make it easier to adjust Python for platforms with
less memory, e.g. mobile phones.
........
2008-02-06 14:31:34 +00:00
|
|
|
python_build = _python_build()
|
2001-08-02 20:03:12 +00:00
|
|
|
|
2010-11-24 19:43:47 +00:00
|
|
|
# Calculate the build qualifier flags if they are defined. Adding the flags
|
|
|
|
|
# to the include and lib directories only makes sense for an installation, not
|
|
|
|
|
# an in-source build.
|
|
|
|
|
build_flags = ''
|
|
|
|
|
try:
|
|
|
|
|
if not python_build:
|
|
|
|
|
build_flags = sys.abiflags
|
|
|
|
|
except AttributeError:
|
|
|
|
|
# It's not a configure-based build, so the sys module doesn't have
|
|
|
|
|
# this attribute, which is fine.
|
|
|
|
|
pass
|
|
|
|
|
|
2010-07-22 12:50:05 +00:00
|
|
|
def get_python_version():
|
|
|
|
|
"""Return a string containing the major and minor Python version,
|
|
|
|
|
leaving off the patchlevel. Sample return values could be '1.5'
|
|
|
|
|
or '2.2'.
|
|
|
|
|
"""
|
2016-02-11 13:10:36 +02:00
|
|
|
return '%d.%d' % sys.version_info[:2]
|
2010-01-29 11:41:03 +00:00
|
|
|
|
2010-07-22 12:50:05 +00:00
|
|
|
|
|
|
|
|
def get_python_inc(plat_specific=0, prefix=None):
|
|
|
|
|
"""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
|
2001-07-26 13:41:06 +00:00
|
|
|
(namely pyconfig.h).
|
2000-03-09 15:54:52 +00:00
|
|
|
|
2012-05-26 03:45:29 +01:00
|
|
|
If 'prefix' is supplied, use it instead of sys.base_prefix or
|
|
|
|
|
sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
|
2001-12-06 20:51:35 +00:00
|
|
|
"""
|
2010-07-22 12:50:05 +00:00
|
|
|
if prefix is None:
|
2012-05-26 03:45:29 +01:00
|
|
|
prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
|
2010-07-22 12:50:05 +00:00
|
|
|
if os.name == "posix":
|
|
|
|
|
if python_build:
|
2010-09-20 10:29:54 +00:00
|
|
|
# Assume the executable is in the build directory. The
|
|
|
|
|
# pyconfig.h file should be in the same directory. Since
|
|
|
|
|
# the build directory may not be the source directory, we
|
|
|
|
|
# must use "srcdir" from the makefile to find the "Include"
|
|
|
|
|
# directory.
|
|
|
|
|
if plat_specific:
|
2017-05-09 09:24:13 -06:00
|
|
|
return _sys_home or project_base
|
2010-09-20 10:29:54 +00:00
|
|
|
else:
|
2012-07-16 18:24:55 +01:00
|
|
|
incdir = os.path.join(get_config_var('srcdir'), 'Include')
|
2017-05-09 09:24:13 -06:00
|
|
|
return os.path.normpath(incdir)
|
2010-11-24 19:43:47 +00:00
|
|
|
python_dir = 'python' + get_python_version() + build_flags
|
|
|
|
|
return os.path.join(prefix, "include", python_dir)
|
2010-07-22 12:50:05 +00:00
|
|
|
elif os.name == "nt":
|
|
|
|
|
return os.path.join(prefix, "include")
|
2000-03-09 03:16:05 +00:00
|
|
|
else:
|
2010-07-22 12:50:05 +00:00
|
|
|
raise DistutilsPlatformError(
|
|
|
|
|
"I don't know where Python installs its C header files "
|
|
|
|
|
"on platform '%s'" % os.name)
|
2000-03-09 03:16:05 +00:00
|
|
|
|
|
|
|
|
|
2010-07-22 12:50:05 +00:00
|
|
|
def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
|
|
|
|
|
"""Return the directory containing the Python library (standard or
|
2000-03-09 15:54:52 +00:00
|
|
|
site additions).
|
2000-03-09 03:16:05 +00:00
|
|
|
|
2000-03-09 15:54:52 +00:00
|
|
|
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.
|
|
|
|
|
|
2012-05-26 03:45:29 +01:00
|
|
|
If 'prefix' is supplied, use it instead of sys.base_prefix or
|
|
|
|
|
sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
|
2000-03-09 15:54:52 +00:00
|
|
|
"""
|
2010-07-22 12:50:05 +00:00
|
|
|
if prefix is None:
|
2012-05-26 03:45:29 +01:00
|
|
|
if standard_lib:
|
|
|
|
|
prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
|
|
|
|
|
else:
|
|
|
|
|
prefix = plat_specific and EXEC_PREFIX or PREFIX
|
2010-07-22 12:50:05 +00:00
|
|
|
|
|
|
|
|
if os.name == "posix":
|
|
|
|
|
libpython = os.path.join(prefix,
|
|
|
|
|
"lib", "python" + get_python_version())
|
|
|
|
|
if standard_lib:
|
|
|
|
|
return libpython
|
2000-03-09 03:16:05 +00:00
|
|
|
else:
|
2010-07-22 12:50:05 +00:00
|
|
|
return os.path.join(libpython, "site-packages")
|
|
|
|
|
elif os.name == "nt":
|
|
|
|
|
if standard_lib:
|
|
|
|
|
return os.path.join(prefix, "Lib")
|
2002-01-31 18:56:00 +00:00
|
|
|
else:
|
2014-09-06 17:24:12 -04:00
|
|
|
return os.path.join(prefix, "Lib", "site-packages")
|
2000-03-09 03:16:05 +00:00
|
|
|
else:
|
2010-07-22 12:50:05 +00:00
|
|
|
raise DistutilsPlatformError(
|
|
|
|
|
"I don't know where Python installs its library "
|
|
|
|
|
"on platform '%s'" % os.name)
|
|
|
|
|
|
2012-06-23 16:02:19 -07:00
|
|
|
|
2010-07-22 12:50:05 +00:00
|
|
|
|
|
|
|
|
def customize_compiler(compiler):
|
|
|
|
|
"""Do any platform-specific customization of a CCompiler instance.
|
|
|
|
|
|
|
|
|
|
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":
|
2012-07-21 05:36:30 -07:00
|
|
|
if sys.platform == "darwin":
|
|
|
|
|
# Perform first-time customization of compiler-related
|
|
|
|
|
# config vars on OS X now that we know we need a compiler.
|
|
|
|
|
# This is primarily to support Pythons from binary
|
|
|
|
|
# installers. The kind and paths to build tools on
|
|
|
|
|
# the user system may vary significantly from the system
|
|
|
|
|
# that Python itself was built on. Also the user OS
|
|
|
|
|
# version and build tools may not support the same set
|
|
|
|
|
# of CPU architectures for universal builds.
|
|
|
|
|
global _config_vars
|
2014-07-06 16:14:33 -07:00
|
|
|
# Use get_config_var() to ensure _config_vars is initialized.
|
|
|
|
|
if not get_config_var('CUSTOMIZED_OSX_COMPILER'):
|
2012-07-21 05:36:30 -07:00
|
|
|
import _osx_support
|
|
|
|
|
_osx_support.customize_compiler(_config_vars)
|
|
|
|
|
_config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'
|
|
|
|
|
|
2013-03-21 13:21:49 -07:00
|
|
|
(cc, cxx, opt, cflags, ccshared, ldshared, shlib_suffix, ar, ar_flags) = \
|
2010-07-22 12:50:05 +00:00
|
|
|
get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
|
2013-03-21 13:21:49 -07:00
|
|
|
'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS')
|
2010-07-22 12:50:05 +00:00
|
|
|
|
|
|
|
|
if 'CC' in os.environ:
|
2013-05-28 16:35:30 -07:00
|
|
|
newcc = os.environ['CC']
|
|
|
|
|
if (sys.platform == 'darwin'
|
|
|
|
|
and 'LDSHARED' not in os.environ
|
|
|
|
|
and ldshared.startswith(cc)):
|
|
|
|
|
# On OS X, if CC is overridden, use that as the default
|
|
|
|
|
# command for LDSHARED as well
|
|
|
|
|
ldshared = newcc + ldshared[len(cc):]
|
|
|
|
|
cc = newcc
|
2010-07-22 12:50:05 +00:00
|
|
|
if 'CXX' in os.environ:
|
|
|
|
|
cxx = os.environ['CXX']
|
|
|
|
|
if 'LDSHARED' in os.environ:
|
|
|
|
|
ldshared = os.environ['LDSHARED']
|
|
|
|
|
if 'CPP' in os.environ:
|
|
|
|
|
cpp = os.environ['CPP']
|
2002-11-04 19:53:24 +00:00
|
|
|
else:
|
2010-07-22 12:50:05 +00:00
|
|
|
cpp = cc + " -E" # not always
|
|
|
|
|
if 'LDFLAGS' in os.environ:
|
|
|
|
|
ldshared = ldshared + ' ' + os.environ['LDFLAGS']
|
|
|
|
|
if 'CFLAGS' in os.environ:
|
|
|
|
|
cflags = opt + ' ' + os.environ['CFLAGS']
|
|
|
|
|
ldshared = ldshared + ' ' + os.environ['CFLAGS']
|
|
|
|
|
if 'CPPFLAGS' in os.environ:
|
|
|
|
|
cpp = cpp + ' ' + os.environ['CPPFLAGS']
|
|
|
|
|
cflags = cflags + ' ' + os.environ['CPPFLAGS']
|
|
|
|
|
ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
|
|
|
|
|
if 'AR' in os.environ:
|
|
|
|
|
ar = os.environ['AR']
|
|
|
|
|
if 'ARFLAGS' in os.environ:
|
|
|
|
|
archiver = ar + ' ' + os.environ['ARFLAGS']
|
|
|
|
|
else:
|
|
|
|
|
archiver = ar + ' ' + ar_flags
|
|
|
|
|
|
|
|
|
|
cc_cmd = cc + ' ' + cflags
|
|
|
|
|
compiler.set_executables(
|
|
|
|
|
preprocessor=cpp,
|
|
|
|
|
compiler=cc_cmd,
|
|
|
|
|
compiler_so=cc_cmd + ' ' + ccshared,
|
|
|
|
|
compiler_cxx=cxx,
|
|
|
|
|
linker_so=ldshared,
|
|
|
|
|
linker_exe=cc,
|
|
|
|
|
archiver=archiver)
|
|
|
|
|
|
2013-03-21 13:21:49 -07:00
|
|
|
compiler.shared_lib_extension = shlib_suffix
|
2010-07-22 12:50:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_config_h_filename():
|
|
|
|
|
"""Return full pathname of installed pyconfig.h file."""
|
|
|
|
|
if python_build:
|
|
|
|
|
if os.name == "nt":
|
2012-05-26 03:45:29 +01:00
|
|
|
inc_dir = os.path.join(_sys_home or project_base, "PC")
|
2010-07-22 12:50:05 +00:00
|
|
|
else:
|
2012-05-26 03:45:29 +01:00
|
|
|
inc_dir = _sys_home or project_base
|
2010-07-22 12:50:05 +00:00
|
|
|
else:
|
|
|
|
|
inc_dir = get_python_inc(plat_specific=1)
|
2014-09-06 17:24:12 -04:00
|
|
|
|
|
|
|
|
return os.path.join(inc_dir, 'pyconfig.h')
|
2010-07-22 12:50:05 +00:00
|
|
|
|
1998-12-18 23:46:33 +00:00
|
|
|
|
1999-01-06 14:46:06 +00:00
|
|
|
def get_makefile_filename():
|
2010-07-22 12:50:05 +00:00
|
|
|
"""Return full pathname of installed Makefile from the Python build."""
|
|
|
|
|
if python_build:
|
2013-01-25 14:33:33 +01:00
|
|
|
return os.path.join(_sys_home or project_base, "Makefile")
|
2011-10-08 01:56:52 +02:00
|
|
|
lib_dir = get_python_lib(plat_specific=0, standard_lib=1)
|
2010-11-24 19:43:47 +00:00
|
|
|
config_file = 'config-{}{}'.format(get_python_version(), build_flags)
|
2016-06-14 08:55:19 +02:00
|
|
|
if hasattr(sys.implementation, '_multiarch'):
|
|
|
|
|
config_file += '-%s' % sys.implementation._multiarch
|
2010-11-24 19:43:47 +00:00
|
|
|
return os.path.join(lib_dir, config_file, 'Makefile')
|
2000-03-09 03:16:05 +00:00
|
|
|
|
2010-07-22 12:50:05 +00:00
|
|
|
|
|
|
|
|
def parse_config_h(fp, g=None):
|
|
|
|
|
"""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
|
|
|
"""
|
2010-07-22 12:50:05 +00:00
|
|
|
if g is None:
|
|
|
|
|
g = {}
|
|
|
|
|
define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
|
|
|
|
|
undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n")
|
|
|
|
|
#
|
|
|
|
|
while True:
|
|
|
|
|
line = fp.readline()
|
|
|
|
|
if not line:
|
|
|
|
|
break
|
|
|
|
|
m = define_rx.match(line)
|
|
|
|
|
if m:
|
|
|
|
|
n, v = m.group(1, 2)
|
|
|
|
|
try: v = int(v)
|
|
|
|
|
except ValueError: pass
|
|
|
|
|
g[n] = v
|
|
|
|
|
else:
|
|
|
|
|
m = undef_rx.match(line)
|
|
|
|
|
if m:
|
|
|
|
|
g[m.group(1)] = 0
|
|
|
|
|
return g
|
1998-12-18 23:46:33 +00:00
|
|
|
|
2000-09-17 00:53:02 +00:00
|
|
|
|
|
|
|
|
# Regexes needed for parsing Makefile (and similar syntaxes,
|
|
|
|
|
# like old-style Setup files).
|
2016-09-08 13:59:53 -04:00
|
|
|
_variable_rx = re.compile(r"([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
|
2000-09-17 00:53:02 +00:00
|
|
|
_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
|
|
|
|
|
_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
|
|
|
|
|
|
2000-09-15 00:03:13 +00:00
|
|
|
def parse_makefile(fn, g=None):
|
2010-07-22 12:50:05 +00:00
|
|
|
"""Parse a Makefile-style file.
|
2000-03-09 15:54:52 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
"""
|
2010-07-22 12:50:05 +00:00
|
|
|
from distutils.text_file import TextFile
|
2010-10-23 17:02:31 +00:00
|
|
|
fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1, errors="surrogateescape")
|
2010-07-22 12:50:05 +00:00
|
|
|
|
|
|
|
|
if g is None:
|
|
|
|
|
g = {}
|
|
|
|
|
done = {}
|
|
|
|
|
notdone = {}
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
line = fp.readline()
|
|
|
|
|
if line is None: # eof
|
|
|
|
|
break
|
|
|
|
|
m = _variable_rx.match(line)
|
|
|
|
|
if m:
|
|
|
|
|
n, v = m.group(1, 2)
|
|
|
|
|
v = v.strip()
|
|
|
|
|
# `$$' is a literal `$' in make
|
|
|
|
|
tmpv = v.replace('$$', '')
|
|
|
|
|
|
|
|
|
|
if "$" in tmpv:
|
|
|
|
|
notdone[n] = v
|
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
v = int(v)
|
|
|
|
|
except ValueError:
|
|
|
|
|
# insert literal `$'
|
|
|
|
|
done[n] = v.replace('$$', '$')
|
|
|
|
|
else:
|
|
|
|
|
done[n] = v
|
|
|
|
|
|
2010-07-23 09:43:17 +00:00
|
|
|
# Variables with a 'PY_' prefix in the makefile. These need to
|
|
|
|
|
# be made available without that prefix through sysconfig.
|
|
|
|
|
# Special care is needed to ensure that variable expansion works, even
|
|
|
|
|
# if the expansion uses the name without a prefix.
|
|
|
|
|
renamed_variables = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS')
|
|
|
|
|
|
2010-07-22 12:50:05 +00:00
|
|
|
# do variable interpolation here
|
|
|
|
|
while notdone:
|
|
|
|
|
for name in list(notdone):
|
|
|
|
|
value = notdone[name]
|
|
|
|
|
m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
|
|
|
|
|
if m:
|
|
|
|
|
n = m.group(1)
|
|
|
|
|
found = True
|
|
|
|
|
if n in done:
|
|
|
|
|
item = str(done[n])
|
|
|
|
|
elif n in notdone:
|
|
|
|
|
# get it on a subsequent round
|
|
|
|
|
found = False
|
|
|
|
|
elif n in os.environ:
|
|
|
|
|
# do it like make: fall back to environment
|
|
|
|
|
item = os.environ[n]
|
2010-07-23 09:43:17 +00:00
|
|
|
|
|
|
|
|
elif n in renamed_variables:
|
|
|
|
|
if name.startswith('PY_') and name[3:] in renamed_variables:
|
|
|
|
|
item = ""
|
|
|
|
|
|
|
|
|
|
elif 'PY_' + n in notdone:
|
|
|
|
|
found = False
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
item = str(done['PY_' + n])
|
2010-07-22 12:50:05 +00:00
|
|
|
else:
|
|
|
|
|
done[n] = item = ""
|
|
|
|
|
if found:
|
|
|
|
|
after = value[m.end():]
|
|
|
|
|
value = value[:m.start()] + item + after
|
|
|
|
|
if "$" in after:
|
|
|
|
|
notdone[name] = value
|
|
|
|
|
else:
|
|
|
|
|
try: value = int(value)
|
|
|
|
|
except ValueError:
|
|
|
|
|
done[name] = value.strip()
|
|
|
|
|
else:
|
|
|
|
|
done[name] = value
|
|
|
|
|
del notdone[name]
|
2010-07-23 09:43:17 +00:00
|
|
|
|
|
|
|
|
if name.startswith('PY_') \
|
|
|
|
|
and name[3:] in renamed_variables:
|
|
|
|
|
|
|
|
|
|
name = name[3:]
|
|
|
|
|
if name not in done:
|
|
|
|
|
done[name] = value
|
2010-07-22 12:50:05 +00:00
|
|
|
else:
|
|
|
|
|
# bogus variable reference; just drop it since we can't deal
|
|
|
|
|
del notdone[name]
|
|
|
|
|
|
|
|
|
|
fp.close()
|
|
|
|
|
|
2010-10-10 09:37:12 +00:00
|
|
|
# strip spurious spaces
|
|
|
|
|
for k, v in done.items():
|
|
|
|
|
if isinstance(v, str):
|
|
|
|
|
done[k] = v.strip()
|
|
|
|
|
|
2010-07-22 12:50:05 +00:00
|
|
|
# save the results in the global dictionary
|
|
|
|
|
g.update(done)
|
|
|
|
|
return g
|
|
|
|
|
|
1998-12-18 23:46:33 +00:00
|
|
|
|
2000-09-17 00:53:02 +00:00
|
|
|
def expand_makefile_vars(s, vars):
|
2010-07-22 12:50:05 +00:00
|
|
|
"""Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
|
2000-09-17 00:53:02 +00:00
|
|
|
'string' according to 'vars' (a dictionary mapping variable names to
|
|
|
|
|
values). Variables not present in 'vars' are silently expanded to the
|
|
|
|
|
empty string. The variable values in 'vars' should not contain further
|
|
|
|
|
variable expansions; if 'vars' is the output of 'parse_makefile()',
|
|
|
|
|
you're fine. Returns a variable-expanded version of 's'.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
# This algorithm does multiple expansion, so if vars['foo'] contains
|
|
|
|
|
# "${bar}", it will expand ${foo} to ${bar}, and then expand
|
|
|
|
|
# ${bar}... and so forth. This is fine as long as 'vars' comes from
|
|
|
|
|
# 'parse_makefile()', which takes care of such expansions eagerly,
|
|
|
|
|
# according to make's variable expansion semantics.
|
|
|
|
|
|
2007-08-30 03:52:21 +00:00
|
|
|
while True:
|
2000-09-17 00:53:02 +00:00
|
|
|
m = _findvar1_rx.search(s) or _findvar2_rx.search(s)
|
|
|
|
|
if m:
|
|
|
|
|
(beg, end) = m.span()
|
|
|
|
|
s = s[0:beg] + vars.get(m.group(1)) + s[end:]
|
|
|
|
|
else:
|
|
|
|
|
break
|
|
|
|
|
return s
|
2010-07-22 12:50:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
_config_vars = None
|
|
|
|
|
|
|
|
|
|
def _init_posix():
|
|
|
|
|
"""Initialize the module as appropriate for POSIX systems."""
|
2016-06-05 01:17:57 +02:00
|
|
|
# _sysconfigdata is generated at build time, see the sysconfig module
|
2016-09-11 22:22:24 +02:00
|
|
|
name = os.environ.get('_PYTHON_SYSCONFIGDATA_NAME',
|
|
|
|
|
'_sysconfigdata_{abi}_{platform}_{multiarch}'.format(
|
2016-09-09 18:29:10 -07:00
|
|
|
abi=sys.abiflags,
|
|
|
|
|
platform=sys.platform,
|
|
|
|
|
multiarch=getattr(sys.implementation, '_multiarch', ''),
|
2016-09-11 22:22:24 +02:00
|
|
|
))
|
2016-06-14 09:22:16 +02:00
|
|
|
_temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
|
|
|
|
|
build_time_vars = _temp.build_time_vars
|
2010-07-22 12:50:05 +00:00
|
|
|
global _config_vars
|
2016-06-05 01:17:57 +02:00
|
|
|
_config_vars = {}
|
|
|
|
|
_config_vars.update(build_time_vars)
|
2010-07-22 12:50:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def _init_nt():
|
|
|
|
|
"""Initialize the module as appropriate for NT"""
|
|
|
|
|
g = {}
|
|
|
|
|
# set basic install directories
|
|
|
|
|
g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
|
|
|
|
|
g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
|
|
|
|
|
|
|
|
|
|
# XXX hmmm.. a normal install puts include files here
|
|
|
|
|
g['INCLUDEPY'] = get_python_inc(plat_specific=0)
|
|
|
|
|
|
2014-11-22 12:54:57 -08:00
|
|
|
g['EXT_SUFFIX'] = _imp.extension_suffixes()[0]
|
2010-07-22 12:50:05 +00:00
|
|
|
g['EXE'] = ".exe"
|
|
|
|
|
g['VERSION'] = get_python_version().replace(".", "")
|
|
|
|
|
g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
|
|
|
|
|
|
|
|
|
|
global _config_vars
|
|
|
|
|
_config_vars = g
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_config_vars(*args):
|
|
|
|
|
"""With no arguments, return a dictionary of all configuration
|
|
|
|
|
variables relevant for the current platform. Generally this includes
|
|
|
|
|
everything needed to build extensions and install both pure modules and
|
|
|
|
|
extensions. On Unix, this means every variable defined in Python's
|
2012-07-21 05:36:30 -07:00
|
|
|
installed Makefile; on Windows it's a much smaller set.
|
2010-07-22 12:50:05 +00:00
|
|
|
|
|
|
|
|
With arguments, return a list of values that result from looking up
|
|
|
|
|
each argument in the configuration variable dictionary.
|
|
|
|
|
"""
|
|
|
|
|
global _config_vars
|
|
|
|
|
if _config_vars is None:
|
|
|
|
|
func = globals().get("_init_" + os.name)
|
|
|
|
|
if func:
|
|
|
|
|
func()
|
|
|
|
|
else:
|
|
|
|
|
_config_vars = {}
|
|
|
|
|
|
|
|
|
|
# Normalized versions of prefix and exec_prefix are handy to have;
|
|
|
|
|
# in fact, these are the standard versions used most places in the
|
|
|
|
|
# Distutils.
|
|
|
|
|
_config_vars['prefix'] = PREFIX
|
|
|
|
|
_config_vars['exec_prefix'] = EXEC_PREFIX
|
|
|
|
|
|
2013-11-22 15:31:35 -05:00
|
|
|
# For backward compatibility, see issue19555
|
|
|
|
|
SO = _config_vars.get('EXT_SUFFIX')
|
|
|
|
|
if SO is not None:
|
|
|
|
|
_config_vars['SO'] = SO
|
|
|
|
|
|
2012-07-27 12:06:55 +01:00
|
|
|
# Always convert srcdir to an absolute path
|
|
|
|
|
srcdir = _config_vars.get('srcdir', project_base)
|
|
|
|
|
if os.name == 'posix':
|
|
|
|
|
if python_build:
|
|
|
|
|
# If srcdir is a relative path (typically '.' or '..')
|
|
|
|
|
# then it should be interpreted relative to the directory
|
|
|
|
|
# containing Makefile.
|
|
|
|
|
base = os.path.dirname(get_makefile_filename())
|
|
|
|
|
srcdir = os.path.join(base, srcdir)
|
|
|
|
|
else:
|
|
|
|
|
# srcdir is not meaningful since the installation is
|
|
|
|
|
# spread about the filesystem. We choose the
|
|
|
|
|
# directory containing the Makefile since we know it
|
|
|
|
|
# exists.
|
|
|
|
|
srcdir = os.path.dirname(get_makefile_filename())
|
|
|
|
|
_config_vars['srcdir'] = os.path.abspath(os.path.normpath(srcdir))
|
|
|
|
|
|
2010-07-22 12:50:05 +00:00
|
|
|
# Convert srcdir into an absolute path if it appears necessary.
|
|
|
|
|
# Normally it is relative to the build directory. However, during
|
|
|
|
|
# testing, for example, we might be running a non-installed python
|
|
|
|
|
# from a different directory.
|
|
|
|
|
if python_build and os.name == "posix":
|
2013-01-25 14:33:33 +01:00
|
|
|
base = project_base
|
2010-07-22 12:50:05 +00:00
|
|
|
if (not os.path.isabs(_config_vars['srcdir']) and
|
|
|
|
|
base != os.getcwd()):
|
|
|
|
|
# srcdir is relative and we are not in the same directory
|
|
|
|
|
# as the executable. Assume executable is in the build
|
|
|
|
|
# directory and make srcdir absolute.
|
|
|
|
|
srcdir = os.path.join(base, _config_vars['srcdir'])
|
|
|
|
|
_config_vars['srcdir'] = os.path.normpath(srcdir)
|
|
|
|
|
|
2012-07-21 05:36:30 -07:00
|
|
|
# OS X platforms require special customization to handle
|
|
|
|
|
# multi-architecture, multi-os-version installers
|
2010-07-22 12:50:05 +00:00
|
|
|
if sys.platform == 'darwin':
|
2012-07-21 05:36:30 -07:00
|
|
|
import _osx_support
|
|
|
|
|
_osx_support.customize_config_vars(_config_vars)
|
2012-07-15 21:30:03 -07:00
|
|
|
|
2010-07-22 12:50:05 +00:00
|
|
|
if args:
|
|
|
|
|
vals = []
|
|
|
|
|
for name in args:
|
|
|
|
|
vals.append(_config_vars.get(name))
|
|
|
|
|
return vals
|
|
|
|
|
else:
|
|
|
|
|
return _config_vars
|
|
|
|
|
|
|
|
|
|
def get_config_var(name):
|
|
|
|
|
"""Return the value of a single variable using the dictionary
|
|
|
|
|
returned by 'get_config_vars()'. Equivalent to
|
|
|
|
|
get_config_vars().get(name)
|
|
|
|
|
"""
|
2013-11-22 15:31:35 -05:00
|
|
|
if name == 'SO':
|
|
|
|
|
import warnings
|
2013-11-26 17:08:24 +02:00
|
|
|
warnings.warn('SO is deprecated, use EXT_SUFFIX', DeprecationWarning, 2)
|
2010-07-22 12:50:05 +00:00
|
|
|
return get_config_vars().get(name)
|