forked from nasa/astrobee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.sh
executable file
·350 lines (323 loc) · 10.3 KB
/
configure.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
#!/bin/bash
#
# Copyright (c) 2017, United States Government, as represented by the
# Administrator of the National Aeronautics and Space Administration.
#
# All rights reserved.
#
# The Astrobee platform is licensed under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# Helper to configure the freeflyer build in a simple a repeatable way
#
# This script simply invoke cmake to configure the build with some
# reasonable options for either Native Linux (-l) or/and ArmHF (-a)
#
# The build path (-b), install path (-p) and build type (-B) have
# default values that can be overriden with the according flags.
# Build path and install path are created by default under the home
# directory.
# First identify more or less where we are (absolute or relative ok)
callcmd=$0
workdir=`pwd`
confdir=`dirname $callcmd`
scriptname=${0##*/}
rootpath=`cd $confdir/..; pwd`
cpu_type=`uname -m`
os_kernel=`uname -s | tr '[:upper:]' '[:lower:]'`
gcc_major=`gcc -dumpversion | cut -f-2 -d .`
archname="${cpu_type}_${os_kernel}_gcc${gcc_major}"
# prefix for installation path
prefix=""
# build name (if used, build under freeflyer/build/$buildname)
buildname=""
# configure nothing by default
native_build=0
armhf_build=0
# by default DDS is activated
dds_opt="-DUSE_DDS=on"
# No extra options by default
extra_opts=""
# Force cache cleaning by default
clean_cache=1
# Default debug mode is off
debug_mode=0
# Build target
target="install"
# short help
usage_string="$scriptname [-h] [-l <linux build>] [-a <arm build>]\
[-p install_path] [-b build_path] [-B build_type] [-c <force clean cache>]\
[-C <don't clean cache>] [-d <with DDS>] [-D <without DDS>]\
[-r <with QP planner>] [-R <without QP planner>]\
[-f <with PicoFlexx driver>] [-F <without PicoFlexx driver>]\
[-k <use ccache if available>] [-K <do not use ccache>]\
[-v <with VIVE>] [-V <without VIVE>]\
[-g <print debug information only>]"
#[-t make_target]
# options to parse
optstring="hlap:b:B:cCdDrRfFkKvVmMg"
# Print the script usage
print_usage()
{
echo $usage_string
}
# Print the help message (list all the options)
print_help()
{
echo "scriptname usage:"
echo $usage_string
echo -e "\t-l Generate a Native Linux build"
echo -e "\t-a Generate a cross-compiled ARM build"
echo -e "\t-p install_path specify the installation directory"
echo -e "\t default=${HOME}/cmake_install_platform"
echo -e "\t-b build_path specify the build directory to use"
echo -e "\t default=${HOME}/cmake_build_platform"
echo -e "\t-B build_type specify build type (Debug|Release|RelWithDebInfo)"
echo -e "\t-c delete the cmake cache before for every modules: default on"
echo -e "\t (necessary when re-running buildall with diffent options)"
echo -e "\t-C do not automatically delete the cmake cache when configure is run"
echo -e "\t (need to be specified to avoid cleaning the cache by default)"
echo -e "\t-k use ccache if available to speed up compilation (default)"
echo -e "\t-K do not use ccache and turn on native optimizations"
echo -e "\t-d build with DDS support (default)"
echo -e "\t-D build without DDS support"
echo -e "\t-r build the QP planner (default)"
echo -e "\t-R build without the QP planner"
echo -e "\t-f build with the PicoFlexx driver (default)"
echo -e "\t-F build without the PicoFlexx driver"
echo -e "\t-v build with the VIVE (default)"
echo -e "\t-V build without VIVE"
# echo -e "\t-t make_target define the make build target"
# echo -e "\t default (when ommited) is 'install'"
echo -e "\t when -t is specified, the configure processs is skipped!"
echo -e "\t-g prints some debug information and exit"
echo
echo "Warning 1: -p and -b, unlike the other flags that are sticky (because"
echo "cmake cache them), need to be re-issued at each invocation of the"
echo "script. Otherwise the default values will be used instead."
echo "Warning 2: when using both -a and -l simultanously, the options"
echo "-b and -p are ignored since they would override the platform specific"
echo "behavior (for example -p will be the same for ArmHF and Linux)."
echo
}
# Parse the command line arguments
parse_args()
{
while getopts $optstring opt $@
do
case $opt in
"h") print_help
exit 0
;;
"?") print_usage
exit 1
;;
"l") native_build=1
;;
"a") armhf_build=1
;;
"p") prefix=$OPTARG
;;
"b") build_path=$OPTARG
;;
"B") build_type=$OPTARG
;;
"c") clean_cache=1
;;
"C") clean_cache=0
;;
"d") dds_opt="-DUSE_DDS=on"
;;
"D") dds_opt="-DUSE_DDS=off"
;;
"r") extra_opts+=" -DENABLE_QP=on"
;;
"R") extra_opts+=" -DENABLE_QP=off"
;;
"f") extra_opts+=" -DENABLE_PICOFLEXX=on"
;;
"F") extra_opts+=" -DENABLE_PICOFLEXX=off"
;;
"k") extra_opts+=" -DUSE_CCACHE=on"
;;
"K") extra_opts+=" -DUSE_CCACHE=off"
;;
"v") extra_opts+=" -DENABLE_VIVE=on"
;;
"V") extra_opts+=" -DENABLE_VIVE=off"
;;
"m") extra_opts+=" -DENABLE_DENSE_MAPPER=on"
;;
"M") extra_opts+=" -DENABLE_DENSE_MAPPER=off"
;;
"g") debug_mode=1
;;
*) print_usage
exit 1
;;
esac
done
}
# Return the full canonical path of a file
# Arguments:
# 1 -> path to canonicalize
# Return:
# 0 if the path exist, 1 if the path does not exist
# prints a string with the canonical path + store it in $canonical_path
canonicalize()
{
freepath=$1
os_name=`uname -s`
case $os_name in
Linux)
# just use readlink :-)
canonical_path=`readlink -f $freepath`
readl_ret=$?
echo $canonical_path
if [ $readl_ret == 1 ] ; then
return 1
else
return 0
fi
;;
Darwin | SunOS)
# BSD systems do not support readlink :-(
if [ -d $freepath ] ; then
# the argument is a directory
canonical_path=`cd $freepath && pwd -P`
else
if [ -f $freepath ] ; then
# the argument is a file
freedir=`dirname $freepath`
freefile=`basename $freepath`
if [ -L $freepath ] ; then
canfile=`cd $freedir && stat -f "%Y" $freefile`
else
canfile=$freefile
fi
candir=`cd $freedir && pwd -P`
canonical_path="${candir}/${canfile}"
else
# given path does not exsit
# since readlink does not return any string for this
# scenario, just lets do the same and return an error
canonical_path=""
return 1
fi
fi
echo $canonical_path
return 0
;;
*)
# echo platform not supported yet
echo "/${os_name}/is/not/yet/supported/by/canonicalize"
return 1
;;
esac
}
# function to use the cmake configure with the right arguments
# arguments:
# 1: build_path
# 2: build_type
# 3: install_path
# 4: freeflyer_path
# 5: clean_cache
# 6-*: other options
configure()
{
local build_path=$1
shift
local build_type=$1
shift
local install_path=$1
shift
local ff_path=$1
shift
local clean_cache=$1
shift
local cmake_opts=$@
if [ $debug_mode == 1 ]; then
echo "build type: ${build_type}"
echo "build path: ${build_path}"
echo "install directory: ${install_path}"
echo
else
if [ "$install_path" != "none" ] ; then
if [ ! -d ${install_path} ] ; then
echo "Creating install directory: ${install_path}"
mkdir -p $install_path
fi
full_install_path=`canonicalize $install_path`
install_opt="-DCMAKE_INSTALL_PREFIX=${full_install_path}"
fi
if [ ! -d ${build_path} ] ; then
echo "Creating build directory: ${build_path}"
mkdir -p ${build_path}
fi
cd ${build_path}
if [ ${clean_cache} -eq 1 ] ; then
echo "Remove the CMake Cache for ${build_path}"
rm -f CMakeCache.txt
fi
cmd="cmake -DCMAKE_BUILD_TYPE=${build_type} ${install_opt} ${cmake_opts} ${ff_path}"
echo $cmd # to se what we are geting
$cmd
fi
}
# Start the real work here...
parse_args $@
# Define the paths to use
ff_path=`canonicalize ${rootpath}`
if [ $debug_mode == 1 ]; then
echo "script is called from: $workdir"
echo "script dir is: $confdir"
echo "scriptname is: $scriptname"
echo "absolute script path: $rootpath"
echo "freeflyer canonical path: ${ff_path}"
echo "DDS configuration: ${dds_opt}"
echo "Other Options:" ${extra_opts}
echo "linux build enabled: ${native_build}"
echo "armhf build enabled: ${armhf_build}"
echo
fi
if [[ $native_build == 0 && $armhf_build == 0 ]] ; then
echo "Nothing to configure (use -l or -a)..."
echo "Use $scriptname -h for the full list of options"
print_usage
fi
if [[ $native_build == 1 && $armhf_build == 1 ]] ; then
echo -n "Linux and ArmHF invoked simultanously:"
echo " dropping any option -p and -b!"
prefix=""
build_path=""
fi
if [ $native_build == 1 ] ; then
echo "configuring for native linux..."
# Performance of the shared disk system is horrendous on Vagrant.
# So by default we build in the home directory that is Vagrant native.
# In addition, we do not create an install directory by default.
# Update: we are currently forced to provide an install prefix!
native_build_path=${build_path:-${HOME}/freeflyer_build/native}
native_install_path=${prefix:-${HOME}/freeflyer_install/native}
configure ${native_build_path} ${build_type:-RelWithDebInfo} \
${native_install_path} ${ff_path} ${clean_cache} \
${dds_opt} ${extra_opts}
fi
if [ $armhf_build == 1 ] ; then
echo "configuring for armhf..."
armhf_opts="-DCMAKE_TOOLCHAIN_FILE=${ff_path}/scripts/build/ubuntu_cross.cmake -DUSE_CTC=true"
armhf_build_path=${build_path:-${HOME}/freeflyer_build/armhf}
armhf_install_path=${prefix:-${HOME}/freeflyer_install/armhf}
configure ${armhf_build_path} ${build_type:-Release} \
${armhf_install_path} ${ff_path} ${clean_cache} \
${dds_opt} ${armhf_opts} ${extra_opts}
fi