forked from apple/turicreate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·330 lines (268 loc) · 9.41 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
#!/bin/bash
# Exit immediately on failure of a subcommand
set -e
##=============================================================================
## Main configuration processing
RELEASE_DIR=release
DEBUG_DIR=debug
TURI_HOME=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
DEPS_PREFIX=$PWD/deps/local
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-ccache (default) Use ccache, if available."
echo " --no-ccache "
echo
echo " --with-capi (default) Build C API."
echo " --with-capi-framework Build C API as macOS framework (macOS only)"
echo " --no-capi Skip building the C API."
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 " --with-extra-opt-flags (default) Enable extra optimization flags (e.g. inlining)."
echo " --no-extra-opt-flags"
echo
echo " --with-stack-display Display stack traces to stderr when possible."
echo " --no-stack-display (default) Only write stack traces to file, not to stderr."
echo " --llvm-path Path to LLVM (required for stack trace display)."
echo
echo " --release-opt-for-size Optimize for size."
echo " --debug-opt-for-size Debug optimize for size."
echo " --target-ios Build for iOS (macOS only)"
echo
echo " --with-remotefs (default) Include capabilities for remote file access."
echo " --no-remotefs Disable remote file access."
echo
echo " --virtualenv VIRTUALENV_EXE Path to virtualenv executable (otherwise looks in \$PATH)."
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 "Relevant environment variables: "
echo
echo " CMAKE Path to CMake executable."
echo " CC Path to C compiler."
echo " CXX Path to C++ compiler."
echo
echo "Example: ./configure"
echo
echo "Cleanup all build directories"
echo "Example: ./configure --cleanup"
echo
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."
# TODO - validate that $VIRTUALENV is set, and/or set it if not
echo "Using virtualenv at $VIRTUALENV."
pushd ${TURI_HOME}
VIRTUALENV=${VIRTUALENV} ./scripts/install_python_toolchain.sh
popd
}
# command flag options
cleanup_option=0
python_only=0
default_yes=0
with_python=1
with_ccache=1
with_capi=1
with_capi_framework=0
with_ios=0
with_ccache=1
with_visualization=1
with_remotefs=1
with_extra_opt_flags=1
with_stack_display=0
release_opt_for_size=0
debug_opt_for_size=0
llvm_path=""
###############################################################################
#
# Parse command line configure flags ------------------------------------------
#
while [ $# -gt 0 ]
do case $1 in
--cleanup) cleanup_option=1;;
--install-python-toolchain) python_only=1;;
--release-opt-for-size) release_opt_for_size=1;;
--debug-opt-for-size) debug_opt_for_size=1;;
--target-ios) with_ios=1; with_python=0; with_capi=1; release_opt_for_size=1;;
--with-ccache) with_ccache=1;;
--no-ccache) with_ccache=0;;
--with-capi) with_capi=1;;
--with-capi-framework) with_capi=1; with_capi_framework=1;;
--no-capi) with_capi=0;;
--with-python) with_python=1;;
--no-python) with_python=0;;
--with-extra-opt-flags) with_extra_opt_flags=1;;
--no-extra-opt-flags) with_extra_opt_flags=0;;
--with-stack-display) with_stack_display=1;;
--no-stack-display) with_stack_display=0;;
--llvm-path) shift; llvm_path="$1";;
--with-visualization) with_visualization=1;;
--no-visualization) with_visualization=0;;
--with-remotefs) with_remotefs=1;;
--no-remotefs) with_remotefs=0;;
--yes) default_yes=1;;
--help) print_help ;;
-D) CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -D $2"; shift ;;
--virtualenv) VIRTUALENV="$2"; shift ;;
*) unknown_option $1 ;;
esac
shift
done
if [[ $cleanup_option == 1 ]]; then
run_cleanup_prompt
exit 0
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"
fi
if [[ $with_extra_opt_flags == 1 ]]; then
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_EXTRA_OPTIMIZATION_FLAGS=1"
fi
if [[ $with_stack_display == 1 ]]; then
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_STACK_DISPLAY=1"
fi
if [[ ! -z "${llvm_path}" ]]; then
llvm_libraries=$("${llvm_path}/bin/llvm-config" --link-static --libs | tr ' ' ';')
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_LLVM_PATH=${llvm_path}"
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_LLVM_LIBRARIES='${llvm_libraries}'"
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_HAS_LLVM=1"
fi
if [[ $release_opt_for_size == 1 ]]; then
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DRELEASE_OPT_FOR_SIZE=1"
fi
if [[ $debug_opt_for_size == 1 ]]; then
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DDEBUG_OPT_FOR_SIZE=1"
fi
# Check what is needed with the remote_fs stuff
if [[ $with_capi == 1 ]]; then
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_BUILD_CAPI=1"
if [[ $with_capi_framework == 1 ]]; then
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_BUILD_CAPI_FRAMEWORK=1"
fi
if [[ $with_ios == 1 ]]; then
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DARCH=arm64 -DTC_BUILD_IOS=1"
fi
else
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_BUILD_CAPI=0"
fi
# Do we need to build the visualization toolkit?
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
# Tell CMake whether we need to build the remote FS stuff.
if [[ $with_remotefs == 1 ]]; then
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_BUILD_REMOTEFS=1"
else
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_BUILD_REMOTEFS=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
echo "======================= FINDING COMPILERS ========================"
# Set up the compilers
mkdir -p ${PWD}/deps/local/bin
CCCMD=`./scripts/find_compiler.sh cc --ccache=$with_ccache --script-dir=${PWD}/deps/local/bin/`
CXXCMD=`./scripts/find_compiler.sh cxx --ccache=$with_ccache --script-dir=${PWD}/deps/local/bin/`
echo "Setting C compiler to $CCCMD."
echo "Setting C++ compiler to $CXXCMD."
echo "======================= FINDING CMAKE ========================"
# Set up the path to CMake
CMAKE=`./scripts/find_cmake.sh`
########################################################
# Prepare to build
set -e
set -o pipefail
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