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

Unified Diff: Lib/distutils/cygwinccompiler.py

Issue 3871: cross and native build of python for mingw32 with distutils
Patch Set: Created 7 years, 2 months ago
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/distutils/command/install.py ('k') | Lib/distutils/sysconfig.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/distutils/cygwinccompiler.py Thu Dec 27 23:52:36 2012 +0200
+++ b/Lib/distutils/cygwinccompiler.py Thu Dec 27 17:35:12 2012 -0500
@@ -63,6 +63,18 @@
"""Include the appropriate MSVC runtime library if Python was built
with MSVC 7.0 or later.
"""
+ # FIXME: next code is from issue870382
+ # MS C-runtime libraries never support backward compatibility.
+ # Linking to a different library without to specify correct runtime
+ # version for the headers will link renamed functions to msvcrt.
+ # See issue3308: this piece of code is python problem even
+ # with correct w32api headers.
+ # Issue: for MSVC compiler we can get the version and from version
+ # to determine mcvcrt as code below. But what about if python is
+ # build with GCC compiler?
+ # Output of sys.version is information for python build on first
+ # line, on the next line is information for the compiler and the
+ # output lack information for the C-runtime.
msc_pos = sys.version.find('MSC v.')
if msc_pos != -1:
msc_ver = sys.version[msc_pos+6:msc_pos+10]
@@ -83,21 +95,26 @@
return ['msvcr100']
else:
raise ValueError("Unknown MS Compiler version %s " % msc_ver)
+ else:
+ return []
class CygwinCCompiler(UnixCCompiler):
""" Handles the Cygwin port of the GNU C compiler to Windows.
"""
+
compiler_type = 'cygwin'
obj_extension = ".o"
static_lib_extension = ".a"
shared_lib_extension = ".dll"
+ # FIXME: dylib_... = ".dll.a" is not enought for binutils
+ # loader on win32 platform !!!
+ dylib_lib_extension = ".dll.a"
static_lib_format = "lib%s%s"
shared_lib_format = "%s%s"
exe_extension = ".exe"
def __init__(self, verbose=0, dry_run=0, force=0):
-
UnixCCompiler.__init__(self, verbose, dry_run, force)
status, details = check_config_h()
@@ -110,6 +127,10 @@
"Compiling may fail because of undefined preprocessor macros."
% details)
+ # Next line of code is problem for cross-compiled enviroment:
+ # NOTE: GCC cross-compiler is prefixed by the <hostarch>-<hostos>-
+ # and by default binaries are installed in same directory
+ # as native compiler.
self.gcc_version, self.ld_version, self.dllwrap_version = \
get_versions()
self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" %
@@ -134,6 +155,9 @@
else:
shared_option = "-mdll -static"
+ # FIXME:
+ # Hard-code may override unix-compiler settings and isn't
+ # possible to use Makefile variables to pass correct flags !
# Hard-code GCC because that's what this is all about.
# XXX optimization, warnings etc. should be customizable.
self.set_executables(compiler='gcc -mcygwin -O -Wall',
@@ -157,6 +181,15 @@
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
"""Compiles the source by spawning GCC and windres if needed."""
+
+ tmp_arg=[]
+
+ for arg in cc_args:
+ if arg not in ["-I.", "-I/mingw/include"]:
+ tmp_arg.append(arg)
+
+ cc_args=tmp_arg
+
if ext == '.rc' or ext == '.res':
# gcc needs '.res' and '.rc' compiled to object files !!!
try:
@@ -175,6 +208,7 @@
export_symbols=None, debug=0, extra_preargs=None,
extra_postargs=None, build_temp=None, target_lang=None):
"""Link the objects."""
+
# use separate copies, so we can modify the lists
extra_preargs = copy.copy(extra_preargs or [])
libraries = copy.copy(libraries or [])
@@ -254,11 +288,19 @@
output_dir = ''
obj_names = []
for src_name in source_filenames:
- # use normcase to make sure '.rc' is really '.rc' and not '.RC'
- base, ext = os.path.splitext(os.path.normcase(src_name))
+ # FIXME: "bogus checks for suffix" - as example the commented
+ # by #BOGUS# code break valid assembler suffix ".S" !
+ #BOGUS## use normcase to make sure '.rc' is really '.rc' and not '.RC'
+ #BOGUS#base, ext = os.path.splitext(os.path.normcase(src_name))
+ base, ext = os.path.splitext (src_name)
+ ext_normcase = os.path.normcase(ext)
+ if ext_normcase in ['.rc','.res']:
+ ext = ext_normcase
if ext not in (self.src_extensions + ['.rc','.res']):
raise UnknownFileError("unknown file type '%s' (from '%s')" % \
(ext, src_name))
+ base = os.path.splitdrive(base)[1] # Chop off the drive
+ base = base[os.path.isabs(base):] # If abs, chop off leading /
if strip_dir:
base = os.path.basename (base)
if ext in ('.res', '.rc'):
@@ -277,30 +319,37 @@
compiler_type = 'mingw32'
def __init__(self, verbose=0, dry_run=0, force=0):
-
CygwinCCompiler.__init__ (self, verbose, dry_run, force)
-
+
+ compiler_options = '-mno-cygwin -O -Wall'
+
# ld_version >= "2.13" support -shared so use it instead of
# -mdll -static
- if self.ld_version >= "2.13":
+ if self.ld_version >= "4.7":
+ shared_option = "-pthread -share -W1"
+ elif self.ld_version >= "2.13":
shared_option = "-shared"
else:
shared_option = "-mdll -static"
# A real mingw32 doesn't need to specify a different entry point,
# but cygwin 2.91.57 in no-cygwin-mode needs it.
- if self.gcc_version <= "2.91.57":
+ if self.gcc_version >= "4.7":
+ entry_point = ''
+ compiler_options = '-pthread -c -Wno-unused-result -mms-bitfields -fwrapv -O3 -Wall -Wstrict-prototypes'
+ elif self.gcc_version <= "2.91.57":
entry_point = '--entry _DllMain@12'
else:
entry_point = ''
- self.set_executables(compiler='gcc -mno-cygwin -O -Wall',
- compiler_so='gcc -mno-cygwin -mdll -O -Wall',
- compiler_cxx='g++ -mno-cygwin -O -Wall',
- linker_exe='gcc -mno-cygwin',
- linker_so='%s -mno-cygwin %s %s'
+ self.set_executables(compiler='gcc %s' % compiler_options,
+ compiler_so='gcc %s' % compiler_options,
+ compiler_cxx='g++ -O2 -Wall',
+ linker_exe='gcc %s' % compiler_options,
+ linker_so='%s %s %s'
% (self.linker_dll, shared_option,
entry_point))
+
# Maybe we should also append -mthreads, but then the finished
# dlls need another dll (mingwm10.dll see Mingw32 docs)
# (-mthreads: Support thread-safe exception handling on `Mingw32')
« no previous file with comments | « Lib/distutils/command/install.py ('k') | Lib/distutils/sysconfig.py » ('j') | no next file with comments »

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