Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Static Private Attributes
distutils.bcppcompiler.BCPPCompiler Class Reference
Collaboration diagram for distutils.bcppcompiler.BCPPCompiler:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def compile
def create_static_lib
def link
def find_library_file
def object_filenames
def preprocess

Public Attributes

 cc
 linker
 lib
 preprocess_options
 compile_options
 compile_options_debug
 ldflags_shared
 ldflags_shared_debug
 ldflags_static
 ldflags_exe
 ldflags_exe_debug

Static Public Attributes

string compiler_type = 'bcpp'
dictionary executables = {}
 src_extensions = _c_extensions+_cpp_extensions
string obj_extension = '.obj'
string static_lib_extension = '.lib'
string shared_lib_extension = '.dll'
string static_lib_format = '%s%s'
string exe_extension = '.exe'

Static Private Attributes

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

Detailed Description

Concrete class that implements an interface to the Borland C/C++
compiler, as defined by the CCompiler abstract class.

Definition at line 25 of file bcppcompiler.py.


Constructor & Destructor Documentation

def distutils.bcppcompiler.BCPPCompiler.__init__ (   self,
  verbose = 0,
  dry_run = 0,
  force = 0 
)

Definition at line 56 of file bcppcompiler.py.

00056 
00057                   force=0):
00058 
00059         CCompiler.__init__ (self, verbose, dry_run, force)
00060 
00061         # These executables are assumed to all be in the path.
00062         # Borland doesn't seem to use any special registry settings to
00063         # indicate their installation locations.
00064 
00065         self.cc = "bcc32.exe"
00066         self.linker = "ilink32.exe"
00067         self.lib = "tlib.exe"
00068 
00069         self.preprocess_options = None
00070         self.compile_options = ['/tWM', '/O2', '/q', '/g0']
00071         self.compile_options_debug = ['/tWM', '/Od', '/q', '/g0']
00072 
00073         self.ldflags_shared = ['/Tpd', '/Gn', '/q', '/x']
00074         self.ldflags_shared_debug = ['/Tpd', '/Gn', '/q', '/x']
00075         self.ldflags_static = []
00076         self.ldflags_exe = ['/Gn', '/q', '/x']
00077         self.ldflags_exe_debug = ['/Gn', '/q', '/x','/r']
00078 

Here is the caller graph for this function:


Member Function Documentation

def distutils.bcppcompiler.BCPPCompiler.compile (   self,
  sources,
  output_dir = None,
  macros = None,
  include_dirs = None,
  debug = 0,
  extra_preargs = None,
  extra_postargs = None,
  depends = None 
)

Definition at line 83 of file bcppcompiler.py.

00083 
00084                 extra_preargs=None, extra_postargs=None, depends=None):
00085 
00086         macros, objects, extra_postargs, pp_opts, build = \
00087                 self._setup_compile(output_dir, macros, include_dirs, sources,
00088                                     depends, extra_postargs)
00089         compile_opts = extra_preargs or []
00090         compile_opts.append ('-c')
00091         if debug:
00092             compile_opts.extend (self.compile_options_debug)
00093         else:
00094             compile_opts.extend (self.compile_options)
00095 
00096         for obj in objects:
00097             try:
00098                 src, ext = build[obj]
00099             except KeyError:
00100                 continue
00101             # XXX why do the normpath here?
00102             src = os.path.normpath(src)
00103             obj = os.path.normpath(obj)
00104             # XXX _setup_compile() did a mkpath() too but before the normpath.
00105             # Is it possible to skip the normpath?
00106             self.mkpath(os.path.dirname(obj))
00107 
00108             if ext == '.res':
00109                 # This is already a binary file -- skip it.
00110                 continue # the 'for' loop
00111             if ext == '.rc':
00112                 # This needs to be compiled to a .res file -- do it now.
00113                 try:
00114                     self.spawn (["brcc32", "-fo", obj, src])
00115                 except DistutilsExecError as msg:
00116                     raise CompileError(msg)
00117                 continue # the 'for' loop
00118 
00119             # The next two are both for the real compiler.
00120             if ext in self._c_extensions:
00121                 input_opt = ""
00122             elif ext in self._cpp_extensions:
00123                 input_opt = "-P"
00124             else:
00125                 # Unknown file type -- no extra options.  The compiler
00126                 # will probably fail, but let it just in case this is a
00127                 # file the compiler recognizes even if we don't.
00128                 input_opt = ""
00129 
00130             output_opt = "-o" + obj
00131 
00132             # Compiler command line syntax is: "bcc32 [options] file(s)".
00133             # Note that the source file names must appear at the end of
00134             # the command line.
00135             try:
00136                 self.spawn ([self.cc] + compile_opts + pp_opts +
00137                             [input_opt, output_opt] +
00138                             extra_postargs + [src])
00139             except DistutilsExecError as msg:
00140                 raise CompileError(msg)
00141 
00142         return objects

