annotate Lib/distutils/sysconfig.py @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents 6240ff5dfebe
children 1d061f83a6bf
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
12840
3912fb6c63f6 Added a bunch of new globals in '_init_mac()' -- these will be needed to
Greg Ward <gward@python.net>
parents: 12740
diff changeset
12 __revision__ = "$Id$"
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
13
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
14 import os
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
15 import re
26186
af3964679e2f Back out part of rev. 1.53, restoring the use of the string module.
Andrew M. Kuchling <amk@amk.ca>
parents: 26048
diff changeset
16 import string
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
17 import sys
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
18
37007
1ddf0d81d6c5 Instead of relative imports, use (implicitly) absolute ones.
Guido van Rossum <guido@python.org>
parents: 36987
diff changeset
19 from distutils.errors import DistutilsPlatformError
11953
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
20
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
21 # 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
22 PREFIX = os.path.normpath(sys.prefix)
f1f665e075ca Better variable names here and there.
Greg Ward <gward@python.net>
parents: 11953
diff changeset
23 EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
11689
09dbb47034e0 Comment fix.
Greg Ward <gward@python.net>
parents: 11251
diff changeset
24
44198
a53ef778590e Fixed get_config_h_filename for Windows. Without the patch it can't find the pyconfig.h file inside a build tree.
Christian Heimes <christian@cheimes.de>
parents: 40055
diff changeset
25 # Path to the base directory of the project. On Windows the binary may
45913
e0c9b9ef0466 Issue2290: Support x64 Windows builds that live in pcbuild/amd64. Without it, sysutils._python_build() returns the wrong directory, which causes the test_get_config_h_filename method in Lib/distutils/tests/test_sysconfig.py to fail.
Trent Nelson <trent.nelson@snakebite.org>
parents: 45413
diff changeset
26 # live in project/PCBuild9. If we're dealing with an x64 Windows build,
e0c9b9ef0466 Issue2290: Support x64 Windows builds that live in pcbuild/amd64. Without it, sysutils._python_build() returns the wrong directory, which causes the test_get_config_h_filename method in Lib/distutils/tests/test_sysconfig.py to fail.
Trent Nelson <trent.nelson@snakebite.org>
parents: 45413
diff changeset
27 # it'll live in project/PCbuild/amd64.
59343
ad22bc22dddc reverting partially distutils to its 2.6.x state so 2.7a4 looks more like the 2.7b1 in this. the whole revert will occur after a4 is tagged
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 58649
diff changeset
28 project_base = os.path.dirname(os.path.abspath(sys.executable))
44198
a53ef778590e Fixed get_config_h_filename for Windows. Without the patch it can't find the pyconfig.h file inside a build tree.
Christian Heimes <christian@cheimes.de>
parents: 40055
diff changeset
29 if os.name == "nt" and "pcbuild" in project_base[-8:].lower():
a53ef778590e Fixed get_config_h_filename for Windows. Without the patch it can't find the pyconfig.h file inside a build tree.
Christian Heimes <christian@cheimes.de>
parents: 40055
diff changeset
30 project_base = os.path.abspath(os.path.join(project_base, os.path.pardir))
44412
901f70db3b34 Added support for new Windows build dirs in PC/ to distutils.sysconfig
Christian Heimes <christian@cheimes.de>
parents: 44308
diff changeset
31 # PC/VS7.1
901f70db3b34 Added support for new Windows build dirs in PC/ to distutils.sysconfig
Christian Heimes <christian@cheimes.de>
parents: 44308
diff changeset
32 if os.name == "nt" and "\\pc\\v" in project_base[-10:].lower():
901f70db3b34 Added support for new Windows build dirs in PC/ to distutils.sysconfig
Christian Heimes <christian@cheimes.de>
parents: 44308
diff changeset
33 project_base = os.path.abspath(os.path.join(project_base, os.path.pardir,
901f70db3b34 Added support for new Windows build dirs in PC/ to distutils.sysconfig
Christian Heimes <christian@cheimes.de>
parents: 44308
diff changeset
34 os.path.pardir))
45913
e0c9b9ef0466 Issue2290: Support x64 Windows builds that live in pcbuild/amd64. Without it, sysutils._python_build() returns the wrong directory, which causes the test_get_config_h_filename method in Lib/distutils/tests/test_sysconfig.py to fail.
Trent Nelson <trent.nelson@snakebite.org>
parents: 45413
diff changeset
35 # PC/AMD64
e0c9b9ef0466 Issue2290: Support x64 Windows builds that live in pcbuild/amd64. Without it, sysutils._python_build() returns the wrong directory, which causes the test_get_config_h_filename method in Lib/distutils/tests/test_sysconfig.py to fail.
Trent Nelson <trent.nelson@snakebite.org>
parents: 45413
diff changeset
36 if os.name == "nt" and "\\pcbuild\\amd64" in project_base[-14:].lower():
e0c9b9ef0466 Issue2290: Support x64 Windows builds that live in pcbuild/amd64. Without it, sysutils._python_build() returns the wrong directory, which causes the test_get_config_h_filename method in Lib/distutils/tests/test_sysconfig.py to fail.
Trent Nelson <trent.nelson@snakebite.org>
parents: 45413
diff changeset
37 project_base = os.path.abspath(os.path.join(project_base, os.path.pardir,
e0c9b9ef0466 Issue2290: Support x64 Windows builds that live in pcbuild/amd64. Without it, sysutils._python_build() returns the wrong directory, which causes the test_get_config_h_filename method in Lib/distutils/tests/test_sysconfig.py to fail.
Trent Nelson <trent.nelson@snakebite.org>
parents: 45413
diff changeset
38 os.path.pardir))
44198
a53ef778590e Fixed get_config_h_filename for Windows. Without the patch it can't find the pyconfig.h file inside a build tree.
Christian Heimes <christian@cheimes.de>
parents: 40055
diff changeset
39
23659
5c5fff5de250 When using a Python that has not been installed to build 3rd-party
Fred Drake <fdrake@acm.org>
parents: 21851
diff changeset
40 # 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
41 # 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
42 # different (hard-wired) directories.
44308
06d122b4bffd Fixed bug #1628
Christian Heimes <christian@cheimes.de>
parents: 44285
diff changeset
43 # Setup.local is available for Makefile builds including VPATH builds,
06d122b4bffd Fixed bug #1628
Christian Heimes <christian@cheimes.de>
parents: 44285
diff changeset
44 # Setup.dist is available on Windows
45168
cfa280424b65 Keep distutils Python 2.1 compatible (or even Python 2.4 in this case).
Marc-André Lemburg <mal@egenix.com>
parents: 44412
diff changeset
45 def _python_build():
cfa280424b65 Keep distutils Python 2.1 compatible (or even Python 2.4 in this case).
Marc-André Lemburg <mal@egenix.com>
parents: 44412
diff changeset
46 for fn in ("Setup.dist", "Setup.local"):
cfa280424b65 Keep distutils Python 2.1 compatible (or even Python 2.4 in this case).
Marc-André Lemburg <mal@egenix.com>
parents: 44412
diff changeset
47 if os.path.isfile(os.path.join(project_base, "Modules", fn)):
cfa280424b65 Keep distutils Python 2.1 compatible (or even Python 2.4 in this case).
Marc-André Lemburg <mal@egenix.com>
parents: 44412
diff changeset
48 return True
cfa280424b65 Keep distutils Python 2.1 compatible (or even Python 2.4 in this case).
Marc-André Lemburg <mal@egenix.com>
parents: 44412
diff changeset
49 return False
cfa280424b65 Keep distutils Python 2.1 compatible (or even Python 2.4 in this case).
Marc-André Lemburg <mal@egenix.com>
parents: 44412
diff changeset
50 python_build = _python_build()
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
51
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
52
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
53 def get_python_version():
26205
d33005f8388e [Bug #550364] Add get_python_version()
Andrew M. Kuchling <amk@amk.ca>
parents: 26186
diff changeset
54 """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
55 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
56 or '2.2'.
d33005f8388e [Bug #550364] Add get_python_version()
Andrew M. Kuchling <amk@amk.ca>
parents: 26186
diff changeset
57 """
d33005f8388e [Bug #550364] Add get_python_version()
Andrew M. Kuchling <amk@amk.ca>
parents: 26186
diff changeset
58 return sys.version[:3]
d33005f8388e [Bug #550364] Add get_python_version()
Andrew M. Kuchling <amk@amk.ca>
parents: 26186
diff changeset
59
d33005f8388e [Bug #550364] Add get_python_version()
Andrew M. Kuchling <amk@amk.ca>
parents: 26186
diff changeset
60
12316
540f10881a59 Added optional 'prefix' arguments to 'get_python_inc()' and
Greg Ward <gward@python.net>
parents: 12315
diff changeset
61 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
62 """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
63
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
64 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
65 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
66 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
67 (namely pyconfig.h).
11953
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
68
12316
540f10881a59 Added optional 'prefix' arguments to 'get_python_inc()' and
Greg Ward <gward@python.net>
parents: 12315
diff changeset
69 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
70 sys.exec_prefix -- i.e., ignore 'plat_specific'.
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19724
diff changeset
71 """
12316
540f10881a59 Added optional 'prefix' arguments to 'get_python_inc()' and
Greg Ward <gward@python.net>
parents: 12315
diff changeset
72 if prefix is None:
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
73 prefix = plat_specific and EXEC_PREFIX or PREFIX
61116
621d2e984d18 Merged revisions 80649 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57637
diff changeset
74
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
75 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
76 if python_build:
61115
10206cb23c80 Fixed #8577. distutils.sysconfig.get_python_inc() now differenciates buildir and srcdir
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 59343
diff changeset
77 buildir = os.path.dirname(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
78 if plat_specific:
61116
621d2e984d18 Merged revisions 80649 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57637
diff changeset
79 # python.h is located in the buildir
621d2e984d18 Merged revisions 80649 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57637
diff changeset
80 inc_dir = buildir
23659
5c5fff5de250 When using a Python that has not been installed to build 3rd-party
Fred Drake <fdrake@acm.org>
parents: 21851
diff changeset
81 else:
61116
621d2e984d18 Merged revisions 80649 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57637
diff changeset
82 # the source dir is relative to the buildir
621d2e984d18 Merged revisions 80649 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57637
diff changeset
83 srcdir = os.path.abspath(os.path.join(buildir,
621d2e984d18 Merged revisions 80649 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57637
diff changeset
84 get_config_var('srcdir')))
621d2e984d18 Merged revisions 80649 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57637
diff changeset
85 # Include is located in the srcdir
621d2e984d18 Merged revisions 80649 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57637
diff changeset
86 inc_dir = os.path.join(srcdir, "Include")
23659
5c5fff5de250 When using a Python that has not been installed to build 3rd-party
Fred Drake <fdrake@acm.org>
parents: 21851
diff changeset
87 return inc_dir
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
88 return os.path.join(prefix, "include", "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
89 elif os.name == "nt":
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
90 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
91 elif os.name == "os2":
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
92 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
93 else:
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
94 raise DistutilsPlatformError(
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
95 "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
96 "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
97
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
98
12316
540f10881a59 Added optional 'prefix' arguments to 'get_python_inc()' and
Greg Ward <gward@python.net>
parents: 12315
diff changeset
99 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
100 """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
101 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
102
11953
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
103 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
104 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
105 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
106 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
107 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
108 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
109
12316
540f10881a59 Added optional 'prefix' arguments to 'get_python_inc()' and
Greg Ward <gward@python.net>
parents: 12315
diff changeset
110 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
111 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
112 """
12316
540f10881a59 Added optional 'prefix' arguments to 'get_python_inc()' and
Greg Ward <gward@python.net>
parents: 12315
diff changeset
113 if prefix is None:
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
114 prefix = plat_specific and EXEC_PREFIX or PREFIX
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
115
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
116 if os.name == "posix":
12315
f1f665e075ca Better variable names here and there.
Greg Ward <gward@python.net>
parents: 11953
diff changeset
117 libpython = os.path.join(prefix,
26205
d33005f8388e [Bug #550364] Add get_python_version()
Andrew M. Kuchling <amk@amk.ca>
parents: 26186
diff changeset
118 "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
119 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
120 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
121 else:
11953
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
122 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
123
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
124 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
125 if standard_lib:
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
126 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
127 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
128 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
129 return prefix
7fb5f15685dd Patch #449054 to implement PEP 250. The standard install directory for
Greg Ward <gward@python.net>
parents: 18945
diff changeset
130 else:
51505
1307a66a38f8 Merged revisions 69485 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 47473
diff changeset
131 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
132
21851
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
133 elif os.name == "os2":
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
134 if standard_lib:
51505
1307a66a38f8 Merged revisions 69485 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 47473
diff changeset
135 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
136 else:
51505
1307a66a38f8 Merged revisions 69485 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 47473
diff changeset
137 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
138
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
139 else:
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
140 raise DistutilsPlatformError(
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
141 "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
142 "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
143
74861
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
144 _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
145
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
146 def customize_compiler(compiler):
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
147 """Do any platform-specific customization of a CCompiler instance.
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
148
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
149 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
150 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
151 """
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
152 if compiler.compiler_type == "unix":
74871
6240ff5dfebe Issue #13994: Earler partial revert of Distutils enhancements in 2.7
Ned Deily <nad@acm.org>
parents: 74861
diff changeset
153 (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
154 get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
74871
6240ff5dfebe Issue #13994: Earler partial revert of Distutils enhancements in 2.7
Ned Deily <nad@acm.org>
parents: 74861
diff changeset
155 'CCSHARED', 'LDSHARED', 'SO', 'AR',
6240ff5dfebe Issue #13994: Earler partial revert of Distutils enhancements in 2.7
Ned Deily <nad@acm.org>
parents: 74861
diff changeset
156 '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
157
74861
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
158 newcc = None
45413
8a187f562959 Removed uses of dict.has_key() from distutils, and uses of
Guido van Rossum <guido@python.org>
parents: 45168
diff changeset
159 if 'CC' in os.environ:
74861
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
160 newcc = os.environ['CC']
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
161 elif sys.platform == 'darwin' and cc == 'gcc-4.2':
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
162 # Issue #13590:
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
163 # Since Apple removed gcc-4.2 in Xcode 4.2, we can no
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
164 # longer assume it is available for extension module builds.
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
165 # If Python was built with gcc-4.2, check first to see if
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
166 # it is available on this system; if not, try to use clang
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
167 # instead unless the caller explicitly set CC.
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
168 global _USE_CLANG
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
169 if _USE_CLANG is None:
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
170 from distutils import log
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
171 from subprocess import Popen, PIPE
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
172 p = Popen("! type gcc-4.2 && type clang && exit 2",
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
173 shell=True, stdout=PIPE, stderr=PIPE)
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
174 p.wait()
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
175 if p.returncode == 2:
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
176 _USE_CLANG = True
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
177 log.warn("gcc-4.2 not found, using clang instead")
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
178 else:
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
179 _USE_CLANG = False
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
180 if _USE_CLANG:
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
181 newcc = 'clang'
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
182 if newcc:
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
183 # On OS X, if CC is overridden, use that as the default
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
184 # command for LDSHARED as well
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
185 if (sys.platform == 'darwin'
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
186 and 'LDSHARED' not in os.environ
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
187 and ldshared.startswith(cc)):
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
188 ldshared = newcc + ldshared[len(cc):]
29507a2acdb5 Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
Ned Deily <nad@acm.org>
parents: 71046
diff changeset
189 cc = newcc
45413
8a187f562959 Removed uses of dict.has_key() from distutils, and uses of
Guido van Rossum <guido@python.org>
parents: 45168
diff changeset
190 if 'CXX' in os.environ:
26036
771b6f521b95 This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 26020
diff changeset
191 cxx = os.environ['CXX']
45413
8a187f562959 Removed uses of dict.has_key() from distutils, and uses of
Guido van Rossum <guido@python.org>
parents: 45168
diff changeset
192 if 'LDSHARED' in os.environ:
33750
ec993b726605 Patch 983206: distutils obeys LDSHARED env var. Removed the code in
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32736
diff changeset
193 ldshared = os.environ['LDSHARED']
45413
8a187f562959 Removed uses of dict.has_key() from distutils, and uses of
Guido van Rossum <guido@python.org>
parents: 45168
diff changeset
194 if 'CPP' in os.environ:
26020
8e3246842773 [Patch #588809] LDFLAGS support for build_ext.py, from Robert Weber
Andrew M. Kuchling <amk@amk.ca>
parents: 24211
diff changeset
195 cpp = os.environ['CPP']
8e3246842773 [Patch #588809] LDFLAGS support for build_ext.py, from Robert Weber
Andrew M. Kuchling <amk@amk.ca>
parents: 24211
diff changeset
196 else:
8e3246842773 [Patch #588809] LDFLAGS support for build_ext.py, from Robert Weber
Andrew M. Kuchling <amk@amk.ca>
parents: 24211
diff changeset
197 cpp = cc + " -E" # not always
45413
8a187f562959 Removed uses of dict.has_key() from distutils, and uses of
Guido van Rossum <guido@python.org>
parents: 45168
diff changeset
198 if 'LDFLAGS' in os.environ:
26020
8e3246842773 [Patch #588809] LDFLAGS support for build_ext.py, from Robert Weber
Andrew M. Kuchling <amk@amk.ca>
parents: 24211
diff changeset
199 ldshared = ldshared + ' ' + os.environ['LDFLAGS']
45413
8a187f562959 Removed uses of dict.has_key() from distutils, and uses of
Guido van Rossum <guido@python.org>
parents: 45168
diff changeset
200 if 'CFLAGS' in os.environ:
34930
294dabcb379b Make parse_makefile fallback to environment variables if nothing is
Martin v. Löwis <martin@v.loewis.de>
parents: 34929
diff changeset
201 cflags = opt + ' ' + os.environ['CFLAGS']
26020
8e3246842773 [Patch #588809] LDFLAGS support for build_ext.py, from Robert Weber
Andrew M. Kuchling <amk@amk.ca>
parents: 24211
diff changeset
202 ldshared = ldshared + ' ' + os.environ['CFLAGS']
45413
8a187f562959 Removed uses of dict.has_key() from distutils, and uses of
Guido van Rossum <guido@python.org>
parents: 45168
diff changeset
203 if 'CPPFLAGS' in os.environ:
26020
8e3246842773 [Patch #588809] LDFLAGS support for build_ext.py, from Robert Weber
Andrew M. Kuchling <amk@amk.ca>
parents: 24211
diff changeset
204 cpp = cpp + ' ' + os.environ['CPPFLAGS']
34930
294dabcb379b Make parse_makefile fallback to environment variables if nothing is
Martin v. Löwis <martin@v.loewis.de>
parents: 34929
diff changeset
205 cflags = cflags + ' ' + os.environ['CPPFLAGS']
26020
8e3246842773 [Patch #588809] LDFLAGS support for build_ext.py, from Robert Weber
Andrew M. Kuchling <amk@amk.ca>
parents: 24211
diff changeset
206 ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
74871
6240ff5dfebe Issue #13994: Earler partial revert of Distutils enhancements in 2.7
Ned Deily <nad@acm.org>
parents: 74861
diff changeset
207 if 'AR' in os.environ:
6240ff5dfebe Issue #13994: Earler partial revert of Distutils enhancements in 2.7
Ned Deily <nad@acm.org>
parents: 74861
diff changeset
208 ar = os.environ['AR']
6240ff5dfebe Issue #13994: Earler partial revert of Distutils enhancements in 2.7
Ned Deily <nad@acm.org>
parents: 74861
diff changeset
209 if 'ARFLAGS' in os.environ:
6240ff5dfebe Issue #13994: Earler partial revert of Distutils enhancements in 2.7
Ned Deily <nad@acm.org>
parents: 74861
diff changeset
210 archiver = ar + ' ' + os.environ['ARFLAGS']
6240ff5dfebe Issue #13994: Earler partial revert of Distutils enhancements in 2.7
Ned Deily <nad@acm.org>
parents: 74861
diff changeset
211 else:
6240ff5dfebe Issue #13994: Earler partial revert of Distutils enhancements in 2.7
Ned Deily <nad@acm.org>
parents: 74861
diff changeset
212 archiver = ar + ' ' + ar_flags
26020
8e3246842773 [Patch #588809] LDFLAGS support for build_ext.py, from Robert Weber
Andrew M. Kuchling <amk@amk.ca>
parents: 24211
diff changeset
213
34930
294dabcb379b Make parse_makefile fallback to environment variables if nothing is
Martin v. Löwis <martin@v.loewis.de>
parents: 34929
diff changeset
214 cc_cmd = cc + ' ' + cflags
13009
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
215 compiler.set_executables(
26020
8e3246842773 [Patch #588809] LDFLAGS support for build_ext.py, from Robert Weber
Andrew M. Kuchling <amk@amk.ca>
parents: 24211
diff changeset
216 preprocessor=cpp,
13009
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
217 compiler=cc_cmd,
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
218 compiler_so=cc_cmd + ' ' + ccshared,
26036
771b6f521b95 This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 26020
diff changeset
219 compiler_cxx=cxx,
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
220 linker_so=ldshared,
74871
6240ff5dfebe Issue #13994: Earler partial revert of Distutils enhancements in 2.7
Ned Deily <nad@acm.org>
parents: 74861
diff changeset
221 linker_exe=cc,
6240ff5dfebe Issue #13994: Earler partial revert of Distutils enhancements in 2.7
Ned Deily <nad@acm.org>
parents: 74861
diff changeset
222 archiver=archiver)
13009
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
223
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
224 compiler.shared_lib_extension = so_ext
13009
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
225
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
226
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
227 def get_config_h_filename():
18835
2dea40e40d9d Patch #411138: Rename config.h to pyconfig.h. Closes bug #231774.
Martin v. Löwis <martin@v.loewis.de>
parents: 18696
diff changeset
228 """Return full pathname of installed pyconfig.h file."""
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
229 if python_build:
44198
a53ef778590e Fixed get_config_h_filename for Windows. Without the patch it can't find the pyconfig.h file inside a build tree.
Christian Heimes <christian@cheimes.de>
parents: 40055
diff changeset
230 if os.name == "nt":
a53ef778590e Fixed get_config_h_filename for Windows. Without the patch it can't find the pyconfig.h file inside a build tree.
Christian Heimes <christian@cheimes.de>
parents: 40055
diff changeset
231 inc_dir = os.path.join(project_base, "PC")
a53ef778590e Fixed get_config_h_filename for Windows. Without the patch it can't find the pyconfig.h file inside a build tree.
Christian Heimes <christian@cheimes.de>
parents: 40055
diff changeset
232 else:
a53ef778590e Fixed get_config_h_filename for Windows. Without the patch it can't find the pyconfig.h file inside a build tree.
Christian Heimes <christian@cheimes.de>
parents: 40055
diff changeset
233 inc_dir = project_base
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
234 else:
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
235 inc_dir = get_python_inc(plat_specific=1)
34661
9fa768a98c5c Patch #1046831: Use get_python_version where appropriate in sysconfig.py.
Martin v. Löwis <martin@v.loewis.de>
parents: 34258
diff changeset
236 if get_python_version() < '2.2':
18837
5e0a40ccb9da Add backwards compatibility.
Marc-André Lemburg <mal@egenix.com>
parents: 18835
diff changeset
237 config_h = 'config.h'
5e0a40ccb9da Add backwards compatibility.
Marc-André Lemburg <mal@egenix.com>
parents: 18835
diff changeset
238 else:
5e0a40ccb9da Add backwards compatibility.
Marc-André Lemburg <mal@egenix.com>
parents: 18835
diff changeset
239 # The name of the config.h file changed in 2.2
5e0a40ccb9da Add backwards compatibility.
Marc-André Lemburg <mal@egenix.com>
parents: 18835
diff changeset
240 config_h = 'pyconfig.h'
5e0a40ccb9da Add backwards compatibility.
Marc-André Lemburg <mal@egenix.com>
parents: 18835
diff changeset
241 return os.path.join(inc_dir, config_h)
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
242
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
243
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
244 def get_makefile_filename():
9783
be24b5b90dec Update and add docstrings.
Fred Drake <fdrake@acm.org>
parents: 9780
diff changeset
245 """Return full pathname of installed Makefile from the Python build."""
15937
d9d0dcb735d7 Patch #103279: sysconfig.py always looks for versions of files in
Andrew M. Kuchling <amk@amk.ca>
parents: 15923
diff changeset
246 if python_build:
59343
ad22bc22dddc reverting partially distutils to its 2.6.x state so 2.7a4 looks more like the 2.7b1 in this. the whole revert will occur after a4 is tagged
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 58649
diff changeset
247 return os.path.join(os.path.dirname(sys.executable), "Makefile")
11953
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
248 lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
249 return os.path.join(lib_dir, "config", "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
250
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
251
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
252 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
253 """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
254
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
255 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
256 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
257 used instead of a new dictionary.
9783
be24b5b90dec Update and add docstrings.
Fred Drake <fdrake@acm.org>
parents: 9780
diff changeset
258 """
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
259 if g is None:
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
260 g = {}
37561
bd375777932d Patch #1429775: Link Python modules to libpython on linux if
Martin v. Löwis <martin@v.loewis.de>
parents: 37007
diff changeset
261 define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
bd375777932d Patch #1429775: Link Python modules to libpython on linux if
Martin v. Löwis <martin@v.loewis.de>
parents: 37007
diff changeset
262 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
263 #
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
264 while 1:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
265 line = fp.readline()
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
266 if not line:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
267 break
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
268 m = define_rx.match(line)
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
269 if m:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
270 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
271 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
272 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
273 g[n] = v
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
274 else:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
275 m = undef_rx.match(line)
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
276 if m:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
277 g[m.group(1)] = 0
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
278 return g
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
279
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
280
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
281 # 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
282 # 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
283 _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
284 _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
285 _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
286
14571
600515747c51 Fixed so 'parse_makefile()' uses the TextFile class to ensure that
Greg Ward <gward@python.net>
parents: 14321
diff changeset
287 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
288 """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
289
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
290 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
291 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
292 used instead of a new dictionary.
9783
be24b5b90dec Update and add docstrings.
Fred Drake <fdrake@acm.org>
parents: 9780
diff changeset
293 """
14571
600515747c51 Fixed so 'parse_makefile()' uses the TextFile class to ensure that
Greg Ward <gward@python.net>
parents: 14321
diff changeset
294 from distutils.text_file import TextFile
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
295 fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1)
14571
600515747c51 Fixed so 'parse_makefile()' uses the TextFile class to ensure that
Greg Ward <gward@python.net>
parents: 14321
diff changeset
296
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
297 if g is None:
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
298 g = {}
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
299 done = {}
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
300 notdone = {}
14571
600515747c51 Fixed so 'parse_makefile()' uses the TextFile class to ensure that
Greg Ward <gward@python.net>
parents: 14321
diff changeset
301
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
302 while 1:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
303 line = fp.readline()
54669
0adf0fa7993b Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51505
diff changeset
304 if line is None: # eof
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
305 break
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
306 m = _variable_rx.match(line)
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
307 if m:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
308 n, v = m.group(1, 2)
54669
0adf0fa7993b Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51505
diff changeset
309 v = v.strip()
0adf0fa7993b Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51505
diff changeset
310 # `$$' is a literal `$' in make
0adf0fa7993b Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51505
diff changeset
311 tmpv = v.replace('$$', '')
0adf0fa7993b Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51505
diff changeset
312
0adf0fa7993b Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51505
diff changeset
313 if "$" in tmpv:
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
314 notdone[n] = v
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
315 else:
54669
0adf0fa7993b Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51505
diff changeset
316 try:
0adf0fa7993b Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51505
diff changeset
317 v = int(v)
0adf0fa7993b Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51505
diff changeset
318 except ValueError:
0adf0fa7993b Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51505
diff changeset
319 # insert literal `$'
0adf0fa7993b Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51505
diff changeset
320 done[n] = v.replace('$$', '$')
0adf0fa7993b Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51505
diff changeset
321 else:
0adf0fa7993b Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51505
diff changeset
322 done[n] = v
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
323
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
324 # do variable interpolation here
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
325 while notdone:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
326 for name in notdone.keys():
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
327 value = notdone[name]
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
328 m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
329 if m:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
330 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
331 found = True
45413
8a187f562959 Removed uses of dict.has_key() from distutils, and uses of
Guido van Rossum <guido@python.org>
parents: 45168
diff changeset
332 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
333 item = str(done[n])
45413
8a187f562959 Removed uses of dict.has_key() from distutils, and uses of
Guido van Rossum <guido@python.org>
parents: 45168
diff changeset
334 elif n in notdone:
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
335 # 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
336 found = False
45413
8a187f562959 Removed uses of dict.has_key() from distutils, and uses of
Guido van Rossum <guido@python.org>
parents: 45168
diff changeset
337 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
338 # 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
339 item = os.environ[n]
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
340 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
341 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
342 if found:
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
343 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
344 value = value[:m.start()] + item + after
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
345 if "$" in after:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
346 notdone[name] = value
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
347 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
348 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
349 except ValueError:
54669
0adf0fa7993b Merged revisions 73341 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51505
diff changeset
350 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
351 else:
ff6c30e8ca73 Fix bugs with integer-valued variables when parsing Makefiles. Values
Andrew M. Kuchling <amk@amk.ca>
parents: 15818
diff changeset
352 done[name] = value
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
353 del notdone[name]
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
354 else:
9690
31489799c8c6 Applied Fred's patch to fix the bugs that John Skaller noticed.
Greg Ward <gward@python.net>
parents: 9658
diff changeset
355 # 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
356 del notdone[name]
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
357
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
358 fp.close()
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
359
65210
ad15b89106de Merged revisions 85353 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61258
diff changeset
360 # strip spurious spaces
ad15b89106de Merged revisions 85353 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61258
diff changeset
361 for k, v in done.items():
ad15b89106de Merged revisions 85353 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61258
diff changeset
362 if isinstance(v, str):
ad15b89106de Merged revisions 85353 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61258
diff changeset
363 done[k] = v.strip()
ad15b89106de Merged revisions 85353 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61258
diff changeset
364
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
365 # save the results in the global dictionary
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
366 g.update(done)
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
367 return g
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
368
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
369
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
370 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
371 """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
372 '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
373 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
374 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
375 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
376 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
377 """
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
378
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
379 # 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
380 # "${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
381 # ${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
382 # '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
383 # 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
384
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
385 while 1:
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
386 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
387 if m:
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
388 (beg, end) = m.span()
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
389 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
390 else:
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
391 break
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
392 return s
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
393
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
394
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
395 _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
396
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
397 def _init_posix():
9783
be24b5b90dec Update and add docstrings.
Fred Drake <fdrake@acm.org>
parents: 9780
diff changeset
398 """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
399 g = {}
11689
09dbb47034e0 Comment fix.
Greg Ward <gward@python.net>
parents: 11251
diff changeset
400 # 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
401 try:
89f42099c5dd Catch failure to open installed Makefile, and report it as a
Greg Ward <gward@python.net>
parents: 12414
diff changeset
402 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
403 parse_makefile(filename, g)
12740
89f42099c5dd Catch failure to open installed Makefile, and report it as a
Greg Ward <gward@python.net>
parents: 12414
diff changeset
404 except IOError, msg:
89f42099c5dd Catch failure to open installed Makefile, and report it as a
Greg Ward <gward@python.net>
parents: 12414
diff changeset
405 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
406 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
407 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
408
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
409 raise DistutilsPlatformError(my_msg)
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
410
37561
bd375777932d Patch #1429775: Link Python modules to libpython on linux if
Martin v. Löwis <martin@v.loewis.de>
parents: 37007
diff changeset
411 # load the installed pyconfig.h:
bd375777932d Patch #1429775: Link Python modules to libpython on linux if
Martin v. Löwis <martin@v.loewis.de>
parents: 37007
diff changeset
412 try:
bd375777932d Patch #1429775: Link Python modules to libpython on linux if
Martin v. Löwis <martin@v.loewis.de>
parents: 37007
diff changeset
413 filename = get_config_h_filename()
bd375777932d Patch #1429775: Link Python modules to libpython on linux if
Martin v. Löwis <martin@v.loewis.de>
parents: 37007
diff changeset
414 parse_config_h(file(filename), g)
bd375777932d Patch #1429775: Link Python modules to libpython on linux if
Martin v. Löwis <martin@v.loewis.de>
parents: 37007
diff changeset
415 except IOError, msg:
bd375777932d Patch #1429775: Link Python modules to libpython on linux if
Martin v. Löwis <martin@v.loewis.de>
parents: 37007
diff changeset
416 my_msg = "invalid Python installation: unable to open %s" % filename
bd375777932d Patch #1429775: Link Python modules to libpython on linux if
Martin v. Löwis <martin@v.loewis.de>
parents: 37007
diff changeset
417 if hasattr(msg, "strerror"):
bd375777932d Patch #1429775: Link Python modules to libpython on linux if
Martin v. Löwis <martin@v.loewis.de>
parents: 37007
diff changeset
418 my_msg = my_msg + " (%s)" % msg.strerror
bd375777932d Patch #1429775: Link Python modules to libpython on linux if
Martin v. Löwis <martin@v.loewis.de>
parents: 37007
diff changeset
419
bd375777932d Patch #1429775: Link Python modules to libpython on linux if
Martin v. Löwis <martin@v.loewis.de>
parents: 37007
diff changeset
420 raise DistutilsPlatformError(my_msg)
bd375777932d Patch #1429775: Link Python modules to libpython on linux if
Martin v. Löwis <martin@v.loewis.de>
parents: 37007
diff changeset
421
13034
f1e40abbedb3 Fixed LDSHARED for AIX, based on a patch by Rene Liebscher.
Greg Ward <gward@python.net>
parents: 13009
diff changeset
422 # 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
423 # -- 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
424 # 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
425 if python_build:
16841
3d29690a24e8 Placate tabnanny
Andrew M. Kuchling <amk@amk.ca>
parents: 16621
diff changeset
426 g['LDSHARED'] = g['BLDSHARED']
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19724
diff changeset
427
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
428 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
429 # 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
430 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
431 # 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
432 # 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
433 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
434 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
435 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
436
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
437 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
438
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
439 elif sys.platform == 'beos':
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
440 # Linker script is in the config directory. In the Makefile it is
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
441 # relative to the srcdir, which after installation no longer makes
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
442 # sense.
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
443 python_lib = get_python_lib(standard_lib=1)
26186
af3964679e2f Back out part of rev. 1.53, restoring the use of the string module.
Andrew M. Kuchling <amk@amk.ca>
parents: 26048
diff changeset
444 linkerscript_path = string.split(g['LDSHARED'])[0]
af3964679e2f Back out part of rev. 1.53, restoring the use of the string module.
Andrew M. Kuchling <amk@amk.ca>
parents: 26048
diff changeset
445 linkerscript_name = os.path.basename(linkerscript_path)
26048
b4a6283b915b Remove use of string module and reflow a couple of long lines.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26036
diff changeset
446 linkerscript = os.path.join(python_lib, 'config',
b4a6283b915b Remove use of string module and reflow a couple of long lines.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26036
diff changeset
447 linkerscript_name)
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19724
diff changeset
448
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
449 # XXX this isn't the right place to do this: adding the Python
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
450 # library to the link, if needed, should be in the "build_ext"
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
451 # command. (It's also needed for non-MS compilers on Windows, and
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
452 # it's taken care of for them by the 'build_ext.get_libraries()'
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
453 # method.)
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
454 g['LDSHARED'] = ("%s -L%s/lib -lpython%s" %
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
455 (linkerscript, PREFIX, get_python_version()))
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19724
diff changeset
456
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
457 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
458 _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
459
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
460
10926
f9c03b3d0f14 Now handles NT, through '_init_nt()' function (courtesy of
Greg Ward <gward@python.net>
parents: 9842
diff changeset
461 def _init_nt():
f9c03b3d0f14 Now handles NT, through '_init_nt()' function (courtesy of
Greg Ward <gward@python.net>
parents: 9842
diff changeset
462 """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
463 g = {}
10926
f9c03b3d0f14 Now handles NT, through '_init_nt()' function (courtesy of
Greg Ward <gward@python.net>
parents: 9842
diff changeset
464 # 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
465 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
466 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
467
11251
2f07bc56e97e Patch from Perry Stoll: tweaks to Windows support.
Greg Ward <gward@python.net>
parents: 10926
diff changeset
468 # 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
469 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
470
11721
eb381ff17a31 get_config_h_filename(): Support NT as well as Posix systems.
Fred Drake <fdrake@acm.org>
parents: 11689
diff changeset
471 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
472 g['EXE'] = ".exe"
44198
a53ef778590e Fixed get_config_h_filename for Windows. Without the patch it can't find the pyconfig.h file inside a build tree.
Christian Heimes <christian@cheimes.de>
parents: 40055
diff changeset
473 g['VERSION'] = get_python_version().replace(".", "")
59343
ad22bc22dddc reverting partially distutils to its 2.6.x state so 2.7a4 looks more like the 2.7b1 in this. the whole revert will occur after a4 is tagged
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 58649
diff changeset
474 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
475
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
476 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
477 _config_vars = g
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
478
11721
eb381ff17a31 get_config_h_filename(): Support NT as well as Posix systems.
Fred Drake <fdrake@acm.org>
parents: 11689
diff changeset
479
21851
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
480 def _init_os2():
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
481 """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
482 g = {}
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
483 # set basic install directories
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
484 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
485 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
486
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
487 # 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
488 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
489
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
490 g['SO'] = '.pyd'
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
491 g['EXE'] = ".exe"
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
492
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
493 global _config_vars
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
494 _config_vars = g
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
495
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
496
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
497 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
498 """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
499 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
500 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
501 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
502 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
503
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
504 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
505 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
506 """
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
507 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
508 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
509 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
510 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
511 func()
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
512 else:
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
513 _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
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 # 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
516 # 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
517 # Distutils.
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
518 _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
519 _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
520
38248
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
521 if sys.platform == 'darwin':
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
522 kernel_version = os.uname()[2] # Kernel version (8.4.3)
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
523 major_version = int(kernel_version.split('.')[0])
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
524
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
525 if major_version < 8:
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
526 # On Mac OS X before 10.4, check if -arch and -isysroot
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
527 # are in CFLAGS or LDFLAGS and remove them if they are.
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
528 # This is needed when building extensions on a 10.3 system
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
529 # using a universal build of python.
57637
b27d946389e7 Merged revisions 76738 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 56187
diff changeset
530 for key in ('LDFLAGS', 'BASECFLAGS', 'LDSHARED',
40055
83965977f34a MacOSX: distutils changes the values of BASECFLAGS and LDFLAGS when using a
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38944
diff changeset
531 # a number of derived variables. These need to be
83965977f34a MacOSX: distutils changes the values of BASECFLAGS and LDFLAGS when using a
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38944
diff changeset
532 # patched up as well.
83965977f34a MacOSX: distutils changes the values of BASECFLAGS and LDFLAGS when using a
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38944
diff changeset
533 'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
38248
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
534 flags = _config_vars[key]
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
535 flags = re.sub('-arch\s+\w+\s', ' ', flags)
38944
0602771b8b49 MacOSX: fix rather dumb buglet that made it impossible to create extensions on
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38248
diff changeset
536 flags = re.sub('-isysroot [^ \t]*', ' ', flags)
38248
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
537 _config_vars[key] = flags
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
538
47473
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
539 else:
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
540
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
541 # Allow the user to override the architecture flags using
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
542 # an environment variable.
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
543 # NOTE: This name was introduced by Apple in OSX 10.5 and
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
544 # is used by several scripting languages distributed with
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
545 # that OS release.
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
546
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
547 if 'ARCHFLAGS' in os.environ:
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
548 arch = os.environ['ARCHFLAGS']
57637
b27d946389e7 Merged revisions 76738 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 56187
diff changeset
549 for key in ('LDFLAGS', 'BASECFLAGS', 'LDSHARED',
40056
768894f33f1c Backport of r52233
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38944
diff changeset
550 # a number of derived variables. These need to be
768894f33f1c Backport of r52233
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38944
diff changeset
551 # patched up as well.
768894f33f1c Backport of r52233
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38944
diff changeset
552 'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
768894f33f1c Backport of r52233
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38944
diff changeset
553
47473
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
554 flags = _config_vars[key]
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
555 flags = re.sub('-arch\s+\w+\s', ' ', flags)
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
556 flags = flags + ' ' + arch
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
557 _config_vars[key] = flags
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
558
56187
4aa7de66137f Merged revisions 75022 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 54669
diff changeset
559 # If we're on OSX 10.5 or later and the user tries to
4aa7de66137f Merged revisions 75022 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 54669
diff changeset
560 # compiles an extension using an SDK that is not present
4aa7de66137f Merged revisions 75022 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 54669
diff changeset
561 # on the current machine it is better to not use an SDK
4aa7de66137f Merged revisions 75022 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 54669
diff changeset
562 # than to fail.
4aa7de66137f Merged revisions 75022 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 54669
diff changeset
563 #
4aa7de66137f Merged revisions 75022 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 54669
diff changeset
564 # The major usecase for this is users using a Python.org
4aa7de66137f Merged revisions 75022 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 54669
diff changeset
565 # binary installer on OSX 10.6: that installer uses
4aa7de66137f Merged revisions 75022 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 54669
diff changeset
566 # the 10.4u SDK, but that SDK is not installed by default
4aa7de66137f Merged revisions 75022 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 54669
diff changeset
567 # when you install Xcode.
4aa7de66137f Merged revisions 75022 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 54669
diff changeset
568 #
4aa7de66137f Merged revisions 75022 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 54669
diff changeset
569 m = re.search('-isysroot\s+(\S+)', _config_vars['CFLAGS'])
4aa7de66137f Merged revisions 75022 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 54669
diff changeset
570 if m is not None:
4aa7de66137f Merged revisions 75022 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 54669
diff changeset
571 sdk = m.group(1)
4aa7de66137f Merged revisions 75022 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 54669
diff changeset
572 if not os.path.exists(sdk):
57637
b27d946389e7 Merged revisions 76738 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 56187
diff changeset
573 for key in ('LDFLAGS', 'BASECFLAGS', 'LDSHARED',
56187
4aa7de66137f Merged revisions 75022 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 54669
diff changeset
574 # a number of derived variables. These need to be
4aa7de66137f Merged revisions 75022 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 54669
diff changeset
575 # patched up as well.
4aa7de66137f Merged revisions 75022 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 54669
diff changeset
576 'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
4aa7de66137f Merged revisions 75022 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 54669
diff changeset
577
4aa7de66137f Merged revisions 75022 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 54669
diff changeset
578 flags = _config_vars[key]
4aa7de66137f Merged revisions 75022 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 54669
diff changeset
579 flags = re.sub('-isysroot\s+\S+(\s|$)', ' ', flags)
4aa7de66137f Merged revisions 75022 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 54669
diff changeset
580 _config_vars[key] = flags
38248
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
581
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
582 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
583 vals = []
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
584 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
585 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
586 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
587 else:
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 _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
589
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
590 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
591 """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
592 returned by 'get_config_vars()'. Equivalent to
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
593 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
594 """
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
595 return get_config_vars().get(name)