Back to index

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

List of all members.

Public Member Functions

def preprocess
def create_static_lib
def link
def library_dir_option
def runtime_library_dir_option
def library_option
def find_library_file

Static Public Attributes

string compiler_type = 'unix'
dictionary executables
list src_extensions = [".c",".C",".cc",".cxx",".cpp",".m"]
string obj_extension = ".o"
string static_lib_extension = ".a"
string shared_lib_extension = ".so"
string dylib_lib_extension = ".dylib"
string static_lib_format = "lib%s%s"
string exe_extension = ".exe"

Private Member Functions

def _compile
def _is_gcc

Detailed Description

Definition at line 104 of file unixccompiler.py.


Member Function Documentation

def distutils.unixccompiler.UnixCCompiler._compile (   self,
  obj,
  src,
  ext,
  cc_args,
  extra_postargs,
  pp_opts 
) [private]

Reimplemented in distutils.cygwinccompiler.CygwinCCompiler, and distutils.emxccompiler.EMXCCompiler.

Definition at line 168 of file unixccompiler.py.

00168 
00169     def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
00170         compiler_so = self.compiler_so
00171         if sys.platform == 'darwin':
00172             compiler_so = _darwin_compiler_fixup(compiler_so, cc_args + extra_postargs)
00173         try:
00174             self.spawn(compiler_so + cc_args + [src, '-o', obj] +
00175                        extra_postargs)
00176         except DistutilsExecError as msg:
00177             raise CompileError(msg)

Here is the call graph for this function:

def distutils.unixccompiler.UnixCCompiler._is_gcc (   self,
  compiler_name 
) [private]

Definition at line 265 of file unixccompiler.py.

00265 
00266     def _is_gcc(self, compiler_name):
00267         return "gcc" in compiler_name or "g++" in compiler_name

Here is the caller graph for this function:

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

Definition at line 179 of file unixccompiler.py.

00179 
00180                           output_dir=None, debug=0, target_lang=None):
00181         objects, output_dir = self._fix_object_args(objects, output_dir)
00182 
00183         output_filename = \
00184             self.library_filename(output_libname, output_dir=output_dir)
00185 
00186         if self._need_link(objects, output_filename):
00187             self.mkpath(os.path.dirname(output_filename))
00188             self.spawn(self.archiver +
00189                        [output_filename] +
00190                        objects + self.objects)
00191 
00192             # Not many Unices required ranlib anymore -- SunOS 4.x is, I
00193             # think the only major Unix that does.  Maybe we need some
00194             # platform intelligence here to skip ranlib if it's not
00195             # needed -- or maybe Python's configure script took care of
00196             # it for us, hence the check for leading colon.
00197             if self.ranlib:
00198                 try:
00199                     self.spawn(self.ranlib + [output_filename])
00200                 except DistutilsExecError as msg:
00201                     raise LibError(msg)
00202         else:
00203             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.unixccompiler.UnixCCompiler.find_library_file (   self,
  dirs,
  lib,
  debug = 0 
)

Reimplemented in distutils.emxccompiler.EMXCCompiler.

Definition at line 313 of file unixccompiler.py.

