forked from SGL-UT/GPSTk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
script_gpstk_cpp.sh
executable file
·439 lines (361 loc) · 10.9 KB
/
script_gpstk_cpp.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
#!/bin/bash
#----------------------------------------
#
# purpose = Automate the use of CMake and make to build C++ GPSTk
#
# outline = Optionally clean out install and build paths
# Export gpstk install path as environment variables used by CMake
# Run CMake to generate build environment
# Run make to build GPSTk
# Run make install to install GPSTk
# Echo a list of the installed files
#
# usage: ./script_gpstk_cpp.sh [-h] [-d] [-b] [-i] [-o] [-t] [-v] [-r <path>] [-s <path>]
#
# OPTIONS:
# -h help, Show this message
# -d build_doxygen, build doxygen files
#
# -b clean_build, rm -rf gpstk_root/build
# -i clean_install, rm -rf gpstk_install
#
# -o core_only, only builds core library code
# -t test_switch, initialize test framework
# -v graphviz, generate dependency graph (.DOT and .PDF files)
#
# -r gpstk_root, default = ~/git/gpstk/dev, path to GPSTk top-level CMakeLists.txt file (and source tree)
# -s gpstk_install, default = ~/git/gpstk/install, path to GPSTk install, e.g. /opt/gpstk, to contain ./bin, ./lib, and ./include
#
#----------------------------------------
#----------------------------------------
# usage() function to use when help is needed:
#----------------------------------------
usage()
{
cat << EOF
usage: $0 [-h] [-d] [-b] [-i] [-o] [-t] [-v] [-r <path>] [-s <path>]
purpose: This script is for use with CMake and building GPSTk.
OPTIONS:
-h help, Show this message
-d build_doxygen, build doxygen files
-b clean_build, rm -rf gpstk_root/build
-i clean_install, rm -rf gpstk_install
-o core_only, only builds core library code
-t test_switch, initialize test framework
-v graphviz, generate dependency graph (.DOT and .PDF files)
-r gpstk_root, default = ~/git/gpstk/dev, path to GPSTk top-level CMakeLists.txt file (and source tree)
-s gpstk_install, default = ~/git/gpstk/install, path to GPSTk install, e.g. ~/opt/gpstk, to contain ./bin, ./lib, and ./include
EOF
exit 1
}
#----------------------------------------
# initialize variables as empty
#----------------------------------------
build_doxygen=
clean_build=
clean_install=
core_only=
test_switch=
graphviz=
gpstk_root=
gpstk_install=
#----------------------------------------
# initialize Color Codes
#----------------------------------------
green='\e[1;32m'
red='\e[1;31m'
normal='\e[0m'
white='\e[1;37m'
cyan='\e[1;36m'
purple='\e[1;35m'
brown='\e[1;33m'
#----------------------------------------
# Parse input arguments
#----------------------------------------
while getopts "hdbiotv:r:s:" option; do
case $option in
h)
usage
;;
d)
build_doxygen=1
;;
b)
clean_build=1
;;
i)
clean_install=1
;;
o)
core_only=1
;;
t)
test_switch=1
;;
v)
graphviz=1
;;
r)
gpstk_root=${OPTARG}
;;
s)
gpstk_install=${OPTARG}
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
esac
done
# Shift OPTIND so that if there are any additional
# command line options we did not capture,
# then they are accessible via use of $*
shift $(($OPTIND - 1))
#----------------------------------------
# Set input arg defaults, if empty
#----------------------------------------
if [ -z $build_doxygen ]
then
build_doxygen=0
echo "$0: Input arg: build_doxygen = $build_doxygen (default)"
else
echo "$0: Input arg: build_doxygen = $build_doxygen (user provided)"
fi
if [ -z $clean_build ]
then
clean_build=0
echo "$0: Input arg: clean_build = $clean_build (default)"
else
echo "$0: Input arg: clean_build = $clean_build (user provided)"
fi
if [ -z $clean_install ]
then
clean_install=0
echo "$0: Input arg: clean_install = $clean_install (default)"
else
echo "$0: Input arg: clean_install = $clean_install (user provided)"
fi
if [ -z $gpstk_root ]
then
gpstk_root=~/git/gpstk/dev
echo "$0: Input arg: gpstk_root = $gpstk_root (default)"
else
echo "$0: Input arg: gpstk_root = $gpstk_root (user provided)"
fi
if [ -z $gpstk_install ]
then
gpstk_install=~/git/gpstk/install
echo "$0: Input arg: gpstk_install = $gpstk_install (default)"
else
echo "$0: Input arg: gpstk_install = $gpstk_install (user provided)"
fi
if [ -z $core_only ]
then
core_only=0
echo "$0: Input arg: core_only = $core_only (default)"
else
echo "$0: Input arg: core_only = $core_only (user provided)"
fi
if [ -z $test_switch ]
then
test_switch=0
echo "$0: Input arg: test_switch = $test_switch (default)"
else
echo "$0: Input arg: test_switch = $test_switch (user provided)"
fi
if [ -z $graphviz ]
then
graphviz=0
echo "$0: Input arg: graphviz = $graphviz (default)"
else
echo "$0: Input arg: graphviz = $graphviz (user provided)"
fi
#----------------------------------------
# Test gpstk paths before doing anything
#----------------------------------------
if [ -d $gpstk_root ]
then
echo "$0: Paths: $gpstk_root, directory exist test = PASS"
else
echo "$0: Paths: $gpstk_root, directory exist test = FAIL"
echo "$0: exitting..."
exit 1
fi
if [ ! -d $gpstk_root/build ]
then
echo "$0: Paths: Creating $gpstk_root/build directory"
mkdir $gpstk_root/build
fi
if [ ! -d $gpstk_install ]
then
echo "$0: Paths: Creating $gpstk_install directory"
mkdir $gpstk_install
fi
#----------------------------------------
# Optionally clean out the last gpstk build
#----------------------------------------
if [[ "$clean_build" == 0 ]]
then
echo "$0: Options: Previous build to be removed = FALSE"
else
echo "$0: Options: Previous build to be removed = TRUE"
rm -rf $gpstk_root/build
mkdir $gpstk_root/build
fi
#----------------------------------------
# Optionally clean out the last gpstk install
#----------------------------------------
if [[ "$clean_install" == 0 ]]
then
echo "$0: Options: Previous install to be removed = FALSE"
else
echo "$0: Options: Previous install to be removed = TRUE"
rm -rf $gpstk_install
mkdir $gpstk_install
fi
#----------------------------------------
# Test and then export install paths needed by CMake
#----------------------------------------
if [ -d $gpstk_install ]
then
echo "$0: Paths: $gpstk_install, directory exist test = PASS"
else
echo "$0: Paths: $gpstk_install, directory exist test = FAIL"
echo "$0: exitting..."
exit 1
fi
# This is required by the current CMake set-up
echo "$0: Paths: Exporting install paths..."
export gpstk=$gpstk_install
#----------------------------------------
# CMake
#----------------------------------------
# Construct CMake command string based on script options
# Reminder: to set variables from command line use "$ cmake -D <var>:<type>=<value>"
cmake_command="cmake"
# Update CMake command if optional core_only switch was selected.
if [[ "$core_only" == 0 ]]
then
echo "$0: Options: core_only build library = FALSE"
else
echo "$0: Options: core_only build library = TRUE"
cmake_command=$cmake_command" -DCORE_ONLY=ON"
fi
# Update CMake command if optional test switch was selected.
if [[ "$test_switch" == 0 ]]
then
echo "$0: Options: test_switch test framework = FALSE"
else
echo "$0: Options: test_switch test framework = TRUE"
cmake_command=$cmake_command" -DTEST_SWITCH=ON"
fi
# Update CMake command if optional Graphiz output was selected.
if [[ "$graphviz" == 0 ]]
then
echo "$0: Options: generate graphviz output = FALSE"
else
echo "$0: Options: generate graphviz output = TRUE"
path_graphviz=$gpstk_install/graphviz
mkdir $path_graphviz
cmake_command=$cmake_command" --graphviz=$path_graphviz/gpstk_graphviz.dot"
fi
# Specify path of top-level CmakeLists.txt file
cmake_command=$cmake_command" $gpstk_root"
# Evaluate CMake command string from the build directory
echo "$0: Calling CMake as: $cmake_command"
cd $gpstk_root/build
eval $cmake_command
#----------------------------------------
# Doxygen
#----------------------------------------
# Build Doxygen Files
if [[ "$build_doxygen" == 0 ]]
then
echo "$0: Options: generate doxygen files = FALSE"
else
echo "$0: Options: generate doxygen files = TRUE"
cd $gpstk_root
doxygen
fi
#----------------------------------------
# GraphViz
#----------------------------------------
# Convert graphviz .DOT file into a .PDF
# Can only be called AFTER the cmake command is executed
if [[ "$graphviz" == 0 ]]
then
echo "$0: Options: generate graphviz PDF = FALSE"
else
echo "$0: Options: generate graphviz PDF = TRUE"
dot -Tpdf $path_graphviz/gpstk_graphviz.dot -o $path_graphviz/gpstk_graphviz.pdf
fi
#----------------------------------------
# Make
#----------------------------------------
# Detect system OS flavor
platform='unknown'
unamestr=`uname`
if [[ "$unamestr" == 'Linux' ]]
then
platform='linux'
elif [[ "$unamestr" == 'Darwin' ]]
then
platform='osx'
elif [[ "$unamestr" == 'FreeBSD' ]]
then
platform='freebsd'
fi
# Determine number of cores so that we can make make faster
num_cores=1
if [[ "$platform" == "osx" ]]
then
num_cores=`sysctl -n hw.ncpu`
elif [[ "$platform" == "linux" ]]
then
last_core_index=`cat /proc/cpuinfo | grep "processor" | awk '{print $3}' | tail -1`
num_cores=`echo "$last_core_index + 1" | bc`
else
num_cores=1
fi
# Modify make command to use "-j" flag if you have multiple cores
if [ "$num_cores" -gt "1" ]
then
echo "$0: Optimizing: Discovered multiple ($num_cores) cores for use with 'make -j' "
make_command="make -j $num_cores"
else
make_command="make"
fi
# Evaluate make command from GPSTk build directory
echo "$0: Calling make and make install..."
cd $gpstk_root/build
eval $make_command
# Install!
make install
#----------------------------------------
# Echo the contents of the install paths
#----------------------------------------
cd $gpstk_install
echo ""
echo "$0: Installed file listing..."
echo ""
echo "$0: Installed binaries: $gpstk_install/bin/"
ls $gpstk_install/bin
echo ""
echo "$0: Installed headers: $gpstk_install/include/"
ls $gpstk_install/include
echo ""
echo "$0: Installed libraries: $gpstk_install/lib/"
ls $gpstk_install/lib
echo ""
echo ""
echo "$0: ...done."
echo ""
echo ""
if [[ "$test_switch" == 1 ]]
then
cd $gpstk_root/build
ctest -v
fi
#----------------------------------------
# The End
#----------------------------------------