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

Side by Side Diff: Lib/distutils/command/build_ext.py

Issue 3871: cross and native build of python for mingw32 with distutils
Patch Set: Created 7 years, 4 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/ccompiler.py ('k') | Lib/distutils/command/install.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 """distutils.command.build_ext 1 """distutils.command.build_ext
2 2
3 Implements the Distutils 'build_ext' command, for building extension 3 Implements the Distutils 'build_ext' command, for building extension
4 modules (currently limited to C extensions, should accommodate C++ 4 modules (currently limited to C extensions, should accommodate C++
5 extensions ASAP).""" 5 extensions ASAP)."""
6 6
7 import sys, os, re 7 import sys, os, re
8 from distutils.core import Command 8 from distutils.core import Command
9 from distutils.errors import * 9 from distutils.errors import *
10 from distutils.sysconfig import customize_compiler, get_python_version 10 from distutils.sysconfig import customize_compiler, get_python_version
11 from distutils.sysconfig import get_config_h_filename 11 from distutils.sysconfig import get_config_h_filename
12 from distutils.dep_util import newer_group 12 from distutils.dep_util import newer_group
13 from distutils.extension import Extension 13 from distutils.extension import Extension
14 from distutils.util import get_platform 14 from distutils.util import get_platform
15 from distutils import log 15 from distutils import log
16 16
17 # this keeps compatibility from 2.3 to 2.5 17 # this keeps compatibility from 2.3 to 2.5
18 if sys.version < "2.6": 18 if sys.version < "2.6":
19 USER_BASE = None 19 USER_BASE = None
20 HAS_USER_SITE = False 20 HAS_USER_SITE = False
21 else: 21 else:
22 from site import USER_BASE 22 from site import USER_BASE
23 HAS_USER_SITE = True 23 HAS_USER_SITE = True
24 24
25 if os.name == 'nt': 25 # GCC(mingw): os.name is "nt" but build system is posix
26 if os.name == 'nt' and sys.version.find('GCC') < 0:
26 from distutils.msvccompiler import get_build_version 27 from distutils.msvccompiler import get_build_version
27 MSVC_VERSION = int(get_build_version()) 28 MSVC_VERSION = int(get_build_version())
28 29
29 # An extension name is just a dot-separated list of Python NAMEs (ie. 30 # An extension name is just a dot-separated list of Python NAMEs (ie.
30 # the same as a fully-qualified module name). 31 # the same as a fully-qualified module name).
31 extension_name_re = re.compile \ 32 extension_name_re = re.compile \
32 (r'^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$') 33 (r'^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$')
33 34
34 35
35 def show_compilers (): 36 def show_compilers ():
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 self.library_dirs = self.library_dirs.split(os.pathsep) 184 self.library_dirs = self.library_dirs.split(os.pathsep)
184 185
185 if self.rpath is None: 186 if self.rpath is None:
186 self.rpath = [] 187 self.rpath = []
187 elif isinstance(self.rpath, str): 188 elif isinstance(self.rpath, str):
188 self.rpath = self.rpath.split(os.pathsep) 189 self.rpath = self.rpath.split(os.pathsep)
189 190
190 # for extensions under windows use different directories 191 # for extensions under windows use different directories
191 # for Release and Debug builds. 192 # for Release and Debug builds.
192 # also Python's library directory must be appended to library_dirs 193 # also Python's library directory must be appended to library_dirs
193 if os.name == 'nt': 194 # GCC(mingw): os.name is "nt" but build system is posix
195 if os.name == 'nt' and sys.version.find('GCC') < 0:
194 # the 'libs' directory is for binary installs - we assume that 196 # the 'libs' directory is for binary installs - we assume that
195 # must be the *native* platform. But we don't really support 197 # must be the *native* platform. But we don't really support
196 # cross-compiling via a binary install anyway, so we let it go. 198 # cross-compiling via a binary install anyway, so we let it go.
197 self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs')) 199 self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs'))
198 if sys.base_exec_prefix != sys.prefix: # Issue 16116 200 if sys.base_exec_prefix != sys.prefix: # Issue 16116
199 self.library_dirs.append(os.path.join(sys.base_exec_prefix, 'lib s')) 201 self.library_dirs.append(os.path.join(sys.base_exec_prefix, 'lib s'))
200 if self.debug: 202 if self.debug:
201 self.build_temp = os.path.join(self.build_temp, "Debug") 203 self.build_temp = os.path.join(self.build_temp, "Debug")
202 else: 204 else:
203 self.build_temp = os.path.join(self.build_temp, "Release") 205 self.build_temp = os.path.join(self.build_temp, "Release")
(...skipping 26 matching lines...) Expand all
230 self.library_dirs.append(os.path.join(sys.exec_prefix, 232 self.library_dirs.append(os.path.join(sys.exec_prefix,
231 'PC', 'VC6')) 233 'PC', 'VC6'))
232 234
233 # OS/2 (EMX) doesn't support Debug vs Release builds, but has the 235 # OS/2 (EMX) doesn't support Debug vs Release builds, but has the
234 # import libraries in its "Config" subdirectory 236 # import libraries in its "Config" subdirectory
235 if os.name == 'os2': 237 if os.name == 'os2':
236 self.library_dirs.append(os.path.join(sys.exec_prefix, 'Config')) 238 self.library_dirs.append(os.path.join(sys.exec_prefix, 'Config'))
237 239
238 # for extensions under Cygwin and AtheOS Python's library directory must be 240 # for extensions under Cygwin and AtheOS Python's library directory must be
239 # appended to library_dirs 241 # appended to library_dirs
240 if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos': 242 if (sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos'
243 or (sys.platform == 'win32' and sys.version.find('GCC') >= 0)):
241 if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")): 244 if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
242 # building third party extensions 245 # building third party extensions
243 self.library_dirs.append(os.path.join(sys.prefix, "lib", 246 self.library_dirs.append(os.path.join(sys.prefix, "lib",
244 "python" + get_python_vers ion(), 247 "python" + get_python_vers ion(),
245 "config")) 248 "config"))
246 else: 249 else:
247 # building python standard extensions 250 # building python standard extensions
248 self.library_dirs.append('.') 251 self.library_dirs.append('.')
249 252
250 # for extensions under Linux or Solaris with a shared Python library, 253 # for extensions under Linux or Solaris with a shared Python library,
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 def get_libraries(self, ext): 699 def get_libraries(self, ext):
697 """Return the list of libraries to link against when building a 700 """Return the list of libraries to link against when building a
698 shared extension. On most platforms, this is just 'ext.libraries'; 701 shared extension. On most platforms, this is just 'ext.libraries';
699 on Windows and OS/2, we add the Python library (eg. python20.dll). 702 on Windows and OS/2, we add the Python library (eg. python20.dll).
700 """ 703 """
701 # The python library is always needed on Windows. For MSVC, this 704 # The python library is always needed on Windows. For MSVC, this
702 # is redundant, since the library is mentioned in a pragma in 705 # is redundant, since the library is mentioned in a pragma in
703 # pyconfig.h that MSVC groks. The other Windows compilers all seem 706 # pyconfig.h that MSVC groks. The other Windows compilers all seem
704 # to need it mentioned explicitly, though, so that's what we do. 707 # to need it mentioned explicitly, though, so that's what we do.
705 # Append '_d' to the python import library on debug builds. 708 # Append '_d' to the python import library on debug builds.
709
710 # FIXME: What is purpose of code below ?
711 # The posix build system khow requred libraries to build a module.
712 # The libraries are stored in config(Makefile) variables BLDLIBRARY,
713 # MODLIBS and SHLIBS. Note that some variables may contain linker
714 # flags.
715 # NOTE: For now we will check only GCC(mingw) compiler as is clear
716 # that we build for windows platfrom.
717 # The code for GCC(mingw) is not correct but this is distutils
718 # limitation - we has to pass variables to the linker as is
719 # instead only library names.
720 if self.compiler.compiler_type == 'mingw32':
721 from distutils import sysconfig
722
723 template = "python%s"
724 if self.debug:
725 template = template + '_d'
726 extra = [(template % (sysconfig.get_config_var('VERSION')))]
727 for lib in sysconfig.get_config_var('BLDLIBRARY').split():
728 if lib.startswith('-l'):
729 extra.append(lib[2:])
730 for lib in sysconfig.get_config_var('MODLIBS').split():
731 if lib.startswith('-l'):
732 extra.append(lib[2:])
733 for lib in sysconfig.get_config_var('SHLIBS').split():
734 if lib.startswith('-l'):
735 extra.append(lib[2:])
736 return ext.libraries + extra
737
706 if sys.platform == "win32": 738 if sys.platform == "win32":
707 from distutils.msvccompiler import MSVCCompiler 739 from distutils.msvccompiler import MSVCCompiler
708 if not isinstance(self.compiler, MSVCCompiler): 740 if not isinstance(self.compiler, MSVCCompiler):
709 template = "python%d%d" 741 template = "python%d%d"
710 if self.debug: 742 if self.debug:
711 template = template + '_d' 743 template = template + '_d'
712 pythonlib = (template % 744 pythonlib = (template %
713 (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) 745 (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
714 # don't extend ext.libraries, it may be shared with other 746 # don't extend ext.libraries, it may be shared with other
715 # extensions, it is a reference to the original list 747 # extensions, it is a reference to the original list
716 return ext.libraries + [pythonlib] 748 return ext.libraries + [pythonlib]
717 else: 749 else:
718 return ext.libraries 750 return ext.libraries
719 elif sys.platform == "os2emx": 751 elif sys.platform == "os2emx":
720 # EMX/GCC requires the python library explicitly, and I 752 # EMX/GCC requires the python library explicitly, and I
721 # believe VACPP does as well (though not confirmed) - AIM Apr01 753 # believe VACPP does as well (though not confirmed) - AIM Apr01
722 template = "python%d%d" 754 template = "python%d%d"
723 # debug versions of the main DLL aren't supported, at least 755 # debug versions of the main DLL aren't supported, at least
724 # not at this time - AIM Apr01 756 # not at this time - AIM Apr01
725 #if self.debug: 757 #if self.debug:
726 # template = template + '_d' 758 # template = template + '_d'
727 pythonlib = (template % 759 pythonlib = (template %
728 (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) 760 (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
729 # don't extend ext.libraries, it may be shared with other 761 # don't extend ext.libraries, it may be shared with other
730 # extensions, it is a reference to the original list 762 # extensions, it is a reference to the original list
731 return ext.libraries + [pythonlib] 763 return ext.libraries + [pythonlib]
732 elif sys.platform[:6] == "cygwin": 764 # NOTE : cygwin use posix build rules ;)
765 elif sys.platform[:6] == "cygwin" and False:
733 template = "python%d.%d" 766 template = "python%d.%d"
734 pythonlib = (template % 767 pythonlib = (template %
735 (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) 768 (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
736 # don't extend ext.libraries, it may be shared with other 769 # don't extend ext.libraries, it may be shared with other
737 # extensions, it is a reference to the original list 770 # extensions, it is a reference to the original list
738 return ext.libraries + [pythonlib] 771 return ext.libraries + [pythonlib]
739 elif sys.platform[:6] == "atheos": 772 elif sys.platform[:6] == "atheos":
740 from distutils import sysconfig 773 from distutils import sysconfig
741 774
742 template = "python%d.%d" 775 template = "python%d.%d"
(...skipping 17 matching lines...) Expand all
760 return ext.libraries 793 return ext.libraries
761 else: 794 else:
762 from distutils import sysconfig 795 from distutils import sysconfig
763 if sysconfig.get_config_var('Py_ENABLE_SHARED'): 796 if sysconfig.get_config_var('Py_ENABLE_SHARED'):
764 pythonlib = 'python{}.{}{}'.format( 797 pythonlib = 'python{}.{}{}'.format(
765 sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff, 798 sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff,
766 sys.abiflags) 799 sys.abiflags)
767 return ext.libraries + [pythonlib] 800 return ext.libraries + [pythonlib]
768 else: 801 else:
769 return ext.libraries 802 return ext.libraries
OLDNEW
« no previous file with comments | « Lib/distutils/ccompiler.py ('k') | Lib/distutils/command/install.py » ('j') | no next file with comments »

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