~edwin-grubbs/python-imaging/trunk

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: effbot
  • Date: 2006-03-01 19:11:48 UTC
  • Revision ID: svn-v4:be285980-f00d-0410-a9fe-d4747b46ecd0:pil:18
Load Imaging-1.1.3 into pil.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#
 
3
# Setup script for PIL
 
4
# $Id: //modules/pil/setup.py#7 $
 
5
#
 
6
# Usage: python setup.py install
 
7
#
 
8
# before running this script, build the libImaging directory
 
9
# and all support libraries (the JPEG library, ZLIB, etc).
 
10
#
 
11
 
 
12
from distutils.core import setup, Extension
 
13
 
 
14
import os, sys, re
 
15
 
 
16
# --------------------------------------------------------------------
 
17
# configuration
 
18
 
 
19
NAME = "PIL"
 
20
DESCRIPTION = "Python Imaging Library"
 
21
AUTHOR = "Secret Labs AB / PythonWare", "info@pythonware.com"
 
22
HOMEPAGE = "http://www.pythonware.com/products/pil"
 
23
 
 
24
# on windows, the build script expects to find both library files and
 
25
# include files in the directories below.  tweak as necessary.
 
26
JPEGDIR = "../../kits/jpeg-6b"
 
27
ZLIBDIR = "../../kits/zlib-1.1.3"
 
28
 
 
29
# on windows, the following is used to control how and where to search
 
30
# for Tcl/Tk files.  None enables automatic searching; to override, set
 
31
# this to a directory name
 
32
TCLROOT = None
 
33
 
 
34
from PIL.Image import VERSION
 
35
 
 
36
PY_VERSION = sys.version[0] + sys.version[2]
 
37
 
 
38
# --------------------------------------------------------------------
 
39
# configure imaging module
 
40
 
 
41
MODULES = []
 
42
 
 
43
INCLUDE_DIRS = ["libImaging"]
 
44
LIBRARY_DIRS = ["libImaging"]
 
45
LIBRARIES = ["Imaging"]
 
46
 
 
47
HAVE_LIBJPEG = 0
 
48
HAVE_LIBTIFF = 0
 
49
HAVE_LIBZ = 0
 
50
 
 
51
# parse ImConfig.h to figure out what external libraries we're using
 
52
for line in open(os.path.join("libImaging", "ImConfig.h")).readlines():
 
53
    m = re.match("#define\s+HAVE_LIB([A-Z]+)", line)
 
54
    if m:
 
55
        lib = m.group(1)
 
56
        if lib == "JPEG":
 
57
            HAVE_LIBJPEG = 1
 
58
            if sys.platform == "win32":
 
59
                LIBRARIES.append("jpeg")
 
60
                INCLUDE_DIRS.append(JPEGDIR)
 
61
                LIBRARY_DIRS.append(JPEGDIR)
 
62
            else:
 
63
                LIBRARIES.append("jpeg")
 
64
        elif lib == "TIFF":
 
65
            HAVE_LIBTIFF = 1
 
66
            LIBRARIES.append("tiff")
 
67
        elif lib == "Z":
 
68
            HAVE_LIBZ = 1
 
69
            if sys.platform == "win32":
 
70
                LIBRARIES.append("zlib")
 
71
                INCLUDE_DIRS.append(ZLIBDIR)
 
72
                LIBRARY_DIRS.append(ZLIBDIR)
 
73
            else:
 
74
                LIBRARIES.append("z")
 
75
 
 
76
if sys.platform == "win32":
 
77
    # standard windows libraries
 
78
    LIBRARIES.extend(["kernel32", "user32", "gdi32"])
 
79
 
 
80
MODULES.append(
 
81
    Extension(
 
82
        "_imaging",
 
83
        ["_imaging.c", "decode.c", "encode.c", "map.c", "display.c",
 
84
         "outline.c", "path.c"],
 
85
        include_dirs=INCLUDE_DIRS,
 
86
        library_dirs=LIBRARY_DIRS,
 
87
        libraries=LIBRARIES
 
88
        )
 
89
    )
 
