-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-ivp.sh
executable file
·195 lines (168 loc) · 6.74 KB
/
build-ivp.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
#!/bin/bash
#---------------------------------------------------------
# Script: build-ivp.sh
# By: Mike Benjamin
#---------------------------------------------------------
# Part 1: Define global script variables
#---------------------------------------------------------
BUILD_DEBUG="yes"
BUILD_OPTIM="yes"
CLEAN="no"
CMD_ARGS="-j$(getconf _NPROCESSORS_ONLN)"
BUILD_WITH_UTM="-DUSE_UTM=ON"
# By default, all code is built
BUILD_BOT_CODE_ONLY="OFF"
BUILD_GUI_CODE="ON"
FORCE_FULL_RASPI_BUILD=""
#---------------------------------------------------------
# Part 2: Handle Command Line Arguments
#---------------------------------------------------------
for ARGI; do
if [ "${ARGI}" = "--help" -o "${ARGI}" = "-h" ]; then
echo "build-ivp.sh [OPTIONS] [MAKE ARGS] "
echo "Options: "
echo " --help, -h "
echo " --nodebug "
echo " Do not include the -g compiler flag "
echo " --noopt "
echo " Do not include the -Os compiler flag "
echo " --fast, -f "
echo " Do not include the -Os, -g compiler flags "
echo " --nogui, -n "
echo " Do not build GUI related apps "
echo " --utm_off, -u "
echo " Do not build wit UTM for Geodesy "
echo " --minrobot, -m "
echo " Only build minimal robot apps "
echo " (Even smaller subset than with --nogui) "
echo " --minrobotx, -mx "
echo " Override min-robot default on Raspbian "
echo " --clean, -c "
echo " Invokes make clean and removes build/* "
echo " "
echo "By default, all code is built, and the debug and "
echo "optimization compiler flags are invoked. "
echo " "
echo "Note: "
echo " By default -jN is provided to make to utilize up to N "
echo " processors in the build. This can be overridden simply "
echo " by using -j1 on the command line instead. This will give "
echo " more reasonable output if there should be a build error. "
exit 0
elif [ "${ARGI}" = "--nodebug" ]; then
BUILD_DEBUG="no"
elif [ "${ARGI}" = "--noopt" ]; then
BUILD_OPTIM="no"
elif [ "${ARGI}" = "--utm_off" -o "${ARGI}" = "-u" ]; then
BUILD_WITH_UTM="-DUSE_UTM=OFF"
elif [ "${ARGI}" = "--fast" -o "${ARGI}" = "-f" ]; then
BUILD_DEBUG="no"
BUILD_OPTIM="no"
elif [ "${ARGI}" = "--clean" -o "${ARGI}" = "-c" ]; then
CLEAN="yes"
elif [ "${ARGI}" = "--nogui" -o "${ARGI}" = "-n" ]; then
BUILD_GUI_CODE="OFF"
elif [ "${ARGI}" = "--minrobot" -o "${ARGI}" = "-m" ]; then
BUILD_BOT_CODE_ONLY="ON"
BUILD_GUI_CODE="OFF"
elif [ "${ARGI}" = "--minrobotx" -o "${ARGI}" = "-mx" ]; then
FORCE_FULL_RASPI_BUILD="yes"
else
if [ "$CMD_ARGS" = "" ]; then
CMD_ARGS=$ARGI
else
CMD_ARGS=$CMD_ARGS" "$ARGI
fi
fi
done
#--------------------------------------------------------------
# Part 3: If this is Raspbian and minrobot not selected, and
# no explicit override given with -mx, CONFIRM first
#--------------------------------------------------------------
command -v raspi-gpio
if [ "$?" = "0" -a "${BUILD_BOT_CODE_ONLY}" = "OFF" ]; then
if [ ! "${FORCE_FULL_RASPI_BUILD}" = "yes" ]; then
echo "Pi OS detected without --minrobotx or -mx selected."
echo "[y] Continue with full build"
echo "[M] Continue with minrobot build"
echo -n "Continue? [y/M] "
read ANSWER
if [ ! "${ANSWER}" = "y" ]; then
BUILD_BOT_CODE_ONLY="ON"
BUILD_GUI_CODE="OFF"
fi
fi
fi
#---------------------------------------------------------
# Part 4: Set Compiler flags
#---------------------------------------------------------
CMAKE_CXX_FLAGS="-Wall -Wextra -Wno-unused-parameter "
CMAKE_CXX_FLAGS+="-Wno-missing-field-initializers -pedantic -fPIC "
# -Wno-psabi turns off warnings about ABI change between gcc 6 and 7.1
CMAKE_CXX_FLAGS+="-Wno-psabi "
if [ "${BUILD_DEBUG}" = "yes" ] ; then
CMAKE_CXX_FLAGS=$CMAKE_CXX_FLAGS" -g"
fi
if [ "${BUILD_OPTIM}" = "yes" ] ; then
CMAKE_CXX_FLAGS=$CMAKE_CXX_FLAGS" -Os"
fi
echo "Compiler flags: ${CMAKE_CXX_FLAGS} "
#---------------------------------------------------------
# Part 5
#---------------------------------------------------------
INVOC_ABS_DIR="$(pwd)"
SCRIPT_ABS_DIR="$(cd $(dirname "$0") && pwd -P)"
BLD_ABS_DIR="${SCRIPT_ABS_DIR}/build"
LIB_ABS_DIR="${SCRIPT_ABS_DIR}/lib"
BIN_ABS_DIR="${SCRIPT_ABS_DIR}/bin"
SRC_ABS_DIR="${SCRIPT_ABS_DIR}/ivp/src"
echo "Built files will be placed into these directories: "
echo " Intermediate build files: ${BLD_ABS_DIR} "
echo " Libraries: ${LIB_ABS_DIR} "
echo " Programs: ${BIN_ABS_DIR} "
mkdir -p "${BLD_ABS_DIR}"
mkdir -p "${LIB_ABS_DIR}"
mkdir -p "${BIN_ABS_DIR}"
cd "${BLD_ABS_DIR}"
#---------------------------------------------------------
# Part 6: For back compatability, if user has environment var
# IVP_BUILD_GUI_CODE set to "OFF" then honor it here
# as if --nogui it were set on the command line
#---------------------------------------------------------
if [ "${IVP_BUILD_GUI_CODE}" = "OFF" ] ; then
BUILD_GUI_CODE="OFF"
echo "IVP GUI Apps will not be built since the "
echo "IVP_BUILD_GUI_CODE environment var is OFF "
fi
echo "BUILD_GUI_CODE = ${BUILD_GUI_CODE} "
#---------------------------------------------------------
# Part 7: Invoke CMake
#---------------------------------------------------------
echo "Invoking cmake..."
echo "BUILD_BOT_CODE_ONLY: ${BUILD_BOT_CODE_ONLY} "
cmake -DIVP_BUILD_GUI_CODE=${BUILD_GUI_CODE} \
-DFLTK_SKIP_FLUID=ON \
-DIVP_BUILD_BOT_CODE_ONLY=${BUILD_BOT_CODE_ONLY} \
-DIVP_LIB_DIRECTORY="${LIB_ABS_DIR}" \
-DIVP_BIN_DIRECTORY="${BIN_ABS_DIR}" \
-DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}" \
${BUILD_WITH_UTM} \
${IVP_CMAKE_FLAGS} \
"${SRC_ABS_DIR}"
#---------------------------------------------------------
# Part 8: Invoke Make
#---------------------------------------------------------
echo "Invoking make ${CMD_ARGS}"
RESULT=0
if [ "${CLEAN}" = "yes" -o "${CMD_ARGS}" = "clean" ] ; then
echo "CLEANING...."
make clean
RESULT=$?
cd ${INVOCATION_ABS_DIR}
rm -rf build/*
else
make ${CMD_ARGS}
RESULT=$?
fi
cd ${INVOC_ABS_DIR}
exit $RESULT