Commit e07c9104 authored by Greg Ward's avatar Greg Ward

Slight change to the meaning of the 'libraries' list: if a library name

  has a directory component, then we only search for the library in
  that one directory, ie. ignore the 'library_dirs' lists for that
  one library.
Changed calling convention to 'gen_lib_options()' again: now, it takes
  a CCompiler instance and calls methods on it instead of taking
  format strings.  Also implemented the new "library name" semantics
  using the 'find_library_file()' method in the CCompiler instance.
Added 'force' flag to CCompiler; added to constructor and 'new_compiler()'.
Added 'warn()' method.
parent c162ef1a
...@@ -67,10 +67,12 @@ class CCompiler: ...@@ -67,10 +67,12 @@ class CCompiler:
def __init__ (self, def __init__ (self,
verbose=0, verbose=0,
dry_run=0): dry_run=0,
force=0):
self.verbose = verbose self.verbose = verbose
self.dry_run = dry_run self.dry_run = dry_run
self.force = force
# 'output_dir': a common output directory for object, library, # 'output_dir': a common output directory for object, library,
# shared object, and shared library files # shared object, and shared library files
...@@ -312,9 +314,19 @@ class CCompiler: ...@@ -312,9 +314,19 @@ class CCompiler:
'output_libname' should be a library name, not a filename; 'output_libname' should be a library name, not a filename;
the filename will be inferred from the library name. the filename will be inferred from the library name.
'library_dirs', if supplied, should be a list of additional 'libraries' is a list of libraries to link against. These are
directories to search on top of the system default and those library names, not filenames, since they're translated into
supplied to 'add_library_dir()' and/or 'set_library_dirs()'. filenames in a platform-specific way (eg. "foo" becomes
"libfoo.a" on Unix and "foo.lib" on DOS/Windows). However, they
can include a directory component, which means the linker will
look in that specific directory rather than searching all the
normal locations.
'library_dirs', if supplied, should be a list of directories to
search for libraries that were specified as bare library names
(ie. no directory component). These are on top of the system
default and those supplied to 'add_library_dir()' and/or
'set_library_dirs()'.
'extra_preargs' and 'extra_postargs' are as for 'compile()' 'extra_preargs' and 'extra_postargs' are as for 'compile()'
(except of course that they supply command-line arguments (except of course that they supply command-line arguments
...@@ -402,6 +414,9 @@ class CCompiler: ...@@ -402,6 +414,9 @@ class CCompiler:
if self.verbose >= level: if self.verbose >= level:
print msg print msg
def warn (self, msg):
sys.stderr.write ("warning: %s\n" % msg)
def spawn (self, cmd): def spawn (self, cmd):
spawn (cmd, verbose=self.verbose, dry_run=self.dry_run) spawn (cmd, verbose=self.verbose, dry_run=self.dry_run)
...@@ -429,7 +444,8 @@ compiler_class = { 'unix': ('unixccompiler', 'UnixCCompiler'), ...@@ -429,7 +444,8 @@ compiler_class = { 'unix': ('unixccompiler', 'UnixCCompiler'),
def new_compiler (plat=None, def new_compiler (plat=None,
compiler=None, compiler=None,
verbose=0, verbose=0,
dry_run=0): dry_run=0,
force=0):
"""Generate an instance of some CCompiler subclass for the supplied """Generate an instance of some CCompiler subclass for the supplied
platform/compiler combination. 'plat' defaults to 'os.name' platform/compiler combination. 'plat' defaults to 'os.name'
...@@ -470,7 +486,7 @@ def new_compiler (plat=None, ...@@ -470,7 +486,7 @@ def new_compiler (plat=None,
("can't compile C/C++ code: unable to find class '%s' " + ("can't compile C/C++ code: unable to find class '%s' " +
"in module '%s'") % (class_name, module_name) "in module '%s'") % (class_name, module_name)
return klass (verbose, dry_run) return klass (verbose, dry_run, force)
def gen_preprocess_options (macros, includes): def gen_preprocess_options (macros, includes):
...@@ -524,20 +540,18 @@ def gen_preprocess_options (macros, includes): ...@@ -524,20 +540,18 @@ def gen_preprocess_options (macros, includes):
# gen_preprocess_options () # gen_preprocess_options ()
def gen_lib_options (library_dirs, libraries, dir_format, lib_format): def gen_lib_options (compiler, library_dirs, libraries):
"""Generate linker options for searching library directories and """Generate linker options for searching library directories and
linking with specific libraries. 'libraries' and 'library_dirs' linking with specific libraries. 'libraries' and 'library_dirs'
are, respectively, lists of library names (not filenames!) and are, respectively, lists of library names (not filenames!) and
search directories. 'lib_format' is a format string with exactly search directories. Returns a list of command-line options suitable
one "%s", into which will be plugged each library name in turn; for use with some compiler (depending on the two format strings
'dir_format' is similar, but directory names will be plugged into passed in)."""
it. Returns a list of command-line options suitable for use with
some compiler (depending on the two format strings passed in)."""
lib_opts = [] lib_opts = []
for dir in library_dirs: for dir in library_dirs:
lib_opts.append (dir_format % dir) lib_opts.append (compiler.library_dir_option (dir))
# XXX it's important that we *not* remove redundant library mentions! # XXX it's important that we *not* remove redundant library mentions!
# sometimes you really do have to say "-lfoo -lbar -lfoo" in order to # sometimes you really do have to say "-lfoo -lbar -lfoo" in order to
...@@ -546,7 +560,16 @@ def gen_lib_options (library_dirs, libraries, dir_format, lib_format): ...@@ -546,7 +560,16 @@ def gen_lib_options (library_dirs, libraries, dir_format, lib_format):
# pretty nasty way to arrange your C code. # pretty nasty way to arrange your C code.
for lib in libraries: for lib in libraries:
lib_opts.append (lib_format % lib) (lib_dir, lib_name) = os.path.split (lib)
if lib_dir:
lib_file = compiler.find_library_file ([lib_dir], lib_name)
if lib_file:
lib_opts.append (lib_file)
else:
compiler.warn ("no library file corresponding to "
"'%s' found (skipping)" % lib)
else:
lib_opts.append (compiler.library_option (lib))
return lib_opts return lib_opts
......
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