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 | |
Jeremy Hylton | 1bba31d | 2002-06-13 17:28:18 +0000 | [diff] [blame] | 83 | def compile(self, sources, |
| 84 | output_dir=None, macros=None, include_dirs=None, debug=0, |
| 85 | extra_preargs=None, extra_postargs=None, depends=None): |
| 86 | |
| 87 | macros, objects, extra_postargs, pp_opts, build = \ |
| 88 | self._setup_compile(output_dir, macros, include_dirs, sources, |
| 89 | depends, extra_postargs) |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 90 | compile_opts = extra_preargs or [] |
| 91 | compile_opts.append ('-c') |
| 92 | if debug: |
| 93 | compile_opts.extend (self.compile_options_debug) |
| 94 | else: |
| 95 | compile_opts.extend (self.compile_options) |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 96 | |
Jeremy Hylton | 1bba31d | 2002-06-13 17:28:18 +0000 | [diff] [blame] | 97 | for obj, (src, ext) in build.items(): |
| 98 | # XXX why do the normpath here? |
| 99 | src = os.path.normpath(src) |
| 100 | obj = os.path.normpath(obj) |
| 101 | # XXX _setup_compile() did a mkpath() too but before the normpath. |
| 102 | # Is it possible to skip the normpath? |
| 103 | self.mkpath(os.path.dirname(obj)) |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 104 | |
Jeremy Hylton | 1bba31d | 2002-06-13 17:28:18 +0000 | [diff] [blame] | 105 | if ext == '.res': |
| 106 | # This is already a binary file -- skip it. |
| 107 | continue # the 'for' loop |
| 108 | if ext == '.rc': |
| 109 | # This needs to be compiled to a .res file -- do it now. |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 110 | try: |
Jeremy Hylton | 1bba31d | 2002-06-13 17:28:18 +0000 | [diff] [blame] | 111 | self.spawn (["brcc32", "-fo", obj, src]) |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 112 | except DistutilsExecError, msg: |
| 113 | raise CompileError, msg |
Jeremy Hylton | 1bba31d | 2002-06-13 17:28:18 +0000 | [diff] [blame] | 114 | continue # the 'for' loop |
| 115 | |
| 116 | # The next two are both for the real compiler. |
| 117 | if ext in self._c_extensions: |
| 118 | input_opt = "" |
| 119 | elif ext in self._cpp_extensions: |
| 120 | input_opt = "-P" |
| 121 | else: |
| 122 | # Unknown file type -- no extra options. The compiler |
| 123 | # will probably fail, but let it just in case this is a |
| 124 | # file the compiler recognizes even if we don't. |
| 125 | input_opt = "" |
| 126 | |
| 127 | output_opt = "-o" + obj |
| 128 | |
| 129 | # Compiler command line syntax is: "bcc32 [options] file(s)". |
| 130 | # Note that the source file names must appear at the end of |
| 131 | # the command line. |
| 132 | try: |
| 133 | self.spawn ([self.cc] + compile_opts + pp_opts + |
| 134 | [input_opt, output_opt] + |
| 135 | extra_postargs + [src]) |
| 136 | except DistutilsExecError, msg: |
| 137 | raise CompileError, msg |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 138 | |
| 139 | return objects |
| 140 | |
| 141 | # compile () |
| 142 | |
| 143 | |
| 144 | def create_static_lib (self, |
| 145 | objects, |
| 146 | output_libname, |
| 147 | output_dir=None, |
| 148 | debug=0, |
| 149 | extra_preargs=None, |
| 150 | extra_postargs=None): |
| 151 | |
| 152 | (objects, output_dir) = self._fix_object_args (objects, output_dir) |
| 153 | output_filename = \ |
| 154 | self.library_filename (output_libname, output_dir=output_dir) |
| 155 | |
| 156 | if self._need_link (objects, output_filename): |
| 157 | lib_args = [output_filename, '/u'] + objects |
| 158 | if debug: |
| 159 | pass # XXX what goes here? |
| 160 | if extra_preargs: |
| 161 | lib_args[:0] = extra_preargs |
| 162 | if extra_postargs: |
| 163 | lib_args.extend (extra_postargs) |
| 164 | try: |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 165 | self.spawn ([self.lib] + lib_args) |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 166 | except DistutilsExecError, msg: |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 167 | raise LibError, msg |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 168 | else: |
Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 169 | log.debug("skipping %s (up-to-date)", output_filename) |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 170 | |
| 171 | # create_static_lib () |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 172 | |
| 173 | |
Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 174 | def link (self, |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 175 | target_desc, |
Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 176 | objects, |
| 177 | output_filename, |
| 178 | output_dir=None, |
| 179 | libraries=None, |
| 180 | library_dirs=None, |
| 181 | runtime_library_dirs=None, |
| 182 | export_symbols=None, |
| 183 | debug=0, |
| 184 | extra_preargs=None, |
| 185 | extra_postargs=None, |
| 186 | build_temp=None): |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 187 | |
Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 188 | # XXX this ignores 'build_temp'! should follow the lead of |
| 189 | # msvccompiler.py |
| 190 | |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 191 | (objects, output_dir) = self._fix_object_args (objects, output_dir) |
| 192 | (libraries, library_dirs, runtime_library_dirs) = \ |
| 193 | self._fix_lib_args (libraries, library_dirs, runtime_library_dirs) |
| 194 | |
| 195 | if runtime_library_dirs: |
Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 196 | log.warn("I don't know what to do with 'runtime_library_dirs': %s", |
| 197 | str(runtime_library_dirs)) |
Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 198 | |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 199 | if output_dir is not None: |
| 200 | output_filename = os.path.join (output_dir, output_filename) |
| 201 | |
| 202 | if self._need_link (objects, output_filename): |
| 203 | |
Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 204 | # Figure out linker args based on type of target. |
| 205 | if target_desc == CCompiler.EXECUTABLE: |
| 206 | startup_obj = 'c0w32' |
| 207 | if debug: |
| 208 | ld_args = self.ldflags_exe_debug[:] |
| 209 | else: |
| 210 | ld_args = self.ldflags_exe[:] |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 211 | else: |
Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 212 | startup_obj = 'c0d32' |
| 213 | if debug: |
| 214 | ld_args = self.ldflags_shared_debug[:] |
| 215 | else: |
| 216 | ld_args = self.ldflags_shared[:] |
| 217 | |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 218 | |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 219 | # Create a temporary exports file for use by the linker |
Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 220 | if export_symbols is None: |
| 221 | def_file = '' |
| 222 | else: |
| 223 | head, tail = os.path.split (output_filename) |
| 224 | modname, ext = os.path.splitext (tail) |
| 225 | temp_dir = os.path.dirname(objects[0]) # preserve tree structure |
| 226 | def_file = os.path.join (temp_dir, '%s.def' % modname) |
| 227 | contents = ['EXPORTS'] |
| 228 | for sym in (export_symbols or []): |
| 229 | contents.append(' %s=_%s' % (sym, sym)) |
| 230 | self.execute(write_file, (def_file, contents), |
| 231 | "writing %s" % def_file) |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 232 | |
Greg Ward | cec1568 | 2000-09-01 01:28:33 +0000 | [diff] [blame] | 233 | # Borland C++ has problems with '/' in paths |
Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 234 | objects2 = map(os.path.normpath, objects) |
| 235 | # split objects in .obj and .res files |
| 236 | # Borland C++ needs them at different positions in the command line |
| 237 | objects = [startup_obj] |
| 238 | resources = [] |
| 239 | for file in objects2: |
| 240 | (base, ext) = os.path.splitext(os.path.normcase(file)) |
| 241 | if ext == '.res': |
| 242 | resources.append(file) |
| 243 | else: |
| 244 | objects.append(file) |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 245 | |
| 246 | |
Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 247 | for l in library_dirs: |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 248 | ld_args.append("/L%s" % os.path.normpath(l)) |
Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 249 | ld_args.append("/L.") # we sometimes use relative paths |
| 250 | |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 251 | # list of object files |
| 252 | ld_args.extend(objects) |
Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 253 | |
Greg Ward | 1398045 | 2000-08-13 00:54:39 +0000 | [diff] [blame] | 254 | # XXX the command-line syntax for Borland C++ is a bit wonky; |
| 255 | # certain filenames are jammed together in one big string, but |
| 256 | # comma-delimited. This doesn't mesh too well with the |
| 257 | # Unix-centric attitude (with a DOS/Windows quoting hack) of |
| 258 | # 'spawn()', so constructing the argument list is a bit |
| 259 | # awkward. Note that doing the obvious thing and jamming all |
| 260 | # the filenames and commas into one argument would be wrong, |
| 261 | # because 'spawn()' would quote any filenames with spaces in |
| 262 | # them. Arghghh!. Apparently it works fine as coded... |
| 263 | |
Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 264 | # name of dll/exe file |
Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 265 | ld_args.extend([',',output_filename]) |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 266 | # no map file and start libraries |
Greg Ward | a4662bc | 2000-08-13 00:43:16 +0000 | [diff] [blame] | 267 | ld_args.append(',,') |
Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 268 | |
| 269 | for lib in libraries: |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 270 | # 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] | 271 | # (xxx_bcpp.lib) |
Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 272 | libfile = self.find_library_file(library_dirs, lib, debug) |
| 273 | if libfile is None: |
| 274 | ld_args.append(lib) |
| 275 | # probably a BCPP internal library -- don't warn |
Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 276 | else: |
| 277 | # full name which prefers bcpp_xxx.lib over xxx.lib |
| 278 | ld_args.append(libfile) |
Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 279 | |
| 280 | # some default libraries |
| 281 | ld_args.append ('import32') |
| 282 | ld_args.append ('cw32mt') |
| 283 | |
Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 284 | # def file for export symbols |
| 285 | ld_args.extend([',',def_file]) |
Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 286 | # add resource files |
| 287 | ld_args.append(',') |
| 288 | ld_args.extend(resources) |
| 289 | |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 290 | |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 291 | if extra_preargs: |
| 292 | ld_args[:0] = extra_preargs |
| 293 | if extra_postargs: |
Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 294 | ld_args.extend(extra_postargs) |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 295 | |
| 296 | self.mkpath (os.path.dirname (output_filename)) |
| 297 | try: |
Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 298 | self.spawn ([self.linker] + ld_args) |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 299 | except DistutilsExecError, msg: |
| 300 | raise LinkError, msg |
| 301 | |
| 302 | else: |
Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 303 | log.debug("skipping %s (up-to-date)", output_filename) |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 304 | |
Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 305 | # link () |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 306 | |
| 307 | # -- Miscellaneous methods ----------------------------------------- |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 308 | |
| 309 | |
Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 310 | def find_library_file (self, dirs, lib, debug=0): |
Greg Ward | 5db2c3a | 2000-08-04 01:30:03 +0000 | [diff] [blame] | 311 | # List of effective library names to try, in order of preference: |
Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 312 | # xxx_bcpp.lib is better than xxx.lib |
Greg Ward | c58c517 | 2000-08-02 01:03:23 +0000 | [diff] [blame] | 313 | # 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] | 314 | # |
Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 315 | # The "_bcpp" suffix is to handle a Python installation for people |
Greg Ward | 5db2c3a | 2000-08-04 01:30:03 +0000 | [diff] [blame] | 316 | # with multiple compilers (primarily Distutils hackers, I suspect |
| 317 | # ;-). The idea is they'd have one static library for each |
| 318 | # compiler they care about, since (almost?) every Windows compiler |
| 319 | # seems to have a different format for static libraries. |
| 320 | if debug: |
| 321 | dlib = (lib + "_d") |
Greg Ward | cec1568 | 2000-09-01 01:28:33 +0000 | [diff] [blame] | 322 | try_names = (dlib + "_bcpp", lib + "_bcpp", dlib, lib) |
Greg Ward | 5db2c3a | 2000-08-04 01:30:03 +0000 | [diff] [blame] | 323 | else: |
Greg Ward | cec1568 | 2000-09-01 01:28:33 +0000 | [diff] [blame] | 324 | try_names = (lib + "_bcpp", lib) |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 325 | |
Greg Ward | 5db2c3a | 2000-08-04 01:30:03 +0000 | [diff] [blame] | 326 | for dir in dirs: |
| 327 | for name in try_names: |
| 328 | libfile = os.path.join(dir, self.library_filename(name)) |
| 329 | if os.path.exists(libfile): |
| 330 | return libfile |
Greg Ward | fe9b818 | 2000-06-28 01:20:35 +0000 | [diff] [blame] | 331 | else: |
| 332 | # Oops, didn't find it in *any* of 'dirs' |
| 333 | return None |
| 334 | |
Greg Ward | 4240648 | 2000-09-27 02:08:14 +0000 | [diff] [blame] | 335 | # overwrite the one from CCompiler to support rc and res-files |
| 336 | def object_filenames (self, |
| 337 | source_filenames, |
| 338 | strip_dir=0, |
| 339 | output_dir=''): |
| 340 | if output_dir is None: output_dir = '' |
| 341 | obj_names = [] |
| 342 | for src_name in source_filenames: |
| 343 | # use normcase to make sure '.rc' is really '.rc' and not '.RC' |
| 344 | (base, ext) = os.path.splitext (os.path.normcase(src_name)) |
| 345 | if ext not in (self.src_extensions + ['.rc','.res']): |
| 346 | raise UnknownFileError, \ |
| 347 | "unknown file type '%s' (from '%s')" % \ |
| 348 | (ext, src_name) |
| 349 | if strip_dir: |
| 350 | base = os.path.basename (base) |
| 351 | if ext == '.res': |
| 352 | # these can go unchanged |
| 353 | obj_names.append (os.path.join (output_dir, base + ext)) |
| 354 | elif ext == '.rc': |
| 355 | # these need to be compiled to .res-files |
| 356 | obj_names.append (os.path.join (output_dir, base + '.res')) |
| 357 | else: |
| 358 | obj_names.append (os.path.join (output_dir, |
| 359 | base + self.obj_extension)) |
| 360 | return obj_names |
| 361 | |
| 362 | # object_filenames () |
Andrew M. Kuchling | db7aed5 | 2001-08-16 20:17:41 +0000 | [diff] [blame] | 363 | |
| 364 | def preprocess (self, |
| 365 | source, |
| 366 | output_file=None, |
| 367 | macros=None, |
| 368 | include_dirs=None, |
| 369 | extra_preargs=None, |
| 370 | extra_postargs=None): |
| 371 | |
| 372 | (_, macros, include_dirs) = \ |
| 373 | self._fix_compile_args(None, macros, include_dirs) |
| 374 | pp_opts = gen_preprocess_options(macros, include_dirs) |
| 375 | pp_args = ['cpp32.exe'] + pp_opts |
| 376 | if output_file is not None: |
| 377 | pp_args.append('-o' + output_file) |
| 378 | if extra_preargs: |
| 379 | pp_args[:0] = extra_preargs |
| 380 | if extra_postargs: |
| 381 | pp_args.extend(extra_postargs) |
| 382 | pp_args.append(source) |
| 383 | |
| 384 | # We need to preprocess: either we're being forced to, or the |
| 385 | # source file is newer than the target (or the target doesn't |
| 386 | # exist). |
| 387 | if self.force or output_file is None or newer(source, output_file): |
| 388 | if output_file: |
| 389 | self.mkpath(os.path.dirname(output_file)) |
| 390 | try: |
| 391 | self.spawn(pp_args) |
| 392 | except DistutilsExecError, msg: |
| 393 | print msg |
| 394 | raise CompileError, msg |
| 395 | |
| 396 | # preprocess() |