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

Side by Side Diff: Lib/distutils/sysconfig.py

Issue 3871: cross and native build of python for mingw32 with distutils
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:
View unified diff | Download patch
« no previous file with comments | « Lib/distutils/cygwinccompiler.py ('k') | Lib/distutils/tests/support.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 """
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 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
85 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;
86 otherwise, this is the path to platform-specific header files 86 otherwise, this is the path to platform-specific header files
87 (namely pyconfig.h). 87 (namely pyconfig.h).
88 88
89 If 'prefix' is supplied, use it instead of sys.base_prefix or 89 If 'prefix' is supplied, use it instead of sys.base_prefix or
90 sys.base_exec_prefix -- i.e., ignore 'plat_specific'. 90 sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
91 """ 91 """
92 if prefix is None: 92 if prefix is None:
93 prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX 93 prefix = plat_specific and BASE_PREFIX or BASE_EXEC_PREFIX
94 if os.name == "posix": 94 # GCC(mingw): os.name is "nt" but build system is posix
95 if os.name == "posix" or sys.version.upper().find('GCC') >= 0:
95 if python_build: 96 if python_build:
96 # Assume the executable is in the build directory. The 97 # Assume the executable is in the build directory. The
97 # pyconfig.h file should be in the same directory. Since 98 # pyconfig.h file should be in the same directory. Since
98 # the build directory may not be the source directory, we 99 # the build directory may not be the source directory, we
99 # must use "srcdir" from the makefile to find the "Include" 100 # must use "srcdir" from the makefile to find the "Include"
100 # directory. 101 # directory.
101 base = _sys_home or os.path.dirname(os.path.abspath(sys.executable)) 102 base = _sys_home or os.path.dirname(os.path.abspath(sys.executable))
102 if plat_specific: 103 if plat_specific:
103 return base 104 return base
104 if _sys_home: 105 if _sys_home:
105 incdir = os.path.join(_sys_home, get_config_var('AST_H_DIR')) 106 incdir = os.path.join(_sys_home, get_config_var('AST_H_DIR'))
106 else: 107 else:
107 incdir = os.path.join(get_config_var('srcdir'), 'Include') 108 incdir = os.path.join(get_config_var('srcdir'), 'Include')
108 return os.path.normpath(incdir) 109 return os.path.normpath(incdir)
110 # TODO mingw build as get_python_version() return dot separated value
109 python_dir = 'python' + get_python_version() + build_flags 111 python_dir = 'python' + get_python_version() + build_flags
110 return os.path.join(prefix, "include", python_dir) 112 return os.path.join(prefix, "include", python_dir)
111 elif os.name == "nt": 113 elif os.name == "nt":
112 return os.path.join(prefix, "include") 114 return os.path.join(prefix, "include")
113 elif os.name == "os2": 115 elif os.name == "os2":
114 return os.path.join(prefix, "Include") 116 return os.path.join(prefix, "Include")
115 else: 117 else:
116 raise DistutilsPlatformError( 118 raise DistutilsPlatformError(
117 "I don't know where Python installs its C header files " 119 "I don't know where Python installs its C header files "
118 "on platform '%s'" % os.name) 120 "on platform '%s'" % os.name)
119 121
120 122
121 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):
122 """Return the directory containing the Python library (standard or 124 """Return the directory containing the Python library (standard or
123 site additions). 125 site additions).
124 126
125 If 'plat_specific' is true, return the directory containing 127 If 'plat_specific' is true, return the directory containing
126 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
127 module distribution; otherwise, return the platform-shared library 129 module distribution; otherwise, return the platform-shared library
128 directory. If 'standard_lib' is true, return the directory 130 directory. If 'standard_lib' is true, return the directory
129 containing standard Python library modules; otherwise, return the 131 containing standard Python library modules; otherwise, return the
130 directory for site-specific modules. 132 directory for site-specific modules.
131 133
132 If 'prefix' is supplied, use it instead of sys.base_prefix or 134 If 'prefix' is supplied, use it instead of sys.base_prefix or
133 sys.base_exec_prefix -- i.e., ignore 'plat_specific'. 135 sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
134 """ 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
135 if prefix is None: 140 if prefix is None:
136 if standard_lib: 141 if standard_lib:
137 prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX 142 prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
138 else: 143 else:
139 prefix = plat_specific and EXEC_PREFIX or PREFIX 144 prefix = plat_specific and EXEC_PREFIX or PREFIX
140 145
141 if os.name == "posix": 146 if posix_build:
142 libpython = os.path.join(prefix, 147 libpython = os.path.join(prefix,
143 "lib", "python" + get_python_version()) 148 "lib", "python" + get_python_version())
144 if standard_lib: 149 if standard_lib:
145 return libpython 150 return libpython
146 else: 151 else:
147 return os.path.join(libpython, "site-packages") 152 return os.path.join(libpython, "site-packages")
148 elif os.name == "nt": 153 elif os.name == "nt":
149 if standard_lib: 154 if standard_lib:
150 return os.path.join(prefix, "Lib") 155 return os.path.join(prefix, "Lib")
151 else: 156 else:
(...skipping 11 matching lines...) Expand all
163 "I don't know where Python installs its library " 168 "I don't know where Python installs its library "
164 "on platform '%s'" % os.name) 169 "on platform '%s'" % os.name)
165 170
166 171
167 172
168 def customize_compiler(compiler): 173 def customize_compiler(compiler):
169 """Do any platform-specific customization of a CCompiler instance. 174 """Do any platform-specific customization of a CCompiler instance.
170 175
171 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
172 varies across Unices and is stored in Python's Makefile. 177 varies across Unices and is stored in Python's Makefile.
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.
173 """ 182 """
183 posix_build = None
174 if compiler.compiler_type == "unix": 184 if compiler.compiler_type == "unix":
185 posix_build = True
175 if sys.platform == "darwin": 186 if sys.platform == "darwin":
176 # Perform first-time customization of compiler-related 187 # Perform first-time customization of compiler-related
177 # config vars on OS X now that we know we need a compiler. 188 # config vars on OS X now that we know we need a compiler.
178 # This is primarily to support Pythons from binary 189 # This is primarily to support Pythons from binary
179 # installers. The kind and paths to build tools on 190 # installers. The kind and paths to build tools on
180 # the user system may vary significantly from the system 191 # the user system may vary significantly from the system
181 # that Python itself was built on. Also the user OS 192 # that Python itself was built on. Also the user OS
182 # version and build tools may not support the same set 193 # version and build tools may not support the same set
183 # of CPU architectures for universal builds. 194 # of CPU architectures for universal builds.
184 global _config_vars 195 global _config_vars
185 if not _config_vars.get('CUSTOMIZED_OSX_COMPILER', ''): 196 if not _config_vars.get('CUSTOMIZED_OSX_COMPILER', ''):
186 import _osx_support 197 import _osx_support
187 _osx_support.customize_compiler(_config_vars) 198 _osx_support.customize_compiler(_config_vars)
188 _config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True' 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
189 204
205 if posix_build == True:
190 (cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \ 206 (cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \
191 get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS', 207 get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
192 'CCSHARED', 'LDSHARED', 'SO', 'AR', 'ARFLAGS') 208 'CCSHARED', 'LDSHARED', 'SO', 'AR', 'ARFLAGS')
193 209
194 newcc = None 210 newcc = None
195 if 'CC' in os.environ: 211 if 'CC' in os.environ:
196 cc = os.environ['CC'] 212 cc = os.environ['CC']
197 if 'CXX' in os.environ: 213 if 'CXX' in os.environ:
198 cxx = os.environ['CXX'] 214 cxx = os.environ['CXX']
199 if 'LDSHARED' in os.environ: 215 if 'LDSHARED' in os.environ:
(...skipping 27 matching lines...) Expand all
227 linker_so=ldshared, 243 linker_so=ldshared,
228 linker_exe=cc, 244 linker_exe=cc,
229 archiver=archiver) 245 archiver=archiver)
230 246
231 compiler.shared_lib_extension = so_ext 247 compiler.shared_lib_extension = so_ext
232 248
233 249
234 def get_config_h_filename(): 250 def get_config_h_filename():
235 """Return full pathname of installed pyconfig.h file.""" 251 """Return full pathname of installed pyconfig.h file."""
236 if python_build: 252 if python_build:
237 if os.name == "nt": 253 # GCC(mingw): os.name is "nt" but build system is posix
254 if os.name == "nt" and sys.version.upper().find('GCC') < 0:
238 inc_dir = os.path.join(_sys_home or project_base, "PC") 255 inc_dir = os.path.join(_sys_home or project_base, "PC")
239 else: 256 else:
240 inc_dir = _sys_home or project_base 257 inc_dir = _sys_home or project_base
241 else: 258 else:
242 inc_dir = get_python_inc(plat_specific=1) 259 inc_dir = get_python_inc(plat_specific=1)
243 if get_python_version() < '2.2': 260 if get_python_version() < '2.2':
244 config_h = 'config.h' 261 config_h = 'config.h'
245 else: 262 else:
246 # The name of the config.h file changed in 2.2 263 # The name of the config.h file changed in 2.2
247 config_h = 'pyconfig.h' 264 config_h = 'pyconfig.h'
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 python_exp = os.path.join(python_lib, 'config', 'python.exp') 485 python_exp = os.path.join(python_lib, 'config', 'python.exp')
469 486
470 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)
471 488
472 global _config_vars 489 global _config_vars
473 _config_vars = g 490 _config_vars = g
474 491
475 492
476 def _init_nt(): 493 def _init_nt():
477 """Initialize the module as appropriate for NT""" 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
478 g = {} 500 g = {}
479 # set basic install directories 501 # set basic install directories
480 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1) 502 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
481 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1) 503 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
482 504
483 # XXX hmmm.. a normal install puts include files here 505 # XXX hmmm.. a normal install puts include files here
484 g['INCLUDEPY'] = get_python_inc(plat_specific=0) 506 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
485 507
486 g['SO'] = '.pyd' 508 g['SO'] = '.pyd'
487 g['EXE'] = ".exe" 509 g['EXE'] = ".exe"
(...skipping 24 matching lines...) Expand all
512 def get_config_vars(*args): 534 def get_config_vars(*args):
513 """With no arguments, return a dictionary of all configuration 535 """With no arguments, return a dictionary of all configuration
514 variables relevant for the current platform. Generally this includes 536 variables relevant for the current platform. Generally this includes
515 everything needed to build extensions and install both pure modules and 537 everything needed to build extensions and install both pure modules and
516 extensions. On Unix, this means every variable defined in Python's 538 extensions. On Unix, this means every variable defined in Python's
517 installed Makefile; on Windows it's a much smaller set. 539 installed Makefile; on Windows it's a much smaller set.
518 540
519 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
520 each argument in the configuration variable dictionary. 542 each argument in the configuration variable dictionary.
521 """ 543 """
544
522 global _config_vars 545 global _config_vars
523 if _config_vars is None: 546 if _config_vars is None:
524 func = globals().get("_init_" + os.name) 547 func = globals().get("_init_" + os.name)
525 if func: 548 if func:
526 func() 549 func()
527 else: 550 else:
528 _config_vars = {} 551 _config_vars = {}
529 552
530 # Normalized versions of prefix and exec_prefix are handy to have; 553 # Normalized versions of prefix and exec_prefix are handy to have;
531 # 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
532 # Distutils. 555 # Distutils.
533 _config_vars['prefix'] = PREFIX 556 _config_vars['prefix'] = PREFIX
534 _config_vars['exec_prefix'] = EXEC_PREFIX 557 _config_vars['exec_prefix'] = EXEC_PREFIX
535 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
536 # Always convert srcdir to an absolute path 562 # Always convert srcdir to an absolute path
537 srcdir = _config_vars.get('srcdir', project_base) 563 srcdir = _config_vars.get('srcdir', project_base)
538 if os.name == 'posix': 564 if posix_build:
539 if python_build: 565 if python_build:
540 # If srcdir is a relative path (typically '.' or '..') 566 # If srcdir is a relative path (typically '.' or '..')
541 # then it should be interpreted relative to the directory 567 # then it should be interpreted relative to the directory
542 # containing Makefile. 568 # containing Makefile.
543 base = os.path.dirname(get_makefile_filename()) 569 base = os.path.dirname(get_makefile_filename())
544 srcdir = os.path.join(base, srcdir) 570 srcdir = os.path.join(base, srcdir)
545 else: 571 else:
546 # srcdir is not meaningful since the installation is 572 # srcdir is not meaningful since the installation is
547 # spread about the filesystem. We choose the 573 # spread about the filesystem. We choose the
548 # directory containing the Makefile since we know it 574 # directory containing the Makefile since we know it
549 # exists. 575 # exists.
550 srcdir = os.path.dirname(get_makefile_filename()) 576 srcdir = os.path.dirname(get_makefile_filename())
551 _config_vars['srcdir'] = os.path.abspath(os.path.normpath(srcdir)) 577 _config_vars['srcdir'] = os.path.abspath(os.path.normpath(srcdir))
552 578
553 # Convert srcdir into an absolute path if it appears necessary. 579 # Convert srcdir into an absolute path if it appears necessary.
554 # Normally it is relative to the build directory. However, during 580 # Normally it is relative to the build directory. However, during
555 # testing, for example, we might be running a non-installed python 581 # testing, for example, we might be running a non-installed python
556 # from a different directory. 582 # from a different directory.
557 if python_build and os.name == "posix": 583 if python_build and posix_build:
558 base = os.path.dirname(os.path.abspath(sys.executable)) 584 base = os.path.dirname(os.path.abspath(sys.executable))
559 if (not os.path.isabs(_config_vars['srcdir']) and 585 if (not os.path.isabs(_config_vars['srcdir']) and
560 base != os.getcwd()): 586 base != os.getcwd()):
561 # srcdir is relative and we are not in the same directory 587 # srcdir is relative and we are not in the same directory
562 # as the executable. Assume executable is in the build 588 # as the executable. Assume executable is in the build
563 # directory and make srcdir absolute. 589 # directory and make srcdir absolute.
564 srcdir = os.path.join(base, _config_vars['srcdir']) 590 srcdir = os.path.join(base, _config_vars['srcdir'])
565 _config_vars['srcdir'] = os.path.normpath(srcdir) 591 _config_vars['srcdir'] = os.path.normpath(srcdir)
566 592
567 # OS X platforms require special customization to handle 593 # OS X platforms require special customization to handle
568 # multi-architecture, multi-os-version installers 594 # multi-architecture, multi-os-version installers
569 if sys.platform == 'darwin': 595 if sys.platform == 'darwin':
570 import _osx_support 596 import _osx_support
571 _osx_support.customize_config_vars(_config_vars) 597 _osx_support.customize_config_vars(_config_vars)
572 598
573 if args: 599 if args:
574 vals = [] 600 vals = []
575 for name in args: 601 for name in args:
576 vals.append(_config_vars.get(name)) 602 vals.append(_config_vars.get(name))
577 return vals 603 return vals
578 else: 604 else:
579 return _config_vars 605 return _config_vars
580 606
581 def get_config_var(name): 607 def get_config_var(name):
582 """Return the value of a single variable using the dictionary 608 """Return the value of a single variable using the dictionary
583 returned by 'get_config_vars()'. Equivalent to 609 returned by 'get_config_vars()'. Equivalent to
584 get_config_vars().get(name) 610 get_config_vars().get(name)
585 """ 611 """
586 return get_config_vars().get(name) 612 return get_config_vars().get(name)
OLDNEW
« no previous file with comments | « Lib/distutils/cygwinccompiler.py ('k') | Lib/distutils/tests/support.py » ('j') | no next file with comments »

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