summaryrefslogtreecommitdiff
path: root/Lib/distutils/ccompiler.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/distutils/ccompiler.py')
-rw-r--r--Lib/distutils/ccompiler.py391
1 files changed, 172 insertions, 219 deletions
diff --git a/Lib/distutils/ccompiler.py b/Lib/distutils/ccompiler.py
index bf92d78026..c2b1f6fbe9 100644
--- a/Lib/distutils/ccompiler.py
+++ b/Lib/distutils/ccompiler.py
@@ -3,21 +3,73 @@
Contains CCompiler, an abstract base class that defines the interface
for the Distutils compiler abstraction model."""
-# This module should be kept compatible with Python 2.1.
-
__revision__ = "$Id$"
-import sys, os, re
-from types import *
-from copy import copy
-from distutils.errors import *
+import sys
+import os
+import re
+
+from distutils.errors import (CompileError, LinkError, UnknownFileError,
+ DistutilsPlatformError, DistutilsModuleError)
from distutils.spawn import spawn
from distutils.file_util import move_file
from distutils.dir_util import mkpath
-from distutils.dep_util import newer_pairwise, newer_group
+from distutils.dep_util import newer_group
from distutils.util import split_quoted, execute
from distutils import log
+_sysconfig = __import__('sysconfig')
+
+def customize_compiler(compiler):
+ """Do any platform-specific customization of a CCompiler instance.
+
+ Mainly needed on Unix, so we can plug in the information that
+ varies across Unices and is stored in Python's Makefile.
+ """
+ if compiler.compiler_type == "unix":
+ (cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \
+ _sysconfig.get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
+ 'CCSHARED', 'LDSHARED', 'SO', 'AR',
+ 'ARFLAGS')
+
+ if 'CC' in os.environ:
+ cc = os.environ['CC']
+ if 'CXX' in os.environ:
+ cxx = os.environ['CXX']
+ if 'LDSHARED' in os.environ:
+ ldshared = os.environ['LDSHARED']
+ if 'CPP' in os.environ:
+ cpp = os.environ['CPP']
+ else:
+ cpp = cc + " -E" # not always
+ if 'LDFLAGS' in os.environ:
+ ldshared = ldshared + ' ' + os.environ['LDFLAGS']
+ if 'CFLAGS' in os.environ:
+ cflags = opt + ' ' + os.environ['CFLAGS']
+ ldshared = ldshared + ' ' + os.environ['CFLAGS']
+ if 'CPPFLAGS' in os.environ:
+ cpp = cpp + ' ' + os.environ['CPPFLAGS']
+ cflags = cflags + ' ' + os.environ['CPPFLAGS']
+ ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
+ if 'AR' in os.environ:
+ ar = os.environ['AR']
+ if 'ARFLAGS' in os.environ:
+ archiver = ar + ' ' + os.environ['ARFLAGS']
+ else:
+ archiver = ar + ' ' + ar_flags
+
+ cc_cmd = cc + ' ' + cflags
+ compiler.set_executables(
+ preprocessor=cpp,
+ compiler=cc_cmd,
+ compiler_so=cc_cmd + ' ' + ccshared,
+ compiler_cxx=cxx,
+ linker_so=ldshared,
+ linker_exe=cc,
+ archiver=archiver)
+
+ compiler.shared_lib_extension = so_ext
+
class CCompiler:
"""Abstract base class to define the interface that must be implemented
by real compiler classes. Also has some utility methods used by
@@ -88,11 +140,7 @@ class CCompiler:
}
language_order = ["c++", "objc", "c"]
- def __init__ (self,
- verbose=0,
- dry_run=0,
- force=0):
-
+ def __init__ (self, verbose=0, dry_run=0, force=0):
self.dry_run = dry_run
self.force = force
self.verbose = verbose
@@ -128,11 +176,7 @@ class CCompiler:
for key in self.executables.keys():
self.set_executable(key, self.executables[key])
- # __init__ ()
-
-
- def set_executables (self, **args):
-
+ def set_executables(self, **args):
"""Define the executables (and options for them) that will be run
to perform the various stages of compilation. The exact set of
executables that may be specified here depends on the compiler
@@ -165,36 +209,31 @@ class CCompiler:
(key, self.__class__.__name__)
self.set_executable(key, args[key])
- # set_executables ()
-
def set_executable(self, key, value):
- if type(value) is StringType:
+ if isinstance(value, str):
setattr(self, key, split_quoted(value))
else:
setattr(self, key, value)
-
- def _find_macro (self, name):
+ def _find_macro(self, name):
i = 0
for defn in self.macros:
if defn[0] == name:
return i
i = i + 1
-
return None
-
- def _check_macro_definitions (self, definitions):
+ def _check_macro_definitions(self, definitions):
"""Ensures that every element of 'definitions' is a valid macro
definition, ie. either (name,value) 2-tuple or a (name,) tuple. Do
nothing if all definitions are OK, raise TypeError otherwise.
"""
for defn in definitions:
- if not (type (defn) is TupleType and
+ if not (isinstance(defn, tuple) and
(len (defn) == 1 or
(len (defn) == 2 and
- (type (defn[1]) is StringType or defn[1] is None))) and
- type (defn[0]) is StringType):
+ (isinstance(defn[1], str) or defn[1] is None))) and
+ isinstance(defn[0], str)):
raise TypeError, \
("invalid macro definition '%s': " % defn) + \
"must be tuple (string,), (string, string), or " + \
@@ -203,7 +242,7 @@ class CCompiler:
# -- Bookkeeping methods -------------------------------------------
- def define_macro (self, name, value=None):
+ def define_macro(self, name, value=None):
"""Define a preprocessor macro for all compilations driven by this
compiler object. The optional parameter 'value' should be a
string; if it is not supplied, then the macro will be defined
@@ -219,8 +258,7 @@ class CCompiler:
defn = (name, value)
self.macros.append (defn)
-
- def undefine_macro (self, name):
+ def undefine_macro(self, name):
"""Undefine a preprocessor macro for all compilations driven by
this compiler object. If the same macro is defined by
'define_macro()' and undefined by 'undefine_macro()' the last call
@@ -238,8 +276,7 @@ class CCompiler:
undefn = (name,)
self.macros.append (undefn)
-
- def add_include_dir (self, dir):
+ def add_include_dir(self, dir):
"""Add 'dir' to the list of directories that will be searched for
header files. The compiler is instructed to search directories in
the order in which they are supplied by successive calls to
@@ -247,7 +284,7 @@ class CCompiler:
"""
self.include_dirs.append (dir)
- def set_include_dirs (self, dirs):
+ def set_include_dirs(self, dirs):
"""Set the list of directories that will be searched to 'dirs' (a
list of strings). Overrides any preceding calls to
'add_include_dir()'; subsequence calls to 'add_include_dir()' add
@@ -255,10 +292,9 @@ class CCompiler:
any list of standard include directories that the compiler may
search by default.
"""
- self.include_dirs = copy (dirs)
-
+ self.include_dirs = dirs[:]
- def add_library (self, libname):
+ def add_library(self, libname):
"""Add 'libname' to the list of libraries that will be included in
all links driven by this compiler object. Note that 'libname'
should *not* be the name of a file containing a library, but the
@@ -274,61 +310,59 @@ class CCompiler:
"""
self.libraries.append (libname)
- def set_libraries (self, libnames):
+ def set_libraries(self, libnames):
"""Set the list of libraries to be included in all links driven by
this compiler object to 'libnames' (a list of strings). This does
not affect any standard system libraries that the linker may
include by default.
"""
- self.libraries = copy (libnames)
+ self.libraries = libnames[:]
- def add_library_dir (self, dir):
+ def add_library_dir(self, dir):
"""Add 'dir' to the list of directories that will be searched for
libraries specified to 'add_library()' and 'set_libraries()'. The
linker will be instructed to search for libraries in the order they
are supplied to 'add_library_dir()' and/or 'set_library_dirs()'.
"""
- self.library_dirs.append (dir)
+ self.library_dirs.append(dir)
- def set_library_dirs (self, dirs):
+ def set_library_dirs(self, dirs):
"""Set the list of library search directories to 'dirs' (a list of
strings). This does not affect any standard library search path
that the linker may search by default.
"""
- self.library_dirs = copy (dirs)
+ self.library_dirs = dirs[:]
-
- def add_runtime_library_dir (self, dir):
+ 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)
+ self.runtime_library_dirs.append(dir)
- def set_runtime_library_dirs (self, dirs):
+ 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)
-
+ self.runtime_library_dirs = dirs[:]
- def add_link_object (self, object):
+ def add_link_object(self, object):
"""Add 'object' to the list of object files (or analogues, such as
explicitly named library files or the output of "resource
compilers") to be included in every link driven by this compiler
object.
"""
- self.objects.append (object)
+ self.objects.append(object)
- def set_link_objects (self, objects):
+ def set_link_objects(self, objects):
"""Set the list of object files (or analogues) to be included in
every link to 'objects'. This does not affect any standard object
files that the linker may include by default (such as system
libraries).
"""
- self.objects = copy (objects)
+ self.objects = objects[:]
# -- Private utility methods --------------------------------------
@@ -341,19 +375,19 @@ class CCompiler:
"""Process arguments and decide which source files to compile."""
if outdir is None:
outdir = self.output_dir
- elif type(outdir) is not StringType:
+ elif not isinstance(outdir, str):
raise TypeError, "'output_dir' must be a string or None"
if macros is None:
macros = self.macros
- elif type(macros) is ListType:
+ elif isinstance(macros, list):
macros = macros + (self.macros or [])
else:
raise TypeError, "'macros' (if supplied) must be a list of tuples"
if incdirs is None:
incdirs = self.include_dirs
- elif type(incdirs) in (ListType, TupleType):
+ elif isinstance(incdirs, (list, tuple)):
incdirs = list(incdirs) + (self.include_dirs or [])
else:
raise TypeError, \
@@ -389,7 +423,7 @@ class CCompiler:
cc_args[:0] = before
return cc_args
- def _fix_compile_args (self, output_dir, macros, include_dirs):
+ def _fix_compile_args(self, output_dir, macros, include_dirs):
"""Typecheck and fix-up some of the arguments to the 'compile()'
method, and return fixed-up values. Specifically: if 'output_dir'
is None, replaces it with 'self.output_dir'; ensures that 'macros'
@@ -401,19 +435,19 @@ class CCompiler:
"""
if output_dir is None:
output_dir = self.output_dir
- elif type (output_dir) is not StringType:
+ elif not isinstance(output_dir, str):
raise TypeError, "'output_dir' must be a string or None"
if macros is None:
macros = self.macros
- elif type (macros) is ListType:
+ elif isinstance(macros, list):
macros = macros + (self.macros or [])
else:
raise TypeError, "'macros' (if supplied) must be a list of tuples"
if include_dirs is None:
include_dirs = self.include_dirs
- elif type (include_dirs) in (ListType, TupleType):
+ elif isinstance(include_dirs, (list, tuple)):
include_dirs = list (include_dirs) + (self.include_dirs or [])
else:
raise TypeError, \
@@ -421,44 +455,25 @@ class CCompiler:
return output_dir, macros, include_dirs
- # _fix_compile_args ()
-
- def _prep_compile(self, sources, output_dir, depends=None):
- """Decide which souce files must be recompiled.
-
- Determine the list of object files corresponding to 'sources',
- and figure out which ones really need to be recompiled.
- Return a list of all object files and a dictionary telling
- which source files can be skipped.
- """
- # Get the list of expected output (object) files
- objects = self.object_filenames(sources, output_dir=output_dir)
- assert len(objects) == len(sources)
-
- # Return an empty dict for the "which source files can be skipped"
- # return value to preserve API compatibility.
- return objects, {}
-
- def _fix_object_args (self, objects, output_dir):
+ def _fix_object_args(self, objects, output_dir):
"""Typecheck and fix up some arguments supplied to various methods.
Specifically: ensure that 'objects' is a list; if output_dir is
None, replace with self.output_dir. Return fixed versions of
'objects' and 'output_dir'.
"""
- if type (objects) not in (ListType, TupleType):
+ if not isinstance(objects, (list, tuple)):
raise TypeError, \
"'objects' must be a list or tuple of strings"
objects = list (objects)
if output_dir is None:
output_dir = self.output_dir
- elif type (output_dir) is not StringType:
+ elif not isinstance(output_dir, str):
raise TypeError, "'output_dir' must be a string or None"
return (objects, output_dir)
-
- def _fix_lib_args (self, libraries, library_dirs, runtime_library_dirs):
+ def _fix_lib_args(self, libraries, library_dirs, runtime_library_dirs):
"""Typecheck and fix up some of the arguments supplied to the
'link_*' methods. Specifically: ensure that all arguments are
lists, and augment them with their permanent versions
@@ -467,7 +482,7 @@ class CCompiler:
"""
if libraries is None:
libraries = self.libraries
- elif type (libraries) in (ListType, TupleType):
+ elif isinstance(libraries, (list, tuple)):
libraries = list (libraries) + (self.libraries or [])
else:
raise TypeError, \
@@ -475,7 +490,7 @@ class CCompiler:
if library_dirs is None:
library_dirs = self.library_dirs
- elif type (library_dirs) in (ListType, TupleType):
+ elif isinstance(library_dirs, (list, tuple)):
library_dirs = list (library_dirs) + (self.library_dirs or [])
else:
raise TypeError, \
@@ -483,7 +498,7 @@ class CCompiler:
if runtime_library_dirs is None:
runtime_library_dirs = self.runtime_library_dirs
- elif type (runtime_library_dirs) in (ListType, TupleType):
+ elif isinstance(runtime_library_dirs, (list, tuple)):
runtime_library_dirs = (list (runtime_library_dirs) +
(self.runtime_library_dirs or []))
else:
@@ -493,10 +508,7 @@ class CCompiler:
return (libraries, library_dirs, runtime_library_dirs)
- # _fix_lib_args ()
-
-
- def _need_link (self, objects, output_file):
+ def _need_link(self, objects, output_file):
"""Return true if we need to relink the files listed in 'objects'
to recreate 'output_file'.
"""
@@ -509,13 +521,11 @@ class CCompiler:
newer = newer_group (objects, output_file)
return newer
- # _need_link ()
-
- def detect_language (self, sources):
+ def detect_language(self, sources):
"""Detect the language of a given file, or list of files. Uses
language_map, and language_order to do the job.
"""
- if type(sources) is not ListType:
+ if not isinstance(sources, list):
sources = [sources]
lang = None
index = len(self.language_order)
@@ -531,18 +541,11 @@ class CCompiler:
pass
return lang
- # detect_language ()
-
# -- Worker methods ------------------------------------------------
# (must be implemented by subclasses)
- def preprocess (self,
- source,
- output_file=None,
- macros=None,
- include_dirs=None,
- extra_preargs=None,
- extra_postargs=None):
+ def preprocess(self, source, output_file=None, macros=None,
+ include_dirs=None, extra_preargs=None, extra_postargs=None):
"""Preprocess a single C/C++ source file, named in 'source'.
Output will be written to file named 'output_file', or stdout if
'output_file' not supplied. 'macros' is a list of macro
@@ -630,12 +633,8 @@ class CCompiler:
# should implement _compile().
pass
- def create_static_lib (self,
- objects,
- output_libname,
- output_dir=None,
- debug=0,
- target_lang=None):
+ def create_static_lib(self, objects, output_libname, output_dir=None,
+ debug=0, target_lang=None):
"""Link a bunch of stuff together to create a static library file.
The "bunch of stuff" consists of the list of object files supplied
as 'objects', the extra object files supplied to
@@ -660,26 +659,15 @@ class CCompiler:
"""
pass
-
# values for target_desc parameter in link()
SHARED_OBJECT = "shared_object"
SHARED_LIBRARY = "shared_library"
EXECUTABLE = "executable"
- def 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):
+ def 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):
"""Link a bunch of stuff together to create an executable or
shared library file.
@@ -728,19 +716,11 @@ class CCompiler:
# Old 'link_*()' methods, rewritten to use the new 'link()' method.
- def link_shared_lib (self,
- objects,
- output_libname,
- 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):
+ def link_shared_lib(self, objects, output_libname, 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):
self.link(CCompiler.SHARED_LIBRARY, objects,
self.library_filename(output_libname, lib_type='shared'),
output_dir,
@@ -749,37 +729,21 @@ class CCompiler:
extra_preargs, extra_postargs, build_temp, target_lang)
- def link_shared_object (self,
- 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):
+ def link_shared_object(self, 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):
self.link(CCompiler.SHARED_OBJECT, objects,
output_filename, output_dir,
libraries, library_dirs, runtime_library_dirs,
export_symbols, debug,
extra_preargs, extra_postargs, build_temp, target_lang)
-
- def link_executable (self,
- objects,
- output_progname,
- output_dir=None,
- libraries=None,
- library_dirs=None,
- runtime_library_dirs=None,
- debug=0,
- extra_preargs=None,
- extra_postargs=None,
- target_lang=None):
+ def link_executable(self, objects, output_progname, output_dir=None,
+ libraries=None, library_dirs=None,
+ runtime_library_dirs=None, debug=0, extra_preargs=None,
+ extra_postargs=None, target_lang=None):
self.link(CCompiler.EXECUTABLE, objects,
self.executable_filename(output_progname), output_dir,
libraries, library_dirs, runtime_library_dirs, None,
@@ -791,29 +755,26 @@ class CCompiler:
# no appropriate default implementation so subclasses should
# implement all of these.
- def library_dir_option (self, dir):
+ def library_dir_option(self, dir):
"""Return the compiler option to add 'dir' to the list of
directories searched for libraries.
"""
raise NotImplementedError
- def runtime_library_dir_option (self, dir):
+ def runtime_library_dir_option(self, dir):
"""Return the compiler option to add 'dir' to the list of
directories searched for runtime libraries.
"""
raise NotImplementedError
- def library_option (self, lib):
+ def library_option(self, lib):
"""Return the compiler option to add 'dir' to the list of libraries
linked into the shared library or executable.
"""
raise NotImplementedError
- def has_function(self, funcname,
- includes=None,
- include_dirs=None,
- libraries=None,
- library_dirs=None):
+ def has_function(self, funcname, includes=None, include_dirs=None,
+ libraries=None, library_dirs=None):
"""Return a boolean indicating whether funcname is supported on
the current platform. The optional arguments can be used to
augment the compilation environment.
@@ -833,14 +794,16 @@ class CCompiler:
library_dirs = []
fd, fname = tempfile.mkstemp(".c", funcname, text=True)
f = os.fdopen(fd, "w")
- for incl in includes:
- f.write("""#include "%s"\n""" % incl)
- f.write("""\
+ try:
+ for incl in includes:
+ f.write("""#include "%s"\n""" % incl)
+ f.write("""\
main (int argc, char **argv) {
%s();
}
""" % funcname)
- f.close()
+ finally:
+ f.close()
try:
objects = self.compile([fname], include_dirs=include_dirs)
except CompileError:
@@ -944,28 +907,28 @@ main (int argc, char **argv) {
# -- Utility methods -----------------------------------------------
- def announce (self, msg, level=1):
+ def announce(self, msg, level=1):
log.debug(msg)
- def debug_print (self, msg):
+ def debug_print(self, msg):
from distutils.debug import DEBUG
if DEBUG:
print msg
- def warn (self, msg):
- sys.stderr.write ("warning: %s\n" % msg)
+ def warn(self, msg):
+ sys.stderr.write("warning: %s\n" % msg)
- def execute (self, func, args, msg=None, level=1):
+ def execute(self, func, args, msg=None, level=1):
execute(func, args, msg, self.dry_run)
- def spawn (self, cmd):
- spawn (cmd, dry_run=self.dry_run)
+ def spawn(self, cmd):
+ spawn(cmd, dry_run=self.dry_run)
- def move_file (self, src, dst):
- return move_file (src, dst, dry_run=self.dry_run)
+ def move_file(self, src, dst):
+ return move_file(src, dst, dry_run=self.dry_run)
- def mkpath (self, name, mode=0777):
- mkpath (name, mode, dry_run=self.dry_run)
+ def mkpath(self, name, mode=0777):
+ mkpath(name, mode, dry_run=self.dry_run)
# class CCompiler
@@ -987,12 +950,10 @@ _default_compilers = (
# OS name mappings
('posix', 'unix'),
('nt', 'msvc'),
- ('mac', 'mwerks'),
)
def get_default_compiler(osname=None, platform=None):
-
""" Determine the default compiler to use for the given platform.
osname should be one of the standard Python OS names (i.e. the
@@ -1027,8 +988,6 @@ compiler_class = { 'unix': ('unixccompiler', 'UnixCCompiler',
"Mingw32 port of GNU C Compiler for Win32"),
'bcpp': ('bcppcompiler', 'BCPPCompiler',
"Borland C++ Compiler"),
- 'mwerks': ('mwerkscompiler', 'MWerksCompiler',
- "MetroWerks CodeWarrior"),
'emx': ('emxccompiler', 'EMXCCompiler',
"EMX port of GNU C Compiler for OS/2"),
}
@@ -1050,11 +1009,7 @@ def show_compilers():
pretty_printer.print_help("List of available compilers:")
-def new_compiler (plat=None,
- compiler=None,
- verbose=0,
- dry_run=0,
- force=0):
+def new_compiler(plat=None, compiler=None, verbose=0, dry_run=0, force=0):
"""Generate an instance of some CCompiler subclass for the supplied
platform/compiler combination. 'plat' defaults to 'os.name'
(eg. 'posix', 'nt'), and 'compiler' defaults to the default compiler
@@ -1096,10 +1051,10 @@ def new_compiler (plat=None,
# XXX The None is necessary to preserve backwards compatibility
# with classes that expect verbose to be the first positional
# argument.
- return klass (None, dry_run, force)
+ return klass(None, dry_run, force)
-def gen_preprocess_options (macros, include_dirs):
+def gen_preprocess_options(macros, include_dirs):
"""Generate C pre-processor options (-D, -U, -I) as used by at least
two types of compilers: the typical Unix compiler and Visual C++.
'macros' is the usual thing, a list of 1- or 2-tuples, where (name,)
@@ -1124,7 +1079,7 @@ def gen_preprocess_options (macros, include_dirs):
pp_opts = []
for macro in macros:
- if not (type (macro) is TupleType and
+ if not (isinstance(macro, tuple) and
1 <= len (macro) <= 2):
raise TypeError, \
("bad macro definition '%s': " +
@@ -1147,27 +1102,27 @@ def gen_preprocess_options (macros, include_dirs):
return pp_opts
-# gen_preprocess_options ()
-
-def gen_lib_options (compiler, library_dirs, runtime_library_dirs, libraries):
+def gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries):
"""Generate linker options for searching library directories and
- linking with specific libraries. 'libraries' and 'library_dirs' are,
- respectively, lists of library names (not filenames!) and search
- directories. Returns a list of command-line options suitable for use
- with some compiler (depending on the two format strings passed in).
+ linking with specific libraries.
+
+ 'libraries' and 'library_dirs' are, respectively, lists of library names
+ (not filenames!) and search directories. Returns a list of command-line
+ options suitable for use with some compiler (depending on the two format
+ strings passed in).
"""
lib_opts = []
for dir in library_dirs:
- lib_opts.append (compiler.library_dir_option (dir))
+ lib_opts.append(compiler.library_dir_option(dir))
for dir in runtime_library_dirs:
- opt = compiler.runtime_library_dir_option (dir)
- if type(opt) is ListType:
- lib_opts = lib_opts + opt
+ opt = compiler.runtime_library_dir_option(dir)
+ if isinstance(opt, list):
+ lib_opts.extend(opt)
else:
- lib_opts.append (opt)
+ lib_opts.append(opt)
# XXX it's important that we *not* remove redundant library mentions!
# sometimes you really do have to say "-lfoo -lbar -lfoo" in order to
@@ -1176,17 +1131,15 @@ def gen_lib_options (compiler, library_dirs, runtime_library_dirs, libraries):
# pretty nasty way to arrange your C code.
for lib in libraries:
- (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)
+ lib_dir, lib_name = os.path.split(lib)
+ if lib_dir != '':
+ lib_file = compiler.find_library_file([lib_dir], lib_name)
+ if lib_file is not None:
+ lib_opts.append(lib_file)
else:
- compiler.warn ("no library file corresponding to "
- "'%s' found (skipping)" % lib)
+ compiler.warn("no library file corresponding to "
+ "'%s' found (skipping)" % lib)
else:
- lib_opts.append (compiler.library_option (lib))
+ lib_opts.append(compiler.library_option(lib))
return lib_opts
-
-# gen_lib_options ()