forked from matthew-brett/mpl-osx-binaries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wscript
267 lines (242 loc) · 10.3 KB
/
wscript
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# waf script
# vim: ft=python
from __future__ import division, print_function, absolute_import
import os
from os.path import join as pjoin, split as psplit, isfile
import sys
from glob import glob
import shutil
from subprocess import check_call, CalledProcessError
from functools import partial
PY3 = sys.version_info[0] >= 3
from wafutils import back_tick, FilePackageMaker as FPM, GitPackageMaker as GPM
# If you change any git commits in the package definitions, you may need to run
# the ``waf refresh_submodules`` command
# External libraries
bzip2_pkg = FPM('bzip2',
'archives/bzip2-1.0.6.tar.gz',
('cd ${SRC[0].abspath()} && '
'LDFLAGS="${THIN_LDFLAGS}" make -j3 && '
'make install PREFIX=${bld.bldnode.abspath()}'))
zlib_pkg = GPM('zlib',
'v1.2.8',
('cd ${SRC[0].abspath()} && '
'LDFLAGS="${THIN_LDFLAGS}" ./configure --prefix=${bld.bldnode.abspath()} && '
'make -j3 install'))
libpng_pkg = GPM('libpng',
'v1.5.9',
('cd ${SRC[0].abspath()} && '
'LDFLAGS="${THIN_LDFLAGS}" ./configure --disable-dependency-tracking '
'--prefix=${bld.bldnode.abspath()} && '
'make -j3 install'),
after = 'zlib.build')
freetype2_pkg = GPM('freetype2',
'VER-2-5-0-1',
('cd ${SRC[0].abspath()} && '
'./configure --prefix=${bld.bldnode.abspath()} && '
'make -j3 && ' # make and install have to be separate
'make -j3 install'), # I have no idea why
patcher = 'patches/freetype2/VER-2-5-0-1.patch',
after = ['bzip2.build', 'libpng.build'])
EXT_LIBS = [bzip2_pkg, zlib_pkg, libpng_pkg, freetype2_pkg]
python_install_rule = ('cd ${SRC[0].abspath()} && ${PYTHON} setup.py install '
'--prefix=${bld.bldnode.abspath()}')
mpkg_build_rule = ('cd ${SRC[0].abspath()} && bdist_mpkg setup.py bdist_mpkg')
# Python packages have to build sequentially because they may compete writing
# easy-install.pth when installing
setuptools_pkg = FPM('setuptools',
'archives/setuptools-1.1.6.tar.gz',
python_install_rule,
after = ['freetype2.build'])
bdist_mpkg_pkg = GPM('bdist_mpkg',
'v0.5.0',
python_install_rule,
after = ['setuptools.build'])
python_dateutil_pkg = FPM('python-dateutil',
'archives/python-dateutil-2.0.tar.gz' if PY3
else 'archives/python-dateutil-1.5.tar.gz',
python_install_rule,
after = ['bdist_mpkg.build'])
pytz_pkg = FPM('pytz',
'archives/pytz-2013.7.tar.gz',
python_install_rule,
after = ['python-dateutil.build'])
six_pkg = FPM('six',
'archives/six-1.4.1.tar.gz',
python_install_rule,
after = ['pytz.build'])
pyparsing_pkg = FPM('pyparsing',
'archives/pyparsing-2.0.1.tar.gz',
python_install_rule,
after = ['six.build'])
tornado_pkg = GPM('tornado',
'v3.1.1',
python_install_rule,
after = ['pyparsing.build'])
def _write_setup_cfg(task):
setup_node = task.inputs[0].make_node('setup.cfg')
setup_node.write("""
# setup.cfg file
[directories]
# 0verride the default basedir in setupext.py.
# This can be a single directory or a comma-delimited list of directories.
basedirlist = {0}, /usr
""".format(task.inputs[0].get_bld().abspath()))
matplotlib_pkg = GPM('matplotlib',
'1.3.1',
mpkg_build_rule,
patcher = _write_setup_cfg,
after = ['tornado.build', 'de-dylibbed'])
# Python packages
PY_PKGS = [setuptools_pkg, bdist_mpkg_pkg, python_dateutil_pkg, pytz_pkg,
six_pkg, pyparsing_pkg, tornado_pkg, matplotlib_pkg]
# Packages for which we make an mpkg
MPKG_PKGS = [python_dateutil_pkg, pytz_pkg, six_pkg, pyparsing_pkg, tornado_pkg]
MPKG_META_PKG = matplotlib_pkg
def options(opt):
opt.load('compiler_c')
# Copy of python.py extension from waf
opt.load('mypython')
# Output for mpkg writing
opt.add_option('--mpkg-outpath', action='store',
help='directory to write built mpkg')
opt.add_option('--mpkg-clobber', action='store_true', default=False,
help='whether to overwrite existing output mpkg')
def _lib_path(start_path):
version = sys.version_info
return '{0}/lib/python{1}.{2}/site-packages'.format(
start_path, version[0], version[1])
def configure(ctx):
sys_env = dict(os.environ)
bld_path = ctx.bldnode.abspath()
ctx.load('compiler_c')
ctx.load('mypython')
ctx.check_python_headers()
ctx.check_python_module('numpy')
# We need to record the build directory for use by non-build functions
ctx.env.BLD_PREFIX = bld_path
ctx.env.BLD_SRC = pjoin(bld_path, 'src')
ctx.find_program('git', var='GIT')
try:
ctx.find_program('pkg-config')
except ctx.errors.ConfigurationError:
ctx.to_log('Failed to find pkg-config; consider installing from '
'source at http://pkgconfig.freedesktop.org/releases.')
ctx.to_log('I used ``./configure --with-internal-glib && make '
'&& sudo make install``')
ctx.fatal('Could not find pkg-config; see log for suggestion')
# Update submodules in repo
print('Running git submodule update, this might take a while')
ctx.exec_command('git submodule update --init')
# Prepare environment variables for compilation
if not 'ARCH_FLAGS' in sys_env:
sys_env['ARCH_FLAGS'] = '-arch i386 -arch x86_64'
ctx.env.THIN_LDFLAGS = '{0} -L{1}/lib'.format(
sys_env['ARCH_FLAGS'],
bld_path)
ctx.env.THICK_LDFLAGS = ctx.env.THIN_LDFLAGS + ' -lpng -lbz2'
# For installing python modules
ctx.env.PYTHONPATH = _lib_path(bld_path)
sys_env['PYTHONPATH'] = ctx.env.PYTHONPATH
sys_env['PKG_CONFIG_PATH'] = '{0}/lib/pkgconfig'.format(bld_path)
sys_env['MACOSX_DEPLOYMENT_TARGET']='10.6'
sys_env['CPPFLAGS'] = ('-I{0}/include '
'-I{0}/freetype2/include').format(bld_path)
sys_env['CFLAGS'] = sys_env['ARCH_FLAGS']
sys_env['LDFLAGS'] = ctx.env.THICK_LDFLAGS
sys_env['PATH'] = '{0}/bin:'.format(bld_path) + sys_env['PATH']
ctx.env.env = sys_env
def build(ctx):
bld_node = ctx.bldnode
bld_path = bld_node.abspath()
# We need the src directory before we start
def pre(ctx):
# src directory for code tree copies
ctx.exec_command('mkdir -p {0}/src'.format(bld_path))
# python site-packages directory for python installs
ctx.exec_command('mkdir -p {0}'.format(_lib_path(bld_path)))
ctx.add_pre_fun(pre)
# Build the external libs
for pkg in EXT_LIBS:
pkg.unpack_patch_build(ctx)
ctx( # Clean dynamic libraries just in case
rule = 'rm -rf lib/*.dylib',
after = 'freetype2.build',
name = 'de-dylibbed')
# Install python build dependencies
mpkg_tasks = []
for pkg in PY_PKGS:
py_task_name, dir_node = pkg.unpack_patch_build(ctx)
# Run the mpkgs after the bdist_mpkg install, and the package install
if pkg in MPKG_PKGS:
mpkg_task = pkg.name + '.mpkg.build'
ctx(
rule = mpkg_build_rule,
source = [dir_node],
after = [py_task_name, 'bdist_mpkg.build'],
name = mpkg_task)
mpkg_tasks.append(mpkg_task)
# Now the mpkg
meta_name = MPKG_META_PKG.name
ctx(
rule = ('cp -r src/{0}/dist/*.mpkg . && '
'cp -r src/*/dist/*.mpkg/Contents/Packages/* '
'{0}*.mpkg/Contents/Packages').format(meta_name),
after = ['matplotlib.build'] + mpkg_tasks,
name = 'mpkg.build')
ctx(rule =
'${{PYTHON}} ../rewrite_plist.py '
'{meta_name} {bld_path}/{meta_name}*.mpkg'.format(
meta_name=meta_name, bld_path=bld_path),
after = ['mpkg.build'],
)
def refresh_submodules(ctx):
# Command to set submodules to defined commits
call = partial(check_call, shell=True)
print('Running git submodule update, this might take a while')
call('git submodule update --init')
for git_name, git_pkg in GPM.instances.items():
checkout_cmd = 'cd {s.git_sdir} && git checkout {s.commit}'.format(
s = git_pkg)
fetch_cmd = 'cd {s.git_sdir} && git fetch'.format(
s = git_pkg)
try:
call(checkout_cmd)
except CalledProcessError:
call(fetch_cmd)
call(checkout_cmd)
def write_mpkg(ctx):
# Change the permissions for mpkg and copy file somewhere
mpkg_outpath = ctx.options.mpkg_outpath
if mpkg_outpath is None:
ctx.fatal('Need to set --mpkg-outpath to write mpkgs')
# Need to be sudo
if not back_tick('whoami') == 'root':
ctx.fatal('Need to be root to run dist command - use `sudo ./waf write_mpkg`?')
# Get build time configuration
from waflib.ConfigSet import ConfigSet
env = ConfigSet()
env_cache = pjoin('build', 'c4che', '_cache.py')
if not isfile(env_cache):
ctx.fatal('Run `configure` and `build` before `dist`')
env.load(env_cache)
# Check if any mpkgs have been built
build_path = env.BLD_PREFIX
globber = pjoin(build_path, '*mpkg')
mpkgs = glob(globber)
if len(mpkgs) == 0:
ctx.fatal("No mpkgs found with " + globber)
# Put built version of bdist_mpkg onto the path
os.environ['PATH'] = pjoin(build_path, 'bin') + ':' + os.environ['PATH']
os.environ['PYTHONPATH'] = env['PYTHONPATH']
# Write mpkgs with permissions updated
for mpkg in mpkgs:
_, mpkg_dir = psplit(mpkg)
out_mpkg = pjoin(mpkg_outpath, mpkg_dir)
print('Found {0}, writing {1}'.format(mpkg, out_mpkg))
if os.path.exists(out_mpkg):
if not ctx.options.mpkg_clobber:
ctx.fatal('mpkg exists, --mpkg-clobber not set')
shutil.rmtree(out_mpkg, ignore_errors=True)
shutil.copytree(mpkg, out_mpkg)
ctx.exec_command(['reown_mpkg', out_mpkg, 'root', 'admin'])