-
Notifications
You must be signed in to change notification settings - Fork 11
/
build-toolchain
executable file
·279 lines (252 loc) · 7.78 KB
/
build-toolchain
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
#!/bin/bash
export TOOLCHAIN_ROOT="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
export INSTALL_FOLDER=$TOOLCHAIN_ROOT/INSTALL
export BUILD_FOLDER=$TOOLCHAIN_ROOT/BUILD
export LOG_FOLDER=$TOOLCHAIN_ROOT/LOG
export SCRIPTS=$TOOLCHAIN_ROOT/build_scripts
export PATH=$INSTALL_FOLDER/bin:$PATH
PARALLEL_JOBS=$(nproc)
#PARALLEL_JOBS=1
if [[ $* == *--help* || $* == *-h* ]]; then
echo "Usage: build-toolchain [--all] [--binutils-mcs] [--binutils] [--gcc-stage1] [--newlib] [--gcc-stage2] [--clean-all] [--clean-binutils-mcs] [--clean-binutils] [--clean-gcc-stage1] [--clean-newlib] [--clean-gcc-stage2] [--help | -h]"
exit 0
fi
if [[ $* == *--clean-all* ]]; then
rm -fr $BUILD_FOLDER
rm -fr $LOG_FOLDER
fi
### Binutils MCS
if [[ $* == *--clean-binutils-mcs* ]]; then
rm -fr $BUILD_FOLDER/binutils-mcs
fi
if [[ $* == *--binutils-mcs* || $* == *--all* ]]; then
export BINUTILS_SRC_FOLDER=$TOOLCHAIN_ROOT/tricore-binutils-gdb
mkdir -p $BUILD_FOLDER/binutils-mcs
mkdir -p $LOG_FOLDER
cd $BUILD_FOLDER/binutils-mcs
if ! $BINUTILS_SRC_FOLDER/configure \
LDFLAGS='-static' \
--target=mcs-elf \
--program-prefix=mcs-elf- \
--disable-threads \
--enable-nls \
--disable-itcl \
--disable-tk \
--disable-tcl \
--disable-winsup \
--disable-gdbtk \
--disable-libgui \
--disable-rda \
--disable-sid \
--disable-sim \
--disable-gdb \
--disable-newlib \
--disable-libgloss \
--disable-test-suite \
--enable-checking=release \
--with-gnu-ld \
--with-gnu-as \
--prefix=$INSTALL_FOLDER \
--disable-werror; then
echo "The build has failed during configure of binutils-mcs"
exit 1
fi
make --output-sync -j${PARALLEL_JOBS} LDFLAGS="-static" 2>&1 | tee $LOG_FOLDER/binutils_mcs.log
if test ${PIPESTATUS[0]} -ne 0; then
echo "The build has failed during make of binutils-mcs"
exit 1
fi
make install 2>&1 | tee -a $LOG_FOLDER/binutils_mcs.log
if test ${PIPESTATUS[0]} -ne 0; then
echo "The build has failed during install of binutils-mcs"
exit 1
fi
fi
### Binutils
if [[ $* == *--clean-binutils* ]]; then
rm -fr $BUILD_FOLDER/binutils
fi
if [[ $* == *--binutils* || $* == *--all* ]]; then
export BINUTILS_SRC_FOLDER=$TOOLCHAIN_ROOT/tricore-binutils-gdb
mkdir -p $BUILD_FOLDER/binutils
mkdir -p $LOG_FOLDER
cd $BUILD_FOLDER/binutils
if ! $BINUTILS_SRC_FOLDER/configure \
LDFLAGS='-static' \
--target=tricore-elf \
--enable-targets=mcs-elf \
--program-prefix=tricore-elf- \
--disable-threads \
--enable-nls \
--disable-itcl \
--disable-tk \
--disable-tcl \
--disable-winsup \
--disable-gdbtk \
--disable-libgui \
--disable-rda \
--disable-sid \
--disable-sim \
--disable-gdb \
--disable-newlib \
--disable-libgloss \
--disable-test-suite \
--enable-checking=release \
--with-gnu-ld \
--with-gnu-as \
--prefix=$INSTALL_FOLDER \
--disable-werror; then
echo "The build has failed during configure of binutils"
exit 1
fi
make --output-sync -j${PARALLEL_JOBS} LDFLAGS="-static" 2>&1 | tee $LOG_FOLDER/binutils.log
if test ${PIPESTATUS[0]} -ne 0; then
echo "The build has failed during make of binutils"
exit 1
fi
make install 2>&1 | tee -a $LOG_FOLDER/binutils.log
if test ${PIPESTATUS[0]} -ne 0; then
echo "The build has failed during install of binutils"
exit 1
fi
fi
### GCC stage1
if [[ $* == *--clean-gcc-stage1* ]]; then
rm -fr $BUILD_FOLDER/gcc-stage1
fi
if [[ $* == *--gcc-stage1* || $* == *--all* ]]; then
export GCC_SRC_FOLDER=$TOOLCHAIN_ROOT/tricore-gcc
mkdir -p $BUILD_FOLDER/gcc-stage1
mkdir -p $LOG_FOLDER
cd $BUILD_FOLDER/gcc-stage1
if ! $GCC_SRC_FOLDER/configure \
LDFLAGS='-static' \
CFLAGS_FOR_TARGET='-g -O2 -gdwarf-3' \
CXXFLAGS_FOR_TARGET='-g -O2 -gdwarf-3' \
--target=tricore-elf \
--enable-lib32 \
--disable-lib64 \
--prefix=$INSTALL_FOLDER \
--enable-languages=c,c++ \
--enable-libstdcxx-debug-flags='-gdwarf-3 -g -O0 -D_GLIBCXX_ASSERTIONS' \
--enable-c99 \
--enable-long-long \
--enable-checking \
--enable-nls \
--enable-static \
--disable-threads \
--disable-shared \
--with-headers=yes \
--with-newlib=yes \
--enable-mingw-wildcard \
--disable-libstdcxx-pch \
--enable-newlib-elix-level=3 \
--enable-newlib-io-long-long \
--disable-newlib-supplied-syscalls \
--disable-libssp \
--disable-test-suite; then
echo "The build has failed during configure of gcc (stage 1)"
exit 1
fi
make -j${PARALLEL_JOBS} all-gcc 2>&1 | tee $LOG_FOLDER/gcc_stage1.log
if test ${PIPESTATUS[0]} -ne 0; then
echo "The build has failed during make of gcc (stage 1)"
exit 1
fi
make install-gcc 2>&1 | tee -a $LOG_FOLDER/gcc_stage1.log
if test ${PIPESTATUS[0]} -ne 0; then
echo "The build has failed during install of gcc (stage 1)"
exit 1
fi
fi
### Newlib
if [[ $* == *--clean-newlib* ]]; then
rm -fr $BUILD_FOLDER/newlib
fi
if [[ $* == *--newlib* || $* == *--all* ]]; then
export NEWLIB_SRC_FOLDER=$TOOLCHAIN_ROOT/tricore-newlib-cygwin
mkdir -p $BUILD_FOLDER/newlib
mkdir -p $LOG_FOLDER
cd $BUILD_FOLDER/newlib
export CC_FOR_TARGET=$INSTALL_FOLDER/bin/tricore-elf-gcc
export CXX_FOR_TARGET=$INSTALL_FOLDER/bin/tricore-elf-c++
export GCC_FOR_TARGET=$INSTALL_FOLDER/bin/tricore-elf-gcc
export AR_FOR_TARGET=$INSTALL_FOLDER/bin/tricore-elf-ar
export AS_FOR_TARGET=$INSTALL_FOLDER/bin/tricore-elf-as
export LD_FOR_TARGET=$INSTALL_FOLDER/bin/tricore-elf-ld
export NM_FOR_TARGET=$INSTALL_FOLDER/bin/tricore-elf-nm
export OBJDUMP_FOR_TARGET=$INSTALL_FOLDER/bin/tricore-elf-objdump
export RANLIB_FOR_TARGET=$INSTALL_FOLDER/bin/tricore-elf-ranlib
export STRIP_FOR_TARGET=$INSTALL_FOLDER/bin/tricore-elf-strip
export READELF_FOR_TARGET=$INSTALL_FOLDER/bin/tricore-elf-readelf
if ! CFLAGS_FOR_TARGET='-g -gdwarf-3 -O2 -ffunction-sections -mfast-div -fno-common' \
CXXFLAGS_FOR_TARGET='-g -gdwarf-3 -O2 -ffunction-sections -mfast-div -fno-common' \
$NEWLIB_SRC_FOLDER/configure \
--target=tricore-elf \
--host=i686-w64-mingw32 \
--build=i686-pc-mingw32 \
--prefix=$INSTALL_FOLDER; then
echo "The build has failed during configure of newlib"
exit 1
fi
make -j${PARALLEL_JOBS} LDFLAGS="-static" all 2>&1 | tee $LOG_FOLDER/newlib.log
if test ${PIPESTATUS[0]} -ne 0; then
echo "The build has failed during make of newlib"
fi
make install 2>&1 | tee -a $LOG_FOLDER/newlib.log
if test ${PIPESTATUS[0]} -ne 0; then
echo "The build has failed during install of newlib"
exit 1
fi
fi
### GCC stage2
if [[ $* == *--clean-gcc-stage2* ]]; then
rm -fr $BUILD_FOLDER/gcc-stage2
fi
if [[ $* == *--gcc-stage2* || $* == *--all* ]]; then
export GCC_SRC_FOLDER=$TOOLCHAIN_ROOT/tricore-gcc
mkdir -p $BUILD_FOLDER/gcc-stage2
mkdir -p $LOG_FOLDER
cd $BUILD_FOLDER/gcc-stage2
if ! $GCC_SRC_FOLDER/configure \
LDFLAGS='-static' \
CFLAGS_FOR_TARGET='-g -gdwarf-3 -O2 -ffast-math -ffunction-sections -mfast-div -fno-common -mno-eabi-bitfield-limit' \
CPPFLAGS_FOR_TARGET='-g -O2 -gdwarf-3 -ffast-math -ffunction-sections -mfast-div -fno-common -mno-eabi-bitfield-limit' \
--target=tricore-elf \
--enable-lib32 \
--disable-lib64 \
--prefix=$INSTALL_FOLDER \
--enable-languages=c,c++ \
--enable-libstdcxx-debug-flags='-gdwarf-3 -g -O0 -D_GLIBCXX_ASSERTIONS' \
--enable-c99 \
--enable-long-long \
--enable-checking \
--enable-nls \
--enable-static \
--disable-threads \
--disable-shared \
--with-headers=yes \
--with-gnu-ld \
--with-gnu-as \
--with-newlib=yes \
--enable-mingw-wildcard \
--disable-libstdcxx-pch \
--enable-newlib-elix-level=3 \
--enable-newlib-io-long-long \
--disable-newlib-supplied-syscalls \
--disable-libssp \
--disable-test-suite; then
echo "The build has failed during configure of gcc (stage 2)"
exit 1
fi
make -j${PARALLEL_JOBS} all 2>&1 | tee $LOG_FOLDER/gcc_stage2.log
if test ${PIPESTATUS[0]} -ne 0; then
echo "The build has failed during make of gcc (stage 2)"
exit 1
fi
make install 2>&1 | tee -a $LOG_FOLDER/gcc_stage2.log
if test ${PIPESTATUS[0]} -ne 0; then
echo "The build has failed during install of gcc (stage 2)"
exit 1
fi
fi