Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(15)

Delta Between Two Patch Sets: Lib/distutils/sysconfig.py

Issue 3871: cross and native build of python for mingw32 with distutils
Left Patch Set: Created 9 years, 6 months ago
Right Patch Set: Created 7 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/distutils/cygwinccompiler.py ('k') | Lib/distutils/tests/support.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 """Provide access to Python's configuration information. The specific 1 """Provide access to Python's configuration information. The specific
2 configuration variables available depend heavily on the platform and 2 configuration variables available depend heavily on the platform and
3 configuration. The values may be retrieved using 3 configuration. The values may be retrieved using
4 get_config_var(name), and the list of variables is available via 4 get_config_var(name), and the list of variables is available via
5 get_config_vars().keys(). Additional convenience functions are also 5 get_config_vars().keys(). Additional convenience functions are also
6 available. 6 available.
7 7
8 Written by: Fred L. Drake, Jr. 8 Written by: Fred L. Drake, Jr.
9 Email: <fdrake@acm.org> 9 Email: <fdrake@acm.org>
10 """ 10 """
11 11
12 __revision__ = "$Id$"
13
14 import io
15 import os 12 import os
16 import re 13 import re
17 import sys 14 import sys
18 15
19 from .errors import DistutilsPlatformError 16 from .errors import DistutilsPlatformError
20 17
21 # These are needed in a couple of spots, so just compute them once. 18 # These are needed in a couple of spots, so just compute them once.
22 PREFIX = os.path.normpath(sys.prefix) 19 PREFIX = os.path.normpath(sys.prefix)
23 EXEC_PREFIX = os.path.normpath(sys.exec_prefix) 20 EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
21 BASE_PREFIX = os.path.normpath(sys.base_prefix)
22 BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
24 23
25 # Path to the base directory of the project. On Windows the binary may 24 # Path to the base directory of the project. On Windows the binary may
26 # live in project/PCBuild9. If we're dealing with an x64 Windows build, 25 # live in project/PCBuild9. If we're dealing with an x64 Windows build,
27 # it'll live in project/PCbuild/amd64. 26 # it'll live in project/PCbuild/amd64.
28 project_base = os.path.dirname(os.path.abspath(sys.executable)) 27 project_base = os.path.dirname(os.path.abspath(sys.executable))
29 if os.name == "nt" and "pcbuild" in project_base[-8:].lower(): 28 if os.name == "nt" and "pcbuild" in project_base[-8:].lower():
30 project_base = os.path.abspath(os.path.join(project_base, os.path.pardir)) 29 project_base = os.path.abspath(os.path.join(project_base, os.path.pardir))
31 # PC/VS7.1 30 # PC/VS7.1
32 if os.name == "nt" and "\\pc\\v" in project_base[-10:].lower(): 31 if os.name == "nt" and "\\pc\\v" in project_base[-10:].lower():
33 project_base = os.path.abspath(os.path.join(project_base, os.path.pardir, 32 project_base = os.path.abspath(os.path.join(project_base, os.path.pardir,
34 os.path.pardir)) 33 os.path.pardir))
35 # PC/AMD64 34 # PC/AMD64
36 if os.name == "nt" and "\\pcbuild\\amd64" in project_base[-14:].lower(): 35 if os.name == "nt" and "\\pcbuild\\amd64" in project_base[-14:].lower():
37 project_base = os.path.abspath(os.path.join(project_base, os.path.pardir, 36 project_base = os.path.abspath(os.path.join(project_base, os.path.pardir,
38 os.path.pardir)) 37 os.path.pardir))
39 38
40 # python_build: (Boolean) if true, we're either building Python or 39 # python_build: (Boolean) if true, we're either building Python or
41 # building an extension with an un-installed Python, so we use 40 # building an extension with an un-installed Python, so we use
42 # different (hard-wired) directories. 41 # different (hard-wired) directories.
43 # Setup.local is available for Makefile builds including VPATH builds, 42 # Setup.local is available for Makefile builds including VPATH builds,
44 # Setup.dist is available on Windows 43 # Setup.dist is available on Windows
45 def _python_build(): 44 def _is_python_source_dir(d):
46 for fn in ("Setup.dist", "Setup.local"): 45 for fn in ("Setup.dist", "Setup.local"):
47 if os.path.isfile(os.path.join(project_base, "Modules", fn)): 46 if os.path.isfile(os.path.join(d, "Modules", fn)):
48 return True 47 return True
49 return False 48 return False
49 _sys_home = getattr(sys, '_home', None)
50 if _sys_home and os.name == 'nt' and \
51 _sys_home.lower().endswith(('pcbuild', 'pcbuild\\amd64')):
52 _sys_home = os.path.dirname(_sys_home)
53 if _sys_home.endswith('pcbuild'): # must be amd64
54 _sys_home = os.path.dirname(_sys_home)
55 def _python_build():
56 if _sys_home:
57 return _is_python_source_dir(_sys_home)
58 return _is_python_source_dir(project_base)
50 python_build = _python_build() 59 python_build = _python_build()
60
61 # Calculate the build qualifier flags if they are defined. Adding the flags
62 # to the include and lib directories only makes sense for an installation, not
63 # an in-source build.
64 build_flags = ''
65 try:
66 if not python_build:
67 build_flags = sys.abiflags
68 except AttributeError:
69 # It's not a configure-based build, so the sys module doesn't have
70 # this attribute, which is fine.
71 pass
51 72
52 def get_python_version(): 73 def get_python_version():
53 """Return a string containing the major and minor Python version, 74 """Return a string containing the major and minor Python version,
54 leaving off the patchlevel. Sample return values could be '1.5' 75 leaving off the patchlevel. Sample return values could be '1.5'
55 or '2.2'. 76 or '2.2'.
56 """ 77 """
57 return sys.version[:3] 78 return sys.version[:3]
58 79
59 80
60 def get_python_inc(plat_specific=0, prefix=None): 81 def get_python_inc(plat_specific=0, prefix=None):
61 """Return the directory containing installed Python header files. 82 """Return the directory containing installed Python header files.
62 83
63 If 'plat_specific' is false (the default), this is the path to the 84 If 'plat_specific' is false (the default), this is the path to the
64 non-platform-specific header files, i.e. Python.h and so on; 85 non-platform-specific header files, i.e. Python.h and so on;
65 otherwise, this is the path to platform-specific header files 86 otherwise, this is the path to platform-specific header files
66 (namely pyconfig.h). 87 (namely pyconfig.h).
67 88
68 If 'prefix' is supplied, use it instead of sys.prefix or 89 If 'prefix' is supplied, use it instead of sys.base_prefix or
69 sys.exec_prefix -- i.e., ignore 'plat_specific'. 90 sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
70 """ 91 """
71 if prefix is None: 92 if prefix is None:
72 prefix = plat_specific and EXEC_PREFIX or PREFIX 93 prefix = plat_specific and BASE_PREFIX or BASE_EXEC_PREFIX
73 if os.name == "posix" or 'msys' in sys.builtin_module_names: 94 # GCC(mingw): os.name is "nt" but build system is posix
95 if os.name == "posix" or sys.version.upper().find('GCC') >= 0:
74 if python_build: 96 if python_build:
75 # Assume the executable is in the build directory. The 97 # Assume the executable is in the build directory. The
76 # pyconfig.h file should be in the same directory. Since 98 # pyconfig.h file should be in the same directory. Since
77 # the build directory may not be the source directory, we 99 # the build directory may not be the source directory, we
78 # must use "srcdir" from the makefile to find the "Include" 100 # must use "srcdir" from the makefile to find the "Include"
79 # directory. 101 # directory.
80 base = os.path.dirname(os.path.abspath(sys.executable)) 102 base = _sys_home or os.path.dirname(os.path.abspath(sys.executable))
81 if plat_specific: 103 if plat_specific:
82 return base 104 return base
105 if _sys_home:
106 incdir = os.path.join(_sys_home, get_config_var('AST_H_DIR'))
83 else: 107 else:
84 incdir = os.path.join(get_config_var('srcdir'), 'Include') 108 incdir = os.path.join(get_config_var('srcdir'), 'Include')
85 return os.path.normpath(incdir) 109 return os.path.normpath(incdir)
86 return os.path.join(prefix, "include", "python" + get_python_version()) 110 # TODO mingw build as get_python_version() return dot separated value
111 python_dir = 'python' + get_python_version() + build_flags
112 return os.path.join(prefix, "include", python_dir)
87 elif os.name == "nt": 113 elif os.name == "nt":
88 return os.path.join(prefix, "include") 114 return os.path.join(prefix, "include")
89 elif os.name == "mac":
90 if plat_specific:
91 return os.path.join(prefix, "Mac", "Include")
92 else:
93 return os.path.join(prefix, "Include")
94 elif os.name == "os2": 115 elif os.name == "os2":
95 return os.path.join(prefix, "Include") 116 return os.path.join(prefix, "Include")
96 else: 117 else:
97 raise DistutilsPlatformError( 118 raise DistutilsPlatformError(
98 "I don't know where Python installs its C header files " 119 "I don't know where Python installs its C header files "
99 "on platform '%s'" % os.name) 120 "on platform '%s'" % os.name)
100 121
101 122
102 def get_python_lib(plat_specific=0, standard_lib=0, prefix=None): 123 def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
103 """Return the directory containing the Python library (standard or 124 """Return the directory containing the Python library (standard or
104 site additions). 125 site additions).
105 126
106 If 'plat_specific' is true, return the directory containing 127 If 'plat_specific' is true, return the directory containing
107 platform-specific modules, i.e. any module from a non-pure-Python 128 platform-specific modules, i.e. any module from a non-pure-Python
108 module distribution; otherwise, return the platform-shared library 129 module distribution; otherwise, return the platform-shared library
109 directory. If 'standard_lib' is true, return the directory 130 directory. If 'standard_lib' is true, return the directory
110 containing standard Python library modules; otherwise, return the 131 containing standard Python library modules; otherwise, return the
111 directory for site-specific modules. 132 directory for site-specific modules.
112 133
113 If 'prefix' is supplied, use it instead of sys.prefix or 134 If 'prefix' is supplied, use it instead of sys.base_prefix or
114 sys.exec_prefix -- i.e., ignore 'plat_specific'. 135 sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
115 """ 136 """
137 # GCC(mingw): os.name is "nt" but build system is posix
138 posix_build = os.name == "posix" or sys.version.upper().find('GCC') >= 0
139
116 if prefix is None: 140 if prefix is None:
117 prefix = plat_specific and EXEC_PREFIX or PREFIX 141 if standard_lib:
118 142 prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
119 if os.name == "posix": 143 else:
144 prefix = plat_specific and EXEC_PREFIX or PREFIX
145
146 if posix_build:
120 libpython = os.path.join(prefix, 147 libpython = os.path.join(prefix,
121 "lib", "python" + get_python_version()) 148 "lib", "python" + get_python_version())
122 if standard_lib: 149 if standard_lib:
123 return libpython 150 return libpython
124 else: 151 else:
125 return os.path.join(libpython, "site-packages") 152 return os.path.join(libpython, "site-packages")
126 elif os.name == "nt" and 'msys' in sys.builtin_module_names: 153 elif os.name == "nt":
127 libpython = os.path.join(prefix,
128 "lib", "python" + get_python_version())
129 if standard_lib:
130 if python_build:
131 return os.path.abspath(sys.executable)
132 return libpython
133 else:
134 return os.path.join(libpython, "site-packages")
135 elif os.name == "nt" and 'msys' not in sys.builtin_module_names:
136 if standard_lib: 154 if standard_lib:
137 return os.path.join(prefix, "Lib") 155 return os.path.join(prefix, "Lib")
138 else: 156 else:
139 if get_python_version() < "2.2": 157 if get_python_version() < "2.2":
140 return prefix 158 return prefix
141 else:
142 return os.path.join(prefix, "Lib", "site-packages")
143 elif os.name == "mac":
144 if plat_specific:
145 if standard_lib:
146 return os.path.join(prefix, "Lib", "lib-dynload")
147 else:
148 return os.path.join(prefix, "Lib", "site-packages")
149 else:
150 if standard_lib:
151 return os.path.join(prefix, "Lib")
152 else: 159 else:
153 return os.path.join(prefix, "Lib", "site-packages") 160 return os.path.join(prefix, "Lib", "site-packages")
154 elif os.name == "os2": 161 elif os.name == "os2":
155 if standard_lib: 162 if standard_lib:
156 return os.path.join(prefix, "Lib") 163 return os.path.join(prefix, "Lib")
157 else: 164 else:
158 return os.path.join(prefix, "Lib", "site-packages") 165 return os.path.join(prefix, "Lib", "site-packages")
159 else: 166 else:
160 raise DistutilsPlatformError( 167 raise DistutilsPlatformError(
161 "I don't know where Python installs its library " 168 "I don't know where Python installs its library "
162 "on platform '%s'" % os.name) 169 "on platform '%s'" % os.name)
163 170
164 171
172
165 def customize_compiler(compiler): 173 def customize_compiler(compiler):
166 """Do any platform-specific customization of a CCompiler instance. 174 """Do any platform-specific customization of a CCompiler instance.
167 175
168 Mainly needed on Unix, so we can plug in the information that 176 Mainly needed on Unix, so we can plug in the information that
169 varies across Unices and is stored in Python's Makefile. 177 varies across Unices and is stored in Python's Makefile.
170 """ 178
179 NOTE (known limitation of python build/install system):
180 In cross-build environment make macros like CC and LDSHARED
181 contain cross-compiler/linker instead of host compiler/linker.
182 """
183 posix_build = None
171 if compiler.compiler_type == "unix": 184 if compiler.compiler_type == "unix":
185 posix_build = True
186 if sys.platform == "darwin":
187 # Perform first-time customization of compiler-related
188 # config vars on OS X now that we know we need a compiler.
189 # This is primarily to support Pythons from binary
190 # installers. The kind and paths to build tools on
191 # the user system may vary significantly from the system
192 # that Python itself was built on. Also the user OS
193 # version and build tools may not support the same set
194 # of CPU architectures for universal builds.
195 global _config_vars
196 if not _config_vars.get('CUSTOMIZED_OSX_COMPILER', ''):
197 import _osx_support
198 _osx_support.customize_compiler(_config_vars)
199 _config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'
200 elif compiler.compiler_type == "mingw32":
201 # GCC(mingw): if build system is posix
202 if sys.version.upper().find('GCC') >= 0:
203 posix_build = True
204
205 if posix_build == True:
172 (cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \ 206 (cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \
173 get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS', 207 get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
174 'CCSHARED', 'LDSHARED', 'SO', 'AR', 'ARFLAGS') 208 'CCSHARED', 'LDSHARED', 'SO', 'AR', 'ARFLAGS')
175 209
210 newcc = None
176 if 'CC' in os.environ: 211 if 'CC' in os.environ:
177 cc = os.environ['CC'] 212 cc = os.environ['CC']
178 if 'CXX' in os.environ: 213 if 'CXX' in os.environ:
179 cxx = os.environ['CXX'] 214 cxx = os.environ['CXX']
180 if 'LDSHARED' in os.environ: 215 if 'LDSHARED' in os.environ:
181 ldshared = os.environ['LDSHARED'] 216 ldshared = os.environ['LDSHARED']
182 if 'CPP' in os.environ: 217 if 'CPP' in os.environ:
183 cpp = os.environ['CPP'] 218 cpp = os.environ['CPP']
184 else: 219 else:
185 cpp = cc + " -E" # not always 220 cpp = cc + " -E" # not always
(...skipping 22 matching lines...) Expand all
208 linker_so=ldshared, 243 linker_so=ldshared,
209 linker_exe=cc, 244 linker_exe=cc,
210 archiver=archiver) 245 archiver=archiver)
211 246
212 compiler.shared_lib_extension = so_ext 247 compiler.shared_lib_extension = so_ext
213 248
214 249
215 def get_config_h_filename(): 250 def get_config_h_filename():
216 """Return full pathname of installed pyconfig.h file.""" 251 """Return full pathname of installed pyconfig.h file."""
217 if python_build: 252 if python_build:
218 if os.name == "nt" and 'msys' not in sys.builtin_module_names: 253 # GCC(mingw): os.name is "nt" but build system is posix
219 inc_dir = os.path.join(project_base, "PC") 254 if os.name == "nt" and sys.version.upper().find('GCC') < 0:
220 else: 255 inc_dir = os.path.join(_sys_home or project_base, "PC")
221 inc_dir = project_base 256 else:
257 inc_dir = _sys_home or project_base
222 else: 258 else:
223 inc_dir = get_python_inc(plat_specific=1) 259 inc_dir = get_python_inc(plat_specific=1)
224 if get_python_version() < '2.2': 260 if get_python_version() < '2.2':
225 config_h = 'config.h' 261 config_h = 'config.h'
226 else: 262 else:
227 # The name of the config.h file changed in 2.2 263 # The name of the config.h file changed in 2.2
228 config_h = 'pyconfig.h' 264 config_h = 'pyconfig.h'
229 return os.path.join(inc_dir, config_h) 265 return os.path.join(inc_dir, config_h)
230 266
231 267
232 def get_makefile_filename(): 268 def get_makefile_filename():
233 """Return full pathname of installed Makefile from the Python build.""" 269 """Return full pathname of installed Makefile from the Python build."""
234 if python_build: 270 if python_build:
235 return os.path.join(os.path.dirname(sys.executable), "Makefile") 271 return os.path.join(_sys_home or os.path.dirname(sys.executable),
236 lib_dir = get_python_lib(plat_specific=1, standard_lib=1) 272 "Makefile")
237 return os.path.join(lib_dir, "config", "Makefile") 273 lib_dir = get_python_lib(plat_specific=0, standard_lib=1)
274 config_file = 'config-{}{}'.format(get_python_version(), build_flags)
275 return os.path.join(lib_dir, config_file, 'Makefile')
238 276
239 277
240 def parse_config_h(fp, g=None): 278 def parse_config_h(fp, g=None):
241 """Parse a config.h-style file. 279 """Parse a config.h-style file.
242 280
243 A dictionary containing name/value pairs is returned. If an 281 A dictionary containing name/value pairs is returned. If an
244 optional dictionary is passed in as the second argument, it is 282 optional dictionary is passed in as the second argument, it is
245 used instead of a new dictionary. 283 used instead of a new dictionary.
246 """ 284 """
247 if g is None: 285 if g is None:
(...skipping 25 matching lines...) Expand all
273 _findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}") 311 _findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
274 312
275 def parse_makefile(fn, g=None): 313 def parse_makefile(fn, g=None):
276 """Parse a Makefile-style file. 314 """Parse a Makefile-style file.
277 315
278 A dictionary containing name/value pairs is returned. If an 316 A dictionary containing name/value pairs is returned. If an
279 optional dictionary is passed in as the second argument, it is 317 optional dictionary is passed in as the second argument, it is
280 used instead of a new dictionary. 318 used instead of a new dictionary.
281 """ 319 """
282 from distutils.text_file import TextFile 320 from distutils.text_file import TextFile
283 fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1) 321 fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1, errors="sur rogateescape")
284 322
285 if g is None: 323 if g is None:
286 g = {} 324 g = {}
287 done = {} 325 done = {}
288 notdone = {} 326 notdone = {}
289 327
290 while True: 328 while True:
291 line = fp.readline() 329 line = fp.readline()
292 if line is None: # eof 330 if line is None: # eof
293 break 331 break
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 399
362 name = name[3:] 400 name = name[3:]
363 if name not in done: 401 if name not in done:
364 done[name] = value 402 done[name] = value
365 else: 403 else:
366 # bogus variable reference; just drop it since we can't deal 404 # bogus variable reference; just drop it since we can't deal
367 del notdone[name] 405 del notdone[name]
368 406
369 fp.close() 407 fp.close()
370 408
409 # strip spurious spaces
410 for k, v in done.items():
411 if isinstance(v, str):
412 done[k] = v.strip()
413
371 # save the results in the global dictionary 414 # save the results in the global dictionary
372 g.update(done) 415 g.update(done)
373 return g 416 return g
374 417
375 418
376 def expand_makefile_vars(s, vars): 419 def expand_makefile_vars(s, vars):
377 """Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in 420 """Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
378 'string' according to 'vars' (a dictionary mapping variable names to 421 'string' according to 'vars' (a dictionary mapping variable names to
379 values). Variables not present in 'vars' are silently expanded to the 422 values). Variables not present in 'vars' are silently expanded to the
380 empty string. The variable values in 'vars' should not contain further 423 empty string. The variable values in 'vars' should not contain further
(...skipping 29 matching lines...) Expand all
410 except IOError as msg: 453 except IOError as msg:
411 my_msg = "invalid Python installation: unable to open %s" % filename 454 my_msg = "invalid Python installation: unable to open %s" % filename
412 if hasattr(msg, "strerror"): 455 if hasattr(msg, "strerror"):
413 my_msg = my_msg + " (%s)" % msg.strerror 456 my_msg = my_msg + " (%s)" % msg.strerror
414 457
415 raise DistutilsPlatformError(my_msg) 458 raise DistutilsPlatformError(my_msg)
416 459
417 # load the installed pyconfig.h: 460 # load the installed pyconfig.h:
418 try: 461 try:
419 filename = get_config_h_filename() 462 filename = get_config_h_filename()
420 parse_config_h(io.open(filename), g) 463 with open(filename) as file:
464 parse_config_h(file, g)
421 except IOError as msg: 465 except IOError as msg:
422 my_msg = "invalid Python installation: unable to open %s" % filename 466 my_msg = "invalid Python installation: unable to open %s" % filename
423 if hasattr(msg, "strerror"): 467 if hasattr(msg, "strerror"):
424 my_msg = my_msg + " (%s)" % msg.strerror 468 my_msg = my_msg + " (%s)" % msg.strerror
425 469
426 raise DistutilsPlatformError(my_msg) 470 raise DistutilsPlatformError(my_msg)
427
428 # On MacOSX we need to check the setting of the environment variable
429 # MACOSX_DEPLOYMENT_TARGET: configure bases some choices on it so
430 # it needs to be compatible.
431 # If it isn't set we set it to the configure-time value
432 if sys.platform == 'darwin' and 'MACOSX_DEPLOYMENT_TARGET' in g:
433 cfg_target = g['MACOSX_DEPLOYMENT_TARGET']
434 cur_target = os.getenv('MACOSX_DEPLOYMENT_TARGET', '')
435 if cur_target == '':
436 cur_target = cfg_target
437 os.putenv('MACOSX_DEPLOYMENT_TARGET', cfg_target)
438 elif [int(x) for x in cfg_target.split('.')] > [int(x) for x in cur_targ et.split('.')]:
439 my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: now "%s" but "%s" dur ing configure'
440 % (cur_target, cfg_target))
441 raise DistutilsPlatformError(my_msg)
442 471
443 # On AIX, there are wrong paths to the linker scripts in the Makefile 472 # On AIX, there are wrong paths to the linker scripts in the Makefile
444 # -- these paths are relative to the Python source, but when installed 473 # -- these paths are relative to the Python source, but when installed
445 # the scripts are in another directory. 474 # the scripts are in another directory.
446 if python_build: 475 if python_build:
447 g['LDSHARED'] = g['BLDSHARED'] 476 g['LDSHARED'] = g['BLDSHARED']
448 477
449 elif get_python_version() < '2.1': 478 elif get_python_version() < '2.1':
450 # The following two branches are for 1.5.2 compatibility. 479 # The following two branches are for 1.5.2 compatibility.
451 if sys.platform == 'aix4': # what about AIX 3.x ? 480 if sys.platform == 'aix4': # what about AIX 3.x ?
452 # Linker script is in the config directory, not in Modules as the 481 # Linker script is in the config directory, not in Modules as the
453 # Makefile says. 482 # Makefile says.
454 python_lib = get_python_lib(standard_lib=1) 483 python_lib = get_python_lib(standard_lib=1)
455 ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix') 484 ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
456 python_exp = os.path.join(python_lib, 'config', 'python.exp') 485 python_exp = os.path.join(python_lib, 'config', 'python.exp')
457 486
458 g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp) 487 g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp)
459 488
460 global _config_vars 489 global _config_vars
461 _config_vars = g 490 _config_vars = g
462 491
463 def _init_msys(): 492
464 """Initialize the module as appropriate for NT/MSys""" 493 def _init_nt():
465 global _config_vars 494 """Initialize the module as appropriate for NT"""
495 if sys.version.upper().find('GCC') >= 0:
496 # GCC(mingw) use posix build system
497 # FIXME: may be modification has to be in get_config_vars ?
498 _init_posix()
499 return
466 g = {} 500 g = {}
467 # set basic install directories 501 # set basic install directories
468 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1) 502 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
469 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1) 503 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
470 504
505 # XXX hmmm.. a normal install puts include files here
506 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
507
471 g['SO'] = '.pyd' 508 g['SO'] = '.pyd'
472 g['EXE'] = ".exe" 509 g['EXE'] = ".exe"
473 g['VERSION'] = get_python_version().replace(".", "") 510 g['VERSION'] = get_python_version().replace(".", "")
474 g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable)) 511 g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
475 512
476 _init_posix()
477 _config_vars.update (g)
478
479 # _init_posix will set it to '.dll'
480 _config_vars['SO'] = '.pyd'
481
482 def _init_nt():
483 """Initialize the module as appropriate for NT"""
484 g = {}
485 # set basic install directories
486 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
487 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
488
489 # XXX hmmm.. a normal install puts include files here
490 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
491
492 g['SO'] = '.pyd'
493 g['EXE'] = ".exe"
494 g['VERSION'] = get_python_version().replace(".", "")
495 g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
496
497 global _config_vars
498 _config_vars = g
499
500
501 def _init_mac():
502 """Initialize the module as appropriate for Macintosh systems"""
503 g = {}
504 # set basic install directories
505 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
506 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
507
508 # XXX hmmm.. a normal install puts include files here
509 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
510
511 import MacOS
512 if not hasattr(MacOS, 'runtimemodel'):
513 g['SO'] = '.ppc.slb'
514 else:
515 g['SO'] = '.%s.slb' % MacOS.runtimemodel
516
517 # XXX are these used anywhere?
518 g['install_lib'] = os.path.join(EXEC_PREFIX, "Lib")
519 g['install_platlib'] = os.path.join(EXEC_PREFIX, "Mac", "Lib")
520
521 # These are used by the extension module build
522 g['srcdir'] = ':'
523 global _config_vars 513 global _config_vars
524 _config_vars = g 514 _config_vars = g
525 515
526 516
527 def _init_os2(): 517 def _init_os2():
528 """Initialize the module as appropriate for OS/2""" 518 """Initialize the module as appropriate for OS/2"""
529 g = {} 519 g = {}
530 # set basic install directories 520 # set basic install directories
531 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1) 521 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
532 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1) 522 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
533 523
534 # XXX hmmm.. a normal install puts include files here 524 # XXX hmmm.. a normal install puts include files here
535 g['INCLUDEPY'] = get_python_inc(plat_specific=0) 525 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
536 526
537 g['SO'] = '.pyd' 527 g['SO'] = '.pyd'
538 g['EXE'] = ".exe" 528 g['EXE'] = ".exe"
539 529
540 global _config_vars 530 global _config_vars
541 _config_vars = g 531 _config_vars = g
542 532
543 533
544 def get_config_vars(*args): 534 def get_config_vars(*args):
545 """With no arguments, return a dictionary of all configuration 535 """With no arguments, return a dictionary of all configuration
546 variables relevant for the current platform. Generally this includes 536 variables relevant for the current platform. Generally this includes
547 everything needed to build extensions and install both pure modules and 537 everything needed to build extensions and install both pure modules and
548 extensions. On Unix, this means every variable defined in Python's 538 extensions. On Unix, this means every variable defined in Python's
549 installed Makefile; on Windows and Mac OS it's a much smaller set. 539 installed Makefile; on Windows it's a much smaller set.
550 540
551 With arguments, return a list of values that result from looking up 541 With arguments, return a list of values that result from looking up
552 each argument in the configuration variable dictionary. 542 each argument in the configuration variable dictionary.
553 """ 543 """
544
554 global _config_vars 545 global _config_vars
555 if _config_vars is None: 546 if _config_vars is None:
556 if 'msys' in sys.builtin_module_names: 547 func = globals().get("_init_" + os.name)
557 func = globals().get("_init_msys")
558 else:
559 func = globals().get("_init_" + os.name)
560 if func: 548 if func:
561 func() 549 func()
562 else: 550 else:
563 _config_vars = {} 551 _config_vars = {}
564 552
565 # Normalized versions of prefix and exec_prefix are handy to have; 553 # Normalized versions of prefix and exec_prefix are handy to have;
566 # in fact, these are the standard versions used most places in the 554 # in fact, these are the standard versions used most places in the
567 # Distutils. 555 # Distutils.
568 _config_vars['prefix'] = PREFIX 556 _config_vars['prefix'] = PREFIX
569 _config_vars['exec_prefix'] = EXEC_PREFIX 557 _config_vars['exec_prefix'] = EXEC_PREFIX
570 558
559 # GCC(mingw): os.name is "nt" but build system is posix
560 posix_build = os.name == "posix" or sys.version.upper().find('GCC') >= 0
561
562 # Always convert srcdir to an absolute path
563 srcdir = _config_vars.get('srcdir', project_base)
564 if posix_build:
565 if python_build:
566 # If srcdir is a relative path (typically '.' or '..')
567 # then it should be interpreted relative to the directory
568 # containing Makefile.
569 base = os.path.dirname(get_makefile_filename())
570 srcdir = os.path.join(base, srcdir)
571 else:
572 # srcdir is not meaningful since the installation is
573 # spread about the filesystem. We choose the
574 # directory containing the Makefile since we know it
575 # exists.
576 srcdir = os.path.dirname(get_makefile_filename())
577 _config_vars['srcdir'] = os.path.abspath(os.path.normpath(srcdir))
578
571 # Convert srcdir into an absolute path if it appears necessary. 579 # Convert srcdir into an absolute path if it appears necessary.
572 # Normally it is relative to the build directory. However, during 580 # Normally it is relative to the build directory. However, during
573 # testing, for example, we might be running a non-installed python 581 # testing, for example, we might be running a non-installed python
574 # from a different directory. 582 # from a different directory.
575 if python_build and (os.name == "posix" or 'msys' in sys.builtin_module_ names): 583 if python_build and posix_build:
576 base = os.path.dirname(os.path.abspath(sys.executable)) 584 base = os.path.dirname(os.path.abspath(sys.executable))
577 if (not os.path.isabs(_config_vars['srcdir']) and 585 if (not os.path.isabs(_config_vars['srcdir']) and
578 base != os.getcwd()): 586 base != os.getcwd()):
579 # srcdir is relative and we are not in the same directory 587 # srcdir is relative and we are not in the same directory
580 # as the executable. Assume executable is in the build 588 # as the executable. Assume executable is in the build
581 # directory and make srcdir absolute. 589 # directory and make srcdir absolute.
582 srcdir = os.path.join(base, _config_vars['srcdir']) 590 srcdir = os.path.join(base, _config_vars['srcdir'])
583 _config_vars['srcdir'] = os.path.normpath(srcdir) 591 _config_vars['srcdir'] = os.path.normpath(srcdir)
584 592
593 # OS X platforms require special customization to handle
594 # multi-architecture, multi-os-version installers
585 if sys.platform == 'darwin': 595 if sys.platform == 'darwin':
586 kernel_version = os.uname()[2] # Kernel version (8.4.3) 596 import _osx_support
587 major_version = int(kernel_version.split('.')[0]) 597 _osx_support.customize_config_vars(_config_vars)
588
589 if major_version < 8:
590 # On Mac OS X before 10.4, check if -arch and -isysroot
591 # are in CFLAGS or LDFLAGS and remove them if they are.
592 # This is needed when building extensions on a 10.3 system
593 # using a universal build of python.
594 for key in ('LDFLAGS', 'BASECFLAGS',
595 # a number of derived variables. These need to be
596 # patched up as well.
597 'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
598 flags = _config_vars[key]
599 flags = re.sub('-arch\s+\w+\s', ' ', flags, re.ASCII)
600 flags = re.sub('-isysroot [^ \t]*', ' ', flags)
601 _config_vars[key] = flags
602
603 else:
604
605 # Allow the user to override the architecture flags using
606 # an environment variable.
607 # NOTE: This name was introduced by Apple in OSX 10.5 and
608 # is used by several scripting languages distributed with
609 # that OS release.
610
611 if 'ARCHFLAGS' in os.environ:
612 arch = os.environ['ARCHFLAGS']
613 for key in ('LDFLAGS', 'BASECFLAGS',
614 # a number of derived variables. These need to be
615 # patched up as well.
616 'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
617
618 flags = _config_vars[key]
619 flags = re.sub('-arch\s+\w+\s', ' ', flags)
620 flags = flags + ' ' + arch
621 _config_vars[key] = flags
622 598
623 if args: 599 if args:
624 vals = [] 600 vals = []
625 for name in args: 601 for name in args:
626 vals.append(_config_vars.get(name)) 602 vals.append(_config_vars.get(name))
627 return vals 603 return vals
628 else: 604 else:
629 return _config_vars 605 return _config_vars
630 606
631 def get_config_var(name): 607 def get_config_var(name):
632 """Return the value of a single variable using the dictionary 608 """Return the value of a single variable using the dictionary
633 returned by 'get_config_vars()'. Equivalent to 609 returned by 'get_config_vars()'. Equivalent to
634 get_config_vars().get(name) 610 get_config_vars().get(name)
635 """ 611 """
636 return get_config_vars().get(name) 612 return get_config_vars().get(name)
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+