-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap-env.sh
executable file
·452 lines (404 loc) · 9.97 KB
/
bootstrap-env.sh
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
#!/bin/bash
#
# bootstrap-env.sh
#
# Takes you from zero to a Python env for pylulesh dev.
#
#
export PY_VERSION="2.7.3"
function info
{
echo "$@"
}
function warn
{
info "WARNING: $@"
}
function error
{
info "ERROR: $@"
if [ x"${BASH_SOURCE[0]}" == x"$0" ] ; then
exit 1
else
kill -SIGINT $$
fi
}
function check
{
if [[ $1 != 0 ]] ; then
error " !Last step failed!"
fi
}
function download
{
if [[ -e $2 ]] ; then
info "Found: $2 <Skipping download>"
return 0
fi
info "NOT Found: $2 <Downloading from $1>"
WGET_TEST=$(which wget)
if [[ $WGET_TEST == "" ]] ; then
curl -ksfLO $1/$2
else
wget $1/$2
fi
}
function set_install_path
{
export START_DIR=`pwd`
export BUILD_DIR=$1/_build
export LOGS_DIR=$BUILD_DIR/logs
export PY_ROOT=$1/python
export PY_PREFIX=$PY_ROOT/$PY_VERSION
export PY_EXE=$PY_PREFIX/bin/python
export PIP_EXE=$PY_PREFIX/bin/pip
export LLVM_PREFIX=$1/llvm
export HDF5_PREFIX=$1/hdf5
}
function check_python_install
{
if [[ -e $1/python/$PY_VERSION/bin/python ]] ; then
return 0
else
return 1
fi
}
function check_llvm_install
{
if [[ -e $1/llvm/lib/libLLVMCore.a ]] ; then
return 0
else
return 1
fi
}
function check_pypy_install
{
if [[ -e $1/pypy-pypy/pytest.py ]] ; then
return 0
else
return 1
fi
}
function check_hdf5_install
{
if [[ -e $1/hdf5/lib ]] ; then
return 0
else
return 1
fi
}
function check_osx
{
$PY_EXE <<END
import sys
import platform
if sys.platform.count("darwin") > 0:
sys.exit(0)
else:
sys.exit(-1)
END
return $?
}
function check_osx_10_8
{
$PY_EXE <<END
import sys
import platform
osx_ml = False
if sys.platform.count("darwin") > 0:
if platform.mac_ver()[0].count("10.8") > 0:
osx_ml = True
if osx_ml:
sys.exit(0)
else:
sys.exit(-1)
END
return $?
}
function check_opencl_support
{
$PY_EXE <<END
import sys
import os
cl_support = False
if sys.platform.count("darwin") > 0:
cl_support = True
else:
cl_support = os.path.isdir("/opt/cudatoolkit-5.0/")
if cl_support:
sys.exit(0)
else:
sys.exit(-1)
END
return $?
}
function check_pyopencl_install
{
$PY_EXE <<END
import sys
try:
import pyopencl
except:
sys.exit(-1)
sys.exit(0)
END
return $?
}
function bootstrap_python
{
mkdir $BUILD_DIR
mkdir $PY_ROOT
mkdir $PY_PREFIX
mkdir $LOGS_DIR
info "================================="
info "Bootstraping Python $PY_VERSION"
info "================================="
info "[Target Prefix: $PY_PREFIX]"
cd $BUILD_DIR
download http://www.python.org/ftp/python/$PY_VERSION Python-$PY_VERSION.tgz
rm -rf Python-$PY_VERSION
info "[Inflating: Python-$PY_VERSION.tgz]"
tar -xzf Python-$PY_VERSION.tgz
cd Python-$PY_VERSION
info "[Configuring Python]"
mkdir -p ${PY_PREFIX}/lib/
./configure --enable-shared --prefix=$PY_PREFIX &> ../logs/python_configure.txt
check $?
info "[Building Python]"
make -j 4 &> ../logs/python_build.txt
check $?
info "[Installing Python]"
make install &> ../logs/python_install.txt
check $?
cd $START_DIR
}
function bootstrap_modules
{
# bootstrap pip
info "================================="
info "Bootstraping base modules"
info "================================="
cd $BUILD_DIR
download http://pypi.python.org/packages/source/d/distribute distribute-0.6.30.tar.gz
rm -rf distribute-0.6.30
info "[Inflating: distribute-0.6.30.tar.gz]"
tar -xzf distribute-0.6.30.tar.gz
cd distribute-0.6.30
info "[Building distribute]"
$PY_EXE setup.py build &> ../logs/distribute_build.txt
check $?
info "[Installing distribute]"
$PY_EXE setup.py install &> ../logs/distribute_install.txt
check $?
cd $BUILD_DIR
download http://pypi.python.org/packages/source/p/pip pip-1.2.1.tar.gz
rm -rf pip-1.2.1
info "[Inflating: pip-1.2.1.tar.gz]"
tar -xzf pip-1.2.1.tar.gz
cd pip-1.2.1
info "[Building pip]"
$PY_EXE setup.py build &> ../logs/pip_build.txt
check $?
info "[Installing pip]"
$PY_EXE setup.py install &> ../logs/pip_install.txt
check $?
cd $START_DIR
}
function build_llvm
{
info "================================="
info "Setting up LLVM 3.2"
info "================================="
info "[Target Prefix: $LLVM_PREFIX]"
cd $BUILD_DIR
download http://llvm.org/releases/3.2/ llvm-3.2.src.tar.gz
rm -rf llvm-3.2.src
info "[Inflating: llvm-3.2.src.tar.gz]"
tar -xzf llvm-3.2.src.tar.gz
cd llvm-3.2.src
info "[Configuring LLVM]"
export REQUIRES_RTTI=1
./configure --enable-optimized --enable-pic --prefix=$LLVM_PREFIX &> ../logs/llvm_configure.txt
check $?
info "[Building LLVM]]"
make -j 4 &> ../logs/llvm_build.txt
check $?
info "[Installing LLVM]]"
make install &> ../logs/llvm_install.txt
check $?
cd $START_DIR
}
function build_pypy
{
info "================================="
info "Setting up pypy"
info "================================="
echo $DEST
cd $DEST
download https://bitbucket.org/pypy/pypy/get release-2.0-beta-1.tar.bz2
info "[Inflating: release-2.0-beta-1.tar.bz2]"
bunzip2 release-2.0-beta-1.tar.bz2
info "[Untaring: release-2.0-beta-1.tar]"
tar xf release-2.0-beta-1.tar
rm release-2.0-beta-1.tar
mv pypy-pypy-* pypy-pypy
download https://bitbucket.org/pypy/pypy/downloads pypy-2.0-beta1-linux64-libc2.13.tar.bz2
info "[Inflating: pypy-2.0-beta1-linux64-libc2.13.tar.bz2]"
bunzip2 pypy-2.0-beta1-linux64-libc2.13.tar.bz2
info "[Untaring: pypy-2.0-beta1-linux64-libc2.13.tar]"
tar xf pypy-2.0-beta1-linux64-libc2.13.tar
rm pypy-2.0-beta1-linux64-libc2.13.tar
cd $START_DIR
}
function build_hdf5
{
info "================================="
info "Setting up HDF5 1.8.7"
info "================================="
info "[Target Prefix: $HDF5_PREFIX]"
cd $BUILD_DIR
download http://www.hdfgroup.org/ftp/HDF5/prev-releases/hdf5-1.8.7/src/ hdf5-1.8.7.tar.gz
rm -rf hdf5-1.8.7
info "[Inflating: hdf5-1.8.7.tar.gz]"
tar -xzf hdf5-1.8.7.tar.gz
cd hdf5-1.8.7
info "[Configuring HDF5]"
./configure --prefix=$HDF5_PREFIX &> ../logs/hdf5_configure.txt
#--disable-shared \
#--enable-static \
check $?
info "[Building HDF5]]"
make -j 4 &> ../logs/hdf5_build.txt
check $?
info "[Installing HDF5]]"
make install &> ../logs/hdf5_install.txt
check $?
cd $START_DIR
}
function build_pyopencl
{
info "================================="
info "Setting up pyopencl"
info "================================="
cd $BUILD_DIR
rm -rf pyopencl
git clone https://github.com/inducer/pyopencl
cd pyopencl
git submodule init
git submodule update
if [[ -e /opt/cudatoolkit-5.0/ ]] ; then
module load cudatoolkit/5.0
fi
if [ -z "$CUDA_INCLUDES" ] ; then
./configure.py
else
./configure.py --cl-inc-dir=$CUDA_INCLUDES
fi
make
make install
cd $START_DIR
}
function build_python_modules
{
# only install readline on osx
if check_osx; then
$PIP_EXE install readline
fi;
# numpy and cython
$PIP_EXE install numpy
$PIP_EXE install cython
# matplot lib & ipython
# avoid gcc & x11 issues on OSX 10.8
if check_osx_10_8 ; then
export CC=clang
export CXX=clang++
export LDFLAGS="-L/usr/X11/lib"
export CFLAGS="-I/usr/X11/include -I/usr/X11/include/freetype2"
fi;
$PIP_EXE install matplotlib
if check_osx_10_8 ; then
unset CC
unset CXX
unset LDFLAGS
unsert CFLAGS
fi
$PIP_EXE install tornado
if check_osx; then
export CC=clang
export CXX=clang++
fi;
$PIP_EXE install pyzmq
if check_osx; then
unset CC
unset CXX
fi;
$PIP_EXE install ipython
$PIP_EXE install pandas
# llvm & numba
export LLVM_CONFIG_PATH=$LLVM_PREFIX/bin/llvm-config
$PIP_EXE install git+https://github.com/llvmpy/llvmpy.git#egg=llvmpy
$PIP_EXE install git+https://github.com/numba/Meta.git#egg=Meta
$PIP_EXE install git+https://github.com/numba/numba.git#egg=numba
$PIP_EXE install nose
# h5py
export HDF5_DIR=$HDF5_PREFIX
$PIP_EXE install h5py
# check if machine has OpenCL support
check_opencl_support
if [[ $? == 0 ]] ; then
# pyopencl
$PIP_EXE install py
$PIP_EXE install pytest
$PIP_EXE install pytools
$PIP_EXE install decorator
$PIP_EXE install mako
check_pyopencl_install
if [[ $? == 0 ]] ; then
info "[Found: pyopencl <Skipping build>]"
else
build_pyopencl
fi
else
info "[WARNING: skipping pyopencl, no OpenCL support]"
fi
}
function main
{
# Possible Feature: Check for DEST passed as $1, use `pwd` as fallback
DEST=`pwd`/libs/
mkdir -p $DEST
set_install_path $DEST
check_python_install $DEST
if [[ $? == 0 ]] ; then
info "[Found: Python $PY_VERSION @ $DEST/$PY_VERSION/bin/python <Skipping build>]"
else
bootstrap_python
bootstrap_modules
fi
# Only add to PATH if `which python` isn't our Python
PY_CURRENT=`which python`
if [[ "$PY_CURRENT" != "$PY_PREFIX/bin/python" ]] ; then
export PATH=$PY_PREFIX/bin:$PATH
fi
check_llvm_install $DEST
if [[ $? == 0 ]] ; then
info "[Found: LLVM @ $LLVM_PREFIX <Skipping build>]"
else
build_llvm
fi
check_pypy_install $DEST
if [[ $? == 0 ]] ; then
info "[Found: PyPy @ $DEST <Skipping build>]"
else
build_pypy
fi
check_hdf5_install $DEST
if [[ $? == 0 ]] ; then
info "[Found: HDF5 @ $HDF5_PREFIX <Skipping build>]"
else
build_hdf5
fi
build_python_modules
info "[Active Python:" `which python` "]"
}
main