Here is the call graph for this function:

Here is the caller graph for this function:

def distutils.bcppcompiler.BCPPCompiler.create_static_lib (   self,
  objects,
  output_libname,
  output_dir = None,
  debug = 0,
  target_lang = None 
)

Definition at line 151 of file bcppcompiler.py.

00151 
00152                            target_lang=None):
00153 
00154         (objects, output_dir) = self._fix_object_args (objects, output_dir)
00155         output_filename = \
00156             self.library_filename (output_libname, output_dir=output_dir)
00157 
00158         if self._need_link (objects, output_filename):
00159             lib_args = [output_filename, '/u'] + objects
00160             if debug:
00161                 pass                    # XXX what goes here?
00162             try:
00163                 self.spawn ([self.lib] + lib_args)
00164             except DistutilsExecError as msg:
00165                 raise LibError(msg)
00166         else:
00167             log.debug("skipping %s (up-to-date)", output_filename)

Here is the call graph for this function:

Here is the caller graph for this function:

def distutils.bcppcompiler.BCPPCompiler.find_library_file (   self,
  dirs,
  lib,
  debug = 0 
)

Definition at line 308 of file bcppcompiler.py.

00308 
00309     def find_library_file (self, dirs, lib, debug=0):
00310         # List of effective library names to try, in order of preference:
00311         # xxx_bcpp.lib is better than xxx.lib
00312         # and xxx_d.lib is better than xxx.lib if debug is set
00313         #
00314         # The "_bcpp" suffix is to handle a Python installation for people
00315         # with multiple compilers (primarily Distutils hackers, I suspect
00316         # ;-).  The idea is they'd have one static library for each
00317         # compiler they care about, since (almost?) every Windows compiler
00318         # seems to have a different format for static libraries.
00319         if debug:
00320             dlib = (lib + "_d")
00321             try_names = (dlib + "_bcpp", lib + "_bcpp", dlib, lib)
00322         else:
00323             try_names = (lib + "_bcpp", lib)
00324 
00325         for dir in dirs:
00326             for name in try_names:
00327                 libfile = os.path.join(dir, self.library_filename(name))
00328                 if os.path.exists(libfile):
00329                     return libfile
00330         else:
00331             # Oops, didn't find it in *any* of 'dirs'
00332             return None

Here is the call graph for this function:

Here is the caller graph for this function:

def distutils.bcppcompiler.BCPPCompiler.link (   self,
  target_desc,
  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,
  build_temp = None,
  target_lang = None 
)

Definition at line 184 of file bcppcompiler.py.

