ci-build-android.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/bash -e
  2. # NOTE: this code is mostly copied from minetest_android_deps
  3. # <https://github.com/minetest/minetest_android_deps>
  4. png_ver=1.6.40
  5. jpeg_ver=3.0.1
  6. download () {
  7. get_tar_archive libpng "https://download.sourceforge.net/libpng/libpng-${png_ver}.tar.gz"
  8. get_tar_archive libjpeg "https://download.sourceforge.net/libjpeg-turbo/libjpeg-turbo-${jpeg_ver}.tar.gz"
  9. }
  10. build () {
  11. # Build libjpg and libpng first because Irrlicht needs them
  12. mkdir -p libpng
  13. pushd libpng
  14. $srcdir/libpng/configure --host=$CROSS_PREFIX
  15. make && make DESTDIR=$PWD install
  16. popd
  17. mkdir -p libjpeg
  18. pushd libjpeg
  19. cmake $srcdir/libjpeg "${CMAKE_FLAGS[@]}" -DENABLE_SHARED=OFF
  20. make && make DESTDIR=$PWD install
  21. popd
  22. local libpng=$PWD/libpng/usr/local/lib/libpng.a
  23. local libjpeg=$(echo $PWD/libjpeg/opt/libjpeg-turbo/lib*/libjpeg.a)
  24. cmake $srcdir/irrlicht "${CMAKE_FLAGS[@]}" \
  25. -DBUILD_SHARED_LIBS=OFF \
  26. -DPNG_LIBRARY=$libpng \
  27. -DPNG_PNG_INCLUDE_DIR=$(dirname "$libpng")/../include \
  28. -DJPEG_LIBRARY=$libjpeg \
  29. -DJPEG_INCLUDE_DIR=$(dirname "$libjpeg")/../include
  30. make
  31. cp -p lib/Android/libIrrlichtMt.a $libpng $libjpeg $pkgdir/
  32. cp -a $srcdir/irrlicht/include $pkgdir/include
  33. cp -a $srcdir/irrlicht/media/Shaders $pkgdir/Shaders
  34. }
  35. get_tar_archive () {
  36. # $1: folder to extract to, $2: URL
  37. local filename="${2##*/}"
  38. [ -d "$1" ] && return 0
  39. wget -c "$2" -O "$filename"
  40. mkdir -p "$1"
  41. tar -xaf "$filename" -C "$1" --strip-components=1
  42. rm "$filename"
  43. }
  44. _setup_toolchain () {
  45. local toolchain=$(echo "$ANDROID_NDK"/toolchains/llvm/prebuilt/*)
  46. if [ ! -d "$toolchain" ]; then
  47. echo "Android NDK path not specified or incorrect"; return 1
  48. fi
  49. export PATH="$toolchain/bin:$ANDROID_NDK:$PATH"
  50. unset CFLAGS CPPFLAGS CXXFLAGS
  51. TARGET_ABI="$1"
  52. API=21
  53. if [ "$TARGET_ABI" == armeabi-v7a ]; then
  54. CROSS_PREFIX=armv7a-linux-androideabi
  55. CFLAGS="-mthumb"
  56. CXXFLAGS="-mthumb"
  57. elif [ "$TARGET_ABI" == arm64-v8a ]; then
  58. CROSS_PREFIX=aarch64-linux-android
  59. elif [ "$TARGET_ABI" == x86 ]; then
  60. CROSS_PREFIX=i686-linux-android
  61. CFLAGS="-mssse3 -mfpmath=sse"
  62. CXXFLAGS="-mssse3 -mfpmath=sse"
  63. elif [ "$TARGET_ABI" == x86_64 ]; then
  64. CROSS_PREFIX=x86_64-linux-android
  65. else
  66. echo "Invalid ABI given"; return 1
  67. fi
  68. export CC=$CROSS_PREFIX$API-clang
  69. export CXX=$CROSS_PREFIX$API-clang++
  70. export AR=llvm-ar
  71. export RANLIB=llvm-ranlib
  72. export CFLAGS="-fPIC ${CFLAGS}"
  73. export CXXFLAGS="-fPIC ${CXXFLAGS}"
  74. CMAKE_FLAGS=(
  75. "-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake"
  76. "-DANDROID_ABI=$TARGET_ABI" "-DANDROID_NATIVE_API_LEVEL=$API"
  77. "-DCMAKE_BUILD_TYPE=Release"
  78. )
  79. # make sure pkg-config doesn't interfere
  80. export PKG_CONFIG=/bin/false
  81. export MAKEFLAGS="-j$(nproc)"
  82. }
  83. _run_build () {
  84. local abi=$1
  85. irrdir=$PWD
  86. mkdir -p $RUNNER_TEMP/src
  87. cd $RUNNER_TEMP/src
  88. srcdir=$PWD
  89. [ -d irrlicht ] || ln -s $irrdir irrlicht
  90. download
  91. builddir=$RUNNER_TEMP/build/irrlicht-$abi
  92. pkgdir=$RUNNER_TEMP/pkg/$abi/Irrlicht
  93. rm -rf "$pkgdir"
  94. mkdir -p "$builddir" "$pkgdir"
  95. cd "$builddir"
  96. build
  97. }
  98. if [ $# -lt 1 ]; then
  99. echo "Usage: ci-build-android.sh <ABI>"
  100. exit 1
  101. fi
  102. _setup_toolchain $1
  103. _run_build $1