| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  | """distutils.bcppcompiler
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Contains BorlandCCompiler, an implementation of the abstract CCompiler class | 
					
						
							|  |  |  | for the Borland C++ compiler. | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # This implementation by Lyle Johnson, based on the original msvccompiler.py | 
					
						
							|  |  |  | # module and using the directions originally published by Gordon Williams. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # XXX looks like there's a LOT of overlap between these two classes: | 
					
						
							|  |  |  | # someone should sit down and factor out the common code as | 
					
						
							|  |  |  | # WindowsCCompiler!  --GPW | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-19 13:12:28 +00:00
										 |  |  | # This module should be kept compatible with Python 1.5.2. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  | __revision__ = "$Id$" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-09 11:14:08 +00:00
										 |  |  | import sys, os | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  | from distutils.errors import \ | 
					
						
							|  |  |  |      DistutilsExecError, DistutilsPlatformError, \ | 
					
						
							| 
									
										
										
										
											2001-08-09 21:02:34 +00:00
										 |  |  |      CompileError, LibError, LinkError, UnknownFileError | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  | from distutils.ccompiler import \ | 
					
						
							|  |  |  |      CCompiler, gen_preprocess_options, gen_lib_options | 
					
						
							| 
									
										
										
										
											2000-08-02 01:03:23 +00:00
										 |  |  | from distutils.file_util import write_file | 
					
						
							| 
									
										
										
										
											2001-08-16 20:17:41 +00:00
										 |  |  | from distutils.dep_util import newer | 
					
						
							| 
									
										
										
										
											2002-06-04 20:14:43 +00:00
										 |  |  | from distutils import log | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | class BCPPCompiler(CCompiler) : | 
					
						
							|  |  |  |     """Concrete class that implements an interface to the Borland C/C++
 | 
					
						
							|  |  |  |     compiler, as defined by the CCompiler abstract class. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     compiler_type = 'bcpp' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Just set this so CCompiler's constructor doesn't barf.  We currently | 
					
						
							|  |  |  |     # don't use the 'set_executables()' bureaucracy provided by CCompiler, | 
					
						
							|  |  |  |     # as it really isn't necessary for this sort of single-compiler class. | 
					
						
							|  |  |  |     # Would be nice to have a consistent interface with UnixCCompiler, | 
					
						
							|  |  |  |     # though, so it's worth thinking about. | 
					
						
							|  |  |  |     executables = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Private class data (need to distinguish C from C++ source for compiler) | 
					
						
							|  |  |  |     _c_extensions = ['.c'] | 
					
						
							|  |  |  |     _cpp_extensions = ['.cc', '.cpp', '.cxx'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Needed for the filename generation methods provided by the | 
					
						
							|  |  |  |     # base class, CCompiler. | 
					
						
							|  |  |  |     src_extensions = _c_extensions + _cpp_extensions | 
					
						
							|  |  |  |     obj_extension = '.obj' | 
					
						
							|  |  |  |     static_lib_extension = '.lib' | 
					
						
							|  |  |  |     shared_lib_extension = '.dll' | 
					
						
							|  |  |  |     static_lib_format = shared_lib_format = '%s%s' | 
					
						
							|  |  |  |     exe_extension = '.exe' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __init__ (self, | 
					
						
							|  |  |  |                   verbose=0, | 
					
						
							|  |  |  |                   dry_run=0, | 
					
						
							|  |  |  |                   force=0): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         CCompiler.__init__ (self, verbose, dry_run, force) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # These executables are assumed to all be in the path. | 
					
						
							|  |  |  |         # Borland doesn't seem to use any special registry settings to | 
					
						
							|  |  |  |         # indicate their installation locations. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self.cc = "bcc32.exe" | 
					
						
							| 
									
										
										
										
											2000-09-27 02:08:14 +00:00
										 |  |  |         self.linker = "ilink32.exe" | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  |         self.lib = "tlib.exe" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self.preprocess_options = None | 
					
						
							| 
									
										
										
										
											2000-08-13 00:43:16 +00:00
										 |  |  |         self.compile_options = ['/tWM', '/O2', '/q', '/g0'] | 
					
						
							|  |  |  |         self.compile_options_debug = ['/tWM', '/Od', '/q', '/g0'] | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         self.ldflags_shared = ['/Tpd', '/Gn', '/q', '/x'] | 
					
						
							|  |  |  |         self.ldflags_shared_debug = ['/Tpd', '/Gn', '/q', '/x'] | 
					
						
							|  |  |  |         self.ldflags_static = [] | 
					
						
							| 
									
										
										
										
											2000-09-27 02:08:14 +00:00
										 |  |  |         self.ldflags_exe = ['/Gn', '/q', '/x'] | 
					
						
							|  |  |  |         self.ldflags_exe_debug = ['/Gn', '/q', '/x','/r'] | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # -- Worker methods ------------------------------------------------ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 17:28:18 +00:00
										 |  |  |     def compile(self, sources, | 
					
						
							|  |  |  |                 output_dir=None, macros=None, include_dirs=None, debug=0, | 
					
						
							|  |  |  |                 extra_preargs=None, extra_postargs=None, depends=None): | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 17:28:18 +00:00
										 |  |  |         macros, objects, extra_postargs, pp_opts, build = \ | 
					
						
							|  |  |  |                 self._setup_compile(output_dir, macros, include_dirs, sources, | 
					
						
							|  |  |  |                                     depends, extra_postargs) | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  |         compile_opts = extra_preargs or [] | 
					
						
							|  |  |  |         compile_opts.append ('-c') | 
					
						
							|  |  |  |         if debug: | 
					
						
							|  |  |  |             compile_opts.extend (self.compile_options_debug) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             compile_opts.extend (self.compile_options) | 
					
						
							| 
									
										
										
										
											2001-12-06 20:51:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-12-05 20:12:23 +00:00
										 |  |  |         for obj in objects: | 
					
						
							|  |  |  |             try: | 
					
						
							|  |  |  |                 src, ext = build[obj] | 
					
						
							|  |  |  |             except KeyError: | 
					
						
							|  |  |  |                 continue | 
					
						
							| 
									
										
										
										
											2002-06-13 17:28:18 +00:00
										 |  |  |             # XXX why do the normpath here? | 
					
						
							|  |  |  |             src = os.path.normpath(src) | 
					
						
							|  |  |  |             obj = os.path.normpath(obj) | 
					
						
							|  |  |  |             # XXX _setup_compile() did a mkpath() too but before the normpath. | 
					
						
							|  |  |  |             # Is it possible to skip the normpath? | 
					
						
							|  |  |  |             self.mkpath(os.path.dirname(obj)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if ext == '.res': | 
					
						
							|  |  |  |                 # This is already a binary file -- skip it. | 
					
						
							|  |  |  |                 continue # the 'for' loop | 
					
						
							|  |  |  |             if ext == '.rc': | 
					
						
							|  |  |  |                 # This needs to be compiled to a .res file -- do it now. | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  |                 try: | 
					
						
							| 
									
										
										
										
											2002-06-13 17:28:18 +00:00
										 |  |  |                     self.spawn (["brcc32", "-fo", obj, src]) | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  |                 except DistutilsExecError, msg: | 
					
						
							|  |  |  |                     raise CompileError, msg | 
					
						
							| 
									
										
										
										
											2002-06-13 17:28:18 +00:00
										 |  |  |                 continue # the 'for' loop | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # The next two are both for the real compiler. | 
					
						
							|  |  |  |             if ext in self._c_extensions: | 
					
						
							|  |  |  |                 input_opt = "" | 
					
						
							|  |  |  |             elif ext in self._cpp_extensions: | 
					
						
							|  |  |  |                 input_opt = "-P" | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 # Unknown file type -- no extra options.  The compiler | 
					
						
							|  |  |  |                 # will probably fail, but let it just in case this is a | 
					
						
							|  |  |  |                 # file the compiler recognizes even if we don't. | 
					
						
							|  |  |  |                 input_opt = "" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             output_opt = "-o" + obj | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # Compiler command line syntax is: "bcc32 [options] file(s)". | 
					
						
							|  |  |  |             # Note that the source file names must appear at the end of | 
					
						
							|  |  |  |             # the command line. | 
					
						
							|  |  |  |             try: | 
					
						
							|  |  |  |                 self.spawn ([self.cc] + compile_opts + pp_opts + | 
					
						
							|  |  |  |                             [input_opt, output_opt] + | 
					
						
							|  |  |  |                             extra_postargs + [src]) | 
					
						
							|  |  |  |             except DistutilsExecError, msg: | 
					
						
							|  |  |  |                 raise CompileError, msg | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return objects | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # compile () | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def create_static_lib (self, | 
					
						
							|  |  |  |                            objects, | 
					
						
							|  |  |  |                            output_libname, | 
					
						
							|  |  |  |                            output_dir=None, | 
					
						
							|  |  |  |                            debug=0, | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |                            target_lang=None): | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         (objects, output_dir) = self._fix_object_args (objects, output_dir) | 
					
						
							|  |  |  |         output_filename = \ | 
					
						
							|  |  |  |             self.library_filename (output_libname, output_dir=output_dir) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if self._need_link (objects, output_filename): | 
					
						
							|  |  |  |             lib_args = [output_filename, '/u'] + objects | 
					
						
							|  |  |  |             if debug: | 
					
						
							|  |  |  |                 pass                    # XXX what goes here? | 
					
						
							|  |  |  |             try: | 
					
						
							| 
									
										
										
										
											2001-12-06 20:51:35 +00:00
										 |  |  |                 self.spawn ([self.lib] + lib_args) | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  |             except DistutilsExecError, msg: | 
					
						
							| 
									
										
										
										
											2001-12-06 20:51:35 +00:00
										 |  |  |                 raise LibError, msg | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2002-06-04 20:14:43 +00:00
										 |  |  |             log.debug("skipping %s (up-to-date)", output_filename) | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # create_static_lib () | 
					
						
							| 
									
										
										
										
											2001-12-06 20:51:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-27 02:08:14 +00:00
										 |  |  |     def link (self, | 
					
						
							| 
									
										
										
										
											2001-12-06 20:51:35 +00:00
										 |  |  |               target_desc, | 
					
						
							| 
									
										
										
										
											2000-09-27 02:08:14 +00:00
										 |  |  |               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, | 
					
						
							| 
									
										
											  
											
												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
										 |  |  |               build_temp=None, | 
					
						
							|  |  |  |               target_lang=None): | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-02 01:03:23 +00:00
										 |  |  |         # XXX this ignores 'build_temp'!  should follow the lead of | 
					
						
							|  |  |  |         # msvccompiler.py | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  |         (objects, output_dir) = self._fix_object_args (objects, output_dir) | 
					
						
							|  |  |  |         (libraries, library_dirs, runtime_library_dirs) = \ | 
					
						
							|  |  |  |             self._fix_lib_args (libraries, library_dirs, runtime_library_dirs) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if runtime_library_dirs: | 
					
						
							| 
									
										
										
										
											2002-06-04 20:14:43 +00:00
										 |  |  |             log.warn("I don't know what to do with 'runtime_library_dirs': %s", | 
					
						
							|  |  |  |                      str(runtime_library_dirs)) | 
					
						
							| 
									
										
										
										
											2000-09-27 02:08:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  |         if output_dir is not None: | 
					
						
							|  |  |  |             output_filename = os.path.join (output_dir, output_filename) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if self._need_link (objects, output_filename): | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-27 02:08:14 +00:00
										 |  |  |             # Figure out linker args based on type of target. | 
					
						
							|  |  |  |             if target_desc == CCompiler.EXECUTABLE: | 
					
						
							|  |  |  |                 startup_obj = 'c0w32' | 
					
						
							|  |  |  |                 if debug: | 
					
						
							|  |  |  |                     ld_args = self.ldflags_exe_debug[:] | 
					
						
							|  |  |  |                 else: | 
					
						
							|  |  |  |                     ld_args = self.ldflags_exe[:] | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  |             else: | 
					
						
							| 
									
										
										
										
											2000-09-27 02:08:14 +00:00
										 |  |  |                 startup_obj = 'c0d32' | 
					
						
							|  |  |  |                 if debug: | 
					
						
							|  |  |  |                     ld_args = self.ldflags_shared_debug[:] | 
					
						
							|  |  |  |                 else: | 
					
						
							|  |  |  |                     ld_args = self.ldflags_shared[:] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             # Create a temporary exports file for use by the linker | 
					
						
							| 
									
										
										
										
											2000-09-27 02:08:14 +00:00
										 |  |  |             if export_symbols is None: | 
					
						
							|  |  |  |                 def_file = '' | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 head, tail = os.path.split (output_filename) | 
					
						
							|  |  |  |                 modname, ext = os.path.splitext (tail) | 
					
						
							|  |  |  |                 temp_dir = os.path.dirname(objects[0]) # preserve tree structure | 
					
						
							|  |  |  |                 def_file = os.path.join (temp_dir, '%s.def' % modname) | 
					
						
							|  |  |  |                 contents = ['EXPORTS'] | 
					
						
							|  |  |  |                 for sym in (export_symbols or []): | 
					
						
							|  |  |  |                     contents.append('  %s=_%s' % (sym, sym)) | 
					
						
							|  |  |  |                 self.execute(write_file, (def_file, contents), | 
					
						
							|  |  |  |                              "writing %s" % def_file) | 
					
						
							| 
									
										
										
										
											2000-08-02 01:03:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-01 01:28:33 +00:00
										 |  |  |             # Borland C++ has problems with '/' in paths | 
					
						
							| 
									
										
										
										
											2000-09-27 02:08:14 +00:00
										 |  |  |             objects2 = map(os.path.normpath, objects) | 
					
						
							|  |  |  |             # split objects in .obj and .res files | 
					
						
							|  |  |  |             # Borland C++ needs them at different positions in the command line | 
					
						
							|  |  |  |             objects = [startup_obj] | 
					
						
							|  |  |  |             resources = [] | 
					
						
							|  |  |  |             for file in objects2: | 
					
						
							|  |  |  |                 (base, ext) = os.path.splitext(os.path.normcase(file)) | 
					
						
							|  |  |  |                 if ext == '.res': | 
					
						
							|  |  |  |                     resources.append(file) | 
					
						
							|  |  |  |                 else: | 
					
						
							|  |  |  |                     objects.append(file) | 
					
						
							| 
									
										
										
										
											2001-12-06 20:51:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-02 01:03:23 +00:00
										 |  |  |             for l in library_dirs: | 
					
						
							| 
									
										
										
										
											2001-12-06 20:51:35 +00:00
										 |  |  |                 ld_args.append("/L%s" % os.path.normpath(l)) | 
					
						
							| 
									
										
										
										
											2000-09-27 02:08:14 +00:00
										 |  |  |             ld_args.append("/L.") # we sometimes use relative paths | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-12-06 20:51:35 +00:00
										 |  |  |             # list of object files | 
					
						
							|  |  |  |             ld_args.extend(objects) | 
					
						
							| 
									
										
										
										
											2000-08-02 01:03:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-13 00:54:39 +00:00
										 |  |  |             # XXX the command-line syntax for Borland C++ is a bit wonky; | 
					
						
							|  |  |  |             # certain filenames are jammed together in one big string, but | 
					
						
							|  |  |  |             # comma-delimited.  This doesn't mesh too well with the | 
					
						
							|  |  |  |             # Unix-centric attitude (with a DOS/Windows quoting hack) of | 
					
						
							|  |  |  |             # 'spawn()', so constructing the argument list is a bit | 
					
						
							|  |  |  |             # awkward.  Note that doing the obvious thing and jamming all | 
					
						
							|  |  |  |             # the filenames and commas into one argument would be wrong, | 
					
						
							|  |  |  |             # because 'spawn()' would quote any filenames with spaces in | 
					
						
							|  |  |  |             # them.  Arghghh!.  Apparently it works fine as coded... | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-27 02:08:14 +00:00
										 |  |  |             # name of dll/exe file | 
					
						
							| 
									
										
										
										
											2000-08-02 01:03:23 +00:00
										 |  |  |             ld_args.extend([',',output_filename]) | 
					
						
							| 
									
										
										
										
											2001-12-06 20:51:35 +00:00
										 |  |  |             # no map file and start libraries | 
					
						
							| 
									
										
										
										
											2000-08-13 00:43:16 +00:00
										 |  |  |             ld_args.append(',,') | 
					
						
							| 
									
										
										
										
											2000-08-02 01:03:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             for lib in libraries: | 
					
						
							| 
									
										
										
										
											2001-12-06 20:51:35 +00:00
										 |  |  |                 # see if we find it and if there is a bcpp specific lib | 
					
						
							| 
									
										
										
										
											2000-09-27 02:08:14 +00:00
										 |  |  |                 # (xxx_bcpp.lib) | 
					
						
							| 
									
										
										
										
											2000-08-02 01:03:23 +00:00
										 |  |  |                 libfile = self.find_library_file(library_dirs, lib, debug) | 
					
						
							|  |  |  |                 if libfile is None: | 
					
						
							|  |  |  |                     ld_args.append(lib) | 
					
						
							|  |  |  |                     # probably a BCPP internal library -- don't warn | 
					
						
							|  |  |  |                 else: | 
					
						
							|  |  |  |                     # full name which prefers bcpp_xxx.lib over xxx.lib | 
					
						
							|  |  |  |                     ld_args.append(libfile) | 
					
						
							| 
									
										
										
										
											2000-09-27 02:08:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             # some default libraries | 
					
						
							|  |  |  |             ld_args.append ('import32') | 
					
						
							|  |  |  |             ld_args.append ('cw32mt') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-02 01:03:23 +00:00
										 |  |  |             # def file for export symbols | 
					
						
							|  |  |  |             ld_args.extend([',',def_file]) | 
					
						
							| 
									
										
										
										
											2000-09-27 02:08:14 +00:00
										 |  |  |             # add resource files | 
					
						
							|  |  |  |             ld_args.append(',') | 
					
						
							|  |  |  |             ld_args.extend(resources) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-12-06 20:51:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  |             if extra_preargs: | 
					
						
							|  |  |  |                 ld_args[:0] = extra_preargs | 
					
						
							|  |  |  |             if extra_postargs: | 
					
						
							| 
									
										
										
										
											2000-08-02 01:03:23 +00:00
										 |  |  |                 ld_args.extend(extra_postargs) | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             self.mkpath (os.path.dirname (output_filename)) | 
					
						
							|  |  |  |             try: | 
					
						
							| 
									
										
										
										
											2000-09-27 02:08:14 +00:00
										 |  |  |                 self.spawn ([self.linker] + ld_args) | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  |             except DistutilsExecError, msg: | 
					
						
							|  |  |  |                 raise LinkError, msg | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         else: | 
					
						
							| 
									
										
										
										
											2002-06-04 20:14:43 +00:00
										 |  |  |             log.debug("skipping %s (up-to-date)", output_filename) | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-27 02:08:14 +00:00
										 |  |  |     # link () | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # -- Miscellaneous methods ----------------------------------------- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-02 01:03:23 +00:00
										 |  |  |     def find_library_file (self, dirs, lib, debug=0): | 
					
						
							| 
									
										
										
										
											2000-08-04 01:30:03 +00:00
										 |  |  |         # List of effective library names to try, in order of preference: | 
					
						
							| 
									
										
										
										
											2000-09-27 02:08:14 +00:00
										 |  |  |         # xxx_bcpp.lib is better than xxx.lib | 
					
						
							| 
									
										
										
										
											2000-08-02 01:03:23 +00:00
										 |  |  |         # and xxx_d.lib is better than xxx.lib if debug is set | 
					
						
							| 
									
										
										
										
											2000-08-04 01:30:03 +00:00
										 |  |  |         # | 
					
						
							| 
									
										
										
										
											2000-09-27 02:08:14 +00:00
										 |  |  |         # The "_bcpp" suffix is to handle a Python installation for people | 
					
						
							| 
									
										
										
										
											2000-08-04 01:30:03 +00:00
										 |  |  |         # with multiple compilers (primarily Distutils hackers, I suspect | 
					
						
							|  |  |  |         # ;-).  The idea is they'd have one static library for each | 
					
						
							|  |  |  |         # compiler they care about, since (almost?) every Windows compiler | 
					
						
							|  |  |  |         # seems to have a different format for static libraries. | 
					
						
							|  |  |  |         if debug: | 
					
						
							|  |  |  |             dlib = (lib + "_d") | 
					
						
							| 
									
										
										
										
											2000-09-01 01:28:33 +00:00
										 |  |  |             try_names = (dlib + "_bcpp", lib + "_bcpp", dlib, lib) | 
					
						
							| 
									
										
										
										
											2000-08-04 01:30:03 +00:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2000-09-01 01:28:33 +00:00
										 |  |  |             try_names = (lib + "_bcpp", lib) | 
					
						
							| 
									
										
										
										
											2000-08-04 01:30:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  |         for dir in dirs: | 
					
						
							| 
									
										
										
										
											2000-08-04 01:30:03 +00:00
										 |  |  |             for name in try_names: | 
					
						
							|  |  |  |                 libfile = os.path.join(dir, self.library_filename(name)) | 
					
						
							|  |  |  |                 if os.path.exists(libfile): | 
					
						
							| 
									
										
										
										
											2000-08-02 01:03:23 +00:00
										 |  |  |                     return libfile | 
					
						
							| 
									
										
										
										
											2000-06-28 01:20:35 +00:00
										 |  |  |         else: | 
					
						
							|  |  |  |             # Oops, didn't find it in *any* of 'dirs' | 
					
						
							|  |  |  |             return None | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-27 02:08:14 +00:00
										 |  |  |     # overwrite the one from CCompiler to support rc and res-files | 
					
						
							|  |  |  |     def object_filenames (self, | 
					
						
							|  |  |  |                           source_filenames, | 
					
						
							|  |  |  |                           strip_dir=0, | 
					
						
							|  |  |  |                           output_dir=''): | 
					
						
							|  |  |  |         if output_dir is None: 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)) | 
					
						
							|  |  |  |             if ext not in (self.src_extensions + ['.rc','.res']): | 
					
						
							|  |  |  |                 raise UnknownFileError, \ | 
					
						
							|  |  |  |                       "unknown file type '%s' (from '%s')" % \ | 
					
						
							|  |  |  |                       (ext, src_name) | 
					
						
							|  |  |  |             if strip_dir: | 
					
						
							|  |  |  |                 base = os.path.basename (base) | 
					
						
							|  |  |  |             if ext == '.res': | 
					
						
							|  |  |  |                 # these can go unchanged | 
					
						
							|  |  |  |                 obj_names.append (os.path.join (output_dir, base + ext)) | 
					
						
							|  |  |  |             elif ext == '.rc': | 
					
						
							|  |  |  |                 # these need to be compiled to .res-files | 
					
						
							|  |  |  |                 obj_names.append (os.path.join (output_dir, base + '.res')) | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 obj_names.append (os.path.join (output_dir, | 
					
						
							|  |  |  |                                             base + self.obj_extension)) | 
					
						
							|  |  |  |         return obj_names | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # object_filenames () | 
					
						
							| 
									
										
										
										
											2001-08-16 20:17:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def preprocess (self, | 
					
						
							|  |  |  |                     source, | 
					
						
							|  |  |  |                     output_file=None, | 
					
						
							|  |  |  |                     macros=None, | 
					
						
							|  |  |  |                     include_dirs=None, | 
					
						
							|  |  |  |                     extra_preargs=None, | 
					
						
							|  |  |  |                     extra_postargs=None): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         (_, macros, include_dirs) = \ | 
					
						
							|  |  |  |             self._fix_compile_args(None, macros, include_dirs) | 
					
						
							|  |  |  |         pp_opts = gen_preprocess_options(macros, include_dirs) | 
					
						
							|  |  |  |         pp_args = ['cpp32.exe'] + pp_opts | 
					
						
							|  |  |  |         if output_file is not None: | 
					
						
							|  |  |  |             pp_args.append('-o' + output_file) | 
					
						
							|  |  |  |         if extra_preargs: | 
					
						
							|  |  |  |             pp_args[:0] = extra_preargs | 
					
						
							|  |  |  |         if extra_postargs: | 
					
						
							|  |  |  |             pp_args.extend(extra_postargs) | 
					
						
							|  |  |  |         pp_args.append(source) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # We need to preprocess: either we're being forced to, or the | 
					
						
							|  |  |  |         # source file is newer than the target (or the target doesn't | 
					
						
							|  |  |  |         # exist). | 
					
						
							|  |  |  |         if self.force or output_file is None or newer(source, output_file): | 
					
						
							|  |  |  |             if output_file: | 
					
						
							|  |  |  |                 self.mkpath(os.path.dirname(output_file)) | 
					
						
							|  |  |  |             try: | 
					
						
							|  |  |  |                 self.spawn(pp_args) | 
					
						
							|  |  |  |             except DistutilsExecError, msg: | 
					
						
							|  |  |  |                 print msg | 
					
						
							|  |  |  |                 raise CompileError, msg | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # preprocess() |