Commit 5cf06667 authored by Greg Ward's avatar Greg Ward

Added 'verbose' and 'dry_run' flags to CCompiler constructor and

  'new_compiler()' factory function.
Added 'runtime_library_dirs' list (for -R linker option) and methods
  to manipulate it.
Deleted some obsolete comments.
Added all the filename manglign methods: 'object_filenames()',
  'shared_object_filename()', 'library_filename()',
  'shared_library_filename()'.
Added 'spawn()' method (front end to the "real" spawn).
parent d1423866
...@@ -11,6 +11,7 @@ import os ...@@ -11,6 +11,7 @@ import os
from types import * from types import *
from copy import copy from copy import copy
from distutils.errors import * from distutils.errors import *
from distutils.spawn import spawn
class CCompiler: class CCompiler:
...@@ -41,23 +42,25 @@ class CCompiler: ...@@ -41,23 +42,25 @@ class CCompiler:
# parameter to the compile/link_* methods, or both? # parameter to the compile/link_* methods, or both?
# * can't completely override the include or library searchg # * can't completely override the include or library searchg
# path, ie. no "cc -I -Idir1 -Idir2" or "cc -L -Ldir1 -Ldir2". # path, ie. no "cc -I -Idir1 -Idir2" or "cc -L -Ldir1 -Ldir2".
# I'm not sure how widely supported this is even by POSIX # I'm not sure how widely supported this is even by Unix
# compilers, much less on other platforms. And I'm even less # compilers, much less on other platforms. And I'm even less
# sure how useful it is; probably for cross-compiling, but I # sure how useful it is; maybe for cross-compiling, but
# have no intention of supporting that. # support for that is a ways off. (And anyways, cross
# compilers probably have a dedicated binary with the
# right paths compiled in. I hope.)
# * can't do really freaky things with the library list/library # * can't do really freaky things with the library list/library
# dirs, e.g. "-Ldir1 -lfoo -Ldir2 -lfoo" to link against # dirs, e.g. "-Ldir1 -lfoo -Ldir2 -lfoo" to link against
# different versions of libfoo.a in different locations. I # different versions of libfoo.a in different locations. I
# think this is useless without the ability to null out the # think this is useless without the ability to null out the
# library search path anyways. # library search path anyways.
# * don't deal with verbose and dry-run flags -- probably a
# CCompiler object should just drag them around the way the
# Distribution object does (either that or we have to drag
# around a Distribution object, which is what Command objects
# do... but might be kind of annoying)
def __init__ (self): def __init__ (self,
verbose=0,
dry_run=0):
self.verbose = verbose
self.dry_run = dry_run
# 'macros': a list of macro definitions (or undefinitions). A # 'macros': a list of macro definitions (or undefinitions). A
# macro definition is a 2-tuple (name, value), where the value is # macro definition is a 2-tuple (name, value), where the value is
...@@ -65,7 +68,6 @@ class CCompiler: ...@@ -65,7 +68,6 @@ class CCompiler:
# undefinition is a 1-tuple (name,). # undefinition is a 1-tuple (name,).
self.macros = [] self.macros = []
# 'include_dirs': a list of directories to search for include files # 'include_dirs': a list of directories to search for include files
self.include_dirs = [] self.include_dirs = []
...@@ -76,6 +78,10 @@ class CCompiler: ...@@ -76,6 +78,10 @@ class CCompiler:
# 'library_dirs': a list of directories to search for libraries # 'library_dirs': a list of directories to search for libraries
self.library_dirs = [] self.library_dirs = []
# 'runtime_library_dirs': a list of directories to search for
# shared libraries/objects at runtime
self.runtime_library_dirs = []
# 'objects': a list of object files (or similar, such as explicitly # 'objects': a list of object files (or similar, such as explicitly
# named library files) to include on any link # named library files) to include on any link
self.objects = [] self.objects = []
...@@ -205,6 +211,19 @@ class CCompiler: ...@@ -205,6 +211,19 @@ class CCompiler:
self.library_dirs = copy (dirs) self.library_dirs = copy (dirs)
def add_runtime_library_dir (self, dir):
"""Add 'dir' to the list of directories that will be searched for
shared libraries at runtime."""
self.runtime_library_dirs.append (dir)
def set_runtime_library_dirs (self, dirs):
"""Set the list of directories to search for shared libraries
at runtime to 'dirs' (a list of strings). This does not affect
any standard search path that the runtime linker may search by
default."""
self.runtime_library_dirs = copy (dirs)
def add_link_object (self, object): def add_link_object (self, object):
"""Add 'object' to the list of object files (or analogues, such """Add 'object' to the list of object files (or analogues, such
as explictly named library files or the output of "resource as explictly named library files or the output of "resource
...@@ -271,9 +290,6 @@ class CCompiler: ...@@ -271,9 +290,6 @@ class CCompiler:
pass pass
# XXX what's better/more consistent/more universally understood
# terminology: "shared library" or "dynamic library"?
def link_shared_lib (self, def link_shared_lib (self,
objects, objects,
output_libname, output_libname,
...@@ -296,10 +312,43 @@ class CCompiler: ...@@ -296,10 +312,43 @@ class CCompiler:
filename is explicitly supplied as 'output_filename'.""" filename is explicitly supplied as 'output_filename'."""
pass pass
# -- Filename mangling methods -------------------------------------
def object_filenames (source_filenames):
"""Return the list of object filenames corresponding to each
specified source filename."""
pass
def shared_object_filename (source_filename):
"""Return the shared object filename corresponding to a
specified source filename."""
pass
def library_filename (libname):
"""Return the static library filename corresponding to the
specified library name."""
pass
def shared_library_filename (libname):
"""Return the shared library filename corresponding to the
specified library name."""
pass
# -- Utility methods -----------------------------------------------
def spawn (self, cmd):
spawn (cmd, verbose=self.verbose, dry_run=self.dry_run)
# class CCompiler # class CCompiler
def new_compiler (plat=None): def new_compiler (plat=None,
verbose=0,
dry_run=0):
"""Generate a CCompiler instance for platform 'plat' (or the """Generate a CCompiler instance for platform 'plat' (or the
current platform, if 'plat' not supplied). Really instantiates current platform, if 'plat' not supplied). Really instantiates
some concrete subclass of CCompiler, of course.""" some concrete subclass of CCompiler, of course."""
...@@ -307,7 +356,7 @@ def new_compiler (plat=None): ...@@ -307,7 +356,7 @@ def new_compiler (plat=None):
if plat is None: plat = os.name if plat is None: plat = os.name
if plat == 'posix': if plat == 'posix':
from unixccompiler import UnixCCompiler from unixccompiler import UnixCCompiler
return UnixCCompiler () return UnixCCompiler (verbose, dry_run)
else: else:
raise DistutilsPlatformError, \ raise DistutilsPlatformError, \
"don't know how to compile C/C++ code on platform %s" % plat "don't know how to compile C/C++ code on platform %s" % plat
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment