2000-06-21 00:33:03 -03:00
|
|
|
"""distutils.cygwinccompiler
|
|
|
|
|
2000-06-29 19:57:55 -03:00
|
|
|
Provides the CygwinCCompiler class, a subclass of UnixCCompiler that
|
|
|
|
handles the Cygwin port of the GNU C compiler to Windows. It also contains
|
|
|
|
the Mingw32CCompiler class which handles the mingw32 port of GCC (same as
|
|
|
|
cygwin in no-cygwin mode).
|
2000-06-21 00:33:03 -03:00
|
|
|
"""
|
|
|
|
|
2000-08-01 22:31:56 -03:00
|
|
|
# problems:
|
|
|
|
#
|
|
|
|
# * if you use a msvc compiled python version (1.5.2)
|
|
|
|
# 1. you have to insert a __GNUC__ section in its config.h
|
|
|
|
# 2. you have to generate a import library for its dll
|
|
|
|
# - create a def-file for python??.dll
|
|
|
|
# - create a import library using
|
|
|
|
# dlltool --dllname python15.dll --def python15.def \
|
|
|
|
# --output-lib libpython15.a
|
|
|
|
#
|
|
|
|
# see also http://starship.python.net/crew/kernr/mingw32/Notes.html
|
|
|
|
#
|
2001-12-06 16:51:35 -04:00
|
|
|
# * We put export_symbols in a def-file, and don't use
|
2000-08-01 22:31:56 -03:00
|
|
|
# --export-all-symbols because it doesn't worked reliable in some
|
|
|
|
# tested configurations. And because other windows compilers also
|
|
|
|
# need their symbols specified this no serious problem.
|
|
|
|
#
|
|
|
|
# tested configurations:
|
2001-12-06 16:51:35 -04:00
|
|
|
#
|
|
|
|
# * cygwin gcc 2.91.57/ld 2.9.4/dllwrap 0.2.4 works
|
2000-08-01 22:31:56 -03:00
|
|
|
# (after patching python's config.h and for C++ some other include files)
|
|
|
|
# see also http://starship.python.net/crew/kernr/mingw32/Notes.html
|
2001-12-06 16:51:35 -04:00
|
|
|
# * mingw32 gcc 2.95.2/ld 2.9.4/dllwrap 0.2.4 works
|
|
|
|
# (ld doesn't support -shared, so we use dllwrap)
|
2000-08-01 22:31:56 -03:00
|
|
|
# * cygwin gcc 2.95.2/ld 2.10.90/dllwrap 2.10.90 works now
|
|
|
|
# - its dllwrap doesn't work, there is a bug in binutils 2.10.90
|
2000-08-31 22:24:31 -03:00
|
|
|
# see also http://sources.redhat.com/ml/cygwin/2000-06/msg01274.html
|
2003-04-14 09:51:26 -03:00
|
|
|
# - using gcc -mdll instead dllwrap doesn't work without -static because
|
|
|
|
# it tries to link against dlls instead their import libraries. (If
|
|
|
|
# it finds the dll first.)
|
|
|
|
# By specifying -static we force ld to link against the import libraries,
|
|
|
|
# this is windows standard and there are normally not the necessary symbols
|
|
|
|
# in the dlls.
|
2001-12-06 16:51:35 -04:00
|
|
|
# *** only the version of June 2000 shows these problems
|
2003-04-14 09:51:26 -03:00
|
|
|
# * cygwin gcc 3.2/ld 2.13.90 works
|
|
|
|
# (ld supports -shared)
|
|
|
|
# * mingw gcc 3.2/ld 2.13 works
|
|
|
|
# (ld supports -shared)
|
2000-08-01 22:31:56 -03:00
|
|
|
|
2000-06-21 00:33:03 -03:00
|
|
|
__revision__ = "$Id$"
|
|
|
|
|
2009-06-10 15:56:35 -03:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import copy
|
|
|
|
from subprocess import Popen, PIPE
|
|
|
|
import re
|
|
|
|
|
2000-09-26 23:08:14 -03:00
|
|
|
from distutils.ccompiler import gen_preprocess_options, gen_lib_options
|
2000-06-21 00:33:03 -03:00
|
|
|
from distutils.unixccompiler import UnixCCompiler
|
2000-08-01 22:31:56 -03:00
|
|
|
from distutils.file_util import write_file
|
2000-09-26 23:08:14 -03:00
|
|
|
from distutils.errors import DistutilsExecError, CompileError, UnknownFileError
|
2002-06-04 17:14:43 -03:00
|
|
|
from distutils import log
|
2009-06-10 15:56:35 -03:00
|
|
|
from distutils.version import LooseVersion
|
|
|
|
from distutils.spawn import find_executable
|
2000-06-21 00:33:03 -03:00
|
|
|
|
Merged revisions 59275-59303 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
NOTE: The merge does NOT contain the modified file Python/import.c from
r59288. I can't get it running. Nick, please check in the PEP 366
manually.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
........
r59279 | georg.brandl | 2007-12-02 19:17:50 +0100 (Sun, 02 Dec 2007) | 2 lines
Fix a sentence I missed before. Do not merge to 3k.
........
r59281 | georg.brandl | 2007-12-02 22:58:54 +0100 (Sun, 02 Dec 2007) | 3 lines
Add documentation for PySys_* functions.
Written by Charlie Shepherd for GHOP. Also fixes #1245.
........
r59288 | nick.coghlan | 2007-12-03 13:55:17 +0100 (Mon, 03 Dec 2007) | 1 line
Implement PEP 366
........
r59290 | christian.heimes | 2007-12-03 14:47:29 +0100 (Mon, 03 Dec 2007) | 3 lines
Applied my patch #1455 with some extra fixes for VS 2005
The new msvc9compiler module supports VS 2005 and VS 2008. I've also fixed build_ext to support PCbuild8 and PCbuild9 and backported my fix for xxmodule.c from py3k. The old code msvccompiler is still in place in case somebody likes to build an extension with VS 2003 or earlier.
I've also updated the cygwin compiler module for VS 2005 and VS 2008. It works with VS 2005 but I'm unable to test it with VS 2008. We have to wait for a new version of cygwin.
........
r59291 | christian.heimes | 2007-12-03 14:55:16 +0100 (Mon, 03 Dec 2007) | 1 line
Added comment to Misc/NEWS for r59290
........
r59292 | christian.heimes | 2007-12-03 15:28:04 +0100 (Mon, 03 Dec 2007) | 1 line
I followed MA Lemberg's suggestion and added comments to the late initialization of the type slots.
........
r59293 | facundo.batista | 2007-12-03 17:29:52 +0100 (Mon, 03 Dec 2007) | 3 lines
Speedup and cleaning of __str__. Thanks Mark Dickinson.
........
r59294 | facundo.batista | 2007-12-03 18:55:00 +0100 (Mon, 03 Dec 2007) | 4 lines
Faster _fix function, and some reordering for a more elegant
coding. Thanks Mark Dickinson.
........
r59295 | martin.v.loewis | 2007-12-03 20:20:02 +0100 (Mon, 03 Dec 2007) | 5 lines
Issue #1727780: Support loading pickles of random.Random objects created
on 32-bit systems on 64-bit systems, and vice versa. As a consequence
of the change, Random pickles created by Python 2.6 cannot be loaded
in Python 2.5.
........
r59297 | facundo.batista | 2007-12-03 20:49:54 +0100 (Mon, 03 Dec 2007) | 3 lines
Two small fixes. Issue 1547.
........
r59299 | georg.brandl | 2007-12-03 20:57:02 +0100 (Mon, 03 Dec 2007) | 2 lines
#1548: fix apostroph placement.
........
r59300 | christian.heimes | 2007-12-03 21:01:02 +0100 (Mon, 03 Dec 2007) | 3 lines
Patch #1537 from Chad Austin
Change GeneratorExit's base class from Exception to BaseException
(This time I'm applying the patch to the correct sandbox.)
........
r59302 | georg.brandl | 2007-12-03 21:03:46 +0100 (Mon, 03 Dec 2007) | 3 lines
Add examples to the xmlrpclib docs.
Written for GHOP by Josip Dzolonga.
........
2007-12-03 17:02:03 -04:00
|
|
|
def get_msvcr():
|
|
|
|
"""Include the appropriate MSVC runtime library if Python was built
|
|
|
|
with MSVC 7.0 or later.
|
|
|
|
"""
|
|
|
|
msc_pos = sys.version.find('MSC v.')
|
|
|
|
if msc_pos != -1:
|
|
|
|
msc_ver = sys.version[msc_pos+6:msc_pos+10]
|
|
|
|
if msc_ver == '1300':
|
|
|
|
# MSVC 7.0
|
|
|
|
return ['msvcr70']
|
|
|
|
elif msc_ver == '1310':
|
|
|
|
# MSVC 7.1
|
|
|
|
return ['msvcr71']
|
|
|
|
elif msc_ver == '1400':
|
|
|
|
# VS2005 / MSVC 8.0
|
|
|
|
return ['msvcr80']
|
|
|
|
elif msc_ver == '1500':
|
|
|
|
# VS2008 / MSVC 9.0
|
|
|
|
return ['msvcr90']
|
|
|
|
else:
|
2009-06-11 06:25:41 -03:00
|
|
|
raise ValueError("Unknown MS Compiler version %s " % msc_ver)
|
Merged revisions 59275-59303 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
NOTE: The merge does NOT contain the modified file Python/import.c from
r59288. I can't get it running. Nick, please check in the PEP 366
manually.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
........
r59279 | georg.brandl | 2007-12-02 19:17:50 +0100 (Sun, 02 Dec 2007) | 2 lines
Fix a sentence I missed before. Do not merge to 3k.
........
r59281 | georg.brandl | 2007-12-02 22:58:54 +0100 (Sun, 02 Dec 2007) | 3 lines
Add documentation for PySys_* functions.
Written by Charlie Shepherd for GHOP. Also fixes #1245.
........
r59288 | nick.coghlan | 2007-12-03 13:55:17 +0100 (Mon, 03 Dec 2007) | 1 line
Implement PEP 366
........
r59290 | christian.heimes | 2007-12-03 14:47:29 +0100 (Mon, 03 Dec 2007) | 3 lines
Applied my patch #1455 with some extra fixes for VS 2005
The new msvc9compiler module supports VS 2005 and VS 2008. I've also fixed build_ext to support PCbuild8 and PCbuild9 and backported my fix for xxmodule.c from py3k. The old code msvccompiler is still in place in case somebody likes to build an extension with VS 2003 or earlier.
I've also updated the cygwin compiler module for VS 2005 and VS 2008. It works with VS 2005 but I'm unable to test it with VS 2008. We have to wait for a new version of cygwin.
........
r59291 | christian.heimes | 2007-12-03 14:55:16 +0100 (Mon, 03 Dec 2007) | 1 line
Added comment to Misc/NEWS for r59290
........
r59292 | christian.heimes | 2007-12-03 15:28:04 +0100 (Mon, 03 Dec 2007) | 1 line
I followed MA Lemberg's suggestion and added comments to the late initialization of the type slots.
........
r59293 | facundo.batista | 2007-12-03 17:29:52 +0100 (Mon, 03 Dec 2007) | 3 lines
Speedup and cleaning of __str__. Thanks Mark Dickinson.
........
r59294 | facundo.batista | 2007-12-03 18:55:00 +0100 (Mon, 03 Dec 2007) | 4 lines
Faster _fix function, and some reordering for a more elegant
coding. Thanks Mark Dickinson.
........
r59295 | martin.v.loewis | 2007-12-03 20:20:02 +0100 (Mon, 03 Dec 2007) | 5 lines
Issue #1727780: Support loading pickles of random.Random objects created
on 32-bit systems on 64-bit systems, and vice versa. As a consequence
of the change, Random pickles created by Python 2.6 cannot be loaded
in Python 2.5.
........
r59297 | facundo.batista | 2007-12-03 20:49:54 +0100 (Mon, 03 Dec 2007) | 3 lines
Two small fixes. Issue 1547.
........
r59299 | georg.brandl | 2007-12-03 20:57:02 +0100 (Mon, 03 Dec 2007) | 2 lines
#1548: fix apostroph placement.
........
r59300 | christian.heimes | 2007-12-03 21:01:02 +0100 (Mon, 03 Dec 2007) | 3 lines
Patch #1537 from Chad Austin
Change GeneratorExit's base class from Exception to BaseException
(This time I'm applying the patch to the correct sandbox.)
........
r59302 | georg.brandl | 2007-12-03 21:03:46 +0100 (Mon, 03 Dec 2007) | 3 lines
Add examples to the xmlrpclib docs.
Written for GHOP by Josip Dzolonga.
........
2007-12-03 17:02:03 -04:00
|
|
|
|
|
|
|
|
2009-06-11 07:00:56 -03:00
|
|
|
class CygwinCCompiler(UnixCCompiler):
|
|
|
|
""" Handles the Cygwin port of the GNU C compiler to Windows.
|
|
|
|
"""
|
2000-06-21 00:33:03 -03:00
|
|
|
compiler_type = 'cygwin'
|
2000-08-12 21:43:56 -03:00
|
|
|
obj_extension = ".o"
|
|
|
|
static_lib_extension = ".a"
|
|
|
|
shared_lib_extension = ".dll"
|
|
|
|
static_lib_format = "lib%s%s"
|
|
|
|
shared_lib_format = "%s%s"
|
|
|
|
exe_extension = ".exe"
|
2001-12-06 16:51:35 -04:00
|
|
|
|
2009-06-11 07:00:56 -03:00
|
|
|
def __init__(self, verbose=0, dry_run=0, force=0):
|
2000-06-21 00:33:03 -03:00
|
|
|
|
2009-06-11 07:00:56 -03:00
|
|
|
UnixCCompiler.__init__(self, verbose, dry_run, force)
|
2000-06-21 00:33:03 -03:00
|
|
|
|
2009-06-11 07:00:56 -03:00
|
|
|
status, details = check_config_h()
|
2000-08-12 22:18:55 -03:00
|
|
|
self.debug_print("Python's GCC status: %s (details: %s)" %
|
|
|
|
(status, details))
|
|
|
|
if status is not CONFIG_H_OK:
|
2000-08-01 22:31:56 -03:00
|
|
|
self.warn(
|
2004-07-18 03:16:08 -03:00
|
|
|
"Python's pyconfig.h doesn't seem to support your compiler. "
|
2002-06-13 14:28:18 -03:00
|
|
|
"Reason: %s. "
|
|
|
|
"Compiling may fail because of undefined preprocessor macros."
|
|
|
|
% details)
|
2001-12-06 16:51:35 -04:00
|
|
|
|
2002-06-13 14:28:18 -03:00
|
|
|
self.gcc_version, self.ld_version, self.dllwrap_version = \
|
2000-08-01 22:31:56 -03:00
|
|
|
get_versions()
|
2000-08-12 21:43:56 -03:00
|
|
|
self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" %
|
2001-12-06 16:51:35 -04:00
|
|
|
(self.gcc_version,
|
|
|
|
self.ld_version,
|
2000-08-01 22:31:56 -03:00
|
|
|
self.dllwrap_version) )
|
|
|
|
|
2003-04-14 09:51:26 -03:00
|
|
|
# ld_version >= "2.10.90" and < "2.13" should also be able to use
|
2000-08-01 22:31:56 -03:00
|
|
|
# gcc -mdll instead of dllwrap
|
2001-12-06 16:51:35 -04:00
|
|
|
# Older dllwraps had own version numbers, newer ones use the
|
2000-08-01 22:31:56 -03:00
|
|
|
# same as the rest of binutils ( also ld )
|
|
|
|
# dllwrap 2.10.90 is buggy
|
2001-12-06 16:51:35 -04:00
|
|
|
if self.ld_version >= "2.10.90":
|
2000-09-26 23:08:14 -03:00
|
|
|
self.linker_dll = "gcc"
|
2000-08-01 22:31:56 -03:00
|
|
|
else:
|
2000-09-26 23:08:14 -03:00
|
|
|
self.linker_dll = "dllwrap"
|
2000-08-01 22:31:56 -03:00
|
|
|
|
2003-04-14 09:51:26 -03:00
|
|
|
# ld_version >= "2.13" support -shared so use it instead of
|
|
|
|
# -mdll -static
|
|
|
|
if self.ld_version >= "2.13":
|
|
|
|
shared_option = "-shared"
|
|
|
|
else:
|
|
|
|
shared_option = "-mdll -static"
|
|
|
|
|
2000-06-29 19:57:55 -03:00
|
|
|
# Hard-code GCC because that's what this is all about.
|
|
|
|
# XXX optimization, warnings etc. should be customizable.
|
2000-08-01 22:31:56 -03:00
|
|
|
self.set_executables(compiler='gcc -mcygwin -O -Wall',
|
|
|
|
compiler_so='gcc -mcygwin -mdll -O -Wall',
|
2004-06-05 15:37:53 -03:00
|
|
|
compiler_cxx='g++ -mcygwin -O -Wall',
|
2000-08-01 22:31:56 -03:00
|
|
|
linker_exe='gcc -mcygwin',
|
2003-04-14 09:51:26 -03:00
|
|
|
linker_so=('%s -mcygwin %s' %
|
|
|
|
(self.linker_dll, shared_option)))
|
2000-06-29 19:57:55 -03:00
|
|
|
|
2001-12-06 16:51:35 -04:00
|
|
|
# cygwin and mingw32 need different sets of libraries
|
2000-08-01 22:31:56 -03:00
|
|
|
if self.gcc_version == "2.91.57":
|
|
|
|
# cygwin shouldn't need msvcrt, but without the dlls will crash
|
|
|
|
# (gcc version 2.91.57) -- perhaps something about initialization
|
|
|
|
self.dll_libraries=["msvcrt"]
|
2001-12-06 16:51:35 -04:00
|
|
|
self.warn(
|
2000-08-01 22:31:56 -03:00
|
|
|
"Consider upgrading to a newer version of gcc")
|
|
|
|
else:
|
2004-08-03 23:36:18 -03:00
|
|
|
# Include the appropriate MSVC runtime library if Python was built
|
Merged revisions 59275-59303 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
NOTE: The merge does NOT contain the modified file Python/import.c from
r59288. I can't get it running. Nick, please check in the PEP 366
manually.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
........
r59279 | georg.brandl | 2007-12-02 19:17:50 +0100 (Sun, 02 Dec 2007) | 2 lines
Fix a sentence I missed before. Do not merge to 3k.
........
r59281 | georg.brandl | 2007-12-02 22:58:54 +0100 (Sun, 02 Dec 2007) | 3 lines
Add documentation for PySys_* functions.
Written by Charlie Shepherd for GHOP. Also fixes #1245.
........
r59288 | nick.coghlan | 2007-12-03 13:55:17 +0100 (Mon, 03 Dec 2007) | 1 line
Implement PEP 366
........
r59290 | christian.heimes | 2007-12-03 14:47:29 +0100 (Mon, 03 Dec 2007) | 3 lines
Applied my patch #1455 with some extra fixes for VS 2005
The new msvc9compiler module supports VS 2005 and VS 2008. I've also fixed build_ext to support PCbuild8 and PCbuild9 and backported my fix for xxmodule.c from py3k. The old code msvccompiler is still in place in case somebody likes to build an extension with VS 2003 or earlier.
I've also updated the cygwin compiler module for VS 2005 and VS 2008. It works with VS 2005 but I'm unable to test it with VS 2008. We have to wait for a new version of cygwin.
........
r59291 | christian.heimes | 2007-12-03 14:55:16 +0100 (Mon, 03 Dec 2007) | 1 line
Added comment to Misc/NEWS for r59290
........
r59292 | christian.heimes | 2007-12-03 15:28:04 +0100 (Mon, 03 Dec 2007) | 1 line
I followed MA Lemberg's suggestion and added comments to the late initialization of the type slots.
........
r59293 | facundo.batista | 2007-12-03 17:29:52 +0100 (Mon, 03 Dec 2007) | 3 lines
Speedup and cleaning of __str__. Thanks Mark Dickinson.
........
r59294 | facundo.batista | 2007-12-03 18:55:00 +0100 (Mon, 03 Dec 2007) | 4 lines
Faster _fix function, and some reordering for a more elegant
coding. Thanks Mark Dickinson.
........
r59295 | martin.v.loewis | 2007-12-03 20:20:02 +0100 (Mon, 03 Dec 2007) | 5 lines
Issue #1727780: Support loading pickles of random.Random objects created
on 32-bit systems on 64-bit systems, and vice versa. As a consequence
of the change, Random pickles created by Python 2.6 cannot be loaded
in Python 2.5.
........
r59297 | facundo.batista | 2007-12-03 20:49:54 +0100 (Mon, 03 Dec 2007) | 3 lines
Two small fixes. Issue 1547.
........
r59299 | georg.brandl | 2007-12-03 20:57:02 +0100 (Mon, 03 Dec 2007) | 2 lines
#1548: fix apostroph placement.
........
r59300 | christian.heimes | 2007-12-03 21:01:02 +0100 (Mon, 03 Dec 2007) | 3 lines
Patch #1537 from Chad Austin
Change GeneratorExit's base class from Exception to BaseException
(This time I'm applying the patch to the correct sandbox.)
........
r59302 | georg.brandl | 2007-12-03 21:03:46 +0100 (Mon, 03 Dec 2007) | 3 lines
Add examples to the xmlrpclib docs.
Written for GHOP by Josip Dzolonga.
........
2007-12-03 17:02:03 -04:00
|
|
|
# with MSVC 7.0 or later.
|
|
|
|
self.dll_libraries = get_msvcr()
|
2001-12-06 16:51:35 -04:00
|
|
|
|
2002-06-18 15:48:55 -03:00
|
|
|
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
|
2009-06-11 07:00:56 -03:00
|
|
|
"""Compiles the source by spawing GCC and windres if needed."""
|
2002-06-18 15:48:55 -03:00
|
|
|
if ext == '.rc' or ext == '.res':
|
|
|
|
# gcc needs '.res' and '.rc' compiled to object files !!!
|
|
|
|
try:
|
|
|
|
self.spawn(["windres", "-i", src, "-o", obj])
|
2007-01-10 12:19:56 -04:00
|
|
|
except DistutilsExecError as msg:
|
2007-08-30 00:52:21 -03:00
|
|
|
raise CompileError(msg)
|
2002-06-18 15:48:55 -03:00
|
|
|
else: # for other files use the C-compiler
|
|
|
|
try:
|
|
|
|
self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
|
|
|
|
extra_postargs)
|
2007-01-10 12:19:56 -04:00
|
|
|
except DistutilsExecError as msg:
|
2007-08-30 00:52:21 -03:00
|
|
|
raise CompileError(msg)
|
2000-09-26 23:08:14 -03:00
|
|
|
|
2009-06-11 07:00:56 -03:00
|
|
|
def link(self, target_desc, objects, output_filename, output_dir=None,
|
|
|
|
libraries=None, library_dirs=None, runtime_library_dirs=None,
|
|
|
|
export_symbols=None, debug=0, extra_preargs=None,
|
|
|
|
extra_postargs=None, build_temp=None, target_lang=None):
|
|
|
|
"""Link the objects."""
|
2000-08-12 21:43:56 -03:00
|
|
|
# use separate copies, so we can modify the lists
|
|
|
|
extra_preargs = copy.copy(extra_preargs or [])
|
|
|
|
libraries = copy.copy(libraries or [])
|
2000-09-26 23:08:14 -03:00
|
|
|
objects = copy.copy(objects or [])
|
2001-12-06 16:51:35 -04:00
|
|
|
|
2000-08-01 22:31:56 -03:00
|
|
|
# Additional libraries
|
2000-06-29 19:57:55 -03:00
|
|
|
libraries.extend(self.dll_libraries)
|
2000-09-26 23:08:14 -03:00
|
|
|
|
|
|
|
# handle export symbols by creating a def-file
|
|
|
|
# with executables this only works with gcc/ld as linker
|
|
|
|
if ((export_symbols is not None) and
|
|
|
|
(target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
|
|
|
|
# (The linker doesn't do anything if output is up-to-date.
|
|
|
|
# So it would probably better to check if we really need this,
|
2001-12-06 16:51:35 -04:00
|
|
|
# but for this we had to insert some unchanged parts of
|
|
|
|
# UnixCCompiler, and this is not what we want.)
|
2000-09-26 23:08:14 -03:00
|
|
|
|
2001-12-06 16:51:35 -04:00
|
|
|
# we want to put some files in the same directory as the
|
2000-09-26 23:08:14 -03:00
|
|
|
# object files are, build_temp doesn't help much
|
|
|
|
# where are the object files
|
|
|
|
temp_dir = os.path.dirname(objects[0])
|
|
|
|
# name of dll to give the helper files the same base name
|
|
|
|
(dll_name, dll_extension) = os.path.splitext(
|
|
|
|
os.path.basename(output_filename))
|
|
|
|
|
|
|
|
# generate the filenames for these files
|
2000-08-01 22:31:56 -03:00
|
|
|
def_file = os.path.join(temp_dir, dll_name + ".def")
|
2000-09-26 23:08:14 -03:00
|
|
|
lib_file = os.path.join(temp_dir, 'lib' + dll_name + ".a")
|
2001-12-06 16:51:35 -04:00
|
|
|
|
2000-09-26 23:08:14 -03:00
|
|
|
# Generate .def file
|
2000-08-01 22:31:56 -03:00
|
|
|
contents = [
|
|
|
|
"LIBRARY %s" % os.path.basename(output_filename),
|
|
|
|
"EXPORTS"]
|
2000-06-21 00:33:03 -03:00
|
|
|
for sym in export_symbols:
|
2000-08-01 22:31:56 -03:00
|
|
|
contents.append(sym)
|
|
|
|
self.execute(write_file, (def_file, contents),
|
|
|
|
"writing %s" % def_file)
|
|
|
|
|
2000-09-26 23:08:14 -03:00
|
|
|
# next add options for def-file and to creating import libraries
|
|
|
|
|
|
|
|
# dllwrap uses different options than gcc/ld
|
|
|
|
if self.linker_dll == "dllwrap":
|
2002-06-04 17:26:44 -03:00
|
|
|
extra_preargs.extend(["--output-lib", lib_file])
|
2000-08-01 22:31:56 -03:00
|
|
|
# for dllwrap we have to use a special option
|
2000-09-26 23:08:14 -03:00
|
|
|
extra_preargs.extend(["--def", def_file])
|
|
|
|
# we use gcc/ld here and can be sure ld is >= 2.9.10
|
|
|
|
else:
|
|
|
|
# doesn't work: bfd_close build\...\libfoo.a: Invalid operation
|
|
|
|
#extra_preargs.extend(["-Wl,--out-implib,%s" % lib_file])
|
2002-06-04 17:26:44 -03:00
|
|
|
# for gcc/ld the def-file is specified as any object files
|
2000-09-26 23:08:14 -03:00
|
|
|
objects.append(def_file)
|
|
|
|
|
|
|
|
#end: if ((export_symbols is not None) and
|
2000-12-12 19:11:42 -04:00
|
|
|
# (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
|
2001-12-06 16:51:35 -04:00
|
|
|
|
2000-06-29 19:57:55 -03:00
|
|
|
# who wants symbols and a many times larger output file
|
2001-12-06 16:51:35 -04:00
|
|
|
# should explicitly switch the debug mode on
|
2000-08-01 22:31:56 -03:00
|
|
|
# otherwise we let dllwrap/ld strip the output file
|
2001-12-06 16:51:35 -04:00
|
|
|
# (On my machine: 10KB < stripped_file < ??100KB
|
2000-09-26 23:08:14 -03:00
|
|
|
# unstripped_file = stripped_file + XXX KB
|
2001-12-06 16:51:35 -04:00
|
|
|
# ( XXX=254 for a typical python extension))
|
|
|
|
if not debug:
|
|
|
|
extra_preargs.append("-s")
|
|
|
|
|
2009-06-11 07:00:56 -03:00
|
|
|
UnixCCompiler.link(self, target_desc, objects, output_filename,
|
|
|
|
output_dir, libraries, library_dirs,
|
2000-09-26 23:08:14 -03:00
|
|
|
runtime_library_dirs,
|
|
|
|
None, # export_symbols, we do this in our def-file
|
2009-06-11 07:00:56 -03:00
|
|
|
debug, extra_preargs, extra_postargs, build_temp,
|
This patch fixes the following bugs:
[#413582] g++ must be called for c++ extensions
[#454030] distutils cannot link C++ code with GCC
topdir = "Lib/distutils"
* bcppcompiler.py
(BCPPCompiler.create_static_lib): Fixed prototype, removing extra_preargs
and extra_postargs parameters. Included target_lang parameter.
(BCPPCompiler.link): Included target_lang parameter.
* msvccompiler.py
(MSVCCompiler.create_static_lib): Fixed prototype, removing extra_preargs
and extra_postargs parameters. Included target_lang parameter.
(MSVCCompiler.link): Included target_lang parameter.
* ccompiler.py
(CCompiler): New language_map and language_order attributes, used by
CCompiler.detect_language().
(CCompiler.detect_language): New method, will return the language of
a given source, or list of sources. Individual source language is
detected using the language_map dict. When mixed sources are used,
language_order will stablish the language precedence.
(CCompiler.create_static_lib, CCompiler.link, CCompiler.link_executable,
CCompiler.link_shared_object, CCompiler.link_shared_lib):
Inlcuded target_lang parameter.
* cygwinccompiler.py
(CygwinCCompiler.link): Included target_lang parameter.
* emxccompiler.py
(EMXCCompiler.link): Included target_lang parameter.
* mwerkscompiler.py
(MWerksCompiler.link): Included target_lang parameter.
* extension.py
(Extension.__init__): New 'language' parameter/attribute, initialized
to None by default. If provided will overlap the automatic detection
made by CCompiler.detect_language(), in build_ext command.
* sysconfig.py
(customize_compiler): Check Makefile for CXX option, and also the
environment variable CXX. Use the resulting value in the 'compiler_cxx'
parameter of compiler.set_executables().
* unixccompiler.py
(UnixCCompiler): Included 'compiler_cxx' in executables dict, defaulting
to 'cc'.
(UnixCCompiler.create_static_lib): Included target_lang parameter.
(UnixCCompiler.link): Included target_lang parameter, and made
linker command use compiler_cxx, if target_lang is 'c++'.
* command/build_ext.py
(build_ext.build_extension): Pass new ext.language attribute
to compiler.link_shared_object()'s target_lang parameter. If
ext.language is not provided, detect language using
compiler.detect_language(sources) instead.
* command/config.py
(config._link): Pass already available lang parameter as target_lang
parameter of compiler.link_executable().
2002-11-05 12:12:02 -04:00
|
|
|
target_lang)
|
2001-12-06 16:51:35 -04:00
|
|
|
|
2000-09-26 23:08:14 -03:00
|
|
|
# -- Miscellaneous methods -----------------------------------------
|
|
|
|
|
2009-06-11 07:00:56 -03:00
|
|
|
def object_filenames(self, source_filenames, strip_dir=0, output_dir=''):
|
|
|
|
"""Adds supports for rc and res files."""
|
|
|
|
if output_dir is None:
|
|
|
|
output_dir = ''
|
2000-09-26 23:08:14 -03:00
|
|
|
obj_names = []
|
|
|
|
for src_name in source_filenames:
|
|
|
|
# use normcase to make sure '.rc' is really '.rc' and not '.RC'
|
2009-06-11 07:00:56 -03:00
|
|
|
base, ext = os.path.splitext(os.path.normcase(src_name))
|
2000-09-26 23:08:14 -03:00
|
|
|
if ext not in (self.src_extensions + ['.rc','.res']):
|
2007-08-30 00:52:21 -03:00
|
|
|
raise UnknownFileError("unknown file type '%s' (from '%s')" % \
|
|
|
|
(ext, src_name))
|
2000-09-26 23:08:14 -03:00
|
|
|
if strip_dir:
|
|
|
|
base = os.path.basename (base)
|
2009-06-11 07:00:56 -03:00
|
|
|
if ext in ('.res', '.rc'):
|
2000-09-26 23:08:14 -03:00
|
|
|
# these need to be compiled to object files
|
2009-06-11 07:00:56 -03:00
|
|
|
obj_names.append (os.path.join(output_dir,
|
|
|
|
base + ext + self.obj_extension))
|
2000-09-26 23:08:14 -03:00
|
|
|
else:
|
2009-06-11 07:00:56 -03:00
|
|
|
obj_names.append (os.path.join(output_dir,
|
|
|
|
base + self.obj_extension))
|
2000-09-26 23:08:14 -03:00
|
|
|
return obj_names
|
|
|
|
|
2000-06-21 00:33:03 -03:00
|
|
|
# the same as cygwin plus some additional parameters
|
2009-06-11 07:00:56 -03:00
|
|
|
class Mingw32CCompiler(CygwinCCompiler):
|
|
|
|
""" Handles the Mingw32 port of the GNU C compiler to Windows.
|
|
|
|
"""
|
2000-06-21 00:33:03 -03:00
|
|
|
compiler_type = 'mingw32'
|
|
|
|
|
2009-06-11 07:00:56 -03:00
|
|
|
def __init__(self, verbose=0, dry_run=0, force=0):
|
2000-06-21 00:33:03 -03:00
|
|
|
|
|
|
|
CygwinCCompiler.__init__ (self, verbose, dry_run, force)
|
2001-12-06 16:51:35 -04:00
|
|
|
|
2003-04-14 09:51:26 -03:00
|
|
|
# ld_version >= "2.13" support -shared so use it instead of
|
|
|
|
# -mdll -static
|
|
|
|
if self.ld_version >= "2.13":
|
|
|
|
shared_option = "-shared"
|
|
|
|
else:
|
|
|
|
shared_option = "-mdll -static"
|
|
|
|
|
2000-08-01 22:31:56 -03:00
|
|
|
# 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":
|
|
|
|
entry_point = '--entry _DllMain@12'
|
|
|
|
else:
|
|
|
|
entry_point = ''
|
2000-06-21 00:33:03 -03:00
|
|
|
|
2000-06-29 19:57:55 -03:00
|
|
|
self.set_executables(compiler='gcc -mno-cygwin -O -Wall',
|
2000-08-01 22:31:56 -03:00
|
|
|
compiler_so='gcc -mno-cygwin -mdll -O -Wall',
|
2004-06-05 15:37:53 -03:00
|
|
|
compiler_cxx='g++ -mno-cygwin -O -Wall',
|
2000-06-29 19:57:55 -03:00
|
|
|
linker_exe='gcc -mno-cygwin',
|
2003-04-14 09:51:26 -03:00
|
|
|
linker_so='%s -mno-cygwin %s %s'
|
|
|
|
% (self.linker_dll, shared_option,
|
|
|
|
entry_point))
|
2000-08-01 22:31:56 -03:00
|
|
|
# Maybe we should also append -mthreads, but then the finished
|
|
|
|
# dlls need another dll (mingwm10.dll see Mingw32 docs)
|
2001-12-06 16:51:35 -04:00
|
|
|
# (-mthreads: Support thread-safe exception handling on `Mingw32')
|
|
|
|
|
|
|
|
# no additional libraries needed
|
2000-08-01 22:31:56 -03:00
|
|
|
self.dll_libraries=[]
|
2001-12-06 16:51:35 -04:00
|
|
|
|
2004-08-03 23:36:18 -03:00
|
|
|
# Include the appropriate MSVC runtime library if Python was built
|
Merged revisions 59275-59303 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
NOTE: The merge does NOT contain the modified file Python/import.c from
r59288. I can't get it running. Nick, please check in the PEP 366
manually.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
........
r59279 | georg.brandl | 2007-12-02 19:17:50 +0100 (Sun, 02 Dec 2007) | 2 lines
Fix a sentence I missed before. Do not merge to 3k.
........
r59281 | georg.brandl | 2007-12-02 22:58:54 +0100 (Sun, 02 Dec 2007) | 3 lines
Add documentation for PySys_* functions.
Written by Charlie Shepherd for GHOP. Also fixes #1245.
........
r59288 | nick.coghlan | 2007-12-03 13:55:17 +0100 (Mon, 03 Dec 2007) | 1 line
Implement PEP 366
........
r59290 | christian.heimes | 2007-12-03 14:47:29 +0100 (Mon, 03 Dec 2007) | 3 lines
Applied my patch #1455 with some extra fixes for VS 2005
The new msvc9compiler module supports VS 2005 and VS 2008. I've also fixed build_ext to support PCbuild8 and PCbuild9 and backported my fix for xxmodule.c from py3k. The old code msvccompiler is still in place in case somebody likes to build an extension with VS 2003 or earlier.
I've also updated the cygwin compiler module for VS 2005 and VS 2008. It works with VS 2005 but I'm unable to test it with VS 2008. We have to wait for a new version of cygwin.
........
r59291 | christian.heimes | 2007-12-03 14:55:16 +0100 (Mon, 03 Dec 2007) | 1 line
Added comment to Misc/NEWS for r59290
........
r59292 | christian.heimes | 2007-12-03 15:28:04 +0100 (Mon, 03 Dec 2007) | 1 line
I followed MA Lemberg's suggestion and added comments to the late initialization of the type slots.
........
r59293 | facundo.batista | 2007-12-03 17:29:52 +0100 (Mon, 03 Dec 2007) | 3 lines
Speedup and cleaning of __str__. Thanks Mark Dickinson.
........
r59294 | facundo.batista | 2007-12-03 18:55:00 +0100 (Mon, 03 Dec 2007) | 4 lines
Faster _fix function, and some reordering for a more elegant
coding. Thanks Mark Dickinson.
........
r59295 | martin.v.loewis | 2007-12-03 20:20:02 +0100 (Mon, 03 Dec 2007) | 5 lines
Issue #1727780: Support loading pickles of random.Random objects created
on 32-bit systems on 64-bit systems, and vice versa. As a consequence
of the change, Random pickles created by Python 2.6 cannot be loaded
in Python 2.5.
........
r59297 | facundo.batista | 2007-12-03 20:49:54 +0100 (Mon, 03 Dec 2007) | 3 lines
Two small fixes. Issue 1547.
........
r59299 | georg.brandl | 2007-12-03 20:57:02 +0100 (Mon, 03 Dec 2007) | 2 lines
#1548: fix apostroph placement.
........
r59300 | christian.heimes | 2007-12-03 21:01:02 +0100 (Mon, 03 Dec 2007) | 3 lines
Patch #1537 from Chad Austin
Change GeneratorExit's base class from Exception to BaseException
(This time I'm applying the patch to the correct sandbox.)
........
r59302 | georg.brandl | 2007-12-03 21:03:46 +0100 (Mon, 03 Dec 2007) | 3 lines
Add examples to the xmlrpclib docs.
Written for GHOP by Josip Dzolonga.
........
2007-12-03 17:02:03 -04:00
|
|
|
# with MSVC 7.0 or later.
|
|
|
|
self.dll_libraries = get_msvcr()
|
2004-08-03 09:41:42 -03:00
|
|
|
|
2001-07-26 10:41:06 -03:00
|
|
|
# Because these compilers aren't configured in Python's pyconfig.h file by
|
2000-08-01 22:31:56 -03:00
|
|
|
# default, we should at least warn the user if he is using a unmodified
|
|
|
|
# version.
|
|
|
|
|
2000-08-12 22:18:55 -03:00
|
|
|
CONFIG_H_OK = "ok"
|
|
|
|
CONFIG_H_NOTOK = "not ok"
|
|
|
|
CONFIG_H_UNCERTAIN = "uncertain"
|
|
|
|
|
2000-08-01 22:31:56 -03:00
|
|
|
def check_config_h():
|
2009-06-10 15:56:35 -03:00
|
|
|
"""Check if the current Python installation appears amenable to building
|
|
|
|
extensions with GCC.
|
|
|
|
|
|
|
|
Returns a tuple (status, details), where 'status' is one of the following
|
|
|
|
constants:
|
|
|
|
|
|
|
|
- CONFIG_H_OK: all is well, go ahead and compile
|
|
|
|
- CONFIG_H_NOTOK: doesn't look good
|
|
|
|
- CONFIG_H_UNCERTAIN: not sure -- unable to read pyconfig.h
|
2000-08-12 22:18:55 -03:00
|
|
|
|
|
|
|
'details' is a human-readable string explaining the situation.
|
|
|
|
|
|
|
|
Note there are two ways to conclude "OK": either 'sys.version' contains
|
|
|
|
the string "GCC" (implying that this Python was built with GCC), or the
|
2001-07-26 10:41:06 -03:00
|
|
|
installed "pyconfig.h" contains the string "__GNUC__".
|
2000-08-01 22:31:56 -03:00
|
|
|
"""
|
2000-08-12 22:18:55 -03:00
|
|
|
|
|
|
|
# XXX since this function also checks sys.version, it's not strictly a
|
2001-07-26 10:41:06 -03:00
|
|
|
# "pyconfig.h" check -- should probably be renamed...
|
2000-08-01 22:31:56 -03:00
|
|
|
|
|
|
|
from distutils import sysconfig
|
2001-12-06 16:51:35 -04:00
|
|
|
|
2009-06-10 15:56:35 -03:00
|
|
|
# if sys.version contains GCC then python was compiled with GCC, and the
|
|
|
|
# pyconfig.h file should be OK
|
|
|
|
if "GCC" in sys.version:
|
|
|
|
return CONFIG_H_OK, "sys.version mentions 'GCC'"
|
|
|
|
|
|
|
|
# let's see if __GNUC__ is mentioned in python.h
|
2000-08-12 22:18:55 -03:00
|
|
|
fn = sysconfig.get_config_h_filename()
|
2000-08-01 22:31:56 -03:00
|
|
|
try:
|
2009-06-10 15:56:35 -03:00
|
|
|
with open(fn) as config_h:
|
|
|
|
if "__GNUC__" in config_h.read():
|
|
|
|
return CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn
|
|
|
|
else:
|
|
|
|
return CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn
|
2007-01-10 12:19:56 -04:00
|
|
|
except IOError as exc:
|
2000-08-12 22:18:55 -03:00
|
|
|
return (CONFIG_H_UNCERTAIN,
|
|
|
|
"couldn't read '%s': %s" % (fn, exc.strerror))
|
|
|
|
|
2009-06-10 15:56:35 -03:00
|
|
|
RE_VERSION = re.compile('(\d+\.\d+(\.\d+)*)')
|
2000-08-12 22:18:55 -03:00
|
|
|
|
2009-06-10 15:56:35 -03:00
|
|
|
def _find_exe_version(cmd):
|
|
|
|
"""Find the version of an executable by running `cmd` in the shell.
|
2000-08-12 22:18:55 -03:00
|
|
|
|
2009-06-10 15:56:35 -03:00
|
|
|
If the command is not found, or the output does not match
|
|
|
|
`RE_VERSION`, returns None.
|
|
|
|
"""
|
|
|
|
executable = cmd.split()[0]
|
|
|
|
if find_executable(executable) is None:
|
|
|
|
return None
|
|
|
|
out = Popen(cmd, shell=True, stdout=PIPE).stdout
|
|
|
|
try:
|
|
|
|
out_string = out.read()
|
|
|
|
finally:
|
|
|
|
out.close()
|
|
|
|
result = RE_VERSION.search(out_string)
|
|
|
|
if result is None:
|
|
|
|
return None
|
|
|
|
return LooseVersion(result.group(1))
|
2000-08-01 22:31:56 -03:00
|
|
|
|
|
|
|
def get_versions():
|
|
|
|
""" Try to find out the versions of gcc, ld and dllwrap.
|
2001-12-06 16:51:35 -04:00
|
|
|
|
2009-06-10 15:56:35 -03:00
|
|
|
If not possible it returns None for it.
|
|
|
|
"""
|
|
|
|
commands = ['gcc -dumpversion', 'ld -v', 'dllwrap --version']
|
|
|
|
return tuple([_find_exe_version(cmd) for cmd in commands])
|