Пример #1
0
    def build_extensions(self):
        numpy_incl = pkg_resources.resource_filename('numpy', 'core/include')

        for ext in self.extensions:
            if hasattr(ext, 'include_dirs') and not numpy_incl in ext.include_dirs:
                ext.include_dirs.append(numpy_incl)
        _build_ext.build_extensions(self)
Пример #2
0
    def build_extensions(self):
        # Detect which modules should be compiled
        self.detect_modules()

        # Tweak compiler options
        if self.compiler.compiler_type in ('unix', 'cygwin', 'mingw32'):
            # Tell GCC to compile using the C99 standard.
            self.__add_compiler_option("-std=c99")

            # Make assert() statements always work
            self.__remove_compiler_option("-DNDEBUG")

            # Choose our own optimization options
            for opt in ["-O", "-O0", "-O1", "-O2", "-O3", "-Os"]:
                self.__remove_compiler_option(opt)
            if self.debug:
                # Basic optimization is still needed when debugging to compile
                # the libtomcrypt code.
                self.__add_compiler_option("-O")
            else:
                # Speed up execution by tweaking compiler options.  This
                # especially helps the DES modules.
                self.__add_compiler_option("-O3")
                self.__add_compiler_option("-fomit-frame-pointer")
                # Don't include debug symbols unless debugging
                self.__remove_compiler_option("-g")
                # Don't include profiling information (incompatible with -fomit-frame-pointer)
                self.__remove_compiler_option("-pg")
            if USE_GCOV:
                self.__add_compiler_option("-fprofile-arcs")
                self.__add_compiler_option("-ftest-coverage")
                self.compiler.libraries += ['gcov']

        # Call the superclass's build_extensions method
        build_ext.build_extensions(self)
Пример #3
0
Файл: setup.py Проект: ion1/OIL
 def build_extensions(self):
     c = self.compiler.compiler_type
     if c == "msvc":
         # customize the build options for this compilier
         for e in self.extensions:
             e.extra_link_args.append("/MANIFEST")
     if c == "unix":
         # customize the build options for this compilier
         for e in self.extensions:
             e.extra_compile_args.append("-ffast-math")
             e.extra_compile_args.append("-O2")
             e.extra_compile_args.append("-Wdeclaration-after-statement")
             e.extra_compile_args.append("-Wall")
             e.extra_compile_args.append("-Werror")
     
     for e in self.extensions:
         if self.with_sse:
             e.define_macros.append(("ENABLE_CPU_SSE_BACKEND", None))
         if self.with_opengl:
             e.define_macros.append(("ENABLE_OPENGL_BACKEND", None))
             e.libraries.append("X11")
             e.libraries.append("GL")
             e.libraries.append("GLEW")
     
     # build in place, and in the build/ tree
     self.inplace = False
     build_ext.build_extensions(self)
     self.inplace = True
     build_ext.build_extensions(self)
Пример #4
0
 def build_extensions(self):
     if self.compiler.compiler_type == 'mingw32':
         # Dirty hack to avoid linking with more than one C runtime when using MinGW
         # Note that this hack forces the compilation to use the old MSVCT
         self.compiler.dll_libraries = [lib for lib in self.compiler.dll_libraries if not lib.startswith('msvcr')]
     self.force = self.libuv_force_fetch or self.libuv_clean_compile
     if self.compiler.compiler_type == 'msvc':
         self.libuv_lib = os.path.join(self.libuv_dir, 'Release', 'lib', 'libuv.lib')
     else:
         self.libuv_lib = os.path.join(self.libuv_dir, 'libuv.a')
     self.get_libuv()
     # Set compiler options
     if self.compiler.compiler_type == 'mingw32':
         self.compiler.add_library_dir(self.libuv_dir)
         self.compiler.add_library('uv')
     else:
         self.extensions[0].extra_objects.extend([self.libuv_lib])
     self.compiler.add_include_dir(os.path.join(self.libuv_dir, 'include'))
     if sys.platform.startswith('linux'):
         self.compiler.add_library('rt')
     elif sys.platform == 'darwin':
         self.extensions[0].extra_link_args.extend(['-framework', 'CoreServices'])
     elif sys.platform == 'win32':
         if self.compiler.compiler_type == 'msvc':
             self.extensions[0].extra_link_args.extend(['/NODEFAULTLIB:libcmt', '/LTCG'])
             self.compiler.add_library('advapi32')
         self.compiler.add_library('iphlpapi')
         self.compiler.add_library('psapi')
         self.compiler.add_library('ws2_32')
     build_ext.build_extensions(self)
Пример #5
0
 def build_extensions(self):
     self.compiler.define_macro('HAVE_CONFIG_H', 1)
     self.compiler.add_include_dir(os.path.join(self.cares_dir, 'src'))
     if sys.platform != 'win32':
         self.compiler.define_macro('_LARGEFILE_SOURCE', 1)
         self.compiler.define_macro('_FILE_OFFSET_BITS', 64)
     if sys.platform.startswith('linux'):
         self.compiler.add_include_dir(os.path.join(self.cares_dir, 'src/config_linux'))
         self.compiler.add_library('dl')
         self.compiler.add_library('rt')
     elif sys.platform == 'darwin':
         self.compiler.add_include_dir(os.path.join(self.cares_dir, 'src/config_darwin'))
         self.compiler.define_macro('_DARWIN_USE_64_BIT_INODE', 1)
     elif sys.platform.startswith('freebsd'):
         self.compiler.add_include_dir(os.path.join(self.cares_dir, 'src/config_freebsd'))
         self.compiler.add_library('kvm')
     elif sys.platform.startswith('dragonfly'):
         self.compiler.add_include_dir(os.path.join(self.cares_dir, 'src/config_freebsd'))
     elif sys.platform.startswith('netbsd'):
         self.compiler.add_include_dir(os.path.join(self.cares_dir, 'src/config_netbsd'))
     elif sys.platform.startswith('openbsd'):
         self.compiler.add_include_dir(os.path.join(self.cares_dir, 'src/config_openbsd'))
     elif sys.platform.startswith('sunos'):
         self.compiler.add_library('socket')
         self.compiler.add_library('nsl')
         self.compiler.add_library('lkstat')
     elif sys.platform == 'win32':
         self.compiler.add_include_dir(os.path.join(self.cares_dir, 'src/config_win32'))
         self.extensions[0].extra_link_args = ['/NODEFAULTLIB:libcmt']
         self.compiler.add_library('advapi32')
         self.compiler.add_library('iphlpapi')
         self.compiler.add_library('psapi')
         self.compiler.add_library('ws2_32')
     self.extensions[0].sources += cares_sources
     build_ext.build_extensions(self)
Пример #6
0
    def build_extensions(self):

        # if builing from c files, don't need to
        # generate template output
        if cython:
            for pxifile in _pxifiles:
                # build pxifiles first, template extension must be .pxi.in
                assert pxifile.endswith('.pxi.in')
                outfile = pxifile[:-3]

                if (os.path.exists(outfile) and
                        os.stat(pxifile).st_mtime < os.stat(outfile).st_mtime):
                    # if .pxi.in is not updated, no need to output .pxi
                    continue

                with open(pxifile, "r") as f:
                    tmpl = f.read()
                pyxcontent = tempita.sub(tmpl)

                with open(outfile, "w") as f:
                    f.write(pyxcontent)

        numpy_incl = pkg_resources.resource_filename('numpy', 'core/include')

        for ext in self.extensions:
            if (hasattr(ext, 'include_dirs') and
                    numpy_incl not in ext.include_dirs):
                ext.include_dirs.append(numpy_incl)
        _build_ext.build_extensions(self)
Пример #7
0
    def build_extensions(self):

        # Add a -std=c++11 or similar flag if needed
        ct = self.compiler.compiler_type
        if ct == 'unix' and not supports_cxx11(self.compiler):
            cxx11_flag = None
            if supports_cxx11(self.compiler, '-std=c++11'):
                cxx11_flag = '-std=c++11'
            if cxx11_flag:
                for ext in self.extensions:
                    # gdalconst builds as a .c file
                    if ext.name != 'osgeo._gdalconst':
                        ext.extra_compile_args += [cxx11_flag]

        # Adding arch flags here if OS X and compiler is clang
        if sys.platform == 'darwin' and [int(x) for x in os.uname()[2].split('.')] >= [11, 0, 0]:
            # since MacOS X 10.9, clang no longer accepts -mno-fused-madd
            # extra_compile_args.append('-Qunused-arguments')
            clang_flag = '-Wno-error=unused-command-line-argument-hard-error-in-future'
            if has_flag(self.compiler, clang_flag): 
                ext.extra_compile_args += [clang_flag]
            else:
                clang_flag = '-Wno-error=unused-command-line-argument'
                if has_flag(self.compiler, clang_flag):
                    ext.extra_compile_args += [clang_flag]

        build_ext.build_extensions(self)
Пример #8
0
    def build_extensions(self):
        if newer("src/docstrings.h.in", "src/docstrings.h"):
            updateDocHeader("src/docstrings.h.in", "src/docstrings.h")

        for ext in self.extensions:
            ext.include_dirs.append(self.boost_include_dir)
            ext.include_dirs.append(self.timbl_include_dir)
            ext.include_dirs.append(self.libxml2_include_dir)
            ext.library_dirs.append(self.timbl_library_dir)
            ext.library_dirs.append(self.boost_library_dir)
            ext.library_dirs.append(self.libxml2_library_dir)


            compile_args = ["-std=c++11"]
            if platform.system() == "Darwin":
                compile_args.append("-stdlib=libc++")
            ext.extra_compile_args.extend(compile_args)
            if isinstance(self.compiler, UnixCCompiler) and self.static_boost_python:
                ext.extra_link_args.extend(
                    "-Wl,-Bstatic -l" + self.boostlib + " -Wl,-Bdynamic".split())
            else:
                ext.libraries.append(self.boostlib)


        build_ext.build_extensions(self)
Пример #9
0
    def build_extensions(self):

        for _pxifile in _pxifiles:
            # build pxifiles first, template extention must be .pxi.in
            assert _pxifile.endswith(".pxi.in")
            pxifile = pjoin(_pxipath, _pxifile)
            outfile = pxifile[:-3]

            if os.path.exists(outfile) and os.stat(pxifile).st_mtime < os.stat(outfile).st_mtime:
                # if .pxi.in is not updated, no need to output .pxi
                continue

            with open(pxifile, "r") as f:
                tmpl = f.read()
            pyxcontent = tempita.sub(tmpl)

            with open(outfile, "w") as f:
                f.write(pyxcontent)

        numpy_incl = pkg_resources.resource_filename("numpy", "core/include")

        for ext in self.extensions:
            if hasattr(ext, "include_dirs") and not numpy_incl in ext.include_dirs:
                ext.include_dirs.append(numpy_incl)
        _build_ext.build_extensions(self)
Пример #10
0
    def build_extensions(self):
        # python2.2 doesn't honor these, so we have to sneak them in
        cxx = os.environ.get("CXX")
        cc = os.environ.get("CC")

        print "compiling with", cc
        if cc:
            self.compiler.preprocessor[0] = cc
            self.compiler.compiler_so[0] = cc
            self.compiler.compiler[0] = cc
        
            if cc.find("33") > -1:
                print "cc is old"
                # rpm thinks we should have -mtune, but older gcc doesn't like it
                cflags = os.environ.get("CFLAGS")
                if cflags != None:
                    cflags = remove_mtune.sub("",cflags)
                    print "cflags", cflags
                    os.environ["CFLAGS"] = cflags

                self.compiler.compiler = [
                    opt for opt in self.compiler.compiler \
                        if opt.find("-mtune") == -1 ]

                self.compiler.compiler_so = [
                    opt for opt in self.compiler.compiler_so \
                        if opt.find("-mtune") == -1 ]

        if cxx:
            if hasattr(self.compiler, "compiler_cxx"):
                self.compiler.compiler_cxx[0] = cxx
            self.compiler.linker_so[0] = cxx

        build_ext.build_extensions(self)
Пример #11
0
    def build_extensions(self):
        # Get 64-bitness
        c = self.compiler.compiler_type
        print "Compiling with %s (64bit=%s)" % (c, str(is_64bits))
        
        # OpenMP build options
        if enable_openmp:
            if copt.has_key(c):
                for e in self.extensions:
                    e.extra_compile_args = copt[ c ]
            if lopt.has_key(c):
                for e in self.extensions:
                    e.extra_link_args = lopt[ c ]
                    
        # Platform-specific build options
        if platform_lopt.has_key(c):
            for e in self.extensions:
                e.extra_link_args = platform_lopt[ c ]

        if platform_copt.has_key(c):
            for e in self.extensions:
                e.extra_compile_args = platform_copt[ c ]


        build_ext.build_extensions(self)
Пример #12
0
    def build_extensions(self):
        global library_dirs, include_dirs, libraries

        if WINDOWS:
            # Detect the compiler so we can specify the correct command line switches
            # and libraries
            from distutils.cygwinccompiler import Mingw32CCompiler
            extra_cc_args = []
            if isinstance(self.compiler, Mingw32CCompiler):
                # Compiler is Mingw32
                freetds_dir = 'ming'
                extra_cc_args = [
                    '-Wl,-allow-multiple-definition',
                    '-Wl,-subsystem,windows-mthreads',
                    '-mwindows',
                    '-Wl,--strip-all'
                ]
                libraries = [
                    'libiconv', 'iconv',
                    'sybdb',
                    'ws2_32', 'wsock32', 'kernel32',
                ]
            else:
                # Assume compiler is Visual Studio
                if sys.version_info >= (3, 5):
                    freetds_dir = 'vs2015'
                elif sys.version_info >= (3, 3):
                    freetds_dir = 'vs2010'
                else:
                    freetds_dir = 'vs2008'
                # XXX: Decide and implement if we are going to allow linking in
                # FreeTDS statically
                if True:
                    libraries = [
                        'ct', 'sybdb',
                        'ws2_32', 'wsock32', 'kernel32', 'shell32',
                        'libeay32MD', 'ssleay32MD',
                    ]
                else:
                    libraries = [
                        'db-lib', 'tds',
                        'ws2_32', 'wsock32', 'kernel32', 'shell32',
                        'libeay{}MD'.format(BITNESS),
                        'ssleay{}MD'.format(BITNESS),
                    ]

            FREETDS = fpath('freetds', '{0}_{1}'.format(freetds_dir, BITNESS))
            suffix = '' if BITNESS == 32 else '64'
            OPENSSL = fpath('openssl', 'lib{}'.format(suffix))
            for e in self.extensions:
                e.extra_compile_args.extend(extra_cc_args)
                e.libraries.extend(libraries)
                e.include_dirs.append(osp.join(FREETDS, 'include'))
                e.library_dirs.append(osp.join(FREETDS, 'lib'))
                e.library_dirs.append(OPENSSL)

        else:
            for e in self.extensions:
                e.libraries.extend(libraries)
        _build_ext.build_extensions(self)
Пример #13
0
 def build_extensions(self):
     # Init self.extra_compile_args
     self.init_extra_compile_args()
     # Modify default compiler settings
     self.modify_compiler()
     # Invoke base build_extensions()
     build_ext.build_extensions(self)
Пример #14
0
    def build_extensions(self):
        numpy_incl = pkg_resources.resource_filename("numpy", "core/include")

        for ext in self.extensions:
            if hasattr(ext, "include_dirs") and not numpy_incl in ext.include_dirs:
                ext.include_dirs.append(numpy_incl)
        _build_ext.build_extensions(self)
Пример #15
0
 def build_extensions(self):
     if self.compiler.compiler_type == "mingw32":
         # Dirty hack to avoid linking with more than one C runtime when using MinGW
         self.compiler.dll_libraries = [lib for lib in self.compiler.dll_libraries if not lib.startswith("msvcr")]
     self.force = self.libuv_force_fetch or self.libuv_clean_compile
     self.get_libuv()
     build_ext.build_extensions(self)
Пример #16
0
 def build_extensions(self):
     if self.compiler.compiler_type == 'mingw32':
         # Dirty hack to avoid linking with more than one C runtime when using MinGW
         self.compiler.dll_libraries = [lib for lib in self.compiler.dll_libraries if not lib.startswith('msvcr')]
     self.force = self.cares_clean_compile
     if self.compiler.compiler_type == 'msvc':
         self.cares_lib = os.path.join(self.cares_dir, 'cares.lib')
     else:
         self.cares_lib = os.path.join(self.cares_dir, 'libcares.a')
     self.build_cares()
     # Set compiler options
     if self.compiler.compiler_type == 'mingw32':
         self.compiler.add_library_dir(self.cares_dir)
         self.compiler.add_library('cares')
     self.extensions[0].extra_objects = [self.cares_lib]
     self.compiler.add_include_dir(os.path.join(self.cares_dir, 'src'))
     if sys.platform.startswith('linux'):
         self.compiler.add_library('rt')
     elif sys.platform == 'win32':
         if self.compiler.compiler_type == 'msvc':
             self.extensions[0].extra_link_args = ['/NODEFAULTLIB:libcmt']
             self.compiler.add_library('advapi32')
         self.compiler.add_library('iphlpapi')
         self.compiler.add_library('psapi')
         self.compiler.add_library('ws2_32')
     build_ext.build_extensions(self)
Пример #17
0
    def build_extensions(self):
        import tempfile

        flags = try_to_add_compile_args()

        f = tempfile.NamedTemporaryFile(suffix=".cpp", delete=True)
        f.name
        c = self.compiler

        ok_flags = []

        with stdout_redirected(), merged_stderr_stdout():
            for flag in flags:
                try:
                    c.compile([f.name], extra_postargs=ok_flags + [flag])
                except CompileError:
                    pass
                else:
                    ok_flags.append(flag)

        for ext in self.extensions:
            ext.extra_compile_args += ok_flags

        f.close()
        build_ext.build_extensions(self)
Пример #18
0
    def build_extensions(self):
        if newer("src/docstrings.h.in", "src/docstrings.h"):
            updateDocHeader("src/docstrings.h.in", "src/docstrings.h")

        for ext in self.extensions:
            ext.include_dirs.append(self.boost_include_dir)
            ext.include_dirs.append(self.timbl_include_dir)
            ext.include_dirs.append(self.libxml2_include_dir)
            ext.library_dirs.append(self.timbl_library_dir)
            ext.library_dirs.append(self.boost_library_dir)
            ext.library_dirs.append(self.libxml2_library_dir)

            pyversion = sys.version[0:3][0] + sys.version[0:3][2]  # returns something like 32
            if os.path.exists(self.boost_library_dir + "/libboost_python-py" + pyversion + ".so"):
                boostlib = "boost_python-py" + pyversion
            elif os.path.exists(self.boost_library_dir + "/libboost_python3.so"):
                boostlib = "boost_python3"
            elif os.path.exists(self.boost_library_dir + "/libboost_python.so"):
                # probably goes wrong if this is for python 2!
                boostlib = "boost_python"
            elif os.path.exists(self.boost_library_dir + "/libboost_python3.dylib"):  # Mac OS X
                boostlib = "boost_python3"
            elif os.path.exists(self.boost_library_dir + "/libboost_python.dylib"):  # Mac OS X
                # probably goes wrong if this is for python 2!
                boostlib = "boost_python"
            else:
                print("Unable to find boost library", file=sys.stderr)
                sys.exit(65)

            if isinstance(self.compiler, UnixCCompiler) and self.static_boost_python:
                ext.extra_link_args.extend("-Wl,-Bstatic -l" + boostlib + " -Wl,-Bdynamic".split())
            else:
                ext.libraries.append(boostlib)

        build_ext.build_extensions(self)
