PNG  IHDR  8] PLTE S =tRNS   PNG  IHDR  8] PLTE S =tRNS   REDROOM
PHP 7.4.33
Preview: build_clib.py Size: 7.94 KB
/opt/alt/python27/lib64/python2.7/distutils/command/build_clib.py

"""distutils.command.build_clib

Implements the Distutils 'build_clib' command, to build a C/C++ library
that is included in the module distribution and needed by an extension
module."""

__revision__ = "$Id$"


# XXX this module has *lots* of code ripped-off quite transparently from
# build_ext.py -- not surprisingly really, as the work required to build
# a static library from a collection of C source files is not really all
# that different from what's required to build a shared object file from
# a collection of C source files.  Nevertheless, I haven't done the
# necessary refactoring to account for the overlap in code between the
# two modules, mainly because a number of subtle details changed in the
# cut 'n paste.  Sigh.

import os
from distutils.core import Command
from distutils.errors import DistutilsSetupError
from distutils.sysconfig import customize_compiler
from distutils import log

def show_compilers():
    from distutils.ccompiler import show_compilers
    show_compilers()


class build_clib(Command):

    description = "build C/C++ libraries used by Python extensions"

    user_options = [
        ('build-clib=', 'b',
         "directory to build C/C++ libraries to"),
        ('build-temp=', 't',
         "directory to put temporary build by-products"),
        ('debug', 'g',
         "compile with debugging information"),
        ('force', 'f',
         "forcibly build everything (ignore file timestamps)"),
        ('compiler=', 'c',
         "specify the compiler type"),
        ]

    boolean_options = ['debug', 'force']

    help_options = [
        ('help-compiler', None,
         "list available compilers", show_compilers),
        ]

    def initialize_options(self):
        self.build_clib = None
        self.build_temp = None

        # List of libraries to build
        self.libraries = None

        # Compilation options for all libraries
        self.include_dirs = None
        self.define = None
        self.undef = None
        self.debug = None
        self.force = 0
        self.compiler = None


    def finalize_options(self):
        # This might be confusing: both build-clib and build-temp default
        # to build-temp as defined by the "build" command.  This is because
        # I think that C libraries are really just temporary build
        # by-products, at least from the point of view of building Python
        # extensions -- but I want to keep my options open.
        self.set_undefined_options('build',
                                   ('build_temp', 'build_clib'),
                                   ('build_temp', 'build_temp'),
                                   ('compiler', 'compiler'),
                                   ('debug', 'debug'),
                                   ('force', 'force'))

        self.libraries = self.distribution.libraries
        if self.libraries:
            self.check_library_list(self.libraries)

        if self.include_dirs is None:
            self.include_dirs = self.distribution.include_dirs or []
        if isinstance(self.include_dirs, str):
            self.include_dirs = self.include_dirs.split(os.pathsep)

        # XXX same as for build_ext -- what about 'self.define' and
        # 'self.undef' ?

    def run(self):
        if not self.libraries:
            return

        # Yech -- this is cut 'n pasted from build_ext.py!
        from distutils.ccompiler import new_compiler
        self.compiler = new_compiler(compiler=self.compiler,
                                     dry_run=self.dry_run,
                                     force=self.force)
        customize_compiler(self.compiler)

        if self.include_dirs is not None:
            self.compiler.set_include_dirs(self.include_dirs)
        if self.define is not None:
            # 'define' option is a list of (name,value) tuples
            for (name,value) in self.define:
                self.compiler.define_macro(name, value)
        if self.undef is not None:
            for macro in self.undef:
                self.compiler.undefine_macro(macro)

        self.build_libraries(self.libraries)


    def check_library_list(self, libraries):
        """Ensure that the list of libraries is valid.

        `library` is presumably provided as a command option 'libraries'.
        This method checks that it is a list of 2-tuples, where the tuples
        are (library_name, build_info_dict).

        Raise DistutilsSetupError if the structure is invalid anywhere;
        just returns otherwise.
        """
        if not isinstance(libraries, list):
            raise DistutilsSetupError, \
                  "'libraries' option must be a list of tuples"

        for lib in libraries:
            if not isinstance(lib, tuple) and len(lib) != 2:
                raise DistutilsSetupError, \
                      "each element of 'libraries' must a 2-tuple"

            name, build_info = lib

            if not isinstance(name, str):
                raise DistutilsSetupError, \
                      "first element of each tuple in 'libraries' " + \
                      "must be a string (the library name)"
            if '/' in name or (os.sep != '/' and os.sep in name):
                raise DistutilsSetupError, \
                      ("bad library name '%s': " +
                       "may not contain directory separators") % \
                      lib[0]

            if not isinstance(build_info, dict):
                raise DistutilsSetupError, \
                      "second element of each tuple in 'libraries' " + \
                      "must be a dictionary (build info)"

    def get_library_names(self):
        # Assume the library list is valid -- 'check_library_list()' is
        # called from 'finalize_options()', so it should be!
        if not self.libraries:
            return None

        lib_names = []
        for (lib_name, build_info) in self.libraries:
            lib_names.append(lib_name)
        return lib_names


    def get_source_files(self):
        self.check_library_list(self.libraries)
        filenames = []
        for (lib_name, build_info) in self.libraries:
            sources = build_info.get('sources')
            if sources is None or not isinstance(sources, (list, tuple)):
                raise DistutilsSetupError, \
                      ("in 'libraries' option (library '%s'), "
                       "'sources' must be present and must be "
                       "a list of source filenames") % lib_name

            filenames.extend(sources)
        return filenames

    def build_libraries(self, libraries):
        for (lib_name, build_info) in libraries:
            sources = build_info.get('sources')
            if sources is None or not isinstance(sources, (list, tuple)):
                raise DistutilsSetupError, \
                      ("in 'libraries' option (library '%s'), " +
                       "'sources' must be present and must be " +
                       "a list of source filenames") % lib_name
            sources = list(sources)

            log.info("building '%s' library", lib_name)

            # First, compile the source code to object files in the library
            # directory.  (This should probably change to putting object
            # files in a temporary build directory.)
            macros = build_info.get('macros')
            include_dirs = build_info.get('include_dirs')
            objects = self.compiler.compile(sources,
                                            output_dir=self.build_temp,
                                            macros=macros,
                                            include_dirs=include_dirs,
                                            debug=self.debug)

            # Now "link" the object files together into a static library.
            # (On Unix at least, this isn't really linking -- it just
            # builds an archive.  Whatever.)
            self.compiler.create_static_lib(objects, lib_name,
                                            output_dir=self.build_clib,
                                            debug=self.debug)

