1#!/usr/bin/env bash 2# shellcheck disable=SC2086 # we want word splitting 3 4# When changing this file, you need to bump the following 5# .gitlab-ci/image-tags.yml tags: 6# DEBIAN_BUILD_TAG 7 8set -e 9 10. .gitlab-ci/setup-test-env.sh 11 12set -x 13 14EPHEMERAL=( 15 autoconf 16 rdfind 17 unzip 18) 19 20apt-get install -y --no-remove "${EPHEMERAL[@]}" 21 22# Fetch the NDK and extract just the toolchain we want. 23ndk=$ANDROID_NDK 24curl -L --retry 4 -f --retry-all-errors --retry-delay 60 \ 25 -o $ndk.zip https://dl.google.com/android/repository/$ndk-linux.zip 26unzip -d / $ndk.zip "$ndk/source.properties" "$ndk/build/cmake/*" "$ndk/toolchains/llvm/*" 27rm $ndk.zip 28# Since it was packed as a zip file, symlinks/hardlinks got turned into 29# duplicate files. Turn them into hardlinks to save on container space. 30rdfind -makehardlinks true -makeresultsfile false /${ndk}/ 31# Drop some large tools we won't use in this build. 32find /${ndk}/ -type f \( -iname '*clang-check*' -o -iname '*clang-tidy*' -o -iname '*lldb*' \) -exec rm -f {} \; 33 34sh .gitlab-ci/container/create-android-ndk-pc.sh /$ndk zlib.pc "" "-lz" "1.2.3" $ANDROID_SDK_VERSION 35 36sh .gitlab-ci/container/create-android-cross-file.sh /$ndk x86_64-linux-android x86_64 x86_64 $ANDROID_SDK_VERSION 37sh .gitlab-ci/container/create-android-cross-file.sh /$ndk i686-linux-android x86 x86 $ANDROID_SDK_VERSION 38sh .gitlab-ci/container/create-android-cross-file.sh /$ndk aarch64-linux-android aarch64 armv8 $ANDROID_SDK_VERSION 39sh .gitlab-ci/container/create-android-cross-file.sh /$ndk arm-linux-androideabi arm armv7hl $ANDROID_SDK_VERSION armv7a-linux-androideabi 40 41for arch in \ 42 x86_64-linux-android \ 43 i686-linux-android \ 44 aarch64-linux-android \ 45 arm-linux-androideabi ; do 46 EXTRA_MESON_ARGS="--cross-file=/cross_file-$arch.txt --libdir=lib/$arch -Dnouveau=disabled -Dintel=disabled" \ 47 . .gitlab-ci/container/build-libdrm.sh 48done 49 50rm -rf $LIBDRM_VERSION 51 52export LIBELF_VERSION=libelf-0.8.13 53curl -L --retry 4 -f --retry-all-errors --retry-delay 60 \ 54 -O https://fossies.org/linux/misc/old/$LIBELF_VERSION.tar.gz 55 56# Not 100% sure who runs the mirror above so be extra careful 57if ! echo "4136d7b4c04df68b686570afa26988ac ${LIBELF_VERSION}.tar.gz" | md5sum -c -; then 58 echo "Checksum failed" 59 exit 1 60fi 61 62tar -xf ${LIBELF_VERSION}.tar.gz 63cd $LIBELF_VERSION 64 65# Work around a bug in the original configure not enabling __LIBELF64. 66autoreconf 67 68for arch in \ 69 x86_64-linux-android \ 70 i686-linux-android \ 71 aarch64-linux-android \ 72 arm-linux-androideabi ; do 73 74 ccarch=${arch} 75 if [ "${arch}" == 'arm-linux-androideabi' ] 76 then 77 ccarch=armv7a-linux-androideabi 78 fi 79 80 export CC=/${ndk}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar 81 export CC=/${ndk}/toolchains/llvm/prebuilt/linux-x86_64/bin/${ccarch}${ANDROID_SDK_VERSION}-clang 82 export CXX=/${ndk}/toolchains/llvm/prebuilt/linux-x86_64/bin/${ccarch}${ANDROID_SDK_VERSION}-clang++ 83 export LD=/${ndk}/toolchains/llvm/prebuilt/linux-x86_64/bin/${arch}-ld 84 export RANLIB=/${ndk}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ranlib 85 86 # The configure script doesn't know about android, but doesn't really use the host anyway it 87 # seems 88 ./configure --host=x86_64-linux-gnu --disable-nls --disable-shared \ 89 --libdir=/usr/local/lib/${arch} 90 make install 91 make distclean 92 93 unset CC 94 unset CC 95 unset CXX 96 unset LD 97 unset RANLIB 98done 99 100cd .. 101rm -rf $LIBELF_VERSION 102 103 104# Build LLVM libraries for Android only if necessary, uploading a copy to S3 105# to avoid rebuilding it in a future run if the version does not change. 106bash .gitlab-ci/container/build-android-x86_64-llvm.sh 107 108apt-get purge -y "${EPHEMERAL[@]}" 109