-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-libs.sh
executable file
·110 lines (92 loc) · 2.57 KB
/
build-libs.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
#!/usr/bin/env bash
#
# Builds Xenomai on the Raspberry Pi.
readonly WHITE='\033[37;1m'
readonly REDBOLD='\033[31;1m'
readonly NOCOLOR='\033[0m'
readonly NUM_CORES="$(grep -c ^processor /proc/cpuinfo)"
readonly ARCH="$(dpkg --print-architecture)"
readonly BASEDIR="/tmp/rpi"
readonly XENODIR="${BASEDIR}/xenomai"
readonly XENOBUILDDIR="${XENODIR}/build"
error_exit()
{
echo -e "${REDBOLD}$(basename $0)${NOCOLOR}:${WHITE} $1${NOCOLOR}" >&2
popd
exit 1
}
# Checks that this is being run on the correct system.
check_system()
{
if [ "${ARCH}" != "armhf" ]; then
error_exit "The current architecture (${ARCH}) is not supported"
fi
}
# Increases the size of swap memory for building ROS in parallel.
configure_swap()
{
if ! sudo -H sed -i 's/\(CONF_SWAPSIZE=\)[0-9]\+/\12048/g' /etc/dphys-swapfile; then
error_exit "Failed to modify swap file configuration"
fi
if ! sudo dphys-swapfile setup; then
sudo dphys-swapfile swapon
error_exit "Failed to reconfigure swap file"
fi
if ! sudo dphys-swapfile swapon; then
error_exit "Failed to enable swap. Try sudo dphys-swapfile swapon."
fi
}
# Install necessary dependencies.
install_deps()
{
echo "Installing build dependencies."
sudo apt-get install -y \
autoconf \
checkinstall \
libtool
if [ $? -ne 0 ]; then
error_exit "Failed to install build dependencies"
fi
}
# Compiles the xenomai libraries.
build_libs()
{
if ! cd "${XENODIR}"; then
error_exit "Failed to cd to xenomai source tree at ${XENODIR}, did you copy the repo from your desktop?"
fi
if ! ./scripts/bootstrap; then
error_exit "Failed to bootstrap libxenomai build at source tree ${XENODIR}"
fi
if ! sudo rm -rf "${XENOBUILDDIR}"; then
error_exit "Failed to rmdir ${XENOBUILDDIR}"
fi
if ! mkdir -v "${XENOBUILDDIR}"; then
error_exit "Failed to mkdir ${XENOBUILDDIR}"
fi
if ! cd "${XENOBUILDDIR}"; then
error_exit "Failed to cd to xenomai build root at ${XENOBUILDDIR}"
fi
${XENODIR}/configure CFLAGS="-march=armv7-a" LDFLAGS="-march=armv7-a" \
--with-core=cobalt \
--enable-debug=symbols \
--enable-smp
if [ $? -ne 0 ]; then
error_exit "Failed to configure libxenomai from source tree ${XENODIR}"
fi
if ! make -j${NUM_CORES}; then
error_exit "Failed to build libxenomai in build dir ${XENOBUILDDIR}"
fi
if ! sudo -H make install; then
error_exit "Failed to make install libxenomai in build dir ${XENOBUILDDIR}}"
fi
}
main()
{
pushd .
check_system
configure_swap
install_deps
build_libs
popd
}
main