-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathcompile_mqttmanager.sh
More file actions
executable file
·166 lines (147 loc) · 5.97 KB
/
compile_mqttmanager.sh
File metadata and controls
executable file
·166 lines (147 loc) · 5.97 KB
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
#!/bin/bash
echo "Starting to compile MQTTManager."
TARGETPLATFORM=""
STRIP=""
TEST_MODE=0
while true; do
case "$1" in
--target-platform)
export TARGETPLATFORM="$2"
echo "Will compile for platform $TARGETPLATFORM"
shift # Remove --target-platform
shift # Remove value for target platform
;;
--strip)
echo "Will strip compiled binaries and .so's"
export STRIP="1"
shift
;;
--test)
echo "Will compile for testing. Removing old test DB (if any)."
rm -f /tmp/nspanelmanager_db_test.sqlite3
TEST_MODE=1
shift
;;
*) break ;;
esac
done
if [ "$TEST_MODE" -eq 1 ]; then
sed -i 's/set(TEST_MODE.*/set(TEST_MODE 1)/g' /MQTTManager/CMakeLists.txt
sed -i 's/add_compile_definitions(TEST_MODE.*/add_compile_definitions(TEST_MODE=1)/g' /MQTTManager/CMakeLists.txt
else
sed -i 's/set(TEST_MODE.*/set(TEST_MODE 0)/g' /MQTTManager/CMakeLists.txt
sed -i 's/add_compile_definitions(TEST_MODE.*/add_compile_definitions(TEST_MODE=0)/g' /MQTTManager/CMakeLists.txt
fi
if [ -z "$TARGETPLATFORM" ]; then
TARGETPLATFORM="linux/$(dpkg-architecture -q DEB_BUILD_ARCH_CPU)"
echo "No platform given as argument, will assume $TARGETPLATFORM"
fi
echo "Compiling for target '$TARGETPLATFORM'"
set -e
set -x
deb_add_arch=""
strip_bin=""
cp /root/.conan2/profiles/default /root/.conan2/profiles/host
if [ "$TARGETPLATFORM" == "linux/386" ]; then
deb_add_arch="i386"
conan_target_arch="x86"
strip_bin="/usr/bin/strip"
apt -y install gcc-multilib g++-multilib
elif [ "$TARGETPLATFORM" == "linux/amd64" ]; then
deb_add_arch="amd64"
conan_target_arch="x86_64"
strip_bin="/usr/bin/strip"
elif [ "$TARGETPLATFORM" == "linux/arm/v6" ]; then
deb_add_arch="armhf"
conan_target_arch="armv6"
strip_bin="/usr/bin/arm-linux-gnueabihf-strip"
apt -y install binutils-arm-linux-gnueabihf gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
echo "" >>/root/.conan2/profiles/host
echo "[buildenv]" >>/root/.conan2/profiles/host
echo "CC=arm-linux-gnueabihf-gcc-12" >>/root/.conan2/profiles/host
echo "CXX=arm-linux-gnueabihf-g++-12" >>/root/.conan2/profiles/host
echo "LD=arm-linux-gnueabihf-ld" >>/root/.conan2/profiles/host
elif [ "$TARGETPLATFORM" == "linux/arm/v7" ]; then
deb_add_arch="armhf"
conan_target_arch="armv7"
strip_bin="/usr/bin/arm-linux-gnueabihf-strip"
apt -y install binutils-arm-linux-gnueabihf gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
echo "" >>/root/.conan2/profiles/host
echo "[buildenv]" >>/root/.conan2/profiles/host
echo "CC=arm-linux-gnueabihf-gcc-12" >>/root/.conan2/profiles/host
echo "CXX=arm-linux-gnueabihf-g++-12" >>/root/.conan2/profiles/host
echo "LD=arm-linux-gnueabihf-ld" >>/root/.conan2/profiles/host
elif [ "$TARGETPLATFORM" == "linux/arm64" ]; then
deb_add_arch="arm64"
conan_target_arch="armv8"
strip_bin="/usr/bin/aarch64-linux-gnu-strip"
apt -y install binutils-aarch64-linux-gnu gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
echo "" >>/root/.conan2/profiles/host
echo "[buildenv]" >>/root/.conan2/profiles/host
echo "CC=aarch64-linux-gnu-gcc-12" >>/root/.conan2/profiles/host
echo "CXX=aarch64-linux-gnu-g++-12" >>/root/.conan2/profiles/host
echo "LD=aarch64-linux-gnu-ld" >>/root/.conan2/profiles/host
#echo "CFLAGS=-march=armv8-a" >>/root/.conan2/profiles/host
#echo "CXXFLAGS=-march=armv8-a" >>/root/.conan2/profiles/host
else
echo "ERROR! Unknown target platform. Will exit."
exit 1
fi
eval $(dpkg-architecture) # Load in what the builder machine is
# Setup apt source file to be able to access both architectures
if [ "$deb_add_arch" != "$DEB_HOST_ARCH" ]; then
if [ ! -f "/etc/apt/sources.list.d/debian.sources.bak" ]; then
cp /etc/apt/sources.list.d/debian.sources /etc/apt/sources.list.d/debian.sources.bak
fi
cp /etc/apt/sources.list.d/debian.sources.bak /etc/apt/sources.list.d/debian.sources
dpkg --add-architecture $deb_add_arch
sed -i "/Components.*/a arch=$DEB_HOST_ARCH,$deb_add_arch" /etc/apt/sources.list.d/debian.sources
apt-get update
fi
apt -y install libssl-dev:$deb_add_arch openssl:$deb_add_arch libcurl4-openssl-dev:$deb_add_arch
BASEDIR=$(dirname "$0")
pushd "$BASEDIR"
cd /MQTTManager/
# rm -rf build
#if [ -e CMakeCache.txt ]; then
# rm CMakeCache.txt
#fi
#sed -i "s/^arch.*/arch=$build_arch/g" /root/.conan2/profiles/host
# Get build type from conan profile
BUILD_TYPE=$(grep -E "^build_type=" /root/.conan2/profiles/default | cut -d'=' -f 2)
sed -i "s/arch=.*/arch=${conan_target_arch}/g" /root/.conan2/profiles/host
# Determine wether to link libraries statically or dynamically.
if [ "$BUILD_TYPE" == "Debug" ]; then
BUILD_SHARED_LIBS=ON
else
BUILD_SHARED_LIBS=OFF
fi
# Workaround: Patch m4's configure script to skip getcwd test
echo 'ac_cv_func_getcwd_path_max=yes' > /etc/config.site
export CONFIG_SITE=/etc/config.site
if [[ "$(uname)" == "Darwin" ]]; then
echo "🔧 Patching m4's configure script to skip getcwd test (avoiding hang on macOS)..."
find /MQTTManager/conan_cache -type f -path "*/src/configure" -exec grep -q "checking whether getcwd handles long file names properly" {} \; -exec sed -i '' '/checking whether getcwd handles long file names properly/ a\
gl_cv_func_getcwd_path_max=yes\
' {} \;
else
echo "✅ Skipping m4 patch (not macOS)"
fi
echo "Conan profile: "
cat /root/.conan2/profiles/default
echo "Will build MQTTManager in ${BUILD_TYPE} mode."
conan install . --build=missing -pr:b default -pr:h host
echo "--> Conan install complete."
cd build
source $BUILD_TYPE/generators/conanbuild.sh
cmake .. -DCMAKE_TOOLCHAIN_FILE=$BUILD_TYPE/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
cmake --build . --config $BUILD_TYPE -j $(nproc)
sed -i "s|/MQTTManager/|/home/tim/NSPanelManager/docker/MQTTManager/|g" compile_commands.json
cp compile_commands.json ../
if [ "$STRIP" == "1" ]; then
echo "Stripping binaries and .so files using '$strip_bin'..."
if compgen -G '/MQTTManager/build/*.so' > /dev/null; then
"$strip_bin" /MQTTManager/build/*.so
fi
"$strip_bin" /MQTTManager/build/nspm_mqttmanager
fi