forked from apple/turicreate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·437 lines (356 loc) · 10.3 KB
/
configure
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
#!/bin/bash
##=============================================================================
## Main configuration processing
RELEASE_DIR=release
DEBUG_DIR=debug
TURI_HOME=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
DEPS_PREFIX=$PWD/deps/local
set -e
function print_help {
echo "Configures the build with the specified toolchain. "
echo
echo "If configure has already been run before, running configure "
echo "will simply reconfigure the build with no changes. "
echo
echo "Usage: ./configure <options>"
echo
echo " --cleanup Clean up everything."
echo
echo " --install-python-toolchain Install python in local virtualenv."
echo
echo " --with-system-cmake (default) Use system cmake, if avaliable."
echo " --no-system-cmake "
echo
echo " --with-ccache (default) Use ccache, if available."
echo " --no-ccache "
echo
echo " --with-python (default) Build python components."
echo " --no-python"
echo
echo " --with-visualization (default) Build Turi Create visualization client."
echo " --no-visualization"
echo
echo " --python2.7 Use Python 2.7 (default)."
echo " --python3.5 Use Python 3.5, default is Python 2.7."
echo " --python3.6 Use Python 3.6, default is Python 2.7."
echo
echo " --yes Defaults to yes on a prompt"
echo
echo " -D var=value Specify CFLAGS definitions to be passed on to cmake."
echo
echo "Example: ./configure"
echo
echo "Cleanup all build directories"
echo "Example: ./configure --cleanup"
echo
exit 1
} # end of print help
function unknown_option {
echo "Unrecognized option: $1"
echo "To get help, run ./configure --help"
exit 1
} # end of unknown option
function run_cleanup {
echo "cleaning up";
rm -rf release debug deps/local/ deps/build/ deps/env
}
function run_cleanup_prompt {
#!/bin/bash
echo "This script completely erases all build folders including dependencies!"
if [[ $default_yes == 1 ]]; then
yesorno="yes"
else
echo "Are you sure you want to continue? (yes or no)"
read yesorno;
fi
if [ "$yesorno" == "yes" ]; then
run_cleanup
else
echo "Doing nothing!";
fi
}
function install_python_toolchain {
echo "Installing python toolchain."
echo "python version = $PYTHON_VERSION."
pushd ${TURI_HOME}
PYTHON_VERSION=${PYTHON_VERSION} ./scripts/install_python_toolchain.sh
popd
}
# command flag options
cleanup_option=0
python_only=0
default_yes=0
with_python=1
with_system_cmake=1
with_ccache=1
with_ccache=1
with_visualization=1
python27=0
python35=0
python36=0
###############################################################################
#
# Parse command line configure flags ------------------------------------------
#
while [ $# -gt 0 ]
do case $1 in
--cleanup) cleanup_option=1;;
--install-python-toolchain) python_only=1;;
--with-system-cmake) with_system_cmake=1;;
--no-system-cmake) with_system_cmake=0;;
--with-ccache) with_ccache=1;;
--no-ccache) with_ccache=0;;
--with-python) with_python=1;;
--no-python) with_python=0;;
--with-visualization) with_visualization=1;;
--no-visualization) with_visualization=0;;
--yes) default_yes=1;;
--python2.7) python27=1;;
--python3.5) python35=1;;
--python3.6) python36=1;;
--help) print_help ;;
-D) CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -D $2"; shift ;;
*) unknown_option $1 ;;
esac
shift
done
if [[ $cleanup_option == 1 ]]; then
run_cleanup_prompt
exit 0
fi
if [[ $(($python27 + $python35 + $python36)) -gt 1 ]]; then
echo "Two or more versions of Python specified. Pick one."
exit 1
fi
if [[ $python35 == 1 ]]; then
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DPYTHON_VERSION=\"python3.5\""
PYTHON_VERSION="python3.5"
elif [[ $python36 == 1 ]]; then
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DPYTHON_VERSION=\"python3.6\""
PYTHON_VERSION="python3.6"
else
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DPYTHON_VERSION=\"python2.7\""
PYTHON_VERSION="python2.7"
fi
if [[ $python_only == 1 ]]; then
install_python_toolchain
exit $?
fi
# If we need to build python, we also need to install the python toolchain
if [[ $with_python == 1 ]]; then
if [[ $with_visualization == 0 ]]; then
echo "Visualization client libraries (--with-visualization) required for python build."
exit 1
fi
install_python_toolchain
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_BUILD_PYTHON=1"
else
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_BUILD_PYTHON=0"
fi
# If we need to build python, we also need to install the python toolchain
if [[ $with_visualization == 1 ]]; then
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_BUILD_VISUALIZATION_CLIENT=1"
else
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_BUILD_VISUALIZATION_CLIENT=0"
fi
##################################################################3
# setup compilers and includes
#
# mac compiler detection
export LD_LIBRARY_PATH=${PWD}/deps/local/lib:${PWD}/deps/local/lib64:$LD_LIBRARY_PATH
export INCLUDE_PATH=${PWD}/deps/local/include:$LD_LIBRARY_PATH
echo "======================= BUILD CONFIGURATION ========================"
echo "System Information: "
uname -v
if [[ $OSTYPE == darwin* ]]; then
if [[ -z $CC ]] && [[ -z $CXX ]]; then
CC=clang
CXX=clang++
fi
fi
# all other cases
# If not specified we assume gcc and g++ are the default c and c++
# compilers
if [[ -z $CC ]]; then
if [[ `which cc` ]]; then
CC=cc
elif [[ `which gcc` ]]; then
CC=gcc
elif [[ `which clang` ]]; then
CC=clang
else
echo "Compiler not in path with cc/gcc/clang; set manually with CC=<comp>"
exit 1
fi
fi
if [[ -z $CXX ]]; then
if [[ `which cxx` ]]; then
CXX=cxx
elif [[ `which c++` ]]; then
CXX=c++
elif [[ `which g++` ]]; then
CXX=g++
elif [[ `which clang++` ]]; then
CXX=clang++
else
echo "Compiler not it path with cxx/c++/g++/clang++; set manually with CXX=<comp>"
exit 1
fi
fi
CCCMD=`which $CC || echo ""`
CXXCMD=`which $CXX || echo ""`
echo "CC = $CCCMD"
echo "CXX = $CXXCMD"
echo "Attempting to use C compiler $CCCMD."
echo "Attempting to use C++ compiler $CXXCMD."
# Test for ccache
CCACHE=`which ccache || echo ""`
CCSCR="$DEPS_PREFIX/bin/cc"
CXXSCR="$DEPS_PREFIX/bin/cxx"
mkdir -p $DEPS_PREFIX/bin
rm -f $CCSCR
rm -f $CXXSCR
if [ $with_ccache -eq 1 ] && [ -f $CCACHE ]; then
echo "Using ccache from $CCACHE."
mkdir -p $DEPS_PREFIX/bin
echo "#!/bin/bash -e
$CCACHE $CCCMD \$@
exit \$?
" > $CCSCR && chmod a+x $CCSCR
echo "#!/bin/bash -e
$CCACHE $CXXCMD \$@
exit \$?
" > $CXXSCR && chmod a+x $CXXSCR
else
echo "#!/bin/bash -e
$CCCMD \$@
exit \$?
" > $CCSCR && chmod a+x $CCSCR
echo "#!/bin/bash -e
$CXXCMD \$@
exit \$?
" > $CXXSCR && chmod a+x $CXXSCR
echo "Not using CCache."
fi
CCCMD=$CCSCR
CXXCMD=$CXXSCR
echo "Checking for CMake."
## ============================================================================
# Install Cmake if not present
## Obtained from forum:
# http://stackoverflow.com/questions/4023830/bash-how-compare-two-strings-in-version-format
# Return 0 if version are equal
# Returns 1 if version 1 is larger
# Returns 2 if version 2 is larger
function check_version {
if [[ $1 == $2 ]]
then
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
return 2
fi
done
return 0
}
function install_cmake {
echo "Running script to build bundled cmake version."
CC=$CCCMD CXX=$CXXCMD ./scripts/cmake_setup.sh ${PWD}/deps/src/cmake-3.9.3 ${PWD}/deps/local || exit 1
return $?
}
CMAKE=`which cmake || echo ""`
function check_cmake {
if [[ -f $CMAKE ]] ; then
if [[ $with_system_cmake == 0 ]]; then
echo "Forcing use of bundled cmake."
CMAKE=${PWD}/deps/local/bin/cmake
if [[ ! -f ${PWD}/deps/local/bin/cmake ]]; then
install_cmake
return $?
fi
fi
if [[ -f ${PWD}/deps/local/bin/cmake ]]; then
CMAKE=${PWD}/deps/local/bin/cmake
fi
#test cmake version
echo "Testing existing cmake version..."
currentversion=`$CMAKE --version | awk -F "patch" '{print $1;}' | tr -dc '[0-9].'`
echo "Detected ${currentversion}. Required 3.5.0"
check_version $currentversion "3.5.1"
if [ $? -ne 2 ]; then
echo "CMake version is good; using built-in version."
else
install_cmake
CMAKE=${PWD}/deps/local/bin/cmake
return $?
fi
else
install_cmake
CMAKE=${PWD}/deps/local/bin/cmake
return $?
fi
}
check_cmake || {
echo "Error 1: Error reported installing CMake."
exit 1
}
########################################################
# Prepare to build
set -e
set -o pipefail
# Delete the cython make files. If cython files get removed,
# CMake has a tendency to leave the build files around.
# So we just delete them and reconfigure should take care of it.
rm -rf ${RELEASE_DIR}/src/unity/python/turicreate/cython
rm -rf ${DEBUG_DIR}/src/unity/python/turicreate/cython
echo -e "\n\n\n======================= Release ========================" \
if [ ! -d $RELEASE_DIR ]; then
mkdir $RELEASE_DIR
fi
cd $RELEASE_DIR
rm -f CMakeCache.txt
build_cmd="$CMAKE \
$GENERATOR \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_C_COMPILER=$CCCMD \
-D CMAKE_CXX_COMPILER=$CXXCMD \
$CMAKE_CONFIG_FLAGS
../."
echo $build_cmd
eval $build_cmd
cd $TURI_HOME
echo -e "\n\n\n======================= Debug =========================" \
if [ ! -d $DEBUG_DIR ]; then
mkdir $DEBUG_DIR
fi
cd $DEBUG_DIR
rm -f CMakeCache.txt
build_cmd="$CMAKE \
$GENERATOR \
-D CMAKE_BUILD_TYPE=Debug \
-D CMAKE_C_COMPILER=$CCCMD \
-D CMAKE_CXX_COMPILER=$CXXCMD \
$CMAKE_CONFIG_FLAGS
../."
echo $build_cmd
eval $build_cmd
cd $TURI_HOME