Merge remote-tracking branch 'remotes/dgilbert-gitlab/tags/pull-migration-20210726a...
[qemu/armbru.git] / tests / docker / dockerfiles / debian-hexagon-cross.docker.d / build-toolchain.sh
blob19b1c9f83e11b23e4181aebaa64945d142f36157
1 #!/bin/bash
3 set -e
5 BASE=$(readlink -f ${PWD})
7 TOOLCHAIN_INSTALL=$(readlink -f "$TOOLCHAIN_INSTALL")
8 ROOTFS=$(readlink -f "$ROOTFS")
10 TOOLCHAIN_BIN=${TOOLCHAIN_INSTALL}/bin
11 HEX_SYSROOT=${TOOLCHAIN_INSTALL}/hexagon-unknown-linux-musl
12 HEX_TOOLS_TARGET_BASE=${HEX_SYSROOT}/usr
14 function cdp() {
15 DIR="$1"
16 mkdir -p "$DIR"
17 cd "$DIR"
20 function fetch() {
21 DIR="$1"
22 URL="$2"
23 TEMP="$(readlink -f "$PWD/tmp.tar.gz")"
24 wget --quiet "$URL" -O "$TEMP"
25 cdp "$DIR"
26 tar xaf "$TEMP" --strip-components=1
27 rm "$TEMP"
28 cd -
31 build_llvm_clang() {
32 fetch "$BASE/llvm-project" "$LLVM_URL"
33 cdp "$BASE/build-llvm"
35 cmake -G Ninja \
36 -DCMAKE_BUILD_TYPE=Release \
37 -DCMAKE_INSTALL_PREFIX=${TOOLCHAIN_INSTALL} \
38 -DLLVM_ENABLE_LLD=ON \
39 -DLLVM_TARGETS_TO_BUILD="Hexagon" \
40 -DLLVM_ENABLE_PROJECTS="clang;lld" \
41 "$BASE/llvm-project/llvm"
42 ninja all install
43 cd ${TOOLCHAIN_BIN}
44 ln -sf clang hexagon-unknown-linux-musl-clang
45 ln -sf clang++ hexagon-unknown-linux-musl-clang++
46 ln -sf llvm-ar hexagon-unknown-linux-musl-ar
47 ln -sf llvm-objdump hexagon-unknown-linux-musl-objdump
48 ln -sf llvm-objcopy hexagon-unknown-linux-musl-objcopy
49 ln -sf llvm-readelf hexagon-unknown-linux-musl-readelf
50 ln -sf llvm-ranlib hexagon-unknown-linux-musl-ranlib
52 # workaround for now:
53 cat <<EOF > hexagon-unknown-linux-musl.cfg
54 -G0 --sysroot=${HEX_SYSROOT}
55 EOF
58 build_clang_rt() {
59 cdp "$BASE/build-clang_rt"
60 cmake -G Ninja \
61 -DCMAKE_BUILD_TYPE=Release \
62 -DLLVM_CONFIG_PATH="$BASE/build-llvm/bin/llvm-config" \
63 -DCMAKE_ASM_FLAGS="-G0 -mlong-calls -fno-pic --target=hexagon-unknown-linux-musl " \
64 -DCMAKE_SYSTEM_NAME=Linux \
65 -DCMAKE_C_COMPILER="${TOOLCHAIN_BIN}/hexagon-unknown-linux-musl-clang" \
66 -DCMAKE_ASM_COMPILER="${TOOLCHAIN_BIN}/hexagon-unknown-linux-musl-clang" \
67 -DCMAKE_INSTALL_PREFIX=${HEX_TOOLS_TARGET_BASE} \
68 -DCMAKE_CROSSCOMPILING=ON \
69 -DCMAKE_C_COMPILER_FORCED=ON \
70 -DCMAKE_CXX_COMPILER_FORCED=ON \
71 -DCOMPILER_RT_BUILD_BUILTINS=ON \
72 -DCOMPILER_RT_BUILTINS_ENABLE_PIC=OFF \
73 -DCMAKE_SIZEOF_VOID_P=4 \
74 -DCOMPILER_RT_OS_DIR= \
75 -DCAN_TARGET_hexagon=1 \
76 -DCAN_TARGET_x86_64=0 \
77 -DCOMPILER_RT_SUPPORTED_ARCH=hexagon \
78 -DLLVM_ENABLE_PROJECTS="compiler-rt" \
79 "$BASE/llvm-project/compiler-rt"
80 ninja install-compiler-rt
83 build_musl_headers() {
84 fetch "$BASE/musl" "$MUSL_URL"
85 cd "$BASE/musl"
86 make clean
87 CC=${TOOLCHAIN_BIN}/hexagon-unknown-linux-musl-clang \
88 CROSS_COMPILE=hexagon-unknown-linux-musl \
89 LIBCC=${HEX_TOOLS_TARGET_BASE}/lib/libclang_rt.builtins-hexagon.a \
90 CROSS_CFLAGS="-G0 -O0 -mv65 -fno-builtin -fno-rounding-math --target=hexagon-unknown-linux-musl" \
91 ./configure --target=hexagon --prefix=${HEX_TOOLS_TARGET_BASE}
92 PATH=${TOOLCHAIN_BIN}:$PATH make CROSS_COMPILE= install-headers
94 cd ${HEX_SYSROOT}/..
95 ln -sf hexagon-unknown-linux-musl hexagon
98 build_kernel_headers() {
99 fetch "$BASE/linux" "$LINUX_URL"
100 mkdir -p "$BASE/build-linux"
101 cd "$BASE/linux"
102 make O=../build-linux ARCH=hexagon \
103 KBUILD_CFLAGS_KERNEL="-mlong-calls" \
104 CC=${TOOLCHAIN_BIN}/hexagon-unknown-linux-musl-clang \
105 LD=${TOOLCHAIN_BIN}/ld.lld \
106 KBUILD_VERBOSE=1 comet_defconfig
107 make mrproper
109 cd "$BASE/build-linux"
110 make \
111 ARCH=hexagon \
112 CC=${TOOLCHAIN_BIN}/clang \
113 INSTALL_HDR_PATH=${HEX_TOOLS_TARGET_BASE} \
114 V=1 \
115 headers_install
118 build_musl() {
119 cd "$BASE/musl"
120 make clean
121 CROSS_COMPILE=hexagon-unknown-linux-musl- \
122 AR=llvm-ar \
123 RANLIB=llvm-ranlib \
124 STRIP=llvm-strip \
125 CC=clang \
126 LIBCC=${HEX_TOOLS_TARGET_BASE}/lib/libclang_rt.builtins-hexagon.a \
127 CFLAGS="-G0 -O0 -mv65 -fno-builtin -fno-rounding-math --target=hexagon-unknown-linux-musl" \
128 ./configure --target=hexagon --prefix=${HEX_TOOLS_TARGET_BASE}
129 PATH=${TOOLCHAIN_BIN}/:$PATH make CROSS_COMPILE= install
130 cd ${HEX_TOOLS_TARGET_BASE}/lib
131 ln -sf libc.so ld-musl-hexagon.so
132 ln -sf ld-musl-hexagon.so ld-musl-hexagon.so.1
133 cdp ${HEX_TOOLS_TARGET_BASE}/../lib
134 ln -sf ../usr/lib/ld-musl-hexagon.so.1
137 build_llvm_clang
138 build_kernel_headers
139 build_musl_headers
140 build_clang_rt
141 build_musl