Back to index

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

List of all members.

Public Member Functions

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

Public Attributes

 dll_libraries
 dllwrap_version
 linker_dll
 gcc_version

Static Public Attributes

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

Detailed Description

Handles the Mingw32 port of the GNU C compiler to Windows.

Definition at line 271 of file cygwinccompiler.py.


Constructor & Destructor Documentation

def distutils.cygwinccompiler.Mingw32CCompiler.__init__ (   self,
  verbose = 0,
  dry_run = 0,
  force = 0 
)

Reimplemented from distutils.cygwinccompiler.CygwinCCompiler.

Definition at line 276 of file cygwinccompiler.py.

00276 
00277     def __init__(self, verbose=0, dry_run=0, force=0):
00278 
00279         CygwinCCompiler.__init__ (self, verbose, dry_run, force)
00280 
00281         # ld_version >= "2.13" support -shared so use it instead of
00282         # -mdll -static
00283         if self.ld_version >= "2.13":
00284             shared_option = "-shared"
00285         else:
00286             shared_option = "-mdll -static"
00287 
00288         # A real mingw32 doesn't need to specify a different entry point,
00289         # but cygwin 2.91.57 in no-cygwin-mode needs it.
00290         if self.gcc_version <= "2.91.57":
00291             entry_point = '--entry _DllMain@12'
00292         else:
00293             entry_point = ''
00294 
00295         self.set_executables(compiler='gcc -mno-cygwin -O -Wall',
00296                              compiler_so='gcc -mno-cygwin -mdll -O -Wall',
00297                              compiler_cxx='g++ -mno-cygwin -O -Wall',
00298                              linker_exe='gcc -mno-cygwin',
00299                              linker_so='%s -mno-cygwin %s %s'
00300                                         % (self.linker_dll, shared_option,
00301                                            entry_point))
00302         # Maybe we should also append -mthreads, but then the finished
00303         # dlls need another dll (mingwm10.dll see Mingw32 docs)
00304         # (-mthreads: Support thread-safe exception handling on `Mingw32')
00305 
00306         # no additional libraries needed
00307         self.dll_libraries=[]
00308 
00309         # Include the appropriate MSVC runtime library if Python was built
00310         # with MSVC 7.0 or later.
00311         self.dll_libraries = get_msvcr()
00312 
00313 # Because these compilers aren't configured in Python's pyconfig.h file by
00314 # default, we should at least warn the user if he is using a unmodified
00315 # version.

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

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

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 
) [inherited]

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:

def distutils.unixccompiler.UnixCCompiler.library_dir_option (   self,
  dir 
) [inherited]

Definition at line 262 of file unixccompiler.py.

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

def distutils.unixccompiler.UnixCCompiler.library_option (   self,
  lib 
) [inherited]

Definition at line 310 of file unixccompiler.py.

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

def distutils.cygwinccompiler.CygwinCCompiler.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 
) [inherited]
Link the objects.

Reimplemented from distutils.unixccompiler.UnixCCompiler.

Definition at line 173 of file cygwinccompiler.py.