Пример #19
0
 def build_extensions(self):
     if self.compiler.compiler_type == 'mingw32':
         # Dirty hack to avoid linking with more than one C runtime when using MinGW
         self.compiler.dll_libraries = [lib for lib in self.compiler.dll_libraries if not lib.startswith('msvcr')]
     self.force = self.cares_clean_compile
     self.build_cares()
     build_ext.build_extensions(self)
Пример #20
0
    def build_extensions(self):
        # Detect which modules should be compiled
        self.detect_modules()

        # Tweak compiler options
        if self.compiler.compiler_type in ("unix", "cygwin", "mingw32"):
            # Make assert() statements always work
            self.__remove_compiler_option("-DNDEBUG")

            if USE_GCOV:  # TODO - move this to configure.ac
                self.__add_compiler_option("-fprofile-arcs")
                self.__add_compiler_option("-ftest-coverage")
                self.compiler.libraries += ["gcov"]

            # Python 2.1 and 2.2 don't respect the LDFLAGS environment variable.  Hack it.
            if sys.version_info < (2, 3, "final", 0):
                if os.environ.get("LDFLAGS"):  # Set from ./buildenv (ultimately provided by autoconf)
                    for opt in os.environ["LDFLAGS"].split(" "):
                        opt = opt.strip()
                        if not opt:
                            continue
                        self.compiler.linker_so.append(opt)

        # Call the superclass's build_extensions method
        build_ext.build_extensions(self)
Пример #21
0
    def build_extensions(self):
        c = self.compiler.compiler_type
        if c == "msvc":
            # customize the build options for this compilier
            for e in self.extensions:
                e.extra_link_args.append("/MANIFEST")

        build_ext.build_extensions(self)
Пример #22
0
    def build_extensions(self):
        if build_concurrency > 1:
            self.check_extensions_list(self.extensions)

            import multiprocessing.pool
            multiprocessing.pool.ThreadPool(processes=build_concurrency).map(self.build_extension, self.extensions)
        else:
            build_ext.build_extensions(self)
Пример #23
0
  def build_extensions(self):
    customize_compiler(self.compiler)
    customize_linker(self.compiler)

    os.system('swig {0} -o '.format(str.join(' ', config.swig_flags)) + \
                'rksolver/rksolver_wrap.cpp rksolver/rksolver.i')

    build_ext.build_extensions(self)
Пример #24
0
 def build_extensions(self):
     for e in self.extensions:
         e.extra_compile_args = compile_options.get(
             self.compiler.compiler_type, compile_options['other'])
     for e in self.extensions:
         e.extra_link_args = link_options.get(
             self.compiler.compiler_type, link_options['other'])
     build_ext.build_extensions(self)
Пример #25
0
 def build_extensions(self):
     
     CC = sysconfig.get_config_var("CC")
     
     if self.compiler.compiler_type == 'unix' and ( 'gcc' in CC or 'g++' in CC):
         for e in self.extensions:
             e.extra_compile_args.append( '-Wno-strict-prototypes' )
             
     build_ext.build_extensions(self)
Пример #26
0
 def build_extensions(self):
     c = self.compiler.compiler_type
     if copt.has_key(c):
         for e in self.extensions:
             e.extra_compile_args = copt[ c ]
     if lopt.has_key(c):
          for e in self.extensions:
              e.extra_link_args = lopt[ c ]
     build_ext.build_extensions(self)
Пример #27
0
    def build_extensions(self):
        # Disable any assembly in libtomcrypt files
        self.compiler.define_macro("LTC_NO_ASM")

        # Detect which modules should be compiled
        self.detect_modules()

        # Call the superclass's build_extensions method
        build_ext.build_extensions(self)
Пример #28
0
 def build_extensions(self):
     c = self.compiler.compiler_type
     if c in platform_cflags.keys():
         for e in self.extensions:
             e.extra_compile_args = platform_cflags[c]
     if c in platform_ldflags.keys():
         for e in self.extensions:
             e.extra_link_args = platform_ldflags[c]
     build_ext.build_extensions(self)
Пример #29
0
 def build_extensions(self):
     c = self.compiler.compiler_type
     if c in copt:
         for e in self.extensions:
             e.extra_compile_args = copt[c]
     if c in lopt:
         for e in self.extensions:
             e.extra_link_args = lopt[c]
     build_ext.build_extensions(self)
Пример #30
0
        def build_extensions(self):
            cc = self.compiler.compiler_type

            if cc == 'mingw32':
                for e in self.extensions:
                    # e.extra_compile_args = []
                    e.extra_link_args = ['-static-libgcc', '-static-libstdc++']

            build_ext.build_extensions(self)
Пример #31
0
    def build_extensions(self):
        if not self.use_system_fitsio:

            # Use the compiler for building python to build cfitsio
            # for maximized compatibility.

            # there is some issue with non-aligned data with optimizations
            # set to '-O3' on some versions of gcc.  It appears to be
            # a disagreement between gcc 4 and gcc 5

            CCold = self.compiler.compiler

            CC = []
            for val in CCold:
                if val == '-O3':
                    print("replacing '-O3' with '-O2' to address " "gcc bug")
                    val = '-O2'
                CC.append(val)

            self.configure_cfitsio(
                CC=CC,
                ARCHIVE=self.compiler.archiver,
                RANLIB=self.compiler.ranlib,
            )

            # If configure detected bzlib.h, we have to link to libbz2

            if '-DHAVE_BZIP2=1' in open(
                    os.path.join(self.cfitsio_build_dir, 'Makefile')).read():
                self.compiler.add_library('bz2')

            if '-DCFITSIO_HAVE_CURL=1' in open(
                    os.path.join(self.cfitsio_build_dir, 'Makefile')).read():
                self.compiler.add_library('curl')

            self.compile_cfitsio()

            # link against the .a library in cfitsio;
            # It should have been a 'static' library of relocatable objects (-fPIC),
            # since we use the python compiler flags

            link_objects = glob.glob(
                os.path.join(self.cfitsio_build_dir, '*.a'))

            self.compiler.set_link_objects(link_objects)

            # Ultimate hack: append the .a files to the dependency list
            # so they will be properly rebuild if cfitsio source is updated.
            for ext in self.extensions:
                ext.depends += link_objects
        else:
            self.compiler.add_library('cfitsio')

            # Check if system cfitsio was compiled with bzip2 and/or curl
            if self.check_system_cfitsio_objects('bzip2'):
                self.compiler.add_library('bz2')
            if self.check_system_cfitsio_objects('curl_'):
                self.compiler.add_library('curl')

        # fitsio requires libm as well.
        self.compiler.add_library('m')

        # call the original build_extensions

        build_ext.build_extensions(self)
Пример #32
0
    def build_extensions(self):

        global TCL_ROOT

        library_dirs = []
        include_dirs = []

        add_directory(include_dirs, "libImaging")

        #
        # add platform directories

        if sys.platform == "cygwin":
            # pythonX.Y.dll.a is in the /usr/lib/pythonX.Y/config directory
            add_directory(
                library_dirs,
                os.path.join("/usr/lib", "python%s" % sys.version[:3],
                             "config"))

        elif sys.platform == "darwin":
            # attempt to make sure we pick freetype2 over other versions
            add_directory(include_dirs, "/sw/include/freetype2")
            add_directory(include_dirs, "/sw/lib/freetype2/include")
            # fink installation directories
            add_directory(library_dirs, "/sw/lib")
            add_directory(include_dirs, "/sw/include")
            # darwin ports installation directories
            add_directory(library_dirs, "/opt/local/lib")
            add_directory(include_dirs, "/opt/local/include")

        add_directory(library_dirs, "/usr/local/lib")
        # FIXME: check /opt/stuff directories here?

        prefix = sysconfig.get_config_var("prefix")
        if prefix:
            add_directory(library_dirs, os.path.join(prefix, "lib"))
            add_directory(include_dirs, os.path.join(prefix, "include"))

        #
        # locate tkinter libraries

        if _tkinter:
            TCL_VERSION = _tkinter.TCL_VERSION[:3]

        if _tkinter and not TCL_ROOT:
            # we have Tkinter but the TCL_ROOT variable was not set;
            # try to locate appropriate Tcl/Tk libraries
            PYVERSION = sys.version[0] + sys.version[2]
            TCLVERSION = TCL_VERSION[0] + TCL_VERSION[2]
            roots = [
                # common installation directories, mostly for Windows
                # (for Unix-style platforms, we'll check in well-known
                # locations later)
                os.path.join("/py" + PYVERSION, "Tcl"),
                os.path.join("/python" + PYVERSION, "Tcl"),
                "/Tcl",
                "/Tcl" + TCLVERSION,
                "/Tcl" + TCL_VERSION,
                os.path.join(os.environ.get("ProgramFiles", ""), "Tcl"),
            ]
            for TCL_ROOT in roots:
                TCL_ROOT = os.path.abspath(TCL_ROOT)
                if os.path.isfile(os.path.join(TCL_ROOT, "include", "tk.h")):
                    # FIXME: use distutils logging (?)
                    print "--- using Tcl/Tk libraries at", TCL_ROOT
                    print "--- using Tcl/Tk version", TCL_VERSION
                    TCL_ROOT = libinclude(TCL_ROOT)
                    break
            else:
                TCL_ROOT = None

        #
        # add configured kits

        for root in [FREETYPE_ROOT, JPEG_ROOT, TCL_ROOT, TIFF_ROOT, ZLIB_ROOT]:
            if isinstance(root, type(())):
                lib_root, include_root = root
            else:
                lib_root = include_root = root
            add_directory(library_dirs, lib_root)
            add_directory(include_dirs, include_root)

        #
        # add standard directories

        add_directory(library_dirs, "/usr/local/lib")
        add_directory(include_dirs, "/usr/local/include")

        add_directory(library_dirs, "/usr/lib")
        add_directory(include_dirs, "/usr/include")

        #
        # insert new dirs *before* default libs, to avoid conflicts
        # between Python PYD stub libs and real libraries

        self.compiler.library_dirs = library_dirs + self.compiler.library_dirs
        self.compiler.include_dirs = include_dirs + self.compiler.include_dirs

        #
        # look for available libraries

        class feature:
            zlib = jpeg = tiff = freetype = tcl = tk = None

        feature = feature()

        if find_library_file(self, "z"):
            feature.zlib = "z"
        elif sys.platform == "win32" and find_library_file(self, "zlib"):
            feature.zlib = "zlib"  # alternative name

        if find_library_file(self, "jpeg"):
            feature.jpeg = "jpeg"
        elif sys.platform == "win32" and find_library_file(self, "libjpeg"):
            feature.jpeg = "libjpeg"  # alternative name

        if find_library_file(self, "tiff"):
            feature.tiff = "tiff"

        if find_library_file(self, "freetype"):
            # look for freetype2 include files
            freetype_version = 0
            for dir in self.compiler.include_dirs:
                if os.path.isfile(os.path.join(dir, "ft2build.h")):
                    freetype_version = 21
                    dir = os.path.join(dir, "freetype2")
                    break
                dir = os.path.join(dir, "freetype2")
                if os.path.isfile(os.path.join(dir, "ft2build.h")):
                    freetype_version = 21
                    break
                if os.path.isdir(os.path.join(dir, "freetype")):
                    freetype_version = 20
                    break
            if freetype_version:
                feature.freetype = "freetype"
                feature.freetype_version = freetype_version
                if dir:
                    add_directory(self.compiler.include_dirs, dir, 0)

        if _tkinter:
            # the library names may vary somewhat (e.g. tcl84 or tcl8.4)
            version = TCL_VERSION[0] + TCL_VERSION[2]
            if find_library_file(self, "tcl" + version):
                feature.tcl = "tcl" + version
            elif find_library_file(self, "tcl" + TCL_VERSION):
                feature.tcl = "tcl" + TCL_VERSION
            if find_library_file(self, "tk" + version):
                feature.tk = "tk" + version
            elif find_library_file(self, "tk" + TCL_VERSION):
                feature.tk = "tk" + TCL_VERSION

        #
        # core library

        files = ["_imaging.c"]
        for file in IMAGING:
            files.append(file + ".c")
        for file in LIBIMAGING:
            files.append(os.path.join("libImaging", file + ".c"))

        libs = []
        defs = []
        if feature.jpeg:
            libs.append(feature.jpeg)
            defs.append(("HAVE_LIBJPEG", None))
        if feature.zlib:
            libs.append(feature.zlib)
            defs.append(("HAVE_LIBZ", None))
        if sys.platform == "win32":
            libs.extend(["kernel32", "user32", "gdi32"])
        if struct.unpack("h", "\0\1")[0] == 1:
            defs.append(("WORDS_BIGENDIAN", None))

        exts = [(Extension("_imaging",
                           files,
                           libraries=libs,
                           define_macros=defs))]

        #
        # additional libraries

        if feature.freetype:
            defs = []
            if feature.freetype_version == 20:
                defs.append(("USE_FREETYPE_2_0", None))
            exts.append(
                Extension("_imagingft", ["_imagingft.c"],
                          libraries=["freetype"],
                          define_macros=defs))

        if os.path.isfile("_imagingtiff.c") and feature.tiff:
            exts.append(
                Extension("_imagingtiff", ["_imagingtiff.c"],
                          libraries=["tiff"]))

        if sys.platform == "darwin":
            # locate Tcl/Tk frameworks
            frameworks = []
            framework_roots = [
                "/Library/Frameworks", "/System/Library/Frameworks"
            ]
            for root in framework_roots:
                if (os.path.exists(os.path.join(root, "Tcl.framework")) and
                        os.path.exists(os.path.join(root, "Tk.framework"))):
                    print "--- using frameworks at", root
                    frameworks = ["-framework", "Tcl", "-framework", "Tk"]
                    dir = os.path.join(root, "Tcl.framework", "Headers")
                    add_directory(self.compiler.include_dirs, dir, 0)
                    dir = os.path.join(root, "Tk.framework", "Headers")
                    add_directory(self.compiler.include_dirs, dir, 1)
                    break
            if frameworks:
                exts.append(
                    Extension("_imagingtk", ["_imagingtk.c", "Tk/tkImaging.c"],
                              extra_compile_args=frameworks,
                              extra_link_args=frameworks))
                feature.tcl = feature.tk = 1  # mark as present
        elif feature.tcl and feature.tk:
            exts.append(
                Extension("_imagingtk", ["_imagingtk.c", "Tk/tkImaging.c"],
                          libraries=[feature.tcl, feature.tk]))

        if os.path.isfile("_imagingmath.c"):
            exts.append(Extension("_imagingmath", ["_imagingmath.c"]))

        self.extensions[:] = exts

        build_ext.build_extensions(self)

        #
        # sanity and security checks

        unsafe_zlib = None

        if feature.zlib:
            unsafe_zlib = self.check_zlib_version(self.compiler.include_dirs)

        self.summary_report(feature, unsafe_zlib)
Пример #33
0
    def build_extensions(self):

        # Detect which modules should be compiled
        self.detect_modules()

        # Remove modules that are present on the disabled list
        self.extensions = [
            ext for ext in self.extensions
            if ext.name not in disabled_module_list
        ]

        # Fix up the autodetected modules, prefixing all the source files
        # with Modules/ and adding Python's include directory to the path.
        (srcdir, ) = sysconfig.get_config_vars('srcdir')

        # Figure out the location of the source code for extension modules
        moddir = os.path.join(os.getcwd(), srcdir, 'Modules')
        moddir = os.path.normpath(moddir)
        srcdir, tail = os.path.split(moddir)
        srcdir = os.path.normpath(srcdir)
        moddir = os.path.normpath(moddir)

        # Fix up the paths for scripts, too
        self.distribution.scripts = [
            os.path.join(srcdir, filename)
            for filename in self.distribution.scripts
        ]

        for ext in self.extensions[:]:
            ext.sources = [
                os.path.join(moddir, filename) for filename in ext.sources
            ]
            ext.include_dirs.append('.')  # to get config.h
            ext.include_dirs.append(os.path.join(srcdir, './Include'))

            # If a module has already been built statically,
            # don't build it here
            if ext.name in sys.builtin_module_names:
                self.extensions.remove(ext)

        # Parse Modules/Setup to figure out which modules are turned
        # on in the file.
        input = text_file.TextFile('Modules/Setup', join_lines=1)
        remove_modules = []
        while 1:
            line = input.readline()
            if not line: break
            line = line.split()
            remove_modules.append(line[0])
        input.close()

        for ext in self.extensions[:]:
            if ext.name in remove_modules:
                self.extensions.remove(ext)

        # When you run "make CC=altcc" or something similar, you really want
        # those environment variables passed into the setup.py phase.  Here's
        # a small set of useful ones.
        compiler = os.environ.get('CC')
        linker_so = os.environ.get('LDSHARED')
        args = {}
        # unfortunately, distutils doesn't let us provide separate C and C++
        # compilers
        if compiler is not None:
            args['compiler_so'] = compiler
        if linker_so is not None:
            args['linker_so'] = linker_so + ' -shared'
        self.compiler.set_executables(**args)

        build_ext.build_extensions(self)
Пример #34
0
 def build_extensions(self):
     c = self.compiler
     if c.compiler_type == 'unix' and 'gcc' in c.compiler:
         for e in self.extensions:
             e.extra_compile_args=['-std=c99']
     build_ext.build_extensions(self)
