Path: blob/main/Tools/c-analyzer/distutils/bcppcompiler.py
12 views
"""distutils.bcppcompiler12Contains BorlandCCompiler, an implementation of the abstract CCompiler class3for the Borland C++ compiler.4"""56# This implementation by Lyle Johnson, based on the original msvccompiler.py7# module and using the directions originally published by Gordon Williams.89# XXX looks like there's a LOT of overlap between these two classes:10# someone should sit down and factor out the common code as11# WindowsCCompiler! --GPW121314import os15from distutils.errors import DistutilsExecError, CompileError16from distutils.ccompiler import \17CCompiler, gen_preprocess_options18from distutils.dep_util import newer1920class BCPPCompiler(CCompiler) :21"""Concrete class that implements an interface to the Borland C/C++22compiler, as defined by the CCompiler abstract class.23"""2425compiler_type = 'bcpp'2627# Just set this so CCompiler's constructor doesn't barf. We currently28# don't use the 'set_executables()' bureaucracy provided by CCompiler,29# as it really isn't necessary for this sort of single-compiler class.30# Would be nice to have a consistent interface with UnixCCompiler,31# though, so it's worth thinking about.32executables = {}3334# Private class data (need to distinguish C from C++ source for compiler)35_c_extensions = ['.c']36_cpp_extensions = ['.cc', '.cpp', '.cxx']3738# Needed for the filename generation methods provided by the39# base class, CCompiler.40src_extensions = _c_extensions + _cpp_extensions41obj_extension = '.obj'42static_lib_extension = '.lib'43shared_lib_extension = '.dll'44static_lib_format = shared_lib_format = '%s%s'45exe_extension = '.exe'464748def __init__ (self,49verbose=0,50dry_run=0,51force=0):5253CCompiler.__init__ (self, verbose, dry_run, force)5455# These executables are assumed to all be in the path.56# Borland doesn't seem to use any special registry settings to57# indicate their installation locations.5859self.cc = "bcc32.exe"60self.linker = "ilink32.exe"61self.lib = "tlib.exe"6263self.preprocess_options = None64self.compile_options = ['/tWM', '/O2', '/q', '/g0']65self.compile_options_debug = ['/tWM', '/Od', '/q', '/g0']6667self.ldflags_shared = ['/Tpd', '/Gn', '/q', '/x']68self.ldflags_shared_debug = ['/Tpd', '/Gn', '/q', '/x']69self.ldflags_static = []70self.ldflags_exe = ['/Gn', '/q', '/x']71self.ldflags_exe_debug = ['/Gn', '/q', '/x','/r']727374# -- Worker methods ------------------------------------------------7576def preprocess (self,77source,78output_file=None,79macros=None,80include_dirs=None,81extra_preargs=None,82extra_postargs=None):8384(_, macros, include_dirs) = \85self._fix_compile_args(None, macros, include_dirs)86pp_opts = gen_preprocess_options(macros, include_dirs)87pp_args = ['cpp32.exe'] + pp_opts88if output_file is not None:89pp_args.append('-o' + output_file)90if extra_preargs:91pp_args[:0] = extra_preargs92if extra_postargs:93pp_args.extend(extra_postargs)94pp_args.append(source)9596# We need to preprocess: either we're being forced to, or the97# source file is newer than the target (or the target doesn't98# exist).99if self.force or output_file is None or newer(source, output_file):100if output_file:101self.mkpath(os.path.dirname(output_file))102try:103self.spawn(pp_args)104except DistutilsExecError as msg:105print(msg)106raise CompileError(msg)107108# preprocess()109110111