00173 
00174              extra_postargs=None, build_temp=None, target_lang=None):
00175         """Link the objects."""
00176         # use separate copies, so we can modify the lists
00177         extra_preargs = copy.copy(extra_preargs or [])
00178         libraries = copy.copy(libraries or [])
00179         objects = copy.copy(objects or [])
00180 
00181         # Additional libraries
00182         libraries.extend(self.dll_libraries)
00183 
00184         # handle export symbols by creating a def-file
00185         # with executables this only works with gcc/ld as linker
00186         if ((export_symbols is not None) and
00187             (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
00188             # (The linker doesn't do anything if output is up-to-date.
00189             # So it would probably better to check if we really need this,
00190             # but for this we had to insert some unchanged parts of
00191             # UnixCCompiler, and this is not what we want.)
00192 
00193             # we want to put some files in the same directory as the
00194             # object files are, build_temp doesn't help much
00195             # where are the object files
00196             temp_dir = os.path.dirname(objects[0])
00197             # name of dll to give the helper files the same base name
00198             (dll_name, dll_extension) = os.path.splitext(
00199                 os.path.basename(output_filename))
00200 
00201             # generate the filenames for these files
00202             def_file = os.path.join(temp_dir, dll_name + ".def")
00203             lib_file = os.path.join(temp_dir, 'lib' + dll_name + ".a")
00204 
00205             # Generate .def file
00206             contents = [
00207                 "LIBRARY %s" % os.path.basename(output_filename),
00208                 "EXPORTS"]
00209             for sym in export_symbols:
00210                 contents.append(sym)
00211             self.execute(write_file, (def_file, contents),
00212                          "writing %s" % def_file)
00213 
00214             # next add options for def-file and to creating import libraries
00215 
00216             # dllwrap uses different options than gcc/ld
00217             if self.linker_dll == "dllwrap":
00218                 extra_preargs.extend(["--output-lib", lib_file])
00219                 # for dllwrap we have to use a special option
00220                 extra_preargs.extend(["--def", def_file])
00221             # we use gcc/ld here and can be sure ld is >= 2.9.10
00222             else:
00223                 # doesn't work: bfd_close build\...\libfoo.a: Invalid operation
00224                 #extra_preargs.extend(["-Wl,--out-implib,%s" % lib_file])
00225                 # for gcc/ld the def-file is specified as any object files
00226                 objects.append(def_file)
00227 
00228         #end: if ((export_symbols is not None) and
00229         #        (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
00230 
00231         # who wants symbols and a many times larger output file
00232         # should explicitly switch the debug mode on
00233         # otherwise we let dllwrap/ld strip the output file
00234         # (On my machine: 10KB < stripped_file < ??100KB
00235         #   unstripped_file = stripped_file + XXX KB
00236         #  ( XXX=254 for a typical python extension))
00237         if not debug:
00238             extra_preargs.append("-s")
00239 
00240         UnixCCompiler.link(self, target_desc, objects, output_filename,
00241                            output_dir, libraries, library_dirs,
00242                            runtime_library_dirs,
00243                            None, # export_symbols, we do this in our def-file
00244                            debug, extra_preargs, extra_postargs, build_temp,
00245                            target_lang)

Here is the call graph for this function:

Here is the caller graph for this function:

def distutils.cygwinccompiler.CygwinCCompiler.object_filenames (   self,
  source_filenames,
  strip_dir = 0,
  output_dir = '' 
) [inherited]
Adds supports for rc and res files.

Definition at line 248 of file cygwinccompiler.py.

00248 
00249     def object_filenames(self, source_filenames, strip_dir=0, output_dir=''):
00250         """Adds supports for rc and res files."""
00251         if output_dir is None:
00252             output_dir = ''
00253         obj_names = []
00254         for src_name in source_filenames:
00255             # use normcase to make sure '.rc' is really '.rc' and not '.RC'
00256             base, ext = os.path.splitext(os.path.normcase(src_name))
00257             if ext not in (self.src_extensions + ['.rc','.res']):
00258                 raise UnknownFileError("unknown file type '%s' (from '%s')" % \
00259                       (ext, src_name))
00260             if strip_dir:
00261                 base = os.path.basename (base)
00262             if ext in ('.res', '.rc'):
00263                 # these need to be compiled to object files
00264                 obj_names.append (os.path.join(output_dir,
00265                                               base + ext + self.obj_extension))
00266             else:
00267                 obj_names.append (os.path.join(output_dir,
00268                                                base + self.obj_extension))
00269         return obj_names
00270 
# the same as cygwin plus some additional parameters
def distutils.unixccompiler.UnixCCompiler.preprocess (   self,
  source,
  output_file = None,
  macros = None,
  include_dirs = None,
  extra_preargs = None,
  extra_postargs = None 
) [inherited]

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

Reimplemented from distutils.cygwinccompiler.CygwinCCompiler.

Definition at line 274 of file cygwinccompiler.py.

Reimplemented from distutils.cygwinccompiler.CygwinCCompiler.

Definition at line 306 of file cygwinccompiler.py.

Definition at line 110 of file cygwinccompiler.py.

Definition at line 137 of file unixccompiler.py.

Reimplemented from distutils.unixccompiler.UnixCCompiler.

Definition at line 94 of file cygwinccompiler.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.

Definition at line 144 of file cygwinccompiler.py.

Definition at line 123 of file cygwinccompiler.py.

Reimplemented from distutils.unixccompiler.UnixCCompiler.

Definition at line 89 of file cygwinccompiler.py.

Reimplemented from distutils.unixccompiler.UnixCCompiler.

Definition at line 91 of file cygwinccompiler.py.

Definition at line 93 of file cygwinccompiler.py.

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

Definition at line 133 of file unixccompiler.py.

Reimplemented from distutils.unixccompiler.UnixCCompiler.

Definition at line 90 of file cygwinccompiler.py.

Reimplemented from distutils.unixccompiler.UnixCCompiler.

Definition at line 92 of file cygwinccompiler.py.


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