Пример #35
0
    def build_extensions(self):

        library_dirs = []
        include_dirs = []

        _add_directory(include_dirs, "src/libImaging")

        pkg_config = None
        if _cmd_exists('pkg-config'):
            pkg_config = _pkg_config

        #
        # add configured kits
        for root_name, lib_name in dict(JPEG_ROOT="libjpeg",
                                        JPEG2K_ROOT="libopenjp2",
                                        TIFF_ROOT=("libtiff-5", "libtiff-4"),
                                        ZLIB_ROOT="zlib",
                                        FREETYPE_ROOT="freetype2",
                                        LCMS_ROOT="lcms2",
                                        IMAGEQUANT_ROOT="libimagequant"
                                        ).items():
            root = globals()[root_name]
            if root is None and pkg_config:
                if isinstance(lib_name, tuple):
                    for lib_name2 in lib_name:
                        _dbg('Looking for `%s` using pkg-config.' % lib_name2)
                        root = pkg_config(lib_name2)
                        if root:
                            break
                else:
                    _dbg('Looking for `%s` using pkg-config.' % lib_name)
                    root = pkg_config(lib_name)

            if isinstance(root, tuple):
                lib_root, include_root = root
            else:
                lib_root = include_root = root

            _add_directory(library_dirs, lib_root)
            _add_directory(include_dirs, include_root)

        # respect CFLAGS/LDFLAGS
        for k in ('CFLAGS', 'LDFLAGS'):
            if k in os.environ:
                for match in re.finditer(r'-I([^\s]+)', os.environ[k]):
                    _add_directory(include_dirs, match.group(1))
                for match in re.finditer(r'-L([^\s]+)', os.environ[k]):
                    _add_directory(library_dirs, match.group(1))

        # include, rpath, if set as environment variables:
        for k in ('C_INCLUDE_PATH', 'CPATH', 'INCLUDE'):
            if k in os.environ:
                for d in os.environ[k].split(os.path.pathsep):
                    _add_directory(include_dirs, d)

        for k in ('LD_RUN_PATH', 'LIBRARY_PATH', 'LIB'):
            if k in os.environ:
                for d in os.environ[k].split(os.path.pathsep):
                    _add_directory(library_dirs, d)

        prefix = sysconfig.get_config_var("prefix")
        if prefix:
            _add_directory(library_dirs, os.path.join(prefix, "lib"))
            _add_directory(include_dirs, os.path.join(prefix, "include"))

        #
        # add platform directories

        if self.disable_platform_guessing:
            pass

        elif sys.platform == "cygwin":
            # pythonX.Y.dll.a is in the /usr/lib/pythonX.Y/config directory
            _add_directory(library_dirs,
                           os.path.join("/usr/lib", "python%s" %
                                        sys.version[:3], "config"))

        elif sys.platform == "darwin":
            # attempt to make sure we pick freetype2 over other versions
            _add_directory(include_dirs, "/sw/include/freetype2")
            _add_directory(include_dirs, "/sw/lib/freetype2/include")
            # fink installation directories
            _add_directory(library_dirs, "/sw/lib")
            _add_directory(include_dirs, "/sw/include")
            # darwin ports installation directories
            _add_directory(library_dirs, "/opt/local/lib")
            _add_directory(include_dirs, "/opt/local/include")

            # if Homebrew is installed, use its lib and include directories
            try:
                prefix = subprocess.check_output(['brew', '--prefix']).strip(
                ).decode('latin1')
            except Exception:
                # Homebrew not installed
                prefix = None

            ft_prefix = None

            if prefix:
                # add Homebrew's include and lib directories
                _add_directory(library_dirs, os.path.join(prefix, 'lib'))
                _add_directory(include_dirs, os.path.join(prefix, 'include'))
                ft_prefix = os.path.join(prefix, 'opt', 'freetype')

            if ft_prefix and os.path.isdir(ft_prefix):
                # freetype might not be linked into Homebrew's prefix
                _add_directory(library_dirs, os.path.join(ft_prefix, 'lib'))
                _add_directory(include_dirs,
                               os.path.join(ft_prefix, 'include'))
            else:
                # fall back to freetype from XQuartz if
                # Homebrew's freetype is missing
                _add_directory(library_dirs, "/usr/X11/lib")
                _add_directory(include_dirs, "/usr/X11/include")

        elif sys.platform.startswith("linux"):
            arch_tp = (plat.processor(), plat.architecture()[0])
            # This should be correct on debian derivatives.
            if os.path.exists('/etc/debian_version'):
                # If this doesn't work, don't just silently patch
                # downstream because it's going to break when people
                # try to build pillow from source instead of
                # installing from the system packages.
                self.add_multiarch_paths()

            elif arch_tp == ("x86_64", "32bit"):
                # Special Case: 32-bit build on 64-bit machine.
                _add_directory(library_dirs, "/usr/lib/i386-linux-gnu")
            else:
                libdirs = {
                    'x86_64':  ["/lib64", "/usr/lib64",
                                "/usr/lib/x86_64-linux-gnu"],
                    '64bit':   ["/lib64", "/usr/lib64",
                                "/usr/lib/x86_64-linux-gnu"],
                    'i386':    ["/usr/lib/i386-linux-gnu"],
                    'i686':    ["/usr/lib/i386-linux-gnu"],
                    '32bit':   ["/usr/lib/i386-linux-gnu"],
                    'aarch64': ["/usr/lib64", "/usr/lib/aarch64-linux-gnu"],
                    'arm':     ["/usr/lib/arm-linux-gnueabi"],
                    'armv71':  ["/usr/lib/arm-linux-gnueabi"],
                    'armv7l':  ["/usr/lib"],
                    'ppc64':   ["/usr/lib64", "/usr/lib/ppc64-linux-gnu",
                                "/usr/lib/powerpc64-linux-gnu"],
                    'ppc64le':   ["/usr/lib64"],
                    'ppc':     ["/usr/lib/ppc-linux-gnu",
                                "/usr/lib/powerpc-linux-gnu"],
                    's390x':   ["/usr/lib64", "/usr/lib/s390x-linux-gnu"],
                    's390':    ["/usr/lib/s390-linux-gnu"],
                    }

                for platform_ in arch_tp:
                    dirs = libdirs.get(platform_, None)
                    if not dirs:
                        continue
                    for path in dirs:
                        _add_directory(library_dirs, path)
                    break

                else:
                    raise ValueError(
                        "Unable to identify Linux platform: `%s`" % platform_)

                # termux support for android.
                # system libraries (zlib) are installed in /system/lib
                # headers are at $PREFIX/include
                # user libs are at $PREFIX/lib
                if os.environ.get('ANDROID_ROOT', None):
                    _add_directory(library_dirs,
                                   os.path.join(os.environ['ANDROID_ROOT'],
                                                'lib'))

        elif sys.platform.startswith("gnu"):
            self.add_multiarch_paths()

        elif sys.platform.startswith("freebsd"):
            _add_directory(library_dirs, "/usr/local/lib")
            _add_directory(include_dirs, "/usr/local/include")

        elif sys.platform.startswith("netbsd"):
            _add_directory(library_dirs, "/usr/pkg/lib")
            _add_directory(include_dirs, "/usr/pkg/include")

        elif sys.platform.startswith("sunos5"):
            _add_directory(library_dirs, "/opt/local/lib")
            _add_directory(include_dirs, "/opt/local/include")

        # FIXME: check /opt/stuff directories here?

        # standard locations
        if not self.disable_platform_guessing:
            _add_directory(library_dirs, "/usr/local/lib")
            _add_directory(include_dirs, "/usr/local/include")

            _add_directory(library_dirs, "/usr/lib")
            _add_directory(include_dirs, "/usr/include")
            # alpine, at least
            _add_directory(library_dirs, "/lib")

        # on Windows, look for the OpenJPEG libraries in the location that
        # the official installer puts them
        if sys.platform == "win32":
            program_files = os.environ.get('ProgramFiles', '')
            best_version = (0, 0)
            best_path = None
            for name in os.listdir(program_files):
                if name.startswith('OpenJPEG '):
                    version = tuple(int(x) for x in
                                    name[9:].strip().split('.'))
                    if version > best_version:
                        best_version = version
                        best_path = os.path.join(program_files, name)

            if best_path:
                _dbg('Adding %s to search list', best_path)
                _add_directory(library_dirs, os.path.join(best_path, 'lib'))
                _add_directory(include_dirs,
                               os.path.join(best_path, 'include'))

        #
        # insert new dirs *before* default libs, to avoid conflicts
        # between Python PYD stub libs and real libraries

        self.compiler.library_dirs = library_dirs + self.compiler.library_dirs
        self.compiler.include_dirs = include_dirs + self.compiler.include_dirs

        #
        # look for available libraries

        feature = self.feature

        if feature.want('zlib'):
            _dbg('Looking for zlib')
            if _find_include_file(self, "zlib.h"):
                if _find_library_file(self, "z"):
                    feature.zlib = "z"
                elif (sys.platform == "win32" and
                      _find_library_file(self, "zlib")):
                    feature.zlib = "zlib"  # alternative name

        if feature.want('jpeg'):
            _dbg('Looking for jpeg')
            if _find_include_file(self, "jpeglib.h"):
                if _find_library_file(self, "jpeg"):
                    feature.jpeg = "jpeg"
                elif (sys.platform == "win32" and
                      _find_library_file(self, "libjpeg")):
                    feature.jpeg = "libjpeg"  # alternative name

        feature.openjpeg_version = None
        if feature.want('jpeg2000'):
            _dbg('Looking for jpeg2000')
            best_version = None
            best_path = None

            # Find the best version
            for directory in self.compiler.include_dirs:
                _dbg('Checking for openjpeg-#.# in %s', directory)
                try:
                    listdir = os.listdir(directory)
                except Exception:
                    # WindowsError, FileNotFoundError
                    continue
                for name in listdir:
                    if name.startswith('openjpeg-') and \
                        os.path.isfile(os.path.join(directory, name,
                                                    'openjpeg.h')):
                        _dbg('Found openjpeg.h in %s/%s', (directory, name))
                        version = tuple(int(x) for x in name[9:].split('.'))
                        if best_version is None or version > best_version:
                            best_version = version
                            best_path = os.path.join(directory, name)
                            _dbg('Best openjpeg version %s so far in %s',
                                 (best_version, best_path))

            if best_version and _find_library_file(self, 'openjp2'):
                # Add the directory to the include path so we can include
                # <openjpeg.h> rather than having to cope with the versioned
                # include path
                # FIXME (melvyn-sopacua):
                # At this point it's possible that best_path is already in
                # self.compiler.include_dirs. Should investigate how that is
                # possible.
                _add_directory(self.compiler.include_dirs, best_path, 0)
                feature.jpeg2000 = 'openjp2'
                feature.openjpeg_version = '.'.join(str(x) for x in
                                                    best_version)

        if feature.want('imagequant'):
            _dbg('Looking for imagequant')
            if _find_include_file(self, 'libimagequant.h'):
                if _find_library_file(self, "imagequant"):
                    feature.imagequant = "imagequant"
                elif _find_library_file(self, "libimagequant"):
                    feature.imagequant = "libimagequant"

        if feature.want('tiff'):
            _dbg('Looking for tiff')
            if _find_include_file(self, 'tiff.h'):
                if _find_library_file(self, "tiff"):
                    feature.tiff = "tiff"
                if (sys.platform in ["win32", "darwin"] and
                        _find_library_file(self, "libtiff")):
                    feature.tiff = "libtiff"

        if feature.want('freetype'):
            _dbg('Looking for freetype')
            if _find_library_file(self, "freetype"):
                # look for freetype2 include files
                freetype_version = 0
                for subdir in self.compiler.include_dirs:
                    _dbg('Checking for include file %s in %s',
                         ("ft2build.h", subdir))
                    if os.path.isfile(os.path.join(subdir, "ft2build.h")):
                        _dbg('Found %s in %s', ("ft2build.h", subdir))
                        freetype_version = 21
                        subdir = os.path.join(subdir, "freetype2")
                        break
                    subdir = os.path.join(subdir, "freetype2")
                    _dbg('Checking for include file %s in %s',
                         ("ft2build.h", subdir))
                    if os.path.isfile(os.path.join(subdir, "ft2build.h")):
                        _dbg('Found %s in %s', ("ft2build.h", subdir))
                        freetype_version = 21
                        break
                if freetype_version:
                    feature.freetype = "freetype"
                    if subdir:
                        _add_directory(self.compiler.include_dirs, subdir, 0)

        if feature.want('lcms'):
            _dbg('Looking for lcms')
            if _find_include_file(self, "lcms2.h"):
                if _find_library_file(self, "lcms2"):
                    feature.lcms = "lcms2"
                elif _find_library_file(self, "lcms2_static"):
                    # alternate Windows name.
                    feature.lcms = "lcms2_static"

        if feature.want('webp'):
            _dbg('Looking for webp')
            if (_find_include_file(self, "webp/encode.h") and
                    _find_include_file(self, "webp/decode.h")):
                # In Google's precompiled zip it is call "libwebp":
                if _find_library_file(self, "webp"):
                    feature.webp = "webp"
                elif _find_library_file(self, "libwebp"):
                    feature.webp = "libwebp"

        if feature.want('webpmux'):
            _dbg('Looking for webpmux')
            if (_find_include_file(self, "webp/mux.h") and
                    _find_include_file(self, "webp/demux.h")):
                if (_find_library_file(self, "webpmux") and
                        _find_library_file(self, "webpdemux")):
                    feature.webpmux = "webpmux"
                if (_find_library_file(self, "libwebpmux") and
                        _find_library_file(self, "libwebpdemux")):
                    feature.webpmux = "libwebpmux"

        for f in feature:
            if not getattr(feature, f) and feature.require(f):
                if f in ('jpeg', 'zlib'):
                    raise RequiredDependencyException(f)
                raise DependencyException(f)

        #
        # core library

        files = ["src/_imaging.c"]
        for src_file in _IMAGING:
            files.append("src/" + src_file + ".c")
        for src_file in _LIB_IMAGING:
            files.append(os.path.join("src/libImaging", src_file + ".c"))

        libs = []
        defs = []
        if feature.jpeg:
            libs.append(feature.jpeg)
            defs.append(("HAVE_LIBJPEG", None))
        if feature.jpeg2000:
            libs.append(feature.jpeg2000)
            defs.append(("HAVE_OPENJPEG", None))
            if sys.platform == "win32":
                defs.append(("OPJ_STATIC", None))
        if feature.zlib:
            libs.append(feature.zlib)
            defs.append(("HAVE_LIBZ", None))
        if feature.imagequant:
            libs.append(feature.imagequant)
            defs.append(("HAVE_LIBIMAGEQUANT", None))
        if feature.tiff:
            libs.append(feature.tiff)
            defs.append(("HAVE_LIBTIFF", None))
        if sys.platform == "win32":
            libs.extend(["kernel32", "user32", "gdi32"])
        if struct.unpack("h", "\0\1".encode('ascii'))[0] == 1:
            defs.append(("WORDS_BIGENDIAN", None))

        if sys.platform == "win32" and not (PLATFORM_PYPY or PLATFORM_MINGW):
            defs.append(("PILLOW_VERSION", '"\\"%s\\""' % PILLOW_VERSION))
        else:
            defs.append(("PILLOW_VERSION", '"%s"' % PILLOW_VERSION))

        exts = [(Extension("PIL._imaging",
                           files,
                           libraries=libs,
                           define_macros=defs,
                           extra_compile_args=['-msse4']))]

        #
        # additional libraries

        if feature.freetype:
            libs = ["freetype"]
            defs = []
            exts.append(Extension(
                "PIL._imagingft", ["src/_imagingft.c"], libraries=libs,
                define_macros=defs))

        if feature.lcms:
            extra = []
            if sys.platform == "win32":
                extra.extend(["user32", "gdi32"])
            exts.append(Extension("PIL._imagingcms",
                                  ["src/_imagingcms.c"],
                                  libraries=[feature.lcms] + extra))

        if feature.webp:
            libs = [feature.webp]
            defs = []

            if feature.webpmux:
                defs.append(("HAVE_WEBPMUX", None))
                libs.append(feature.webpmux)
                libs.append(feature.webpmux.replace('pmux', 'pdemux'))

            exts.append(Extension("PIL._webp",
                                  ["src/_webp.c"],
                                  libraries=libs,
                                  define_macros=defs))

        tk_libs = ['psapi'] if sys.platform == 'win32' else []
        exts.append(Extension("PIL._imagingtk",
                              ["src/_imagingtk.c", "src/Tk/tkImaging.c"],
                              include_dirs=['src/Tk'],
                              libraries=tk_libs))

        exts.append(Extension("PIL._imagingmath", ["src/_imagingmath.c"]))
        exts.append(Extension("PIL._imagingmorph", ["src/_imagingmorph.c"]))

        self.extensions[:] = exts

        build_ext.build_extensions(self)

        #
        # sanity checks

        self.summary_report(feature)
Пример #36
0
 def build_extensions(self):
     if self.parallel is None and os.environ.get("SPACY_NUM_BUILD_JOBS") is not None:
         self.parallel = int(os.environ.get("SPACY_NUM_BUILD_JOBS"))
     build_ext_options.build_options(self)
     build_ext.build_extensions(self)
Пример #37
0
    def build_extensions(self):
        _build_ext.build_extensions(self)

        # lib_name -> ([used for, ...], is present)
        libraries = {}

        for extension in self.extensions:
            if ((hasattr(extension, "library_manifest")
                 and callable(extension.library_manifest))):
                for (library, used_for,
                     is_present) in extension.library_manifest():
                    if library in libraries:
                        libraries[library] = (libraries[library][0] +
                                              [used_for], libraries[library][1]
                                              and is_present)
                    else:
                        libraries[library] = ([used_for], is_present)

        if ext_audiotools_cdio not in self.extensions:
            libraries["libcdio"] = (["CDDA data extraction"], False)
        if ext_audiotools_dvdaudio not in self.extensions:
            libraries["libdvd-audio"] = (["DVD-Audio extraction"], False)

        all_libraries_present = (set([l[1] for l in libraries.values()
                                      ]) == set([True]))

        table = output_table()

        header = table.row()
        header.add_column("library", "right")
        header.add_column(" ")
        header.add_column("present?")
        header.add_column(" ")
        header.add_column("used for")
        if not all_libraries_present:
            header.add_column(" ")
            header.add_column("download URL")

        if not all_libraries_present:
            table.divider_row(["-", " ", "-", " ", "-", " ", "-"])
        else:
            table.divider_row(["-", " ", "-", " ", "-"])

        for library in sorted(libraries.keys()):
            row = table.row()
            row.add_column(library, "right")
            row.add_column(" ")
            row.add_column("yes" if libraries[library][1] else "no")
            row.add_column(" ")
            row.add_column(", ".join(libraries[library][0]))
            if not all_libraries_present:
                row.add_column(" ")
                if not libraries[library][1]:
                    row.add_column(LIBRARY_URLS[library])
                else:
                    row.add_column("")

        try:
            pkg_config = subprocess.Popen(["pkg-config", "--version"],
                                          stdout=open(os.devnull, "wb"),
                                          stderr=open(os.devnull, "wb"))
            pkg_config_found = (pkg_config.wait() == 0)
        except OSError:
            pkg_config_found = False

        print("=" * table.total_width())
        print("Python Audio Tools %s Setup" % (VERSION))
        print("=" * table.total_width())

        if not pkg_config_found:

            def add_row(table, text, alignment="left"):
                row = table.row()
                row.add_column("*")
                row.add_column(text, alignment)
                row.add_column("*")

            table2 = output_table()
            row = table2.row()
            row.add_column("*")
            row.add_column("*" * 60)
            row.add_column("*")

            add_row(table2, "pkg-config not found", "center")

            add_row(table2, "some libraries may not be located automatically",
                    "center")

            add_row(table2, "")

            add_row(table2, "  download pkg-config from:")
            add_row(table2,
                    "  http://www.freedesktop.org/wiki/Software/pkg-config/")

            add_row(table2, "")

            add_row(
                table2, "  or specify which libraries are available " +
                "in \"setup.cfg\"")

            row = table2.row()
            row.add_column("*")
            row.add_column("*" * 60)
            row.add_column("*")

            for row in table2.format():
                print(row)

        for row in table.format():
            print(row)
        print()