Directory Contents

Dirs: 0 × Files: 76

Name Size Perms Modified Actions
5.46 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
5.12 KB lrw-r--r-- 2025-12-02 12:55:37
Edit Download
5.12 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
5.07 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
4.93 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
4.93 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
34.37 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
23.62 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
23.51 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
20.56 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
17.31 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
17.23 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
14.65 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
10.60 KB lrw-r--r-- 2025-12-02 12:55:38
Edit Download
10.52 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
5.33 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
5.15 KB lrw-r--r-- 2025-12-02 12:55:12
Edit Download
5.15 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
7.94 KB lrw-r--r-- 2025-01-08 10:54:00
Edit Download
6.33 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
6.33 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
31.74 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
31.51 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
19.13 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
19.13 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
15.96 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
11.49 KB lrw-r--r-- 2025-12-02 12:55:37
Edit Download
11.42 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
4.49 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
4.46 KB lrw-r--r-- 2025-12-02 12:55:37
Edit Download
4.46 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
5.54 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
6.27 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
6.27 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
2.75 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
3.06 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
3.06 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
719 B lrw-r--r-- 2025-01-08 10:54:01
Edit Download
12.82 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
12.64 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
12.64 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
25.65 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
16.73 KB lrw-r--r-- 2025-12-02 12:55:12
Edit Download
16.73 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
2.78 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
3.13 KB lrw-r--r-- 2025-12-02 12:55:38
Edit Download
3.13 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
2.53 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
3.77 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
3.77 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
1.31 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
2.29 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
2.29 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
8.14 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
6.68 KB lrw-r--r-- 2025-12-02 12:55:38
Edit Download
6.68 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
2.02 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
2.95 KB lrw-r--r-- 2025-12-02 12:55:37
Edit Download
2.95 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
11.56 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
10.13 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
10.13 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
18.12 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
16.53 KB lrw-r--r-- 2025-12-02 12:55:37
Edit Download
16.53 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
6.84 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
6.24 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
6.24 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
60.00 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
64.00 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
60.00 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
218.50 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
191.50 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
822 B lrw-r--r-- 2025-01-08 10:54:01
Edit Download
678 B lrw-r--r-- 2025-12-02 12:55:12
Edit Download
678 B lrw-r--r-- 2025-01-08 10:54:01
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).
 !"#$%&'(()*+,-./00123456789 t\ wIDATx ]ys  47Y ƒ -  "  Rv  < f{Ɛ $k l L > L  ~h^ 1  [  r G t& h  l F z3O Y ! p A(_g̷ E8 )S 8 c  Kb"z ~ 5 J xAL WU <  *  5 m;W a pB h ~P J 2 3 6 ҙ .Ƹ P i  4g F R L P ΪK/D  M v (a3 k J Œ4N5* SH ` SdJ z  O J Xՠ V>u ߱ BE&L b2 ?2` tX+  c CB A$ i b C ĀMB E : /  # Dx &l =q Ty  0 \p I ( L Ǎ { e 4k ;`u^ヲ eP!( d {  )T A 8 O;Ě n >;s6 !  :Nx `[S D HU ~ q›J F} a g*D 49 / pn k h (t 8NxƐF _!r չ7 ZR R׷ q/5") Ӎ NY 0 x sZ!   o  fu  ,  K"$ ? pg  㕣=  1» {h " fh7    y  } € +7  $ y " X —ą - G P u 4 m >J 5 L =V ' ^@I p ?MS xЌ XV P ! h "C NS9B8̢ ]!K  e   zA , ӏkbY  !< XQ ٿyS| *" f { w  4@[S <  # 0 ! js [m  =,~ o "ݎ DHf Wo $ g ! Vԅ t mB /y Wf V4񺍸 c+@x?  B ~u " xUN e 0 BĂ) ~J pz! 7y6]l Ԥ@ P a< O /DHC `≻  N m"$  0ObB }{ x AO FCG D R ^ "B  { WDH  UR l@ T #  +"d T ; 0 i  D}. 7 ` ' ] w rE &S i ƕiTD EL P _ u h $ Ա FG wVD G L R Zf ' .!] J /ZR oGЍs Mr Ĥ ʬ 3 Q [3 cL ` ^ p + ( F;# B 5 '  2Y f [  ϶R0e }  E 7 6M aۮ H <& n % L] E}Up x紉, Uw' Q  Ǯշo k ވۙ 0N94 VX5 xEDE l D #֤ } C o )W :  ^ s 9  bRf iX5u ཱི 4 :[  T 1. | [E 2ؽ Iy\ : o x K G 5 ylP ' uK E ftb/i[3 .g _  [3M n G, #NwQ5~  ؚ) | n =Ц"x qg gB ` 듘 ~ x w ? ? R~  _ u. &VQ K˻   H C ( TN˄+ `C dA nB׭ D 3"Z G ê ^k H_ /- ~ " R_  .8 Z_ 6@ o  xg  uP ? 3լ @7AM!  E7^ - =V L  x  g-D0  CtmW 7  O  G _ WD0 g C  w1 r d w : a | \  *" f nֳ ^ H# f L ` Z ۽hV  }S F r0Ù Bć5r] @! NL iQ]{s^=4 d  WD  "  "   M; t" 8 5 e dL| "-*st" ) SWD ?R[S e ooF  20.D ? bo =) A i o d ģ ZҰaO @E =) i D a &ܟa CϞ y6 ,<%{^x%{f8? `iw^ ?/ M * IEND B`