annotate Lib/distutils/sysconfig.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents 9143d20d8b26
children 65793acc0095
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.
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
28 project_base = os.path.dirname(os.path.abspath(sys.executable))
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
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
74 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
75 if python_build:
51343
f4012e78260c Fix get_python_inc() to work when building in a directory separate from
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 47473
diff changeset
76 # Assume the executable is in the build directory. The
f4012e78260c Fix get_python_inc() to work when building in a directory separate from
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 47473
diff changeset
77 # pyconfig.h file should be in the same directory. Since
f4012e78260c Fix get_python_inc() to work when building in a directory separate from
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 47473
diff changeset
78 # the build directory may not be the source directory, we
f4012e78260c Fix get_python_inc() to work when building in a directory separate from
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 47473
diff changeset
79 # must use "srcdir" from the makefile to find the "Include"
f4012e78260c Fix get_python_inc() to work when building in a directory separate from
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 47473
diff changeset
80 # directory.
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 base = os.path.dirname(os.path.abspath(sys.executable))
5c5fff5de250 When using a Python that has not been installed to build 3rd-party
Fred Drake <fdrake@acm.org>
parents: 21851
diff changeset
82 if plat_specific:
51343
f4012e78260c Fix get_python_inc() to work when building in a directory separate from
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 47473
diff changeset
83 return base
23659
5c5fff5de250 When using a Python that has not been installed to build 3rd-party
Fred Drake <fdrake@acm.org>
parents: 21851
diff changeset
84 else:
51343
f4012e78260c Fix get_python_inc() to work when building in a directory separate from
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 47473
diff changeset
85 incdir = os.path.join(get_config_var('srcdir'), 'Include')
f4012e78260c Fix get_python_inc() to work when building in a directory separate from
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 47473
diff changeset
86 return os.path.normpath(incdir)
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
87 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
88 elif os.name == "nt":
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
89 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
90 elif os.name == "mac":
24021
fcf2e01c616a Whitespace normalization (remove tabs)
Neal Norwitz <nnorwitz@gmail.com>
parents: 24007
diff changeset
91 if plat_specific:
30772
897afcacba00 Patch #812378: Normalize white space.
Martin v. Löwis <martin@v.loewis.de>
parents: 27788
diff changeset
92 return os.path.join(prefix, "Mac", "Include")
24021
fcf2e01c616a Whitespace normalization (remove tabs)
Neal Norwitz <nnorwitz@gmail.com>
parents: 24007
diff changeset
93 else:
30772
897afcacba00 Patch #812378: Normalize white space.
Martin v. Löwis <martin@v.loewis.de>
parents: 27788
diff changeset
94 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
95 elif os.name == "os2":
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
96 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
97 else:
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
98 raise DistutilsPlatformError(
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
99 "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
100 "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
101
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
102
12316
540f10881a59 Added optional 'prefix' arguments to 'get_python_inc()' and
Greg Ward <gward@python.net>
parents: 12315
diff changeset
103 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
104 """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
105 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
106
11953
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
107 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
108 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
109 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
110 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
111 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
112 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
113
12316
540f10881a59 Added optional 'prefix' arguments to 'get_python_inc()' and
Greg Ward <gward@python.net>
parents: 12315
diff changeset
114 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
115 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
116 """
12316
540f10881a59 Added optional 'prefix' arguments to 'get_python_inc()' and
Greg Ward <gward@python.net>
parents: 12315
diff changeset
117 if prefix is None:
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
118 prefix = plat_specific and EXEC_PREFIX or PREFIX
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
119
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
120 if os.name == "posix":
12315
f1f665e075ca Better variable names here and there.
Greg Ward <gward@python.net>
parents: 11953
diff changeset
121 libpython = os.path.join(prefix,
26205
d33005f8388e [Bug #550364] Add get_python_version()
Andrew M. Kuchling <amk@amk.ca>
parents: 26186
diff changeset
122 "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
123 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
124 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
125 else:
11953
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
126 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
127
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
128 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
129 if standard_lib:
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
130 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
131 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
132 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
133 return prefix
7fb5f15685dd Patch #449054 to implement PEP 250. The standard install directory for
Greg Ward <gward@python.net>
parents: 18945
diff changeset
134 else:
51504
c61f24ff055e Fixed #3386: the optional prefix argument was ignored under OS2 and NT in distutils.sysconfig.get_python_lib
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51405
diff changeset
135 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
136
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
137 elif os.name == "mac":
13811
f38e321be8a4 Typo fix.
Greg Ward <gward@python.net>
parents: 13804
diff changeset
138 if plat_specific:
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
139 if standard_lib:
19681
7de4e6b8d199 On the mac some library paths returned were outdated, some were outright funny.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19453
diff changeset
140 return os.path.join(prefix, "Lib", "lib-dynload")
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
141 else:
19681
7de4e6b8d199 On the mac some library paths returned were outdated, some were outright funny.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19453
diff changeset
142 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
143 else:
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
144 if standard_lib:
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
145 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
146 else:
19681
7de4e6b8d199 On the mac some library paths returned were outdated, some were outright funny.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19453
diff changeset
147 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
148
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
149 elif os.name == "os2":
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
150 if standard_lib:
51504
c61f24ff055e Fixed #3386: the optional prefix argument was ignored under OS2 and NT in distutils.sysconfig.get_python_lib
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51405
diff changeset
151 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
152 else:
51504
c61f24ff055e Fixed #3386: the optional prefix argument was ignored under OS2 and NT in distutils.sysconfig.get_python_lib
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51405
diff changeset
153 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
154
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
155 else:
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
156 raise DistutilsPlatformError(
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
157 "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
158 "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
159
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
160
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
161 def customize_compiler(compiler):
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
162 """Do any platform-specific customization of a CCompiler instance.
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
163
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
164 Mainly needed on Unix, so we can plug in the information that
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
165 varies across Unices and is stored in Python's Makefile.
13009
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
166 """
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
167 if compiler.compiler_type == "unix":
53888
9143d20d8b26 Fixed #5941: added ARFLAGS for the archiver command.
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51504
diff changeset
168 (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
169 get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
53888
9143d20d8b26 Fixed #5941: added ARFLAGS for the archiver command.
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51504
diff changeset
170 'CCSHARED', 'LDSHARED', 'SO', 'AR', 'ARFLAGS')
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
171
45413
8a187f562959 Removed uses of dict.has_key() from distutils, and uses of
Guido van Rossum <guido@python.org>
parents: 45168
diff changeset
172 if 'CC' 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
173 cc = os.environ['CC']
45413
8a187f562959 Removed uses of dict.has_key() from distutils, and uses of
Guido van Rossum <guido@python.org>
parents: 45168
diff changeset
174 if 'CXX' in os.environ:
26036
771b6f521b95 This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 26020
diff changeset
175 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
176 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
177 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
178 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
179 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
180 else:
8e3246842773 [Patch #588809] LDFLAGS support for build_ext.py, from Robert Weber
Andrew M. Kuchling <amk@amk.ca>
parents: 24211
diff changeset
181 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
182 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
183 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
184 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
185 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
186 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
187 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
188 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
189 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
190 ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
51374
fdecb9182604 fixed #1520877: now distutils reads Read from the environment/Makefile
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51343
diff changeset
191 if 'AR' in os.environ:
fdecb9182604 fixed #1520877: now distutils reads Read from the environment/Makefile
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51343
diff changeset
192 ar = os.environ['AR']
53888
9143d20d8b26 Fixed #5941: added ARFLAGS for the archiver command.
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51504
diff changeset
193 if 'ARFLAGS' in os.environ:
9143d20d8b26 Fixed #5941: added ARFLAGS for the archiver command.
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51504
diff changeset
194 archiver = ar + ' ' + os.environ['ARFLAGS']
9143d20d8b26 Fixed #5941: added ARFLAGS for the archiver command.
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51504
diff changeset
195 else:
9143d20d8b26 Fixed #5941: added ARFLAGS for the archiver command.
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51504
diff changeset
196 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
197
34930
294dabcb379b Make parse_makefile fallback to environment variables if nothing is
Martin v. Löwis <martin@v.loewis.de>
parents: 34929
diff changeset
198 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
199 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
200 preprocessor=cpp,
13009
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
201 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
202 compiler_so=cc_cmd + ' ' + ccshared,
26036
771b6f521b95 This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 26020
diff changeset
203 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
204 linker_so=ldshared,
51374
fdecb9182604 fixed #1520877: now distutils reads Read from the environment/Makefile
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51343
diff changeset
205 linker_exe=cc,
53888
9143d20d8b26 Fixed #5941: added ARFLAGS for the archiver command.
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51504
diff changeset
206 archiver=archiver)
13009
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
207
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
208 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
209
7b38678b3652 Added the 'customize_compiler()' function, which plugs in the essential
Greg Ward <gward@python.net>
parents: 12840
diff changeset
210
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
211 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
212 """Return full pathname of installed pyconfig.h file."""
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
213 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
214 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
215 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
216 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
217 inc_dir = project_base
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
218 else:
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
219 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
220 if get_python_version() < '2.2':
18837
5e0a40ccb9da Add backwards compatibility.
Marc-André Lemburg <mal@egenix.com>
parents: 18835
diff changeset
221 config_h = 'config.h'
5e0a40ccb9da Add backwards compatibility.
Marc-André Lemburg <mal@egenix.com>
parents: 18835
diff changeset
222 else:
5e0a40ccb9da Add backwards compatibility.
Marc-André Lemburg <mal@egenix.com>
parents: 18835
diff changeset
223 # 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
224 config_h = 'pyconfig.h'
5e0a40ccb9da Add backwards compatibility.
Marc-André Lemburg <mal@egenix.com>
parents: 18835
diff changeset
225 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
226
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
227
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
228 def get_makefile_filename():
9783
be24b5b90dec Update and add docstrings.
Fred Drake <fdrake@acm.org>
parents: 9780
diff changeset
229 """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
230 if python_build:
23659
5c5fff5de250 When using a Python that has not been installed to build 3rd-party
Fred Drake <fdrake@acm.org>
parents: 21851
diff changeset
231 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
232 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
233 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
234
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
235
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
236 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
237 """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
238
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
239 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
240 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
241 used instead of a new dictionary.
9783
be24b5b90dec Update and add docstrings.
Fred Drake <fdrake@acm.org>
parents: 9780
diff changeset
242 """
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
243 if g is None:
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
244 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
245 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
246 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
247 #
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
248 while 1:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
249 line = fp.readline()
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
250 if not line:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
251 break
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
252 m = define_rx.match(line)
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
253 if m:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
254 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
255 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
256 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
257 g[n] = v
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
258 else:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
259 m = undef_rx.match(line)
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
260 if m:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
261 g[m.group(1)] = 0
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
262 return g
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
263
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
264
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
265 # 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
266 # 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
267 _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
268 _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
269 _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
270
14571
600515747c51 Fixed so 'parse_makefile()' uses the TextFile class to ensure that
Greg Ward <gward@python.net>
parents: 14321
diff changeset
271 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
272 """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
273
f9db3654a1fd There are a few places which can raise DistutilsPlatformError; make
Fred Drake <fdrake@acm.org>
parents: 11952
diff changeset
274 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
275 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
276 used instead of a new dictionary.
9783
be24b5b90dec Update and add docstrings.
Fred Drake <fdrake@acm.org>
parents: 9780
diff changeset
277 """
14571
600515747c51 Fixed so 'parse_makefile()' uses the TextFile class to ensure that
Greg Ward <gward@python.net>
parents: 14321
diff changeset
278 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
279 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
280
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
281 if g is None:
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
282 g = {}
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
283 done = {}
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
284 notdone = {}
14571
600515747c51 Fixed so 'parse_makefile()' uses the TextFile class to ensure that
Greg Ward <gward@python.net>
parents: 14321
diff changeset
285
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
286 while 1:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
287 line = fp.readline()
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
288 if line is None: # eof
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
289 break
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
290 m = _variable_rx.match(line)
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
291 if m:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
292 n, v = m.group(1, 2)
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
293 v = string.strip(v)
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
294 if "$" in v:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
295 notdone[n] = v
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
296 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
297 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
298 except ValueError: pass
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
299 done[n] = v
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
300
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
301 # do variable interpolation here
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
302 while notdone:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
303 for name in notdone.keys():
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
304 value = notdone[name]
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
305 m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
306 if m:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
307 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
308 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
309 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
310 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
311 elif n in notdone:
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
312 # 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
313 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
314 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
315 # 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
316 item = os.environ[n]
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
317 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
318 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
319 if found:
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
320 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
321 value = value[:m.start()] + item + after
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
322 if "$" in after:
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
323 notdone[name] = value
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
324 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
325 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
326 except ValueError:
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
327 done[name] = string.strip(value)
15923
ff6c30e8ca73 Fix bugs with integer-valued variables when parsing Makefiles. Values
Andrew M. Kuchling <amk@amk.ca>
parents: 15818
diff changeset
328 else:
ff6c30e8ca73 Fix bugs with integer-valued variables when parsing Makefiles. Values
Andrew M. Kuchling <amk@amk.ca>
parents: 15818
diff changeset
329 done[name] = value
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
330 del notdone[name]
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
331 else:
9690
31489799c8c6 Applied Fred's patch to fix the bugs that John Skaller noticed.
Greg Ward <gward@python.net>
parents: 9658
diff changeset
332 # 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
333 del notdone[name]
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
334
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
335 fp.close()
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
336
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
337 # save the results in the global dictionary
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
338 g.update(done)
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
339 return g
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
340
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
341
14651
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
342 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
343 """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
344 '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
345 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
346 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
347 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
348 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
349 """
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
350
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
351 # 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
352 # "${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
353 # ${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
354 # '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
355 # 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
356
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
357 while 1:
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
358 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
359 if m:
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
360 (beg, end) = m.span()
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
361 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
362 else:
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
363 break
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
364 return s
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
365
7fc4569d9625 Added 'expand_makefile_vars()' to (duh) expand make-style variables
Greg Ward <gward@python.net>
parents: 14572
diff changeset
366
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
367 _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
368
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
369 def _init_posix():
9783
be24b5b90dec Update and add docstrings.
Fred Drake <fdrake@acm.org>
parents: 9780
diff changeset
370 """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
371 g = {}
11689
09dbb47034e0 Comment fix.
Greg Ward <gward@python.net>
parents: 11251
diff changeset
372 # 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
373 try:
89f42099c5dd Catch failure to open installed Makefile, and report it as a
Greg Ward <gward@python.net>
parents: 12414
diff changeset
374 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
375 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
376 except IOError, msg:
89f42099c5dd Catch failure to open installed Makefile, and report it as a
Greg Ward <gward@python.net>
parents: 12414
diff changeset
377 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
378 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
379 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
380
18696
1c2da78b839b Minor changes for stylistic cleanliness and consistency.
Fred Drake <fdrake@acm.org>
parents: 17847
diff changeset
381 raise DistutilsPlatformError(my_msg)
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
382
37561
bd375777932d Patch #1429775: Link Python modules to libpython on linux if
Martin v. Löwis <martin@v.loewis.de>
parents: 37007
diff changeset
383 # 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
384 try:
bd375777932d Patch #1429775: Link Python modules to libpython on linux if
Martin v. Löwis <martin@v.loewis.de>
parents: 37007
diff changeset
385 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
386 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
387 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
388 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
389 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
390 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
391
bd375777932d Patch #1429775: Link Python modules to libpython on linux if
Martin v. Löwis <martin@v.loewis.de>
parents: 37007
diff changeset
392 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
393
32218
fdf75eef6a5c Partial fix for #887242 (link extensions with dynamic_lookup in stead
Jack Jansen <jack.jansen@cwi.nl>
parents: 30772
diff changeset
394 # On MacOSX we need to check the setting of the environment variable
fdf75eef6a5c Partial fix for #887242 (link extensions with dynamic_lookup in stead
Jack Jansen <jack.jansen@cwi.nl>
parents: 30772
diff changeset
395 # MACOSX_DEPLOYMENT_TARGET: configure bases some choices on it so
fdf75eef6a5c Partial fix for #887242 (link extensions with dynamic_lookup in stead
Jack Jansen <jack.jansen@cwi.nl>
parents: 30772
diff changeset
396 # it needs to be compatible.
34258
646195b59205 After discussion on the PythonMac-SIG it was decided that it is better
Jack Jansen <jack.jansen@cwi.nl>
parents: 33750
diff changeset
397 # If it isn't set we set it to the configure-time value
45413
8a187f562959 Removed uses of dict.has_key() from distutils, and uses of
Guido van Rossum <guido@python.org>
parents: 45168
diff changeset
398 if sys.platform == 'darwin' and 'MACOSX_DEPLOYMENT_TARGET' in g:
38040
36c7a4422e30 Patch 1471883: --enable-universalsdk on Mac OS X
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37801
diff changeset
399 cfg_target = g['MACOSX_DEPLOYMENT_TARGET']
32218
fdf75eef6a5c Partial fix for #887242 (link extensions with dynamic_lookup in stead
Jack Jansen <jack.jansen@cwi.nl>
parents: 30772
diff changeset
400 cur_target = os.getenv('MACOSX_DEPLOYMENT_TARGET', '')
34258
646195b59205 After discussion on the PythonMac-SIG it was decided that it is better
Jack Jansen <jack.jansen@cwi.nl>
parents: 33750
diff changeset
401 if cur_target == '':
646195b59205 After discussion on the PythonMac-SIG it was decided that it is better
Jack Jansen <jack.jansen@cwi.nl>
parents: 33750
diff changeset
402 cur_target = cfg_target
646195b59205 After discussion on the PythonMac-SIG it was decided that it is better
Jack Jansen <jack.jansen@cwi.nl>
parents: 33750
diff changeset
403 os.putenv('MACOSX_DEPLOYMENT_TARGET', cfg_target)
37801
4d82093e2e19 disutils checks if MACOSX_DEPLOYMENT_TARGET is consistent with the value at
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37788
diff changeset
404 elif map(int, cfg_target.split('.')) > map(int, cur_target.split('.')):
32218
fdf75eef6a5c Partial fix for #887242 (link extensions with dynamic_lookup in stead
Jack Jansen <jack.jansen@cwi.nl>
parents: 30772
diff changeset
405 my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: now "%s" but "%s" during configure'
fdf75eef6a5c Partial fix for #887242 (link extensions with dynamic_lookup in stead
Jack Jansen <jack.jansen@cwi.nl>
parents: 30772
diff changeset
406 % (cur_target, cfg_target))
fdf75eef6a5c Partial fix for #887242 (link extensions with dynamic_lookup in stead
Jack Jansen <jack.jansen@cwi.nl>
parents: 30772
diff changeset
407 raise DistutilsPlatformError(my_msg)
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32218
diff changeset
408
13034
f1e40abbedb3 Fixed LDSHARED for AIX, based on a patch by Rene Liebscher.
Greg Ward <gward@python.net>
parents: 13009
diff changeset
409 # 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
410 # -- 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
411 # 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
412 if python_build:
16841
3d29690a24e8 Placate tabnanny
Andrew M. Kuchling <amk@amk.ca>
parents: 16621
diff changeset
413 g['LDSHARED'] = g['BLDSHARED']
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19724
diff changeset
414
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
415 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
416 # 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
417 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
418 # 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
419 # 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
420 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
421 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
422 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
423
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
424 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
425
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
426 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
427 # 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
428 # 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
429 # 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
430 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
431 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
432 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
433 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
434 linkerscript_name)
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19724
diff changeset
435
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
436 # 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
437 # 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
438 # 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
439 # 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
440 # 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
441 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
442 (linkerscript, PREFIX, get_python_version()))
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19724
diff changeset
443
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
444 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
445 _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
446
9658
23237bcb774b Fred's sysconfig module.
Greg Ward <gward@python.net>
parents:
diff changeset
447
10926
f9c03b3d0f14 Now handles NT, through '_init_nt()' function (courtesy of
Greg Ward <gward@python.net>
parents: 9842
diff changeset
448 def _init_nt():
f9c03b3d0f14 Now handles NT, through '_init_nt()' function (courtesy of
Greg Ward <gward@python.net>
parents: 9842
diff changeset
449 """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
450 g = {}
10926
f9c03b3d0f14 Now handles NT, through '_init_nt()' function (courtesy of
Greg Ward <gward@python.net>
parents: 9842
diff changeset
451 # 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
452 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
453 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
454
11251
2f07bc56e97e Patch from Perry Stoll: tweaks to Windows support.
Greg Ward <gward@python.net>
parents: 10926
diff changeset
455 # 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
456 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
457
11721
eb381ff17a31 get_config_h_filename(): Support NT as well as Posix systems.
Fred Drake <fdrake@acm.org>
parents: 11689
diff changeset
458 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
459 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
460 g['VERSION'] = get_python_version().replace(".", "")
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
461 g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
462
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
463 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
464 _config_vars = g
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
465
11721
eb381ff17a31 get_config_h_filename(): Support NT as well as Posix systems.
Fred Drake <fdrake@acm.org>
parents: 11689
diff changeset
466
11935
c94572a50995 Patch from Corran Webster <cwebster@nevada.edu>: add '_init_mac()'.
Greg Ward <gward@python.net>
parents: 11721
diff changeset
467 def _init_mac():
c94572a50995 Patch from Corran Webster <cwebster@nevada.edu>: add '_init_mac()'.
Greg Ward <gward@python.net>
parents: 11721
diff changeset
468 """Initialize the module as appropriate for Macintosh 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
469 g = {}
11935
c94572a50995 Patch from Corran Webster <cwebster@nevada.edu>: add '_init_mac()'.
Greg Ward <gward@python.net>
parents: 11721
diff changeset
470 # 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
471 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
472 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
11935
c94572a50995 Patch from Corran Webster <cwebster@nevada.edu>: add '_init_mac()'.
Greg Ward <gward@python.net>
parents: 11721
diff changeset
473
c94572a50995 Patch from Corran Webster <cwebster@nevada.edu>: add '_init_mac()'.
Greg Ward <gward@python.net>
parents: 11721
diff changeset
474 # 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
475 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
11935
c94572a50995 Patch from Corran Webster <cwebster@nevada.edu>: add '_init_mac()'.
Greg Ward <gward@python.net>
parents: 11721
diff changeset
476
17846
9ff35f7661bd Made distutils understand the MacPython Carbon runtime model. Distutils will build for the runtime model you are currently using for the interpreter.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16841
diff changeset
477 import MacOS
9ff35f7661bd Made distutils understand the MacPython Carbon runtime model. Distutils will build for the runtime model you are currently using for the interpreter.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16841
diff changeset
478 if not hasattr(MacOS, 'runtimemodel'):
17847
7f4554a1cae2 Fixed botched indent in _init_mac() code. (It may never be executed,
Guido van Rossum <guido@python.org>
parents: 17846
diff changeset
479 g['SO'] = '.ppc.slb'
17846
9ff35f7661bd Made distutils understand the MacPython Carbon runtime model. Distutils will build for the runtime model you are currently using for the interpreter.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16841
diff changeset
480 else:
9ff35f7661bd Made distutils understand the MacPython Carbon runtime model. Distutils will build for the runtime model you are currently using for the interpreter.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16841
diff changeset
481 g['SO'] = '.%s.slb' % MacOS.runtimemodel
11952
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
482
e10515e7d356 Added Joe Van Andel's 'get_python_inc()', adapted by me to supply
Greg Ward <gward@python.net>
parents: 11935
diff changeset
483 # XXX are these used anywhere?
12315
f1f665e075ca Better variable names here and there.
Greg Ward <gward@python.net>
parents: 11953
diff changeset
484 g['install_lib'] = os.path.join(EXEC_PREFIX, "Lib")
f1f665e075ca Better variable names here and there.
Greg Ward <gward@python.net>
parents: 11953
diff changeset
485 g['install_platlib'] = os.path.join(EXEC_PREFIX, "Mac", "Lib")
11935
c94572a50995 Patch from Corran Webster <cwebster@nevada.edu>: add '_init_mac()'.
Greg Ward <gward@python.net>
parents: 11721
diff changeset
486
24007
00e578f78caa Fixed various MacPython-specific issues found by attempting to use the standard core setup.py for MacPython.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23671
diff changeset
487 # These are used by the extension module build
00e578f78caa Fixed various MacPython-specific issues found by attempting to use the standard core setup.py for MacPython.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23671
diff changeset
488 g['srcdir'] = ':'
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
489 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
490 _config_vars = g
9780
4b18f8eaa16b Another patch from Fred: factored _init_posix into
Greg Ward <gward@python.net>
parents: 9690
diff changeset
491
11721
eb381ff17a31 get_config_h_filename(): Support NT as well as Posix systems.
Fred Drake <fdrake@acm.org>
parents: 11689
diff changeset
492
21851
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
493 def _init_os2():
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
494 """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
495 g = {}
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
496 # set basic install directories
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
497 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
498 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
499
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
500 # 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
501 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
502
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
503 g['SO'] = '.pyd'
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
504 g['EXE'] = ".exe"
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
505
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
506 global _config_vars
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
507 _config_vars = g
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
508
e0fc286d57a4 OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents: 21267
diff changeset
509
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
510 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
511 """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
512 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
513 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
514 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
515 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
516
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
517 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
518 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
519 """
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
520 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
521 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
522 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
523 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
524 func()
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
525 else:
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
526 _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
527
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
528 # 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
529 # 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
530 # Distutils.
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
531 _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
532 _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
533
51343
f4012e78260c Fix get_python_inc() to work when building in a directory separate from
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 47473
diff changeset
534 if 'srcdir' not in _config_vars:
f4012e78260c Fix get_python_inc() to work when building in a directory separate from
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 47473
diff changeset
535 _config_vars['srcdir'] = project_base
f4012e78260c Fix get_python_inc() to work when building in a directory separate from
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 47473
diff changeset
536
51405
baa88e9e9766 Convert "srcdir" into an absolute path if that seems prudent. Currrently
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51374
diff changeset
537 # Convert srcdir into an absolute path if it appears necessary.
baa88e9e9766 Convert "srcdir" into an absolute path if that seems prudent. Currrently
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51374
diff changeset
538 # Normally it is relative to the build directory. However, during
baa88e9e9766 Convert "srcdir" into an absolute path if that seems prudent. Currrently
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51374
diff changeset
539 # testing, for example, we might be running a non-installed python
baa88e9e9766 Convert "srcdir" into an absolute path if that seems prudent. Currrently
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51374
diff changeset
540 # from a different directory.
baa88e9e9766 Convert "srcdir" into an absolute path if that seems prudent. Currrently
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51374
diff changeset
541 if python_build and os.name == "posix":
baa88e9e9766 Convert "srcdir" into an absolute path if that seems prudent. Currrently
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51374
diff changeset
542 base = os.path.dirname(os.path.abspath(sys.executable))
baa88e9e9766 Convert "srcdir" into an absolute path if that seems prudent. Currrently
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51374
diff changeset
543 if (not os.path.isabs(_config_vars['srcdir']) and
baa88e9e9766 Convert "srcdir" into an absolute path if that seems prudent. Currrently
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51374
diff changeset
544 base != os.getcwd()):
baa88e9e9766 Convert "srcdir" into an absolute path if that seems prudent. Currrently
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51374
diff changeset
545 # srcdir is relative and we are not in the same directory
baa88e9e9766 Convert "srcdir" into an absolute path if that seems prudent. Currrently
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51374
diff changeset
546 # as the executable. Assume executable is in the build
baa88e9e9766 Convert "srcdir" into an absolute path if that seems prudent. Currrently
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51374
diff changeset
547 # directory and make srcdir absolute.
baa88e9e9766 Convert "srcdir" into an absolute path if that seems prudent. Currrently
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51374
diff changeset
548 srcdir = os.path.join(base, _config_vars['srcdir'])
baa88e9e9766 Convert "srcdir" into an absolute path if that seems prudent. Currrently
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51374
diff changeset
549 _config_vars['srcdir'] = os.path.normpath(srcdir)
baa88e9e9766 Convert "srcdir" into an absolute path if that seems prudent. Currrently
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 51374
diff changeset
550
38248
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
551 if sys.platform == 'darwin':
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
552 kernel_version = os.uname()[2] # Kernel version (8.4.3)
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
553 major_version = int(kernel_version.split('.')[0])
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
554
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
555 if major_version < 8:
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
556 # On Mac OS X before 10.4, check if -arch and -isysroot
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
557 # are in CFLAGS or LDFLAGS and remove them if they are.
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
558 # This is needed when building extensions on a 10.3 system
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
559 # using a universal build of python.
40055
83965977f34a MacOSX: distutils changes the values of BASECFLAGS and LDFLAGS when using a
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38944
diff changeset
560 for key in ('LDFLAGS', 'BASECFLAGS',
83965977f34a MacOSX: distutils changes the values of BASECFLAGS and LDFLAGS when using a
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38944
diff changeset
561 # 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
562 # 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
563 'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
38248
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
564 flags = _config_vars[key]
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
565 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
566 flags = re.sub('-isysroot [^ \t]*', ' ', flags)
38248
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
567 _config_vars[key] = flags
3078fdb7cf3d Patch #1488098.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38040
diff changeset
568
47473
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
569 else:
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
570
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
571 # 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
572 # an environment variable.
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
573 # 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
574 # 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
575 # that OS release.
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
576
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
577 if 'ARCHFLAGS' in os.environ:
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
578 arch = os.environ['ARCHFLAGS']
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
579 for key in ('LDFLAGS', 'BASECFLAGS',
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
580 # a number of derived variables. These need to be
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
581 # patched up as well.
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
582 'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
583
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
584 flags = _config_vars[key]
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
585 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
586 flags = flags + ' ' + arch
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
587 _config_vars[key] = flags
c34e34057714 MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45913
diff changeset
588
14572
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
589 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
590 vals = []
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
591 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
592 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
593 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
594 else:
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 _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
596
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
597 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
598 """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
599 returned by 'get_config_vars()'. Equivalent to
18945
f8fdd5083af3 Miscellaneous minor cleanups.
Fred Drake <fdrake@acm.org>
parents: 18837
diff changeset
600 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
601 """
25b7ac05689e Changed from eager parsing of Makefile (at import time) to lazy: only do
Greg Ward <gward@python.net>
parents: 14571
diff changeset
602 return get_config_vars().get(name)