forked from Screenly/Anthias
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_qt5.sh
executable file
·343 lines (298 loc) · 11.4 KB
/
build_qt5.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#!/bin/bash
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# -*- sh-basic-offset: 4 -*-
set -exuo pipefail
BUILD_TARGET=/build
SRC=/src
QT_BRANCH="5.15.5"
QT_URL='https://download.qt.io/archive/qt/5.15/5.15.5/single/qt-everywhere-opensource-src-5.15.5.tar.xz'
QT_HASH='https://download.qt.io/archive/qt/5.15/5.15.5/single/md5sums.txt'
DEBIAN_VERSION=$(lsb_release -cs)
MAKE_CORES="$(expr $(nproc) + 2)"
mkdir -p "$BUILD_TARGET"
mkdir -p "$SRC"
/usr/games/cowsay -f tux "Building QT version $QT_BRANCH."
function fetch_rpi_firmware () {
if [ ! -d "/src/opt" ]; then
pushd /src
# We do an `svn checkout` here as the entire git repo here is *huge*
# and `git` doesn't support partial checkouts well (yet)
svn checkout -q https://github.com/raspberrypi/firmware/trunk/opt
popd
fi
# We need to exclude all of these .h and android files to make QT build.
# In the blog post referenced, this is done using `dpkg --purge libraspberrypi-dev`,
# but since we're copying in the source, we're just going to exclude these from the rsync.
# https://www.enricozini.org/blog/2020/qt5/build-qt5-cross-builder-with-raspbian-sysroot-compiling-with-the-sysroot-continued/
rsync \
-aP \
--exclude '*android*' \
--exclude 'hello_pi' \
--exclude '.svn' \
/src/opt/ /sysroot/opt/
}
function patch_qt () {
local QMAKE_CONF="/src/qt5/qtbase/mkspecs/devices/$1/qmake.conf"
if [ "$1" != "linux-arm-generic-g++" ]; then
# Yes, yes, this all should be converted to proper patches
# but I really just wanted to get it to work.
# QT is linking against the old libraries for Pi 1 - Pi 3
# https://bugreports.qt.io/browse/QTBUG-62216
sed -i 's/lEGL/lbrcmEGL/' "$QMAKE_CONF"
sed -i 's/lGLESv2/lbrcmGLESv2/' "$QMAKE_CONF"
# Qmake won't account for sysroot
# https://wiki.qt.io/RaspberryPi2EGLFS
sed -i 's#^VC_LIBRARY_PATH.*#VC_LIBRARY_PATH = $$[QT_SYSROOT]/opt/vc/lib#' "$QMAKE_CONF"
sed -i 's#^VC_INCLUDE_PATH.*#VC_INCLUDE_PATH = $$[QT_SYSROOT]/opt/vc/include#' "$QMAKE_CONF"
sed -i 's#^VC_LINK_LINE.*#VC_LINK_LINE = -L$${VC_LIBRARY_PATH}#' "$QMAKE_CONF"
sed -i 's#^QMAKE_LIBDIR_OPENGL_ES2.*#QMAKE_LIBDIR_OPENGL_ES2 = $${VC_LIBRARY_PATH}#' "$QMAKE_CONF"
else
patch -d "/src/qt5/qtbase/" -p0 <<'EOF'
--- mkspecs/devices/linux-arm-generic-g++/qmake.conf 2022-08-03 13:48:47.074865145 +0300
+++ mkspecs/devices/linux-arm-generic-g++/qmake.conf 2022-08-03 13:49:12.234373968 +0300
@@ -5,5 +5,8 @@
# ./configure -device arm-generic-g++ -device-option CROSS_COMPILE=arm-linux-gnueabi-
include(../common/linux_device_pre.conf)
+DISTRO_OPTS += hard-float
+DISTRO_OPTS += deb-multi-arch
+QMAKE_CFLAGS = -march=armv8-a -mtune=cortex-a53 -mfpu=crypto-neon-fp-armv8
include(../common/linux_arm_device_post.conf)
load(qt_config)
EOF
fi
}
function patch_qtwebengine () {
# Patch up WebEngine due to GCC bug
# https://www.enricozini.org/blog/2020/qt5/build-qt5-cross-builder-with-raspbian-sysroot-compiling-with-the-sysroot/
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96206
pushd "/src/qt5/qtwebengine"
sed -i '1s/^/#pragma GCC push_options\n#pragma GCC optimize ("O0")\n/' src/3rdparty/chromium/third_party/skia/third_party/skcms/skcms.cc
echo "#pragma GCC pop_options" >> src/3rdparty/chromium/third_party/skia/third_party/skcms/skcms.cc
popd
}
function fetch_qt5 () {
local SRC_DIR="/src/qt5"
pushd /src
if [ ! -d "$SRC_DIR" ]; then
if [ ! -f "qt-everywhere-opensource-src-$QT_BRANCH.tar.xz" ]; then
wget "$QT_URL"
fi
if [ ! -f "md5sums.txt" ]; then
wget "$QT_HASH"
fi
md5sum --ignore-missing -c md5sums.txt
# Extract and make a clone
tar xf "qt-everywhere-opensource-src-$QT_BRANCH.tar.xz"
rsync -aqP "qt-everywhere-src-$QT_BRANCH/" qt5
else
rsync -aqP --delete "qt-everywhere-src-$QT_BRANCH/" qt5
fi
popd
}
function build_qt () {
# This build process is inspired by
# https://www.tal.org/tutorials/building-qt-512-raspberry-pi
local SRC_DIR="/src/$1"
if [ ! -f "$BUILD_TARGET/qt5-$QT_BRANCH-$DEBIAN_VERSION-$1.tar.gz" ]; then
/usr/games/cowsay -f tux "Building QT for $1"
# Make sure we have a clean QT 5 tree
fetch_qt5
if [ "${CLEAN_BUILD-x}" == "1" ]; then
rm -rf "$SRC_DIR"
fi
mkdir -p "$SRC_DIR"
pushd "$SRC_DIR"
if [ "$1" = "pi1" ]; then
local BUILD_ARGS=(
"-device" "linux-rasp-pi-g++"
)
patch_qt "linux-rasp-pi-g++"
patch_qtwebengine
elif [ "$1" = "pi2" ]; then
local BUILD_ARGS=(
"-device" "linux-rasp-pi2-g++"
)
patch_qt "linux-rasp-pi2-g++"
elif [ "$1" = "pi3" ]; then
local BUILD_ARGS=(
"-device" "linux-rasp-pi3-g++"
)
patch_qt "linux-rasp-pi3-g++"
# The opengl flag only works on Pi 4. It breaks the QTWebEngine build
# process on any other model.
elif [ "$1" = "pi4" ]; then
local BUILD_ARGS=(
"-device" "linux-rasp-pi4-v3d-g++"
"-opengl" "es2"
)
elif [ "$1" = "generic" ]; then
local BUILD_ARGS=(
"-device" "linux-arm-generic-g++"
)
patch_qt "linux-arm-generic-g++"
else
echo "Unknown device. Exiting."
exit 1
fi
# @TODO: Add in the `-opengl es2` flag for Pi 1 - Pi 3.
# Currently this breaks the QTWebEngine process.
/src/qt5/configure \
"${BUILD_ARGS[@]}" \
-ccache \
-confirm-license \
-dbus-linked \
-device-option CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- \
-no-eglfs \
-no-linuxfb \
-evdev \
-extprefix "$SRC_DIR/qt5pi" \
-force-pkg-config \
-glib \
-make libs \
-no-compile-examples \
-no-cups \
-no-gbm \
-no-gtk \
-no-pch \
-no-use-gold-linker \
-nomake examples \
-nomake tests \
-opensource \
-prefix /usr/local/qt5pi \
-qpa xcb \
-xcb \
-qt-pcre \
-reduce-exports \
-release \
-skip qt3d \
-skip qtactiveqt \
-skip qtandroidextras \
-skip qtcanvas3d \
-skip qtdatavis3d \
-skip qtgamepad \
-skip qtlocation \
-skip qtlottie \
-skip qtmacextras \
-skip qtpurchasing \
-skip qtsensors \
-skip qtspeech \
-skip qtwayland \
-skip qtwebview \
-skip qtwinextras \
-skip qtx11extras \
-skip wayland \
-skip webengine \
-ssl \
-system-freetype \
-system-libjpeg \
-system-libpng \
-system-zlib \
-feature-dialog \
-sysroot /sysroot
# The RAM consumption is proportional to the amount of cores.
# On an 8 core box, the build process will require ~16GB of RAM.
make -j"$MAKE_CORES"
make install
# I'm not sure we actually need this anymore. It's from an
# old build process for QT 4.9 that we used.
cp -r /usr/share/fonts/truetype/dejavu/ "$SRC_DIR/qt5pi/lib/fonts"
pushd "$SRC_DIR"
tar cfz "$BUILD_TARGET/qt5-$QT_BRANCH-$DEBIAN_VERSION-$1.tar.gz" qt5pi
popd
pushd "$BUILD_TARGET"
sha256sum "qt5-$QT_BRANCH-$DEBIAN_VERSION-$1.tar.gz" > "qt5-$QT_BRANCH-$DEBIAN_VERSION-$1.tar.gz.sha256"
popd
else
echo "QT Build already exist."
fi
}
function build_module () {
local SRC_DIR="/src/$1"
local MODULE="$2"
if [ ! -f "$BUILD_TARGET/$MODULE-$QT_BRANCH-$DEBIAN_VERSION-$1-$GIT_HASH.tar.gz" ]; then
pushd "$SRC_DIR"
if [ ! -d "$MODULE-everywhere-opensource-src-$QT_BRANCH" ]; then
if [ ! -f "../$MODULE-everywhere-opensource-src-$QT_BRANCH.tar.xz" ]; then
wget "https://download.qt.io/archive/qt/5.15/$QT_BRANCH/submodules/$MODULE-everywhere-opensource-src-$QT_BRANCH.tar.xz" -P ".."
fi
tar xf "../$MODULE-everywhere-opensource-src-$QT_BRANCH.tar.xz"
fi
rsync -aqP --delete "$MODULE-everywhere-src-$QT_BRANCH/" "$MODULE"
popd
pushd "$SRC_DIR/$MODULE"
mkdir -p fakeroot
"$SRC_DIR/qt5pi/bin/qmake"
make -j"$MAKE_CORES"
INSTALL_ROOT="$SRC_DIR/$MODULE/fakeroot/" make install
pushd fakeroot
tar cfz "$BUILD_TARGET/$MODULE-$QT_BRANCH-$DEBIAN_VERSION-$1-$GIT_HASH.tar.gz" .
popd
pushd "$BUILD_TARGET"
sha256sum "$MODULE-$QT_BRANCH-$DEBIAN_VERSION-$1-$GIT_HASH.tar.gz" > "$MODULE-$QT_BRANCH-$DEBIAN_VERSION-$1-$GIT_HASH.tar.gz.sha256"
popd
else
echo "$MODULE Build already exist."
fi
}
function build_qtjsonserializer () {
local SRC_DIR="/src/$1"
if [ ! -f "$BUILD_TARGET/qtjsonserializer-$QT_BRANCH-$DEBIAN_VERSION-$1-$GIT_HASH.tar.gz" ]; then
if [ "${BUILD_QTJSONSERLIALIZER-x}" == "1" ]; then
if [ ! -d "$SRC_DIR/qtjsonserializer" ] ; then
git clone --depth=1 https://github.com/Skycoder42/QtJsonSerializer.git -b 3.2.0-2 "$SRC_DIR/qtjsonserializer"
else
pushd "$SRC_DIR/qtjsonserializer"
git reset --hard "3.2.0-2"
popd
fi
pushd "$SRC_DIR/qtjsonserializer"
mkdir -p fakeroot
sed -i '/doxygen/d' qtjsonserializer.pro
sed -i '/runtests/d' qtjsonserializer.pro
sed -i '/doc/d' qtjsonserializer.pro
"$SRC_DIR/qt5pi/bin/qmake"
make qmake_all -j"$MAKE_CORES"
make -j"$MAKE_CORES"
make
INSTALL_ROOT="$SRC_DIR/qtjsonserializer/fakeroot/" make install
pushd fakeroot
tar cfz "$BUILD_TARGET/qtjsonserializer-$QT_BRANCH-$DEBIAN_VERSION-$1-$GIT_HASH.tar.gz" .
popd
pushd "$BUILD_TARGET"
sha256sum "qtjsonserializer-$QT_BRANCH-$DEBIAN_VERSION-$1-$GIT_HASH.tar.gz" > "qtjsonserializer-$QT_BRANCH-$DEBIAN_VERSION-$1-$GIT_HASH.tar.gz.sha256"
popd
fi
else
echo "qtjsonserializer Build already exist."
fi
}
function export_sysroot () {
if [ ! -f "$BUILD_TARGET/sysroot-$DEBIAN_VERSION.tar.gz" ]; then
echo "exporting sysroot"
pushd /sysroot
tar cfz "$BUILD_TARGET/sysroot-$DEBIAN_VERSION.tar.gz" .
popd
else
echo "sysroot is already exported."
fi
}
# Modify paths for build process
/usr/local/bin/sysroot-relativelinks.py /sysroot
fetch_rpi_firmware
if [ ! "${TARGET-}" ]; then
# Let's work our way through all Pis in order of relevance
for device in pi4 pi3 pi2 pi1; do
build_qt "$device"
if [ "${BUILD_MQTT-x}" == "1" ]; then
build_module "$device" "qtmqtt"
fi
build_qtjsonserializer "$device"
done
else
build_qt "$TARGET"
if [ "${BUILD_MQTT-x}" == "1" ]; then
build_module "$TARGET" "qtmqtt"
fi
build_qtjsonserializer "$TARGET"
fi
export_sysroot