90
 
 
91
# security check
 
92
 
 
93
if HAVE_LIBZ:
 
94
    # look for old, unsafe version of zlib
 
95
    # note: this only finds zlib.h if ZLIBDIR is properly set
 
96
    zlibfile = os.path.join(ZLIBDIR, "zlib.h")
 
97
    if os.path.isfile(zlibfile):
 
98
        for line in open(zlibfile).readlines():
 
99
            m = re.match('#define\s+ZLIB_VERSION\s+"([^"]*)"', line)
 
100
            if m:
 
101
                if m.group(1) < "1.1.4":
 
102
                    print
 
103
                    print "*** Warning: zlib", m.group(1),
 
104
                    print "may contain a security vulnerability."
 
105
                    print "*** Consider upgrading to zlib 1.1.4 or newer."
 
106
                    print "*** See:",
 
107
                    print "http://www.gzip.org/zlib/advisory-2002-03-11.txt"
 
108
                    print
 
109
                break
 
110
 
 
111
# --------------------------------------------------------------------
 
112
# configure imagingtk module
 
113
 
 
114
try:
 
115
    import _tkinter
 
116
    TCL_VERSION = _tkinter.TCL_VERSION[:3]
 
117
except (ImportError, AttributeError):
 
118
    pass
 
119
else:
 
120
    INCLUDE_DIRS = ["libImaging"]
 
121
    LIBRARY_DIRS = ["libImaging"]
 
122
    LIBRARIES = ["Imaging"]
 
123
    if sys.platform == "win32":
 
124
        # locate tcl/tk on windows
 
125
        if TCLROOT:
 
126
            path = [TCLROOT]
 
127
        else:
 
128
            path = [
 
129
                os.path.join("/py" + PY_VERSION, "Tcl"),
 
130
                os.path.join(os.environ.get("ProgramFiles", ""), "Tcl"),
 
131
                # FIXME: add more directories here?
 
132
                ]
 
133
        for root in path:
 
134
            TCLROOT = os.path.abspath(root)
 
135
            if os.path.isfile(os.path.join(TCLROOT, "include", "tk.h")):
 
136
                break
 
137
        else:
 
138
            print "*** cannot find Tcl/Tk headers and library files"
 
139
            print "    change the TCLROOT variable in the setup.py file"
 
140
            sys.exit(1)
 
141
 
 
142
        # print "using Tcl/Tk libraries at", TCLROOT
 
143
        # print "using Tcl/Tk version", TCL_VERSION
 
144
 
 
145
        version = TCL_VERSION[0] + TCL_VERSION[2]
 
146
        INCLUDE_DIRS.append(os.path.join(TCLROOT, "include"))
 
147
        LIBRARY_DIRS.append(os.path.join(TCLROOT, "lib"))
 
148
        LIBRARIES.extend(["tk" + version, "tcl" + version])
 
149
    else:
 
150
        # assume the libraries are installed in the default location
 
151
        LIBRARIES.extend(["tk" + TCL_VERSION, "tcl" + TCL_VERSION])
 
152
 
 
153
    MODULES.append(
 
154
        Extension(
 
155
            "_imagingtk",
 
156
            ["_imagingtk.c", "Tk/tkImaging.c"],
 
157
            include_dirs=INCLUDE_DIRS,
 
158
            library_dirs=LIBRARY_DIRS,
 
159
            libraries=LIBRARIES
 
160
            )
 
161
        )
 
162
 
 
163
# build!
 
164
 
 
165
setup(
 
166
    name=NAME,
 
167
    version=VERSION,
 
168
    author=AUTHOR[0],
 
169
    author_email=AUTHOR[1],
 
170
    description=DESCRIPTION,
 
171
    url=HOMEPAGE,
 
172
    packages=[""],
 
173
    extra_path = "PIL",
 
174
    package_dir={"": "PIL"},
 
175
    ext_modules = MODULES,
 
176
    )