build_x86.sh
9.62 KB
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
#!/usr/bin/env bash
# directory to download source files and store intermediates
[[ -z $TARGET ]] && TARGET=i586-none-elf
[[ -z $TMP_DIR ]] && TMP_DIR=/var/tmp/RIOT-toolchain-${USER}
[[ -z $BUILDDIR ]] && BUILDDIR=${TMP_DIR}/${TARGET}
[[ -z $PREFIX ]] && PREFIX=${PWD}/toolchain/${TARGET}
[[ -z $MAKE_THREADS ]] && MAKE_THREADS=
PATCHDIR=$(readlink -e "$(dirname $0)/patches")
NEWLIB_VER=2.2.0.20150623
NEWLIB_ARCHIVE=newlib-${NEWLIB_VER}.tar.gz
NEWLIB_MD5=5cf6cd9ded91bca10c9f0a22a9da8e02
NEWLIB_CONFIGURE_FLAGS=(
--target=${TARGET}
--prefix=${PREFIX}
--with-gmp=${PREFIX}
--with-mpfr=${PREFIX}
--with-mpc=${PREFIX}
--enable-interwork
--enable-multilib
--enable-target-optspace
--disable-newlib-supplied-syscalls
--disable-newlib-reent-small
--enable-newlib-io-long-long
--enable-newlib-io-float
--enable-newlib-io-pos-args
--enable-newlib-io-c99-formats
--enable-newlib-multithread
)
NEWLIB_PATCHES=(
newlib-2.2.0.20150623-RIOT-i586-none-elf.patch
)
NEWLIB_TARGET_CFLAGS=(
-DREENTRANT_SYSCALLS_PROVIDED
-DMALLOC_PROVIDED
-DSIGNAL_PROVIDED
-DPREFER_SIZE_OVER_SPEED
-ggdb3
-Os
-fomit-frame-pointer
-ffunction-sections
-fdata-sections
)
GCC_VER=4.8.5
GCC_ARCHIVE=gcc-${GCC_VER}.tar.bz2
GCC_MD5=80d2c2982a3392bb0b89673ff136e223
GCC_CONFIGURE_FLAGS=(
--target=${TARGET}
--prefix=${PREFIX}
--with-gmp=${PREFIX}
--with-mpfr=${PREFIX}
--with-mpc=${PREFIX}
--enable-interwork
--enable-multilib
--enable-languages="c,c++"
--with-newlib
--disable-libssp
--with-headers=${BUILDDIR}/newlib-${NEWLIB_VER}/newlib/libc/include
--enable-obsolete
--enable-target-optspace
--disable-nls
)
BINUTILS_VER=2.25
BINUTILS_ARCHIVE=binutils-${BINUTILS_VER}.tar.bz2
BINUTILS_MD5=d9f3303f802a5b6b0bb73a335ab89d66
BINUTILS_CONFIGURE_FLAGS=(
--prefix=${PREFIX}
--enable-interwork
--enable-multilib
--disable-nls
)
GDB_VER=7.9.1
GDB_ARCHIVE=gdb-${GDB_VER}.tar.xz
GDB_MD5=35374c77a70884eb430c97061053a36e
GDB_CONFIGURE_FLAGS=(
--target=${TARGET}
--prefix=${PREFIX}
--with-gmp=${PREFIX}
--with-mpfr=${PREFIX}
--with-mpc=${PREFIX}
--enable-interwork
--enable-multilib
--disable-nls
)
GMP_VER=5.1.3
GMP_ARCHIVE=gmp-${GMP_VER}.tar.xz
GMP_MD5=e5fe367801ff067b923d1e6a126448aa
GMP_CONFIGURE_FLAGS=(
--prefix=${PREFIX}
--enable-cxx
--disable-nls
)
MPFR_VER=3.1.2
MPFR_ARCHIVE=mpfr-${MPFR_VER}.tar.xz
MPFR_MD5=e3d203d188b8fe60bb6578dd3152e05c
MPFR_CONFIGURE_FLAGS=(
--prefix=${PREFIX}
--with-gmp=${PREFIX}
--disable-nls
)
MPC_VER=1.0.2
MPC_ARCHIVE=mpc-${MPC_VER}.tar.gz
MPC_MD5=68fadff3358fb3e7976c7a398a0af4c3
MPC_CONFIGURE_FLAGS=(
--prefix=${PREFIX}
--with-gmp=${PREFIX}
--with-mpfr=${PREFIX}
--disable-nls
)
DOWNLOADER=wget
DOWNLOADER_OPTS="-nv -c"
SPACE_NEEDED=3264960
build_binutils() {
cd ${BUILDDIR}
echo
[[ -e .binutils_built ]] && return
local TARGETS=(${TARGET} i386-efi-pe)
for i in 0 1; do
echo "Building binutils (${BINUTILS_VER}) for ${TARGETS[$i]} ..."
rm -rf binutils-${TARGETS[$i]}-build &&
mkdir -p binutils-${TARGETS[$i]}-build &&
cd binutils-${TARGETS[$i]}-build &&
../binutils-${BINUTILS_VER}/configure "${BINUTILS_CONFIGURE_FLAGS[@]}" --target=${TARGETS[$i]} --enable-targets=${TARGETS[$i]},${TARGETS[1-$i]} &&
make ${MAKE_THREADS} all &&
make install &&
cd ${BUILDDIR} ||
return $?
done
date -uIns > .binutils_built
}
build_gcc() {
cd ${BUILDDIR}
echo
echo "Building gcc (${GCC_VER}) ..."
[[ -e .gcc_built ]] && return
rm -rf gcc-build && mkdir -p gcc-build && cd gcc-build &&
../gcc-${GCC_VER}/configure "${GCC_CONFIGURE_FLAGS[@]}" &&
make ${MAKE_THREADS} all &&
make install &&
cd ${BUILDDIR} &&
date -uIns > .gcc_built
}
build_newlib() {
cd ${BUILDDIR}
echo
echo "Building newlib (${NEWLIB_VER}) ..."
[[ -e .newlib_built ]] && return
rm -rf newlib-build && mkdir -p newlib-build && cd newlib-build &&
CFLAGS="${NEWLIB_TARGET_CFLAGS[*]}" \
CXXFLAGS="${NEWLIB_TARGET_CFLAGS[*]}" \
CFLAGS_FOR_TARGET="${NEWLIB_TARGET_CFLAGS[*]}" \
CXXFLAGS_FOR_TARGET="${NEWLIB_TARGET_CFLAGS[*]}" \
../newlib-${NEWLIB_VER}/configure "${NEWLIB_CONFIGURE_FLAGS[@]}" &&
sed -i ./Makefile -e '/C\(XX\)\?FLAGS_FOR_TARGET = -g /d' &&
make ${MAKE_THREADS} all &&
make install &&
cd ${BUILDDIR} &&
date -uIns > .newlib_built
}
build_gdb() {
cd ${BUILDDIR}
echo
echo "Building gdb (${GDB_VER}) ..."
[[ -e .gdb_built ]] && return
rm -rf gdb-build && mkdir -p gdb-build && cd gdb-build &&
../gdb-${GDB_VER}/configure "${GDB_CONFIGURE_FLAGS[@]}" &&
make ${MAKE_THREADS} all CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0" &&
make install &&
cd ${BUILDDIR} &&
date -uIns > .gdb_built
}
build_gmp() {
cd ${BUILDDIR}
echo
echo "Building gmp (${GMP_VER}) ..."
[[ -e .gmp_built ]] && return
rm -rf gmp-build && mkdir -p gmp-build && cd gmp-build &&
../gmp-${GMP_VER}/configure "${GMP_CONFIGURE_FLAGS[@]}" &&
make ${MAKE_THREADS} all &&
make install &&
cd ${BUILDDIR} &&
date -uIns > .gmp_built
}
build_mpfr() {
cd ${BUILDDIR}
echo
echo "Building mpfr (${MPFR_VER}) ..."
[[ -e .mpfr_built ]] && return
rm -rf mpfr-build && mkdir -p mpfr-build && cd mpfr-build &&
../mpfr-${MPFR_VER}/configure "${MPFR_CONFIGURE_FLAGS[@]}" &&
make ${MAKE_THREADS} all &&
make install &&
cd ${BUILDDIR} &&
date -uIns > .mpfr_built
}
build_mpc() {
cd ${BUILDDIR}
echo
echo "Building mpc (${MPC_VER}) ..."
[[ -e .mpc_built ]] && return
rm -rf mpc-build && mkdir -p mpc-build && cd mpc-build &&
../mpc-${MPC_VER}/configure "${MPC_CONFIGURE_FLAGS[@]}" &&
make ${MAKE_THREADS} all &&
make install &&
cd ${BUILDDIR} &&
date -uIns > .mpc_built
}
clean() {
echo
echo "Cleaning up..."
for F in binutils gcc newlib gdb gmp mpfr mpc; do
rm -rf ./.${F}_extracted ./.${F}_built ./${F}_build || return $?
done
}
export PATH=$PATH:${PREFIX}/bin
download() {
echo
echo "Downloading TAR files."
download_file ftp://ftp.cs.tu-berlin.de/pub/gnu/binutils ${BINUTILS_ARCHIVE} ${BINUTILS_MD5} &&
download_file ftp://ftp.cs.tu-berlin.de/pub/gnu/gcc/gcc-${GCC_VER} ${GCC_ARCHIVE} ${GCC_MD5} &&
download_file ftp://ftp.cs.tu-berlin.de/pub/gnu/gdb ${GDB_ARCHIVE} ${GDB_MD5} &&
download_file ftp://ftp.cs.tu-berlin.de/pub/gnu/gmp ${GMP_ARCHIVE} ${GMP_MD5} &&
download_file ftp://ftp.cs.tu-berlin.de/pub/gnu/mpfr ${MPFR_ARCHIVE} ${MPFR_MD5} &&
download_file ftp://ftp.cs.tu-berlin.de/pub/gnu/mpc ${MPC_ARCHIVE} ${MPC_MD5} &&
download_file ftp://sources.redhat.com/pub/newlib ${NEWLIB_ARCHIVE} ${NEWLIB_MD5}
}
extract() {
echo
echo "Extracting TAR files."
if [[ ! -x ./binutils-${BINUTILS_VER}/configure ]]; then
tar axf ${TMP_DIR}/${BINUTILS_ARCHIVE} || return $?
fi
if [[ ! -x ./gcc-${GCC_VER}/configure ]]; then
tar axf ${TMP_DIR}/${GCC_ARCHIVE} || return $?
fi
if [[ ! -x ./gdb-${GDB_VER}/configure ]]; then
tar axf ${TMP_DIR}/${GDB_ARCHIVE} || return $?
fi
if [[ ! -x ./gmp-${GMP_VER}/configure ]]; then
tar axf ${TMP_DIR}/${GMP_ARCHIVE} || return $?
fi
if [[ ! -x ./mpfr-${MPFR_VER}/configure ]]; then
tar axf ${TMP_DIR}/${MPFR_ARCHIVE} || return $?
fi
if [[ ! -x ./mpc-${MPC_VER}/configure ]]; then
tar axf ${TMP_DIR}/${MPC_ARCHIVE} || return $?
fi
if [[ ! -x ./newlib-${NEWLIB_VER}/configure ]]; then
tar axf ${TMP_DIR}/${NEWLIB_ARCHIVE} &&
for (( I=0; I < ${#NEWLIB_PATCHES[@]}; I+=1 )); do
echo "Applying Newlib patch ${NEWLIB_PATCHES[$I]}"
for (( P=0; P < 4; P+=1 )); do
patch -p${P} --ignore-whitespace --dry-run -f < "${PATCHDIR}/${NEWLIB_PATCHES[$I]}" 2>&1 > /dev/null || continue
patch -p${P} --ignore-whitespace -f < "${PATCHDIR}/${NEWLIB_PATCHES[$I]}" || return $?
break
done
done
fi
}
download_file() {
echo "Downloading ${1}/${2}..."
cd ${TMP_DIR} &&
${DOWNLOADER} ${DOWNLOADER_OPTS} $1/$2 &&
echo -n "Checking MD5 of " &&
echo "${3} ${2}" | md5sum -c - &&
cd ${BUILDDIR}
}
check_space() {
echo
echo "Checking disk space in ${TMP_DIR}"
FREETMP=$(df ${BUILDDIR} | awk '{ if (NR == 2) print $4}')
if [[ $FREETMP -lt $SPACE_NEEDED ]]; then
echo "Not enough available space in ${TMP_DIR}."
echo "Minimum ${SPACE_NEEDED} free bytes required."
return 1
fi
}
all() {
echo
echo "Starting in ${BUILDDIR}. Installing to ${PREFIX}."
check_space &&
download &&
extract &&
build_binutils &&
build_gmp &&
build_mpfr &&
build_mpc &&
build_gcc &&
build_newlib &&
build_gdb &&
echo &&
echo 'Success!' &&
echo "Insert \"export PATH=${PREFIX}/bin:\$PATH\" to your .bashrc"
}
usage() {
echo "usage: ${0} [all | download | extract | clean | build_[binutils|gcc|newlib|gdb|gmp|mpfr|mpc]]"
echo "example: ${0} all"
echo ""
echo "Builds a(n) \"${TARGET}\" toolchain,"
echo "installs into \"${PREFIX}\", and"
echo "uses \"${TMP_DIR}\" as temp."
echo ""
echo "Use PREFIX=... and TMP_DIR=... to change these directories."
echo "Use TARGET=... to change the target (affects PREFIX)."
echo ""
echo "Run like \"MAKE_THREADS=-j$(nproc) ${0} all\" to speed up on multicore systems."
}
if [[ -z $1 ]]; then
usage
exit 1
fi
mkdir -p ${PREFIX} &&
mkdir -p ${TMP_DIR} &&
mkdir -p ${BUILDDIR} &&
cd ${BUILDDIR} &&
for arg; do
${arg} || exit $?
done