00313 
00314     def find_library_file(self, dirs, lib, debug=0):
00315         shared_f = self.library_filename(lib, lib_type='shared')
00316         dylib_f = self.library_filename(lib, lib_type='dylib')
00317         static_f = self.library_filename(lib, lib_type='static')
00318 
00319         if sys.platform == 'darwin':
00320             # On OSX users can specify an alternate SDK using
00321             # '-isysroot', calculate the SDK root if it is specified
00322             # (and use it further on)
00323             cflags = sysconfig.get_config_var('CFLAGS')
00324             m = re.search(r'-isysroot\s+(\S+)', cflags)
00325             if m is None:
00326                 sysroot = '/'
00327             else:
00328                 sysroot = m.group(1)
00329 
00330 
00331 
00332         for dir in dirs:
00333             shared = os.path.join(dir, shared_f)
00334             dylib = os.path.join(dir, dylib_f)
00335             static = os.path.join(dir, static_f)
00336 
00337             if sys.platform == 'darwin' and (
00338                 dir.startswith('/System/') or (
00339                 dir.startswith('/usr/') and not dir.startswith('/usr/local/'))):
00340 
00341                 shared = os.path.join(sysroot, dir[1:], shared_f)
00342                 dylib = os.path.join(sysroot, dir[1:], dylib_f)
00343                 static = os.path.join(sysroot, dir[1:], static_f)
00344 
00345             # We're second-guessing the linker here, with not much hard
00346             # data to go on: GCC seems to prefer the shared library, so I'm
00347             # assuming that *all* Unix C compilers do.  And of course I'm
00348             # ignoring even GCC's "-static" option.  So sue me.
00349             if os.path.exists(dylib):
00350                 return dylib
00351             elif os.path.exists(shared):
00352                 return shared
00353             elif os.path.exists(static):
00354                 return static
00355 
00356         # Oops, didn't find it in *any* of 'dirs'
00357         return None

Here is the call graph for this function:

Definition at line 262 of file unixccompiler.py.

00262 
00263     def library_dir_option(self, dir):
00264         return "-L" + dir

Definition at line 310 of file unixccompiler.py.

00310 
00311     def library_option(self, lib):
00312         return "-l" + lib

def distutils.unixccompiler.UnixCCompiler.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 
)

Reimplemented in distutils.cygwinccompiler.CygwinCCompiler, and distutils.emxccompiler.EMXCCompiler.

Definition at line 208 of file unixccompiler.py.

00208 
00209              extra_postargs=None, build_temp=None, target_lang=None):
00210         objects, output_dir = self._fix_object_args(objects, output_dir)
00211         fixed_args = self._fix_lib_args(libraries, library_dirs,
00212                                         runtime_library_dirs)
00213         libraries, library_dirs, runtime_library_dirs = fixed_args
00214 
00215         lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,
00216                                    libraries)
00217         if not isinstance(output_dir, (str, type(None))):
00218             raise TypeError("'output_dir' must be a string or None")
00219         if output_dir is not None:
00220             output_filename = os.path.join(output_dir, output_filename)
00221 
00222         if self._need_link(objects, output_filename):
00223             ld_args = (objects + self.objects +
00224                        lib_opts + ['-o', output_filename])
00225             if debug:
00226                 ld_args[:0] = ['-g']
00227             if extra_preargs:
00228                 ld_args[:0] = extra_preargs
00229             if extra_postargs:
00230                 ld_args.extend(extra_postargs)
00231             self.mkpath(os.path.dirname(output_filename))
00232             try:
00233                 if target_desc == CCompiler.EXECUTABLE:
00234                     linker = self.linker_exe[:]
00235                 else:
00236                     linker = self.linker_so[:]
00237                 if target_lang == "c++" and self.compiler_cxx:
00238                     # skip over environment variable settings if /usr/bin/env
00239                     # is used to set up the linker's environment.
00240                     # This is needed on OSX. Note: this assumes that the
00241                     # normal and C++ compiler have the same environment
00242                     # settings.
00243                     i = 0
00244                     if os.path.basename(linker[0]) == "env":
00245                         i = 1
00246                         while '=' in linker[i]:
00247                             i += 1
00248                     linker[i] = self.compiler_cxx[i]
00249 
00250                 if sys.platform == 'darwin':
00251                     linker = _darwin_compiler_fixup(linker, ld_args)
00252 
00253                 self.spawn(linker + ld_args)
00254             except DistutilsExecError as msg:
00255                 raise LinkError(msg)
00256         else:
00257             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.unixccompiler.UnixCCompiler.preprocess (   self,
  source,
  output_file = None,
  macros = None,
  include_dirs = None,
  extra_preargs = None,
  extra_postargs = None 
)

Definition at line 143 of file unixccompiler.py.

