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_brew.sh
executable file
·133 lines (105 loc) · 5.59 KB
/
build_both_brew.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
#!/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
mkdir ${workdir}/ext
cd ${workdir}
min_macos_ver=10.14
brew install qt@5 openssl cmake ninja boost
# download and build libtorrent
git clone --recurse-submodules https://github.com/blahdy/libtorrent.git
cd libtorrent
OPENSSL_ROOT_DIR=/usr/local/opt/openssl
OPENSSL_LIBRARIES=/usr/local/opt/openssl/lib
cmake -Wno-dev -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 -DBUILD_SHARED_LIBS=OFF -Ddeprecated-functions=OFF -DCMAKE_INSTALL_PREFIX=${depsdir} -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib
cmake --build build
cmake --install build
cd ..
# 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}
mkdir build && cd build
cmake -DCMAKE_PREFIX_PATH="$HOME/tmp/qbt/ext" -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_EXTENSIONS=OFF -DCMAKE_OSX_DEPLOYMENT_TARGET=10.14 -DCMAKE_BUILD_TYPE=Release -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib -DQt5_DIR=$(brew --prefix qt5)/lib/cmake/Qt5 ..
make -j$(sysctl -n hw.ncpu)
# 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="/usr/local/opt/qt5"
$QT_ROOT/bin/macdeployqt "qbittorrent.app"
# deploy Qt' translations
tr_path="$PWD/qbittorrent.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" >> "qbittorrent.app/Contents/Resources/qt.conf"
# create .dmg file, there magic becomes :)
codesign --deep --force --verify --verbose --sign "-" "qbittorrent.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="qbittorrent.app" "qbittorrent" "$out_file"
else
# use 'hdiutil' available on each macOS
hdiutil create -srcfolder "qbittorrent.app" -nospotlight -layout NONE -fs HFS+ "qbittorrent.dmg"
# this is very strange, but much better compression is achieved only after image conversion ...
hdiutil convert "qbittorrent.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}
mkdir build && cd build
cmake -DCMAKE_PREFIX_PATH="$HOME/tmp/qbt/ext" -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_EXTENSIONS=OFF -DCMAKE_OSX_DEPLOYMENT_TARGET=10.14 -DCMAKE_BUILD_TYPE=Release -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib -DQt5_DIR=$(brew --prefix qt5)/lib/cmake/Qt5 ..
make -j$(sysctl -n hw.ncpu)
# deploy Qt' libraries for an app
$QT_ROOT/bin/macdeployqt "qbittorrent.app"
# deploy Qt' translations
tr_path="$PWD/qbittorrent.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" >> "qbittorrent.app/Contents/Resources/qt.conf"
# create .dmg file, there magic becomes :)
codesign --deep --force --verify --verbose --sign "-" "qbittorrent.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="qbittorrent.app" "qbittorrent" "$out_file"
else
# use 'hdiutil' available on each macOS
hdiutil create -srcfolder "qbittorrent.app" -nospotlight -layout NONE -fs HFS+ "qbittorrent.dmg"
# this is very strange, but much better compression is achieved only after image conversion ...
hdiutil convert "qbittorrent.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}"