-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.sh
199 lines (177 loc) · 7.38 KB
/
build.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
#!/usr/bin/env bash
SCRIPT=$(readlink -f "$0")
SCRIPTPATH=$(dirname "$SCRIPT")
USAGE="Usage: ./build.sh [c++=[0,1]] [py=[0,1]] [clean]\n"
USAGE+="\tc++=[0,1] : 0 to not build ORBSLAM2 C++11 implementation and 1 otherwise\n"
USAGE+="\t default is 0\n"
USAGE+="\tpy=[0,1] : 0 to not build ORBSLAM2 Python implementation and 1 otherwise\n"
USAGE+="\t default is 1\n"
USAGE+="\tclean : clean both C++11 and Python previous build and don't rebuild\n"
#########################################
# Configurate the Build #
#########################################
# If no arguments, build only python wrapper by default
BUILDCPLUSPLUS=false
BUILDPYTHON=true
# Parsing command-line arguments
# If it's the first time build, build both C++ and python wrapper
if [ -z $ORBSLAM2PYFIRSTBUILD ] ; then
BUILDCPLUSPLUS=true
BUILDPYTHON=true
# If there are arguments, parse all arguments
elif [ $# -ne 0 ] ; then
while [ ! -z $1 ] ; do
if [ "$1" = "c++=1" ] ; then # Build C++
BUILDCPLUSPLUS=true
elif [ "$1" = "py=0" ] ; then # Don't build python wrapper
BUILDPYTHON=false
elif [ "$1" = "clean" ] ; then # Clean previous builds only
BUILDCLEAN=true
break
elif [[ "$1" != "c++=0" && "$1" != "py=1" ]] ; then
echo -e "Unknown argument: " $1
echo -e "$USAGE"
exit 1
fi
shift # shift $2 to $n to be renamed $1 to $(n-1)
done
fi
#########################################
# Start the Clean Process #
#########################################
if [ "$BUILDCLEAN" = true ] ; then
echo -e "\nNo build will be done, only cleaning\n"
# Remove ORBSLAM2_C++11 previous build
echo -e "\nRemoving C++11 previous build..."
cd "$SCRIPTPATH"/ORBSLAM2_C++11
rm -rf build lib \
Thirdparty/DBoW2/build \
Thirdparty/DBoW2/lib \
Thirdparty/g2o/build \
Thirdparty/g2o/lib \
Thirdparty/g2o/config.h \
Vocabulary/ORBvoc.txt \
Examples/Monocular/mono_euroc \
Examples/Monocular/mono_kitti \
Examples/Monocular/mono_tum \
Examples/RGB-D/rgbd_tum \
Examples/Stereo/stereo_euroc \
Examples/Stereo/stereo_kitti
# Remove python wrapper previous build
echo -e "\nRemoving Python previous build..."
cd "$SCRIPTPATH"
rm -rf bin build
exit 0
fi
# Echo the building information
echo -e "\n\n"
echo -e "################################################################################\n"
echo -e "\tBuilding Information\n"
if [ "$BUILDCPLUSPLUS" = true ] ; then
echo -e "\t\tBuild C++11 Implementation\n"
fi
if [ "$BUILDPYTHON" = true ] ; then
echo -e "\t\tBuild Python Implementation\n"
fi
if [[ "$BUILDCPLUSPLUS" = false && "$BUILDPYTHON" = false ]] ; then
echo -e "\t\tNo build is specified... Exiting...\n"
echo -e "################################################################################\n"
echo -e "\n$USAGE\n"
exit 0
fi
echo -e "################################################################################\n"
# Prints out USAGE
echo -e "\n$USAGE\n"
echo -e ".......... Building will start in 5 seconds .........."
sleep 5
#########################################
# Start the Build Process #
#########################################
if [ "$BUILDCPLUSPLUS" = true ] ; then
# Remove ORBSLAM2_C++11 previous build
echo -e "\nRemoving C++11 previous build..."
cd "$SCRIPTPATH"/ORBSLAM2_C++11
rm -rf build lib \
Thirdparty/DBoW2/build \
Thirdparty/DBoW2/lib \
Thirdparty/g2o/build \
Thirdparty/g2o/lib \
Thirdparty/g2o/config.h \
Vocabulary/ORBvoc.txt \
Examples/Monocular/mono_euroc \
Examples/Monocular/mono_kitti \
Examples/Monocular/mono_tum \
Examples/RGB-D/rgbd_tum \
Examples/Stereo/stereo_euroc \
Examples/Stereo/stereo_kitti
# Rebuild ORBSLAM2_C++11
echo -e "\nBuilding C++11 Implementation..."
chmod +x build.sh
./build.sh
if [ $? -ne 0 ] ; then
echo -e "\nFailed to build C++11 Implementation... Exiting...\n"
exit 1
fi
cd "$SCRIPTPATH/ORBSLAM2_C++11/build"
make install
if [ $? -ne 0 ] ; then
echo -e "\nFailed to make install C++11 Implementation... Exiting...\n"
exit 1
fi
fi
if [ "$BUILDPYTHON" = true ] ; then
# Remove python wrapper previous build
echo -e "\nRemoving Python previous build..."
cd "$SCRIPTPATH"
rm -rf bin build
# Build python wrapper
echo -e "\nBuilding Python Implementation..."
mkdir build
cd build
cmake ..
if [ $? -ne 0 ] ; then
echo -e "\nFailed to cmake Python Implementation... Exiting...\n"
exit 1
fi
# If it's the first time build, add environment variable
if [ -z $ORBSLAM2PYFIRSTBUILD ] ; then
echo "export CPATH=/usr/local/include/eigen/:"$SCRIPTPATH"/ORBSLAM2_C++11:/slamdoom/libs/cppzmq:/usr/local/include/" \
>> ~/.bashrc
echo "export LD_LIBRARY_PATH="$SCRIPTPATH"/ORBSLAM2_C++11/Thirdparty/DBoW2/lib" \
>> ~/.bashrc
source ~/.bashrc
fi
make -j$(nproc)
if [ $? -ne 0 ] ; then
echo -e "\nFailed to make Python Implementation... Exiting...\n"
exit 1
fi
make install
if [ $? -ne 0 ] ; then
echo -e "\nFailed to make install Python Implementation... Exiting...\n"
exit 1
fi
fi
# If it's the first time build, include into PYTHONPATH
if [ -z $ORBSLAM2PYFIRSTBUILD ] ; then
echo "export ORBSLAM2PYFIRSTBUILD=false" \
>> ~/.bashrc
source ~/.bashrc
fi
# Echo command to run example
COMMANDTORUNCPLUSPLUS="\t\tcd ORBSLAM2_C++11/Examples/Stereo/KITTI_Dataset\n"
COMMANDTORUNCPLUSPLUS+="\t\t./download_kitti_dataset.sh\n"
COMMANDTORUNCPLUSPLUS+="\t\tcd ..\n"
COMMANDTORUNCPLUSPLUS+="\t\t./stereo_kitti ../../Vocabulary/ORBvoc.txt ./KITTIX.yaml \\ \n"
COMMANDTORUNCPLUSPLUS+="\t\t\t./KITTI_Dataset/dataset/sequences/SEQUENCE_NUMBER\n"
COMMANDTORUNPYTHON="\t\tpython3 examples/orbslam_stereo_kitti.py \\ \n"
COMMANDTORUNPYTHON+="\t\t\tORBSLAM2_C++11/Vocabulary/ORBvoc.txt \\ \n"
COMMANDTORUNPYTHON+="\t\t\tORBSLAM2_C++11/Examples/Stereo/KITTIX.yaml \\ \n"
COMMANDTORUNPYTHON+="\t\t\tORBSLAM2_C++11/Examples/Stereo/KITTI_Dataset/dataset/sequences/SEQUENCE_NUMBER\n"
echo -e "\n\n"
echo -e "################################################################################\n"
echo -e "\tCommmand to run ORBSLAM2 C++11 Implementation:\n"\
"${COMMANDTORUNCPLUSPLUS}"\
"\n\tCommand to run ORBSLAM2 Python Implementation:\n"\
"${COMMANDTORUNPYTHON}"
echo -e "################################################################################\n"