build-toolchain.sh (4144B)
1#!/bin/bash 2 3set -e 4 5BASE=$(readlink -f ${PWD}) 6 7TOOLCHAIN_INSTALL=$(readlink -f "$TOOLCHAIN_INSTALL") 8ROOTFS=$(readlink -f "$ROOTFS") 9 10TOOLCHAIN_BIN=${TOOLCHAIN_INSTALL}/bin 11HEX_SYSROOT=${TOOLCHAIN_INSTALL}/hexagon-unknown-linux-musl 12HEX_TOOLS_TARGET_BASE=${HEX_SYSROOT}/usr 13 14function cdp() { 15 DIR="$1" 16 mkdir -p "$DIR" 17 cd "$DIR" 18} 19 20function 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 - 29} 30 31build_llvm_clang() { 32 fetch "$BASE/llvm-project" "$LLVM_URL" 33 cdp "$BASE/build-llvm" 34 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 51 52 # workaround for now: 53 cat <<EOF > hexagon-unknown-linux-musl.cfg 54-G0 --sysroot=${HEX_SYSROOT} 55EOF 56} 57 58build_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 81} 82 83build_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 93 94 cd ${HEX_SYSROOT}/.. 95 ln -sf hexagon-unknown-linux-musl hexagon 96} 97 98build_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 108 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 116} 117 118build_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 135} 136 137build_llvm_clang 138build_kernel_headers 139build_musl_headers 140build_clang_rt 141build_musl