annotate Lib/distutils/sysconfig.py @ 79691:05c8928362ee

Merge __next__ method link fixes with 3.3.
author Ezio Melotti <ezio.melotti@gmail.com>
date Fri, 12 Oct 2012 13:46:37 +0300
parents 147b9d530dd0
children 7d69d04522e3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
1 """Provide access to Python's configuration information. The specific
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
2 configuration variables available depend heavily on the platform and
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
3 configuration. The values may be retrieved using
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
4 get_config_var(name), and the list of variables is available via
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
5 get_config_vars().keys(). Additional convenience functions are also
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
6 available.
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
7
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
8 Written by: Fred L. Drake, Jr.
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
9 Email: <fdrake@acm.org>
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
10 """
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
11
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
12 import os
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
13 import re
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
14 import sys
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
15
36988
49c6eb688906 Checkpoint. 218 tests are okay; 53 are failing. Done so far:
Guido van Rossum <guido@python.org>
parents: 34960
diff changeset
16 from .errors import DistutilsPlatformError
11953
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
17
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
18 # These are needed in a couple of spots, so just compute them once.
12315
f1f665e075ca Better variable names here and there.
Greg Ward <gward@python.net>
parents: 11953
diff changeset
19 PREFIX = os.path.normpath(sys.prefix)
f1f665e075ca Better variable names here and there.
Greg Ward <gward@python.net>
parents: 11953
diff changeset
20 EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
77154
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
21 BASE_PREFIX = os.path.normpath(sys.base_prefix)
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
22 BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
11689
09dbb47034e0 Comment fix.
Greg Ward <gward@python.net>
parents: 11251
diff changeset
23
44226
aad65a2424e3 Merged revisions 59376-59406 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43026
diff changeset
24 # Path to the base directory of the project. On Windows the binary may
45931
1657f0acca78 Merged revisions 61538-61540,61556,61559-61560,61563,61565,61571,61575-61576,61580-61582,61586,61591,61593,61595,61605-61606,61613-61616,61618,61621-61623,61625,61627,61631-61634 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45192
diff changeset
25 # live in project/PCBuild9. If we're dealing with an x64 Windows build,
1657f0acca78 Merged revisions 61538-61540,61556,61559-61560,61563,61565,61571,61575-61576,61580-61582,61586,61591,61593,61595,61605-61606,61613-61616,61618,61621-61623,61625,61627,61631-61634 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45192
diff changeset
26 # it'll live in project/PCbuild/amd64.
63136
29a3eda89995 reverted distutils its 3.1 state. All new work is now happening in disutils2, and distutils is now feature-frozen.
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 58652
diff changeset
27 project_base = os.path.dirname(os.path.abspath(sys.executable))
44226
aad65a2424e3 Merged revisions 59376-59406 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43026
diff changeset
28 if os.name == "nt" and "pcbuild" in project_base[-8:].lower():
aad65a2424e3 Merged revisions 59376-59406 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43026
diff changeset
29 project_base = os.path.abspath(os.path.join(project_base, os.path.pardir))
44413
eee1b76a94e0 Merged revisions 59628-59641 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44310
diff changeset
30 # PC/VS7.1
eee1b76a94e0 Merged revisions 59628-59641 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44310
diff changeset
31 if os.name == "nt" and "\\pc\\v" in project_base[-10:].lower():
eee1b76a94e0 Merged revisions 59628-59641 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44310
diff changeset
32 project_base = os.path.abspath(os.path.join(project_base, os.path.pardir,
eee1b76a94e0 Merged revisions 59628-59641 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44310
diff changeset
33 os.path.pardir))
45931
1657f0acca78 Merged revisions 61538-61540,61556,61559-61560,61563,61565,61571,61575-61576,61580-61582,61586,61591,61593,61595,61605-61606,61613-61616,61618,61621-61623,61625,61627,61631-61634 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45192
diff changeset
34 # PC/AMD64
1657f0acca78 Merged revisions 61538-61540,61556,61559-61560,61563,61565,61571,61575-61576,61580-61582,61586,61591,61593,61595,61605-61606,61613-61616,61618,61621-61623,61625,61627,61631-61634 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45192
diff changeset
35 if os.name == "nt" and "\\pcbuild\\amd64" in project_base[-14:].lower():
1657f0acca78 Merged revisions 61538-61540,61556,61559-61560,61563,61565,61571,61575-61576,61580-61582,61586,61591,61593,61595,61605-61606,61613-61616,61618,61621-61623,61625,61627,61631-61634 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45192
diff changeset
36 project_base = os.path.abspath(os.path.join(project_base, os.path.pardir,
1657f0acca78 Merged revisions 61538-61540,61556,61559-61560,61563,61565,61571,61575-61576,61580-61582,61586,61591,61593,61595,61605-61606,61613-61616,61618,61621-61623,61625,61627,61631-61634 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45192
diff changeset
37 os.path.pardir))
44226
aad65a2424e3 Merged revisions 59376-59406 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43026
diff changeset
38
23659
5c5fff5de250 When using a Python that has not been installed to build 3rd-party
Fred Drake <fdrake@acm.org>
parents: 21851
diff changeset
39 # python_build: (Boolean) if true, we're either building Python or
5c5fff5de250 When using a Python that has not been installed to build 3rd-party
Fred Drake <fdrake@acm.org>
parents: 21851
diff changeset
40 # building an extension with an un-installed Python, so we use
5c5fff5de250 When using a Python that has not been installed to build 3rd-party
Fred Drake <fdrake@acm.org>
parents: 21851
diff changeset
41 # different (hard-wired) directories.
44310
e70acbf26cda Merged revisions 59488-59511 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44291
diff changeset
42 # Setup.local is available for Makefile builds including VPATH builds,
e70acbf26cda Merged revisions 59488-59511 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44291
diff changeset
43 # Setup.dist is available on Windows
77154
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
44 def _is_python_source_dir(d):
45192
142a11b3057e 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
Christian Heimes <christian@cheimes.de>
parents: 44413
diff changeset
45 for fn in ("Setup.dist", "Setup.local"):
77154
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
46 if os.path.isfile(os.path.join(d, "Modules", fn)):
45192
142a11b3057e 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
Christian Heimes <christian@cheimes.de>
parents: 44413
diff changeset
47 return True
142a11b3057e 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
Christian Heimes <christian@cheimes.de>
parents: 44413
diff changeset
48 return False
77154
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
49 _sys_home = getattr(sys, '_home', None)
77167
564caa2c61ae Addressed some buildbot errors and comments on the checkin by Antoine on python-dev.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 77154
diff changeset
50 if _sys_home and os.name == 'nt' and \
564caa2c61ae Addressed some buildbot errors and comments on the checkin by Antoine on python-dev.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 77154
diff changeset
51 _sys_home.lower().endswith(('pcbuild', 'pcbuild\\amd64')):
77154
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
52 _sys_home = os.path.dirname(_sys_home)
77182
a45c86f5ba96 Fixed _sys_home computation and added diagnostics for Windows buildbot failures.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 77167
diff changeset
53 if _sys_home.endswith('pcbuild'): # must be amd64
a45c86f5ba96 Fixed _sys_home computation and added diagnostics for Windows buildbot failures.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 77167
diff changeset
54 _sys_home = os.path.dirname(_sys_home)
77154
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
55 def _python_build():
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
56 if _sys_home:
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
57 return _is_python_source_dir(_sys_home)
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
58 return _is_python_source_dir(project_base)
45192
142a11b3057e 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
Christian Heimes <christian@cheimes.de>
parents: 44413
diff changeset
59 python_build = _python_build()
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
60
66429
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
61 # Calculate the build qualifier flags if they are defined. Adding the flags
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
62 # to the include and lib directories only makes sense for an installation, not
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
63 # an in-source build.
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
64 build_flags = ''
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
65 try:
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
66 if not python_build:
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
67 build_flags = sys.abiflags
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
68 except AttributeError:
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
69 # It's not a configure-based build, so the sys module doesn't have
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
70 # this attribute, which is fine.
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
71 pass
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
72
34661
9fa768a98c5c Patch #1046831: Use get_python_version where appropriate in sysconfig.py.
Martin v. Löwis <martin@v.loewis.de>
parents: 34258
diff changeset
73 def get_python_version():
26205
d33005f8388e [Bug #550364] Add get_python_version()
Andrew M. Kuchling <amk@amk.ca>
parents: 26186
diff changeset
74 """Return a string containing the major and minor Python version,
d33005f8388e [Bug #550364] Add get_python_version()
Andrew M. Kuchling <amk@amk.ca>
parents: 26186
diff changeset
75 leaving off the patchlevel. Sample return values could be '1.5'
d33005f8388e [Bug #550364] Add get_python_version()
Andrew M. Kuchling <amk@amk.ca>
parents: 26186
diff changeset
76 or '2.2'.
d33005f8388e [Bug #550364] Add get_python_version()
Andrew M. Kuchling <amk@amk.ca>
parents: 26186
diff changeset
77 """
d33005f8388e [Bug #550364] Add get_python_version()
Andrew M. Kuchling <amk@amk.ca>
parents: 26186
diff changeset
78 return sys.version[:3]
d33005f8388e [Bug #550364] Add get_python_version()
Andrew M. Kuchling <amk@amk.ca>
parents: 26186
diff changeset
79
d33005f8388e [Bug #550364] Add get_python_version()
Andrew M. Kuchling <amk@amk.ca>
parents: 26186
diff changeset
80
12316
540f10881a59 Added optional 'prefix' arguments to 'get_python_inc()' and
Greg Ward <gward@python.net>
parents: 12315
diff changeset
81 def get_python_inc(plat_specific=0, prefix=None):
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
82 """Return the directory containing installed Python header files.
11953
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
83
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
84 If 'plat_specific' is false (the default), this is the path to the
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
85 non-platform-specific header files, i.e. Python.h and so on;
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
86 otherwise, this is the path to platform-specific header files
18835
2dea40e40d9d Patch #411138: Rename config.h to pyconfig.h. Closes bug #231774.
Martin v. Löwis <martin@v.loewis.de>
parents: 18696
diff changeset
87 (namely pyconfig.h).
11953
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
88
77154
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
89 If 'prefix' is supplied, use it instead of sys.base_prefix or
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
90 sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19724
diff changeset
91 """
12316
540f10881a59 Added optional 'prefix' arguments to 'get_python_inc()' and
Greg Ward <gward@python.net>
parents: 12315
diff changeset
92 if prefix is None:
77154
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
93 prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
94 if os.name == "posix":
15937
d9d0dcb735d7 Patch #103279: sysconfig.py always looks for versions of files in
Andrew M. Kuchling <amk@amk.ca>
parents: 15923
diff changeset
95 if python_build:
51347
41c71ad47f89 Fix get_python_inc() to work when building in a directory separate from
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 48769
diff changeset
96 # Assume the executable is in the build directory. The
41c71ad47f89 Fix get_python_inc() to work when building in a directory separate from
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 48769
diff changeset
97 # pyconfig.h file should be in the same directory. Since
41c71ad47f89 Fix get_python_inc() to work when building in a directory separate from
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 48769
diff changeset
98 # the build directory may not be the source directory, we
41c71ad47f89 Fix get_python_inc() to work when building in a directory separate from
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 48769
diff changeset
99 # must use "srcdir" from the makefile to find the "Include"
41c71ad47f89 Fix get_python_inc() to work when building in a directory separate from
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 48769
diff changeset
100 # directory.
77154
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
101 base = _sys_home or os.path.dirname(os.path.abspath(sys.executable))
23659
5c5fff5de250 When using a Python that has not been installed to build 3rd-party
Fred Drake <fdrake@acm.org>
parents: 21851
diff changeset
102 if plat_specific:
51347
41c71ad47f89 Fix get_python_inc() to work when building in a directory separate from
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 48769
diff changeset
103 return base
78135
998c8a8f2aea Closes #15366: Corrected computation of include location for source builds. Thanks to Richard Oudkerk for the bug report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 78126
diff changeset
104 if _sys_home:
998c8a8f2aea Closes #15366: Corrected computation of include location for source builds. Thanks to Richard Oudkerk for the bug report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 78126
diff changeset
105 incdir = os.path.join(_sys_home, get_config_var('AST_H_DIR'))
23659
5c5fff5de250 When using a Python that has not been installed to build 3rd-party
Fred Drake <fdrake@acm.org>
parents: 21851
diff changeset
106 else:
78135
998c8a8f2aea Closes #15366: Corrected computation of include location for source builds. Thanks to Richard Oudkerk for the bug report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 78126
diff changeset
107 incdir = os.path.join(get_config_var('srcdir'), 'Include')
998c8a8f2aea Closes #15366: Corrected computation of include location for source builds. Thanks to Richard Oudkerk for the bug report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 78126
diff changeset
108 return os.path.normpath(incdir)
66429
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
109 python_dir = 'python' + get_python_version() + build_flags
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
110 return os.path.join(prefix, "include", python_dir)
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
111 elif os.name == "nt":
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
112 return os.path.join(prefix, "include")
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
113 else:
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
114 raise DistutilsPlatformError(
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
115 "I don't know where Python installs its C header files "
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
116 "on platform '%s'" % os.name)
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
117
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
118
12316
540f10881a59 Added optional 'prefix' arguments to 'get_python_inc()' and
Greg Ward <gward@python.net>
parents: 12315
diff changeset
119 def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
120 """Return the directory containing the Python library (standard or
11953
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
121 site additions).
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
122
11953
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
123 If 'plat_specific' is true, return the directory containing
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
124 platform-specific modules, i.e. any module from a non-pure-Python
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
125 module distribution; otherwise, return the platform-shared library
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
126 directory. If 'standard_lib' is true, return the directory
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
127 containing standard Python library modules; otherwise, return the
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
128 directory for site-specific modules.
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
129
77154
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
130 If 'prefix' is supplied, use it instead of sys.base_prefix or
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
131 sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
11953
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
132 """
12316
540f10881a59 Added optional 'prefix' arguments to 'get_python_inc()' and
Greg Ward <gward@python.net>
parents: 12315
diff changeset
133 if prefix is None:
77154
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
134 if standard_lib:
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
135 prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
136 else:
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
137 prefix = plat_specific and EXEC_PREFIX or PREFIX
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
138
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
139 if os.name == "posix":
12315
f1f665e075ca Better variable names here and there.
Greg Ward <gward@python.net>
parents: 11953
diff changeset
140 libpython = os.path.join(prefix,
26205
d33005f8388e [Bug #550364] Add get_python_version()
Andrew M. Kuchling <amk@amk.ca>
parents: 26186
diff changeset
141 "lib", "python" + get_python_version())
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
142 if standard_lib:
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
143 return libpython
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
144 else:
11953
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
145 return os.path.join(libpython, "site-packages")
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
146 elif os.name == "nt":
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
147 if standard_lib:
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
148 return os.path.join(prefix, "Lib")
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
149 else:
34661
9fa768a98c5c Patch #1046831: Use get_python_version where appropriate in sysconfig.py.
Martin v. Löwis <martin@v.loewis.de>
parents: 34258
diff changeset
150 if get_python_version() < "2.2":
19453
7fb5f15685dd Patch #449054 to implement PEP 250. The standard install directory for
Greg Ward <gward@python.net>
parents: 18945
diff changeset
151 return prefix
7fb5f15685dd Patch #449054 to implement PEP 250. The standard install directory for
Greg Ward <gward@python.net>
parents: 18945
diff changeset
152 else:
51506
8a28d99f784d Merged revisions 69485 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51406
diff changeset
153 return os.path.join(prefix, "Lib", "site-packages")
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
154 else:
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
155 raise DistutilsPlatformError(
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
156 "I don't know where Python installs its library "
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
157 "on platform '%s'" % os.name)
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
158
77661
688d48e434e4 Issue #13590: Improve support for OS X Xcode 4:
Ned Deily <nad@acm.org>
parents: 77182
diff changeset
159
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
160
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
161 def customize_compiler(compiler):
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
162 """Do any platform-specific customization of a CCompiler instance.
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
163
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
164 Mainly needed on Unix, so we can plug in the information that
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
165 varies across Unices and is stored in Python's Makefile.
13009
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
166 """
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
167 if compiler.compiler_type == "unix":
78216
d76b83803e7e Issue #15184: Ensure consistent results of OS X configuration
Ned Deily <nad@acm.org>
parents: 78135
diff changeset
168 if sys.platform == "darwin":
d76b83803e7e Issue #15184: Ensure consistent results of OS X configuration
Ned Deily <nad@acm.org>
parents: 78135
diff changeset
169 # Perform first-time customization of compiler-related
d76b83803e7e Issue #15184: Ensure consistent results of OS X configuration
Ned Deily <nad@acm.org>
parents: 78135
diff changeset
170 # config vars on OS X now that we know we need a compiler.
d76b83803e7e Issue #15184: Ensure consistent results of OS X configuration
Ned Deily <nad@acm.org>
parents: 78135
diff changeset
171 # This is primarily to support Pythons from binary
d76b83803e7e Issue #15184: Ensure consistent results of OS X configuration
Ned Deily <nad@acm.org>
parents: 78135
diff changeset
172 # installers. The kind and paths to build tools on
d76b83803e7e Issue #15184: Ensure consistent results of OS X configuration
Ned Deily <nad@acm.org>
parents: 78135
diff changeset
173 # the user system may vary significantly from the system
d76b83803e7e Issue #15184: Ensure consistent results of OS X configuration
Ned Deily <nad@acm.org>
parents: 78135
diff changeset
174 # that Python itself was built on. Also the user OS
d76b83803e7e Issue #15184: Ensure consistent results of OS X configuration
Ned Deily <nad@acm.org>
parents: 78135
diff changeset
175 # version and build tools may not support the same set
d76b83803e7e Issue #15184: Ensure consistent results of OS X configuration
Ned Deily <nad@acm.org>
parents: 78135
diff changeset
176 # of CPU architectures for universal builds.
d76b83803e7e Issue #15184: Ensure consistent results of OS X configuration
Ned Deily <nad@acm.org>
parents: 78135
diff changeset
177 global _config_vars
d76b83803e7e Issue #15184: Ensure consistent results of OS X configuration
Ned Deily <nad@acm.org>
parents: 78135
diff changeset
178 if not _config_vars.get('CUSTOMIZED_OSX_COMPILER', ''):
d76b83803e7e Issue #15184: Ensure consistent results of OS X configuration
Ned Deily <nad@acm.org>
parents: 78135
diff changeset
179 import _osx_support
d76b83803e7e Issue #15184: Ensure consistent results of OS X configuration
Ned Deily <nad@acm.org>
parents: 78135
diff changeset
180 _osx_support.customize_compiler(_config_vars)
d76b83803e7e Issue #15184: Ensure consistent results of OS X configuration
Ned Deily <nad@acm.org>
parents: 78135
diff changeset
181 _config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'
d76b83803e7e Issue #15184: Ensure consistent results of OS X configuration
Ned Deily <nad@acm.org>
parents: 78135
diff changeset
182
53889
198b68ae2c2d Merged revisions 72445 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51506
diff changeset
183 (cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \
34960
80fb2891b33b Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 34930
diff changeset
184 get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
53889
198b68ae2c2d Merged revisions 72445 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51506
diff changeset
185 'CCSHARED', 'LDSHARED', 'SO', 'AR', 'ARFLAGS')
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
186
74862
5c784b0f263d Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 72820
diff changeset
187 newcc = None
39575
63237fcefd99 Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents: 39442
diff changeset
188 if 'CC' in os.environ:
77661
688d48e434e4 Issue #13590: Improve support for OS X Xcode 4:
Ned Deily <nad@acm.org>
parents: 77182
diff changeset
189 cc = os.environ['CC']
39575
63237fcefd99 Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents: 39442
diff changeset
190 if 'CXX' in os.environ:
26036
771b6f521b95 This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 26020
diff changeset
191 cxx = os.environ['CXX']
39575
63237fcefd99 Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents: 39442
diff changeset
192 if 'LDSHARED' in os.environ:
33750
ec993b726605 Patch 983206: distutils obeys LDSHARED env var. Removed the code in
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32736
diff changeset
193 ldshared = os.environ['LDSHARED']
39575
63237fcefd99 Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents: 39442
diff changeset
194 if 'CPP' in os.environ:
26020
8e3246842773 [Patch #588809] LDFLAGS support for build_ext.py, from Robert Weber
Andrew M. Kuchling <amk@amk.ca>
parents: 24211
diff changeset
195 cpp = os.environ['CPP']
8e3246842773 [Patch #588809] LDFLAGS support for build_ext.py, from Robert Weber
Andrew M. Kuchling <amk@amk.ca>
parents: 24211
diff changeset
196 else:
8e3246842773 [Patch #588809] LDFLAGS support for build_ext.py, from Robert Weber
Andrew M. Kuchling <amk@amk.ca>
parents: 24211
diff changeset
197 cpp = cc + " -E" # not always
39575
63237fcefd99 Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents: 39442
diff changeset
198 if 'LDFLAGS' in os.environ:
26020
8e3246842773 [Patch #588809] LDFLAGS support for build_ext.py, from Robert Weber
Andrew M. Kuchling <amk@amk.ca>
parents: 24211
diff changeset
199 ldshared = ldshared + ' ' + os.environ['LDFLAGS']
39575
63237fcefd99 Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents: 39442
diff changeset
200 if 'CFLAGS' in os.environ:
34930
294dabcb379b Make parse_makefile fallback to environment variables if nothing is
Martin v. Löwis <martin@v.loewis.de>
parents: 34929
diff changeset
201 cflags = opt + ' ' + os.environ['CFLAGS']
26020
8e3246842773 [Patch #588809] LDFLAGS support for build_ext.py, from Robert Weber
Andrew M. Kuchling <amk@amk.ca>
parents: 24211
diff changeset
202 ldshared = ldshared + ' ' + os.environ['CFLAGS']
39575
63237fcefd99 Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents: 39442
diff changeset
203 if 'CPPFLAGS' in os.environ:
26020
8e3246842773 [Patch #588809] LDFLAGS support for build_ext.py, from Robert Weber
Andrew M. Kuchling <amk@amk.ca>
parents: 24211
diff changeset
204 cpp = cpp + ' ' + os.environ['CPPFLAGS']
34930
294dabcb379b Make parse_makefile fallback to environment variables if nothing is
Martin v. Löwis <martin@v.loewis.de>
parents: 34929
diff changeset
205 cflags = cflags + ' ' + os.environ['CPPFLAGS']
26020
8e3246842773 [Patch #588809] LDFLAGS support for build_ext.py, from Robert Weber
Andrew M. Kuchling <amk@amk.ca>
parents: 24211
diff changeset
206 ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
51376
207097691972 Merged revisions 69342 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51347
diff changeset
207 if 'AR' in os.environ:
207097691972 Merged revisions 69342 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51347
diff changeset
208 ar = os.environ['AR']
53889
198b68ae2c2d Merged revisions 72445 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51506
diff changeset
209 if 'ARFLAGS' in os.environ:
198b68ae2c2d Merged revisions 72445 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51506
diff changeset
210 archiver = ar + ' ' + os.environ['ARFLAGS']
198b68ae2c2d Merged revisions 72445 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51506
diff changeset
211 else:
198b68ae2c2d Merged revisions 72445 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51506
diff changeset
212 archiver = ar + ' ' + ar_flags
26020
8e3246842773 [Patch #588809] LDFLAGS support for build_ext.py, from Robert Weber
Andrew M. Kuchling <amk@amk.ca>
parents: 24211
diff changeset
213
34930
294dabcb379b Make parse_makefile fallback to environment variables if nothing is
Martin v. Löwis <martin@v.loewis.de>
parents: 34929
diff changeset
214 cc_cmd = cc + ' ' + cflags
13009
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
215 compiler.set_executables(
26020
8e3246842773 [Patch #588809] LDFLAGS support for build_ext.py, from Robert Weber
Andrew M. Kuchling <amk@amk.ca>
parents: 24211
diff changeset
216 preprocessor=cpp,
13009
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
217 compiler=cc_cmd,
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
218 compiler_so=cc_cmd + ' ' + ccshared,
26036
771b6f521b95 This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 26020
diff changeset
219 compiler_cxx=cxx,
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
220 linker_so=ldshared,
51376
207097691972 Merged revisions 69342 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51347
diff changeset
221 linker_exe=cc,
53889
198b68ae2c2d Merged revisions 72445 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51506
diff changeset
222 archiver=archiver)
13009
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
223
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
224 compiler.shared_lib_extension = so_ext
13009
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
225
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
226
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
227 def get_config_h_filename():
18835
2dea40e40d9d Patch #411138: Rename config.h to pyconfig.h. Closes bug #231774.
Martin v. Löwis <martin@v.loewis.de>
parents: 18696
diff changeset
228 """Return full pathname of installed pyconfig.h file."""
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
229 if python_build:
44226
aad65a2424e3 Merged revisions 59376-59406 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43026
diff changeset
230 if os.name == "nt":
77154
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
231 inc_dir = os.path.join(_sys_home or project_base, "PC")
44226
aad65a2424e3 Merged revisions 59376-59406 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43026
diff changeset
232 else:
77154
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
233 inc_dir = _sys_home or project_base
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
234 else:
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
235 inc_dir = get_python_inc(plat_specific=1)
34661
9fa768a98c5c Patch #1046831: Use get_python_version where appropriate in sysconfig.py.
Martin v. Löwis <martin@v.loewis.de>
parents: 34258
diff changeset
236 if get_python_version() < '2.2':
18837
5e0a40ccb9da Add backwards compatibility.
Marc-André Lemburg <mal@egenix.com>
parents: 18835
diff changeset
237 config_h = 'config.h'
5e0a40ccb9da Add backwards compatibility.
Marc-André Lemburg <mal@egenix.com>
parents: 18835
diff changeset
238 else:
5e0a40ccb9da Add backwards compatibility.
Marc-André Lemburg <mal@egenix.com>
parents: 18835
diff changeset
239 # The name of the config.h file changed in 2.2
5e0a40ccb9da Add backwards compatibility.
Marc-André Lemburg <mal@egenix.com>
parents: 18835
diff changeset
240 config_h = 'pyconfig.h'
5e0a40ccb9da Add backwards compatibility.
Marc-André Lemburg <mal@egenix.com>
parents: 18835
diff changeset
241 return os.path.join(inc_dir, config_h)
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
242
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
243
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
244 def get_makefile_filename():
9783
be24b5b90dec Update and add docstrings.
Fred Drake <fdrake@acm.org>
parents: 9780
diff changeset
245 """Return full pathname of installed Makefile from the Python build."""
15937
d9d0dcb735d7 Patch #103279: sysconfig.py always looks for versions of files in
Andrew M. Kuchling <amk@amk.ca>
parents: 15923
diff changeset
246 if python_build:
77154
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
247 return os.path.join(_sys_home or os.path.dirname(sys.executable),
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 74862
diff changeset
248 "Makefile")
72820
9afd3d54c3cb Fix distutils.sysconfig.get_makefile_filename when prefix != exec-prefix
Éric Araujo <merwok@netwok.org>
parents: 71540
diff changeset
249 lib_dir = get_python_lib(plat_specific=0, standard_lib=1)
66429
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
250 config_file = 'config-{}{}'.format(get_python_version(), build_flags)
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
251 return os.path.join(lib_dir, config_file, 'Makefile')
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
252
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
253
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
254 def parse_config_h(fp, g=None):
11953
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
255 """Parse a config.h-style file.
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
256
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
257 A dictionary containing name/value pairs is returned. If an
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
258 optional dictionary is passed in as the second argument, it is
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
259 used instead of a new dictionary.
9783
be24b5b90dec Update and add docstrings.
Fred Drake <fdrake@acm.org>
parents: 9780
diff changeset
260 """
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
261 if g is None:
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
262 g = {}
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36988
diff changeset
263 define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36988
diff changeset
264 undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n")
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
265 #
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42645
diff changeset
266 while True:
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
267 line = fp.readline()
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
268 if not line:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
269 break
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
270 m = define_rx.match(line)
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
271 if m:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
272 n, v = m.group(1, 2)
26048
b4a6283b915b Remove use of string module and reflow a couple of long lines.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26036
diff changeset
273 try: v = int(v)
9690
31489799c8c6 Applied Fred's patch to fix the bugs that John Skaller noticed.
Greg Ward <gward@python.net>
parents: 9658
diff changeset
274 except ValueError: pass
31489799c8c6 Applied Fred's patch to fix the bugs that John Skaller noticed.
Greg Ward <gward@python.net>
parents: 9658
diff changeset
275 g[n] = v
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
276 else:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
277 m = undef_rx.match(line)
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
278 if m:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
279 g[m.group(1)] = 0
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
280 return g
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
281
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
282
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
283 # Regexes needed for parsing Makefile (and similar syntaxes,
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
284 # like old-style Setup files).
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
285 _variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
286 _findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
287 _findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
288
14571
600515747c51 Fixed so 'parse_makefile()' uses the TextFile class to ensure that
Greg Ward <gward@python.net>
parents: 14321
diff changeset
289 def parse_makefile(fn, g=None):
11953
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
290 """Parse a Makefile-style file.
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
291
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
292 A dictionary containing name/value pairs is returned. If an
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
293 optional dictionary is passed in as the second argument, it is
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
294 used instead of a new dictionary.
9783
be24b5b90dec Update and add docstrings.
Fred Drake <fdrake@acm.org>
parents: 9780
diff changeset
295 """
14571
600515747c51 Fixed so 'parse_makefile()' uses the TextFile class to ensure that
Greg Ward <gward@python.net>
parents: 14321
diff changeset
296 from distutils.text_file import TextFile
65605
1a08f4a9eafd Issue #6011: sysconfig and distutils.sysconfig use the surrogateescape error
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65206
diff changeset
297 fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1, errors="surrogateescape")
14571
600515747c51 Fixed so 'parse_makefile()' uses the TextFile class to ensure that
Greg Ward <gward@python.net>
parents: 14321
diff changeset
298
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
299 if g is None:
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
300 g = {}
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
301 done = {}
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
302 notdone = {}
14571
600515747c51 Fixed so 'parse_makefile()' uses the TextFile class to ensure that
Greg Ward <gward@python.net>
parents: 14321
diff changeset
303
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42645
diff changeset
304 while True:
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
305 line = fp.readline()
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42645
diff changeset
306 if line is None: # eof
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
307 break
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
308 m = _variable_rx.match(line)
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
309 if m:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
310 n, v = m.group(1, 2)
41480
99027c2b3fd2 Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40809
diff changeset
311 v = v.strip()
54670
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
312 # `$$' is a literal `$' in make
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
313 tmpv = v.replace('$$', '')
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
314
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
315 if "$" in tmpv:
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
316 notdone[n] = v
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
317 else:
54670
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
318 try:
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
319 v = int(v)
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
320 except ValueError:
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
321 # insert literal `$'
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
322 done[n] = v.replace('$$', '$')
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
323 else:
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
324 done[n] = v
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
325
63140
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
326 # Variables with a 'PY_' prefix in the makefile. These need to
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
327 # be made available without that prefix through sysconfig.
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
328 # Special care is needed to ensure that variable expansion works, even
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
329 # if the expansion uses the name without a prefix.
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
330 renamed_variables = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS')
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
331
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
332 # do variable interpolation here
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
333 while notdone:
40809
f340cb045bf9 - PEP 3106: dict.iterkeys(), .iteritems(), .itervalues() are now gone;
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
334 for name in list(notdone):
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
335 value = notdone[name]
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
336 m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
337 if m:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
338 n = m.group(1)
34930
294dabcb379b Make parse_makefile fallback to environment variables if nothing is
Martin v. Löwis <martin@v.loewis.de>
parents: 34929
diff changeset
339 found = True
39575
63237fcefd99 Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents: 39442
diff changeset
340 if n in done:
34930
294dabcb379b Make parse_makefile fallback to environment variables if nothing is
Martin v. Löwis <martin@v.loewis.de>
parents: 34929
diff changeset
341 item = str(done[n])
39575
63237fcefd99 Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents: 39442
diff changeset
342 elif n in notdone:
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
343 # get it on a subsequent round
34930
294dabcb379b Make parse_makefile fallback to environment variables if nothing is
Martin v. Löwis <martin@v.loewis.de>
parents: 34929
diff changeset
344 found = False
39575
63237fcefd99 Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents: 39442
diff changeset
345 elif n in os.environ:
34930
294dabcb379b Make parse_makefile fallback to environment variables if nothing is
Martin v. Löwis <martin@v.loewis.de>
parents: 34929
diff changeset
346 # do it like make: fall back to environment
294dabcb379b Make parse_makefile fallback to environment variables if nothing is
Martin v. Löwis <martin@v.loewis.de>
parents: 34929
diff changeset
347 item = os.environ[n]
63140
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
348
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
349 elif n in renamed_variables:
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
350 if name.startswith('PY_') and name[3:] in renamed_variables:
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
351 item = ""
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
352
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
353 elif 'PY_' + n in notdone:
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
354 found = False
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
355
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
356 else:
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
357 item = str(done['PY_' + n])
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
358 else:
34930
294dabcb379b Make parse_makefile fallback to environment variables if nothing is
Martin v. Löwis <martin@v.loewis.de>
parents: 34929
diff changeset
359 done[n] = item = ""
294dabcb379b Make parse_makefile fallback to environment variables if nothing is
Martin v. Löwis <martin@v.loewis.de>
parents: 34929
diff changeset
360 if found:
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
361 after = value[m.end():]
34930
294dabcb379b Make parse_makefile fallback to environment variables if nothing is
Martin v. Löwis <martin@v.loewis.de>
parents: 34929
diff changeset
362 value = value[:m.start()] + item + after
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
363 if "$" in after:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
364 notdone[name] = value
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
365 else:
26048
b4a6283b915b Remove use of string module and reflow a couple of long lines.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26036
diff changeset
366 try: value = int(value)
15923
ff6c30e8ca73 Fix bugs with integer-valued variables when parsing Makefiles. Values
Andrew M. Kuchling <amk@amk.ca>
parents: 15818
diff changeset
367 except ValueError:
41480
99027c2b3fd2 Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40809
diff changeset
368 done[name] = value.strip()
15923
ff6c30e8ca73 Fix bugs with integer-valued variables when parsing Makefiles. Values
Andrew M. Kuchling <amk@amk.ca>
parents: 15818
diff changeset
369 else:
ff6c30e8ca73 Fix bugs with integer-valued variables when parsing Makefiles. Values
Andrew M. Kuchling <amk@amk.ca>
parents: 15818
diff changeset
370 done[name] = value
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
371 del notdone[name]
63140
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
372
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
373 if name.startswith('PY_') \
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
374 and name[3:] in renamed_variables:
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
375
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
376 name = name[3:]
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
377 if name not in done:
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
378 done[name] = value
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
379 else:
9690
31489799c8c6 Applied Fred's patch to fix the bugs that John Skaller noticed.
Greg Ward <gward@python.net>
parents: 9658
diff changeset
380 # bogus variable reference; just drop it since we can't deal
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
381 del notdone[name]
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
382
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
383 fp.close()
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
384
65206
25d078739c2a Issue #9437: Fix building C extensions with non-default LDFLAGS.
Antoine Pitrou <solipsis@pitrou.net>
parents: 64850
diff changeset
385 # strip spurious spaces
25d078739c2a Issue #9437: Fix building C extensions with non-default LDFLAGS.
Antoine Pitrou <solipsis@pitrou.net>
parents: 64850
diff changeset
386 for k, v in done.items():
25d078739c2a Issue #9437: Fix building C extensions with non-default LDFLAGS.
Antoine Pitrou <solipsis@pitrou.net>
parents: 64850
diff changeset
387 if isinstance(v, str):
25d078739c2a Issue #9437: Fix building C extensions with non-default LDFLAGS.
Antoine Pitrou <solipsis@pitrou.net>
parents: 64850
diff changeset
388 done[k] = v.strip()
25d078739c2a Issue #9437: Fix building C extensions with non-default LDFLAGS.
Antoine Pitrou <solipsis@pitrou.net>
parents: 64850
diff changeset
389
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
390 # save the results in the global dictionary
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
391 g.update(done)
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
392 return g
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
393
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
394
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
395 def expand_makefile_vars(s, vars):
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
396 """Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
397 'string' according to 'vars' (a dictionary mapping variable names to
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
398 values). Variables not present in 'vars' are silently expanded to the
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
399 empty string. The variable values in 'vars' should not contain further
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
400 variable expansions; if 'vars' is the output of 'parse_makefile()',
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
401 you're fine. Returns a variable-expanded version of 's'.
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
402 """
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
403
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
404 # This algorithm does multiple expansion, so if vars['foo'] contains
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
405 # "${bar}", it will expand ${foo} to ${bar}, and then expand
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
406 # ${bar}... and so forth. This is fine as long as 'vars' comes from
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
407 # 'parse_makefile()', which takes care of such expansions eagerly,
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
408 # according to make's variable expansion semantics.
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
409
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42645
diff changeset
410 while True:
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
411 m = _findvar1_rx.search(s) or _findvar2_rx.search(s)
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
412 if m:
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
413 (beg, end) = m.span()
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
414 s = s[0:beg] + vars.get(m.group(1)) + s[end:]
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
415 else:
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
416 break
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
417 return s
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
418
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
419
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
420 _config_vars = None
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
421
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
422 def _init_posix():
9783
be24b5b90dec Update and add docstrings.
Fred Drake <fdrake@acm.org>
parents: 9780
diff changeset
423 """Initialize the module as appropriate for POSIX systems."""
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
424 g = {}
11689
09dbb47034e0 Comment fix.
Greg Ward <gward@python.net>
parents: 11251
diff changeset
425 # load the installed Makefile:
12740
89f42099c5dd Catch failure to open installed Makefile, and report it as a
Greg Ward <gward@python.net>
parents: 12414
diff changeset
426 try:
89f42099c5dd Catch failure to open installed Makefile, and report it as a
Greg Ward <gward@python.net>
parents: 12414
diff changeset
427 filename = get_makefile_filename()
14571
600515747c51 Fixed so 'parse_makefile()' uses the TextFile class to ensure that
Greg Ward <gward@python.net>
parents: 14321
diff changeset
428 parse_makefile(filename, g)
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
429 except IOError as msg:
12740
89f42099c5dd Catch failure to open installed Makefile, and report it as a
Greg Ward <gward@python.net>
parents: 12414
diff changeset
430 my_msg = "invalid Python installation: unable to open %s" % filename
89f42099c5dd Catch failure to open installed Makefile, and report it as a
Greg Ward <gward@python.net>
parents: 12414
diff changeset
431 if hasattr(msg, "strerror"):
89f42099c5dd Catch failure to open installed Makefile, and report it as a
Greg Ward <gward@python.net>
parents: 12414
diff changeset
432 my_msg = my_msg + " (%s)" % msg.strerror
89f42099c5dd Catch failure to open installed Makefile, and report it as a
Greg Ward <gward@python.net>
parents: 12414
diff changeset
433
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
434 raise DistutilsPlatformError(my_msg)
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
435
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36988
diff changeset
436 # load the installed pyconfig.h:
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36988
diff changeset
437 try:
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36988
diff changeset
438 filename = get_config_h_filename()
65729
3da23deb6e9a Have distutils.sysconfig close a file to remove ResourceWarnings coming up
Brett Cannon <bcannon@gmail.com>
parents: 65605
diff changeset
439 with open(filename) as file:
3da23deb6e9a Have distutils.sysconfig close a file to remove ResourceWarnings coming up
Brett Cannon <bcannon@gmail.com>
parents: 65605
diff changeset
440 parse_config_h(file, g)
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
441 except IOError as msg:
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36988
diff changeset
442 my_msg = "invalid Python installation: unable to open %s" % filename
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36988
diff changeset
443 if hasattr(msg, "strerror"):
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36988
diff changeset
444 my_msg = my_msg + " (%s)" % msg.strerror
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36988
diff changeset
445
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36988
diff changeset
446 raise DistutilsPlatformError(my_msg)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36988
diff changeset
447
13034
f1e40abbedb3 Fixed LDSHARED for AIX, based on a patch by Rene Liebscher.
Greg Ward <gward@python.net>
parents: 13009
diff changeset
448 # On AIX, there are wrong paths to the linker scripts in the Makefile
f1e40abbedb3 Fixed LDSHARED for AIX, based on a patch by Rene Liebscher.
Greg Ward <gward@python.net>
parents: 13009
diff changeset
449 # -- these paths are relative to the Python source, but when installed
f1e40abbedb3 Fixed LDSHARED for AIX, based on a patch by Rene Liebscher.
Greg Ward <gward@python.net>
parents: 13009
diff changeset
450 # the scripts are in another directory.
16621
c958678720fd Linking just got simpiler on AIX and BeOS (closes SF patch #103679).
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 16224
diff changeset
451 if python_build:
16841
3d29690a24e8 Placate tabnanny
Andrew M. Kuchling <amk@amk.ca>
parents: 16621
diff changeset
452 g['LDSHARED'] = g['BLDSHARED']
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19724
diff changeset
453
34661
9fa768a98c5c Patch #1046831: Use get_python_version where appropriate in sysconfig.py.
Martin v. Löwis <martin@v.loewis.de>
parents: 34258
diff changeset
454 elif get_python_version() < '2.1':
19724
ba9aabcd89e3 [Bug #404274] Restore some special-case code for AIX and BeOS under 1.5.2.
Andrew M. Kuchling <amk@amk.ca>
parents: 19681
diff changeset
455 # The following two branches are for 1.5.2 compatibility.
ba9aabcd89e3 [Bug #404274] Restore some special-case code for AIX and BeOS under 1.5.2.
Andrew M. Kuchling <amk@amk.ca>
parents: 19681
diff changeset
456 if sys.platform == 'aix4': # what about AIX 3.x ?
ba9aabcd89e3 [Bug #404274] Restore some special-case code for AIX and BeOS under 1.5.2.
Andrew M. Kuchling <amk@amk.ca>
parents: 19681
diff changeset
457 # Linker script is in the config directory, not in Modules as the
ba9aabcd89e3 [Bug #404274] Restore some special-case code for AIX and BeOS under 1.5.2.
Andrew M. Kuchling <amk@amk.ca>
parents: 19681
diff changeset
458 # Makefile says.
ba9aabcd89e3 [Bug #404274] Restore some special-case code for AIX and BeOS under 1.5.2.
Andrew M. Kuchling <amk@amk.ca>
parents: 19681
diff changeset
459 python_lib = get_python_lib(standard_lib=1)
ba9aabcd89e3 [Bug #404274] Restore some special-case code for AIX and BeOS under 1.5.2.
Andrew M. Kuchling <amk@amk.ca>
parents: 19681
diff changeset
460 ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
ba9aabcd89e3 [Bug #404274] Restore some special-case code for AIX and BeOS under 1.5.2.
Andrew M. Kuchling <amk@amk.ca>
parents: 19681
diff changeset
461 python_exp = os.path.join(python_lib, 'config', 'python.exp')
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
462
19724
ba9aabcd89e3 [Bug #404274] Restore some special-case code for AIX and BeOS under 1.5.2.
Andrew M. Kuchling <amk@amk.ca>
parents: 19681
diff changeset
463 g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp)
ba9aabcd89e3 [Bug #404274] Restore some special-case code for AIX and BeOS under 1.5.2.
Andrew M. Kuchling <amk@amk.ca>
parents: 19681
diff changeset
464
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
465 global _config_vars
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
466 _config_vars = g
14321
ada4ec4cffd5 Rene Liebscher: hack '_init_posix()' to handle the BeOS linker script.
Greg Ward <gward@python.net>
parents: 13811
diff changeset
467
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
468
10926
f9c03b3d0f14 Now handles NT, through '_init_nt()' function (courtesy of
Greg Ward <gward@python.net>
parents: 9842
diff changeset
469 def _init_nt():
f9c03b3d0f14 Now handles NT, through '_init_nt()' function (courtesy of
Greg Ward <gward@python.net>
parents: 9842
diff changeset
470 """Initialize the module as appropriate for NT"""
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
471 g = {}
10926
f9c03b3d0f14 Now handles NT, through '_init_nt()' function (courtesy of
Greg Ward <gward@python.net>
parents: 9842
diff changeset
472 # set basic install directories
11953
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
473 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
474 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
10926
f9c03b3d0f14 Now handles NT, through '_init_nt()' function (courtesy of
Greg Ward <gward@python.net>
parents: 9842
diff changeset
475
11251
2f07bc56e97e Patch from Perry Stoll: tweaks to Windows support.
Greg Ward <gward@python.net>
parents: 10926
diff changeset
476 # XXX hmmm.. a normal install puts include files here
11953
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
477 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
11251
2f07bc56e97e Patch from Perry Stoll: tweaks to Windows support.
Greg Ward <gward@python.net>
parents: 10926
diff changeset
478
11721
eb381ff17a31 get_config_h_filename(): Support NT as well as Posix systems.
Fred Drake <fdrake@acm.org>
parents: 11689
diff changeset
479 g['SO'] = '.pyd'
13804
c77f8873da84 Rene Liebscher: deleted unneeded hard-coded assignments of CC, RANLIB, etc.
Greg Ward <gward@python.net>
parents: 13035
diff changeset
480 g['EXE'] = ".exe"
44226
aad65a2424e3 Merged revisions 59376-59406 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43026
diff changeset
481 g['VERSION'] = get_python_version().replace(".", "")
63136
29a3eda89995 reverted distutils its 3.1 state. All new work is now happening in disutils2, and distutils is now feature-frozen.
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 58652
diff changeset
482 g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
11935
c94572a50995 Patch from Corran Webster <cwebster@nevada.edu>: add '_init_mac()'.
Greg Ward <gward@python.net>
parents: 11721
diff changeset
483
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
484 global _config_vars
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
485 _config_vars = g
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
486
11721
eb381ff17a31 get_config_h_filename(): Support NT as well as Posix systems.
Fred Drake <fdrake@acm.org>
parents: 11689
diff changeset
487
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
488 def get_config_vars(*args):
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
489 """With no arguments, return a dictionary of all configuration
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
490 variables relevant for the current platform. Generally this includes
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
491 everything needed to build extensions and install both pure modules and
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
492 extensions. On Unix, this means every variable defined in Python's
78216
d76b83803e7e Issue #15184: Ensure consistent results of OS X configuration
Ned Deily <nad@acm.org>
parents: 78135
diff changeset
493 installed Makefile; on Windows it's a much smaller set.
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
494
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
495 With arguments, return a list of values that result from looking up
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
496 each argument in the configuration variable dictionary.
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
497 """
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
498 global _config_vars
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
499 if _config_vars is None:
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
500 func = globals().get("_init_" + os.name)
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
501 if func:
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
502 func()
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
503 else:
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
504 _config_vars = {}
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
505
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
506 # Normalized versions of prefix and exec_prefix are handy to have;
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
507 # in fact, these are the standard versions used most places in the
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
508 # Distutils.
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
509 _config_vars['prefix'] = PREFIX
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
510 _config_vars['exec_prefix'] = EXEC_PREFIX
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
511
78295
d2f448dbc30d Issue #15364: Fix sysconfig.get_config_var('srcdir') to be an absolute path.
Richard Oudkerk <shibturn@gmail.com>
parents: 78216
diff changeset
512 # Always convert srcdir to an absolute path
d2f448dbc30d Issue #15364: Fix sysconfig.get_config_var('srcdir') to be an absolute path.
Richard Oudkerk <shibturn@gmail.com>
parents: 78216
diff changeset
513 srcdir = _config_vars.get('srcdir', project_base)
d2f448dbc30d Issue #15364: Fix sysconfig.get_config_var('srcdir') to be an absolute path.
Richard Oudkerk <shibturn@gmail.com>
parents: 78216
diff changeset
514 if os.name == 'posix':
d2f448dbc30d Issue #15364: Fix sysconfig.get_config_var('srcdir') to be an absolute path.
Richard Oudkerk <shibturn@gmail.com>
parents: 78216
diff changeset
515 if python_build:
d2f448dbc30d Issue #15364: Fix sysconfig.get_config_var('srcdir') to be an absolute path.
Richard Oudkerk <shibturn@gmail.com>
parents: 78216
diff changeset
516 # If srcdir is a relative path (typically '.' or '..')
d2f448dbc30d Issue #15364: Fix sysconfig.get_config_var('srcdir') to be an absolute path.
Richard Oudkerk <shibturn@gmail.com>
parents: 78216
diff changeset
517 # then it should be interpreted relative to the directory
d2f448dbc30d Issue #15364: Fix sysconfig.get_config_var('srcdir') to be an absolute path.
Richard Oudkerk <shibturn@gmail.com>
parents: 78216
diff changeset
518 # containing Makefile.
d2f448dbc30d Issue #15364: Fix sysconfig.get_config_var('srcdir') to be an absolute path.
Richard Oudkerk <shibturn@gmail.com>
parents: 78216
diff changeset
519 base = os.path.dirname(get_makefile_filename())
d2f448dbc30d Issue #15364: Fix sysconfig.get_config_var('srcdir') to be an absolute path.
Richard Oudkerk <shibturn@gmail.com>
parents: 78216
diff changeset
520 srcdir = os.path.join(base, srcdir)
d2f448dbc30d Issue #15364: Fix sysconfig.get_config_var('srcdir') to be an absolute path.
Richard Oudkerk <shibturn@gmail.com>
parents: 78216
diff changeset
521 else:
d2f448dbc30d Issue #15364: Fix sysconfig.get_config_var('srcdir') to be an absolute path.
Richard Oudkerk <shibturn@gmail.com>
parents: 78216
diff changeset
522 # srcdir is not meaningful since the installation is
d2f448dbc30d Issue #15364: Fix sysconfig.get_config_var('srcdir') to be an absolute path.
Richard Oudkerk <shibturn@gmail.com>
parents: 78216
diff changeset
523 # spread about the filesystem. We choose the
d2f448dbc30d Issue #15364: Fix sysconfig.get_config_var('srcdir') to be an absolute path.
Richard Oudkerk <shibturn@gmail.com>
parents: 78216
diff changeset
524 # directory containing the Makefile since we know it
d2f448dbc30d Issue #15364: Fix sysconfig.get_config_var('srcdir') to be an absolute path.
Richard Oudkerk <shibturn@gmail.com>
parents: 78216
diff changeset
525 # exists.
d2f448dbc30d Issue #15364: Fix sysconfig.get_config_var('srcdir') to be an absolute path.
Richard Oudkerk <shibturn@gmail.com>
parents: 78216
diff changeset
526 srcdir = os.path.dirname(get_makefile_filename())
d2f448dbc30d Issue #15364: Fix sysconfig.get_config_var('srcdir') to be an absolute path.
Richard Oudkerk <shibturn@gmail.com>
parents: 78216
diff changeset
527 _config_vars['srcdir'] = os.path.abspath(os.path.normpath(srcdir))
d2f448dbc30d Issue #15364: Fix sysconfig.get_config_var('srcdir') to be an absolute path.
Richard Oudkerk <shibturn@gmail.com>
parents: 78216
diff changeset
528
51406
2a40d981c652 Make test_build_ext.py use sysconfig "srcdir" to find the source for
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51376
diff changeset
529 # Convert srcdir into an absolute path if it appears necessary.
2a40d981c652 Make test_build_ext.py use sysconfig "srcdir" to find the source for
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51376
diff changeset
530 # Normally it is relative to the build directory. However, during
2a40d981c652 Make test_build_ext.py use sysconfig "srcdir" to find the source for
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51376
diff changeset
531 # testing, for example, we might be running a non-installed python
2a40d981c652 Make test_build_ext.py use sysconfig "srcdir" to find the source for
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51376
diff changeset
532 # from a different directory.
2a40d981c652 Make test_build_ext.py use sysconfig "srcdir" to find the source for
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51376
diff changeset
533 if python_build and os.name == "posix":
2a40d981c652 Make test_build_ext.py use sysconfig "srcdir" to find the source for
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51376
diff changeset
534 base = os.path.dirname(os.path.abspath(sys.executable))
2a40d981c652 Make test_build_ext.py use sysconfig "srcdir" to find the source for
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51376
diff changeset
535 if (not os.path.isabs(_config_vars['srcdir']) and
2a40d981c652 Make test_build_ext.py use sysconfig "srcdir" to find the source for
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51376
diff changeset
536 base != os.getcwd()):
2a40d981c652 Make test_build_ext.py use sysconfig "srcdir" to find the source for
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51376
diff changeset
537 # srcdir is relative and we are not in the same directory
2a40d981c652 Make test_build_ext.py use sysconfig "srcdir" to find the source for
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51376
diff changeset
538 # as the executable. Assume executable is in the build
2a40d981c652 Make test_build_ext.py use sysconfig "srcdir" to find the source for
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51376
diff changeset
539 # directory and make srcdir absolute.
2a40d981c652 Make test_build_ext.py use sysconfig "srcdir" to find the source for
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51376
diff changeset
540 srcdir = os.path.join(base, _config_vars['srcdir'])
2a40d981c652 Make test_build_ext.py use sysconfig "srcdir" to find the source for
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51376
diff changeset
541 _config_vars['srcdir'] = os.path.normpath(srcdir)
2a40d981c652 Make test_build_ext.py use sysconfig "srcdir" to find the source for
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51376
diff changeset
542
78216
d76b83803e7e Issue #15184: Ensure consistent results of OS X configuration
Ned Deily <nad@acm.org>
parents: 78135
diff changeset
543 # OS X platforms require special customization to handle
d76b83803e7e Issue #15184: Ensure consistent results of OS X configuration
Ned Deily <nad@acm.org>
parents: 78135
diff changeset
544 # multi-architecture, multi-os-version installers
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
545 if sys.platform == 'darwin':
78216
d76b83803e7e Issue #15184: Ensure consistent results of OS X configuration
Ned Deily <nad@acm.org>
parents: 78135
diff changeset
546 import _osx_support
d76b83803e7e Issue #15184: Ensure consistent results of OS X configuration
Ned Deily <nad@acm.org>
parents: 78135
diff changeset
547 _osx_support.customize_config_vars(_config_vars)
78126
6a1e983647bd Issue #13590: Improve support for OS X Xcode 4:
Ned Deily <nad@acm.org>
parents: 77661
diff changeset
548
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
549 if args:
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
550 vals = []
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
551 for name in args:
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
552 vals.append(_config_vars.get(name))
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
553 return vals
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
554 else:
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
555 return _config_vars
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
556
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
557 def get_config_var(name):
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
558 """Return the value of a single variable using the dictionary
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
559 returned by 'get_config_vars()'. Equivalent to
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
560 get_config_vars().get(name)
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
561 """
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
562 return get_config_vars().get(name)