forked from openhwgroup/corev-gcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-corev-gcc-tools.sh
318 lines (288 loc) · 11.6 KB
/
build-corev-gcc-tools.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#!/bin/bash
# Build script for the CORE-V GCC and GNU tools.
# Copyright (C) 2020 Embecosm Limited
# Contributor Jessica Mills <[email protected]>
# This file is part of the Embecosm GNU toolchain build system for RISC-V.
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http:https://www.gnu.org/licenses/>.
export ROOT_PREFIX=$(cd ../ && pwd)
export GCC_FOLDER=corev-gcc
export GCC_PREFIX=${ROOT_PREFIX}/${GCC_FOLDER}
export STAGE1_FOLDER=${GCC_FOLDER}-stage1
export STAGE2_FOLDER=${GCC_FOLDER}-stage2
export NEWLIB_FOLDER=riscv-newlib
export NEWLIB_PREFIX=${ROOT_PREFIX}/${NEWLIB_FOLDER}
export BINUTILS_GDB_FOLDER=corev-binutils-gdb
export BINUTILS_GDB_PREFIX=${ROOT_PREFIX}/${BINUTILS_PREFIX}
export BUILD_GCC_FOLDER=build-${GCC_FOLDER}
export BUILD_GCC_PREFIX=${ROOT_PREFIX}/${BUILD_GCC_FOLDER}
export BUILD_BINUTILS_FOLDER=build-${BINUTILS_GDB_FOLDER}
export BUILD_BINUTILS_PREFIX=${ROOT_PREFIX}/${BUILD_BINUTILS_FOLDER}
export INSTALL_FOLDER=toolchain-install
export INSTALL_PREFIX=${ROOT_PREFIX}/${INSTALL_FOLDER}
mkdir -p ${INSTALL_PREFIX}
PARALLEL_JOBS=$(nproc)
DEFAULTARCH=rv32im
DEFAULTABI=ilp32
if [[ $* == *--gcc-stage1* || $* == *--all* ]]; then
if [[ $* == *--debug* ]]; then
export BUILD_STAGE1_PREFIX=${BUILD_GCC_PREFIX}-DEBUG/${STAGE1_FOLDER}
else
export BUILD_STAGE1_PREFIX=${BUILD_GCC_PREFIX}/${STAGE1_FOLDER}
fi
mkdir -p ${GCC_PREFIX}
fi
if [[ $* == *--newlib* || $* == *--all* ]]; then
if [[ $* == *--debug* ]]; then
export BUILD_NEWLIB_PREFIX=${BUILD_GCC_PREFIX}-DEBUG/${NEWLIB_FOLDER}
else
export BUILD_NEWLIB_PREFIX=${BUILD_GCC_PREFIX}/${NEWLIB_FOLDER}
fi
mkdir -p ${GCC_PREFIX}
fi
if [[ $* == *--gcc-stage2* || $* == *--all* ]]; then
if [[ $* == *--debug* ]]; then
export BUILD_STAGE2_PREFIX=${BUILD_GCC_PREFIX}-DEBUG/${STAGE2_FOLDER}
else
export BUILD_STAGE2_PREFIX=${BUILD_GCC_PREFIX}/${STAGE2_FOLDER}
fi
mkdir -p ${GCC_PREFIX}
fi
if [[ $* == *--binutilts-gdb* || $* == *--all* ]]; then
if [[ $* == *--debug* ]]; then
export BUILD_BINGDB_PREFIX=${ROOT_PREFIX}/${BUILD_BINUTILS_FOLDER}-DEBUG
else
export BUILD_BINGDB_PREFIX=${ROOT_PREFIX}/${BUILD_BINUTILS_FOLDER}
fi
fi
installs=(
"riscv32-corev-elf-addr2line"
"riscv32-corev-elf-nm"
"riscv32-corev-elf-ar"
"riscv32-corev-elf-objcopy"
"riscv32-corev-elf-objdump"
"riscv32-corev-elf-ranlib"
"riscv32-corev-elf-c++filt"
"riscv32-corev-elf-readelf"
"riscv32-corev-elf-run"
"riscv32-corev-elf-elfedit"
"riscv32-corev-elf-gdb"
"riscv32-corev-elf-size"
"riscv32-corev-elf-gprof"
"riscv32-corev-elf-strings"
"riscv32-corev-elf-ld"
"riscv32-corev-elf-strip"
"riscv32-corev-elf-ld.bfd"
"riscv32-corev-elf-as"
"riscv32-corev-elf-gcc-ar"
"riscv32-corev-elf-gcc-nm"
"riscv32-corev-elf-gcc-ranlib"
"riscv32-corev-elf-gcov"
"riscv32-corev-elf-gcov-dump"
"riscv32-corev-elf-cpp"
"riscv32-corev-elf-gcov-tool"
"riscv32-corev-elf-gcc"
"riscv32-corev-elf-gcc-7.1.1"
"riscv32-corev-elf-c++"
"riscv32-corev-elf-g++"
)
if [[ $* == *--help* || $* == *-h* ]]; then
echo "Usage: build-corev-gcc-tools.sh [--all] [--binutils-gdb] [--gcc-stage1] [--newlib] [--gcc-stage2] [--clean] [--debug] [--help | -h]"
echo " Builds and installs the PULP tool chain"
echo " Build directory is the peer directory 'build', install directory is the peer directory 'install'"
echo " Generates installation summary - this is the only action if no options are specified"
echo "The options are:"
echo " --all Build all components"
echo " --binutils-gdb Build binutils and GDB"
echo " --gcc-stage1 Build GCC stage 1"
echo " --newlib Build newlib"
echo " --gcc-stage2 Build GCC stage 2"
echo " --clean Remove build directory"
echo " --debug Include debugging CFLAGS"
echo " --help | -h Print this help message and exit"
exit 0
fi
if [[ $* == *--clean* ]]; then
if [[ -d ${BUILD_STAGE1_PREFIX} ]]; then
echo Cleaning... ${BUILD_STAGE1_PREFIX}
rm -rf ${BUILD_STAGE1_PREFIX}
fi
if [[ -d ${BUILD_NEWLIB_PREFIX} ]]; then
echo Cleaning... ${BUILD_NEWLIB_PREFIX}
rm -rf ${BUILD_NEWLIB_PREFIX}
fi
if [[ -d ${BUILD_STAGE2_PREFIX} ]]; then
echo Cleaning... ${BUILD_STAGE2_PREFIX}
rm -rf ${BUILD_STAGE2_PREFIX}
fi
if [[ -d ${BUILD_BINGDB_PREFIX} ]]; then
echo Cleaning... ${BUILD_BINGDB_PREFIX}
rm -rf ${BUILD_BINGDB_PREFIX}
fi
fi
# Binutils-gdb
if [[ $* == *--binutils-gdb* || $* == *--all* ]]; then
mkdir -p ${BUILD_BINGDB_PREFIX}
cd ${BUILD_BINGDB_PREFIX}
../${BINUTILS_GDB_FOLDER}/configure \
--target=riscv32-corev-elf \
--prefix=${INSTALL_PREFIX} \
--disable-werror
#CFLAGS as option for debugging
if [[ $* == *--debug* ]]; then
if ! make CFLAGS="-O0 -ggdb3" -j${PARALLEL_JOBS}; then
echo "The build has failed during binutils-gdb!" >/dev/stderr
exit 1
fi
if ! make CFLAGS="-O0 -ggdb3" install; then
echo "The build has failed during binutils-gdb!" >/dev/stderr
exit 1
fi
else
if ! make -j${PARALLEL_JOBS}; then
echo "The build has failed during binutils-gdb!" >/dev/stderr
exit 1
fi
if ! make install; then
echo "The build has failed during binutils-gdb!" >/dev/stderr
exit 1
fi
fi
fi
# GCC (Stage 1)
if [[ $* == *--gcc-stage1* || $* == *--all* ]]; then
cd ${GCC_PREFIX}
./contrib/download_prerequisites
mkdir -p ${BUILD_STAGE1_PREFIX}
cd ${BUILD_STAGE1_PREFIX}
../../${GCC_FOLDER}/configure \
--with-system-zlib \
--target=riscv32-corev-elf \
--prefix=${INSTALL_PREFIX} \
--with-sysroot=${INSTALL_PREFIX}/riscv32-corev-elf \
--with-newlib \
--without-headers \
--disable-shared \
--enable-languages=c \
--disable-werror \
--disable-libatomic \
--disable-libmudflap \
--disable-libssp \
--disable-quadmath \
--disable-libgomp \
--disable-nls \
--disable-bootstrap \
--enable-multilib \
--with-arch=${DEFAULTARCH} \
--with-abi=${DEFAULTABI}
#CFLAGS as option for debugging
if [[ $* == *--debug* ]]; then
if ! make CFLAGS="-O0 -g3" CXXFLAGS="-O0 -g3" -j${PARALLEL_JOBS}; then
echo "The build has failed during gcc-stage1!" >/dev/stderr
exit 1
fi
if ! make CFLAGS="-O0 -g3" CXXFLAGS="-O0 -g3" install; then
echo "The build has failed during gcc-stage1!" >/dev/stderr
exit 1
fi
else
if ! make -j${PARALLEL_JOBS}; then
echo "The build has failed during gcc-stage1!" >/dev/stderr
exit 1
fi
if ! make install; then
echo "The build has failed during gcc-stage1!" >/dev/stderr
exit 1
fi
fi
fi
# Newlib - need target tools in PATH from now on
if [[ $* == *--newlib* || $* == *--all* ]]; then
PATH=${INSTALL_PREFIX}/bin:${PATH}
mkdir -p ${BUILD_NEWLIB_PREFIX}
cd ${BUILD_NEWLIB_PREFIX}
../../${NEWLIB_FOLDER}/configure \
--target=riscv32-corev-elf \
--prefix=${INSTALL_PREFIX} \
--with-arch=${DEFAULTARCH} \
--with-abi=${DEFAULTABI} \
--enable-multilib
#CFLAGS as option for debugging
if [[ $* == *--debug* ]]; then
if ! make CFLAGS="-O0 -ggdb3" -j${PARALLEL_JOBS}; then
echo "The build has failed during newlib!" >/dev/stderr
exit 1
fi
if ! make CFLAGS="-O0 -ggdb3" install; then
echo "The build has failed during newlib!" >/dev/stderr
exit 1
fi
else
if ! make -j${PARALLEL_JOBS}; then
echo "The build has failed during newlib!" >/dev/stderr
exit 1
fi
if ! make install; then
echo "The build has failed during newlib!" >/dev/stderr
exit 1
fi
fi
fi
# GCC (Stage 2)
if [[ $* == *--gcc-stage2* || $* == *--all* ]]; then
mkdir -p ${BUILD_STAGE2_PREFIX}
cd ${BUILD_STAGE2_PREFIX}
../../${GCC_FOLDER}/configure \
--with-system-zlib \
--target=riscv32-corev-elf \
--prefix=${INSTALL_PREFIX} \
--with-sysroot=${INSTALL_PREFIX}/riscv32-corev-elf \
--with-native-system-header-dir=/include \
--with-newlib \
--disable-shared \
--enable-languages=c,c++ \
--enable-tls \
--disable-werror \
--disable-libmudflap \
--disable-libssp \
--disable-quadmath \
--disable-libgomp \
--disable-nls \
--enable-multilib \
--with-arch=${DEFAULTARCH} \
--with-abi=${DEFAULTABI}
#CFLAGS as option for debugging
if [[ $* == *--debug* ]]; then
if ! make CFLAGS="-O0 -g3" CXXFLAGS="-O0 -g3" -j${PARALLEL_JOBS}; then
echo "The build has failed during gcc-stage2!" >/dev/stderr
exit 1
fi
if ! make CFLAGS="-O0 -g3" CXXFLAGS="-O0 -g3" install; then
echo "The build has failed during gcc-stage2!" >/dev/stderr
exit 1
fi
else
if ! make -j${PARALLEL_JOBS}; then
echo "The build has failed during gcc-stage2!" >/dev/stderr
exit 1
fi
if ! make install; then
echo "The build has failed during gcc-stage2!" >/dev/stderr
exit 1
fi
fi
fi
echo ===== Install summary =====
echo ${INSTALL_PREFIX}/bin/
for install in "${installs[@]}"
do
[ -f ${INSTALL_PREFIX}/bin/${install} ] && echo "${install} ... exists." || echo "${install} ... does not exist."
done