00143 
00144                    include_dirs=None, extra_preargs=None, extra_postargs=None):
00145         fixed_args = self._fix_compile_args(None, macros, include_dirs)
00146         ignore, macros, include_dirs = fixed_args
00147         pp_opts = gen_preprocess_options(macros, include_dirs)
00148         pp_args = self.preprocessor + pp_opts
00149         if output_file:
00150             pp_args.extend(['-o', output_file])
00151         if extra_preargs:
00152             pp_args[:0] = extra_preargs
00153         if extra_postargs:
00154             pp_args.extend(extra_postargs)
00155         pp_args.append(source)
00156 
00157         # We need to preprocess: either we're being forced to, or we're
00158         # generating output to stdout, or there's a target output file and
00159         # the source file is newer than the target (or the target doesn't
00160         # exist).
00161         if self.force or output_file is None or newer(source, output_file):
00162             if output_file:
00163                 self.mkpath(os.path.dirname(output_file))
00164             try:
00165                 self.spawn(pp_args)
00166             except DistutilsExecError as msg:
00167                 raise CompileError(msg)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 268 of file unixccompiler.py.

00268 
00269     def runtime_library_dir_option(self, dir):
00270         # XXX Hackish, at the very least.  See Python bug #445902:
00271         # http://sourceforge.net/tracker/index.php
00272         #   ?func=detail&aid=445902&group_id=5470&atid=105470
00273         # Linkers on different platforms need different options to
00274         # specify that directories need to be added to the list of
00275         # directories searched for dependencies when a dynamic library
00276         # is sought.  GCC on GNU systems (Linux, FreeBSD, ...) has to
00277         # be told to pass the -R option through to the linker, whereas
00278         # other compilers and gcc on other systems just know this.
00279         # Other compilers may need something slightly different.  At
00280         # this time, there's no way to determine this information from
00281         # the configuration data stored in the Python installation, so
00282         # we use this hack.
00283         compiler = os.path.basename(sysconfig.get_config_var("CC"))
00284         if sys.platform[:6] == "darwin":
00285             # MacOSX's linker doesn't understand the -R flag at all
00286             return "-L" + dir
00287         elif sys.platform[:5] == "hp-ux":
00288             if self._is_gcc(compiler):
00289                 return ["-Wl,+s", "-L" + dir]
00290             return ["+s", "-L" + dir]
00291         elif sys.platform[:7] == "irix646" or sys.platform[:6] == "osf1V5":
00292             return ["-rpath", dir]
00293         else:
00294             if self._is_gcc(compiler):
00295                 # gcc on non-GNU systems does not need -Wl, but can
00296                 # use it anyway.  Since distutils has always passed in
00297                 # -Wl whenever gcc was used in the past it is probably
00298                 # safest to keep doing so.
00299                 if sysconfig.get_config_var("GNULD") == "yes":
00300                     # GNU ld needs an extra option to get a RUNPATH
00301                     # instead of just an RPATH.
00302                     return "-Wl,--enable-new-dtags,-R" + dir
00303                 else:
00304                     return "-Wl,-R" + dir
00305             else:
00306                 # No idea how --enable-new-dtags would be passed on to
00307                 # ld if this system was using GNU ld.  Don't know if a
00308                 # system like this even exists.
00309                 return "-R" + dir

Here is the call graph for this function:


Member Data Documentation

Definition at line 137 of file unixccompiler.py.

Initial value:
{'preprocessor' : None,
                   'compiler'     : ["cc"],
                   'compiler_so'  : ["cc"],
                   'compiler_cxx' : ["cc"],
                   'linker_so'    : ["cc", "-shared"],
                   'linker_exe'   : ["cc"],
                   'archiver'     : ["ar", "-cr"],
                   'ranlib'       : None,
                  }

Definition at line 114 of file unixccompiler.py.

list distutils.unixccompiler.UnixCCompiler.src_extensions = [".c",".C",".cc",".cxx",".cpp",".m"] [static]

Definition at line 133 of file unixccompiler.py.


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