| 
									
										
										
										
											1999-07-10 02:04:22 +00:00
										 |  |  | """distutils.unixccompiler
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Contains the UnixCCompiler class, a subclass of CCompiler that handles | 
					
						
							|  |  |  | the "typical" Unix-style command-line C compiler: | 
					
						
							|  |  |  |   * macros defined with -Dname[=value] | 
					
						
							|  |  |  |   * macros undefined with -Uname | 
					
						
							|  |  |  |   * include search directories specified with -Idir | 
					
						
							|  |  |  |   * libraries specified with -lllib | 
					
						
							|  |  |  |   * library search directories specified with -Ldir | 
					
						
							|  |  |  |   * compile handled by 'cc' (or similar) executable with -c option: | 
					
						
							|  |  |  |     compiles .c to .o | 
					
						
							|  |  |  |   * link static library handled by 'ar' command (possibly with 'ranlib') | 
					
						
							|  |  |  |   * link shared library handled by 'cc -shared' | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-03-02 01:49:45 +00:00
										 |  |  | __revision__ = "$Id$" | 
					
						
							| 
									
										
										
										
											1999-07-10 02:04:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-04 20:18:24 +00:00
										 |  |  | import os, sys | 
					
						
							| 
									
										
										
										
											2002-06-13 15:01:38 +00:00
										 |  |  | from types import StringType, NoneType | 
					
						
							| 
									
										
										
										
											1999-09-13 03:12:53 +00:00
										 |  |  | from copy import copy | 
					
						
							| 
									
										
										
										
											2002-06-13 15:01:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-12-11 05:04:24 +00:00
										 |  |  | from distutils import sysconfig | 
					
						
							| 
									
										
										
										
											2000-06-21 02:58:46 +00:00
										 |  |  | from distutils.dep_util import newer | 
					
						
							| 
									
										
										
										
											2000-05-30 01:56:44 +00:00
										 |  |  | from distutils.ccompiler import \ | 
					
						
							| 
									
										
										
										
											2000-05-30 02:02:49 +00:00
										 |  |  |      CCompiler, gen_preprocess_options, gen_lib_options | 
					
						
							|  |  |  | from distutils.errors import \ | 
					
						
							|  |  |  |      DistutilsExecError, CompileError, LibError, LinkError | 
					
						
							| 
									
										
										
										
											2002-06-04 20:14:43 +00:00
										 |  |  | from distutils import log | 
					
						
							| 
									
										
										
										
											1999-07-10 02:04:22 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # XXX Things not currently handled: | 
					
						
							|  |  |  | #   * optimization/debug/warning flags; we just use whatever's in Python's | 
					
						
							|  |  |  | #     Makefile and live with it.  Is this adequate?  If not, we might | 
					
						
							|  |  |  | #     have to have a bunch of subclasses GNUCCompiler, SGICCompiler, | 
					
						
							|  |  |  | #     SunCCompiler, and I suspect down that road lies madness. | 
					
						
							|  |  |  | #   * even if we don't know a warning flag from an optimization flag, | 
					
						
							|  |  |  | #     we need some way for outsiders to feed preprocessor/compiler/linker | 
					
						
							|  |  |  | #     flags in to us -- eg. a sysadmin might want to mandate certain flags | 
					
						
							|  |  |  | #     via a site config file, or a user might want to set something for | 
					
						
							|  |  |  | #     compiling this module distribution only via the setup.py command | 
					
						
							|  |  |  | #     line, whatever.  As long as these options come from something on the | 
					
						
							|  |  |  | #     current system, they can be as system-dependent as they like, and we | 
					
						
							|  |  |  | #     should just happily stuff them into the preprocessor/compiler/linker | 
					
						
							|  |  |  | #     options and carry on. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 15:01:38 +00:00
										 |  |  | class UnixCCompiler(CCompiler): | 
					
						
							| 
									
										
										
										
											1999-07-10 02:04:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-09-29 12:22:50 +00:00
										 |  |  |     compiler_type = 'unix' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-25 02:05:29 +00:00
										 |  |  |     # These are used by CCompiler in two places: the constructor sets | 
					
						
							|  |  |  |     # instance attributes 'preprocessor', 'compiler', etc. from them, and | 
					
						
							|  |  |  |     # 'set_executable()' allows any of these to be set.  The defaults here | 
					
						
							|  |  |  |     # are pretty generic; they will probably have to be set by an outsider | 
					
						
							|  |  |  |     # (eg. using information discovered by the sysconfig about building | 
					
						
							|  |  |  |     # Python extensions). | 
					
						
							|  |  |  |     executables = {'preprocessor' : None, | 
					
						
							|  |  |  |                    'compiler'     : ["cc"], | 
					
						
							|  |  |  |                    'compiler_so'  : ["cc"], | 
					
						
							| 
									
										
											  
											
												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 16:12:02 +00:00
										 |  |  |                    'compiler_cxx' : ["cc"], | 
					
						
							| 
									
										
										
										
											2000-06-25 02:05:29 +00:00
										 |  |  |                    'linker_so'    : ["cc", "-shared"], | 
					
						
							|  |  |  |                    'linker_exe'   : ["cc"], | 
					
						
							|  |  |  |                    'archiver'     : ["ar", "-cr"], | 
					
						
							|  |  |  |                    'ranlib'       : None, | 
					
						
							|  |  |  |                   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-02-11 15:31:50 +00:00
										 |  |  |     if sys.platform[:6] == "darwin": | 
					
						
							|  |  |  |         executables['ranlib'] = ["ranlib"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-25 02:05:29 +00:00
										 |  |  |     # Needed for the filename generation methods provided by the base | 
					
						
							|  |  |  |     # class, CCompiler.  NB. whoever instantiates/uses a particular | 
					
						
							|  |  |  |     # UnixCCompiler instance should set 'shared_lib_ext' -- we set a | 
					
						
							|  |  |  |     # reasonable common default here, but it's not necessarily used on all | 
					
						
							|  |  |  |     # Unices! | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-05 15:46:48 +00:00
										 |  |  |     src_extensions = [".c",".C",".cc",".cxx",".cpp",".m"] | 
					
						
							| 
									
										
										
										
											2000-03-06 03:40:29 +00:00
										 |  |  |     obj_extension = ".o" | 
					
						
							|  |  |  |     static_lib_extension = ".a" | 
					
						
							| 
									
										
										
										
											2000-06-25 02:05:29 +00:00
										 |  |  |     shared_lib_extension = ".so" | 
					
						
							| 
									
										
										
										
											2001-08-27 15:08:16 +00:00
										 |  |  |     dylib_lib_extension = ".dylib" | 
					
						
							|  |  |  |     static_lib_format = shared_lib_format = dylib_lib_format = "lib%s%s" | 
					
						
							| 
									
										
										
										
											2003-04-18 17:27:47 +00:00
										 |  |  |     if sys.platform == "cygwin": | 
					
						
							|  |  |  |         exe_extension = ".exe" | 
					
						
							| 
									
										
										
										
											2000-01-09 22:47:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 15:14:10 +00:00
										 |  |  |     def preprocess(self, source, | 
					
						
							|  |  |  |                    output_file=None, macros=None, include_dirs=None, | 
					
						
							|  |  |  |                    extra_preargs=None, extra_postargs=None): | 
					
						
							|  |  |  |         ignore, macros, include_dirs = \ | 
					
						
							| 
									
										
										
										
											2000-09-26 01:56:15 +00:00
										 |  |  |             self._fix_compile_args(None, macros, include_dirs) | 
					
						
							|  |  |  |         pp_opts = gen_preprocess_options(macros, include_dirs) | 
					
						
							| 
									
										
										
										
											2000-06-25 02:05:29 +00:00
										 |  |  |         pp_args = self.preprocessor + pp_opts | 
					
						
							| 
									
										
										
										
											2000-06-21 02:58:46 +00:00
										 |  |  |         if output_file: | 
					
						
							| 
									
										
										
										
											2000-06-25 02:05:29 +00:00
										 |  |  |             pp_args.extend(['-o', output_file]) | 
					
						
							| 
									
										
										
										
											2000-06-21 02:58:46 +00:00
										 |  |  |         if extra_preargs: | 
					
						
							| 
									
										
										
										
											2000-06-25 02:05:29 +00:00
										 |  |  |             pp_args[:0] = extra_preargs | 
					
						
							| 
									
										
										
										
											2000-06-21 02:58:46 +00:00
										 |  |  |         if extra_postargs: | 
					
						
							| 
									
										
										
										
											2001-07-16 14:19:20 +00:00
										 |  |  |             pp_args.extend(extra_postargs) | 
					
						
							| 
									
										
										
										
											2002-09-09 12:16:58 +00:00
										 |  |  |         pp_args.append(source) | 
					
						
							| 
									
										
										
										
											2000-06-21 02:58:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-16 14:19:20 +00:00
										 |  |  |         # We need to preprocess: either we're being forced to, or we're | 
					
						
							| 
									
										
										
										
											2001-12-06 20:51:35 +00:00
										 |  |  |         # generating output to stdout, or there's a target output file and | 
					
						
							|  |  |  |         # the source file is newer than the target (or the target doesn't | 
					
						
							| 
									
										
										
										
											2000-06-21 02:58:46 +00:00
										 |  |  |         # exist). | 
					
						
							| 
									
										
										
										
											2001-07-16 14:46:13 +00:00
										 |  |  |         if self.force or output_file is None or newer(source, output_file): | 
					
						
							| 
									
										
										
										
											2000-06-21 02:58:46 +00:00
										 |  |  |             if output_file: | 
					
						
							|  |  |  |                 self.mkpath(os.path.dirname(output_file)) | 
					
						
							|  |  |  |             try: | 
					
						
							| 
									
										
										
										
											2000-09-26 01:56:15 +00:00
										 |  |  |                 self.spawn(pp_args) | 
					
						
							| 
									
										
										
										
											2000-06-21 02:58:46 +00:00
										 |  |  |             except DistutilsExecError, msg: | 
					
						
							|  |  |  |                 raise CompileError, msg | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-18 18:48:55 +00:00
										 |  |  |     def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + | 
					
						
							|  |  |  |                        extra_postargs) | 
					
						
							|  |  |  |         except DistutilsExecError, msg: | 
					
						
							|  |  |  |             raise CompileError, msg | 
					
						
							| 
									
										
										
										
											2000-01-09 22:47:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 15:14:10 +00:00
										 |  |  |     def create_static_lib(self, objects, output_libname, | 
					
						
							| 
									
										
											  
											
												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 16:12:02 +00:00
										 |  |  |                           output_dir=None, debug=0, target_lang=None): | 
					
						
							| 
									
										
										
										
											2002-06-13 15:14:10 +00:00
										 |  |  |         objects, output_dir = self._fix_object_args(objects, output_dir) | 
					
						
							| 
									
										
										
										
											2000-01-09 22:47:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-03-06 03:40:29 +00:00
										 |  |  |         output_filename = \ | 
					
						
							| 
									
										
										
										
											2000-09-26 01:56:15 +00:00
										 |  |  |             self.library_filename(output_libname, output_dir=output_dir) | 
					
						
							| 
									
										
										
										
											2000-01-09 22:47:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-26 01:56:15 +00:00
										 |  |  |         if self._need_link(objects, output_filename): | 
					
						
							|  |  |  |             self.mkpath(os.path.dirname(output_filename)) | 
					
						
							|  |  |  |             self.spawn(self.archiver + | 
					
						
							|  |  |  |                        [output_filename] + | 
					
						
							|  |  |  |                        objects + self.objects) | 
					
						
							| 
									
										
										
										
											2000-04-14 00:48:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-14 13:53:34 +00:00
										 |  |  |             # Not many Unices required ranlib anymore -- SunOS 4.x is, I | 
					
						
							|  |  |  |             # think the only major Unix that does.  Maybe we need some | 
					
						
							|  |  |  |             # platform intelligence here to skip ranlib if it's not | 
					
						
							|  |  |  |             # needed -- or maybe Python's configure script took care of | 
					
						
							|  |  |  |             # it for us, hence the check for leading colon. | 
					
						
							| 
									
										
										
										
											2000-06-25 02:05:29 +00:00
										 |  |  |             if self.ranlib: | 
					
						
							| 
									
										
										
										
											2000-05-30 01:56:44 +00:00
										 |  |  |                 try: | 
					
						
							| 
									
										
										
										
											2000-09-26 01:56:15 +00:00
										 |  |  |                     self.spawn(self.ranlib + [output_filename]) | 
					
						
							| 
									
										
										
										
											2000-05-30 01:56:44 +00:00
										 |  |  |                 except DistutilsExecError, msg: | 
					
						
							|  |  |  |                     raise LibError, msg | 
					
						
							| 
									
										
										
										
											2000-01-09 22:47:53 +00:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2002-06-04 20:14:43 +00:00
										 |  |  |             log.debug("skipping %s (up-to-date)", output_filename) | 
					
						
							| 
									
										
										
										
											2000-01-09 22:47:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 15:14:10 +00: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, | 
					
						
							| 
									
										
											  
											
												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 16:12:02 +00:00
										 |  |  |              extra_postargs=None, build_temp=None, target_lang=None): | 
					
						
							| 
									
										
										
										
											2002-06-13 15:14:10 +00:00
										 |  |  |         objects, output_dir = self._fix_object_args(objects, output_dir) | 
					
						
							|  |  |  |         libraries, library_dirs, runtime_library_dirs = \ | 
					
						
							| 
									
										
										
										
											2000-09-26 01:56:15 +00:00
										 |  |  |             self._fix_lib_args(libraries, library_dirs, runtime_library_dirs) | 
					
						
							| 
									
										
										
										
											1999-12-12 16:57:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 15:14:10 +00:00
										 |  |  |         lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs, | 
					
						
							| 
									
										
										
										
											2000-09-26 01:56:15 +00:00
										 |  |  |                                    libraries) | 
					
						
							|  |  |  |         if type(output_dir) not in (StringType, NoneType): | 
					
						
							| 
									
										
										
										
											2000-02-10 02:51:32 +00:00
										 |  |  |             raise TypeError, "'output_dir' must be a string or None" | 
					
						
							| 
									
										
										
										
											1999-09-13 03:12:53 +00:00
										 |  |  |         if output_dir is not None: | 
					
						
							| 
									
										
										
										
											2000-09-26 01:56:15 +00:00
										 |  |  |             output_filename = os.path.join(output_dir, output_filename) | 
					
						
							| 
									
										
										
										
											1999-09-13 03:12:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-26 01:56:15 +00:00
										 |  |  |         if self._need_link(objects, output_filename): | 
					
						
							| 
									
										
										
										
											2001-12-06 20:51:35 +00:00
										 |  |  |             ld_args = (objects + self.objects + | 
					
						
							| 
									
										
										
										
											2000-03-06 03:40:29 +00:00
										 |  |  |                        lib_opts + ['-o', output_filename]) | 
					
						
							| 
									
										
										
										
											2000-02-09 02:17:00 +00:00
										 |  |  |             if debug: | 
					
						
							|  |  |  |                 ld_args[:0] = ['-g'] | 
					
						
							| 
									
										
										
										
											1999-09-29 12:22:50 +00:00
										 |  |  |             if extra_preargs: | 
					
						
							|  |  |  |                 ld_args[:0] = extra_preargs | 
					
						
							|  |  |  |             if extra_postargs: | 
					
						
							| 
									
										
										
										
											2000-09-26 01:56:15 +00:00
										 |  |  |                 ld_args.extend(extra_postargs) | 
					
						
							|  |  |  |             self.mkpath(os.path.dirname(output_filename)) | 
					
						
							| 
									
										
										
										
											2000-05-30 01:56:44 +00:00
										 |  |  |             try: | 
					
						
							| 
									
										
										
										
											2001-12-06 20:51:35 +00:00
										 |  |  |                 if target_desc == CCompiler.EXECUTABLE: | 
					
						
							| 
									
										
											  
											
												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 16:12:02 +00:00
										 |  |  |                     linker = self.linker_exe[:] | 
					
						
							| 
									
										
										
										
											2000-09-27 02:08:14 +00:00
										 |  |  |                 else: | 
					
						
							| 
									
										
											  
											
												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 16:12:02 +00:00
										 |  |  |                     linker = self.linker_so[:] | 
					
						
							|  |  |  |                 if target_lang == "c++" and self.compiler_cxx: | 
					
						
							|  |  |  |                     linker[0] = self.compiler_cxx[0] | 
					
						
							|  |  |  |                 self.spawn(linker + ld_args) | 
					
						
							| 
									
										
										
										
											2000-05-30 01:56:44 +00:00
										 |  |  |             except DistutilsExecError, msg: | 
					
						
							|  |  |  |                 raise LinkError, msg | 
					
						
							| 
									
										
										
										
											1999-09-13 03:12:53 +00:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2002-06-04 20:14:43 +00:00
										 |  |  |             log.debug("skipping %s (up-to-date)", output_filename) | 
					
						
							| 
									
										
										
										
											1999-08-14 23:53:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-03-06 03:40:29 +00:00
										 |  |  |     # -- Miscellaneous methods ----------------------------------------- | 
					
						
							|  |  |  |     # These are all used by the 'gen_lib_options() function, in | 
					
						
							|  |  |  |     # ccompiler.py. | 
					
						
							| 
									
										
										
										
											2001-12-06 20:51:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 14:58:30 +00:00
										 |  |  |     def library_dir_option(self, dir): | 
					
						
							| 
									
										
										
										
											1999-10-03 20:45:33 +00:00
										 |  |  |         return "-L" + dir | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 14:58:30 +00:00
										 |  |  |     def runtime_library_dir_option(self, dir): | 
					
						
							| 
									
										
										
										
											2001-12-11 05:04:24 +00:00
										 |  |  |         # XXX Hackish, at the very least.  See Python bug #445902: | 
					
						
							|  |  |  |         # http://sourceforge.net/tracker/index.php | 
					
						
							|  |  |  |         #   ?func=detail&aid=445902&group_id=5470&atid=105470 | 
					
						
							|  |  |  |         # Linkers on different platforms need different options to | 
					
						
							|  |  |  |         # specify that directories need to be added to the list of | 
					
						
							|  |  |  |         # directories searched for dependencies when a dynamic library | 
					
						
							|  |  |  |         # is sought.  GCC has to be told to pass the -R option through | 
					
						
							|  |  |  |         # to the linker, whereas other compilers just know this. | 
					
						
							|  |  |  |         # Other compilers may need something slightly different.  At | 
					
						
							|  |  |  |         # this time, there's no way to determine this information from | 
					
						
							|  |  |  |         # the configuration data stored in the Python installation, so | 
					
						
							|  |  |  |         # we use this hack. | 
					
						
							|  |  |  |         compiler = os.path.basename(sysconfig.get_config_var("CC")) | 
					
						
							| 
									
										
										
										
											2002-10-09 21:37:18 +00:00
										 |  |  |         if sys.platform[:6] == "darwin": | 
					
						
							|  |  |  |             # MacOSX's linker doesn't understand the -R flag at all | 
					
						
							|  |  |  |             return "-L" + dir | 
					
						
							| 
									
										
										
										
											2003-06-01 19:27:40 +00:00
										 |  |  |         elif sys.platform[:5] == "hp-ux": | 
					
						
							| 
									
										
										
										
											2003-05-31 08:09:21 +00:00
										 |  |  |             return "+s -L" + dir | 
					
						
							| 
									
										
										
										
											2004-08-29 16:40:55 +00:00
										 |  |  |         elif sys.platform[:7] == "irix646" or sys.platform[:6] == "osf1V5": | 
					
						
							|  |  |  |             return ["-rpath", dir] | 
					
						
							| 
									
										
										
										
											2003-06-01 19:27:40 +00:00
										 |  |  |         elif compiler[:3] == "gcc" or compiler[:3] == "g++": | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  |             return "-Wl,-R" + dir | 
					
						
							| 
									
										
										
										
											2001-12-11 05:04:24 +00:00
										 |  |  |         else: | 
					
						
							|  |  |  |             return "-R" + dir | 
					
						
							| 
									
										
										
										
											2000-03-18 15:19:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 14:58:30 +00:00
										 |  |  |     def library_option(self, lib): | 
					
						
							| 
									
										
										
										
											1999-10-03 20:45:33 +00:00
										 |  |  |         return "-l" + lib | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 14:58:30 +00:00
										 |  |  |     def find_library_file(self, dirs, lib, debug=0): | 
					
						
							| 
									
										
										
										
											2002-06-13 15:14:10 +00:00
										 |  |  |         shared_f = self.library_filename(lib, lib_type='shared') | 
					
						
							|  |  |  |         dylib_f = self.library_filename(lib, lib_type='dylib') | 
					
						
							|  |  |  |         static_f = self.library_filename(lib, lib_type='static') | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-10-03 20:45:33 +00:00
										 |  |  |         for dir in dirs: | 
					
						
							| 
									
										
										
										
											2002-06-13 15:14:10 +00:00
										 |  |  |             shared = os.path.join(dir, shared_f) | 
					
						
							|  |  |  |             dylib = os.path.join(dir, dylib_f) | 
					
						
							|  |  |  |             static = os.path.join(dir, static_f) | 
					
						
							| 
									
										
										
										
											1999-10-03 20:45:33 +00:00
										 |  |  |             # We're second-guessing the linker here, with not much hard | 
					
						
							|  |  |  |             # data to go on: GCC seems to prefer the shared library, so I'm | 
					
						
							|  |  |  |             # assuming that *all* Unix C compilers do.  And of course I'm | 
					
						
							|  |  |  |             # ignoring even GCC's "-static" option.  So sue me. | 
					
						
							| 
									
										
										
										
											2001-08-27 15:08:16 +00:00
										 |  |  |             if os.path.exists(dylib): | 
					
						
							|  |  |  |                 return dylib | 
					
						
							|  |  |  |             elif os.path.exists(shared): | 
					
						
							| 
									
										
										
										
											1999-10-03 20:45:33 +00:00
										 |  |  |                 return shared | 
					
						
							| 
									
										
										
										
											2000-09-26 01:56:15 +00:00
										 |  |  |             elif os.path.exists(static): | 
					
						
							| 
									
										
										
										
											1999-10-03 20:45:33 +00:00
										 |  |  |                 return static | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 15:14:10 +00:00
										 |  |  |         # Oops, didn't find it in *any* of 'dirs' | 
					
						
							|  |  |  |         return None |