~ubuntu-branches/ubuntu/trusty/pillow/trusty

« back to all changes in this revision

Viewing changes to .pc/lcms2.diff/setup.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-12-16 15:29:17 UTC
  • mfrom: (5.1.1 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131216152917-gh1s5ebev138eeo1
Tags: 2.2.1-3ubuntu2
Include test images for the lcms2 support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# > pyroma .
 
2
# ------------------------------
 
3
# Checking .
 
4
# Found Pillow
 
5
# ------------------------------
 
6
# Final rating: 10/10
 
7
# Your cheese is so fresh most people think it's a cream: Mascarpone
 
8
# ------------------------------
 
9
from __future__ import print_function
 
10
import glob
 
11
import os
 
12
import platform as plat
 
13
import re
 
14
import struct
 
15
import sys
 
16
 
 
17
from distutils.command.build_ext import build_ext
 
18
try:
 
19
    import sysconfig
 
20
    host_platform = sysconfig.get_platform()
 
21
except:
 
22
    from distutils import sysconfig
 
23
    host_platform = sys.platform
 
24
 
 
25
from setuptools import Extension, setup, find_packages
 
26
 
 
27
 
 
28
_IMAGING = (
 
29
    "decode", "encode", "map", "display", "outline", "path")
 
30
 
 
31
_LIB_IMAGING = (
 
32
    "Access", "AlphaComposite", "Antialias", "Bands", "BitDecode", "Blend",
 
33
    "Chops", "Convert", "ConvertYCbCr", "Copy", "Crc32", "Crop", "Dib", "Draw",
 
34
    "Effects", "EpsEncode", "File", "Fill", "Filter", "FliDecode",
 
35
    "Geometry", "GetBBox", "GifDecode", "GifEncode", "HexDecode",
 
36
    "Histo", "JpegDecode", "JpegEncode", "LzwDecode", "Matrix",
 
37
    "ModeFilter", "MspDecode", "Negative", "Offset", "Pack",
 
38
    "PackDecode", "Palette", "Paste", "Quant", "QuantOctree", "QuantHash",
 
39
    "QuantHeap", "PcdDecode", "PcxDecode", "PcxEncode", "Point",
 
40
    "RankFilter", "RawDecode", "RawEncode", "Storage", "SunRleDecode",
 
41
    "TgaRleDecode", "Unpack", "UnpackYCC", "UnsharpMask", "XbmDecode",
 
42
    "XbmEncode", "ZipDecode", "ZipEncode", "TiffDecode")
 
43
 
 
44
 
 
45
def _add_directory(path, dir, where=None):
 
46
    if dir and os.path.isdir(dir) and dir not in path:
 
47
        if where is None:
 
48
            path.append(dir)
 
49
        else:
 
50
            path.insert(where, dir)
 
51
 
 
52
 
 
53
def _find_include_file(self, include):
 
54
    for directory in self.compiler.include_dirs:
 
55
        if os.path.isfile(os.path.join(directory, include)):
 
56
            return 1
 
57
    return 0
 
58
 
 
59
 
 
60
def _find_library_file(self, library):
 
61
    # Fix for 3.2.x <3.2.4, 3.3.0, shared lib extension is the python shared
 
62
    # lib extension, not the system shared lib extension: e.g. .cpython-33.so
 
63
    # vs .so. See Python bug http://bugs.python.org/16754
 
64
    if 'cpython' in self.compiler.shared_lib_extension:
 
65
        existing = self.compiler.shared_lib_extension
 
66
        self.compiler.shared_lib_extension = "." + existing.split('.')[-1]
 
67
        ret = self.compiler.find_library_file(
 
68
            self.compiler.library_dirs, library)
 
69
        self.compiler.shared_lib_extension = existing
 
70
        return ret
 
71
    else:
 
72
        return self.compiler.find_library_file(
 
73
            self.compiler.library_dirs, library)
 
74
 
 
75
 
 
76
def _lib_include(root):
 
77
    # map root to (root/lib, root/include)
 
78
    return os.path.join(root, "lib"), os.path.join(root, "include")
 
79
 
 
80
 
 
81
def _read(file):
 
82
    return open(file, 'rb').read()
 
83
 
 
84
try:
 
85
    import _tkinter
 
86
except ImportError:
 
87
    _tkinter = None
 
88
    print('XXXXX _tkinter not found XXXXX')
 
89
 
 
90
 
 
91
NAME = 'Pillow'
 
92
VERSION = '2.2.1'
 
93
TCL_ROOT = None
 
94
JPEG_ROOT = None
 
95
ZLIB_ROOT = None
 
96
TIFF_ROOT = None
 
97
FREETYPE_ROOT = None
 
98
LCMS_ROOT = None
 
99
 
 
100
 
 
101
class pil_build_ext(build_ext):
 
102
 
 
103
    class feature:
 
104
        zlib = jpeg = tiff = freetype = tcl = tk = lcms = webp = webpmux = None
 
105
        required = []
 
106
 
 
107
        def require(self, feat):
 
108
            return feat in self.required
 
109
        def want(self, feat):
 
110
            return getattr(self, feat) is None
 
111
 
 
112
        def __iter__(self):
 
113
            for x in dir(self):
 
114
                if x[1] != '_':
 
115
                    yield x
 
116
 
 
117
    feature = feature()
 
118
 
 
119
    user_options = build_ext.user_options + [
 
120
        ('disable-%s' % x, None, 'Disable support for %s' % x)
 
121
        for x in feature
 
122
    ] + [
 
123
        ('enable-%s' % x, None, 'Enable support for %s' % x)
 
124
        for x in feature
 
125
    ]
 
126
 
 
127
    def initialize_options(self):
 
128
        build_ext.initialize_options(self)
 
129
        for x in self.feature:
 
130
            setattr(self, 'disable_%s' % x, None)
 
131
            setattr(self, 'enable_%s' % x, None)
 
132
 
 
133
    def finalize_options(self):
 
134
        build_ext.finalize_options(self)
 
135
        for x in self.feature:
 
136
            if getattr(self, 'disable_%s' % x):
 
137
                setattr(self.feature, x, False)
 
138
                if getattr(self, 'enable_%s' % x):
 
139
                    raise ValueError(
 
140
                            'Conflicting options: --enable-%s and --disable-%s'
 
141
                            % (x, x))
 
142
            if getattr(self, 'enable_%s' % x):
 
143
                self.feature.required.append(x)
 
144
 
 
145
    def add_gcc_paths(self):
 
146
        gcc = sysconfig.get_config_var('CC')
 
147
        tmpfile = os.path.join(self.build_temp, 'gccpaths')
 
148
        if not os.path.exists(self.build_temp):
 
149
            os.makedirs(self.build_temp)
 
150
        ret = os.system('%s -E -v - </dev/null 2>%s 1>/dev/null' % (gcc, tmpfile))
 
151
        is_gcc = False
 
152
        in_incdirs = False
 
153
        inc_dirs = []
 
154
        lib_dirs = []
 
155
        try:
 
156
            if ret >> 8 == 0:
 
157
                with open(tmpfile) as fp:
 
158
                    for line in fp.readlines():
 
159
                        if line.startswith("gcc version"):
 
160
                            is_gcc = True
 
161
                        elif line.startswith("#include <...>"):
 
162
                            in_incdirs = True
 
163
                        elif line.startswith("End of search list"):
 
164
                            in_incdirs = False
 
165
                        elif is_gcc and line.startswith("LIBRARY_PATH"):
 
166
                            for d in line.strip().split("=")[1].split(":"):
 
167
                                d = os.path.normpath(d)
 
168
                                if '/gcc/' not in d:
 
169
                                    _add_directory(self.compiler.library_dirs,
 
170
                                                   d)
 
171
                        elif is_gcc and in_incdirs and '/gcc/' not in line:
 
172
                            _add_directory(self.compiler.include_dirs,
 
173
                                           line.strip())
 
174
        finally:
 
175
            os.unlink(tmpfile)
 
176
 
 
177
    def build_extensions(self):
 
178
 
 
179
        global TCL_ROOT
 
180
 
 
181
        library_dirs = []
 
182
        include_dirs = []
 
183
 
 
184
        _add_directory(include_dirs, "libImaging")
 
185
 
 
186
        #
 
187
        # add configured kits
 
188
 
 
189
        for root in (TCL_ROOT, JPEG_ROOT, TIFF_ROOT, ZLIB_ROOT,
 
190
                     FREETYPE_ROOT, LCMS_ROOT):
 
191
            if isinstance(root, type(())):
 
192
                lib_root, include_root = root
 
193
            else:
 
194
                lib_root = include_root = root
 
195
            _add_directory(library_dirs, lib_root)
 
196
            _add_directory(include_dirs, include_root)
 
197
 
 
198
        #
 
199
        # add platform directories
 
200
 
 
201
        if host_platform == "cygwin":
 
202
            # pythonX.Y.dll.a is in the /usr/lib/pythonX.Y/config directory
 
203
            _add_directory(library_dirs, os.path.join(
 
204
                "/usr/lib", "python%s" % sys.version[:3], "config"))
 
205
 
 
206
        elif host_platform == "darwin":
 
207
            # attempt to make sure we pick freetype2 over other versions
 
208
            _add_directory(include_dirs, "/sw/include/freetype2")
 
209
            _add_directory(include_dirs, "/sw/lib/freetype2/include")
 
210
            # fink installation directories
 
211
            _add_directory(library_dirs, "/sw/lib")
 
212
            _add_directory(include_dirs, "/sw/include")
 
213
            # darwin ports installation directories
 
214
            _add_directory(library_dirs, "/opt/local/lib")
 
215
            _add_directory(include_dirs, "/opt/local/include")
 
216
            # freetype2 ships with X11
 
217
            _add_directory(library_dirs, "/usr/X11/lib")
 
218
            _add_directory(include_dirs, "/usr/X11/include")
 
219
            # if homebrew is installed, use its lib and include directories
 
220
            import subprocess
 
221
            try:
 
222
                prefix = subprocess.check_output(['brew', '--prefix'])
 
223
                if prefix:
 
224
                    prefix = prefix.strip()
 
225
                    _add_directory(library_dirs, os.path.join(prefix, 'lib'))
 
226
                    _add_directory(include_dirs, os.path.join(prefix, 'include'))
 
227
            except:
 
228
                pass # homebrew not installed
 
229
                    
 
230
        elif host_platform.startswith("linux"):
 
231
            self.add_multiarch_paths()
 
232
 
 
233
        _add_directory(library_dirs, "/usr/local/lib")
 
234
        # FIXME: check /opt/stuff directories here?
 
235
 
 
236
        # include, rpath, if set as environment variables:
 
237
        for k in 'C_INCLUDE_PATH INCLUDE'.split():
 
238
            if k in os.environ:
 
239
                for d in os.environ[k].split(os.path.pathsep):
 
240
                    _add_directory(include_dirs, d)
 
241
 
 
242
        for k in 'LD_RUN_PATH LIBRARY_PATH LIB'.split():
 
243
            if k in os.environ:
 
244
                for d in os.environ[k].split(os.path.pathsep):
 
245
                    _add_directory(library_dirs, d)
 
246
 
 
247
        prefix = sysconfig.get_config_var("prefix")
 
248
        if prefix:
 
249
            _add_directory(library_dirs, os.path.join(prefix, "lib"))
 
250
            _add_directory(include_dirs, os.path.join(prefix, "include"))
 
251
 
 
252
        #
 
253
        # locate tkinter libraries
 
254
 
 
255
        if _tkinter:
 
256
            TCL_VERSION = _tkinter.TCL_VERSION[:3]
 
257
 
 
258
        if _tkinter and not TCL_ROOT:
 
259
            # we have Tkinter but the TCL_ROOT variable was not set;
 
260
            # try to locate appropriate Tcl/Tk libraries
 
261
            PYVERSION = sys.version[0] + sys.version[2]
 
262
            TCLVERSION = TCL_VERSION[0] + TCL_VERSION[2]
 
263
            roots = [
 
264
                # common installation directories, mostly for Windows
 
265
                # (for Unix-style platforms, we'll check in well-known
 
266
                # locations later)
 
267
                os.path.join("/py" + PYVERSION, "Tcl"),
 
268
                os.path.join("/python" + PYVERSION, "Tcl"),
 
269
                "/Tcl", "/Tcl" + TCLVERSION, "/Tcl" + TCL_VERSION,
 
270
                os.path.join(os.environ.get("ProgramFiles", ""), "Tcl"), ]
 
271
            for TCL_ROOT in roots:
 
272
                TCL_ROOT = os.path.abspath(TCL_ROOT)
 
273
                if os.path.isfile(os.path.join(TCL_ROOT, "include", "tk.h")):
 
274
                    # FIXME: use distutils logging (?)
 
275
                    print("--- using Tcl/Tk libraries at", TCL_ROOT)
 
276
                    print("--- using Tcl/Tk version", TCL_VERSION)
 
277
                    TCL_ROOT = _lib_include(TCL_ROOT)
 
278
                    break
 
279
            else:
 
280
                TCL_ROOT = None
 
281
 
 
282
        # add standard directories
 
283
 
 
284
        # look for tcl specific subdirectory (e.g debian)
 
285
        if _tkinter:
 
286
            tcl_dir = "/usr/include/tcl" + TCL_VERSION
 
287
            if os.path.isfile(os.path.join(tcl_dir, "tk.h")):
 
288
                _add_directory(include_dirs, tcl_dir)
 
289
 
 
290
        # standard locations
 
291
        _add_directory(library_dirs, "/usr/local/lib")
 
292
        _add_directory(include_dirs, "/usr/local/include")
 
293
 
 
294
        _add_directory(library_dirs, "/usr/lib")
 
295
        _add_directory(include_dirs, "/usr/include")
 
296
 
 
297
        #
 
298
        # insert new dirs *before* default libs, to avoid conflicts
 
299
        # between Python PYD stub libs and real libraries
 
300
 
 
301
        self.compiler.library_dirs = library_dirs + self.compiler.library_dirs
 
302
        self.compiler.include_dirs = include_dirs + self.compiler.include_dirs
 
303
 
 
304
        #
 
305
        # look for available libraries
 
306
 
 
307
        feature = self.feature
 
308
 
 
309
        if feature.want('zlib'):
 
310
            if _find_include_file(self, "zlib.h"):
 
311
                if _find_library_file(self, "z"):
 
312
                    feature.zlib = "z"
 
313
                elif host_platform == "win32" and _find_library_file(self, "zlib"):
 
314
                    feature.zlib = "zlib"  # alternative name
 
315
 
 
316
        if feature.want('jpeg'):
 
317
            if _find_include_file(self, "jpeglib.h"):
 
318
                if _find_library_file(self, "jpeg"):
 
319
                    feature.jpeg = "jpeg"
 
320
                elif (
 
321
                        host_platform == "win32" and
 
322
                        _find_library_file(self, "libjpeg")):
 
323
                    feature.jpeg = "libjpeg"  # alternative name
 
324
 
 
325
        if feature.want('tiff'):
 
326
            if _find_library_file(self, "tiff"):
 
327
                feature.tiff = "tiff"
 
328
            if host_platform == "win32" and _find_library_file(self, "libtiff"):
 
329
                feature.tiff = "libtiff"
 
330
            if host_platform == "darwin" and _find_library_file(self, "libtiff"):
 
331
                feature.tiff = "libtiff"
 
332
 
 
333
        if feature.want('freetype'):
 
334
            if _find_library_file(self, "freetype"):
 
335
                # look for freetype2 include files
 
336
                freetype_version = 0
 
337
                for dir in self.compiler.include_dirs:
 
338
                    if os.path.isfile(os.path.join(dir, "ft2build.h")):
 
339
                        freetype_version = 21
 
340
                        dir = os.path.join(dir, "freetype2")
 
341
                        break
 
342
                    dir = os.path.join(dir, "freetype2")
 
343
                    if os.path.isfile(os.path.join(dir, "ft2build.h")):
 
344
                        freetype_version = 21
 
345
                        break
 
346
                    if os.path.isdir(os.path.join(dir, "freetype")):
 
347
                        freetype_version = 20
 
348
                        break
 
349
                if freetype_version:
 
350
                    feature.freetype = "freetype"
 
351
                    feature.freetype_version = freetype_version
 
352
                    if dir:
 
353
                        _add_directory(self.compiler.include_dirs, dir, 0)
 
354
 
 
355
        if feature.want('lcms'):
 
356
            if _find_include_file(self, "lcms.h"):
 
357
                if _find_library_file(self, "lcms"):
 
358
                    feature.lcms = "lcms"
 
359
 
 
360
        if _tkinter and _find_include_file(self, "tk.h"):
 
361
            # the library names may vary somewhat (e.g. tcl84 or tcl8.4)
 
362
            version = TCL_VERSION[0] + TCL_VERSION[2]
 
363
            if feature.want('tcl'):
 
364
                if _find_library_file(self, "tcl" + version):
 
365
                    feature.tcl = "tcl" + version
 
366
                elif _find_library_file(self, "tcl" + TCL_VERSION):
 
367
                    feature.tcl = "tcl" + TCL_VERSION
 
368
            if feature.want('tk'):
 
369
                if _find_library_file(self, "tk" + version):
 
370
                    feature.tk = "tk" + version
 
371
                elif _find_library_file(self, "tk" + TCL_VERSION):
 
372
                    feature.tk = "tk" + TCL_VERSION
 
373
 
 
374
        if feature.want('webp'):
 
375
            if (_find_include_file(self, "webp/encode.h") and
 
376
                    _find_include_file(self, "webp/decode.h")):
 
377
                if _find_library_file(self, "webp"): # in googles precompiled zip it is call "libwebp"
 
378
                    feature.webp = "webp"
 
379
 
 
380
        if feature.want('webpmux'):
 
381
            if (_find_include_file(self, "webp/mux.h") and
 
382
                    _find_include_file(self, "webp/demux.h")):
 
383
                if _find_library_file(self, "webpmux") and _find_library_file(self, "webpdemux"):
 
384
                    feature.webpmux = "webpmux"
 
385
 
 
386
        for f in feature:
 
387
            if not getattr(feature, f) and feature.require(f):
 
388
                raise ValueError(
 
389
                        '--enable-%s requested but %s not found, aborting.'
 
390
                        % (f, f))
 
391
 
 
392
        #
 
393
        # core library
 
394
 
 
395
        files = ["_imaging.c"]
 
396
        for file in _IMAGING:
 
397
            files.append(file + ".c")
 
398
        for file in _LIB_IMAGING:
 
399
            files.append(os.path.join("libImaging", file + ".c"))
 
400
 
 
401
        libs = []
 
402
        defs = []
 
403
        if feature.jpeg:
 
404
            libs.append(feature.jpeg)
 
405
            defs.append(("HAVE_LIBJPEG", None))
 
406
        if feature.zlib:
 
407
            libs.append(feature.zlib)
 
408
            defs.append(("HAVE_LIBZ", None))
 
409
        if feature.tiff:
 
410
            libs.append(feature.tiff)
 
411
            defs.append(("HAVE_LIBTIFF", None))
 
412
        if host_platform == "win32":
 
413
            libs.extend(["kernel32", "user32", "gdi32"])
 
414
        if struct.unpack("h", "\0\1".encode('ascii'))[0] == 1:
 
415
            defs.append(("WORDS_BIGENDIAN", None))
 
416
 
 
417
        exts = [(Extension(
 
418
            "PIL._imaging", files, libraries=libs, define_macros=defs))]
 
419
 
 
420
        #
 
421
        # additional libraries
 
422
 
 
423
        if feature.freetype:
 
424
            defs = []
 
425
            if feature.freetype_version == 20:
 
426
                defs.append(("USE_FREETYPE_2_0", None))
 
427
            exts.append(Extension(
 
428
                "PIL._imagingft", ["_imagingft.c"], libraries=["freetype"],
 
429
                define_macros=defs))
 
430
 
 
431
        if os.path.isfile("_imagingtiff.c") and feature.tiff:
 
432
            exts.append(Extension(
 
433
                "PIL._imagingtiff", ["_imagingtiff.c"], libraries=["tiff"]))
 
434
 
 
435
        if os.path.isfile("_imagingcms.c") and feature.lcms:
 
436
            extra = []
 
437
            if host_platform == "win32":
 
438
                extra.extend(["user32", "gdi32"])
 
439
            exts.append(Extension(
 
440
                "PIL._imagingcms", ["_imagingcms.c"], libraries=["lcms"] + extra))
 
441
 
 
442
        if os.path.isfile("_webp.c") and feature.webp:
 
443
            libs = ["webp"]
 
444
            defs = []
 
445
 
 
446
            if feature.webpmux:
 
447
                defs.append(("HAVE_WEBPMUX", None))
 
448
                libs.append("webpmux")
 
449
                libs.append("webpdemux")
 
450
 
 
451
            exts.append(Extension(
 
452
                "PIL._webp", ["_webp.c"], libraries=libs, define_macros=defs))
 
453
 
 
454
        if host_platform == "darwin":
 
455
            # locate Tcl/Tk frameworks
 
456
            frameworks = []
 
457
            framework_roots = [
 
458
                "/Library/Frameworks",
 
459
                "/System/Library/Frameworks"]
 
460
            for root in framework_roots:
 
461
                if (
 
462
                        os.path.exists(os.path.join(root, "Tcl.framework")) and
 
463
                        os.path.exists(os.path.join(root, "Tk.framework"))):
 
464
                    print("--- using frameworks at %s" % root)
 
465
                    frameworks = ["-framework", "Tcl", "-framework", "Tk"]
 
466
                    dir = os.path.join(root, "Tcl.framework", "Headers")
 
467
                    _add_directory(self.compiler.include_dirs, dir, 0)
 
468
                    dir = os.path.join(root, "Tk.framework", "Headers")
 
469
                    _add_directory(self.compiler.include_dirs, dir, 1)
 
470
                    break
 
471
            if frameworks:
 
472
                exts.append(Extension(
 
473
                    "PIL._imagingtk", ["_imagingtk.c", "Tk/tkImaging.c"],
 
474
                    extra_compile_args=frameworks, extra_link_args=frameworks))
 
475
                feature.tcl = feature.tk = 1  # mark as present
 
476
        elif feature.tcl and feature.tk:
 
477
            exts.append(Extension(
 
478
                "PIL._imagingtk", ["_imagingtk.c", "Tk/tkImaging.c"],
 
479
                libraries=[feature.tcl, feature.tk]))
 
480
 
 
481
        if os.path.isfile("_imagingmath.c"):
 
482
            exts.append(Extension("PIL._imagingmath", ["_imagingmath.c"]))
 
483
 
 
484
        self.extensions[:] = exts
 
485
 
 
486
        build_ext.build_extensions(self)
 
487
 
 
488
        #
 
489
        # sanity and security checks
 
490
 
 
491
        unsafe_zlib = None
 
492
 
 
493
        if feature.zlib:
 
494
            unsafe_zlib = self.check_zlib_version(self.compiler.include_dirs)
 
495
 
 
496
        self.summary_report(feature, unsafe_zlib)
 
497
 
 
498
    def summary_report(self, feature, unsafe_zlib):
 
499
 
 
500
        print("-" * 68)
 
501
        print("PIL SETUP SUMMARY")
 
502
        print("-" * 68)
 
503
        print("version      Pillow %s" % VERSION)
 
504
        v = sys.version.split("[")
 
505
        print("platform     %s %s" % (host_platform, v[0].strip()))
 
506
        for v in v[1:]:
 
507
            print("             [%s" % v.strip())
 
508
        print("-" * 68)
 
509
 
 
510
        options = [
 
511
            (feature.tcl and feature.tk, "TKINTER"),
 
512
            (feature.jpeg, "JPEG"),
 
513
            (feature.zlib, "ZLIB (PNG/ZIP)"),
 
514
            (feature.tiff, "TIFF G3/G4 (experimental)"),
 
515
            (feature.freetype, "FREETYPE2"),
 
516
            (feature.lcms, "LITTLECMS"),
 
517
            (feature.webp, "WEBP"),
 
518
            (feature.webpmux, "WEBPMUX"), ]
 
519
 
 
520
        all = 1
 
521
        for option in options:
 
522
            if option[0]:
 
523
                print("--- %s support available" % option[1])
 
524
            else:
 
525
                print("*** %s support not available" % option[1])
 
526
                if option[1] == "TKINTER" and _tkinter:
 
527
                    version = _tkinter.TCL_VERSION
 
528
                    print("(Tcl/Tk %s libraries needed)" % version)
 
529
                all = 0
 
530
 
 
531
        if feature.zlib and unsafe_zlib:
 
532
            print("")
 
533
            print("*** Warning: zlib", unsafe_zlib)
 
534
            print("may contain a security vulnerability.")
 
535
            print("*** Consider upgrading to zlib 1.2.3 or newer.")
 
536
            print("*** See: http://www.kb.cert.org/vuls/id/238678")
 
537
            print(" http://www.kb.cert.org/vuls/id/680620")
 
538
            print(" http://www.gzip.org/zlib/advisory-2002-03-11.txt")
 
539
            print("")
 
540
 
 
541
        print("-" * 68)
 
542
 
 
543
        if not all:
 
544
            print("To add a missing option, make sure you have the required")
 
545
            print("library, and set the corresponding ROOT variable in the")
 
546
            print("setup.py script.")
 
547
            print("")
 
548
 
 
549
        print("To check the build, run the selftest.py script.")
 
550
        print("")
 
551
 
 
552
    def check_zlib_version(self, include_dirs):
 
553
        # look for unsafe versions of zlib
 
554
        for dir in include_dirs:
 
555
            zlibfile = os.path.join(dir, "zlib.h")
 
556
            if os.path.isfile(zlibfile):
 
557
                break
 
558
        else:
 
559
            return
 
560
        for line in open(zlibfile).readlines():
 
561
            m = re.match('#define\s+ZLIB_VERSION\s+"([^"]*)"', line)
 
562
            if not m:
 
563
                continue
 
564
            if m.group(1) < "1.2.3":
 
565
                return m.group(1)
 
566
 
 
567
    # http://hg.python.org/users/barry/rev/7e8deab93d5a
 
568
    def add_multiarch_paths(self):
 
569
        # Debian/Ubuntu multiarch support.
 
570
        # https://wiki.ubuntu.com/MultiarchSpec
 
571
        # self.build_temp
 
572
        tmpfile = os.path.join(self.build_temp, 'multiarch')
 
573
        if not os.path.exists(self.build_temp):
 
574
            os.makedirs(self.build_temp)
 
575
        ret = os.system(
 
576
            'dpkg-architecture -qDEB_HOST_MULTIARCH > %s 2> /dev/null' %
 
577
            tmpfile)
 
578
        try:
 
579
            if ret >> 8 == 0:
 
580
                fp = open(tmpfile, 'r')
 
581
                multiarch_path_component = fp.readline().strip()
 
582
                _add_directory(
 
583
                    self.compiler.library_dirs,
 
584
                    '/usr/lib/' + multiarch_path_component)
 
585
                _add_directory(
 
586
                    self.compiler.include_dirs,
 
587
                    '/usr/include/' + multiarch_path_component)
 
588
        finally:
 
589
            os.unlink(tmpfile)
 
590
 
 
591
setup(
 
592
    name=NAME,
 
593
    version=VERSION,
 
594
    description='Python Imaging Library (Fork)',
 
595
    long_description=(
 
596
        _read('README.rst') + b'\n' +
 
597
        _read('CHANGES.rst') + b'\n' +
 
598
        _read('CONTRIBUTORS.rst')).decode('utf-8'),
 
599
    author='Alex Clark (fork author)',
 
600
    author_email='aclark@aclark.net',
 
601
    url='http://python-imaging.github.io/',
 
602
    classifiers=[
 
603
        "Development Status :: 6 - Mature",
 
604
        "Topic :: Multimedia :: Graphics",
 
605
        "Topic :: Multimedia :: Graphics :: Capture :: Digital Camera",
 
606
        "Topic :: Multimedia :: Graphics :: Capture :: Scanners",
 
607
        "Topic :: Multimedia :: Graphics :: Capture :: Screen Capture",
 
608
        "Topic :: Multimedia :: Graphics :: Graphics Conversion",
 
609
        "Topic :: Multimedia :: Graphics :: Viewers",
 
610
        "Programming Language :: Python :: 2",
 
611
        "Programming Language :: Python :: 2.6",
 
612
        "Programming Language :: Python :: 2.7",
 
613
        "Programming Language :: Python :: 3",
 
614
        "Programming Language :: Python :: 3.2",
 
615
        "Programming Language :: Python :: 3.3", ],
 
616
    cmdclass={"build_ext": pil_build_ext},
 
617
    ext_modules=[Extension("PIL._imaging", ["_imaging.c"])],
 
618
    include_package_data=True,
 
619
    packages=find_packages(),
 
620
    scripts=glob.glob("Scripts/pil*.py"),
 
621
    test_suite='PIL.tests',
 
622
    keywords=["Imaging",],
 
623
    license='Standard PIL License',
 
624
    zip_safe=True,
 
625
    )
 
626