aboutsummaryrefslogtreecommitdiff
path: root/tests/docker/dockerfiles/debian-nios2-cross.d/build-toolchain.sh
blob: ba3c9d8affacd6591ac8f804d91e1ae30e3e7554 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash

set -e

TARGET=nios2-linux-gnu
LINUX_ARCH=nios2

J=$(expr $(nproc) / 2)
TOOLCHAIN_INSTALL=/usr/local
TOOLCHAIN_BIN=${TOOLCHAIN_INSTALL}/bin
CROSS_SYSROOT=${TOOLCHAIN_INSTALL}/$TARGET/sys-root

export PATH=${TOOLCHAIN_BIN}:$PATH

#
# Grab all of the source for the toolchain bootstrap.
#

wget https://ftp.gnu.org/gnu/binutils/binutils-2.37.tar.xz
wget https://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.xz
wget https://ftp.gnu.org/gnu/glibc/glibc-2.34.tar.xz
wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.70.tar.xz

tar axf binutils-2.37.tar.xz
tar axf gcc-11.2.0.tar.xz
tar axf glibc-2.34.tar.xz
tar axf linux-5.10.70.tar.xz

mv binutils-2.37 src-binu
mv gcc-11.2.0 src-gcc
mv glibc-2.34 src-glibc
mv linux-5.10.70 src-linux

mkdir -p bld-hdr bld-binu bld-gcc bld-glibc
mkdir -p ${CROSS_SYSROOT}/usr/include

#
# Install kernel and glibc headers
#

cd src-linux
make headers_install ARCH=${LINUX_ARCH} INSTALL_HDR_PATH=${CROSS_SYSROOT}/usr
cd ..

cd bld-hdr
../src-glibc/configure --prefix=/usr --host=${TARGET}
make install-headers DESTDIR=${CROSS_SYSROOT}
touch ${CROSS_SYSROOT}/usr/include/gnu/stubs.h
cd ..

#
# Build binutils
#

cd bld-binu
../src-binu/configure --disable-werror \
  --prefix=${TOOLCHAIN_INSTALL} --with-sysroot --target=${TARGET}
make -j${J}
make install
cd ..

#
# Build gcc, without shared libraries, because we do not yet
# have a shared libc against which to link.
#

cd bld-gcc
../src-gcc/configure --disable-werror --disable-shared \
  --prefix=${TOOLCHAIN_INSTALL} --with-sysroot --target=${TARGET} \
  --enable-languages=c --disable-libssp --disable-libsanitizer \
  --disable-libatomic --disable-libgomp --disable-libquadmath
make -j${J}
make install
cd ..

#
# Build glibc
# There are a few random things that use c++ but we didn't build that
# cross-compiler.  We can get away without them.  Disable CXX so that
# glibc doesn't try to use the host c++ compiler.
#

cd bld-glibc
CXX=false ../src-glibc/configure --prefix=/usr --host=${TARGET}
make -j${j}
make install DESTDIR=${CROSS_SYSROOT}
cd ..