File indexing completed on 2024-11-10 04:05:16
0001 #!/bin/bash -e 0002 # 0003 # SPDX-License-Identifier: GPL-3.0-or-later 0004 # 0005 0006 # Example: androidbuild.sh -p=all --src=/home/sh_zam/workspace/krita --build-type=Release --build-root=/home/sh_zam/workspace/test-kreeta --ndk-path=/home/sh_zam/Android/Sdk/ndk-bundle --sdk-path=/home/sh_zam/Android/Sdk --api-level=21 --android-abi=armeabi-v7a --qt-path=/home/sh_zam/Qt/5.12.1/android_armv7 0007 0008 set -e 0009 set -x 0010 0011 echoerr() { printf "ERROR: %s\n" "$*" >&2; } 0012 0013 print_usage() { 0014 printf "\nUsage: "$0" [-p=PACKAGE] [ARGUMENTS..]\n" 0015 printf "Packages: [all|krita-bin|apk|qt|3rdparty|plugins|boost|kf5]\n" 0016 printf "Arguments: \n" 0017 printf "\t--src=PATH Source files\n" 0018 printf "\t--build-type=TYPE TYPE=[Debug|RelWithDebInfo|Release]\n" 0019 printf "\t--build-root=PATH Path to build folder\n" 0020 printf "\t--qt-path=PATH Path to qt libs(optional)\n" 0021 printf "\t--ndk-path=PATH Android NDK root path\n" 0022 printf "\t--sdk-path=PATH Android SDK root path\n" 0023 printf "\t--api-level=NUMBER API level >= 21\n" 0024 printf "\t--android-abi=ABI ABI=[armeabi-v7a|arm64-v8a|x86|x86_64]\n" 0025 } 0026 0027 # check if the argument is passed 0028 check_exists() { 0029 if [[ ! -d ${!1} ]]; then 0030 echoerr "$1 not specified or does not exist" 0031 print_usage 0032 exit 0033 fi 0034 } 0035 0036 setup_directories() { 0037 export DOWNLOADS_DIR=$BUILD_ROOT/d 0038 export DEPS_BUILD=$BUILD_ROOT/b 0039 export PLUGINS_BUILD=$BUILD_ROOT/p 0040 export THIRDPARTY_INSTALL=$BUILD_ROOT/i 0041 0042 if [[ ! -d $DOWNLOADS_DIR ]]; then 0043 mkdir $DOWNLOADS_DIR -p 0044 fi 0045 0046 if [[ ! -d $DEPS_BUILD ]]; then 0047 mkdir $DEPS_BUILD -p 0048 fi 0049 0050 if [[ ! -d $PLUGINS_BUILD ]]; then 0051 mkdir $PLUGINS_BUILD -p 0052 fi 0053 0054 if [[ ! -d $THIRDPARTY_INSTALL ]]; then 0055 mkdir $THIRDPARTY_INSTALL -p 0056 fi 0057 } 0058 0059 configure_ext() { 0060 cd $DEPS_BUILD 0061 cmake $KRITA_ROOT/3rdparty \ 0062 -DINSTALL_ROOT=$THIRDPARTY_INSTALL \ 0063 -DEXTERNALS_DOWNLOAD_DIR=$DOWNLOADS_DIR \ 0064 -DCMAKE_INSTALL_PREFIX=$THIRDPARTY_INSTALL \ 0065 -DCMAKE_TOOLCHAIN_FILE=$CMAKE_ANDROID_NDK/build/cmake/android.toolchain.cmake \ 0066 -DANDROID_ABI=$ANDROID_ABI \ 0067 -DANDROID_STL=c++_shared \ 0068 -DANDROID_PLATFORM=$ANDROID_NATIVE_API_LEVEL \ 0069 -DANDROID_SDK_ROOT=$ANDROID_SDK_ROOT \ 0070 -DCMAKE_FIND_ROOT_PATH="$BUILD_ROOT/i" \ 0071 -DANDROID_SDK_COMPILE_API="android-33" \ 0072 -G Ninja 0073 cd $BUILD_ROOT 0074 } 0075 0076 configure_plugins() { 0077 cd $PLUGINS_BUILD 0078 cmake $KRITA_ROOT/3rdparty_plugins \ 0079 -DINSTALL_ROOT=$INSTALL_PREFIX \ 0080 -DEXTERNALS_DOWNLOAD_DIR=$DOWNLOADS_DIR \ 0081 -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \ 0082 -DCMAKE_TOOLCHAIN_FILE=$CMAKE_ANDROID_NDK/build/cmake/android.toolchain.cmake \ 0083 -DANDROID_ABI=$ANDROID_ABI \ 0084 -DANDROID_STL=c++_shared \ 0085 -DANDROID_PLATFORM=$ANDROID_NATIVE_API_LEVEL \ 0086 -DANDROID_SDK_ROOT=$ANDROID_SDK_ROOT \ 0087 -DCMAKE_FIND_ROOT_PATH="$BUILD_ROOT/i;$INSTALL_PREFIX" 0088 cd $BUILD_ROOT 0089 } 0090 0091 PROC_COUNT=`grep processor /proc/cpuinfo | wc -l` 0092 0093 if [ $PROC_COUNT -gt "2" ]; then 0094 let "jobs = ${PROC_COUNT} - 2" 0095 PROC_COUNT=$jobs 0096 fi 0097 0098 build_qt() { 0099 if [[ ! -z $QT_ANDROID && -e $QT_ANDROID/lib/libQt5AndroidExtras_*.so ]]; then 0100 echo "Qt path provided; Skipping Qt build" 0101 return 0 0102 fi 0103 configure_ext 0104 cd $DEPS_BUILD 0105 cmake --build . --config $BUILD_TYPE --target ext_qt -- -j$PROC_COUNT 0106 cd $BUILD_ROOT 0107 } 0108 0109 build_ext() { 0110 if [[ ! -d $QT_ANDROID ]]; then 0111 echoerr "qt libs not found" 0112 echo "Please run -p=qt prior to this" 0113 exit 0114 fi 0115 0116 export PKG_CONFIG_LIBDIR="$BUILD_ROOT/i/lib/pkgconfig" 0117 0118 configure_ext 0119 cd $DEPS_BUILD 0120 # Please do not change the order 0121 cmake --build . --config $BUILD_TYPE --target ext_png -- -j$PROC_COUNT 0122 cmake --build . --config $BUILD_TYPE --target ext_zlib -- -j$PROC_COUNT 0123 cmake --build . --config $BUILD_TYPE --target ext_quazip -- -j$PROC_COUNT 0124 cmake --build . --config $BUILD_TYPE --target ext_lcms2 -- -j$PROC_COUNT 0125 cmake --build . --config $BUILD_TYPE --target ext_expat -- -j$PROC_COUNT 0126 cmake --build . --config $BUILD_TYPE --target ext_exiv2 -- -j$PROC_COUNT 0127 cmake --build . --config $BUILD_TYPE --target ext_gsl -- -j$PROC_COUNT 0128 cmake --build . --config $BUILD_TYPE --target ext_tiff -- -j$PROC_COUNT 0129 cmake --build . --config $BUILD_TYPE --target ext_fftw3 -- -j$PROC_COUNT 0130 cmake --build . --config $BUILD_TYPE --target ext_jpeg -- -j$PROC_COUNT 0131 cmake --build . --config $BUILD_TYPE --target ext_giflib -- -j$PROC_COUNT 0132 cmake --build . --config $BUILD_TYPE --target ext_eigen3 -- -j$PROC_COUNT 0133 cmake --build . --config $BUILD_TYPE --target ext_seexpr -- -j$PROC_COUNT 0134 cmake --build . --config $BUILD_TYPE --target ext_mypaint -- -j$PROC_COUNT 0135 cmake --build . --config $BUILD_TYPE --target ext_webp -- -j$PROC_COUNT 0136 cmake --build . --config $BUILD_TYPE --target ext_libunwindstack-ndk -- -j$PROC_COUNT 0137 cmake --build . --config $BUILD_TYPE --target ext_xsimd -- -j$PROC_COUNT 0138 cmake --build . --config $BUILD_TYPE --target ext_jpegxl -- -j$PROC_COUNT 0139 # cmake --build . --config $BUILD_TYPE --target ext_ocio -- -j$PROC_COUNT 0140 cmake --build . --config $BUILD_TYPE --target ext_freetype -- -j$PROC_COUNT 0141 cmake --build . --config $BUILD_TYPE --target ext_fribidi -- -j$PROC_COUNT 0142 cmake --build . --config $BUILD_TYPE --target ext_unibreak -- -j$PROC_COUNT 0143 cmake --build . --config $BUILD_TYPE --target ext_fontconfig -- -j$PROC_COUNT 0144 cmake --build . --config $BUILD_TYPE --target ext_lager -- -j$PROC_COUNT 0145 0146 cmake --build . --config $BUILD_TYPE --target ext_mlt -- -j$PROC_COUNT 0147 cd $BUILD_ROOT 0148 } 0149 0150 build_plugins() { 0151 if [[ ! -d $QT_ANDROID ]]; then 0152 echoerr "qt libs not found" 0153 echo "Please run -p=qt prior to this" 0154 exit 0155 fi 0156 0157 configure_plugins 0158 cd $PLUGINS_BUILD 0159 # Please do not change the order 0160 cmake --build . --config $BUILD_TYPE --target ext_gmic -- -j$PROC_COUNT 0161 0162 cd $BUILD_ROOT 0163 } 0164 0165 build_boost() { 0166 configure_ext 0167 cd $DEPS_BUILD 0168 cmake --build . --config $BUILD_TYPE --target ext_boost -- -j$PROC_COUNT 0169 cd $BUILD_ROOT 0170 } 0171 0172 build_kf5() { 0173 if [[ ! -d $QT_ANDROID ]]; then 0174 echoerr "qt libs not found" 0175 echo "Please run -p=qt prior to this" 0176 exit 0177 fi 0178 0179 configure_ext 0180 cd $DEPS_BUILD 0181 0182 cmake --build . --config $BUILD_TYPE --target ext_extra_cmake_modules -- -j$PROC_COUNT 0183 cmake --build . --config $BUILD_TYPE --target ext_libintl-lite -- -j$PROC_COUNT 0184 cmake --build . --config $BUILD_TYPE --target ext_kconfig -- -j$PROC_COUNT 0185 cmake --build . --config $BUILD_TYPE --target ext_kwidgetsaddons -- -j$PROC_COUNT 0186 cmake --build . --config $BUILD_TYPE --target ext_kcompletion -- -j$PROC_COUNT 0187 cmake --build . --config $BUILD_TYPE --target ext_kcoreaddons -- -j$PROC_COUNT 0188 cmake --build . --config $BUILD_TYPE --target ext_kguiaddons -- -j$PROC_COUNT 0189 cmake --build . --config $BUILD_TYPE --target ext_ki18n -- -j$PROC_COUNT 0190 cmake --build . --config $BUILD_TYPE --target ext_kitemmodels -- -j$PROC_COUNT 0191 cmake --build . --config $BUILD_TYPE --target ext_kitemviews -- -j$PROC_COUNT 0192 cmake --build . --config $BUILD_TYPE --target ext_kwindowsystem -- -j$PROC_COUNT 0193 0194 cd $BUILD_ROOT 0195 } 0196 0197 build_krita() { 0198 cd $BUILD_ROOT 0199 if [[ $NIGHTLY_BUILD == 1 ]]; then 0200 # to copy files, --aux-mode doesn't seem to work 0201 EXTRA_ARGS="--no-gdbserver" 0202 elif [[ $BUILD_TYPE == "Release" ]]; then 0203 EXTRA_ARGS="--release" 0204 else 0205 EXTRA_ARGS="--no-gdbserver" 0206 fi 0207 # Configure files using cmake 0208 cmake $KRITA_ROOT -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \ 0209 -DKRITA_ENABLE_PCH=off \ 0210 -DDEFINE_NO_DEPRECATED=1 \ 0211 -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ 0212 -DCMAKE_TOOLCHAIN_FILE=$CMAKE_ANDROID_NDK/build/cmake/android.toolchain.cmake \ 0213 -DANDROID_PLATFORM=$ANDROID_NATIVE_API_LEVEL \ 0214 -DBUILD_TESTING=OFF -DKDE4_BUILD_TESTS=OFF \ 0215 -DBoost_NO_BOOST_CMAKE=TRUE \ 0216 -DBoost_NO_SYSTEM_PATHS=TRUE \ 0217 -DTIFF_HAS_PSD_TAGS=TRUE \ 0218 -DTIFF_CAN_WRITE_PSD_TAGS=TRUE \ 0219 -DQTANDROID_EXPORTED_TARGET=krita \ 0220 -DANDROID_APK_DIR=$KRITA_ROOT/packaging/android/apk \ 0221 -DANDROID_STL=c++_shared \ 0222 -DANDROID_ABI=$ANDROID_ABI \ 0223 -DKRITA_3rdparty_LIB_PREFIX="$BUILD_ROOT/i/lib" \ 0224 -DCMAKE_FIND_ROOT_PATH="$BUILD_ROOT/i" \ 0225 -DANDROIDDEPLOYQT_EXTRA_ARGS="$EXTRA_ARGS" 0226 0227 cmake --build . --target install --parallel $PROC_COUNT 0228 } 0229 0230 build_apk() { 0231 cd $BUILD_ROOT 0232 0233 cmake --build . --target create-apk 0234 if [[ $NIGHTLY_BUILD == 1 ]]; then 0235 cd $BUILD_ROOT/krita_build_apk 0236 ./gradlew clean # so binary factory doesn't use the debug files 0237 ./gradlew assembleNightly 0238 0239 cd $BUILD_ROOT 0240 fi 0241 } 0242 0243 # if no arguments are passed 0244 if [[ "$#" == 0 ]]; then 0245 print_usage 0246 exit 0247 fi 0248 0249 for i in "$@" 0250 do 0251 case $i in 0252 -p=*) 0253 PACKAGE="${i#*=}" 0254 shift 0255 ;; 0256 --src=*) 0257 export KRITA_ROOT="${i#*=}" 0258 shift 0259 ;; 0260 --build-type=*) 0261 export BUILD_TYPE="${i#*=}" 0262 ;; 0263 --build-root=*) 0264 export BUILD_ROOT="${i#*=}" 0265 shift 0266 ;; 0267 --qt-path=*) 0268 export QT_ANDROID="${i#*=}" 0269 shift 0270 ;; 0271 --ndk-path=*) 0272 export CMAKE_ANDROID_NDK="${i#*=}" 0273 shift 0274 ;; 0275 --sdk-path=*) 0276 export ANDROID_SDK_ROOT="${i#*=}" 0277 shift 0278 ;; 0279 --api-level=*) 0280 export ANDROID_API_LEVEL="${i#*=}" 0281 shift 0282 ;; 0283 --android-abi=*) 0284 export ANDROID_ABI="${i#*=}" 0285 shift 0286 ;; 0287 --help) 0288 print_usage 0289 exit 0290 ;; 0291 esac 0292 done 0293 0294 if [[ -z $ANDROID_ABI ]]; then 0295 echo "Warning: ANDROID_ABI not specified, using the default one: arm64-v8a" 0296 export ANDROID_ABI=arm64-v8a 0297 fi 0298 0299 if [[ $ANDROID_ABI != "armeabi-v7a" && $ANDROID_ABI != "arm64-v8a" && \ 0300 $ANDROID_ABI != "x86" && $ANDROID_ABI != "x86_64" ]]; then 0301 echoerr "Invalid ABI, please choose among: armeabi-v7a, arm64-v8a, x86, x86_64" 0302 echo "Exiting Now." 0303 exit 0304 fi 0305 0306 if [[ -z $ANDROID_API_LEVEL ]]; then 0307 echo "Warning: ANDROID_API_LEVEL not set, using the default one: 23" 0308 export ANDROID_API_LEVEL=23 0309 fi 0310 0311 if [[ -z $BUILD_ROOT ]]; then 0312 echoerr "Build root not specified" 0313 print_usage 0314 elif [[ ! -d $BUILD_ROOT ]]; then 0315 mkdir $BUILD_ROOT -p 0316 fi 0317 0318 check_exists CMAKE_ANDROID_NDK 0319 check_exists ANDROID_SDK_ROOT 0320 check_exists KRITA_ROOT 0321 0322 # this helps SDK find the NDK, where ever it may be 0323 export ANDROID_NDK_HOME=$CMAKE_ANDROID_NDK 0324 export ANDROID_NATIVE_API_LEVEL=android-$ANDROID_API_LEVEL 0325 export INSTALL_PREFIX=$BUILD_ROOT/krita-android-build 0326 export ANDROID_NDK=$CMAKE_ANDROID_NDK 0327 if [[ -z $QT_ANDROID ]]; then 0328 export QT_ANDROID=$BUILD_ROOT/i 0329 fi 0330 0331 setup_directories 0332 0333 case $PACKAGE in 0334 all) 0335 build_qt 0336 build_kf5 0337 build_ext 0338 build_boost 0339 build_krita 0340 # build_plugins 0341 build_apk 0342 ;; 0343 krita-bin) 0344 build_krita 0345 ;; 0346 apk) 0347 # build_plugins 0348 build_apk 0349 ;; 0350 qt) 0351 build_qt 0352 ;; 0353 3rdparty) 0354 build_ext 0355 ;; 0356 plugins) 0357 build_plugins 0358 ;; 0359 boost) 0360 build_boost 0361 ;; 0362 kf5) 0363 build_qt 0364 build_kf5 0365 ;; 0366 *) 0367 echoerr "Invalid package" 0368 print_usage 0369 ;; 0370 esac 0371