annotate Lib/distutils/sysconfig.py @ 78069:a8aa77458e12 3.2

Add c_size_t and c_ssize_t to the ctypes summary table.
author Antoine Pitrou <solipsis@pitrou.net>
date Thu, 12 Jul 2012 20:31:50 +0200
parents 5c784b0f263d
children 502b139b3b19 294f8aeb4d4b
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)
11689
09dbb47034e0 Comment fix.
Greg Ward <gward@python.net>
parents: 11251
diff changeset
21
44226
aad65a2424e3 Merged revisions 59376-59406 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43026
diff changeset
22 # 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
23 # 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
24 # 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
25 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
26 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
27 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
28 # PC/VS7.1
eee1b76a94e0 Merged revisions 59628-59641 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44310
diff changeset
29 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
30 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
31 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
32 # 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
33 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
34 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
35 os.path.pardir))
44226
aad65a2424e3 Merged revisions 59376-59406 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43026
diff changeset
36
23659
5c5fff5de250 When using a Python that has not been installed to build 3rd-party
Fred Drake <fdrake@acm.org>
parents: 21851
diff changeset
37 # 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
38 # 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
39 # different (hard-wired) directories.
44310
e70acbf26cda Merged revisions 59488-59511 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44291
diff changeset
40 # 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
41 # Setup.dist is available on Windows
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
42 def _python_build():
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
43 for fn in ("Setup.dist", "Setup.local"):
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
44 if os.path.isfile(os.path.join(project_base, "Modules", fn)):
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 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
46 return False
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 python_build = _python_build()
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
48
66429
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
49 # 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
50 # 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
51 # an in-source build.
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
52 build_flags = ''
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
53 try:
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
54 if not python_build:
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
55 build_flags = sys.abiflags
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
56 except AttributeError:
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
57 # 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
58 # this attribute, which is fine.
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
59 pass
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
60
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
61 def get_python_version():
26205
d33005f8388e [Bug #550364] Add get_python_version()
Andrew M. Kuchling <amk@amk.ca>
parents: 26186
diff changeset
62 """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
63 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
64 or '2.2'.
d33005f8388e [Bug #550364] Add get_python_version()
Andrew M. Kuchling <amk@amk.ca>
parents: 26186
diff changeset
65 """
d33005f8388e [Bug #550364] Add get_python_version()
Andrew M. Kuchling <amk@amk.ca>
parents: 26186
diff changeset
66 return sys.version[:3]
d33005f8388e [Bug #550364] Add get_python_version()
Andrew M. Kuchling <amk@amk.ca>
parents: 26186
diff changeset
67
d33005f8388e [Bug #550364] Add get_python_version()
Andrew M. Kuchling <amk@amk.ca>
parents: 26186
diff changeset
68
12316
540f10881a59 Added optional 'prefix' arguments to 'get_python_inc()' and
Greg Ward <gward@python.net>
parents: 12315
diff changeset
69 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
70 """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
71
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
72 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
73 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
74 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
75 (namely pyconfig.h).
11953
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
76
12316
540f10881a59 Added optional 'prefix' arguments to 'get_python_inc()' and
Greg Ward <gward@python.net>
parents: 12315
diff changeset
77 If 'prefix' is supplied, use it instead of sys.prefix or
540f10881a59 Added optional 'prefix' arguments to 'get_python_inc()' and
Greg Ward <gward@python.net>
parents: 12315
diff changeset
78 sys.exec_prefix -- i.e., ignore 'plat_specific'.
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19724
diff changeset
79 """
12316
540f10881a59 Added optional 'prefix' arguments to 'get_python_inc()' and
Greg Ward <gward@python.net>
parents: 12315
diff changeset
80 if prefix is None:
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
81 prefix = plat_specific and EXEC_PREFIX or 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
82 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
83 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
84 # 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
85 # 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
86 # 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
87 # 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
88 # directory.
64850
3a4afaa96ac3 Reverted changes which were inadvertently committed.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 64849
diff changeset
89 base = 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
90 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
91 return base
23659
5c5fff5de250 When using a Python that has not been installed to build 3rd-party
Fred Drake <fdrake@acm.org>
parents: 21851
diff changeset
92 else:
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
93 incdir = os.path.join(get_config_var('srcdir'), '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
94 return os.path.normpath(incdir)
66429
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
95 python_dir = 'python' + get_python_version() + build_flags
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
96 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
97 elif os.name == "nt":
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
98 return os.path.join(prefix, "include")
21851
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
99 elif os.name == "os2":
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
100 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
101 else:
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
102 raise DistutilsPlatformError(
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
103 "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
104 "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
105
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
106
12316
540f10881a59 Added optional 'prefix' arguments to 'get_python_inc()' and
Greg Ward <gward@python.net>
parents: 12315
diff changeset
107 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
108 """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
109 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
110
11953
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
111 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
112 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
113 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
114 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
115 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
116 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
117
12316
540f10881a59 Added optional 'prefix' arguments to 'get_python_inc()' and
Greg Ward <gward@python.net>
parents: 12315
diff changeset
118 If 'prefix' is supplied, use it instead of sys.prefix or
540f10881a59 Added optional 'prefix' arguments to 'get_python_inc()' and
Greg Ward <gward@python.net>
parents: 12315
diff changeset
119 sys.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
120 """
12316
540f10881a59 Added optional 'prefix' arguments to 'get_python_inc()' and
Greg Ward <gward@python.net>
parents: 12315
diff changeset
121 if prefix is None:
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
122 prefix = plat_specific and EXEC_PREFIX or PREFIX
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
123
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
124 if os.name == "posix":
12315
f1f665e075ca Better variable names here and there.
Greg Ward <gward@python.net>
parents: 11953
diff changeset
125 libpython = os.path.join(prefix,
26205
d33005f8388e [Bug #550364] Add get_python_version()
Andrew M. Kuchling <amk@amk.ca>
parents: 26186
diff changeset
126 "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
127 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
128 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
129 else:
11953
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
130 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
131 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
132 if standard_lib:
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
133 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
134 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
135 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
136 return prefix
7fb5f15685dd Patch #449054 to implement PEP 250. The standard install directory for
Greg Ward <gward@python.net>
parents: 18945
diff changeset
137 else:
51506
8a28d99f784d Merged revisions 69485 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51406
diff changeset
138 return os.path.join(prefix, "Lib", "site-packages")
21851
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
139 elif os.name == "os2":
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
140 if standard_lib:
51506
8a28d99f784d Merged revisions 69485 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51406
diff changeset
141 return os.path.join(prefix, "Lib")
21851
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
142 else:
51506
8a28d99f784d Merged revisions 69485 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51406
diff changeset
143 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
144 else:
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
145 raise DistutilsPlatformError(
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
146 "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
147 "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
148
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
149 _USE_CLANG = 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
150
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
151 def customize_compiler(compiler):
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
152 """Do any platform-specific customization of a CCompiler instance.
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
153
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
154 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
155 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
156 """
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
157 if compiler.compiler_type == "unix":
53889
198b68ae2c2d Merged revisions 72445 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51506
diff changeset
158 (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
159 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
160 '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
161
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
162 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
163 if 'CC' in os.environ:
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
164 newcc = os.environ['CC']
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
165 elif sys.platform == 'darwin' and cc == 'gcc-4.2':
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
166 # Issue #13590:
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
167 # Since Apple removed gcc-4.2 in Xcode 4.2, we can no
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
168 # longer assume it is available for extension module builds.
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
169 # If Python was built with gcc-4.2, check first to see if
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
170 # it is available on this system; if not, try to use clang
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
171 # instead unless the caller explicitly set CC.
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
172 global _USE_CLANG
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
173 if _USE_CLANG is None:
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
174 from distutils import log
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
175 from subprocess import Popen, PIPE
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
176 p = Popen("! type gcc-4.2 && type clang && exit 2",
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
177 shell=True, stdout=PIPE, stderr=PIPE)
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
178 p.wait()
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
179 if p.returncode == 2:
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
180 _USE_CLANG = True
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
181 log.warn("gcc-4.2 not found, using clang instead")
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
182 else:
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
183 _USE_CLANG = False
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
184 if _USE_CLANG:
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
185 newcc = 'clang'
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
186 if newcc:
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 # On OS X, if CC is overridden, use that as the default
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
188 # command for LDSHARED as well
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
189 if (sys.platform == 'darwin'
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
190 and 'LDSHARED' not in os.environ
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
191 and ldshared.startswith(cc)):
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
192 ldshared = newcc + ldshared[len(cc):]
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
193 cc = newcc
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 'CXX' in os.environ:
26036
771b6f521b95 This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 26020
diff changeset
195 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
196 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
197 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
198 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
199 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
200 else:
8e3246842773 [Patch #588809] LDFLAGS support for build_ext.py, from Robert Weber
Andrew M. Kuchling <amk@amk.ca>
parents: 24211
diff changeset
201 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
202 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
203 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
204 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
205 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
206 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
207 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
208 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
209 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
210 ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
51376
207097691972 Merged revisions 69342 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51347
diff changeset
211 if 'AR' in os.environ:
207097691972 Merged revisions 69342 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51347
diff changeset
212 ar = os.environ['AR']
53889
198b68ae2c2d Merged revisions 72445 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51506
diff changeset
213 if 'ARFLAGS' in os.environ:
198b68ae2c2d Merged revisions 72445 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51506
diff changeset
214 archiver = ar + ' ' + os.environ['ARFLAGS']
198b68ae2c2d Merged revisions 72445 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51506
diff changeset
215 else:
198b68ae2c2d Merged revisions 72445 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51506
diff changeset
216 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
217
34930
294dabcb379b Make parse_makefile fallback to environment variables if nothing is
Martin v. Löwis <martin@v.loewis.de>
parents: 34929
diff changeset
218 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
219 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
220 preprocessor=cpp,
13009
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
221 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
222 compiler_so=cc_cmd + ' ' + ccshared,
26036
771b6f521b95 This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 26020
diff changeset
223 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
224 linker_so=ldshared,
51376
207097691972 Merged revisions 69342 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51347
diff changeset
225 linker_exe=cc,
53889
198b68ae2c2d Merged revisions 72445 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51506
diff changeset
226 archiver=archiver)
13009
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
227
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
228 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
229
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
230
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
231 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
232 """Return full pathname of installed pyconfig.h file."""
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
233 if python_build:
44226
aad65a2424e3 Merged revisions 59376-59406 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43026
diff changeset
234 if os.name == "nt":
aad65a2424e3 Merged revisions 59376-59406 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43026
diff changeset
235 inc_dir = os.path.join(project_base, "PC")
aad65a2424e3 Merged revisions 59376-59406 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43026
diff changeset
236 else:
aad65a2424e3 Merged revisions 59376-59406 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43026
diff changeset
237 inc_dir = project_base
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
238 else:
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
239 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
240 if get_python_version() < '2.2':
18837
5e0a40ccb9da Add backwards compatibility.
Marc-André Lemburg <mal@egenix.com>
parents: 18835
diff changeset
241 config_h = 'config.h'
5e0a40ccb9da Add backwards compatibility.
Marc-André Lemburg <mal@egenix.com>
parents: 18835
diff changeset
242 else:
5e0a40ccb9da Add backwards compatibility.
Marc-André Lemburg <mal@egenix.com>
parents: 18835
diff changeset
243 # 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
244 config_h = 'pyconfig.h'
5e0a40ccb9da Add backwards compatibility.
Marc-André Lemburg <mal@egenix.com>
parents: 18835
diff changeset
245 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
246
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
247
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
248 def get_makefile_filename():
9783
be24b5b90dec Update and add docstrings.
Fred Drake <fdrake@acm.org>
parents: 9780
diff changeset
249 """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
250 if python_build:
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
251 return os.path.join(os.path.dirname(sys.executable), "Makefile")
72820
9afd3d54c3cb Fix distutils.sysconfig.get_makefile_filename when prefix != exec-prefix
Éric Araujo <merwok@netwok.org>
parents: 71540
diff changeset
252 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
253 config_file = 'config-{}{}'.format(get_python_version(), build_flags)
a763ed3d6e8c Final patch for issue 9807.
Barry Warsaw <barry@python.org>
parents: 66018
diff changeset
254 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
255
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
256
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
257 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
258 """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
259
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
260 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
261 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
262 used instead of a new dictionary.
9783
be24b5b90dec Update and add docstrings.
Fred Drake <fdrake@acm.org>
parents: 9780
diff changeset
263 """
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
264 if g is None:
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
265 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
266 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
267 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
268 #
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42645
diff changeset
269 while True:
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
270 line = fp.readline()
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
271 if not line:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
272 break
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
273 m = define_rx.match(line)
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
274 if m:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
275 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
276 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
277 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
278 g[n] = v
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
279 else:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
280 m = undef_rx.match(line)
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
281 if m:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
282 g[m.group(1)] = 0
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
283 return g
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
284
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
285
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
286 # 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
287 # 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
288 _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
289 _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
290 _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
291
14571
600515747c51 Fixed so 'parse_makefile()' uses the TextFile class to ensure that
Greg Ward <gward@python.net>
parents: 14321
diff changeset
292 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
293 """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
294
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
295 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
296 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
297 used instead of a new dictionary.
9783
be24b5b90dec Update and add docstrings.
Fred Drake <fdrake@acm.org>
parents: 9780
diff changeset
298 """
14571
600515747c51 Fixed so 'parse_makefile()' uses the TextFile class to ensure that
Greg Ward <gward@python.net>
parents: 14321
diff changeset
299 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
300 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
301
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
302 if g is None:
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
303 g = {}
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
304 done = {}
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
305 notdone = {}
14571
600515747c51 Fixed so 'parse_makefile()' uses the TextFile class to ensure that
Greg Ward <gward@python.net>
parents: 14321
diff changeset
306
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42645
diff changeset
307 while True:
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
308 line = fp.readline()
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42645
diff changeset
309 if line is None: # eof
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
310 break
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
311 m = _variable_rx.match(line)
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
312 if m:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
313 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
314 v = v.strip()
54670
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
315 # `$$' is a literal `$' in make
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
316 tmpv = v.replace('$$', '')
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
317
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
318 if "$" in tmpv:
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
319 notdone[n] = v
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
320 else:
54670
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
321 try:
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
322 v = int(v)
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
323 except ValueError:
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
324 # insert literal `$'
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
325 done[n] = v.replace('$$', '$')
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
326 else:
8b3ae3a38250 Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53889
diff changeset
327 done[n] = v
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
328
63140
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
329 # 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
330 # be made available without that prefix through sysconfig.
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
331 # 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
332 # 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
333 renamed_variables = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS')
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
334
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
335 # do variable interpolation here
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
336 while notdone:
40809
f340cb045bf9 - PEP 3106: dict.iterkeys(), .iteritems(), .itervalues() are now gone;
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
337 for name in list(notdone):
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
338 value = notdone[name]
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
339 m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
340 if m:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
341 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
342 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
343 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
344 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
345 elif n in notdone:
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
346 # 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
347 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
348 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
349 # 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
350 item = os.environ[n]
63140
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
351
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
352 elif n in renamed_variables:
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
353 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
354 item = ""
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 elif 'PY_' + n in notdone:
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
357 found = False
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
358
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
359 else:
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
360 item = str(done['PY_' + n])
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
361 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
362 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
363 if found:
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
364 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
365 value = value[:m.start()] + item + after
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
366 if "$" in after:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
367 notdone[name] = value
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
368 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
369 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
370 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
371 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
372 else:
ff6c30e8ca73 Fix bugs with integer-valued variables when parsing Makefiles. Values
Andrew M. Kuchling <amk@amk.ca>
parents: 15818
diff changeset
373 done[name] = value
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
374 del notdone[name]
63140
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 if name.startswith('PY_') \
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
377 and name[3:] in renamed_variables:
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
378
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
379 name = name[3:]
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
380 if name not in done:
16edd4fba6a5 Ensure that the Makefile variable expansion
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 63136
diff changeset
381 done[name] = value
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
382 else:
9690
31489799c8c6 Applied Fred's patch to fix the bugs that John Skaller noticed.
Greg Ward <gward@python.net>
parents: 9658
diff changeset
383 # 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
384 del notdone[name]
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
385
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
386 fp.close()
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
387
65206
25d078739c2a Issue #9437: Fix building C extensions with non-default LDFLAGS.
Antoine Pitrou <solipsis@pitrou.net>
parents: 64850
diff changeset
388 # strip spurious spaces
25d078739c2a Issue #9437: Fix building C extensions with non-default LDFLAGS.
Antoine Pitrou <solipsis@pitrou.net>
parents: 64850
diff changeset
389 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
390 if isinstance(v, str):
25d078739c2a Issue #9437: Fix building C extensions with non-default LDFLAGS.
Antoine Pitrou <solipsis@pitrou.net>
parents: 64850
diff changeset
391 done[k] = v.strip()
25d078739c2a Issue #9437: Fix building C extensions with non-default LDFLAGS.
Antoine Pitrou <solipsis@pitrou.net>
parents: 64850
diff changeset
392
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
393 # save the results in the global dictionary
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
394 g.update(done)
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
395 return g
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
396
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
397
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
398 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
399 """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
400 '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
401 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
402 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
403 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
404 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
405 """
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
406
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
407 # 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
408 # "${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
409 # ${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
410 # '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
411 # 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
412
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42645
diff changeset
413 while True:
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
414 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
415 if m:
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
416 (beg, end) = m.span()
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
417 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
418 else:
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
419 break
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
420 return s
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
421
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
422
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
423 _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
424
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
425 def _init_posix():
9783
be24b5b90dec Update and add docstrings.
Fred Drake <fdrake@acm.org>
parents: 9780
diff changeset
426 """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
427 g = {}
11689
09dbb47034e0 Comment fix.
Greg Ward <gward@python.net>
parents: 11251
diff changeset
428 # 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
429 try:
89f42099c5dd Catch failure to open installed Makefile, and report it as a
Greg Ward <gward@python.net>
parents: 12414
diff changeset
430 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
431 parse_makefile(filename, g)
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
432 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
433 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
434 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
435 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
436
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
437 raise DistutilsPlatformError(my_msg)
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
438
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
439 # 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
440 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
441 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
442 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
443 parse_config_h(file, g)
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
444 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
445 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
446 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
447 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
448
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36988
diff changeset
449 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
450
13034
f1e40abbedb3 Fixed LDSHARED for AIX, based on a patch by Rene Liebscher.
Greg Ward <gward@python.net>
parents: 13009
diff changeset
451 # 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
452 # -- 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
453 # 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
454 if python_build:
16841
3d29690a24e8 Placate tabnanny
Andrew M. Kuchling <amk@amk.ca>
parents: 16621
diff changeset
455 g['LDSHARED'] = g['BLDSHARED']
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19724
diff changeset
456
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
457 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
458 # 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
459 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
460 # 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
461 # 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
462 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
463 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
464 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
465
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
466 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
467
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
468 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
469 _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
470
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
471
10926
f9c03b3d0f14 Now handles NT, through '_init_nt()' function (courtesy of
Greg Ward <gward@python.net>
parents: 9842
diff changeset
472 def _init_nt():
f9c03b3d0f14 Now handles NT, through '_init_nt()' function (courtesy of
Greg Ward <gward@python.net>
parents: 9842
diff changeset
473 """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
474 g = {}
10926
f9c03b3d0f14 Now handles NT, through '_init_nt()' function (courtesy of
Greg Ward <gward@python.net>
parents: 9842
diff changeset
475 # 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
476 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
477 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
478
11251
2f07bc56e97e Patch from Perry Stoll: tweaks to Windows support.
Greg Ward <gward@python.net>
parents: 10926
diff changeset
479 # 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
480 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
481
11721
eb381ff17a31 get_config_h_filename(): Support NT as well as Posix systems.
Fred Drake <fdrake@acm.org>
parents: 11689
diff changeset
482 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
483 g['EXE'] = ".exe"
44226
aad65a2424e3 Merged revisions 59376-59406 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43026
diff changeset
484 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
485 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
486
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
487 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
488 _config_vars = g
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
489
11721
eb381ff17a31 get_config_h_filename(): Support NT as well as Posix systems.
Fred Drake <fdrake@acm.org>
parents: 11689
diff changeset
490
21851
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
491 def _init_os2():
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
492 """Initialize the module as appropriate for OS/2"""
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
493 g = {}
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
494 # set basic install directories
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
495 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
496 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
497
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
498 # XXX hmmm.. a normal install puts include files here
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
499 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
500
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
501 g['SO'] = '.pyd'
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
502 g['EXE'] = ".exe"
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
503
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
504 global _config_vars
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
505 _config_vars = g
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
506
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
507
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
508 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
509 """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
510 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
511 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
512 extensions. On Unix, this means every variable defined in Python's
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
513 installed Makefile; on Windows and Mac OS it's a much smaller set.
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
514
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
515 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
516 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
517 """
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
518 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
519 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
520 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
521 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
522 func()
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
523 else:
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
524 _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
525
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
526 # 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
527 # 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
528 # Distutils.
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
529 _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
530 _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
531
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
532 # 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
533 # 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
534 # 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
535 # 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
536 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
537 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
538 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
539 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
540 # 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
541 # 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
542 # 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
543 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
544 _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
545
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
546 if sys.platform == 'darwin':
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
547 kernel_version = os.uname()[2] # Kernel version (8.4.3)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
548 major_version = int(kernel_version.split('.')[0])
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
549
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
550 if major_version < 8:
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
551 # On Mac OS X before 10.4, check if -arch and -isysroot
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
552 # are in CFLAGS or LDFLAGS and remove them if they are.
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
553 # This is needed when building extensions on a 10.3 system
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
554 # using a universal build of python.
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39647
diff changeset
555 for key in ('LDFLAGS', 'BASECFLAGS',
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39647
diff changeset
556 # a number of derived variables. These need to be
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39647
diff changeset
557 # patched up as well.
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39647
diff changeset
558 'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
559 flags = _config_vars[key]
48769
83b2d07b475b #2834: Change re module semantics, so that str and bytes mixing is forbidden,
Antoine Pitrou <solipsis@pitrou.net>
parents: 48485
diff changeset
560 flags = re.sub('-arch\s+\w+\s', ' ', flags, re.ASCII)
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
561 flags = re.sub('-isysroot [^ \t]*', ' ', flags)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
562 _config_vars[key] = flags
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
563
48485
bd4841069c68 Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45931
diff changeset
564 else:
bd4841069c68 Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45931
diff changeset
565
bd4841069c68 Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45931
diff changeset
566 # Allow the user to override the architecture flags using
bd4841069c68 Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45931
diff changeset
567 # an environment variable.
bd4841069c68 Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45931
diff changeset
568 # NOTE: This name was introduced by Apple in OSX 10.5 and
bd4841069c68 Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45931
diff changeset
569 # is used by several scripting languages distributed with
bd4841069c68 Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45931
diff changeset
570 # that OS release.
bd4841069c68 Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45931
diff changeset
571
bd4841069c68 Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45931
diff changeset
572 if 'ARCHFLAGS' in os.environ:
bd4841069c68 Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45931
diff changeset
573 arch = os.environ['ARCHFLAGS']
bd4841069c68 Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45931
diff changeset
574 for key in ('LDFLAGS', 'BASECFLAGS',
bd4841069c68 Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45931
diff changeset
575 # a number of derived variables. These need to be
bd4841069c68 Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45931
diff changeset
576 # patched up as well.
bd4841069c68 Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45931
diff changeset
577 'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
bd4841069c68 Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45931
diff changeset
578
bd4841069c68 Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45931
diff changeset
579 flags = _config_vars[key]
bd4841069c68 Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45931
diff changeset
580 flags = re.sub('-arch\s+\w+\s', ' ', flags)
bd4841069c68 Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45931
diff changeset
581 flags = flags + ' ' + arch
bd4841069c68 Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45931
diff changeset
582 _config_vars[key] = flags
bd4841069c68 Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45931
diff changeset
583
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
584 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
585 vals = []
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
586 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
587 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
588 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
589 else:
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
590 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
591
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
592 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
593 """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
594 returned by 'get_config_vars()'. Equivalent to
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
595 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
596 """
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
597 return get_config_vars().get(name)