This repository has been archived by the owner on Feb 16, 2023. It is now read-only.
forked from qbittorrent/qBittorrent
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_both_with sources.sh
221 lines (173 loc) · 9.54 KB
/
build_both_with sources.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
#!/bin/bash -e -u -x
# -e / set -e / set -o errexit - exit immediately if a command exits with a non-zero status
# -u / set -u / set -o nounset - treat unset variables as an error when substituting
# -x / set -x / set -o xtrace - print commands and their arguments as they are executed
set -o pipefail # the return value of a pipeline is the status of the last command to exit with a non-zero status
workdir=$(mktemp -d) # path must be absolute, must be writable for current user
echo "current working directory: ${workdir}"
depsdir="${workdir%/}/ext" # all dependencies will be placed here
cd ${workdir}
# download Qt from Git repository
qt_branch=dev # Qt version to use
git clone https://code.qt.io/qt/qt5.git
cd qt5
git checkout ${qt_branch}
perl init-repository --module-subset=qtbase,qtsvg,qttools,qttranslations
# detect minimum macOS version required by Qt and use this value while building all other stuff
min_macos_ver=10.14
# leave Qt sources for a while... some dependencies must be build before building Qt itself
cd ${workdir}
# download and build OpenSSL
openssl_ver=OpenSSL_1_1_1-stable # OpenSSL version to use
curl -L https://github.com/openssl/openssl/archive/${openssl_ver}.tar.gz | tar xz
cd openssl-${openssl_ver}
./config no-comp no-deprecated no-dynamic-engine no-tests no-zlib --openssldir=/etc/ssl --prefix=${depsdir} -mmacosx-version-min=${min_macos_ver}
make -j$(sysctl -n hw.ncpu)
make install_sw
cd ${workdir}
# download CMake and Ninja
cmake_ver=3.22.0-rc2 # CMake version to use
curl -L https://github.com/Kitware/CMake/releases/download/v${cmake_ver}/cmake-${cmake_ver}-macos-universal.tar.gz | tar xz
cmakedir=$(ls | grep cmake)
cmake="${workdir}/${cmakedir}/CMake.app/Contents/bin/cmake"
PATH="${workdir}/cmake-${cmake_ver}-macos-universal/CMake.app/Contents/bin":"$PATH"
# so, Qt dependencies are satisfied now, time to build Qt
cd qt5
qtbuilddir="../build-qt"
mkdir ${qtbuilddir} && cd ${qtbuilddir}
${workdir}/qt5/configure -prefix "${depsdir}" -opensource -confirm-license -release -appstore-compliant -c++std c++17 -no-pch -I "${depsdir}/include" -L "${depsdir}/lib" -make libs -no-dbus -no-icu -qt-pcre -system-zlib -ssl -openssl-linked -no-cups -qt-libpng -qt-libjpeg -no-feature-testlib -no-feature-concurrent
make -j$(sysctl -n hw.ncpu)
make install
cd ${workdir}
# download and build Boost
boost_ver=1.77.0 # Boost version to use
boost_ver_u=${boost_ver//./_}
curl -L https://boostorg.jfrog.io/artifactory/main/master/boost_${boost_ver_u}-snapshot.tar.bz2 | tar xj
cd boost_${boost_ver_u}
./bootstrap.sh
./b2 --prefix=${depsdir} --with-system variant=release link=static cxxflags="-std=c++17 -mmacosx-version-min=${min_macos_ver}" install
cd ${workdir}
ninja_ver=1.10.2 # Ninja version to use
curl -O -J -L https://github.com/ninja-build/ninja/releases/download/v${ninja_ver}/ninja-mac.zip
unzip -d "${depsdir}/bin" ninja-mac.zip
# download and build libtorrent
git clone --recurse-submodules https://github.com/arvidn/libtorrent.git
cd libtorrent
# I build static library, something was changed and now linker produce few warnings during qBittorrent building,
# so apply patch to fix these warnings. I don't know is they are critical or not, but I just don't like them.
# this fix is just "quick fix" or workaround, so merge request was not submitted to the developers.
${cmake} -B build -G Ninja -Wno-dev -DCMAKE_PREFIX_PATH=${depsdir} -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_EXTENSIONS=OFF -DCMAKE_OSX_DEPLOYMENT_TARGET=${min_macos_ver} -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -Ddeprecated-functions=OFF -DCMAKE_INSTALL_PREFIX=${depsdir}
${cmake} --build build
${cmake} --install build
cd ${workdir}
# download and build qBittorrent - some magic comes here :)
# download the sources
qbt_branch=master # qBittorrent version to use, use latest development version
curl -L https://github.com/blahdy/qBittorrent/archive/{$qbt_branch}.tar.gz | tar xz
cd qBittorrent-${qbt_branch}
# I don't like the way how official qBittorrent app is packaged for macOS, so I do it in my own way.
# I didn't suggest any patches used there to qBittorrent developers/maintainers, because I'm not Apple
# developer and strictly don't know the "true" methods, and these changes were made in my own opinion.
# patches are completely optional.
# first patch disables Qt translations deployment, I'll do it later.
# cmake doesn't understand qmake' placeholders in Info.plist, so change them
perl -pi -e "s/\@EXECUTABLE\@/\\$\\{MACOSX_BUNDLE_EXECUTABLE_NAME\\}/g" dist/mac/Info.plist
perl -pi -e "s/\\$\\{MACOSX_DEPLOYMENT_TARGET\\}/${min_macos_ver}/g" dist/mac/Info.plist
${cmake} -B build -G Ninja -DCMAKE_PREFIX_PATH=${depsdir} -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_EXTENSIONS=OFF -DCMAKE_OSX_DEPLOYMENT_TARGET=${min_macos_ver} -DCMAKE_BUILD_TYPE=Release -D QT6="ON"
${cmake} --build build
# next part of this script is part from my another script used to build my own projects for macOS.
# I was to lazy to rename/remove variables :), so that in slightly different style.
QT_ROOT="${depsdir}"
APP_NAME="qBittorrent"
# deploy Qt' libraries for an app
cd build
mv qbittorrent.app "$APP_NAME.app"
$QT_ROOT/bin/macdeployqt "$APP_NAME.app"
# deploy Qt' translations
tr_path="$PWD/$APP_NAME.app/Contents/Resources/translations"
[[ -d "$tr_path" ]] || mkdir "$tr_path"
pushd "$QT_ROOT/translations" > /dev/null
langs=$(ls -1 qt_*.qm | grep -v help | sed 's/qt_\(.*\)\.qm/\1/g')
for lang in $langs
do
lang_files=$(ls -1 qt*_$lang.qm)
$QT_ROOT/bin/lconvert -o "$tr_path/qt_$lang.qm" $lang_files
done
popd > /dev/null
# update generated qt.conf
echo "Translations = Resources/translations" >> "$APP_NAME.app/Contents/Resources/qt.conf"
# create .dmg file, there magic becomes :)
codesign --deep --force --verify --verbose --sign "-" "$APP_NAME.app"
out_file="$PWD/qbittorrent-${qbt_branch}-macosx.dmg"
if [[ $(which dmgbuild) ]]
then
# use 'dmgbuild' utility: https://pypi.org/project/dmgbuild/
curl -O -J -L -s "https://www.dropbox.com/s/q315bjd96umlxm0/settings.py?dl=1"
dmgbuild -s "settings.py" -D app="$APP_NAME.app" "$APP_NAME" "$out_file"
else
# use 'hdiutil' available on each macOS
hdiutil create -srcfolder "$APP_NAME.app" -nospotlight -layout NONE -fs HFS+ "$APP_NAME.dmg"
# this is very strange, but much better compression is achieved only after image conversion ...
hdiutil convert "$APP_NAME.dmg" -format UDBZ -o "$out_file"
fi
# move created .dmg file to user's Downloads directory, it is writable everywhere
mv "$out_file" "$HOME/Downloads/"
cd ${workdir}
# download and build qBittorrent - some magic comes here :)
# download the sources
qbt_branch=masters # qBittorrent version to use, use latest development version
curl -L https://github.com/blahdy/qBittorrent/archive/{$qbt_branch}.tar.gz | tar xz
cd qBittorrent-${qbt_branch}
# I don't like the way how official qBittorrent app is packaged for macOS, so I do it in my own way.
# I didn't suggest any patches used there to qBittorrent developers/maintainers, because I'm not Apple
# developer and strictly don't know the "true" methods, and these changes were made in my own opinion.
# patches are completely optional.
# first patch disables Qt translations deployment, I'll do it later.
curl -L -s "https://www.dropbox.com/s/pnri68xsdhu5rej/qbt-no-predef-qt-stuff-cmake.patch?dl=1" | patch -p1
# better HiDPI support
curl -L -s "https://www.dropbox.com/s/2crekp814e5m2vj/hidpi-hacks-new.patch?dl=1" | patch -p1
# cmake doesn't understand qmake' placeholders in Info.plist, so change them
perl -pi -e "s/\@EXECUTABLE\@/\\$\\{MACOSX_BUNDLE_EXECUTABLE_NAME\\}/g" dist/mac/Info.plist
perl -pi -e "s/\\$\\{MACOSX_DEPLOYMENT_TARGET\\}/${min_macos_ver}/g" dist/mac/Info.plist
${cmake} -B build -G Ninja -DCMAKE_PREFIX_PATH=${depsdir} -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_EXTENSIONS=OFF -DCMAKE_OSX_DEPLOYMENT_TARGET=${min_macos_ver} -DCMAKE_BUILD_TYPE=Release
${cmake} --build build
# next part of this script is part from my another script used to build my own projects for macOS.
# I was to lazy to rename/remove variables :), so that in slightly different style.
QT_ROOT="${depsdir}"
APP_NAME="qBittorrent"
# deploy Qt' libraries for an app
cd build
mv qbittorrent.app "$APP_NAME.app"
$QT_ROOT/bin/macdeployqt "$APP_NAME.app"
# deploy Qt' translations
tr_path="$PWD/$APP_NAME.app/Contents/Resources/translations"
[[ -d "$tr_path" ]] || mkdir "$tr_path"
pushd "$QT_ROOT/translations" > /dev/null
langs=$(ls -1 qt_*.qm | grep -v help | sed 's/qt_\(.*\)\.qm/\1/g')
for lang in $langs
do
lang_files=$(ls -1 qt*_$lang.qm)
$QT_ROOT/bin/lconvert -o "$tr_path/qt_$lang.qm" $lang_files
done
popd > /dev/null
# update generated qt.conf
echo "Translations = Resources/translations" >> "$APP_NAME.app/Contents/Resources/qt.conf"
# create .dmg file, there magic becomes :)
codesign --deep --force --verify --verbose --sign "-" "$APP_NAME.app"
out_file="$PWD/qbittorrent-${qbt_branch}-macosx.dmg"
if [[ $(which dmgbuild) ]]
then
# use 'dmgbuild' utility: https://pypi.org/project/dmgbuild/
curl -O -J -L -s "https://www.dropbox.com/s/q315bjd96umlxm0/settings.py?dl=1"
dmgbuild -s "settings.py" -D app="$APP_NAME.app" "$APP_NAME" "$out_file"
else
# use 'hdiutil' available on each macOS
hdiutil create -srcfolder "$APP_NAME.app" -nospotlight -layout NONE -fs HFS+ "$APP_NAME.dmg"
# this is very strange, but much better compression is achieved only after image conversion ...
hdiutil convert "$APP_NAME.dmg" -format UDBZ -o "$out_file"
fi
# move created .dmg file to user's Downloads directory, it is writable everywhere
mv "$out_file" "$HOME/Downloads/"
# cleanup
cd "${workdir}/.."
rm -rf "${workdir}"