1bf215546Sopenharmony_ci#!/bin/bash
2bf215546Sopenharmony_ci
3bf215546Sopenharmony_ciarch=$1
4bf215546Sopenharmony_cicross_file="/cross_file-$arch.txt"
5bf215546Sopenharmony_ci/usr/share/meson/debcrossgen --arch $arch -o "$cross_file"
6bf215546Sopenharmony_ci# Explicitly set ccache path for cross compilers
7bf215546Sopenharmony_cised -i "s|/usr/bin/\([^-]*\)-linux-gnu\([^-]*\)-g|/usr/lib/ccache/\\1-linux-gnu\\2-g|g" "$cross_file"
8bf215546Sopenharmony_ciif [ "$arch" = "i386" ]; then
9bf215546Sopenharmony_ci    # Work around a bug in debcrossgen that should be fixed in the next release
10bf215546Sopenharmony_ci    sed -i "s|cpu_family = 'i686'|cpu_family = 'x86'|g" "$cross_file"
11bf215546Sopenharmony_cifi
12bf215546Sopenharmony_ci# Rely on qemu-user being configured in binfmt_misc on the host
13bf215546Sopenharmony_cised -i -e '/\[properties\]/a\' -e "needs_exe_wrapper = False" "$cross_file"
14bf215546Sopenharmony_ci
15bf215546Sopenharmony_ci# Add a line for rustc, which debcrossgen is missing.
16bf215546Sopenharmony_cicc=`sed -n 's|c = .\(.*\).|\1|p' < $cross_file`
17bf215546Sopenharmony_ciif [[ "$arch" = "arm64" ]]; then
18bf215546Sopenharmony_ci    rust_target=aarch64-unknown-linux-gnu
19bf215546Sopenharmony_cielif [[ "$arch" = "armhf" ]]; then
20bf215546Sopenharmony_ci    rust_target=armv7-unknown-linux-gnueabihf
21bf215546Sopenharmony_cielif [[ "$arch" = "i386" ]]; then
22bf215546Sopenharmony_ci    rust_target=i686-unknown-linux-gnu
23bf215546Sopenharmony_cielif [[ "$arch" = "ppc64el" ]]; then
24bf215546Sopenharmony_ci    rust_target=powerpc64le-unknown-linux-gnu
25bf215546Sopenharmony_cielif [[ "$arch" = "s390x" ]]; then
26bf215546Sopenharmony_ci    rust_target=s390x-unknown-linux-gnu
27bf215546Sopenharmony_cielse
28bf215546Sopenharmony_ci    echo "Needs rustc target mapping"
29bf215546Sopenharmony_cifi
30bf215546Sopenharmony_cised -i -e '/\[binaries\]/a\' -e "rust = ['rustc', '--target=$rust_target', '-C', 'linker=$cc']" "$cross_file"
31bf215546Sopenharmony_ci
32bf215546Sopenharmony_ci# Set up cmake cross compile toolchain file for dEQP builds
33bf215546Sopenharmony_citoolchain_file="/toolchain-$arch.cmake"
34bf215546Sopenharmony_ciif [[ "$arch" = "arm64" ]]; then
35bf215546Sopenharmony_ci    GCC_ARCH="aarch64-linux-gnu"
36bf215546Sopenharmony_ci    DE_CPU="DE_CPU_ARM_64"
37bf215546Sopenharmony_ci    CMAKE_ARCH=arm
38bf215546Sopenharmony_cielif [[ "$arch" = "armhf" ]]; then
39bf215546Sopenharmony_ci    GCC_ARCH="arm-linux-gnueabihf"
40bf215546Sopenharmony_ci    DE_CPU="DE_CPU_ARM"
41bf215546Sopenharmony_ci    CMAKE_ARCH=arm
42bf215546Sopenharmony_cifi
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_ciif [[ -n "$GCC_ARCH" ]]; then
45bf215546Sopenharmony_ci    echo "set(CMAKE_SYSTEM_NAME Linux)" > "$toolchain_file"
46bf215546Sopenharmony_ci    echo "set(CMAKE_SYSTEM_PROCESSOR arm)" >> "$toolchain_file"
47bf215546Sopenharmony_ci    echo "set(CMAKE_C_COMPILER /usr/lib/ccache/$GCC_ARCH-gcc)" >> "$toolchain_file"
48bf215546Sopenharmony_ci    echo "set(CMAKE_CXX_COMPILER /usr/lib/ccache/$GCC_ARCH-g++)" >> "$toolchain_file"
49bf215546Sopenharmony_ci    echo "set(ENV{PKG_CONFIG} \"/usr/bin/$GCC_ARCH-pkg-config\")" >> "$toolchain_file"
50bf215546Sopenharmony_ci    echo "set(DE_CPU $DE_CPU)" >> "$toolchain_file"
51bf215546Sopenharmony_cifi
52