-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcc.build
executable file
·312 lines (271 loc) · 8.03 KB
/
gcc.build
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
#!/bin/bash
# Written by Uwe Hermann <[email protected]>, released as public domain.
# Modified by Piotr Esden-Tempski <[email protected]>, released as public domain.
# Modified by Benjamin Lesage <[email protected]>, released as public domain.
# Original repository: https://github.com/esden/summon-arm-toolchain
# Stop if any command fails
set -e
##############################################################################
# Settings section
# You probably want to customize those
##############################################################################
TARGET=arm-elf
PREFIX=$(pwd)/gcc-${TARGET} # Install location of your final toolchain
DEPS_PREFIX=$(pwd)/build/lib_install
# Set to 1 to be quieter while running
QUIET=0
##############################################################################
# Version and download url settings section
##############################################################################
GCCVERSION=4.5.1
GCC=gcc-${GCCVERSION}
GCCURL=http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.gz
BINUTILS=binutils-2.20.1
NEWLIB=newlib-1.18.0
GDB=gdb-7.3.1
GMP=gmp-5.0.1
MPFR=mpfr-3.0.0
MPC=mpc-0.8.2
LIBELF=libelf-0.8.13
##############################################################################
# Flags section
##############################################################################
CPUS=$(getconf _NPROCESSORS_ONLN)
PARALLEL=-j$((CPUS + 1))
echo "${CPUS} cpu's detected running make with '${PARALLEL}' flag"
GDBFLAGS=
BINUTILFLAGS=
GCCFLAGS=
MAKEFLAGS=${PARALLEL}
TARFLAGS=v
if [ ${QUIET} != 0 ]; then
TARFLAGS=
MAKEFLAGS="${MAKEFLAGS} -s"
fi
SUMMON_DIR=$(pwd)
SOURCES=${SUMMON_DIR}/sources
STAMPS=${SUMMON_DIR}/stamps
export PATH="${PREFIX}/bin:${PATH}"
export LD_LIBRARY_PATH="${DEPS_PREFIX}/lib:${PREFIX}/lib:${LD_LIBRARY_PATH}"
export LD_RUN_PATH="${DEPS_PREFIX}/lib:${PREFIX}/lib:${LD_RUN_PATH}"
export LD_FLAGS="${LD_FLAGS} -static"
export LD_FLAGS="${LD_FLAGS} -L${DEPS_PREFIX} -L${PREFIX}/lib"
##############################################################################
# Tool section
##############################################################################
TAR=tar
##############################################################################
# OS and Tooldetection section
# Detects which tools and flags to use
##############################################################################
case "$(uname)" in
Linux)
echo "Found Linux OS."
;;
Darwin)
echo "Found Darwin OS."
#exit 0
;;
*)
echo "Found unknown OS. Aborting!"
exit 1
;;
esac
##############################################################################
# Building section
# You probably don't have to touch anything after this
##############################################################################
# Fetch a versioned file from a URL
function fetch {
if [ ! -e ${STAMPS}/$1.fetch ]; then
log "Downloading $1 sources..."
wget -c $2
touch ${STAMPS}/$1.fetch
fi
}
# Log a message out to the console
function log {
echo "******************************************************************"
echo "* $*"
echo "******************************************************************"
}
# Unpack an archive
function unpack {
log Unpacking $*
# Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
case ${ARCHIVE} in
*.bz2)
echo "archive type bz2"
TYPE=j
;;
*.gz)
echo "archive type gz"
TYPE=z
;;
*)
echo "Unknown archive type of $1"
echo ${ARCHIVE}
exit 1
;;
esac
${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
}
# Install a build
function install {
log $1
${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
}
mkdir -p ${STAMPS} ${SOURCES}
cd ${SOURCES}
fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
fetch ${GCC} ${GCCURL}
fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
fetch ${GMP} ftp://ftp.gmplib.org/pub/${GMP}/${GMP}.tar.bz2
fetch ${MPFR} http://www.mpfr.org/${MPFR}/${MPFR}.tar.bz2
fetch ${MPC} http://www.multiprecision.org/mpc/download/${MPC}.tar.gz
fetch ${LIBELF} http://www.mr511.de/software/${LIBELF}.tar.gz
cd ${SUMMON_DIR}
if [ ! -e build/temp ]; then
mkdir -p build/temp
fi
if [ ! -e ${STAMPS}/${LIBELF}.build ]; then
cd build
unpack ${LIBELF}
cd temp
log "Configuring ${LIBELF}"
../${LIBELF}/configure --prefix=${DEPS_PREFIX} --disable-shared --enable-static
make ${MAKEFLAGS}
install ${LIBELF} install
cd ..
log "Cleaning up ${LIBELF}"
rm -rf temp/* ${LIBELF}
cd ..
touch ${STAMPS}/${LIBELF}.build
fi
if [ ! -e ${STAMPS}/${GMP}.build ]; then
cd build
unpack ${GMP}
cd temp
log "Configuring ${GMP}"
../${GMP}/configure --prefix=${DEPS_PREFIX} --disable-shared --enable-static
make ${MAKEFLAGS}
make ${MAKEFLAGS} check
install ${GMP} install
cd ..
log "Cleaning up ${GMP}"
rm -rf temp/* ${GMP}
cd ..
touch ${STAMPS}/${GMP}.build
fi
if [ ! -e ${STAMPS}/${MPFR}.build ]; then
cd build
unpack ${MPFR}
cd temp
log "Configuring ${MPFR}"
../${MPFR}/configure --prefix=${DEPS_PREFIX} --with-gmp=${DEPS_PREFIX} --disable-shared --enable-static
make ${MAKEFLAGS}
install ${MPFR} install
cd ..
log "Cleaning up ${MPFR}"
rm -rf temp/* ${MPFR}
cd ..
touch ${STAMPS}/${MPFR}.build
fi
if [ ! -e ${STAMPS}/${MPC}.build ]; then
cd build
unpack ${MPC}
cd temp
log "Configuring ${MPC}"
../${MPC}/configure --prefix=${DEPS_PREFIX} --with-gmp=${DEPS_PREFIX} --disable-shared --enable-static
make ${MAKEFLAGS}
install ${MPC} install
cd ..
log "Cleaning up ${MPC}"
rm -rf temp/* ${MPC}
cd ..
touch ${STAMPS}/${MPC}.build
fi
if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
cd build
unpack ${BINUTILS}
cd temp
log "Configuring ${BINUTILS}"
../${BINUTILS}/configure --target=${TARGET} \
--prefix=${PREFIX} \
--disable-shared \
--enable-interwork \
--disable-multilib \
--with-gnu-as \
--with-gnu-ld \
--disable-nls \
--disable-werror \
${BINUTILFLAGS}
log "Building ${BINUTILS}"
make ${MAKEFLAGS}
install ${BINUTILS} install
cd ..
log "Cleaning up ${BINUTILS}"
rm -rf temp/* ${BINUTILS}
cd ..
touch ${STAMPS}/${BINUTILS}.build
fi
if [ ! -e ${STAMPS}/${GCC}-${NEWLIB}.build ]; then
cd build
unpack ${GCC}
unpack ${NEWLIB}
log "Adding newlib symlink to gcc"
ln -fs `pwd`/${NEWLIB}/newlib ${GCC}
log "Adding libgloss symlink to gcc"
ln -fs `pwd`/${NEWLIB}/libgloss ${GCC}
cd temp
log "Configuring ${GCC} and ${NEWLIB}"
../${GCC}/configure --target=${TARGET} \
--prefix=${PREFIX} \
--with-mpfr=${DEPS_PREFIX} \
--with-gmp=${DEPS_PREFIX} \
--with-mpc=${DEPS_PREFIX} \
--enable-interwork \
--disable-multilib \
--enable-languages="c,c++" \
--with-newlib \
--with-gnu-as \
--with-gnu-ld \
--disable-nls \
--disable-shared \
--disable-threads \
--with-headers=newlib/libc/include \
--disable-werror \
--with-system-zlib \
--disable-newlib-supplied-syscalls \
${GCCFLAGS}
log "Building ${GCC} and ${NEWLIB}"
make ${MAKEFLAGS}
install ${GCC} install
cd ..
log "Cleaning up ${GCC} and ${NEWLIB}"
rm -rf temp/* ${GCC} ${NEWLIB}
cd ..
touch ${STAMPS}/${GCC}-${NEWLIB}.build
fi
if [ ! -e ${STAMPS}/${GDB}.build ]; then
cd build
unpack ${GDB}
cd temp
log "Configuring ${GDB}"
../${GDB}/configure --target=${TARGET} \
--prefix=${PREFIX} \
--enable-interwork \
--enable-multilib \
--disable-werror \
${GDBFLAGS}
log "Building ${GDB}"
make ${MAKEFLAGS}
install ${GDB} install
cd ..
log "Cleaning up ${GDB}"
rm -rf temp/* ${GDB}
cd ..
touch ${STAMPS}/${GDB}.build
fi