Merge branch 'g-clear-pointer-no-side-effects' into 'master'
[glib.git] / .gitlab-ci / android-setup-env.sh
blob510056f667b76a751d1c457f4ba43951b43d74a2
1 #!/bin/bash
4 # Copyright 2018 Collabora ltd.
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 # Author: Xavier Claessens <xavier.claessens@collabora.com>
22 set -e
24 arch=$1
25 api=$2
26 toolchain_path=$(pwd)/android-toolchain-$arch-$api
27 prefix_path=$(pwd)/android-$arch-$api
29 # Create standalone toolchains
30 $ANDROID_NDK_PATH/build/tools/make_standalone_toolchain.py --arch $arch --api $api --install-dir $toolchain_path
32 target_host=aarch64-linux-android
33 export AR=$target_host-ar
34 export AS=$target_host-clang
35 export CC=$target_host-clang
36 export CXX=$target_host-clang++
37 export LD=$target_host-ld
38 export STRIP=$target_host-strip
39 export PATH=$PATH:$toolchain_path/bin
41 # Cross build libiconv when using API level <= 28.
42 # Newer Android has it in its libc already.
43 if [ "$api" -lt "28" ]; then
44 wget --quiet http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
45 echo "1233fe3ca09341b53354fd4bfe342a7589181145a1232c9919583a8c9979636855839049f3406f253a9d9829908816bb71fd6d34dd544ba290d6f04251376b1a libiconv-1.15.tar.gz" | sha512sum -c
46 tar xzf libiconv-1.15.tar.gz
47 pushd libiconv-1.15
48 ./configure --host=$target_host --prefix=$prefix_path --libdir=$prefix_path/lib64
49 make
50 make install
51 popd
52 rm libiconv-1.15.tar.gz
53 rm -r libiconv-1.15
56 # Cross build libffi
57 wget --quiet https://github.com/libffi/libffi/releases/download/v3.3-rc0/libffi-3.3-rc0.tar.gz
58 echo "e6e695d32cd6eb7d65983f32986fccdfc786a593d2ea18af30ce741f58cfa1eb264b1a8d09df5084cb916001aea15187b005c2149a0620a44397a4453b6137d4 libffi-3.3-rc0.tar.gz" | sha512sum -c
59 tar xzf libffi-3.3-rc0.tar.gz
60 pushd libffi-3.3-rc0
61 ./configure --host=$target_host --prefix=$prefix_path --libdir=$prefix_path/lib64
62 make
63 make install
64 popd
65 rm libffi-3.3-rc0.tar.gz
66 rm -r libffi-3.3-rc0
68 # Create a pkg-config wrapper that won't pick fedora libraries
69 mkdir -p $prefix_path/bin
70 export PKG_CONFIG=$prefix_path/bin/pkg-config
71 cat > $PKG_CONFIG <<- EOM
72 #!/bin/sh
73 SYSROOT=${prefix_path}
74 export PKG_CONFIG_DIR=
75 export PKG_CONFIG_LIBDIR=\${SYSROOT}/lib64/pkgconfig
76 export PKG_CONFIG_SYSROOT_DIR=\${SYSROOT}
77 exec pkg-config "\$@"
78 EOM
79 chmod +x $PKG_CONFIG
81 # Create a cross file that can be passed to meson
82 cat > cross_file_android_${arch}_${api}.txt <<- EOM
83 [host_machine]
84 system = 'android'
85 cpu_family = 'arm64'
86 cpu = 'arm64'
87 endian = 'little'
89 [properties]
90 c_args = ['-I${prefix_path}/include']
91 c_link_args = ['-L${prefix_path}/lib64',
92 '-fuse-ld=gold']
94 [binaries]
95 c = '${toolchain_path}/bin/${CC}'
96 cpp = '${toolchain_path}/bin/${CXX}'
97 ar = '${toolchain_path}/bin/${AR}'
98 strip = '${toolchain_path}/bin/${STRIP}'
99 pkgconfig = '${PKG_CONFIG}'