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 concrete class that implements an interface to the borland cc compiler as defined by the ccompiler abstract class just set this so ccompiler s constructor doesn t barf we currently don t use the setexecutables bureaucracy provided by ccompiler as it really isn t necessary for this sort of singlecompiler class would be nice to have a consistent interface with unixccompiler though so it s worth thinking about private class data need to distinguish c from c source for compiler needed for the filename generation methods provided by the base class ccompiler 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 worker methods 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 preprocess 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 concrete class that implements an interface to the borland c c compiler as defined by the ccompiler abstract class 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 private class data need to distinguish c from c source for compiler needed for the filename generation methods provided by the base class ccompiler 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 worker methods 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 preprocess
import os
from distutils.errors import DistutilsExecError, CompileError
from distutils.ccompiler import \
     CCompiler, gen_preprocess_options
from distutils.dep_util import newer

class BCPPCompiler(CCompiler) :
    

    compiler_type = 'bcpp'

    
    
    
    
    
    executables = {}

    
    _c_extensions = ['.c']
    _cpp_extensions = ['.cc', '.cpp', '.cxx']

    
    
    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)

        
        
        

        self.cc = "bcc32.exe"
        self.linker = "ilink32.exe"
        self.lib = "tlib.exe"

        self.preprocess_options = None
        self.compile_options = ['/tWM', '/O2', '/q', '/g0']
        self.compile_options_debug = ['/tWM', '/Od', '/q', '/g0']

        self.ldflags_shared = ['/Tpd', '/Gn', '/q', '/x']
        self.ldflags_shared_debug = ['/Tpd', '/Gn', '/q', '/x']
        self.ldflags_static = []
        self.ldflags_exe = ['/Gn', '/q', '/x']
        self.ldflags_exe_debug = ['/Gn', '/q', '/x','/r']


    

    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)

        
        
        
        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 as msg:
                print(msg)
                raise CompileError(msg)