-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-kstarslite.sh
executable file
·335 lines (297 loc) · 11.5 KB
/
build-kstarslite.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
#!/bin/bash
. build-config #load values from config file
get_script_dir () {
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$( readlink "$SOURCE" )"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
$( cd -P "$( dirname "$SOURCE" )" )
pwd
}
export SCRIPT_DIR="$(get_script_dir)"
mkdir android_libs -p
# Ask user what libraries should be downloaded/built
if [ -z "$download_kf5" ]
then
echo "Should we download everything needed to build KF5 for Android(Y/N)? Check (http://thelastpolaris.blogspot.de/2016/05/how-to-build-kstars-lite-for-android.html)"
read user_response
download_kf5="$user_response"
fi
if [ -z "$build_kf5" ]
then
echo "Do you need to build KF5 for Android?"
read user_response
build_kf5="$user_response"
fi
if [ -z "$build_cfitsio" ]
then
echo "Do you need to build CFITSIO for Android"
read user_response
build_cfitsio="$user_response"
fi
if [ -z "$build_nova" ]
then
echo "Do you need to build NOVA for Android"
read user_response
build_nova="$user_response"
fi
if [ -z "$download_indi" ]
then
echo "Do you need to download INDI? (You can set location of INDI in build-config file)"
read user_response
download_indi="$user_response"
fi
if [ "$download_indi" = "Y" ] || [ "$download_indi" = "y" ] || [ "$download_indi" = "Yes" ] || [ "$download_indi" = "yes" ]
then
echo "Specify the location where to put INDI"
read user_response
download_indi_path="$user_response"
fi
if [ -z "$build_indi" ]
then
echo "Do you need to build INDI for Android?"
read user_response
build_indi="$user_response"
fi
if [ -z "$build_libraw" ]
then
echo "Do you need to build LibRAW for Android?"
read user_response
build_libraw="$user_response"
fi
# if [ ! -d "$kf5_android_path" ]
# then
# echo "Directory for saving KF5 doesn't exist"
# exit
# fi
echo "Libraries to download:"
if [ "$download_kf5" = "Y" ] || [ "$download_kf5" = "y" ] || [ "$download_kf5" = "Yes" ] || [ "$download_kf5" = "yes" ]
then
echo "* KF5"
fi
if [ "$download_indi" = "Y" ] || [ "$download_indi" = "y" ] || [ "$download_indi" = "Yes" ] || [ "$download_indi" = "yes" ]
then
echo "* INDI"
fi
echo "Libraries to build:"
if [ "$build_kf5" = "Y" ] || [ "$build_kf5" = "y" ] || [ "$build_kf5" = "Yes" ] || [ "$build_kf5" = "yes" ]
then
echo "* KF5"
fi
if [ "$build_cfitsio" = "Y" ] || [ "$build_cfitsio" = "y" ] || [ "$build_cfitsio" = "Yes" ] || [ "$build_cfitsio" = "yes" ]
then
echo "* CFITSIO"
fi
if [ "$build_nova" = "Y" ] || [ "$build_nova" = "y" ] || [ "$build_nova" = "Yes" ] || [ "$build_nova" = "yes" ]
then
echo "* NOVA"
fi
if [ "$build_indi" = "Y" ] || [ "$build_indi" = "y" ] || [ "$build_indi" = "Yes" ] || [ "$build_indi" = "yes" ]
then
echo "* INDI"
fi
if [ "$build_libraw" = "Y" ] || [ "$build_libraw" = "y" ] || [ "$build_libraw" = "Yes" ] || [ "$build_libraw" = "yes" ]
then
echo "* LibRAW"
fi
echo "Please, wait while we are downloading/building the libraries"
if [ "$download_kf5" = "Y" ] || [ "$download_kf5" = "y" ] || [ "$download_kf5" = "Yes" ] || [ "$download_kf5" = "yes" ]
then
# rm -rf ${kf5_android_path}
mkdir ${kf5_android_path} -p
cd ${kf5_android_path}
git clone git://anongit.kde.org/scratch/cordlandwehr/kdesrc-conf-android.git
mkdir -p extragear/kdesrc-build -p
git clone git://anongit.kde.org/kdesrc-build extragear/kdesrc-build
ln -s extragear/kdesrc-build/kdesrc-build kdesrc-build
ln -s kdesrc-conf-android/kdesrc-buildrc kdesrc-buildrc
fi
export ANDROID_NDK="$android_ndk"
export ANDROID_SDK_ROOT="$android_sdk_root"
export Qt5_android="$qt_android_libs"
export PATH=$ANDROID_SDK_ROOT/platform-tools/:$PATH
export ANT="$ant"
export JAVA_HOME="$java_home"
export ANDROID_ARCHITECTURE="$android_architecture"
export ANDROID_API_LEVEL="$android_api_level"
export BUILD_KSTARSLITE_DIR="${SCRIPT_DIR}"
export RELEASE_TYPE="${release_type}"
if [ "$ANDROID_ARCHITECTURE" == "arm64" ]
then
export ANDROID_TOOLCHAIN="aarch64-linux-android"
export ANDROID_ABI="arm64-v8a"
elif [ "$ANDROID_ARCHITECTURE" == "arm" ]
then
export ANDROID_TOOLCHAIN="arm-linux-androideabi"
export ANDROID_ABI="armeabi-v7a"
elif [ "$ANDROID_ARCHITECTURE" == "x86" ]
then
export ANDROID_TOOLCHAIN="x86"
export ANDROID_ABI="x86"
elif [ "$ANDROID_ARCHITECTURE" == "x86_64" ]
then
export ANDROID_TOOLCHAIN="x86_64-linux-android"
export ANDROID_ABI="x86_64"
elif [ "$ANDROID_ARCHITECTURE" == "mips" ]
then
export ANDROID_TOOLCHAIN="mipsel-linux-android"
export ANDROID_ABI="mips"
elif [ "$ANDROID_ARCHITECTURE" == "mips64" ]
then
export ANDROID_TOOLCHAIN="mips64el-linux-android"
export ANDROID_ABI="mips64"
else
echo "Can't recognize the architecture. Exit."
exit
fi
if [ "$build_kf5" = "Y" ] || [ "$build_kf5" = "y" ] || [ "$build_kf5" = "Yes" ] || [ "$build_kf5" = "yes" ]
then
cd ${kf5_android_path}
sed -E -i "s|build-dir.*|build-dir ${kf5_android_path}/kde/build/${android_architecture} |g" kdesrc-conf-android/kdesrc-buildrc
sed -E -i "s|source-dir.*|source-dir ${kf5_android_path}/kde/src |g" kdesrc-conf-android/kdesrc-buildrc
sed -E -i "s|kdedir.*|kdedir ${kf5_android_path}/kde/install/${android_architecture} |g" kdesrc-conf-android/kdesrc-buildrc
sed -E -i "s|-DCMAKE_TOOLCHAIN_FILE=.*?\\ |-DCMAKE_TOOLCHAIN_FILE=${SCRIPT_DIR}/android_libs_src/AndroidToolchain.cmake |g" kdesrc-conf-android/kdesrc-buildrc
if [ -e $qt_android_libs ]
then
sed -E -i "s|-DCMAKE_PREFIX_PATH=.*?\\ |-DCMAKE_PREFIX_PATH=${qt_android_libs} |g" kdesrc-conf-android/kdesrc-buildrc
else
echo "Qt Android libraries path doesn't exist. Exiting."
exit
fi
sed -E -i "s|use-modules.+|use-modules kconfig ki18n kplotting|g" kdesrc-conf-android/kdesrc-buildrc
rm -rf ${kf5_android_path}/kde/build/${android_architecture}/* # clean build folders
./kdesrc-build extra-cmake-modules libintl-lite frameworks-android
fi
#Create separate directory for all libraries built for this architecture
mkdir "${SCRIPT_DIR}/android_libs/${android_architecture}" -p
if [ "$build_cfitsio" = "Y" ] || [ "$build_cfitsio" = "y" ] || [ "$build_cfitsio" = "Yes" ] || [ "$build_cfitsio" = "yes" ]
then
# Build CFITSIO
cd "${SCRIPT_DIR}/android_libs_src/cfitsio"
make distclean
./build.sh "${SCRIPT_DIR}/android_libs/${android_architecture}/"
mv libcfitsio.a "${SCRIPT_DIR}/android_libs/${android_architecture}/"
make distclean
fi
# Build libnova
if [ "$build_nova" = "Y" ] || [ "$build_nova" = "y" ] || [ "$build_nova" = "Yes" ] || [ "$build_nova" = "yes" ]
then
rm -rf "${SCRIPT_DIR}/android_libs_src/libnova/build"
mkdir "${SCRIPT_DIR}/android_libs_src/libnova/build" -p
cd "${SCRIPT_DIR}/android_libs_src/libnova/build"
cmake ../ -DCMAKE_TOOLCHAIN_FILE="${SCRIPT_DIR}/android_libs_src/AndroidToolchain.cmake" -DBUILD_SHARED_LIBRARY=OFF
make
mv lib/liblibnova.a "${SCRIPT_DIR}/android_libs/${android_architecture}/"
make clean
fi
# Download INDI
if [ "$download_indi" = "Y" ] || [ "$download_indi" = "y" ] || [ "$download_indi" = "Yes" ] || [ "$download_indi" = "yes" ]
then
mkdir $download_indi_path -p
cd $download_indi_path
echo $PWD
git clone https://github.com/indilib/indi.git
# Update indi location in build-config file
sed -E -i "s|indi_location.*|indi_location=\"$download_indi_path\" # Set INDI source location (location of libindi with CMakeLists.txt in it)|g" ${SCRIPT_DIR}/build-config
indi_location=$download_indi_path
fi
# Build INDI
if [ "$build_indi" = "Y" ] || [ "$build_indi" = "y" ] || [ "$build_indi" = "Yes" ] || [ "$build_indi" = "yes" ]
then
cd $indi_location/indi/
git pull
rm -rf $indi_location/indi/build-android
mkdir $indi_location/indi/build-android -p
cd $indi_location/indi/build-android
cmake $indi_location/indi/libindi -DCMAKE_TOOLCHAIN_FILE="${SCRIPT_DIR}/android_libs_src/AndroidToolchain.cmake" \
-DCFITSIO_LIBRARIES="${SCRIPT_DIR}/android_libs/${android_architecture}/libcfitsio.a" \
-DCFITSIO_INCLUDE_DIR="${SCRIPT_DIR}/include" \
-DNOVA_LIBRARIES="${SCRIPT_DIR}/android_libs/${android_architecture}/liblibnova.a" \
-DCMAKE_PREFIX_PATH="${Qt5_android}"
make
mv libindi.a "${SCRIPT_DIR}/android_libs/${android_architecture}/"
mv libindiclientqt.a "${SCRIPT_DIR}/android_libs/${android_architecture}/"
rm CMakeCache.txt
make clean
cd "${SCRIPT_DIR}/android_libs/${ANDROID_ARCHITECTURE}"
# Combine libindi and liblibnova
ar -M <<EOM
CREATE libindiclientandroid.a
ADDLIB liblibnova.a
ADDLIB libindiclientqt.a
ADDLIB libindi.a
SAVE
END
EOM
ranlib libindiclientandroid.a
rm libindiclientqt.a
rm libindi.a
fi
#Build LibRAW
if [ "$build_libraw" = "Y" ] || [ "$build_libraw" = "y" ] || [ "$build_libraw" = "Yes" ] || [ "$build_libraw" = "yes" ]
then
cd "${SCRIPT_DIR}/android_libs_src/libraw/Android/jni/"
sed -E -i "s|APP_PLATFORM.*|APP_PLATFORM := android-${ANDROID_API_LEVEL} |g" Application.mk
sed -E -i "s|APP_ABI.*|APP_ABI := ${ANDROID_ABI} |g" Application.mk
${ANDROID_NDK}/./ndk-build
mv ../libs/${ANDROID_ABI}/libRAWExtractor.so "${SCRIPT_DIR}/android_libs/${android_architecture}/"
rm -rf ../libs/
rm -rf ../obj/
fi
# Build KStars Lite
mkdir ${build_dir} -p
# rm -rf "${build_dir}/build"
mkdir "${build_dir}/build" -p
cd "${build_dir}/build"
rm -rf "${build_dir}/export"
mkdir "${build_dir}/export" -p
release_file="no_file"
if [ "$release_type" = "Release" ]
then
release_file="QtApp-release-unsigned.apk"
else
release_file="QtApp-debug.apk"
fi
cmake "${kstars_DIR}" -DCMAKE_TOOLCHAIN_FILE="${SCRIPT_DIR}/android_libs_src/AndroidToolchain.cmake" \
-DBUILD_KSTARSLITE_DIR=${SCRIPT_DIR} \
-DANDROID_ARCHITECTURE=${ANDROID_ARCHITECTURE} \
-DCMAKE_BUILD_TYPE=${release_type} \
-DCMAKE_PREFIX_PATH=${qt_android_libs} \
-DCMAKE_INSTALL_PREFIX="${build_dir}/export" \
-DQTANDROID_EXPORTED_TARGET=kstars \
-DANDROID_APK_DIR="${kstars_DIR}"/apk \
-DBUILD_KSTARS_LITE=ON \
-DKF5Config_DIR="${kf5_android_path}/kde/install/${android_architecture}/lib/cmake/KF5Config" \
-DKF5Plotting_DIR="${kf5_android_path}/kde/install/${android_architecture}/lib/cmake/KF5Plotting" \
-DKF5I18n_DIR="${kf5_android_path}/kde/install/${android_architecture}/lib/cmake/KF5I18n" \
-DKF5_HOST_TOOLING="${kf5_host_tooling}" \
make install
make create-apk-kstars
if [ "$release_type" = "Release" ]
then
echo "Would you like to sign apk?"
read user_response
if [ "$user_response" = "Y" ] || [ "$user_response" = "y" ] || [ "$user_response" = "Yes" ] || [ "$user_response" = "yes" ]
then
echo "Do you need to create a keystore (yes/no)?"
read user_response
if [ "$user_response" = "Y" ] || [ "$user_response" = "y" ] || [ "$user_response" = "Yes" ] || [ "$user_response" = "yes" ]
then
keytool -genkey -alias ${keystore_alias} -keyalg RSA -keystore ${keystore_path} -keysize 2048
fi
read -s -p "Enter password for keystore: " keystore_password
jarsigner -keystore ${keystore_path} -storepass "$keystore_password" ${build_dir}/build/kstars_build_apk/bin/${release_file} ${keystore_alias}
rm ${build_dir}/build/kstars_build_apk/bin/kstars-signed.apk
zipalign -v 4 ${build_dir}/build/kstars_build_apk/bin/${release_file} ${build_dir}/build/kstars_build_apk/bin/kstars-signed.apk
release_file="kstars-signed.apk"
fi
fi
echo "Final APK file is ${build_dir}/build/kstars_build_apk/bin/${release_file}"
echo "If you want to install KStars Lite to your Android device, connect it to your PC (only one Android device at a time) and enter Y/Yes."
read user_response
if [ "$user_response" = "Y" ] || [ "$user_response" = "y" ] || [ "$user_response" = "Yes" ] || [ "$user_response" = "yes" ]
then
adb install -r kstars_build_apk/bin/${release_file}
fi