-
Notifications
You must be signed in to change notification settings - Fork 2
/
build_micro_ros_library.sh
executable file
·258 lines (224 loc) · 9.82 KB
/
build_micro_ros_library.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
#!/bin/bash
# Depending on the MICROROS_TARGET environment variable, this script will build the micro-ROS library for the selected target.
# The following targets are supported:
# - VITIS_MICROBLAZE
# - VITIS_CORTEX_R5
# - GENERIC_ARM
# Set compiler flags
export MICROROS_FLAGS=""
# MicroBlaze custom flags
export MICROBLAZE_ENDIANNESS_FLAG="-mlittle-endian"
export MICROBLAZE_64BITS=""
# Iterate over the arguments
for arg in "$@"
do
case $arg in
-f)
export FORCE_BUILD=1
shift
;;
-v)
export VERBOSE_BUILD=1
shift
;;
-bigendiann)
export MICROBLAZE_ENDIANNESS_FLAG="-mbig-endian"
shift
;;
-64bits)
export MICROBLAZE_64BITS="-m64"
shift
;;
*)
# Unknown option
echo "Unknown option: $arg"
exit 1
;;
esac
done
# Check if ROS 2 is sourced
if command -v "ros2" >/dev/null 2>&1
then
echo "ROS 2 sourced, please run this script in a new terminal without sourcing ROS 2"
exit
fi
# Check if MICROROS_TARGET is set
if [ -z "${MICROROS_TARGET}" ]; then
echo "MICROROS_TARGET is not set"
exit
fi
# Check if MICROROS_TARGET is supported
if [ "${MICROROS_TARGET}" != "VITIS_MICROBLAZE" ] &&
[ "${MICROROS_TARGET}" != "VITIS_CORTEX_R5" ] &&
[ "${MICROROS_TARGET}" != "GENERIC_ARM" ]; then
echo "MICROROS_TARGET ${MICROROS_TARGET} is not supported"
exit
fi
# Set toolchain prefixes
if [ "${MICROROS_TARGET}" = "VITIS_MICROBLAZE" ]; then
export TOOLCHAIN_PREFIX=mb-
export MICROROS_FLAGS="${MICROROS_FLAGS} ${MICROBLAZE_ENDIANNESS_FLAG} ${MICROBLAZE_64BITS} -fPIC"
elif [ "${MICROROS_TARGET}" = "VITIS_CORTEX_R5" ]; then
export TOOLCHAIN_PREFIX=armr5-none-eabi-
elif [ "${MICROROS_TARGET}" = "GENERIC_ARM" ]; then
export TOOLCHAIN_PREFIX="arm-none-eabi-"
fi
# Define compilers
export C_COMPILER=${TOOLCHAIN_PREFIX}gcc
export CXX_COMPILER=${TOOLCHAIN_PREFIX}g++
# Check if compilers are available
if ! command -v "${C_COMPILER}" >/dev/null 2>&1
then
echo "${C_COMPILER} command could not be found"
echo "Please add required toolchain to the PATH"
exit 1
fi
if ! command -v "${CXX_COMPILER}" >/dev/null 2>&1
then
echo "${CXX_COMPILER} command could not be found"
echo "Please add required toolchain to the PATH"
exit 1
fi
# Define micro-ROS environment variables
export MICRO_ROS_DISTRO=jazzy
# Set toolchain prefixes
if [ "${MICROROS_TARGET}" = "VITIS_MICROBLAZE" ]; then
export MICRO_ROS_BUILD_DIR=microros_build_microblaze
elif [ "${MICROROS_TARGET}" = "VITIS_CORTEX_R5" ]; then
export MICRO_ROS_BUILD_DIR=microros_build_cortex_r5
elif [ "${MICROROS_TARGET}" = "GENERIC_ARM" ]; then
export MICRO_ROS_BUILD_DIR=microros_build_generic_arm
fi
mkdir -p $MICRO_ROS_BUILD_DIR
# If FORCE_BUILD clean $MICRO_ROS_BUILD_DIR directory
if [ -n "${FORCE_BUILD}" ]; then
rm -rf $MICRO_ROS_BUILD_DIR/*
fi
# If $MICRO_ROS_BUILD_DIR/dev/src exists, skip this
if [ ! -d "$MICRO_ROS_BUILD_DIR/dev/src" ]; then
# Generate micro-ROS dev environment
mkdir -p $MICRO_ROS_BUILD_DIR/dev/
pushd $MICRO_ROS_BUILD_DIR/dev/ > /dev/null
# Dev environment
git clone -b ${MICRO_ROS_DISTRO} https:/ament/ament_cmake src/ament_cmake;
git clone -b ${MICRO_ROS_DISTRO} https:/ament/ament_lint src/ament_lint;
git clone -b ${MICRO_ROS_DISTRO} https:/ament/ament_package src/ament_package;
git clone -b ${MICRO_ROS_DISTRO} https:/ament/googletest src/googletest;
git clone -b ${MICRO_ROS_DISTRO} https:/ros2/ament_cmake_ros src/ament_cmake_ros;
git clone -b ${MICRO_ROS_DISTRO} https:/ament/ament_index src/ament_index;
popd > /dev/null
fi
# Define colcon event handlers depending of VERBOSE_BUILD
if [ -n "${VERBOSE_BUILD}" ]; then
export COLCON_EVENT_HANDLERS="";
else
export COLCON_EVENT_HANDLERS="--event-handlers compile_commands- console_stderr-";
fi
# If $MICRO_ROS_BUILD_DIR/dev/install exists, skip this
if [ ! -d "$MICRO_ROS_BUILD_DIR/dev/install" ]; then
# Install micro-ROS dev environment
pushd $MICRO_ROS_BUILD_DIR/dev/ > /dev/null
colcon build $COLCON_EVENT_HANDLERS;
popd > /dev/null
fi
# Extra packages folder
export MICROROS_EXTRA_PACKAGES=$(pwd)/extra_packages
# Toolchain file
export TOOLCHAIN=$(pwd)/toolchain.cmake
# If $MICRO_ROS_BUILD_DIR/microros exists, skip this
if [ ! -d "$MICRO_ROS_BUILD_DIR/microros/src" ]; then
# Generate micro-ROS firmware environment
mkdir -p $MICRO_ROS_BUILD_DIR/microros/
pushd $MICRO_ROS_BUILD_DIR/microros/ > /dev/null
# Firmware environment
git clone -b ros2 https:/eProsima/Micro-XRCE-DDS-Client src/Micro-XRCE-DDS-Client;
git clone -b ros2 https:/eProsima/micro-CDR src/micro-CDR;
git clone -b ${MICRO_ROS_DISTRO} https:/micro-ROS/rmw_microxrcedds src/rmw_microxrcedds;
git clone -b ${MICRO_ROS_DISTRO} https:/micro-ROS/rcl src/rcl;
git clone -b ${MICRO_ROS_DISTRO} https:/ros2/rclc src/rclc;
git clone -b ${MICRO_ROS_DISTRO} https:/micro-ROS/rcutils src/rcutils;
git clone -b ${MICRO_ROS_DISTRO} https:/micro-ROS/micro_ros_msgs src/micro_ros_msgs;
git clone -b ${MICRO_ROS_DISTRO} https:/micro-ROS/rosidl_typesupport src/rosidl_typesupport;
git clone -b ${MICRO_ROS_DISTRO} https:/micro-ROS/rosidl_typesupport_microxrcedds src/rosidl_typesupport_microxrcedds;
git clone -b ${MICRO_ROS_DISTRO} https:/ros2/rosidl src/rosidl;
git clone -b ${MICRO_ROS_DISTRO} https:/ros2/rosidl_dynamic_typesupport src/rosidl_dynamic_typesupport;
git clone -b ${MICRO_ROS_DISTRO} https:/ros2/rmw src/rmw;
git clone -b ${MICRO_ROS_DISTRO} https:/ros2/rcl_interfaces src/rcl_interfaces;
git clone -b ${MICRO_ROS_DISTRO} https:/ros2/rosidl_defaults src/rosidl_defaults;
git clone -b ${MICRO_ROS_DISTRO} https:/ros2/unique_identifier_msgs src/unique_identifier_msgs;
git clone -b ${MICRO_ROS_DISTRO} https:/ros2/common_interfaces src/common_interfaces;
git clone -b ${MICRO_ROS_DISTRO} https:/ros2/example_interfaces src/example_interfaces;
git clone -b ${MICRO_ROS_DISTRO} https:/ros2/test_interface_files src/test_interface_files;
git clone -b ${MICRO_ROS_DISTRO} https:/ros2/rmw_implementation src/rmw_implementation;
git clone -b ${MICRO_ROS_DISTRO} https:/ros2/rcl_logging src/rcl_logging;
git clone -b ${MICRO_ROS_DISTRO} https:/ros2/ros2_tracing src/ros2_tracing;
git clone -b ${MICRO_ROS_DISTRO} https:/micro-ROS/micro_ros_utilities src/micro_ros_utilities;
git clone -b ${MICRO_ROS_DISTRO} https:/ros2/rosidl_core src/rosidl_core;
touch src/rosidl/rosidl_typesupport_introspection_cpp/COLCON_IGNORE;
touch src/rcl_logging/rcl_logging_spdlog/COLCON_IGNORE;
touch src/rclc/rclc_examples/COLCON_IGNORE;
touch src/rcl/rcl_yaml_param_parser/COLCON_IGNORE;
touch src/ros2_tracing/test_tracetools/COLCON_IGNORE;
touch src/ros2_tracing/lttngpy/COLCON_IGNORE;
# Add extra packages
cp -rf $MICROROS_EXTRA_PACKAGES src/extra_packages || :;
test -f src/extra_packages/extra_packages.repos && cd src/extra_packages && vcs import --input extra_packages.repos || :;
popd > /dev/null
fi
# Source micro-ROS dev environment
source $MICRO_ROS_BUILD_DIR/dev/install/local_setup.sh;
# Set colcon meta
export COLCON_META=$(pwd)/colcon.meta
# If $MICRO_ROS_BUILD_DIR/microros/install exists, skip this
if [ ! -d "$MICRO_ROS_BUILD_DIR/microros/install" ]; then
# Install micro-ROS firmware environment
pushd $MICRO_ROS_BUILD_DIR/microros/ > /dev/null
# Build
colcon build \
--merge-install \
--packages-ignore-regex=.*_cpp \
--metas $COLCON_META \
$COLCON_EVENT_HANDLERS \
--cmake-args \
"--no-warn-unused-cli" \
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=OFF \
-DTHIRDPARTY=ON \
-DBUILD_SHARED_LIBS=OFF \
-DBUILD_TESTING=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN \
-DCMAKE_VERBOSE_MAKEFILE=ON;
# Fix include paths
echo "Fixing include paths for micro-ROS packages"
INCLUDE_ROS2_PACKAGES=$(colcon list | awk '{print $1}' | awk -v d=" " '{s=(NR==1?s:s d)$0}END{print s}')
for var in ${INCLUDE_ROS2_PACKAGES}; do
rsync -r ./install/include/${var}/${var}/* ./install/include/${var}/ > /dev/null 2>&1
rm -rf ./install/include/${var}/${var}/ > /dev/null 2>&1
done
# # Delete all empty folder in install/include
find ./install/include -type d -empty -delete
popd > /dev/null
fi
# Generate the output folder
if [ "${MICROROS_TARGET}" = "VITIS_MICROBLAZE" ]; then
export OUTPUT_FOLDER=microros_microblaze_lib
elif [ "${MICROROS_TARGET}" = "VITIS_CORTEX_R5" ]; then
export OUTPUT_FOLDER=microros_cortex_r5_lib
elif [ "${MICROROS_TARGET}" = "GENERIC_ARM" ]; then
export OUTPUT_FOLDER=microros_generic_arm_lib
fi
rm -rf ${OUTPUT_FOLDER}
mkdir -p ${OUTPUT_FOLDER}
# Copy includes
mkdir -p ${OUTPUT_FOLDER}/include
cp -r $MICRO_ROS_BUILD_DIR/microros/install/include/* ${OUTPUT_FOLDER}/include
# Generate combined libraries
echo "Creating libmicroros.a"
pushd $MICRO_ROS_BUILD_DIR/microros > /dev/null
echo "CREATE libmicroros.a" > ar_script
find install/lib -name "*.a" -exec echo "ADDLIB $(pwd)/{}" >> ar_script \;
echo "SAVE" >> ar_script
popd > /dev/null
pushd ${OUTPUT_FOLDER} > /dev/null
ar -M < ../$MICRO_ROS_BUILD_DIR/microros/ar_script
popd > /dev/null