1#!/bin/bash
2
3set -e
4
5TARGET=microblaze-linux-musl
6LINUX_ARCH=microblaze
7
8J=$(expr $(nproc) / 2)
9TOOLCHAIN_INSTALL=/usr/local
10TOOLCHAIN_BIN=${TOOLCHAIN_INSTALL}/bin
11CROSS_SYSROOT=${TOOLCHAIN_INSTALL}/$TARGET/sys-root
12
13export PATH=${TOOLCHAIN_BIN}:$PATH
14
15#
16# Grab all of the source for the toolchain bootstrap.
17#
18
19wget https://ftp.gnu.org/gnu/binutils/binutils-2.37.tar.xz
20wget https://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.xz
21wget https://www.musl-libc.org/releases/musl-1.2.2.tar.gz
22wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.70.tar.xz
23
24tar axf binutils-2.37.tar.xz
25tar axf gcc-11.2.0.tar.xz
26tar axf musl-1.2.2.tar.gz
27tar axf linux-5.10.70.tar.xz
28
29mv binutils-2.37 src-binu
30mv gcc-11.2.0 src-gcc
31mv musl-1.2.2 src-musl
32mv linux-5.10.70 src-linux
33
34mkdir -p bld-hdr bld-binu bld-gcc bld-musl
35mkdir -p ${CROSS_SYSROOT}/usr/include
36
37#
38# Install kernel headers
39#
40
41cd src-linux
42make headers_install ARCH=${LINUX_ARCH} INSTALL_HDR_PATH=${CROSS_SYSROOT}/usr
43cd ..
44
45#
46# Build binutils
47#
48
49cd bld-binu
50../src-binu/configure --disable-werror \
51  --prefix=${TOOLCHAIN_INSTALL} --with-sysroot --target=${TARGET}
52make -j${J}
53make install
54cd ..
55
56#
57# Build gcc, just the compiler so far.
58#
59
60cd bld-gcc
61../src-gcc/configure --disable-werror --disable-shared \
62  --prefix=${TOOLCHAIN_INSTALL} --with-sysroot --target=${TARGET} \
63  --enable-languages=c --disable-libssp --disable-libsanitizer \
64  --disable-libatomic --disable-libgomp --disable-libquadmath
65make -j${J} all-gcc
66make install-gcc
67cd ..
68
69#
70# Build musl.
71# We won't go through the extra step of building shared libraries
72# because we don't actually use them in QEMU docker testing.
73#
74
75cd bld-musl
76../src-musl/configure --prefix=/usr --host=${TARGET} --disable-shared
77make -j${j}
78make install DESTDIR=${CROSS_SYSROOT}
79cd ..
80
81#
82# Go back and build the compiler runtime
83#
84
85cd bld-gcc
86make -j${j}
87make install
88cd ..
89