00184 
00185               target_lang=None):
00186 
00187         # XXX this ignores 'build_temp'!  should follow the lead of
00188         # msvccompiler.py
00189 
00190         (objects, output_dir) = self._fix_object_args (objects, output_dir)
00191         (libraries, library_dirs, runtime_library_dirs) = \
00192             self._fix_lib_args (libraries, library_dirs, runtime_library_dirs)
00193 
00194         if runtime_library_dirs:
00195             log.warn("I don't know what to do with 'runtime_library_dirs': %s",
00196                      str(runtime_library_dirs))
00197 
00198         if output_dir is not None:
00199             output_filename = os.path.join (output_dir, output_filename)
00200 
00201         if self._need_link (objects, output_filename):
00202 
00203             # Figure out linker args based on type of target.
00204             if target_desc == CCompiler.EXECUTABLE:
00205                 startup_obj = 'c0w32'
00206                 if debug:
00207                     ld_args = self.ldflags_exe_debug[:]
00208                 else:
00209                     ld_args = self.ldflags_exe[:]
00210             else:
00211                 startup_obj = 'c0d32'
00212                 if debug:
00213                     ld_args = self.ldflags_shared_debug[:]
00214                 else:
00215                     ld_args = self.ldflags_shared[:]
00216 
00217 
00218             # Create a temporary exports file for use by the linker
00219             if export_symbols is None:
00220                 def_file = ''
00221             else:
00222                 head, tail = os.path.split (output_filename)
00223                 modname, ext = os.path.splitext (tail)
00224                 temp_dir = os.path.dirname(objects[0]) # preserve tree structure
00225                 def_file = os.path.join (temp_dir, '%s.def' % modname)
00226                 contents = ['EXPORTS']
00227                 for sym in (export_symbols or []):
00228                     contents.append('  %s=_%s' % (sym, sym))
00229                 self.execute(write_file, (def_file, contents),
00230                              "writing %s" % def_file)
00231 
00232             # Borland C++ has problems with '/' in paths
00233             objects2 = map(os.path.normpath, objects)
00234             # split objects in .obj and .res files
00235             # Borland C++ needs them at different positions in the command line
00236             objects = [startup_obj]
00237             resources = []
00238             for file in objects2:
00239                 (base, ext) = os.path.splitext(os.path.normcase(file))
00240                 if ext == '.res':
00241                     resources.append(file)
00242                 else:
00243                     objects.append(file)
00244 
00245 
00246             for l in library_dirs:
00247                 ld_args.append("/L%s" % os.path.normpath(l))
00248             ld_args.append("/L.") # we sometimes use relative paths
00249 
00250             # list of object files
00251             ld_args.extend(objects)
00252 
00253             # XXX the command-line syntax for Borland C++ is a bit wonky;
00254             # certain filenames are jammed together in one big string, but
00255             # comma-delimited.  This doesn't mesh too well with the
00256             # Unix-centric attitude (with a DOS/Windows quoting hack) of
00257             # 'spawn()', so constructing the argument list is a bit
00258             # awkward.  Note that doing the obvious thing and jamming all
00259             # the filenames and commas into one argument would be wrong,
00260             # because 'spawn()' would quote any filenames with spaces in
00261             # them.  Arghghh!.  Apparently it works fine as coded...
00262 
00263             # name of dll/exe file
00264             ld_args.extend([',',output_filename])
00265             # no map file and start libraries
00266             ld_args.append(',,')
00267 
00268             for lib in libraries:
00269                 # see if we find it and if there is a bcpp specific lib
00270                 # (xxx_bcpp.lib)
00271                 libfile = self.find_library_file(library_dirs, lib, debug)
00272                 if libfile is None:
00273                     ld_args.append(lib)
00274                     # probably a BCPP internal library -- don't warn
00275                 else:
00276                     # full name which prefers bcpp_xxx.lib over xxx.lib
00277                     ld_args.append(libfile)
00278 
00279             # some default libraries
00280             ld_args.append ('import32')
00281             ld_args.append ('cw32mt')
00282 
00283             # def file for export symbols
00284             ld_args.extend([',',def_file])
00285             # add resource files
00286             ld_args.append(',')
00287             ld_args.extend(resources)
00288 
00289 
00290             if extra_preargs:
00291                 ld_args[:0] = extra_preargs
00292             if extra_postargs:
00293                 ld_args.extend(extra_postargs)
00294 
00295             self.mkpath (os.path.dirname (output_filename))
00296             try:
00297                 self.spawn ([self.linker] + ld_args)
00298             except DistutilsExecError as msg:
00299                 raise LinkError(msg)
00300 
00301         else:
00302             log.debug("skipping %s (up-to-date)", output_filename)

