-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathlibrary_generation.sh
executable file
·271 lines (201 loc) · 10.5 KB
/
library_generation.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
#!/bin/bash
PLATFORMS=()
while getopts "p:" o; do
case "$o" in
p)
PLATFORMS+=(${OPTARG})
;;
esac
done
if [ $OPTIND -eq 1 ]; then
PLATFORMS+=("opencr1")
PLATFORMS+=("teensy4")
PLATFORMS+=("teensy32")
PLATFORMS+=("teensy35")
PLATFORMS+=("teensy36")
PLATFORMS+=("cortex_m0")
PLATFORMS+=("cortex_m3")
PLATFORMS+=("cortex_m4")
# PLATFORMS+=("portenta-m4")
PLATFORMS+=("portenta-m7")
PLATFORMS+=("kakutef7-m7")
PLATFORMS+=("esp32")
fi
shift $((OPTIND-1))
######## Init ########
apt update
cd /uros_ws
source /opt/ros/$ROS_DISTRO/setup.bash
source install/local_setup.bash
ros2 run micro_ros_setup create_firmware_ws.sh generate_lib
######## Adding extra packages ########
pushd firmware/mcu_ws > /dev/null
# Workaround: Copy just tf2_msgs
git clone -b rolling https://github.com/ros2/geometry2
cp -R geometry2/tf2_msgs ros2/tf2_msgs
rm -rf geometry2
# Import user defined packages
mkdir extra_packages
pushd extra_packages > /dev/null
cp -R /project/extras/library_generation/extra_packages/* .
vcs import --input extra_packages.repos
popd > /dev/null
popd > /dev/null
######## Clean and source ########
find /project/src/ ! -name micro_ros_arduino.h ! -name *.c ! -name *.cpp ! -name *.c.in -delete
######## Build for OpenCR ########
if [[ " ${PLATFORMS[@]} " =~ " opencr1 " ]]; then
rm -rf firmware/build
export TOOLCHAIN_PREFIX=/uros_ws/gcc-arm-none-eabi-5_4-2016q2/bin/arm-none-eabi-
ros2 run micro_ros_setup build_firmware.sh /project/extras/library_generation/opencr_toolchain.cmake /project/extras/library_generation/colcon.meta
find firmware/build/include/ -name "*.c" -delete
cp -R firmware/build/include/* /project/src/
mkdir -p /project/src/cortex-m7/fpv5-sp-d16-softfp
cp -R firmware/build/libmicroros.a /project/src/cortex-m7/fpv5-sp-d16-softfp/libmicroros.a
fi
######## Build for SAMD (e.g. Arduino Zero) ########
if [[ " ${PLATFORMS[@]} " =~ " cortex_m0 " ]]; then
rm -rf firmware/build
export TOOLCHAIN_PREFIX=/uros_ws/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-
ros2 run micro_ros_setup build_firmware.sh /project/extras/library_generation/cortex_m0_toolchain.cmake /project/extras/library_generation/colcon_verylowmem.meta
find firmware/build/include/ -name "*.c" -delete
cp -R firmware/build/include/* /project/src/
mkdir -p /project/src/cortex-m0plus
cp -R firmware/build/libmicroros.a /project/src/cortex-m0plus/libmicroros.a
fi
######## Build for SAM (e.g. Arduino Due) ########
if [[ " ${PLATFORMS[@]} " =~ " cortex_m3 " ]]; then
rm -rf firmware/build
export TOOLCHAIN_PREFIX=/uros_ws/gcc-arm-none-eabi-4_8-2014q1/bin/arm-none-eabi-
ros2 run micro_ros_setup build_firmware.sh /project/extras/library_generation/cortex_m3_toolchain.cmake /project/extras/library_generation/colcon_lowmem.meta
find firmware/build/include/ -name "*.c" -delete
cp -R firmware/build/include/* /project/src/
mkdir -p /project/src/cortex-m3
cp -R firmware/build/libmicroros.a /project/src/cortex-m3/libmicroros.a
fi
######## Build for STM32F4 ########
if [[ " ${PLATFORMS[@]} " =~ " cortex_m4 " ]]; then
rm -rf firmware/build
export TOOLCHAIN_PREFIX=/uros_ws/gcc-arm-none-eabi-9-2020-q2-update/bin/arm-none-eabi-
ros2 run micro_ros_setup build_firmware.sh /project/extras/library_generation/cortex_m4_toolchain.cmake /project/extras/library_generation/colcon_lowmem.meta
find firmware/build/include/ -name "*.c" -delete
cp -R firmware/build/include/* /project/src/
mkdir -p /project/src/cortex-m4
cp -R firmware/build/libmicroros.a /project/src/cortex-m4/libmicroros.a
fi
######## Build for Teensy 3.2 ########
if [[ " ${PLATFORMS[@]} " =~ " teensy32 " ]]; then
rm -rf firmware/build
export TOOLCHAIN_PREFIX=/uros_ws/teensy-compile/tools/arm/bin/arm-none-eabi-
ros2 run micro_ros_setup build_firmware.sh /project/extras/library_generation/teensy32_toolchain.cmake /project/extras/library_generation/colcon_lowmem.meta
find firmware/build/include/ -name "*.c" -delete
cp -R firmware/build/include/* /project/src/
mkdir -p /project/src/mk20dx256
cp -R firmware/build/libmicroros.a /project/src/mk20dx256/libmicroros.a
fi
######## Build for Teensy 3.5 ########
if [[ " ${PLATFORMS[@]} " =~ " teensy35 " ]]; then
rm -rf firmware/build
export TOOLCHAIN_PREFIX=/uros_ws/teensy-compile/tools/arm/bin/arm-none-eabi-
ros2 run micro_ros_setup build_firmware.sh /project/extras/library_generation/teensy35_toolchain.cmake /project/extras/library_generation/colcon_lowmem.meta
find firmware/build/include/ -name "*.c" -delete
cp -R firmware/build/include/* /project/src/
mkdir -p /project/src/mk64fx512/fpv4-sp-d16-hard
cp -R firmware/build/libmicroros.a /project/src/mk64fx512/fpv4-sp-d16-hard/libmicroros.a
fi
######## Build for Teensy 3.6 ########
if [[ " ${PLATFORMS[@]} " =~ " teensy36 " ]]; then
rm -rf firmware/build
mkdir -p /project/src/mk66fx1m0/fpv4-sp-d16-hard
# Reuse Teensy 3.5 build if possible
if [[ " ${PLATFORMS[@]} " =~ " teensy35 " ]]; then
ln /project/src/mk64fx512/fpv4-sp-d16-hard/libmicroros.a /project/src/mk66fx1m0/fpv4-sp-d16-hard/libmicroros.a
else
export TOOLCHAIN_PREFIX=/uros_ws/teensy-compile/tools/arm/bin/arm-none-eabi-
ros2 run micro_ros_setup build_firmware.sh /project/extras/library_generation/teensy35_toolchain.cmake /project/extras/library_generation/colcon_lowmem.meta
find firmware/build/include/ -name "*.c" -delete
cp -R firmware/build/include/* /project/src/
cp -R firmware/build/libmicroros.a /project/src/mk66fx1m0/fpv4-sp-d16-hard/libmicroros.a
fi
fi
######## Build for Teensy 4 ########
if [[ " ${PLATFORMS[@]} " =~ " teensy4 " ]]; then
rm -rf firmware/build
export TOOLCHAIN_PREFIX=/uros_ws/teensy-compile/tools/arm/bin/arm-none-eabi-
ros2 run micro_ros_setup build_firmware.sh /project/extras/library_generation/teensy4_toolchain.cmake /project/extras/library_generation/colcon.meta
find firmware/build/include/ -name "*.c" -delete
cp -R firmware/build/include/* /project/src/
mkdir -p /project/src/imxrt1062/fpv5-d16-hard
cp -R firmware/build/libmicroros.a /project/src/imxrt1062/fpv5-d16-hard/libmicroros.a
fi
######## Build for Arduino Portenta M4 core ########
# if [[ " ${PLATFORMS[@]} " =~ " portenta-m4 " ]]; then
# rm -rf firmware/build
# export TOOLCHAIN_PREFIX=/uros_ws/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-
# ros2 run micro_ros_setup build_firmware.sh /project/extras/library_generation/portenta-m4_toolchain.cmake /project/extras/library_generation/colcon.meta
# find firmware/build/include/ -name "*.c" -delete
# cp -R firmware/build/include/* /project/src/
# mkdir -p /project/src/cortex-m4/fpv4-sp-d16-softfp
# cp -R firmware/build/libmicroros.a /project/src/cortex-m4/fpv4-sp-d16-softfp/libmicroros.a
# fi
######## Build for Arduino Portenta M7 core ########
if [[ " ${PLATFORMS[@]} " =~ " portenta-m7 " ]]; then
rm -rf firmware/build
export TOOLCHAIN_PREFIX=/uros_ws/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-
ros2 run micro_ros_setup build_firmware.sh /project/extras/library_generation/portenta-m7_toolchain.cmake /project/extras/library_generation/colcon.meta
find firmware/build/include/ -name "*.c" -delete
cp -R firmware/build/include/* /project/src/
mkdir -p /project/src/cortex-m7/fpv5-d16-softfp
cp -R firmware/build/libmicroros.a /project/src/cortex-m7/fpv5-d16-softfp/libmicroros.a
fi
######## Build for Kakute F7 M7 core ########
if [[ " ${PLATFORMS[@]} " =~ " kakutef7-m7 " ]]; then
rm -rf firmware/build
export TOOLCHAIN_PREFIX=/uros_ws/gcc-arm-none-eabi-9-2020-q2-update/bin/arm-none-eabi-
ros2 run micro_ros_setup build_firmware.sh /project/extras/library_generation/kakutef7-m7_toolchain.cmake /project/extras/library_generation/colcon.meta
find firmware/build/include/ -name "*.c" -delete
cp -R firmware/build/include/* /project/src/
mkdir -p /project/src/cortex-m7/fpv5-sp-d16-hardfp
cp -R firmware/build/libmicroros.a /project/src/cortex-m7/fpv5-sp-d16-hardfp/libmicroros.a
fi
######## Build for ESP32 ########
if [[ " ${PLATFORMS[@]} " =~ " esp32 " ]]; then
rm -rf firmware/build
export TOOLCHAIN_PREFIX=/uros_ws/xtensa-esp32-elf/bin/xtensa-esp32-elf-
ros2 run micro_ros_setup build_firmware.sh /project/extras/library_generation/esp32_toolchain.cmake /project/extras/library_generation/colcon.meta
find firmware/build/include/ -name "*.c" -delete
cp -R firmware/build/include/* /project/src/
mkdir -p /project/src/esp32
cp -R firmware/build/libmicroros.a /project/src/esp32/libmicroros.a
fi
######## Build for ESP32S3 ######
if [[ " ${PLATFORMS[@]} " =~ " esp32s3 " ]]; then
rm -rf firmware/build
export TOOLCHAIN_PREFIX=/uros_ws/xtensa-esp32-elf/bin/xtensa-esp32-elf-
ros2 run micro_ros_setup build_firmware.sh /project/extras/library_generation/esp32_toolchain.cmake /project/extras/library_generation/colcon.meta
find firmware/build/include/ -name "*.c" -delete
cp -R firmware/build/include/* /project/src/
mkdir -p /project/src/esp32s3
cp -R firmware/build/libmicroros.a /project/src/esp32s3/libmicroros.a
fi
######## Fix include paths ########
pushd firmware/mcu_ws > /dev/null
INCLUDE_ROS2_PACKAGES=$(colcon list | awk '{print $1}' | awk -v d=" " '{s=(NR==1?s:s d)$0}END{print s}')
popd > /dev/null
apt -y install rsync
for var in ${INCLUDE_ROS2_PACKAGES}; do
rsync -r /project/src/${var}/${var}/* /project/src/${var}/ > /dev/null 2>&1
rm -rf /project/src/${var}/${var}/ > /dev/null 2>&1
done
######## Generate extra files ########
find firmware/mcu_ws/ros2 \( -name "*.srv" -o -name "*.msg" -o -name "*.action" \) | awk -F"/" '{print $(NF-2)"/"$NF}' > /project/available_ros2_types
find firmware/mcu_ws/extra_packages \( -name "*.srv" -o -name "*.msg" -o -name "*.action" \) | awk -F"/" '{print $(NF-2)"/"$NF}' >> /project/available_ros2_types
# sort it so that the result order is reproducible
sort -o /project/available_ros2_types /project/available_ros2_types
cd firmware
echo "" > /project/built_packages
for f in $(find $(pwd) -name .git -type d); do pushd $f > /dev/null; echo $(git config --get remote.origin.url) $(git rev-parse HEAD) >> /project/built_packages; popd > /dev/null; done;
# sort it so that the result order is reproducible
sort -o /project/built_packages /project/built_packages
######## Fix permissions ########
sudo chmod -R 777 .