-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathbuild_linux_toolchain.sh
executable file
·144 lines (117 loc) · 4.04 KB
/
build_linux_toolchain.sh
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
TARGET=riscv32-linux
PREFIX=`pwd`/nds32le-linux-glibc-v5d
ARCH=rv32imafdcxandes
ABI=ilp32d
CPU=andes-25-series
XLEN=32
BUILD=`pwd`/build-nds32le-linux-glibc-v5d
SYSROOT=${PREFIX}/sysroot
TARGET_CC=${PREFIX}/bin/${TARGET}-gcc
TARGET_CXX=${PREFIX}/bin/${TARGET}-g++
BINUTILS_SRC=`pwd`/binutils
GDB_SRC=`pwd`/gdb
GCC_SRC=`pwd`/gcc
GLIBC_SRC=`pwd`/glibc
KERNEL_HDR_SRC=`pwd`/linux-headers
MAKE_PARALLEL=-j`nproc`
#MAKE_PARALLEL=-j12
mkdir ${BUILD}
# 00. Prepare
export PATH=${PREFIX}/bin:$PATH
cd ${GCC_SRC}
./contrib/download_prerequisites
cd -
cd ${BUILD}
# 01. Binutils
mkdir -p binutils
cd binutils
${BINUTILS_SRC}/configure \
--target=${TARGET} --prefix=${PREFIX} --with-arch=${ARCH} \
--with-curses --disable-nls --disable-tui --with-python=no --with-lzma=no \
--with-expat=yes --with-guile=no --enable-plugins --disable-werror \
--enable-deterministic-archives --disable-gdb --disable-sim \
--with-sysroot=${SYSROOT}
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make ${MAKE_PARALLEL} all
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make install
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
cd ..
# 02. Install kernel header files.
mkdir -p ${SYSROOT}/usr/
cp -a ${KERNEL_HDR_SRC}/include ${SYSROOT}/usr/
# 03. Bootstrap GCC
mkdir -p bootstrap-gcc
cd bootstrap-gcc
${GCC_SRC}/configure \
--target=${TARGET} --prefix=${PREFIX} --with-tune=${CPU} --target=${TARGET} \
--disable-nls --enable-languages=c,c++ --enable-lto \
--enable-gp-insn-relax-default=yes \
--with-arch=${ARCH} --with-abi=${ABI} --disable-werror \
--disable-multilib --enable-shared --enable-tls \
--disable-libsanitizer --enable-checking=release \
CFLAGS_FOR_TARGET="-O2 -g -mstrict-align" \
CXXFLAGS_FOR_TARGET="-O2 -g -mstrict-align" \
--without-headers --disable-shared --disable-threads \
--disable-libatomic --disable-libmudflap --disable-libssp \
--disable-libquadmath --disable-libgomp
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make ${MAKE_PARALLEL} inhibit-libc=true all-gcc
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make inhibit-libc=true install-gcc
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make ${MAKE_PARALLEL} inhibit-libc=true all-target-libgcc
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make inhibit-libc=true install-gcc install-target-libgcc
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
cd ..
# 04. glibc
mkdir -p glibc
cd glibc
${GLIBC_SRC}/configure --prefix=/usr --host=${TARGET} \
--prefix=/usr --disable-werror --enable-shared --enable-obsolete-rpc \
--enable-kernel=3.0.0 --with-headers=${SYSROOT}/usr/include \
--with-arch=${ARCH} --with-abi=${ABI} \
CC=${TARGET_CC} CXX=${TARGET_CXX} CFLAGS="-O2 -g"
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make ${MAKE_PARALLEL}
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make install install_root=${SYSROOT}
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
cd ..
# 05. Final GCC
mkdir -p final-gcc
cd final-gcc
${GCC_SRC}/configure \
--target=${TARGET} --prefix=${PREFIX} --with-tune=${CPU} --target=${TARGET} \
--disable-nls --enable-languages=c,c++ --enable-lto \
--enable-gp-insn-relax-default=yes \
--with-arch=${ARCH} --with-abi=${ABI} --disable-werror \
--disable-multilib --enable-shared --enable-tls \
--with-sysroot=${SYSROOT} \
--enable-checking=release \
CFLAGS_FOR_TARGET="-O2 -g -mstrict-align" \
CXXFLAGS_FOR_TARGET="-O2 -g -mstrict-align"
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make ${MAKE_PARALLEL} all
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make install
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
cd ..
# 6. GDB
mkdir -p gdb
cd gdb
${GDB_SRC}/configure \
--target=${TARGET} --prefix=${PREFIX} --with-arch=${ARCH} \
--with-curses --disable-nls --enable-tui --with-python=no \
--with-lzma=no --with-expat=yes --with-guile=no \
--disable-werror --disable-sim \
--disable-binutils --disable-ld --disable-gas --disable-gprof \
CFLAGS="-std=gnu99"
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make ${MAKE_PARALLEL} all
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make install
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
cd ..
cp -r ${PREFIX}/${TARGET}/lib/* ${SYSROOT}/lib${XLEN}/${ABI}/