-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·280 lines (261 loc) · 9.37 KB
/
build.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
#!/bin/bash
# build.sh
# (c) 2020 Bernd Wachter <bwachter@aardsoft.fi>
GIT_SOURCE_DIR=`git rev-parse -q --absolute-git-dir 2>/dev/null`
IS_GITDIR=$?
if [ $IS_GITDIR -eq 0 ]; then
if [ -f $GIT_SOURCE_DIR/../.local ]; then
. $GIT_SOURCE_DIR/../.local
fi
GIT_NEWEST_TAG=`git describe --abbrev=0 --tags`
GIT_COMMIT_COUNT=`git rev-list ${GIT_NEWEST_TAG}.. --count`
GIT_TOTAL_COMMIT_COUNT=`git rev-list HEAD --count`
# 0 if dirty, 1 if clean
IS_GITDIRTY=`git describe --abbrev=0 --tags --dirty="/dirty"|grep -q dirty; echo $?`
SOURCE_DIR=$GIT_SOURCE_DIR/../
else
SOURCE_DIR=`pwd`
if [ -f .local ]; then
.local
fi
fi
ANDROID_ABIS=${ANDROID_ABIS:-arm64-v8a x86_64 armeabi-v7a}
ANDROID_SDK_VERSION=${ANDROID_SDK_VERSION:-android-29}
QT_VERSION=${QT_VERSION:-5.15.1}
QT_ANDROID_BIN=${QT_ANDROID_BIN:-$HOME/qt/qt${QT_VERSION}-${ANDROID_SDK_VERSION}/bin}
QT_WINDOWS_BIN=${QT_WINDOWS_BIN:-$HOME/qt/qt${QT_VERSION}-mingw64/bin}
WIN32_OBJDUMP=${WIN32_OBJDUMP:-x86_64-w64-mingw32-objdump}
WIN32_SYSROOT=${WIN32_SYSROOT:-/usr/x86_64-w64-mingw32/sys-root/mingw/bin}
WIN32_PLUGINS=${WIN32_PLUGINS:-platforms}
BUILD_DIR=${BUILD_DIR:-build}
QMAKE_CXX=${QMAKE_CXX:-clang++}
QMAKE_LINK=${QMAKE_LINK:-clang++}
declare -A ANDROID_ICONS=( [hdpi]=72 [mdpi]=48 [ldpi]=36 [xhdpi]=96 [xxhdpi]=142 [xxxhdpi]=192 )
declare -A PC_ICONS=( [mini]=48 [regular]=256 [large]=512 )
export ANDROID_SDK_ROOT
dump_DLL(){
if [ -n "$1" ]; then
$WIN32_OBJDUMP -p $1 |grep 'DLL Name:'|sed 's/^.*DLL Name: //'
fi
}
deploy_DLLs(){
for _dll in `dump_DLL $1`; do
if [ -f "${QT_WINDOWS_BIN}/${_dll}" ]; then
cp "${QT_WINDOWS_BIN}/${_dll}" ${2}/
elif [ -f "${WIN32_SYSROOT}/${_dll}" ]; then
cp "${WIN32_SYSROOT}/${_dll}" ${2}/
else
echo "Skipping ${_dll}"
fi
done
}
build_android(){
if [ -z "$ANDROID_SDK_ROOT" ]; then
echo "ANDROID_SDK_ROOT not set. It can be configured in the .local file."
exit 1
fi
mkdir -p ${BUILD_DIR}/android
cd ${BUILD_DIR}/android
$QT_ANDROID_BIN/qmake CONFIG+=release ANDROID_ABIS="$ANDROID_ABIS" $SOURCE_DIR
make -j$(nproc)
cd emacsbridge
make -j$(nproc) apk
cd $SOURCE_DIR
}
build_android_icons(){
mkdir -p android/res
cd android/res
for _res_name in "${!ANDROID_ICONS[@]}"; do
_res=${ANDROID_ICONS[$_res_name]}
mkdir -p drawable-${_res_name}
echo "magick -density ${_res}x${_res} -background transparent ${SOURCE_DIR}/source_icons/merged.svg -define icon:auto-resize -resize ${_res}x${_res} -colors 256 drawable-${_res_name}/icon.png"
magick -density ${_res}x${_res} -background transparent ${SOURCE_DIR}/source_icons/merged.svg -define icon:auto-resize -colors 256 -resize ${_res}x${_res} drawable-${_res_name}/icon.png
done
cd $SOURCE_DIR
}
build_pc(){
echo "Building PC build in ${BUILD_DIR}/pc"
mkdir -p ${BUILD_DIR}/pc
cd ${BUILD_DIR}/pc
qmake-qt5 QMAKE_CXX=$QMAKE_CXX QMAKE_LINK=$QMAKE_LINK $SOURCE_DIR
make -j$(nproc)
cd $SOURCE_DIR
}
build_pc_icons(){
mkdir -p icons
for _res_name in "${!PC_ICONS[@]}"; do
_res=${PC_ICONS[$_res_name]}
if [ $_res_name = "regular" ]; then
_icon_name="icon.png"
else
_icon_name="icon_${_res_name}.png"
fi
echo "magick -density ${_res}x${_res} -background transparent source_icons/merged.svg -define icon:auto-resize -resize ${_res}x${_res} -colors 256 icons/${_icon_name}"
magick -density ${_res}x${_res} -background transparent source_icons/merged.svg -define icon:auto-resize -resize ${_res}x${_res} -colors 256 icons/${_icon_name}
done
}
build_dev_rpm(){
# calling release here makes sure metadata for the binary is updated
release y
rm -rf ${BUILD_DIR}
if [ $IS_GITDIR -eq 0 ]; then
if [ $IS_GITDIRTY -eq 0 ]; then
_release="dirty"
else
_release=1
fi
mkdir -p ~/rpmbuild/SPECS ~/rpmbuild/SOURCES
if [ -d $GIT_SOURCE_DIR/../build ]; then
rm -Rf $GIT_SOURCE_DIR/../build
fi
tar czf ~/rpmbuild/SOURCES/emacsbridge.tar.gz $GIT_SOURCE_DIR/..
sed -e "s/RELEASE/$_release/" -e "s/VERSION/$GIT_NEWEST_TAG.$GIT_COMMIT_COUNT/" $GIT_SOURCE_DIR/../emacsbridge.spec > ~/rpmbuild/SPECS/emacsbridge.spec
rpmbuild -ba ~/rpmbuild/SPECS/emacsbridge.spec
else
echo "Building dev RPMs is only supported from within a git tree"
fi
}
build_windows(){
mkdir -p ${BUILD_DIR}/windows
cd ${BUILD_DIR}/windows
$QT_WINDOWS_BIN/qmake CONFIG+=debug -recursive $SOURCE_DIR
make -j$(nproc)
cd $SOURCE_DIR
}
copy_android_artifacts(){
_debug_dir=$BUILD_DIR/android/emacsbridge/android-build/build/outputs/apk/debug
_release_dir=$BUILD_DIR/android-deploy/build/outputs/apk/release
_bundle_dir=$BUILD_DIR/android-deploy/build/outputs/bundle
if [ -n "$ARTIFACT_COPY_DIR" ]; then
_version=$GIT_NEWEST_TAG.$GIT_COMMIT_COUNT
if [ $IS_GITDIRTY -eq 0 ]; then
_version=${_version}-dirty
fi
mkdir -p "$ARTIFACT_COPY_DIR"
if [ -f $_debug_dir/android-build-debug.apk ]; then
cp $_debug_dir/android-build-debug.apk $ARTIFACT_COPY_DIR/emacsbridge-${_version}-debug.apk
fi
if [ -f $_release_dir/android-deploy-release-signed.apk ]; then
cp $_release_dir/android-deploy-release-signed.apk $ARTIFACT_COPY_DIR/emacsbridge-${_version}-release-signed.apk
fi
if [ -f $_release_dir/android-deploy-release-unsigned.apk ]; then
cp $_release_dir/android-deploy-release-unsigned.apk $ARTIFACT_COPY_DIR/emacsbridge-${_version}-release-unsigned.apk
fi
if [ -f $_bundle_dir/release/android-deploy-release.aab ]; then
cp $_bundle_dir/release/android-deploy-release.aab $ARTIFACT_COPY_DIR/emacsbridge-${_version}-release.aab
fi
if [ -f $_bundle_dir/debug/android-deploy-debug.aab ]; then
cp $_bundle_dir/debug/android-deploy-debug.aab $ARTIFACT_COPY_DIR/emacsbridge-${_version}-debug.aab
fi
fi
}
deploy_android(){
mkdir -p ${BUILD_DIR}/android-deploy
export BUILD_TARGET=${BUILD_DIR}/android-deploy
cd ${BUILD_DIR}/android
make install INSTALL_ROOT=$BUILD_TARGET
if [ -n "$SIGN_URL" ] && [ -n "$SIGN_ALIAS" ]; then
DEPLOY_SIGN_ARGS="--sign $SIGN_URL $SIGN_ALIAS"
fi
$QT_ANDROID_BIN/androiddeployqt --release --output $BUILD_TARGET --gradle --android-platform $ANDROID_SDK_VERSION --input emacsbridge/android-emacsbridge-deployment-settings.json --aab $DEPLOY_SIGN_ARGS
cd $SOURCE_DIR
}
deploy_windows(){
mkdir -p ${BUILD_DIR}/windows-deploy
export BUILD_TARGET=${BUILD_DIR}/windows-deploy
cd ${BUILD_DIR}/windows
cp qthttpserver/lib/Qt5HttpServer.dll ${BUILD_TARGET}/
deploy_DLLs emacsbridge/debug/emacsbridge.exe ${BUILD_TARGET}/
for _dll in ${BUILD_TARGET}/*.dll; do
deploy_DLLs $_dll ${BUILD_TARGET}/
done | grep Skipping|sort|uniq
mkdir -p ${BUILD_TARGET}/plugins
for _plugin in ${WIN32_PLUGINS}; do
cp -R ${QT_WINDOWS_BIN}/../plugins/${_plugin} ${BUILD_TARGET}/plugins/
done
cp -R ${QT_WINDOWS_BIN}/../qml ${BUILD_TARGET}/
cd $SOURCE_DIR
}
org_to_html(){
if ! [ -f ${BUILD_DIR}/htmlize.el ]; then
wget --compression=auto -O ${BUILD_DIR}/htmlize.el https://raw.githubusercontent.com/hniksic/emacs-htmlize/master/htmlize.el
fi
_org_files="index hacking user settings"
for _file in $_org_files; do
echo "Building $_file"
emacs doc/$_file.org -L ${BUILD_DIR} --batch --eval '(load-file "export-html.lisp")' -f org-html-export-to-html --kill
mv doc/$_file.html html/$_file.html
done
}
release(){
_tar_only="$1"
_custom_tag="$2"
# Force documentation update on releases
org_to_html
(( _total_commit_count=$GIT_TOTAL_COMMIT_COUNT+1 ))
if [ -n "$_custom_tag" ]; then
_new_tag=$_custom_tag
else
_newest_tag_minor=${GIT_NEWEST_TAG//*./}
_newest_tag_major=${GIT_NEWEST_TAG//.*/}
(( _newest_tag_minor=_newest_tag_minor+1 ))
_new_tag=$_newest_tag_major.$_newest_tag_minor
fi
cat >release_version.pri <<-EOF
NEWEST_TAG = $_new_tag
COMMIT_COUNT = 0
TOTAL_COMMIT_COUNT = $_total_commit_count
EOF
if [ -z "$_tar_only" ] || [ "$_tar_only" = "n" ]; then
echo "Comitting and tagging release files"
git add html/*.html
git add release_version.pri
git commit -m "Release $_new_tag"
git tag $_new_tag
fi
}
mkdir -p $BUILD_DIR
case "$1" in
"build-icons")
build_android_icons
build_pc_icons
;;
"deploy-android")
build_android
deploy_android
copy_android_artifacts
;;
"android")
build_android
copy_android_artifacts
;;
"dev-rpm")
build_dev_rpm
;;
"html")
org_to_html
;;
"pc")
build_pc
;;
"release")
echo "$1,$2,$3"
release "$2" "$3"
;;
"run")
shift
if [ -z "$1" ]; then
LD_LIBRARY_PATH=$BUILD_DIR/pc/qthttpserver/lib $BUILD_DIR/pc/emacsbridge/emacsbridge
else
LD_LIBRARY_PATH=$BUILD_DIR/pc/qthttpserver/lib $BUILD_DIR/pc/emacsbridge/emacsbridge $@
fi
;;
"windows")
build_windows
deploy_windows
;;
*)
build_pc
build_android
;;
esac