Пример #38
0
 def build_extensions(self):
     self.patch_compiler()
     for ext in self.extensions:
         self.patch_extension(ext)
     build_ext.build_extensions(self)
Пример #39
0
 def build_extensions(self):
     """Set up the build extensions."""
     # TODO: move build customization here?
     build_ext.build_extensions(self)
Пример #40
0
    def build_extensions(self):

        library_dirs = []
        include_dirs = []

        _add_directory(include_dirs, "libImaging")

        pkg_config = None
        if _cmd_exists('pkg-config'):
            pkg_config = _pkg_config

        #
        # add configured kits
        for root_name, lib_name in dict(JPEG_ROOT="libjpeg",
                                        JPEG2K_ROOT="libopenjp2",
                                        TIFF_ROOT=("libtiff-5", "libtiff-4"),
                                        ZLIB_ROOT="zlib",
                                        FREETYPE_ROOT="freetype2",
                                        LCMS_ROOT="lcms2",
                                        IMAGEQUANT_ROOT="libimagequant"
                                        ).items():
            root = globals()[root_name]
            if root is None and pkg_config:
                if isinstance(lib_name, tuple):
                    for lib_name2 in lib_name:
                        _dbg('Looking for `%s` using pkg-config.' % lib_name2)
                        root = pkg_config(lib_name2)
                        if root:
                            break
                else:
                    _dbg('Looking for `%s` using pkg-config.' % lib_name)
                    root = pkg_config(lib_name)

            if isinstance(root, tuple):
                lib_root, include_root = root
            else:
                lib_root = include_root = root

            _add_directory(library_dirs, lib_root)
            _add_directory(include_dirs, include_root)

        # respect CFLAGS/LDFLAGS
        for k in ('CFLAGS', 'LDFLAGS'):
            if k in os.environ:
                for match in re.finditer(r'-I([^\s]+)', os.environ[k]):
                    _add_directory(include_dirs, match.group(1))
                for match in re.finditer(r'-L([^\s]+)', os.environ[k]):
                    _add_directory(library_dirs, match.group(1))

        # include, rpath, if set as environment variables:
        for k in ('C_INCLUDE_PATH', 'CPATH', 'INCLUDE'):
            if k in os.environ:
                for d in os.environ[k].split(os.path.pathsep):
                    _add_directory(include_dirs, d)

        for k in ('LD_RUN_PATH', 'LIBRARY_PATH', 'LIB'):
            if k in os.environ:
                for d in os.environ[k].split(os.path.pathsep):
                    _add_directory(library_dirs, d)

        prefix = sysconfig.get_config_var("prefix")
        if prefix:
            _add_directory(library_dirs, os.path.join(prefix, "lib"))
            _add_directory(include_dirs, os.path.join(prefix, "include"))

        #
        # add platform directories

        if self.disable_platform_guessing:
            pass

        elif sys.platform == "cygwin":
            # pythonX.Y.dll.a is in the /usr/lib/pythonX.Y/config directory
            _add_directory(library_dirs,
                           os.path.join("/usr/lib", "python%s" %
                                        sys.version[:3], "config"))

        elif sys.platform == "darwin":
            # attempt to make sure we pick freetype2 over other versions
            _add_directory(include_dirs, "/sw/include/freetype2")
            _add_directory(include_dirs, "/sw/lib/freetype2/include")
            # fink installation directories
            _add_directory(library_dirs, "/sw/lib")
            _add_directory(include_dirs, "/sw/include")
            # darwin ports installation directories
            _add_directory(library_dirs, "/opt/local/lib")
            _add_directory(include_dirs, "/opt/local/include")

            # if Homebrew is installed, use its lib and include directories
            try:
                prefix = subprocess.check_output(['brew', '--prefix']).strip(
                ).decode('latin1')
            except:
                # Homebrew not installed
                prefix = None

            ft_prefix = None

            if prefix:
                # add Homebrew's include and lib directories
                _add_directory(library_dirs, os.path.join(prefix, 'lib'))
                _add_directory(include_dirs, os.path.join(prefix, 'include'))
                ft_prefix = os.path.join(prefix, 'opt', 'freetype')

            if ft_prefix and os.path.isdir(ft_prefix):
                # freetype might not be linked into Homebrew's prefix
                _add_directory(library_dirs, os.path.join(ft_prefix, 'lib'))
                _add_directory(include_dirs,
                               os.path.join(ft_prefix, 'include'))
            else:
                # fall back to freetype from XQuartz if
                # Homebrew's freetype is missing
                _add_directory(library_dirs, "/usr/X11/lib")
                _add_directory(include_dirs, "/usr/X11/include")

        elif sys.platform.startswith("linux"):
            arch_tp = (plat.processor(), plat.architecture()[0])
            if arch_tp == ("x86_64", "32bit"):
                # 32-bit build on 64-bit machine.
                _add_directory(library_dirs, "/usr/lib/i386-linux-gnu")
            else:
                for platform_ in arch_tp:

                    if not platform_:
                        continue

                    if platform_ in ["x86_64", "64bit"]:
                        _add_directory(library_dirs, "/lib64")
                        _add_directory(library_dirs, "/usr/lib64")
                        _add_directory(library_dirs,
                                       "/usr/lib/x86_64-linux-gnu")
                        break
                    elif platform_ in ["i386", "i686", "32bit"]:
                        _add_directory(library_dirs, "/usr/lib/i386-linux-gnu")
                        break
                    elif platform_ in ["aarch64"]:
                        _add_directory(library_dirs, "/usr/lib64")
                        _add_directory(library_dirs,
                                       "/usr/lib/aarch64-linux-gnu")
                        break
                    elif platform_ in ["arm", "armv7l"]:
                        _add_directory(library_dirs,
                                       "/usr/lib/arm-linux-gnueabi")
                        break
                    elif platform_ in ["ppc64"]:
                        _add_directory(library_dirs, "/usr/lib64")
                        _add_directory(library_dirs,
                                       "/usr/lib/ppc64-linux-gnu")
                        _add_directory(library_dirs,
                                       "/usr/lib/powerpc64-linux-gnu")
                        break
                    elif platform_ in ["ppc"]:
                        _add_directory(library_dirs, "/usr/lib/ppc-linux-gnu")
                        _add_directory(library_dirs,
                                       "/usr/lib/powerpc-linux-gnu")
                        break
                    elif platform_ in ["s390x"]:
                        _add_directory(library_dirs, "/usr/lib64")
                        _add_directory(library_dirs,
                                       "/usr/lib/s390x-linux-gnu")
                        break
                    elif platform_ in ["s390"]:
                        _add_directory(library_dirs, "/usr/lib/s390-linux-gnu")
                        break
                else:
                    raise ValueError(
                        "Unable to identify Linux platform: `%s`" % platform_)

                # XXX Kludge. Above /\ we brute force support multiarch. Here we
                # try Barry's more general approach. Afterward, something should
                # work ;-)
                self.add_multiarch_paths()

        elif sys.platform.startswith("gnu"):
            self.add_multiarch_paths()

        elif sys.platform.startswith("freebsd"):
            _add_directory(library_dirs, "/usr/local/lib")
            _add_directory(include_dirs, "/usr/local/include")

        elif sys.platform.startswith("netbsd"):
            _add_directory(library_dirs, "/usr/pkg/lib")
            _add_directory(include_dirs, "/usr/pkg/include")

        elif sys.platform.startswith("sunos5"):
            _add_directory(library_dirs, "/opt/local/lib")
            _add_directory(include_dirs, "/opt/local/include")

        # FIXME: check /opt/stuff directories here?

        # standard locations
        if not self.disable_platform_guessing:
            _add_directory(library_dirs, "/usr/local/lib")
            _add_directory(include_dirs, "/usr/local/include")

            _add_directory(library_dirs, "/usr/lib")
            _add_directory(include_dirs, "/usr/include")
            # alpine, at least
            _add_directory(library_dirs, "/lib")

        # on Windows, look for the OpenJPEG libraries in the location that
        # the official installer puts them
        if sys.platform == "win32":
            program_files = os.environ.get('ProgramFiles', '')
            best_version = (0, 0)
            best_path = None
            for name in os.listdir(program_files):
                if name.startswith('OpenJPEG '):
                    version = tuple(int(x) for x in name[9:].strip().split('.'))
                    if version > best_version:
                        best_version = version
                        best_path = os.path.join(program_files, name)

            if best_path:
                _dbg('Adding %s to search list', best_path)
                _add_directory(library_dirs, os.path.join(best_path, 'lib'))
                _add_directory(include_dirs,
                               os.path.join(best_path, 'include'))

        #
        # insert new dirs *before* default libs, to avoid conflicts
        # between Python PYD stub libs and real libraries

        self.compiler.library_dirs = library_dirs + self.compiler.library_dirs
        self.compiler.include_dirs = include_dirs + self.compiler.include_dirs

        #
        # look for available libraries

        feature = self.feature

        if feature.want('zlib'):
            _dbg('Looking for zlib')
            if _find_include_file(self, "zlib.h"):
                if _find_library_file(self, "z"):
                    feature.zlib = "z"
                elif (sys.platform == "win32" and
                      _find_library_file(self, "zlib")):
                    feature.zlib = "zlib"  # alternative name

        if feature.want('jpeg'):
            _dbg('Looking for jpeg')
            if _find_include_file(self, "jpeglib.h"):
                if _find_library_file(self, "jpeg"):
                    feature.jpeg = "jpeg"
                elif (sys.platform == "win32" and
                      _find_library_file(self, "libjpeg")):
                    feature.jpeg = "libjpeg"  # alternative name

        feature.openjpeg_version = None
        if feature.want('jpeg2000'):
            _dbg('Looking for jpeg2000')
            best_version = None
            best_path = None

            # Find the best version
            for directory in self.compiler.include_dirs:
                _dbg('Checking for openjpeg-#.# in %s', directory)
                try:
                    listdir = os.listdir(directory)
                except Exception:
                    # WindowsError, FileNotFoundError
                    continue
                for name in listdir:
                    if name.startswith('openjpeg-') and \
                        os.path.isfile(os.path.join(directory, name,
                                                    'openjpeg.h')):
                        _dbg('Found openjpeg.h in %s/%s', (directory, name))
                        version = tuple(int(x) for x in name[9:].split('.'))
                        if best_version is None or version > best_version:
                            best_version = version
                            best_path = os.path.join(directory, name)
                            _dbg('Best openjpeg version %s so far in %s',
                                 (best_version, best_path))

            if best_version and _find_library_file(self, 'openjp2'):
                # Add the directory to the include path so we can include
                # <openjpeg.h> rather than having to cope with the versioned
                # include path
                _add_directory(self.compiler.include_dirs, best_path, 0)
                feature.jpeg2000 = 'openjp2'
                feature.openjpeg_version = '.'.join(str(x) for x in best_version)

        if feature.want('imagequant'):
            _dbg('Looking for imagequant')
            if _find_include_file(self, 'libimagequant.h'):
                if _find_library_file(self, "imagequant"):
                    feature.imagequant = "imagequant"
                elif _find_library_file(self, "libimagequant"):
                    feature.imagequant = "libimagequant"

        if feature.want('tiff'):
            _dbg('Looking for tiff')
            if _find_include_file(self, 'tiff.h'):
                if _find_library_file(self, "tiff"):
                    feature.tiff = "tiff"
                if sys.platform == "win32" and _find_library_file(self, "libtiff"):
                    feature.tiff = "libtiff"
                if (sys.platform == "darwin" and
                        _find_library_file(self, "libtiff")):
                    feature.tiff = "libtiff"

        if feature.want('freetype'):
            _dbg('Looking for freetype')
            if _find_library_file(self, "freetype"):
                # look for freetype2 include files
                freetype_version = 0
                for subdir in self.compiler.include_dirs:
                    _dbg('Checking for include file %s in %s', ("ft2build.h", subdir))
                    if os.path.isfile(os.path.join(subdir, "ft2build.h")):
                        _dbg('Found %s in %s', ("ft2build.h", subdir))
                        freetype_version = 21
                        subdir = os.path.join(subdir, "freetype2")
                        break
                    subdir = os.path.join(subdir, "freetype2")
                    _dbg('Checking for include file %s in %s', ("ft2build.h", subdir))
                    if os.path.isfile(os.path.join(subdir, "ft2build.h")):
                        _dbg('Found %s in %s', ("ft2build.h", subdir))
                        freetype_version = 21
                        break
                if freetype_version:
                    feature.freetype = "freetype"
                    feature.freetype_version = freetype_version
                    if subdir:
                        _add_directory(self.compiler.include_dirs, subdir, 0)

        if feature.want('lcms'):
            _dbg('Looking for lcms')
            if _find_include_file(self, "lcms2.h"):
                if _find_library_file(self, "lcms2"):
                    feature.lcms = "lcms2"
                elif _find_library_file(self, "lcms2_static"):
                    # alternate Windows name.
                    feature.lcms = "lcms2_static"

        if feature.want('webp'):
            _dbg('Looking for webp')
            if (_find_include_file(self, "webp/encode.h") and
                    _find_include_file(self, "webp/decode.h")):
                # In Google's precompiled zip it is call "libwebp":
                if _find_library_file(self, "webp"):
                    feature.webp = "webp"
                elif _find_library_file(self, "libwebp"):
                    feature.webp = "libwebp"

        if feature.want('webpmux'):
            _dbg('Looking for webpmux')
            if (_find_include_file(self, "webp/mux.h") and
                    _find_include_file(self, "webp/demux.h")):
                if (_find_library_file(self, "webpmux") and
                        _find_library_file(self, "webpdemux")):
                    feature.webpmux = "webpmux"
                if (_find_library_file(self, "libwebpmux") and
                        _find_library_file(self, "libwebpdemux")):
                    feature.webpmux = "libwebpmux"

        for f in feature:
            if not getattr(feature, f) and feature.require(f):
                if f in ('jpeg', 'zlib'):
                    raise ValueError(
                        '%s is required unless explicitly disabled'
                        ' using --disable-%s, aborting' % (f, f))
                raise ValueError(
                    '--enable-%s requested but %s not found, aborting.' %
                    (f, f))

        #
        # core library

        files = ["_imaging.c"]
        for src_file in _IMAGING:
            files.append(src_file + ".c")
        for src_file in _LIB_IMAGING:
            files.append(os.path.join("libImaging", src_file + ".c"))

        libs = []
        defs = []
        if feature.jpeg:
            libs.append(feature.jpeg)
            defs.append(("HAVE_LIBJPEG", None))
        if feature.jpeg2000:
            libs.append(feature.jpeg2000)
            defs.append(("HAVE_OPENJPEG", None))
            if sys.platform == "win32":
                defs.append(("OPJ_STATIC", None))
        if feature.zlib:
            libs.append(feature.zlib)
            defs.append(("HAVE_LIBZ", None))
        if feature.imagequant:
            libs.append(feature.imagequant)
            defs.append(("HAVE_LIBIMAGEQUANT", None))
        if feature.tiff:
            libs.append(feature.tiff)
            defs.append(("HAVE_LIBTIFF", None))
        if sys.platform == "win32":
            libs.extend(["kernel32", "user32", "gdi32"])
        if struct.unpack("h", "\0\1".encode('ascii'))[0] == 1:
            defs.append(("WORDS_BIGENDIAN", None))

        exts = [(Extension("PIL._imaging",
                           files,
                           libraries=libs,
                           define_macros=defs))]

        #
        # additional libraries

        if feature.freetype:
            exts.append(Extension("PIL._imagingft",
                                  ["_imagingft.c"],
                                  libraries=["freetype"]))

        if feature.lcms:
            extra = []
            if sys.platform == "win32":
                extra.extend(["user32", "gdi32"])
            exts.append(Extension("PIL._imagingcms",
                                  ["_imagingcms.c"],
                                  libraries=[feature.lcms] + extra))

        if feature.webp:
            libs = [feature.webp]
            defs = []

            if feature.webpmux:
                defs.append(("HAVE_WEBPMUX", None))
                libs.append(feature.webpmux)
                libs.append(feature.webpmux.replace('pmux', 'pdemux'))

            exts.append(Extension("PIL._webp",
                                  ["_webp.c"],
                                  libraries=libs,
                                  define_macros=defs))

        tk_libs = ['psapi'] if sys.platform == 'win32' else []
        exts.append(Extension("PIL._imagingtk",
                              ["_imagingtk.c", "Tk/tkImaging.c"],
                              include_dirs=['Tk'],
                              libraries=tk_libs))

        exts.append(Extension("PIL._imagingmath", ["_imagingmath.c"]))
        exts.append(Extension("PIL._imagingmorph", ["_imagingmorph.c"]))

        self.extensions[:] = exts

        build_ext.build_extensions(self)

        #
        # sanity and security checks

        unsafe_zlib = None

        if feature.zlib:
            unsafe_zlib = self.check_zlib_version(self.compiler.include_dirs)

        self.summary_report(feature, unsafe_zlib)
Пример #41
0
 def build_extensions(self):
     build_ext_options.build_options(self)
     build_ext.build_extensions(self)
Пример #42
0
 def build_extensions(self):
     c = self.compiler.compiler_type
     if c in copt:
         for e in self.extensions:
             e.extra_compile_args = copt[c]
     build_ext.build_extensions(self)
Пример #43
0
 def build_extensions(self):
     customize_compiler_for_nvcc(self.compiler)
     build_ext.build_extensions(self)
Пример #44
0
    def build_extensions(self):

        global TCL_ROOT

        library_dirs = []
        include_dirs = []

        _add_directory(include_dirs, "libImaging")

        #
        # add configured kits

        for root in (TCL_ROOT, JPEG_ROOT, JPEG2K_ROOT, TIFF_ROOT, ZLIB_ROOT,
                     FREETYPE_ROOT, LCMS_ROOT):
            if isinstance(root, type(())):
                lib_root, include_root = root
            else:
                lib_root = include_root = root
            _add_directory(library_dirs, lib_root)
            _add_directory(include_dirs, include_root)

        # respect CFLAGS/LDFLAGS
        for k in ('CFLAGS', 'LDFLAGS'):
            if k in os.environ:
                for match in re.finditer(r'-I([^\s]+)', os.environ[k]):
                    _add_directory(include_dirs, match.group(1))
                for match in re.finditer(r'-L([^\s]+)', os.environ[k]):
                    _add_directory(library_dirs, match.group(1))

        # include, rpath, if set as environment variables:
        for k in ('C_INCLUDE_PATH', 'CPATH', 'INCLUDE'):
            if k in os.environ:
                for d in os.environ[k].split(os.path.pathsep):
                    _add_directory(include_dirs, d)

        for k in ('LD_RUN_PATH', 'LIBRARY_PATH', 'LIB'):
            if k in os.environ:
                for d in os.environ[k].split(os.path.pathsep):
                    _add_directory(library_dirs, d)

        prefix = sysconfig.get_config_var("prefix")
        if prefix:
            _add_directory(library_dirs, os.path.join(prefix, "lib"))
            _add_directory(include_dirs, os.path.join(prefix, "include"))

        #
        # add platform directories

        if sys.platform == "cygwin":
            # pythonX.Y.dll.a is in the /usr/lib/pythonX.Y/config directory
            _add_directory(library_dirs,
                           os.path.join("/usr/lib", "python%s" %
                                        sys.version[:3], "config"))

        elif sys.platform == "darwin":
            # attempt to make sure we pick freetype2 over other versions
            _add_directory(include_dirs, "/sw/include/freetype2")
            _add_directory(include_dirs, "/sw/lib/freetype2/include")
            # fink installation directories
            _add_directory(library_dirs, "/sw/lib")
            _add_directory(include_dirs, "/sw/include")
            # darwin ports installation directories
            _add_directory(library_dirs, "/opt/local/lib")
            _add_directory(include_dirs, "/opt/local/include")

            # if Homebrew is installed, use its lib and include directories
            import subprocess
            try:
                prefix = subprocess.check_output(['brew', '--prefix']).strip(
                ).decode('latin1')
            except:
                # Homebrew not installed
                prefix = None

            ft_prefix = None

            if prefix:
                # add Homebrew's include and lib directories
                _add_directory(library_dirs, os.path.join(prefix, 'lib'))
                _add_directory(include_dirs, os.path.join(prefix, 'include'))
                ft_prefix = os.path.join(prefix, 'opt', 'freetype')

            if ft_prefix and os.path.isdir(ft_prefix):
                # freetype might not be linked into Homebrew's prefix
                _add_directory(library_dirs, os.path.join(ft_prefix, 'lib'))
                _add_directory(include_dirs,
                               os.path.join(ft_prefix, 'include'))
            else:
                # fall back to freetype from XQuartz if
                # Homebrew's freetype is missing
                _add_directory(library_dirs, "/usr/X11/lib")
                _add_directory(include_dirs, "/usr/X11/include")

        elif sys.platform.startswith("linux"):
            arch_tp = (plat.processor(), plat.architecture()[0])
            if arch_tp == ("x86_64", "32bit"):
                # 32-bit build on 64-bit machine.
                _add_directory(library_dirs, "/usr/lib/i386-linux-gnu")
            else:
                for platform_ in arch_tp:

                    if not platform_:
                        continue

                    if platform_ in ["x86_64", "64bit"]:
                        _add_directory(library_dirs, "/lib64")
                        _add_directory(library_dirs, "/usr/lib64")
                        _add_directory(library_dirs,
                                       "/usr/lib/x86_64-linux-gnu")
                        break
                    elif platform_ in ["i386", "i686", "32bit"]:
                        _add_directory(library_dirs, "/usr/lib/i386-linux-gnu")
                        break
                    elif platform_ in ["aarch64"]:
                        _add_directory(library_dirs, "/usr/lib64")
                        _add_directory(library_dirs,
                                       "/usr/lib/aarch64-linux-gnu")
                        break
                    elif platform_ in ["arm", "armv7l"]:
                        _add_directory(library_dirs,
                                       "/usr/lib/arm-linux-gnueabi")
                        break
                    elif platform_ in ["ppc64"]:
                        _add_directory(library_dirs, "/usr/lib64")
                        _add_directory(library_dirs,
                                       "/usr/lib/ppc64-linux-gnu")
                        _add_directory(library_dirs,
                                       "/usr/lib/powerpc64-linux-gnu")
                        break
                    elif platform_ in ["ppc"]:
                        _add_directory(library_dirs, "/usr/lib/ppc-linux-gnu")
                        _add_directory(library_dirs,
                                       "/usr/lib/powerpc-linux-gnu")
                        break
                    elif platform_ in ["s390x"]:
                        _add_directory(library_dirs, "/usr/lib64")
                        _add_directory(library_dirs,
                                       "/usr/lib/s390x-linux-gnu")
                        break
                    elif platform_ in ["s390"]:
                        _add_directory(library_dirs, "/usr/lib/s390-linux-gnu")
                        break
                else:
                    raise ValueError(
                        "Unable to identify Linux platform: `%s`" % platform_)

            # XXX Kludge. Above /\ we brute force support multiarch. Here we
            # try Barry's more general approach. Afterward, something should
            # work ;-)
            self.add_multiarch_paths()

        elif sys.platform.startswith("gnu"):
            self.add_multiarch_paths()

        elif sys.platform.startswith("freebsd"):
            _add_directory(library_dirs, "/usr/local/lib")
            _add_directory(include_dirs, "/usr/local/include")

        elif sys.platform.startswith("netbsd"):
            _add_directory(library_dirs, "/usr/pkg/lib")
            _add_directory(include_dirs, "/usr/pkg/include")

        elif sys.platform.startswith("sunos5"):
            _add_directory(library_dirs, "/opt/local/lib")
            _add_directory(include_dirs, "/opt/local/include")

        # FIXME: check /opt/stuff directories here?

        # locate tkinter libraries

        if _tkinter:
            TCL_VERSION = _tkinter.TCL_VERSION[:3]
            _dbg('Tkinter found, will check for Tcl/Tk')
        else:
            _dbg('Tkinter not found')

        if _tkinter and not TCL_ROOT:
            # we have Tkinter but the TCL_ROOT variable was not set;
            # try to locate appropriate Tcl/Tk libraries
            PYVERSION = sys.version[0] + sys.version[2]
            TCLVERSION = TCL_VERSION[0] + TCL_VERSION[2]
            roots = [
                # common installation directories, mostly for Windows
                # (for Unix-style platforms, we'll check in well-known
                # locations later)
                os.path.join("/py" + PYVERSION, "Tcl"),
                os.path.join("/python" + PYVERSION, "Tcl"),
                "/Tcl",
                "/Tcl" + TCLVERSION,
                "/Tcl" + TCL_VERSION,
                os.path.join(
                    os.environ.get("ProgramFiles", ""), "Tcl"),
            ]
            for TCL_ROOT in roots:
                TCL_ROOT = os.path.abspath(TCL_ROOT)
                _dbg('Checking %s for tk.h', TCL_ROOT)
                if os.path.isfile(os.path.join(TCL_ROOT, "include", "tk.h")):
                    # FIXME: use distutils logging (?)
                    print("--- using Tcl/Tk libraries at", TCL_ROOT)
                    print("--- using Tcl/Tk version", TCL_VERSION)
                    TCL_ROOT = _lib_include(TCL_ROOT)
                    break
            else:
                TCL_ROOT = None
                _dbg('Tcl/tk not found')

        # add standard directories

        # look for tcl specific subdirectory (e.g debian)
        if _tkinter:
            tcl_dir = "/usr/include/tcl" + TCL_VERSION
            if os.path.isfile(os.path.join(tcl_dir, "tk.h")):
                _add_directory(include_dirs, tcl_dir)

        # standard locations
        _add_directory(library_dirs, "/usr/local/lib")
        _add_directory(include_dirs, "/usr/local/include")

        _add_directory(library_dirs, "/usr/lib")
        _add_directory(include_dirs, "/usr/include")

        # on Windows, look for the OpenJPEG libraries in the location that
        # the official installer puts them
        if sys.platform == "win32":
            program_files = os.environ.get('ProgramFiles', '')
            best_version = (0, 0)
            best_path = None
            for name in os.listdir(program_files):
                if name.startswith('OpenJPEG '):
                    version = tuple([int(x) for x in name[9:].strip().split(
                        '.')])
                    if version > best_version:
                        best_version = version
                        best_path = os.path.join(program_files, name)

            if best_path:
                _dbg('Adding %s to search list', best_path)
                _add_directory(library_dirs, os.path.join(best_path, 'lib'))
                _add_directory(include_dirs,
                               os.path.join(best_path, 'include'))

        #
        # insert new dirs *before* default libs, to avoid conflicts
        # between Python PYD stub libs and real libraries

        self.compiler.library_dirs = library_dirs + self.compiler.library_dirs
        self.compiler.include_dirs = include_dirs + self.compiler.include_dirs

        #
        # look for available libraries

        feature = self.feature

        if feature.want('zlib'):
            _dbg('Looking for zlib')
            if _find_include_file(self, "zlib.h"):
                if _find_library_file(self, "z"):
                    feature.zlib = "z"
                elif (sys.platform == "win32" and
                      _find_library_file(self, "zlib")):
                    feature.zlib = "zlib"  # alternative name

        if feature.want('jpeg'):
            _dbg('Looking for jpeg')
            if _find_include_file(self, "jpeglib.h"):
                if _find_library_file(self, "jpeg"):
                    feature.jpeg = "jpeg"
                elif (sys.platform == "win32" and
                      _find_library_file(self, "libjpeg")):
                    feature.jpeg = "libjpeg"  # alternative name

        feature.openjpeg_version = None
        if feature.want('jpeg2000'):
            _dbg('Looking for jpeg2000')
            best_version = None
            best_path = None

            # Find the best version
            for directory in self.compiler.include_dirs:
                _dbg('Checking for openjpeg-#.# in %s', directory)
                try:
                    listdir = os.listdir(directory)
                except Exception:
                    # WindowsError, FileNotFoundError
                    continue
                for name in listdir:
                    if name.startswith('openjpeg-') and \
                        os.path.isfile(os.path.join(directory, name,
                                                    'openjpeg.h')):
                        _dbg('Found openjpeg.h in %s/%s', (directory, name))
                        version = tuple([int(x) for x in name[9:].split('.')])
                        if best_version is None or version > best_version:
                            best_version = version
                            best_path = os.path.join(directory, name)
                            _dbg('Best openjpeg version %s so far in %s',
                                 (best_version, best_path))

            if best_version and _find_library_file(self, 'openjp2'):
                # Add the directory to the include path so we can include
                # <openjpeg.h> rather than having to cope with the versioned
                # include path
                _add_directory(self.compiler.include_dirs, best_path, 0)
                feature.jpeg2000 = 'openjp2'
                feature.openjpeg_version = '.'.join([str(x) for x in
                                                     best_version])

        if feature.want('tiff'):
            _dbg('Looking for tiff')
            if _find_include_file(self, 'tiff.h'):
                if _find_library_file(self, "tiff"):
                    feature.tiff = "tiff"
                if sys.platform == "win32" and _find_library_file(self, "libtiff"):
                    feature.tiff = "libtiff"
                if (sys.platform == "darwin" and
                        _find_library_file(self, "libtiff")):
                    feature.tiff = "libtiff"

        if feature.want('freetype'):
            _dbg('Looking for freetype')
            if _find_library_file(self, "freetype"):
                # look for freetype2 include files
                freetype_version = 0
                for subdir in self.compiler.include_dirs:
                    _dbg('Checking for include file %s in %s', ("ft2build.h", subdir))
                    if os.path.isfile(os.path.join(subdir, "ft2build.h")):
                        _dbg('Found %s in %s', ("ft2build.h", subdir))
                        freetype_version = 21
                        subdir = os.path.join(subdir, "freetype2")
                        break
                    subdir = os.path.join(subdir, "freetype2")
                    _dbg('Checking for include file %s in %s', ("ft2build.h", subdir))
                    if os.path.isfile(os.path.join(subdir, "ft2build.h")):
                        _dbg('Found %s in %s', ("ft2build.h", subdir))
                        freetype_version = 21
                        break
                if freetype_version:
                    feature.freetype = "freetype"
                    feature.freetype_version = freetype_version
                    if subdir:
                        _add_directory(self.compiler.include_dirs, subdir, 0)

        if feature.want('lcms'):
            _dbg('Looking for lcms')
            if _find_include_file(self, "lcms2.h"):
                if _find_library_file(self, "lcms2"):
                    feature.lcms = "lcms2"
                elif _find_library_file(self, "lcms2_static"):
                    # alternate Windows name.
                    feature.lcms = "lcms2_static"

        if _tkinter and _find_include_file(self, "tk.h"):
            # the library names may vary somewhat (e.g. tcl85 or tcl8.5)
            version = TCL_VERSION[0] + TCL_VERSION[2]
            if feature.want('tcl'):
                _dbg('Looking for TCL')
                if _find_library_file(self, "tcl" + version):
                    feature.tcl = "tcl" + version
                elif _find_library_file(self, "tcl" + TCL_VERSION):
                    feature.tcl = "tcl" + TCL_VERSION
            if feature.want('tk'):
                _dbg('Looking for TK')
                if _find_library_file(self, "tk" + version):
                    feature.tk = "tk" + version
                elif _find_library_file(self, "tk" + TCL_VERSION):
                    feature.tk = "tk" + TCL_VERSION

        if feature.want('webp'):
            _dbg('Looking for webp')
            if (_find_include_file(self, "webp/encode.h") and
                    _find_include_file(self, "webp/decode.h")):
                # In Google's precompiled zip it is call "libwebp":
                if _find_library_file(self, "webp"):
                    feature.webp = "webp"
                elif _find_library_file(self, "libwebp"):
                    feature.webp = "libwebp"

        if feature.want('webpmux'):
            _dbg('Looking for webpmux')
            if (_find_include_file(self, "webp/mux.h") and
                    _find_include_file(self, "webp/demux.h")):
                if (_find_library_file(self, "webpmux") and
                        _find_library_file(self, "webpdemux")):
                    feature.webpmux = "webpmux"
                if (_find_library_file(self, "libwebpmux") and
                        _find_library_file(self, "libwebpdemux")):
                    feature.webpmux = "libwebpmux"

        for f in feature:
            if not getattr(feature, f) and feature.require(f):
                if f in ('jpeg', 'zlib'):
                    raise ValueError(
                        '%s is required unless explicitly disabled'
                        ' using --disable-%s, aborting' % (f, f))
                raise ValueError(
                    '--enable-%s requested but %s not found, aborting.' %
                    (f, f))

        #
        # core library

        files = ["_imaging.c"]
        for src_file in _IMAGING:
            files.append(src_file + ".c")
        for src_file in _LIB_IMAGING:
            files.append(os.path.join("libImaging", src_file + ".c"))

        libs = []
        defs = []
        if feature.jpeg:
            libs.append(feature.jpeg)
            defs.append(("HAVE_LIBJPEG", None))
        if feature.jpeg2000:
            libs.append(feature.jpeg2000)
            defs.append(("HAVE_OPENJPEG", None))
            if sys.platform == "win32":
                defs.append(("OPJ_STATIC", None))
        if feature.zlib:
            libs.append(feature.zlib)
            defs.append(("HAVE_LIBZ", None))
        if feature.tiff:
            libs.append(feature.tiff)
            defs.append(("HAVE_LIBTIFF", None))
        if sys.platform == "win32":
            libs.extend(["kernel32", "user32", "gdi32"])
        if struct.unpack("h", "\0\1".encode('ascii'))[0] == 1:
            defs.append(("WORDS_BIGENDIAN", None))

        exts = [(Extension("PIL._imaging",
                           files,
                           libraries=libs,
                           define_macros=defs))]

        #
        # additional libraries

        if feature.freetype:
            exts.append(Extension("PIL._imagingft",
                                  ["_imagingft.c"],
                                  libraries=["freetype"]))

        if feature.lcms:
            extra = []
            if sys.platform == "win32":
                extra.extend(["user32", "gdi32"])
            exts.append(Extension("PIL._imagingcms",
                                  ["_imagingcms.c"],
                                  libraries=[feature.lcms] + extra))

        if feature.webp:
            libs = [feature.webp]
            defs = []

            if feature.webpmux:
                defs.append(("HAVE_WEBPMUX", None))
                libs.append(feature.webpmux)
                libs.append(feature.webpmux.replace('pmux', 'pdemux'))

            exts.append(Extension("PIL._webp",
                                  ["_webp.c"],
                                  libraries=libs,
                                  define_macros=defs))

        if feature.tcl and feature.tk:
            if sys.platform == "darwin":
                # locate Tcl/Tk frameworks
                frameworks = []
                framework_roots = [
                    "/Library/Frameworks", "/System/Library/Frameworks"
                ]
                _dbg('Looking for TclTk Framework Build')
                for root in framework_roots:
                    root_tcl = os.path.join(root, "Tcl.framework")
                    root_tk = os.path.join(root, "Tk.framework")
                    if (os.path.exists(root_tcl) and os.path.exists(root_tk)):
                        print("--- using frameworks at %s" % root)
                        frameworks = ["-framework", "Tcl", "-framework", "Tk"]
                        subdir = os.path.join(root_tcl, "Headers")
                        _add_directory(self.compiler.include_dirs, subdir, 0)
                        subdir = os.path.join(root_tk, "Headers")
                        _add_directory(self.compiler.include_dirs, subdir, 1)
                        break
                if frameworks:
                    exts.append(Extension("PIL._imagingtk",
                                          ["_imagingtk.c", "Tk/tkImaging.c"],
                                          extra_compile_args=frameworks,
                                          extra_link_args=frameworks))
            else:
                exts.append(Extension("PIL._imagingtk",
                                      ["_imagingtk.c", "Tk/tkImaging.c"],
                                      libraries=[feature.tcl, feature.tk]))

        exts.append(Extension("PIL._imagingmath", ["_imagingmath.c"]))
        exts.append(Extension("PIL._imagingmorph", ["_imagingmorph.c"]))

        self.extensions[:] = exts

        build_ext.build_extensions(self)

        #
        # sanity and security checks

        unsafe_zlib = None

        if feature.zlib:
            unsafe_zlib = self.check_zlib_version(self.compiler.include_dirs)

        self.summary_report(feature, unsafe_zlib)
Пример #45
0
 def build_extensions(self, *args, **kargs):
     self.PETSC_ARCH_LIST = []
     _build_ext.build_extensions(self, *args, **kargs)
     if not self.PETSC_ARCH_LIST: return
     self.build_configuration(self.PETSC_ARCH_LIST)
Пример #46
0
 def build_extensions(self):
     self.compiler.initialize()
     self.compiler.compile_options.remove('/MD')
     build_ext.build_extensions(self)
Пример #47
0
    def build_extensions(self):

        global TCL_ROOT

        library_dirs = []
        include_dirs = []

        _add_directory(include_dirs, "libImaging")

        #
        # add configured kits

        for root in (TCL_ROOT, JPEG_ROOT, TIFF_ROOT, ZLIB_ROOT, FREETYPE_ROOT,
                     LCMS_ROOT):
            if isinstance(root, type(())):
                lib_root, include_root = root
            else:
                lib_root = include_root = root
            _add_directory(library_dirs, lib_root)
            _add_directory(include_dirs, include_root)

        # respect CFLAGS/LDFLAGS
        for k in ('CFLAGS', 'LDFLAGS'):
            if k in os.environ:
                for match in re.finditer(r'-I([^\s]+)', os.environ[k]):
                    _add_directory(include_dirs, match.group(1))
                for match in re.finditer(r'-L([^\s]+)', os.environ[k]):
                    _add_directory(library_dirs, match.group(1))

        # include, rpath, if set as environment variables:
        for k in ('C_INCLUDE_PATH', 'CPATH', 'INCLUDE'):
            if k in os.environ:
                for d in os.environ[k].split(os.path.pathsep):
                    _add_directory(include_dirs, d)

        for k in ('LD_RUN_PATH', 'LIBRARY_PATH', 'LIB'):
            if k in os.environ:
                for d in os.environ[k].split(os.path.pathsep):
                    _add_directory(library_dirs, d)

        prefix = sysconfig.get_config_var("prefix")
        if prefix:
            _add_directory(library_dirs, os.path.join(prefix, "lib"))
            _add_directory(include_dirs, os.path.join(prefix, "include"))

        #
        # add platform directories

        if sys.platform == "cygwin":
            # pythonX.Y.dll.a is in the /usr/lib/pythonX.Y/config directory
            _add_directory(
                library_dirs,
                os.path.join("/usr/lib", "python%s" % sys.version[:3],
                             "config"))

        elif sys.platform == "darwin":
            # attempt to make sure we pick freetype2 over other versions
            _add_directory(include_dirs, "/sw/include/freetype2")
            _add_directory(include_dirs, "/sw/lib/freetype2/include")
            # fink installation directories
            _add_directory(library_dirs, "/sw/lib")
            _add_directory(include_dirs, "/sw/include")
            # darwin ports installation directories
            _add_directory(library_dirs, "/opt/local/lib")
            _add_directory(include_dirs, "/opt/local/include")

            # if homebrew is installed, use its lib and include directories
            import subprocess
            try:
                prefix = subprocess.check_output(['brew', '--prefix'])
                if prefix:
                    prefix = prefix.strip()
                    _add_directory(library_dirs, os.path.join(prefix, 'lib'))
                    _add_directory(include_dirs,
                                   os.path.join(prefix, 'include'))

                    # freetype2 is a key-only brew under opt/
                    _add_directory(
                        library_dirs,
                        os.path.join(prefix, 'opt', 'freetype', 'lib'))
                    _add_directory(
                        include_dirs,
                        os.path.join(prefix, 'opt', 'freetype', 'include'))
            except:
                pass  # homebrew not installed

            # freetype2 ships with X11 (after homebrew, so that homebrew freetype is preferred)
            _add_directory(library_dirs, "/usr/X11/lib")
            _add_directory(include_dirs, "/usr/X11/include")

        elif sys.platform.startswith("linux"):
            for platform_ in (plat.processor(), plat.architecture()[0]):

                if not platform_:
                    continue

                if platform_ in ["x86_64", "64bit"]:
                    _add_directory(library_dirs, "/lib64")
                    _add_directory(library_dirs, "/usr/lib64")
                    _add_directory(library_dirs, "/usr/lib/x86_64-linux-gnu")
                    break
                elif platform_ in ["i386", "i686", "32bit"]:
                    _add_directory(library_dirs, "/usr/lib/i386-linux-gnu")
                    break
                elif platform_ in ["aarch64"]:
                    _add_directory(library_dirs, "/usr/lib64")
                    _add_directory(library_dirs, "/usr/lib/aarch64-linux-gnu")
                    break
                elif platform_ in ["arm", "armv7l"]:
                    _add_directory(library_dirs, "/usr/lib/arm-linux-gnueabi")
                    break
                elif platform_ in ["ppc64"]:
                    _add_directory(library_dirs, "/usr/lib64")
                    _add_directory(library_dirs, "/usr/lib/ppc64-linux-gnu")
                    _add_directory(library_dirs,
                                   "/usr/lib/powerpc64-linux-gnu")
                    break
                elif platform_ in ["ppc"]:
                    _add_directory(library_dirs, "/usr/lib/ppc-linux-gnu")
                    _add_directory(library_dirs, "/usr/lib/powerpc-linux-gnu")
                    break
                elif platform_ in ["s390x"]:
                    _add_directory(library_dirs, "/usr/lib64")
                    _add_directory(library_dirs, "/usr/lib/s390x-linux-gnu")
                    break
                elif platform_ in ["s390"]:
                    _add_directory(library_dirs, "/usr/lib/s390-linux-gnu")
                    break
            else:
                raise ValueError("Unable to identify Linux platform: `%s`" %
                                 platform_)

            # XXX Kludge. Above /\ we brute force support multiarch. Here we
            # try Barry's more general approach. Afterward, something should
            # work ;-)
            self.add_multiarch_paths()

        elif sys.platform.startswith("gnu"):
            self.add_multiarch_paths()

        elif sys.platform.startswith("netbsd"):
            _add_directory(library_dirs, "/usr/pkg/lib")
            _add_directory(include_dirs, "/usr/pkg/include")

        # FIXME: check /opt/stuff directories here?

        #
        # locate tkinter libraries

        if _tkinter:
            TCL_VERSION = _tkinter.TCL_VERSION[:3]

        if _tkinter and not TCL_ROOT:
            # we have Tkinter but the TCL_ROOT variable was not set;
            # try to locate appropriate Tcl/Tk libraries
            PYVERSION = sys.version[0] + sys.version[2]
            TCLVERSION = TCL_VERSION[0] + TCL_VERSION[2]
            roots = [
                # common installation directories, mostly for Windows
                # (for Unix-style platforms, we'll check in well-known
                # locations later)
                os.path.join("/py" + PYVERSION, "Tcl"),
                os.path.join("/python" + PYVERSION, "Tcl"),
                "/Tcl",
                "/Tcl" + TCLVERSION,
                "/Tcl" + TCL_VERSION,
                os.path.join(os.environ.get("ProgramFiles", ""), "Tcl"),
            ]
            for TCL_ROOT in roots:
                TCL_ROOT = os.path.abspath(TCL_ROOT)
                if os.path.isfile(os.path.join(TCL_ROOT, "include", "tk.h")):
                    # FIXME: use distutils logging (?)
                    print("--- using Tcl/Tk libraries at", TCL_ROOT)
                    print("--- using Tcl/Tk version", TCL_VERSION)
                    TCL_ROOT = _lib_include(TCL_ROOT)
                    break
            else:
                TCL_ROOT = None

        # add standard directories

        # look for tcl specific subdirectory (e.g debian)
        if _tkinter:
            tcl_dir = "/usr/include/tcl" + TCL_VERSION
            if os.path.isfile(os.path.join(tcl_dir, "tk.h")):
                _add_directory(include_dirs, tcl_dir)

        # standard locations
        _add_directory(library_dirs, "/usr/local/lib")
        _add_directory(include_dirs, "/usr/local/include")

        _add_directory(library_dirs, "/usr/lib")
        _add_directory(include_dirs, "/usr/include")
        _add_directory(library_dirs, "/usr/lib/i386-linux-gnu")

        #
        # insert new dirs *before* default libs, to avoid conflicts
        # between Python PYD stub libs and real libraries

        self.compiler.library_dirs = library_dirs + self.compiler.library_dirs
        self.compiler.include_dirs = include_dirs + self.compiler.include_dirs

        #
        # look for available libraries

        feature = self.feature

        if feature.want('zlib'):
            if _find_include_file(self, "zlib.h"):
                if _find_library_file(self, "z"):
                    feature.zlib = "z"
                elif sys.platform == "win32" and _find_library_file(
                        self, "zlib"):
                    feature.zlib = "zlib"  # alternative name

        if feature.want('jpeg'):
            if _find_include_file(self, "jpeglib.h"):
                if _find_library_file(self, "jpeg"):
                    feature.jpeg = "jpeg"
                elif (sys.platform == "win32"
                      and _find_library_file(self, "libjpeg")):
                    feature.jpeg = "libjpeg"  # alternative name

        if feature.want('tiff'):
            if _find_library_file(self, "tiff"):
                feature.tiff = "tiff"
            if sys.platform == "win32" and _find_library_file(self, "libtiff"):
                feature.tiff = "libtiff"
            if sys.platform == "darwin" and _find_library_file(
                    self, "libtiff"):
                feature.tiff = "libtiff"

        if feature.want('freetype'):
            if _find_library_file(self, "freetype"):
                # look for freetype2 include files
                freetype_version = 0
                for dir in self.compiler.include_dirs:
                    if os.path.isfile(os.path.join(dir, "ft2build.h")):
                        freetype_version = 21
                        dir = os.path.join(dir, "freetype2")
                        break
                    dir = os.path.join(dir, "freetype2")
                    if os.path.isfile(os.path.join(dir, "ft2build.h")):
                        freetype_version = 21
                        break
                    if os.path.isdir(os.path.join(dir, "freetype")):
                        freetype_version = 20
                        break
                if freetype_version:
                    feature.freetype = "freetype"
                    feature.freetype_version = freetype_version
                    if dir:
                        _add_directory(self.compiler.include_dirs, dir, 0)

        if feature.want('lcms'):
            if _find_include_file(self, "lcms2.h"):
                if _find_library_file(self, "lcms2"):
                    feature.lcms = "lcms"

        if _tkinter and _find_include_file(self, "tk.h"):
            # the library names may vary somewhat (e.g. tcl84 or tcl8.4)
            version = TCL_VERSION[0] + TCL_VERSION[2]
            if feature.want('tcl'):
                if _find_library_file(self, "tcl" + version):
                    feature.tcl = "tcl" + version
                elif _find_library_file(self, "tcl" + TCL_VERSION):
                    feature.tcl = "tcl" + TCL_VERSION
            if feature.want('tk'):
                if _find_library_file(self, "tk" + version):
                    feature.tk = "tk" + version
                elif _find_library_file(self, "tk" + TCL_VERSION):
                    feature.tk = "tk" + TCL_VERSION

        if feature.want('webp'):
            if (_find_include_file(self, "webp/encode.h")
                    and _find_include_file(self, "webp/decode.h")):
                if _find_library_file(
                        self, "webp"
                ):  # in googles precompiled zip it is call "libwebp"
                    feature.webp = "webp"

        if feature.want('webpmux'):
            if (_find_include_file(self, "webp/mux.h")
                    and _find_include_file(self, "webp/demux.h")):
                if _find_library_file(self, "webpmux") and _find_library_file(
                        self, "webpdemux"):
                    feature.webpmux = "webpmux"

        for f in feature:
            if not getattr(feature, f) and feature.require(f):
                raise ValueError(
                    '--enable-%s requested but %s not found, aborting.' %
                    (f, f))

        #
        # core library

        files = ["_imaging.c"]
        for file in _IMAGING:
            files.append(file + ".c")
        for file in _LIB_IMAGING:
            files.append(os.path.join("libImaging", file + ".c"))

        libs = []
        defs = []
        if feature.jpeg:
            libs.append(feature.jpeg)
            defs.append(("HAVE_LIBJPEG", None))
        if feature.zlib:
            libs.append(feature.zlib)
            defs.append(("HAVE_LIBZ", None))
        if feature.tiff:
            libs.append(feature.tiff)
            defs.append(("HAVE_LIBTIFF", None))
        if sys.platform == "win32":
            libs.extend(["kernel32", "user32", "gdi32"])
        if struct.unpack("h", "\0\1".encode('ascii'))[0] == 1:
            defs.append(("WORDS_BIGENDIAN", None))

        exts = [(Extension("PIL._imaging",
                           files,
                           libraries=libs,
                           define_macros=defs))]

        #
        # additional libraries

        if feature.freetype:
            defs = []
            if feature.freetype_version == 20:
                defs.append(("USE_FREETYPE_2_0", None))
            exts.append(
                Extension("PIL._imagingft", ["_imagingft.c"],
                          libraries=["freetype"],
                          define_macros=defs))

        if os.path.isfile("_imagingtiff.c") and feature.tiff:
            exts.append(
                Extension("PIL._imagingtiff", ["_imagingtiff.c"],
                          libraries=["tiff"]))

        if os.path.isfile("_imagingcms.c") and feature.lcms:
            extra = []
            if sys.platform == "win32":
                extra.extend(["user32", "gdi32"])
            exts.append(
                Extension("PIL._imagingcms", ["_imagingcms.c"],
                          libraries=["lcms2"] + extra))

        if os.path.isfile("_webp.c") and feature.webp:
            libs = ["webp"]
            defs = []

            if feature.webpmux:
                defs.append(("HAVE_WEBPMUX", None))
                libs.append("webpmux")
                libs.append("webpdemux")

            exts.append(
                Extension("PIL._webp", ["_webp.c"],
                          libraries=libs,
                          define_macros=defs))

        if sys.platform == "darwin":
            # locate Tcl/Tk frameworks
            frameworks = []
            framework_roots = [
                "/Library/Frameworks", "/System/Library/Frameworks"
            ]
            for root in framework_roots:
                if (os.path.exists(os.path.join(root, "Tcl.framework")) and
                        os.path.exists(os.path.join(root, "Tk.framework"))):
                    print("--- using frameworks at %s" % root)
                    frameworks = ["-framework", "Tcl", "-framework", "Tk"]
                    dir = os.path.join(root, "Tcl.framework", "Headers")
                    _add_directory(self.compiler.include_dirs, dir, 0)
                    dir = os.path.join(root, "Tk.framework", "Headers")
                    _add_directory(self.compiler.include_dirs, dir, 1)
                    break
            if frameworks:
                exts.append(
                    Extension("PIL._imagingtk",
                              ["_imagingtk.c", "Tk/tkImaging.c"],
                              extra_compile_args=frameworks,
                              extra_link_args=frameworks))
                feature.tcl = feature.tk = 1  # mark as present
        elif feature.tcl and feature.tk:
            exts.append(
                Extension("PIL._imagingtk", ["_imagingtk.c", "Tk/tkImaging.c"],
                          libraries=[feature.tcl, feature.tk]))

        if os.path.isfile("_imagingmath.c"):
            exts.append(Extension("PIL._imagingmath", ["_imagingmath.c"]))

        self.extensions[:] = exts

        build_ext.build_extensions(self)

        #
        # sanity and security checks

        unsafe_zlib = None

        if feature.zlib:
            unsafe_zlib = self.check_zlib_version(self.compiler.include_dirs)

        self.summary_report(feature, unsafe_zlib)
Пример #48
0
 def build_extensions(self):
     build_ext.build_extensions(self)
Пример #49
0
    def build_extensions(self):
        """Compile the python extension module for further installation."""
        global final_supported_archs

        ext_extra_objects = []
        ext_libs = []
        ext_libs_dir = []
        ext_includes = []

        self.platform = CustomBuildExtension.PLATFORMS.get(sys.platform, None)
        if self.platform == None:
            raise Exception("unsupported platform: %s" % sys.platform)

        if self.with_static_binutils:  # the user has specified a custom binutils distro.
            print "[+] Using specific binutils static distribution"
            print "[+]   %s" % self.with_static_binutils
            self.platform["libs"] = [
                os.path.join(self.with_static_binutils, "lib"),
            ]
            self.platform["includes"] = [
                os.path.join(self.with_static_binutils, "include"),
            ]
            self.platform["possible-lib-ext"] = [
                ".a",
            ]  # for all unix platforms.

        # check for known includes
        for inc in self.platform["includes"]:
            if self.check_includes(inc):
                self.includes = inc  # found a valid include dir with bintuils
                break
        if self.includes == None:
            raise Exception(
                "unable to determine correct include path for bfd.h / dis-asm.h"
            )

        print "[+] Using binutils headers at:"
        print "[+]   %s" % self.includes

        # we'll use this include path for building.
        ext_includes = [
            self.includes,
        ]

        # Try to guess libopcodes / libbfd libs.
        libs_dirs = self.platform["libs"]
        print "[+] Searching binutils libraries..."
        for libdir in libs_dirs:
            for possible_lib_ext in self.platform["possible-lib-ext"]:
                libs = self.find_binutils_libs(libdir, possible_lib_ext)
                if libs:
                    self.libs = libdir, libs
                    break

        if self.libs == None:
            raise Exception("unable to find binutils libraries.")

        for lib in self.libs[1]:
            print "[+]   %s" % os.path.join(self.libs[0], lib)
        #
        # check for libopcodes / libbfd
        #
        libraries_path, libs = self.libs
        if not all([
                lib.startswith("libopcodes") or lib.startswith("libbfd")
                for lib in libs
        ]):
            raise Exception(
                "missing expected library (libopcodes / libbfd) in %s." %
                libraries_path)

        ext_libs_dir.append(libraries_path)

        if self.with_static_binutils:
            # use libs as extra objects...
            ext_extra_objects.extend(
                [os.path.join(libraries_path, lib) for lib in libs])
        else:
            ext_libs = [self.prepare_libs_for_cc(lib) for lib in libs]

        # add dependecy to libiberty
        if self.with_static_binutils or sys.platform == "darwin":  # in OSX we always needs a static lib-iverty.

            lib_liberty_partialpath = [
                libraries_path,
            ]
            if sys.platform == "darwin":  # in osx the lib-iberty is prefixe by "machine" ppc/i386/x86_64
                lib_liberty_partialpath.append(self._darwin_current_arch())
            lib_liberty_partialpath.append("libiberty.a")

            lib_liberty_fullpath = os.path.join(
                *lib_liberty_partialpath)  # merge the prefix and the path
            if not os.path.isfile(lib_liberty_fullpath):
                raise Exception("missing expected library (libiberty) in %s." %
                                libraries_path)
            ext_extra_objects.append(lib_liberty_fullpath)

        # generate .py / .h files that depends of libopcodes / libbfd currently selected
        final_supported_archs = self.generate_source_files()

        # final hacks for OSX
        if sys.platform == "darwin":
            # fix arch value.
            os.environ["ARCHFLAGS"] = "-arch %s" % self._darwin_current_arch()
            # In OSX we've to link against libintl.
            ext_libs.append("intl")

            # TODO: we have to improve the detection of gettext/libintl in OSX.. this is a quick fix.
            dirs = [
                "/usr/local/opt/gettext/lib",  # homebrew
                "/opt/local/lib"  # macports
            ]
            for d in dirs:
                if os.path.exists(d):
                    ext_libs_dir.append(d)

        # fix extensions.
        for extension in self.extensions:
            extension.include_dirs.extend(ext_includes)
            extension.extra_objects.extend(ext_extra_objects)
            extension.libraries.extend(ext_libs)
            extension.library_dirs.extend(ext_libs_dir)

        return build_ext.build_extensions(self)
Пример #50
0
 def build_extensions(self):
     try:
         self.compiler.compiler_so.remove("-Wstrict-prototypes")
     except (AttributeError, ValueError):
         pass
     build_ext.build_extensions(self)
Пример #51
0
    def build_extensions(self):
        global library_dirs, include_dirs, libraries

        if WINDOWS:
            # Detect the compiler so we can specify the correct command line switches
            # and libraries
            from distutils.cygwinccompiler import Mingw32CCompiler
            extra_cc_args = []
            if isinstance(self.compiler, Mingw32CCompiler):
                # Compiler is Mingw32
                freetds_dir = 'ming'
                extra_cc_args = [
                    '-Wl,-allow-multiple-definition',
                    '-Wl,-subsystem,windows-mthreads', '-mwindows',
                    '-Wl,--strip-all'
                ]
                libraries = [
                    'libiconv',
                    'iconv',
                    'sybdb',
                    'ws2_32',
                    'wsock32',
                    'kernel32',
                ]
            else:
                # Assume compiler is Visual Studio
                if sys.version_info >= (3, 5):
                    freetds_dir = 'vs2015'
                elif sys.version_info >= (3, 3):
                    freetds_dir = 'vs2010'
                elif sys.version_info >= (2, 7) and BITNESS == 64:
                    freetds_dir = 'vs2010'
                else:
                    freetds_dir = 'vs2008'
                if LINK_FREETDS_STATICALLY:
                    libraries = [
                        'iconv',
                        'replacements',
                        'db-lib',
                        'tds',
                        'tdsutils',
                        'ws2_32',
                        'wsock32',
                        'kernel32',
                        'shell32',
                    ]
                    if LINK_OPENSSL:
                        libraries.extend([
                            'libeay{}MD'.format(BITNESS),
                            'ssleay{}MD'.format(BITNESS)
                        ])
                else:
                    libraries = [
                        'ct',
                        'sybdb',
                        'ws2_32',
                        'wsock32',
                        'kernel32',
                        'shell32',
                    ]
                    if LINK_OPENSSL:
                        libraries.extend(['libeay32MD', 'ssleay32MD'])

            FREETDS = fpath('freetds', '{0}_{1}'.format(freetds_dir, BITNESS))
            suffix = '' if BITNESS == 32 else '64'
            OPENSSL = fpath('openssl', 'lib{}'.format(suffix))
            for e in self.extensions:
                e.extra_compile_args.extend(extra_cc_args)
                e.libraries.extend(libraries)
                e.include_dirs.append(osp.join(FREETDS, 'include'))
                e.include_dirs.append(osp.join(ROOT, 'build', 'include'))
                e.library_dirs.append(osp.join(ROOT, 'build', 'lib'))
                if LINK_OPENSSL:
                    freetds_lib_dir = ''
                else:
                    freetds_lib_dir = 'lib'
                if LINK_FREETDS_STATICALLY:
                    e.library_dirs.append(osp.join(FREETDS, freetds_lib_dir))
                else:
                    e.library_dirs.append(osp.join(FREETDS, freetds_lib_dir))
                if LINK_OPENSSL:
                    e.library_dirs.append(OPENSSL)

        else:
            for e in self.extensions:
                e.libraries.extend(libraries)
        _build_ext.build_extensions(self)
Пример #52
0
 def build_extensions(self):
     self.build_options()
     build_ext.build_extensions(self)
Пример #53
0
    def build_extensions(self):

        global TCL_ROOT

        library_dirs = []
        include_dirs = []

        _add_directory(include_dirs, "libImaging")

        #
        # add configured kits

        for root in (TCL_ROOT, JPEG_ROOT, TIFF_ROOT, ZLIB_ROOT, FREETYPE_ROOT,
                     LCMS_ROOT):
            if isinstance(root, type(())):
                lib_root, include_root = root
            else:
                lib_root = include_root = root
            _add_directory(library_dirs, lib_root)
            _add_directory(include_dirs, include_root)

        #
        # add platform directories

        if sys.platform == "cygwin":
            # pythonX.Y.dll.a is in the /usr/lib/pythonX.Y/config directory
            _add_directory(
                library_dirs,
                os.path.join("/usr/lib", "python%s" % sys.version[:3],
                             "config"))

        elif sys.platform == "darwin":
            # attempt to make sure we pick freetype2 over other versions
            _add_directory(include_dirs, "/sw/include/freetype2")
            _add_directory(include_dirs, "/sw/lib/freetype2/include")
            # fink installation directories
            _add_directory(library_dirs, "/sw/lib")
            _add_directory(include_dirs, "/sw/include")
            # darwin ports installation directories
            _add_directory(library_dirs, "/opt/local/lib")
            _add_directory(include_dirs, "/opt/local/include")
            # freetype2 ships with X11
            _add_directory(library_dirs, "/usr/X11/lib")
            _add_directory(include_dirs, "/usr/X11/include")

        elif sys.platform.startswith("linux"):
            for platform_ in (platform.processor(),
                              platform.architecture()[0]):
                if not platform_: continue

                if platform_ in ["x86_64", "64bit"]:
                    _add_directory(library_dirs, "/lib64")
                    _add_directory(library_dirs, "/usr/lib64")
                    _add_directory(library_dirs, "/usr/lib/x86_64-linux-gnu")
                    break
                elif platform_ in ["i386", "i686", "32bit"]:
                    _add_directory(library_dirs, "/usr/lib/i386-linux-gnu")
                    break
            else:
                raise ValueError("Unable to identify Linux platform: `%s`" %
                                 platform_)

            # XXX Kludge. Above /\ we brute force support multiarch. Here we
            # try Barry's more general approach. Afterward, something should
            # work ;-)
            self.add_multiarch_paths()

        _add_directory(library_dirs, "/usr/local/lib")
        # FIXME: check /opt/stuff directories here?

        prefix = sysconfig.get_config_var("prefix")
        if prefix:
            _add_directory(library_dirs, os.path.join(prefix, "lib"))
            _add_directory(include_dirs, os.path.join(prefix, "include"))

        #
        # locate tkinter libraries

        if _tkinter:
            TCL_VERSION = _tkinter.TCL_VERSION[:3]

        if _tkinter and not TCL_ROOT:
            # we have Tkinter but the TCL_ROOT variable was not set;
            # try to locate appropriate Tcl/Tk libraries
            PYVERSION = sys.version[0] + sys.version[2]
            TCLVERSION = TCL_VERSION[0] + TCL_VERSION[2]
            roots = [
                # common installation directories, mostly for Windows
                # (for Unix-style platforms, we'll check in well-known
                # locations later)
                os.path.join("/py" + PYVERSION, "Tcl"),
                os.path.join("/python" + PYVERSION, "Tcl"),
                "/Tcl",
                "/Tcl" + TCLVERSION,
                "/Tcl" + TCL_VERSION,
                os.path.join(os.environ.get("ProgramFiles", ""), "Tcl"),
            ]
            for TCL_ROOT in roots:
                TCL_ROOT = os.path.abspath(TCL_ROOT)
                if os.path.isfile(os.path.join(TCL_ROOT, "include", "tk.h")):
                    # FIXME: use distutils logging (?)
                    print("--- using Tcl/Tk libraries at", TCL_ROOT)
                    print("--- using Tcl/Tk version", TCL_VERSION)
                    TCL_ROOT = _lib_include(TCL_ROOT)
                    break
            else:
                TCL_ROOT = None

        #
        # add standard directories

        # look for tcl specific subdirectory (e.g debian)
        if _tkinter:
            tcl_dir = "/usr/include/tcl" + TCL_VERSION
            if os.path.isfile(os.path.join(tcl_dir, "tk.h")):
                _add_directory(include_dirs, tcl_dir)

        # standard locations
        _add_directory(library_dirs, "/usr/local/lib")
        _add_directory(include_dirs, "/usr/local/include")

        _add_directory(library_dirs, "/usr/lib")
        _add_directory(include_dirs, "/usr/include")

        #
        # insert new dirs *before* default libs, to avoid conflicts
        # between Python PYD stub libs and real libraries

        self.compiler.library_dirs = library_dirs + self.compiler.library_dirs
        self.compiler.include_dirs = include_dirs + self.compiler.include_dirs

        #
        # look for available libraries

        class feature:
            zlib = jpeg = tiff = freetype = tcl = tk = lcms = webp = None

        feature = feature()

        if _find_include_file(self, "zlib.h"):
            if _find_library_file(self, "z"):
                feature.zlib = "z"
            elif sys.platform == "win32" and _find_library_file(self, "zlib"):
                feature.zlib = "zlib"  # alternative name

        if _find_include_file(self, "jpeglib.h"):
            if _find_library_file(self, "jpeg"):
                feature.jpeg = "jpeg"
            elif sys.platform == "win32" and _find_library_file(
                    self, "libjpeg"):
                feature.jpeg = "libjpeg"  # alternative name

        if _find_library_file(self, "tiff"):
            feature.tiff = "tiff"
        if sys.platform == "win32" and _find_library_file(self, "libtiff"):
            feature.tiff = "libtiff"
        if sys.platform == "darwin" and _find_library_file(self, "libtiff"):
            feature.tiff = "libtiff"

        if _find_library_file(self, "freetype"):
            # look for freetype2 include files
            freetype_version = 0
            for dir in self.compiler.include_dirs:
                if os.path.isfile(os.path.join(dir, "ft2build.h")):
                    freetype_version = 21
                    dir = os.path.join(dir, "freetype2")
                    break
                dir = os.path.join(dir, "freetype2")
                if os.path.isfile(os.path.join(dir, "ft2build.h")):
                    freetype_version = 21
                    break
                if os.path.isdir(os.path.join(dir, "freetype")):
                    freetype_version = 20
                    break
            if freetype_version:
                feature.freetype = "freetype"
                feature.freetype_version = freetype_version
                if dir:
                    _add_directory(self.compiler.include_dirs, dir, 0)

        if _find_include_file(self, "lcms.h"):
            if _find_library_file(self, "lcms"):
                feature.lcms = "lcms"

        if _tkinter and _find_include_file(self, "tk.h"):
            # the library names may vary somewhat (e.g. tcl84 or tcl8.4)
            version = TCL_VERSION[0] + TCL_VERSION[2]
            if _find_library_file(self, "tcl" + version):
                feature.tcl = "tcl" + version
            elif _find_library_file(self, "tcl" + TCL_VERSION):
                feature.tcl = "tcl" + TCL_VERSION
            if _find_library_file(self, "tk" + version):
                feature.tk = "tk" + version
            elif _find_library_file(self, "tk" + TCL_VERSION):
                feature.tk = "tk" + TCL_VERSION

        if _find_include_file(self, "webp/encode.h") and _find_include_file(
                self, "webp/decode.h"):
            if _find_library_file(self, "webp"):
                feature.webp = "webp"

        #
        # core library

        files = ["_imaging.c"]
        for file in _IMAGING:
            files.append(file + ".c")
        for file in _LIB_IMAGING:
            files.append(os.path.join("libImaging", file + ".c"))

        libs = []
        defs = []
        if feature.jpeg:
            libs.append(feature.jpeg)
            defs.append(("HAVE_LIBJPEG", None))
        if feature.zlib:
            libs.append(feature.zlib)
            defs.append(("HAVE_LIBZ", None))
        if feature.tiff:
            libs.append(feature.tiff)
            defs.append(("HAVE_LIBTIFF", None))
        if sys.platform == "win32":
            libs.extend(["kernel32", "user32", "gdi32"])
        if struct.unpack("h", "\0\1".encode('ascii'))[0] == 1:
            defs.append(("WORDS_BIGENDIAN", None))

        exts = [(Extension("_imaging",
                           files,
                           libraries=libs,
                           define_macros=defs))]

        #
        # additional libraries

        if feature.freetype:
            defs = []
            if feature.freetype_version == 20:
                defs.append(("USE_FREETYPE_2_0", None))
            exts.append(
                Extension("_imagingft", ["_imagingft.c"],
                          libraries=["freetype"],
                          define_macros=defs))

        if os.path.isfile("_imagingtiff.c") and feature.tiff:
            exts.append(
                Extension("_imagingtiff", ["_imagingtiff.c"],
                          libraries=["tiff"]))

        if os.path.isfile("_imagingcms.c") and feature.lcms:
            extra = []
            if sys.platform == "win32":
                extra.extend(["user32", "gdi32"])
            exts.append(
                Extension("_imagingcms", ["_imagingcms.c"],
                          libraries=["lcms"] + extra))

        if os.path.isfile("_webp.c") and feature.webp:
            exts.append(Extension("_webp", ["_webp.c"], libraries=["webp"]))

        if sys.platform == "darwin":
            # locate Tcl/Tk frameworks
            frameworks = []
            framework_roots = [
                "/Library/Frameworks", "/System/Library/Frameworks"
            ]
            for root in framework_roots:
                if (os.path.exists(os.path.join(root, "Tcl.framework")) and
                        os.path.exists(os.path.join(root, "Tk.framework"))):
                    print("--- using frameworks at %s" % root)
                    frameworks = ["-framework", "Tcl", "-framework", "Tk"]
                    dir = os.path.join(root, "Tcl.framework", "Headers")
                    _add_directory(self.compiler.include_dirs, dir, 0)
                    dir = os.path.join(root, "Tk.framework", "Headers")
                    _add_directory(self.compiler.include_dirs, dir, 1)
                    break
            if frameworks:
                exts.append(
                    Extension("_imagingtk", ["_imagingtk.c", "Tk/tkImaging.c"],
                              extra_compile_args=frameworks,
                              extra_link_args=frameworks))
                feature.tcl = feature.tk = 1  # mark as present
        elif feature.tcl and feature.tk:
            exts.append(
                Extension("_imagingtk", ["_imagingtk.c", "Tk/tkImaging.c"],
                          libraries=[feature.tcl, feature.tk]))

        if os.path.isfile("_imagingmath.c"):
            exts.append(Extension("_imagingmath", ["_imagingmath.c"]))

        self.extensions[:] = exts

        build_ext.build_extensions(self)

        #
        # sanity and security checks

        unsafe_zlib = None

        if feature.zlib:
            unsafe_zlib = self.check_zlib_version(self.compiler.include_dirs)

        self.summary_report(feature, unsafe_zlib)
Пример #54
0
    def build_extensions(self):
        #
        # add platform directories

        if sys.platform == "cygwin":
            # pythonX.Y.dll.a is in the /usr/lib/pythonX.Y/config directory
            add_directory(library_dirs, os.path.join(
                "/usr/lib", "python%s" % sys.version[:3], "config"))

        elif sys.platform == "darwin":
            # attempt to make sure we pick freetype2 over other versions
            add_directory(include_dirs, "/sw/include/freetype2")
            add_directory(include_dirs, "/sw/lib/freetype2/include")
            # fink installation directories
            add_directory(library_dirs, "/sw/lib")
            add_directory(include_dirs, "/sw/include")
            # darwin ports installation directories
            add_directory(library_dirs, "/opt/local/lib")
            add_directory(include_dirs, "/opt/local/include")
            # freetype2 ships with X11
            add_directory(library_dirs, "/usr/X11/lib")
            add_directory(include_dirs, "/usr/X11/include")
            # if homebrew is installed, use its lib and include directories
            import subprocess
            try:
                prefix = subprocess.check_output(['brew', '--prefix'])
                if prefix:
                    prefix = prefix.strip()
                    add_directory(library_dirs, os.path.join(prefix, 'lib'))
                    add_directory(include_dirs, os.path.join(prefix, 'include'))
            except:
                pass # homebrew not installed

        elif sys.platform.startswith("linux"):
            for platform_ in (plat.processor(), plat.architecture()[0]):

                if not platform_:
                    continue

                if platform_ in ["x86_64", "64bit"]:
                    add_directory(library_dirs, "/lib64")
                    add_directory(library_dirs, "/usr/lib64")
                    add_directory(library_dirs, "/usr/lib/x86_64-linux-gnu")
                    break
                elif platform_ in ["i386", "i686", "32bit"]:
                    add_directory(library_dirs, "/usr/lib/i386-linux-gnu")
                    break
            else:
                raise ValueError(
                    "Unable to identify Linux platform: `%s`" % platform_)

            # XXX Kludge. Above /\ we brute force support multiarch. Here we
            # try Barry's more general approach. Afterward, something should
            # work ;-)
            self.add_multiarch_paths()

        add_directory(library_dirs, "/usr/local/lib")

        prefix = sysconfig.get_config_var("prefix")
        if prefix:
            add_directory(library_dirs, os.path.join(prefix, "lib"))
            add_directory(include_dirs, os.path.join(prefix, "include"))

        #
        # add configured kits
        if isinstance(FREETYPE_ROOT, tuple):
            lib_root, include_root = FREETYPE_ROOT
        else:
            lib_root = include_root = FREETYPE_ROOT
        add_directory(library_dirs, lib_root)
        add_directory(include_dirs, include_root)

        #
        # add standard directories
        # standard locations
        add_directory(library_dirs, "/usr/local/lib")
        add_directory(include_dirs, "/usr/local/include")

        add_directory(library_dirs, "/usr/lib")
        add_directory(include_dirs, "/usr/include")

        #
        # insert new dirs *before* default libs, to avoid conflicts
        # between Python PYD stub libs and real libraries

        self.compiler.library_dirs = library_dirs + self.compiler.library_dirs
        self.compiler.include_dirs = include_dirs + self.compiler.include_dirs

        #
        # look for available libraries

        class feature:
            freetype = None
        feature = feature()

        if find_library_file(self, "freetype"):
            # look for freetype2 include files
            freetype_version = 0
            for dir in self.compiler.include_dirs:
                if os.path.isfile(os.path.join(dir, "ft2build.h")):
                    freetype_version = 21
                    dir = os.path.join(dir, "freetype2")
                    break
                dir = os.path.join(dir, "freetype2")
                if os.path.isfile(os.path.join(dir, "ft2build.h")):
                    freetype_version = 21
                    break
                if os.path.isdir(os.path.join(dir, "freetype")):
                    freetype_version = 20
                    break
            if freetype_version:
                feature.freetype = "freetype"
                feature.freetype_version = freetype_version
                if dir:
                    add_directory(self.compiler.include_dirs, dir, 0)

        libs = []
        if sys.platform == "win32":
            libs.extend(["kernel32", "user32", "gdi32"])
        if struct.unpack("h", "\0\1")[0] == 1:
            defines.append(("WORDS_BIGENDIAN", None))

        #
        # additional libraries
        if feature.freetype:
            sources.append("agg2/font_freetype/agg_font_freetype.cpp")
            include_dirs.append("agg2/font_freetype")
            libraries.append("freetype")

            defines.append(("HAVE_FREETYPE2", None))
            if feature.freetype_version == 20:
                defines.append(("USE_FREETYPE_2_0", None))
        build_ext.build_extensions(self)

        #
        # sanity and security checks
        self.summary_report(feature)
    def build_extensions(self):

        # Detect which modules should be compiled
        old_so = self.compiler.shared_lib_extension
        # Workaround PEP 3149 stuff
        self.compiler.shared_lib_extension = os.environ.get("SO", ".so")
        try:
            missing = self.detect_modules()
        finally:
            self.compiler.shared_lib_extension = old_so

        # Remove modules that are present on the disabled list
        extensions = [
            ext for ext in self.extensions
            if ext.name not in disabled_module_list
        ]
        # move ctypes to the end, it depends on other modules
        ext_map = dict((ext.name, i) for i, ext in enumerate(extensions))
        if "_ctypes" in ext_map:
            ctypes = extensions.pop(ext_map["_ctypes"])
            extensions.append(ctypes)
        self.extensions = extensions

        # Fix up the autodetected modules, prefixing all the source files
        # with Modules/.
        srcdir = sysconfig.get_config_var('srcdir')
        if not srcdir:
            # Maybe running on Windows but not using CYGWIN?
            raise ValueError("No source directory; cannot proceed.")
        srcdir = os.path.abspath(srcdir)
        moddirlist = [os.path.join(srcdir, 'Modules')]

        # Fix up the paths for scripts, too
        self.distribution.scripts = [
            os.path.join(srcdir, filename)
            for filename in self.distribution.scripts
        ]

        # Python header files
        headers = [sysconfig.get_config_h_filename()]
        headers += glob(os.path.join(sysconfig.get_path('include'), "*.h"))

        for ext in self.extensions[:]:
            ext.sources = [
                find_module_file(filename, moddirlist)
                for filename in ext.sources
            ]
            if ext.depends is not None:
                ext.depends = [
                    find_module_file(filename, moddirlist)
                    for filename in ext.depends
                ]
            else:
                ext.depends = []
            # re-compile extensions if a header file has been changed
            ext.depends.extend(headers)

            # If a module has already been built statically,
            # don't build it here
            if ext.name in sys.builtin_module_names:
                self.extensions.remove(ext)

        # Parse Modules/Setup and Modules/Setup.local to figure out which
        # modules are turned on in the file.
        remove_modules = []
        for filename in ('Modules/Setup', 'Modules/Setup.local'):
            input = text_file.TextFile(filename, join_lines=1)
            while 1:
                line = input.readline()
                if not line: break
                line = line.split()
                remove_modules.append(line[0])
            input.close()

        for ext in self.extensions[:]:
            if ext.name in remove_modules:
                self.extensions.remove(ext)

        # When you run "make CC=altcc" or something similar, you really want
        # those environment variables passed into the setup.py phase.  Here's
        # a small set of useful ones.
        compiler = os.environ.get('CC')
        args = {}
        # unfortunately, distutils doesn't let us provide separate C and C++
        # compilers
        if compiler is not None:
            (ccshared, cppflags, cflags) = \
                sysconfig.get_config_vars('CCSHARED', 'CPPFLAGS', 'CFLAGS')
            cppflags = ' '.join(
                [f for f in cppflags.split() if not f.startswith('-I')])
            args[
                'compiler_so'] = compiler + ' ' + ccshared + ' ' + cppflags + ' ' + cflags
        self.compiler.set_executables(**args)

        build_ext.build_extensions(self)

        longest = max([len(e.name) for e in self.extensions])
        if self.failed:
            longest = max(longest, max([len(name) for name in self.failed]))

        def print_three_column(lst):
            lst.sort(key=str.lower)
            # guarantee zip() doesn't drop anything
            while len(lst) % 3:
                lst.append("")
            for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]):
                print("%-*s   %-*s   %-*s" %
                      (longest, e, longest, f, longest, g))

        if missing:
            print()
            print("Python build finished, but the necessary bits to build "
                  "these modules were not found:")
            print_three_column(missing)
            print("To find the necessary bits, look in setup.py in"
                  " detect_modules() for the module's name.")
            print()

        if self.failed:
            failed = self.failed[:]
            print()
            print("Failed to build these modules:")
            print_three_column(failed)
            print()
Пример #56
0
 def build_extensions(self):
     # we're going to need to switch between compilers, so lets save both
     self.default_compiler = self.compiler
     self.nvcc = NVCC()
     build_ext.build_extensions(self)
Пример #57
0
    def build_extensions(self):

        library_dirs = []
        include_dirs = []

        _add_directory(include_dirs, "src/libImaging")

        pkg_config = None
        if _cmd_exists(os.environ.get("PKG_CONFIG", "pkg-config")):
            pkg_config = _pkg_config

        #
        # add configured kits
        for root_name, lib_name in dict(
                JPEG_ROOT="libjpeg",
                JPEG2K_ROOT="libopenjp2",
                TIFF_ROOT=("libtiff-5", "libtiff-4"),
                ZLIB_ROOT="zlib",
                FREETYPE_ROOT="freetype2",
                LCMS_ROOT="lcms2",
                IMAGEQUANT_ROOT="libimagequant",
        ).items():
            root = globals()[root_name]

            if root is None and root_name in os.environ:
                prefix = os.environ[root_name]
                root = (os.path.join(prefix,
                                     "lib"), os.path.join(prefix, "include"))

            if root is None and pkg_config:
                if isinstance(lib_name, tuple):
                    for lib_name2 in lib_name:
                        _dbg("Looking for `%s` using pkg-config." % lib_name2)
                        root = pkg_config(lib_name2)
                        if root:
                            break
                else:
                    _dbg("Looking for `%s` using pkg-config." % lib_name)
                    root = pkg_config(lib_name)

            if isinstance(root, tuple):
                lib_root, include_root = root
            else:
                lib_root = include_root = root

            _add_directory(library_dirs, lib_root)
            _add_directory(include_dirs, include_root)

        # respect CFLAGS/CPPFLAGS/LDFLAGS
        for k in ("CFLAGS", "CPPFLAGS", "LDFLAGS"):
            if k in os.environ:
                for match in re.finditer(r"-I([^\s]+)", os.environ[k]):
                    _add_directory(include_dirs, match.group(1))
                for match in re.finditer(r"-L([^\s]+)", os.environ[k]):
                    _add_directory(library_dirs, match.group(1))

        # include, rpath, if set as environment variables:
        for k in ("C_INCLUDE_PATH", "CPATH", "INCLUDE"):
            if k in os.environ:
                for d in os.environ[k].split(os.path.pathsep):
                    _add_directory(include_dirs, d)

        for k in ("LD_RUN_PATH", "LIBRARY_PATH", "LIB"):
            if k in os.environ:
                for d in os.environ[k].split(os.path.pathsep):
                    _add_directory(library_dirs, d)

        prefix = sysconfig.get_config_var("prefix")
        if prefix:
            _add_directory(library_dirs, os.path.join(prefix, "lib"))
            _add_directory(include_dirs, os.path.join(prefix, "include"))

        #
        # add platform directories

        if self.disable_platform_guessing:
            pass

        elif sys.platform == "cygwin":
            # pythonX.Y.dll.a is in the /usr/lib/pythonX.Y/config directory
            _add_directory(
                library_dirs,
                os.path.join("/usr/lib",
                             "python{}.{}".format(*sys.version_info),
                             "config"),
            )

        elif sys.platform == "darwin":
            # attempt to make sure we pick freetype2 over other versions
            _add_directory(include_dirs, "/sw/include/freetype2")
            _add_directory(include_dirs, "/sw/lib/freetype2/include")
            # fink installation directories
            _add_directory(library_dirs, "/sw/lib")
            _add_directory(include_dirs, "/sw/include")
            # darwin ports installation directories
            _add_directory(library_dirs, "/opt/local/lib")
            _add_directory(include_dirs, "/opt/local/include")

            # if Homebrew is installed, use its lib and include directories
            try:
                prefix = (subprocess.check_output(["brew", "--prefix"
                                                   ]).strip().decode("latin1"))
            except Exception:
                # Homebrew not installed
                prefix = None

            ft_prefix = None

            if prefix:
                # add Homebrew's include and lib directories
                _add_directory(library_dirs, os.path.join(prefix, "lib"))
                _add_directory(include_dirs, os.path.join(prefix, "include"))
                ft_prefix = os.path.join(prefix, "opt", "freetype")

            if ft_prefix and os.path.isdir(ft_prefix):
                # freetype might not be linked into Homebrew's prefix
                _add_directory(library_dirs, os.path.join(ft_prefix, "lib"))
                _add_directory(include_dirs,
                               os.path.join(ft_prefix, "include"))
            else:
                # fall back to freetype from XQuartz if
                # Homebrew's freetype is missing
                _add_directory(library_dirs, "/usr/X11/lib")
                _add_directory(include_dirs, "/usr/X11/include")

        elif (sys.platform.startswith("linux")
              or sys.platform.startswith("gnu")
              or sys.platform.startswith("freebsd")):
            for dirname in _find_library_dirs_ldconfig():
                _add_directory(library_dirs, dirname)
            if sys.platform.startswith("linux") and os.environ.get(
                    "ANDROID_ROOT", None):
                # termux support for android.
                # system libraries (zlib) are installed in /system/lib
                # headers are at $PREFIX/include
                # user libs are at $PREFIX/lib
                _add_directory(library_dirs,
                               os.path.join(os.environ["ANDROID_ROOT"], "lib"))

        elif sys.platform.startswith("netbsd"):
            _add_directory(library_dirs, "/usr/pkg/lib")
            _add_directory(include_dirs, "/usr/pkg/include")

        elif sys.platform.startswith("sunos5"):
            _add_directory(library_dirs, "/opt/local/lib")
            _add_directory(include_dirs, "/opt/local/include")

        # FIXME: check /opt/stuff directories here?

        # standard locations
        if not self.disable_platform_guessing:
            _add_directory(library_dirs, "/usr/local/lib")
            _add_directory(include_dirs, "/usr/local/include")

            _add_directory(library_dirs, "/usr/lib")
            _add_directory(include_dirs, "/usr/include")
            # alpine, at least
            _add_directory(library_dirs, "/lib")

        if sys.platform == "win32":
            if PLATFORM_MINGW:
                _add_directory(include_dirs,
                               "C:\\msys64\\mingw32\\include\\libimagequant")

            # on Windows, look for the OpenJPEG libraries in the location that
            # the official installer puts them
            program_files = os.environ.get("ProgramFiles", "")
            best_version = (0, 0)
            best_path = None
            for name in os.listdir(program_files):
                if name.startswith("OpenJPEG "):
                    version = tuple(
                        int(x) for x in name[9:].strip().split("."))
                    if version > best_version:
                        best_version = version
                        best_path = os.path.join(program_files, name)

            if best_path:
                _dbg("Adding %s to search list", best_path)
                _add_directory(library_dirs, os.path.join(best_path, "lib"))
                _add_directory(include_dirs,
                               os.path.join(best_path, "include"))

        #
        # insert new dirs *before* default libs, to avoid conflicts
        # between Python PYD stub libs and real libraries

        self.compiler.library_dirs = library_dirs + self.compiler.library_dirs
        self.compiler.include_dirs = include_dirs + self.compiler.include_dirs

        #
        # look for available libraries

        feature = self.feature

        if feature.want("zlib"):
            _dbg("Looking for zlib")
            if _find_include_file(self, "zlib.h"):
                if _find_library_file(self, "z"):
                    feature.zlib = "z"
                elif sys.platform == "win32" and _find_library_file(
                        self, "zlib"):
                    feature.zlib = "zlib"  # alternative name

        if feature.want("jpeg"):
            _dbg("Looking for jpeg")
            if _find_include_file(self, "jpeglib.h"):
                if _find_library_file(self, "jpeg"):
                    feature.jpeg = "jpeg"
                elif sys.platform == "win32" and _find_library_file(
                        self, "libjpeg"):
                    feature.jpeg = "libjpeg"  # alternative name

        feature.openjpeg_version = None
        if feature.want("jpeg2000"):
            _dbg("Looking for jpeg2000")
            best_version = None
            best_path = None

            # Find the best version
            for directory in self.compiler.include_dirs:
                _dbg("Checking for openjpeg-#.# in %s", directory)
                try:
                    listdir = os.listdir(directory)
                except Exception:
                    # WindowsError, FileNotFoundError
                    continue
                for name in listdir:
                    if name.startswith("openjpeg-") and os.path.isfile(
                            os.path.join(directory, name, "openjpeg.h")):
                        _dbg("Found openjpeg.h in %s/%s", (directory, name))
                        version = tuple(int(x) for x in name[9:].split("."))
                        if best_version is None or version > best_version:
                            best_version = version
                            best_path = os.path.join(directory, name)
                            _dbg(
                                "Best openjpeg version %s so far in %s",
                                (best_version, best_path),
                            )

            if best_version and _find_library_file(self, "openjp2"):
                # Add the directory to the include path so we can include
                # <openjpeg.h> rather than having to cope with the versioned
                # include path
                # FIXME (melvyn-sopacua):
                # At this point it's possible that best_path is already in
                # self.compiler.include_dirs. Should investigate how that is
                # possible.
                _add_directory(self.compiler.include_dirs, best_path, 0)
                feature.jpeg2000 = "openjp2"
                feature.openjpeg_version = ".".join(
                    str(x) for x in best_version)

        if feature.want("imagequant"):
            _dbg("Looking for imagequant")
            if _find_include_file(self, "libimagequant.h"):
                if _find_library_file(self, "imagequant"):
                    feature.imagequant = "imagequant"
                elif _find_library_file(self, "libimagequant"):
                    feature.imagequant = "libimagequant"

        if feature.want("tiff"):
            _dbg("Looking for tiff")
            if _find_include_file(self, "tiff.h"):
                if _find_library_file(self, "tiff"):
                    feature.tiff = "tiff"
                if sys.platform in ["win32", "darwin"] and _find_library_file(
                        self, "libtiff"):
                    feature.tiff = "libtiff"

        if feature.want("freetype"):
            _dbg("Looking for freetype")
            if _find_library_file(self, "freetype"):
                # look for freetype2 include files
                freetype_version = 0
                for subdir in self.compiler.include_dirs:
                    _dbg("Checking for include file %s in %s",
                         ("ft2build.h", subdir))
                    if os.path.isfile(os.path.join(subdir, "ft2build.h")):
                        _dbg("Found %s in %s", ("ft2build.h", subdir))
                        freetype_version = 21
                        subdir = os.path.join(subdir, "freetype2")
                        break
                    subdir = os.path.join(subdir, "freetype2")
                    _dbg("Checking for include file %s in %s",
                         ("ft2build.h", subdir))
                    if os.path.isfile(os.path.join(subdir, "ft2build.h")):
                        _dbg("Found %s in %s", ("ft2build.h", subdir))
                        freetype_version = 21
                        break
                if freetype_version:
                    feature.freetype = "freetype"
                    if subdir:
                        _add_directory(self.compiler.include_dirs, subdir, 0)

        if feature.want("lcms"):
            _dbg("Looking for lcms")
            if _find_include_file(self, "lcms2.h"):
                if _find_library_file(self, "lcms2"):
                    feature.lcms = "lcms2"
                elif _find_library_file(self, "lcms2_static"):
                    # alternate Windows name.
                    feature.lcms = "lcms2_static"

        if feature.want("webp"):
            _dbg("Looking for webp")
            if _find_include_file(self,
                                  "webp/encode.h") and _find_include_file(
                                      self, "webp/decode.h"):
                # In Google's precompiled zip it is call "libwebp":
                if _find_library_file(self, "webp"):
                    feature.webp = "webp"
                elif _find_library_file(self, "libwebp"):
                    feature.webp = "libwebp"

        if feature.want("webpmux"):
            _dbg("Looking for webpmux")
            if _find_include_file(self, "webp/mux.h") and _find_include_file(
                    self, "webp/demux.h"):
                if _find_library_file(self, "webpmux") and _find_library_file(
                        self, "webpdemux"):
                    feature.webpmux = "webpmux"
                if _find_library_file(self,
                                      "libwebpmux") and _find_library_file(
                                          self, "libwebpdemux"):
                    feature.webpmux = "libwebpmux"

        for f in feature:
            if not getattr(feature, f) and feature.require(f):
                if f in ("jpeg", "zlib"):
                    raise RequiredDependencyException(f)
                raise DependencyException(f)

        #
        # core library

        files = ["src/_imaging.c"]
        for src_file in _IMAGING:
            files.append("src/" + src_file + ".c")
        for src_file in _LIB_IMAGING:
            files.append(os.path.join("src/libImaging", src_file + ".c"))

        libs = self.add_imaging_libs.split()
        defs = []
        if feature.jpeg:
            libs.append(feature.jpeg)
            defs.append(("HAVE_LIBJPEG", None))
        if feature.jpeg2000:
            libs.append(feature.jpeg2000)
            defs.append(("HAVE_OPENJPEG", None))
            if sys.platform == "win32":
                defs.append(("OPJ_STATIC", None))
        if feature.zlib:
            libs.append(feature.zlib)
            defs.append(("HAVE_LIBZ", None))
        if feature.imagequant:
            libs.append(feature.imagequant)
            defs.append(("HAVE_LIBIMAGEQUANT", None))
        if feature.tiff:
            libs.append(feature.tiff)
            defs.append(("HAVE_LIBTIFF", None))
        if sys.platform == "win32":
            libs.extend(["kernel32", "user32", "gdi32"])
        if struct.unpack("h", "\0\1".encode("ascii"))[0] == 1:
            defs.append(("WORDS_BIGENDIAN", None))

        if sys.platform == "win32" and not (PLATFORM_PYPY or PLATFORM_MINGW):
            defs.append(("PILLOW_VERSION", '"\\"%s\\""' % PILLOW_VERSION))
        else:
            defs.append(("PILLOW_VERSION", '"%s"' % PILLOW_VERSION))

        exts = [(Extension("PIL._imaging",
                           files,
                           libraries=libs,
                           define_macros=defs))]

        #
        # additional libraries

        if feature.freetype:
            libs = ["freetype"]
            defs = []
            exts.append(
                Extension(
                    "PIL._imagingft",
                    ["src/_imagingft.c"],
                    libraries=libs,
                    define_macros=defs,
                ))

        if feature.lcms:
            extra = []
            if sys.platform == "win32":
                extra.extend(["user32", "gdi32"])
            exts.append(
                Extension(
                    "PIL._imagingcms",
                    ["src/_imagingcms.c"],
                    libraries=[feature.lcms] + extra,
                ))

        if feature.webp:
            libs = [feature.webp]
            defs = []

            if feature.webpmux:
                defs.append(("HAVE_WEBPMUX", None))
                libs.append(feature.webpmux)
                libs.append(feature.webpmux.replace("pmux", "pdemux"))

            exts.append(
                Extension("PIL._webp", ["src/_webp.c"],
                          libraries=libs,
                          define_macros=defs))

        tk_libs = ["psapi"] if sys.platform == "win32" else []
        exts.append(
            Extension(
                "PIL._imagingtk",
                ["src/_imagingtk.c", "src/Tk/tkImaging.c"],
                include_dirs=["src/Tk"],
                libraries=tk_libs,
            ))

        exts.append(Extension("PIL._imagingmath", ["src/_imagingmath.c"]))
        exts.append(Extension("PIL._imagingmorph", ["src/_imagingmorph.c"]))

        self.extensions[:] = exts

        build_ext.build_extensions(self)

        #
        # sanity checks

        self.summary_report(feature)
Пример #58
0
 def build_extensions(self):
     for ext in self.extensions:
         cythonize(ext)
     build_ext.build_extensions(self)
Пример #59
0
 def build_extensions(self):
     # TODO: move build customization here?
     build_ext.build_extensions(self)