Here is the call graph for this function:

Here is the caller graph for this function:

def distutils.bcppcompiler.BCPPCompiler.object_filenames (   self,
  source_filenames,
  strip_dir = 0,
  output_dir = '' 
)

Definition at line 337 of file bcppcompiler.py.

00337 
00338                           output_dir=''):
00339         if output_dir is None: output_dir = ''
00340         obj_names = []
00341         for src_name in source_filenames:
00342             # use normcase to make sure '.rc' is really '.rc' and not '.RC'
00343             (base, ext) = os.path.splitext (os.path.normcase(src_name))
00344             if ext not in (self.src_extensions + ['.rc','.res']):
00345                 raise UnknownFileError("unknown file type '%s' (from '%s')" % \
00346                       (ext, src_name))
00347             if strip_dir:
00348                 base = os.path.basename (base)
00349             if ext == '.res':
00350                 # these can go unchanged
00351                 obj_names.append (os.path.join (output_dir, base + ext))
00352             elif ext == '.rc':
00353                 # these need to be compiled to .res-files
00354                 obj_names.append (os.path.join (output_dir, base + '.res'))
00355             else:
00356                 obj_names.append (os.path.join (output_dir,
00357                                             base + self.obj_extension))
00358         return obj_names

Here is the call graph for this function:

Here is the caller graph for this function:

def distutils.bcppcompiler.BCPPCompiler.preprocess (   self,
  source,
  output_file = None,
  macros = None,
  include_dirs = None,
  extra_preargs = None,
  extra_postargs = None 
)

Definition at line 367 of file bcppcompiler.py.

00367 
00368                     extra_postargs=None):
00369 
00370         (_, macros, include_dirs) = \
00371             self._fix_compile_args(None, macros, include_dirs)
00372         pp_opts = gen_preprocess_options(macros, include_dirs)
00373         pp_args = ['cpp32.exe'] + pp_opts
00374         if output_file is not None:
00375             pp_args.append('-o' + output_file)
00376         if extra_preargs:
00377             pp_args[:0] = extra_preargs
00378         if extra_postargs:
00379             pp_args.extend(extra_postargs)
00380         pp_args.append(source)
00381 
00382         # We need to preprocess: either we're being forced to, or the
00383         # source file is newer than the target (or the target doesn't
00384         # exist).
00385         if self.force or output_file is None or newer(source, output_file):
00386             if output_file:
00387                 self.mkpath(os.path.dirname(output_file))
00388             try:
00389                 self.spawn(pp_args)
00390             except DistutilsExecError as msg:
00391                 print(msg)
00392                 raise CompileError(msg)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 40 of file bcppcompiler.py.

list distutils.bcppcompiler.BCPPCompiler._cpp_extensions = ['.cc', '.cpp', '.cxx'] [static, private]

Definition at line 41 of file bcppcompiler.py.

Definition at line 64 of file bcppcompiler.py.

Definition at line 69 of file bcppcompiler.py.

Definition at line 70 of file bcppcompiler.py.

Definition at line 30 of file bcppcompiler.py.

Definition at line 50 of file bcppcompiler.py.

Definition at line 37 of file bcppcompiler.py.

Definition at line 75 of file bcppcompiler.py.

Definition at line 76 of file bcppcompiler.py.

Definition at line 72 of file bcppcompiler.py.

Definition at line 73 of file bcppcompiler.py.

Definition at line 74 of file bcppcompiler.py.

Definition at line 66 of file bcppcompiler.py.

Definition at line 65 of file bcppcompiler.py.

Definition at line 46 of file bcppcompiler.py.

Definition at line 68 of file bcppcompiler.py.

Definition at line 48 of file bcppcompiler.py.

Definition at line 45 of file bcppcompiler.py.

Definition at line 47 of file bcppcompiler.py.

Definition at line 49 of file bcppcompiler.py.


The documentation for this class was generated from the following file: