| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 1 | """distutils.bcppcompiler | 
 | 2 |  | 
 | 3 | Contains BorlandCCompiler, an implementation of the abstract CCompiler class | 
 | 4 | for the Borland C++ compiler. | 
 | 5 | """ | 
 | 6 |  | 
 | 7 | # This implementation by Lyle Johnson, based on the original msvccompiler.py | 
 | 8 | # module and using the directions originally published by Gordon Williams. | 
 | 9 |  | 
 | 10 | # XXX looks like there's a LOT of overlap between these two classes: | 
 | 11 | # someone should sit down and factor out the common code as | 
 | 12 | # WindowsCCompiler!  --GPW | 
 | 13 |  | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 14 | __revision__ = "$Id$" | 
 | 15 |  | 
 | 16 |  | 
| Eric S. Raymond | 8b3cf58 | 2001-02-09 11:14:08 +0000 | [diff] [blame] | 17 | import sys, os | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 18 | from distutils.errors import \ | 
 | 19 |      DistutilsExecError, DistutilsPlatformError, \ | 
| Andrew M. Kuchling | 6386a4c | 2001-08-09 21:02:34 +0000 | [diff] [blame] | 20 |      CompileError, LibError, LinkError, UnknownFileError | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 21 | from distutils.ccompiler import \ | 
 | 22 |      CCompiler, gen_preprocess_options, gen_lib_options | 
| Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 23 | from distutils.file_util import write_file | 
| Andrew M. Kuchling | db7aed5 | 2001-08-16 20:17:41 +0000 | [diff] [blame] | 24 | from distutils.dep_util import newer | 
| Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 25 | from distutils import log | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 26 |  | 
 | 27 | class BCPPCompiler(CCompiler) : | 
 | 28 |     """Concrete class that implements an interface to the Borland C/C++ | 
 | 29 |     compiler, as defined by the CCompiler abstract class. | 
 | 30 |     """ | 
 | 31 |  | 
 | 32 |     compiler_type = 'bcpp' | 
 | 33 |  | 
 | 34 |     # Just set this so CCompiler's constructor doesn't barf.  We currently | 
 | 35 |     # don't use the 'set_executables()' bureaucracy provided by CCompiler, | 
 | 36 |     # as it really isn't necessary for this sort of single-compiler class. | 
 | 37 |     # Would be nice to have a consistent interface with UnixCCompiler, | 
 | 38 |     # though, so it's worth thinking about. | 
 | 39 |     executables = {} | 
 | 40 |  | 
 | 41 |     # Private class data (need to distinguish C from C++ source for compiler) | 
 | 42 |     _c_extensions = ['.c'] | 
 | 43 |     _cpp_extensions = ['.cc', '.cpp', '.cxx'] | 
 | 44 |  | 
 | 45 |     # Needed for the filename generation methods provided by the | 
 | 46 |     # base class, CCompiler. | 
 | 47 |     src_extensions = _c_extensions + _cpp_extensions | 
 | 48 |     obj_extension = '.obj' | 
 | 49 |     static_lib_extension = '.lib' | 
 | 50 |     shared_lib_extension = '.dll' | 
 | 51 |     static_lib_format = shared_lib_format = '%s%s' | 
 | 52 |     exe_extension = '.exe' | 
 | 53 |  | 
 | 54 |  | 
 | 55 |     def __init__ (self, | 
 | 56 |                   verbose=0, | 
 | 57 |                   dry_run=0, | 
 | 58 |                   force=0): | 
 | 59 |  | 
 | 60 |         CCompiler.__init__ (self, verbose, dry_run, force) | 
 | 61 |  | 
 | 62 |         # These executables are assumed to all be in the path. | 
 | 63 |         # Borland doesn't seem to use any special registry settings to | 
 | 64 |         # indicate their installation locations. | 
 | 65 |  | 
 | 66 |         self.cc = "bcc32.exe" | 
| Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 67 |         self.linker = "ilink32.exe" | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 68 |         self.lib = "tlib.exe" | 
 | 69 |  | 
 | 70 |         self.preprocess_options = None | 
| Greg Ward | a4662bc | 2000-08-13 00:43:16 +0000 | [diff] [blame] | 71 |         self.compile_options = ['/tWM', '/O2', '/q', '/g0'] | 
 | 72 |         self.compile_options_debug = ['/tWM', '/Od', '/q', '/g0'] | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 73 |  | 
 | 74 |         self.ldflags_shared = ['/Tpd', '/Gn', '/q', '/x'] | 
 | 75 |         self.ldflags_shared_debug = ['/Tpd', '/Gn', '/q', '/x'] | 
 | 76 |         self.ldflags_static = [] | 
| Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 77 |         self.ldflags_exe = ['/Gn', '/q', '/x'] | 
 | 78 |         self.ldflags_exe_debug = ['/Gn', '/q', '/x','/r'] | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 79 |  | 
 | 80 |  | 
 | 81 |     # -- Worker methods ------------------------------------------------ | 
 | 82 |  | 
 | 83 |     def compile (self, | 
 | 84 |                  sources, | 
 | 85 |                  output_dir=None, | 
 | 86 |                  macros=None, | 
 | 87 |                  include_dirs=None, | 
 | 88 |                  debug=0, | 
 | 89 |                  extra_preargs=None, | 
 | 90 |                  extra_postargs=None): | 
 | 91 |  | 
 | 92 |         (output_dir, macros, include_dirs) = \ | 
 | 93 |             self._fix_compile_args (output_dir, macros, include_dirs) | 
 | 94 |         (objects, skip_sources) = self._prep_compile (sources, output_dir) | 
 | 95 |  | 
 | 96 |         if extra_postargs is None: | 
 | 97 |             extra_postargs = [] | 
 | 98 |  | 
 | 99 |         pp_opts = gen_preprocess_options (macros, include_dirs) | 
 | 100 |         compile_opts = extra_preargs or [] | 
 | 101 |         compile_opts.append ('-c') | 
 | 102 |         if debug: | 
 | 103 |             compile_opts.extend (self.compile_options_debug) | 
 | 104 |         else: | 
 | 105 |             compile_opts.extend (self.compile_options) | 
| Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 106 |  | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 107 |         for i in range (len (sources)): | 
 | 108 |             src = sources[i] ; obj = objects[i] | 
 | 109 |             ext = (os.path.splitext (src))[1] | 
 | 110 |  | 
 | 111 |             if skip_sources[src]: | 
| Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 112 |                 log.debug("skipping %s (%s up-to-date)", src, obj) | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 113 |             else: | 
| Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 114 |                 src = os.path.normpath(src) | 
 | 115 |                 obj = os.path.normpath(obj) | 
 | 116 |                 self.mkpath(os.path.dirname(obj)) | 
 | 117 |  | 
 | 118 |                 if ext == '.res': | 
 | 119 |                     # This is already a binary file -- skip it. | 
 | 120 |                     continue # the 'for' loop | 
 | 121 |                 if ext == '.rc': | 
 | 122 |                     # This needs to be compiled to a .res file -- do it now. | 
 | 123 |                     try: | 
 | 124 |                         self.spawn (["brcc32", "-fo", obj, src]) | 
 | 125 |                     except DistutilsExecError, msg: | 
 | 126 |                         raise CompileError, msg | 
 | 127 |                     continue # the 'for' loop | 
 | 128 |  | 
 | 129 |                 # The next two are both for the real compiler. | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 130 |                 if ext in self._c_extensions: | 
 | 131 |                     input_opt = "" | 
 | 132 |                 elif ext in self._cpp_extensions: | 
 | 133 |                     input_opt = "-P" | 
| Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 134 |                 else: | 
| Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 135 |                     # Unknown file type -- no extra options.  The compiler | 
 | 136 |                     # will probably fail, but let it just in case this is a | 
 | 137 |                     # file the compiler recognizes even if we don't. | 
| Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 138 |                     input_opt = "" | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 139 |  | 
 | 140 |                 output_opt = "-o" + obj | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 141 |  | 
 | 142 |                 # Compiler command line syntax is: "bcc32 [options] file(s)". | 
 | 143 |                 # Note that the source file names must appear at the end of | 
 | 144 |                 # the command line. | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 145 |                 try: | 
 | 146 |                     self.spawn ([self.cc] + compile_opts + pp_opts + | 
 | 147 |                                 [input_opt, output_opt] + | 
 | 148 |                                 extra_postargs + [src]) | 
 | 149 |                 except DistutilsExecError, msg: | 
 | 150 |                     raise CompileError, msg | 
 | 151 |  | 
 | 152 |         return objects | 
 | 153 |  | 
 | 154 |     # compile () | 
 | 155 |  | 
 | 156 |  | 
 | 157 |     def create_static_lib (self, | 
 | 158 |                            objects, | 
 | 159 |                            output_libname, | 
 | 160 |                            output_dir=None, | 
 | 161 |                            debug=0, | 
 | 162 |                            extra_preargs=None, | 
 | 163 |                            extra_postargs=None): | 
 | 164 |  | 
 | 165 |         (objects, output_dir) = self._fix_object_args (objects, output_dir) | 
 | 166 |         output_filename = \ | 
 | 167 |             self.library_filename (output_libname, output_dir=output_dir) | 
 | 168 |  | 
 | 169 |         if self._need_link (objects, output_filename): | 
 | 170 |             lib_args = [output_filename, '/u'] + objects | 
 | 171 |             if debug: | 
 | 172 |                 pass                    # XXX what goes here? | 
 | 173 |             if extra_preargs: | 
 | 174 |                 lib_args[:0] = extra_preargs | 
 | 175 |             if extra_postargs: | 
 | 176 |                 lib_args.extend (extra_postargs) | 
 | 177 |             try: | 
| Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 178 |                 self.spawn ([self.lib] + lib_args) | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 179 |             except DistutilsExecError, msg: | 
| Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 180 |                 raise LibError, msg | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 181 |         else: | 
| Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 182 |             log.debug("skipping %s (up-to-date)", output_filename) | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 183 |  | 
 | 184 |     # create_static_lib () | 
| Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 185 |  | 
 | 186 |  | 
| Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 187 |     def link (self, | 
| Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 188 |               target_desc, | 
| Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 189 |               objects, | 
 | 190 |               output_filename, | 
 | 191 |               output_dir=None, | 
 | 192 |               libraries=None, | 
 | 193 |               library_dirs=None, | 
 | 194 |               runtime_library_dirs=None, | 
 | 195 |               export_symbols=None, | 
 | 196 |               debug=0, | 
 | 197 |               extra_preargs=None, | 
 | 198 |               extra_postargs=None, | 
 | 199 |               build_temp=None): | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 200 |  | 
| Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 201 |         # XXX this ignores 'build_temp'!  should follow the lead of | 
 | 202 |         # msvccompiler.py | 
 | 203 |  | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 204 |         (objects, output_dir) = self._fix_object_args (objects, output_dir) | 
 | 205 |         (libraries, library_dirs, runtime_library_dirs) = \ | 
 | 206 |             self._fix_lib_args (libraries, library_dirs, runtime_library_dirs) | 
 | 207 |  | 
 | 208 |         if runtime_library_dirs: | 
| Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 209 |             log.warn("I don't know what to do with 'runtime_library_dirs': %s", | 
 | 210 |                      str(runtime_library_dirs)) | 
| Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 211 |  | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 212 |         if output_dir is not None: | 
 | 213 |             output_filename = os.path.join (output_dir, output_filename) | 
 | 214 |  | 
 | 215 |         if self._need_link (objects, output_filename): | 
 | 216 |  | 
| Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 217 |             # Figure out linker args based on type of target. | 
 | 218 |             if target_desc == CCompiler.EXECUTABLE: | 
 | 219 |                 startup_obj = 'c0w32' | 
 | 220 |                 if debug: | 
 | 221 |                     ld_args = self.ldflags_exe_debug[:] | 
 | 222 |                 else: | 
 | 223 |                     ld_args = self.ldflags_exe[:] | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 224 |             else: | 
| Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 225 |                 startup_obj = 'c0d32' | 
 | 226 |                 if debug: | 
 | 227 |                     ld_args = self.ldflags_shared_debug[:] | 
 | 228 |                 else: | 
 | 229 |                     ld_args = self.ldflags_shared[:] | 
 | 230 |  | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 231 |  | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 232 |             # Create a temporary exports file for use by the linker | 
| Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 233 |             if export_symbols is None: | 
 | 234 |                 def_file = '' | 
 | 235 |             else: | 
 | 236 |                 head, tail = os.path.split (output_filename) | 
 | 237 |                 modname, ext = os.path.splitext (tail) | 
 | 238 |                 temp_dir = os.path.dirname(objects[0]) # preserve tree structure | 
 | 239 |                 def_file = os.path.join (temp_dir, '%s.def' % modname) | 
 | 240 |                 contents = ['EXPORTS'] | 
 | 241 |                 for sym in (export_symbols or []): | 
 | 242 |                     contents.append('  %s=_%s' % (sym, sym)) | 
 | 243 |                 self.execute(write_file, (def_file, contents), | 
 | 244 |                              "writing %s" % def_file) | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 245 |  | 
| Greg Ward | cec1568 | 2000-09-01 01:28:33 +0000 | [diff] [blame] | 246 |             # Borland C++ has problems with '/' in paths | 
| Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 247 |             objects2 = map(os.path.normpath, objects) | 
 | 248 |             # split objects in .obj and .res files | 
 | 249 |             # Borland C++ needs them at different positions in the command line | 
 | 250 |             objects = [startup_obj] | 
 | 251 |             resources = [] | 
 | 252 |             for file in objects2: | 
 | 253 |                 (base, ext) = os.path.splitext(os.path.normcase(file)) | 
 | 254 |                 if ext == '.res': | 
 | 255 |                     resources.append(file) | 
 | 256 |                 else: | 
 | 257 |                     objects.append(file) | 
| Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 258 |  | 
 | 259 |  | 
| Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 260 |             for l in library_dirs: | 
| Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 261 |                 ld_args.append("/L%s" % os.path.normpath(l)) | 
| Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 262 |             ld_args.append("/L.") # we sometimes use relative paths | 
 | 263 |  | 
| Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 264 |             # list of object files | 
 | 265 |             ld_args.extend(objects) | 
| Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 266 |  | 
| Greg Ward | 1398045 | 2000-08-13 00:54:39 +0000 | [diff] [blame] | 267 |             # XXX the command-line syntax for Borland C++ is a bit wonky; | 
 | 268 |             # certain filenames are jammed together in one big string, but | 
 | 269 |             # comma-delimited.  This doesn't mesh too well with the | 
 | 270 |             # Unix-centric attitude (with a DOS/Windows quoting hack) of | 
 | 271 |             # 'spawn()', so constructing the argument list is a bit | 
 | 272 |             # awkward.  Note that doing the obvious thing and jamming all | 
 | 273 |             # the filenames and commas into one argument would be wrong, | 
 | 274 |             # because 'spawn()' would quote any filenames with spaces in | 
 | 275 |             # them.  Arghghh!.  Apparently it works fine as coded... | 
 | 276 |  | 
| Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 277 |             # name of dll/exe file | 
| Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 278 |             ld_args.extend([',',output_filename]) | 
| Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 279 |             # no map file and start libraries | 
| Greg Ward | a4662bc | 2000-08-13 00:43:16 +0000 | [diff] [blame] | 280 |             ld_args.append(',,') | 
| Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 281 |  | 
 | 282 |             for lib in libraries: | 
| Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 283 |                 # see if we find it and if there is a bcpp specific lib | 
| Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 284 |                 # (xxx_bcpp.lib) | 
| Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 285 |                 libfile = self.find_library_file(library_dirs, lib, debug) | 
 | 286 |                 if libfile is None: | 
 | 287 |                     ld_args.append(lib) | 
 | 288 |                     # probably a BCPP internal library -- don't warn | 
| Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 289 |                 else: | 
 | 290 |                     # full name which prefers bcpp_xxx.lib over xxx.lib | 
 | 291 |                     ld_args.append(libfile) | 
| Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 292 |  | 
 | 293 |             # some default libraries | 
 | 294 |             ld_args.append ('import32') | 
 | 295 |             ld_args.append ('cw32mt') | 
 | 296 |  | 
| Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 297 |             # def file for export symbols | 
 | 298 |             ld_args.extend([',',def_file]) | 
| Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 299 |             # add resource files | 
 | 300 |             ld_args.append(',') | 
 | 301 |             ld_args.extend(resources) | 
 | 302 |  | 
| Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 303 |  | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 304 |             if extra_preargs: | 
 | 305 |                 ld_args[:0] = extra_preargs | 
 | 306 |             if extra_postargs: | 
| Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 307 |                 ld_args.extend(extra_postargs) | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 308 |  | 
 | 309 |             self.mkpath (os.path.dirname (output_filename)) | 
 | 310 |             try: | 
| Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 311 |                 self.spawn ([self.linker] + ld_args) | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 312 |             except DistutilsExecError, msg: | 
 | 313 |                 raise LinkError, msg | 
 | 314 |  | 
 | 315 |         else: | 
| Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 316 |             log.debug("skipping %s (up-to-date)", output_filename) | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 317 |  | 
| Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 318 |     # link () | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 319 |  | 
 | 320 |     # -- Miscellaneous methods ----------------------------------------- | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 321 |  | 
 | 322 |  | 
| Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 323 |     def find_library_file (self, dirs, lib, debug=0): | 
| Greg Ward | 5db2c3a | 2000-08-04 01:30:03 +0000 | [diff] [blame] | 324 |         # List of effective library names to try, in order of preference: | 
| Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 325 |         # xxx_bcpp.lib is better than xxx.lib | 
| Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 326 |         # and xxx_d.lib is better than xxx.lib if debug is set | 
| Greg Ward | 5db2c3a | 2000-08-04 01:30:03 +0000 | [diff] [blame] | 327 |         # | 
| Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 328 |         # The "_bcpp" suffix is to handle a Python installation for people | 
| Greg Ward | 5db2c3a | 2000-08-04 01:30:03 +0000 | [diff] [blame] | 329 |         # with multiple compilers (primarily Distutils hackers, I suspect | 
 | 330 |         # ;-).  The idea is they'd have one static library for each | 
 | 331 |         # compiler they care about, since (almost?) every Windows compiler | 
 | 332 |         # seems to have a different format for static libraries. | 
 | 333 |         if debug: | 
 | 334 |             dlib = (lib + "_d") | 
| Greg Ward | cec1568 | 2000-09-01 01:28:33 +0000 | [diff] [blame] | 335 |             try_names = (dlib + "_bcpp", lib + "_bcpp", dlib, lib) | 
| Greg Ward | 5db2c3a | 2000-08-04 01:30:03 +0000 | [diff] [blame] | 336 |         else: | 
| Greg Ward | cec1568 | 2000-09-01 01:28:33 +0000 | [diff] [blame] | 337 |             try_names = (lib + "_bcpp", lib) | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 338 |  | 
| Greg Ward | 5db2c3a | 2000-08-04 01:30:03 +0000 | [diff] [blame] | 339 |         for dir in dirs: | 
 | 340 |             for name in try_names: | 
 | 341 |                 libfile = os.path.join(dir, self.library_filename(name)) | 
 | 342 |                 if os.path.exists(libfile): | 
 | 343 |                     return libfile | 
| Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 344 |         else: | 
 | 345 |             # Oops, didn't find it in *any* of 'dirs' | 
 | 346 |             return None | 
 | 347 |  | 
| Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 348 |     # overwrite the one from CCompiler to support rc and res-files | 
 | 349 |     def object_filenames (self, | 
 | 350 |                           source_filenames, | 
 | 351 |                           strip_dir=0, | 
 | 352 |                           output_dir=''): | 
 | 353 |         if output_dir is None: output_dir = '' | 
 | 354 |         obj_names = [] | 
 | 355 |         for src_name in source_filenames: | 
 | 356 |             # use normcase to make sure '.rc' is really '.rc' and not '.RC' | 
 | 357 |             (base, ext) = os.path.splitext (os.path.normcase(src_name)) | 
 | 358 |             if ext not in (self.src_extensions + ['.rc','.res']): | 
 | 359 |                 raise UnknownFileError, \ | 
 | 360 |                       "unknown file type '%s' (from '%s')" % \ | 
 | 361 |                       (ext, src_name) | 
 | 362 |             if strip_dir: | 
 | 363 |                 base = os.path.basename (base) | 
 | 364 |             if ext == '.res': | 
 | 365 |                 # these can go unchanged | 
 | 366 |                 obj_names.append (os.path.join (output_dir, base + ext)) | 
 | 367 |             elif ext == '.rc': | 
 | 368 |                 # these need to be compiled to .res-files | 
 | 369 |                 obj_names.append (os.path.join (output_dir, base + '.res')) | 
 | 370 |             else: | 
 | 371 |                 obj_names.append (os.path.join (output_dir, | 
 | 372 |                                             base + self.obj_extension)) | 
 | 373 |         return obj_names | 
 | 374 |  | 
 | 375 |     # object_filenames () | 
| Andrew M. Kuchling | db7aed5 | 2001-08-16 20:17:41 +0000 | [diff] [blame] | 376 |  | 
 | 377 |     def preprocess (self, | 
 | 378 |                     source, | 
 | 379 |                     output_file=None, | 
 | 380 |                     macros=None, | 
 | 381 |                     include_dirs=None, | 
 | 382 |                     extra_preargs=None, | 
 | 383 |                     extra_postargs=None): | 
 | 384 |  | 
 | 385 |         (_, macros, include_dirs) = \ | 
 | 386 |             self._fix_compile_args(None, macros, include_dirs) | 
 | 387 |         pp_opts = gen_preprocess_options(macros, include_dirs) | 
 | 388 |         pp_args = ['cpp32.exe'] + pp_opts | 
 | 389 |         if output_file is not None: | 
 | 390 |             pp_args.append('-o' + output_file) | 
 | 391 |         if extra_preargs: | 
 | 392 |             pp_args[:0] = extra_preargs | 
 | 393 |         if extra_postargs: | 
 | 394 |             pp_args.extend(extra_postargs) | 
 | 395 |         pp_args.append(source) | 
 | 396 |  | 
 | 397 |         # We need to preprocess: either we're being forced to, or the | 
 | 398 |         # source file is newer than the target (or the target doesn't | 
 | 399 |         # exist). | 
 | 400 |         if self.force or output_file is None or newer(source, output_file): | 
 | 401 |             if output_file: | 
 | 402 |                 self.mkpath(os.path.dirname(output_file)) | 
 | 403 |             try: | 
 | 404 |                 self.spawn(pp_args) | 
 | 405 |             except DistutilsExecError, msg: | 
 | 406 |                 print msg | 
 | 407 |                 raise CompileError, msg | 
 | 408 |  | 
 | 409 |     # preprocess() |