-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Expand file tree
/
Copy pathsetupext.py
More file actions
213 lines (160 loc) · 5.99 KB
/
setupext.py
File metadata and controls
213 lines (160 loc) · 5.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
"""
Some helper functions for building the C extensions
"""
import sys, os
from distutils.core import Extension
import glob
major, minor1, minor2, s, tmp = sys.version_info
if major<2 or (major==2 and minor1<3):
True = 1
False = 0
else:
True = True
False = False
BUILT_AGG = False
BUILT_FONTTOOLS = False
BUILT_GTKGD = False
BUILT_GTKAGG = False
BUILT_TKAGG = False
BUILT_FT2FONT = False
def getoutput(s):
'get the output of a system command'
return os.popen(s).read().strip()
def add_agg_flags(module):
'Add the module flags to build extensions which use agg'
module.include_dirs.extend(['src','agg2/include'])
if sys.platform in ('win32', 'darwin'):
module.include_dirs.extend(
[ # build these libs on win32
'win32src/freetype1',
'win32src/libpng',
'win32src/zlib',
]
)
else:
module.include_dirs.extend(
['/usr/include/freetype2',]
)
if sys.platform not in ('win32', 'darwin'):
module.libraries.extend(['z', 'freetype', 'png'])
module.libraries.extend(['stdc++'])
def add_gd_flags(module):
'Add the module flags to build extensions which use gd'
module.libraries.append('gd')
def add_ft2font_flags(module):
'Add the module flags to build extensions which use gd'
module.include_dirs.extend(
['/usr/include', '/usr/include/freetype2',]
)
module.libraries.extend(['freetype', 'm'])
def add_pygtk_flags(module):
'Add the module flags to build extensions which use gtk'
pygtkIncludes = getoutput('pkg-config --cflags-only-I pygtk-2.0').split()
gtkIncludes = getoutput('pkg-config --cflags-only-I gtk+-2.0').split()
includes = pygtkIncludes + gtkIncludes
module.include_dirs.extend([include[2:] for include in includes])
pygtkLinker = getoutput('pkg-config --libs pygtk-2.0').split()
gtkLinker = getoutput('pkg-config --libs gtk+-2.0').split()
linkerFlags = pygtkLinker + gtkLinker
module.libraries.extend(
[flag[2:] for flag in linkerFlags if flag.startswith('-l')])
module.library_dirs.extend(
[flag[2:] for dir in linkerFlags if flag.startswith('-L')])
module.extra_link_args.extend(
[flag for flag in linkerFlags if not
(flag.startswith('-l') or flag.startswith('-L'))])
def add_tk_flags(module):
'Add the module flags to build extensions which use tk'
includes = [] # ["-I/usr/include"]
module.include_dirs.extend([include[2:] for include in includes])
linkerFlags = ["-ltcl", "-ltk"] # [, "-L/usr/lib"]
module.libraries.extend(
[flag[2:] for flag in linkerFlags if flag.startswith('-l')])
module.library_dirs.extend(
[flag[2:] for dir in linkerFlags if flag.startswith('-L')])
module.extra_link_args.extend(
[flag for flag in linkerFlags if not
(flag.startswith('-l') or flag.startswith('-L'))])
def build_ft2font(ext_modules, packages):
global BUILT_FT2FONT
if BUILT_FT2FONT: return # only build it if you you haven't already
module = Extension('matplotlib.ft2font',
['src/ft2font.c'],
)
add_ft2font_flags(module)
ext_modules.append(module)
BUILT_GTKGD = True
def build_gtkgd(ext_modules, packages):
global BUILT_GTKGD
if BUILT_GTKGD: return # only build it if you you haven't already
module = Extension('matplotlib.backends._gtkgd',
['src/_gtkgd.c'],
)
add_pygtk_flags(module)
add_gd_flags(module)
ext_modules.append(module)
BUILT_GTKGD = True
def build_gtkagg(ext_modules, packages):
global BUILT_GTKAGG
if BUILT_GTKAGG: return # only build it if you you haven't already
module = Extension('matplotlib.backends._gtkagg',
['src/_gtkagg.cpp'],
)
# add agg flags before pygtk because agg only supports freetype1
# and pygtk includes freetype2. This is a bit fragile.
add_agg_flags(module)
add_pygtk_flags(module)
ext_modules.append(module)
BUILT_GTKAGG = True
def build_tkagg(ext_modules, packages):
global BUILT_TKAGG
if BUILT_TKAGG: return # only build it if you you haven't already
module = Extension('matplotlib.backends._tkagg',
['src/_tkagg.cpp'],
)
# add agg flags before pygtk because agg only supports freetype1
# and pygtk includes freetype2. This is a bit fragile.
add_agg_flags(module)
add_tk_flags(module)
ext_modules.append(module)
BUILT_GTKAGG = True
def build_agg(ext_modules, packages):
global BUILT_AGG
if BUILT_AGG: return # only build it if you you haven't already
deps = ['src/_backend_agg.cpp', 'src/ft2font.c']
deps.extend(glob.glob('agg2/src/*.cpp'))
if sys.platform in ('win32', 'darwin'):
deps.extend(glob.glob('win32src/freetype2/freetype/*.c'))
deps.extend(glob.glob('win32src/libpng/*.c'))
deps.extend(glob.glob('win32src/zlib/*.c'))
module = Extension(
'matplotlib.backends._backend_agg',
deps
,
)
add_agg_flags(module)
ext_modules.append(module)
BUILT_AGG = True
def build_fonttools(ext_modules, packages):
# don't build it if we have it
try: import ttfquery
except ImportError: pass
else: return
global BUILT_FONTTOOLS
if BUILT_FONTTOOLS: return # only build it if you you haven't already
packages.extend(
['ttfquery',
'FontTools',
'FontTools.fontTools',
'FontTools.fontTools.encodings',
'FontTools.fontTools.misc',
'FontTools.fontTools.ttLib',
'FontTools.fontTools.ttLib.tables',
'FontTools.fontTools.ttLib.test',
])
ext_modules.append(
Extension(
'FontTools.fontTools.misc.eexecOp',
['FontToolsSrc/eexecOp/eexecOpmodule.c'],
))
BUILT_FONTTOOLS = True