source: mainline/tools/toolchain.sh@ c5bff3c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c5bff3c was 2385952, checked in by Martin Decky <martin@…>, 13 years ago

bump GCC to 4.7.0 (no longer distributed in separate packages)
switch to ARM EABI (the original ABI is obsolete now)

  • Property mode set to 100755
File size: 10.7 KB
Line 
1#! /bin/bash
2
3#
4# Copyright (c) 2009 Martin Decky
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10#
11# - Redistributions of source code must retain the above copyright
12# notice, this list of conditions and the following disclaimer.
13# - Redistributions in binary form must reproduce the above copyright
14# notice, this list of conditions and the following disclaimer in the
15# documentation and/or other materials provided with the distribution.
16# - The name of the author may not be used to endorse or promote products
17# derived from this software without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29#
30
31GMP_MAIN=<<EOF
32#define GCC_GMP_VERSION_NUM(a, b, c) \
33 (((a) << 16L) | ((b) << 8) | (c))
34
35#define GCC_GMP_VERSION \
36 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
37
38#if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,2)
39 choke me
40#endif
41EOF
42
43MPFR_MAIN=<<EOF
44#if MPFR_VERSION < MPFR_VERSION_NUM(2, 4, 2)
45choke me
46 #endif
47EOF
48
49MPC_MAIN=<<EOF
50#if MPC_VERSION < MPC_VERSION_NUM(0, 8, 1)
51 choke me
52#endif
53EOF
54
55BINUTILS_VERSION="2.22"
56BINUTILS_RELEASE=""
57GCC_VERSION="4.7.0"
58GDB_VERSION="7.4"
59
60BASEDIR="`pwd`"
61BINUTILS="binutils-${BINUTILS_VERSION}${BINUTILS_RELEASE}.tar.bz2"
62GCC="gcc-${GCC_VERSION}.tar.bz2"
63GDB="gdb-${GDB_VERSION}.tar.bz2"
64
65#
66# Check if the library described in the argument
67# exists and has acceptable version.
68#
69check_dependency() {
70 DEPENDENCY="$1"
71 HEADER="$2"
72 BODY="$3"
73
74 FNAME="/tmp/conftest-$$"
75
76 echo "#include ${HEADER}" > "${FNAME}.c"
77 echo >> "${FNAME}.c"
78 echo "int main()" >> "${FNAME}.c"
79 echo "{" >> "${FNAME}.c"
80 echo "${BODY}" >> "${FNAME}.c"
81 echo " return 0;" >> "${FNAME}.c"
82 echo "}" >> "${FNAME}.c"
83
84 cc -c -o "${FNAME}.o" "${FNAME}.c" 2> "${FNAME}.log"
85 RC="$?"
86
87 if [ "$RC" -ne "0" ] ; then
88 echo " ${DEPENDENCY} not found, too old or compiler error."
89 echo " Please recheck manually the source file \"${FNAME}.c\"."
90 echo " The compilation of the toolchain is probably going to fail,"
91 echo " you have been warned."
92 echo
93 echo " ===== Compiler output ====="
94 cat "${FNAME}.log"
95 echo " ==========================="
96 echo
97 else
98 echo " ${DEPENDENCY} found"
99 rm -f "${FNAME}.log" "${FNAME}.o" "${FNAME}.c"
100 fi
101}
102
103check_dependecies() {
104 echo ">>> Basic dependency check"
105 check_dependency "GMP" "<gmp.h>" "${GMP_MAIN}"
106 check_dependency "MPFR" "<mpfr.h>" "${MPFR_MAIN}"
107 check_dependency "MPC" "<mpc.h>" "${MPC_MAIN}"
108 echo
109}
110
111check_error() {
112 if [ "$1" -ne "0" ]; then
113 echo
114 echo "Script failed: $2"
115
116 exit 1
117 fi
118}
119
120check_md5() {
121 FILE="$1"
122 SUM="$2"
123
124 COMPUTED="`md5sum "${FILE}" | cut -d' ' -f1`"
125 if [ "${SUM}" != "${COMPUTED}" ] ; then
126 echo
127 echo "Checksum of ${FILE} does not match."
128
129 exit 2
130 fi
131}
132
133show_usage() {
134 echo "Cross-compiler toolchain build script"
135 echo
136 echo "Syntax:"
137 echo " $0 <platform>"
138 echo
139 echo "Possible target platforms are:"
140 echo " amd64 AMD64 (x86-64, x64)"
141 echo " arm32 ARM"
142 echo " ia32 IA-32 (x86, i386)"
143 echo " ia64 IA-64 (Itanium)"
144 echo " mips32 MIPS little-endian 32b"
145 echo " mips32eb MIPS big-endian 32b"
146 echo " mips64 MIPS little-endian 64b"
147 echo " ppc32 32-bit PowerPC"
148 echo " ppc64 64-bit PowerPC"
149 echo " sparc64 SPARC V9"
150 echo " all build all targets"
151 echo " parallel same as 'all', but in parallel"
152 echo
153 echo "The toolchain will be installed to the directory specified by"
154 echo "the CROSS_PREFIX environment variable. If the variable is not"
155 echo "defined, /usr/local/cross will be used by default."
156 echo
157
158 exit 3
159}
160
161change_title() {
162 echo -en "\e]0;$1\a"
163}
164
165show_countdown() {
166 TM="$1"
167
168 if [ "${TM}" -eq 0 ] ; then
169 echo
170 return 0
171 fi
172
173 echo -n "${TM} "
174 change_title "${TM}"
175 sleep 1
176
177 TM="`expr "${TM}" - 1`"
178 show_countdown "${TM}"
179}
180
181show_dependencies() {
182 echo "IMPORTANT NOTICE:"
183 echo
184 echo "For a successful compilation and use of the cross-compiler"
185 echo "toolchain you need at least the following dependencies."
186 echo
187 echo "Please make sure that the dependencies are present in your"
188 echo "system. Otherwise the compilation process might fail after"
189 echo "a few seconds or minutes."
190 echo
191 echo " - SED, AWK, Flex, Bison, gzip, bzip2, Bourne Shell"
192 echo " - gettext, zlib, Texinfo, libelf, libgomp"
193 echo " - GNU Multiple Precision Library (GMP)"
194 echo " - GNU Make"
195 echo " - GNU tar"
196 echo " - GNU Coreutils"
197 echo " - GNU Sharutils"
198 echo " - MPFR"
199 echo " - MPC"
200 echo " - Parma Polyhedra Library (PPL)"
201 echo " - ClooG-PPL"
202 echo " - native C compiler, assembler and linker"
203 echo " - native C library with headers"
204 echo
205}
206
207download_fetch() {
208 SOURCE="$1"
209 FILE="$2"
210 CHECKSUM="$3"
211
212 if [ ! -f "${FILE}" ]; then
213 change_title "Downloading ${FILE}"
214 wget -c "${SOURCE}${FILE}"
215 check_error $? "Error downloading ${FILE}."
216 fi
217
218 check_md5 "${FILE}" "${CHECKSUM}"
219}
220
221source_check() {
222 FILE="$1"
223
224 if [ ! -f "${FILE}" ]; then
225 echo
226 echo "File ${FILE} not found."
227
228 exit 4
229 fi
230}
231
232cleanup_dir() {
233 DIR="$1"
234
235 if [ -d "${DIR}" ]; then
236 change_title "Removing ${DIR}"
237 echo " >>> Removing ${DIR}"
238 rm -fr "${DIR}"
239 fi
240}
241
242create_dir() {
243 DIR="$1"
244 DESC="$2"
245
246 change_title "Creating ${DESC}"
247 echo ">>> Creating ${DESC}"
248
249 mkdir -p "${DIR}"
250 test -d "${DIR}"
251 check_error $? "Unable to create ${DIR}."
252}
253
254unpack_tarball() {
255 FILE="$1"
256 DESC="$2"
257
258 change_title "Unpacking ${DESC}"
259 echo " >>> Unpacking ${DESC}"
260
261 tar -xjf "${FILE}"
262 check_error $? "Error unpacking ${DESC}."
263}
264
265prepare() {
266 show_dependencies
267 check_dependecies
268 show_countdown 10
269
270 BINUTILS_SOURCE="ftp://ftp.gnu.org/gnu/binutils/"
271 GCC_SOURCE="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"
272 GDB_SOURCE="ftp://ftp.gnu.org/gnu/gdb/"
273
274 download_fetch "${BINUTILS_SOURCE}" "${BINUTILS}" "ee0f10756c84979622b992a4a61ea3f5"
275 download_fetch "${GCC_SOURCE}" "${GCC}" "2a0f1d99fda235c29d40b561f81d9a77"
276 download_fetch "${GDB_SOURCE}" "${GDB}" "95a9a8305fed4d30a30a6dc28ff9d060"
277}
278
279build_target() {
280 PLATFORM="$1"
281 TARGET="$2"
282
283 WORKDIR="${BASEDIR}/${PLATFORM}"
284 BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}"
285 GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
286 OBJDIR="${WORKDIR}/gcc-obj"
287 GDBDIR="${WORKDIR}/gdb-${GDB_VERSION}"
288
289 if [ -z "${CROSS_PREFIX}" ] ; then
290 CROSS_PREFIX="/usr/local/cross"
291 fi
292
293 PREFIX="${CROSS_PREFIX}/${PLATFORM}"
294
295 echo ">>> Downloading tarballs"
296 source_check "${BASEDIR}/${BINUTILS}"
297 source_check "${BASEDIR}/${GCC}"
298 source_check "${BASEDIR}/${GDB}"
299
300 echo ">>> Removing previous content"
301 cleanup_dir "${PREFIX}"
302 cleanup_dir "${WORKDIR}"
303
304 create_dir "${PREFIX}" "destination directory"
305 create_dir "${OBJDIR}" "GCC object directory"
306
307 echo ">>> Unpacking tarballs"
308 cd "${WORKDIR}"
309 check_error $? "Change directory failed."
310
311 unpack_tarball "${BASEDIR}/${BINUTILS}" "binutils"
312 unpack_tarball "${BASEDIR}/${GCC}" "GCC"
313 unpack_tarball "${BASEDIR}/${GDB}" "GDB"
314
315 echo ">>> Processing binutils (${PLATFORM})"
316 cd "${BINUTILSDIR}"
317 check_error $? "Change directory failed."
318
319 change_title "binutils: configure (${PLATFORM})"
320 CFLAGS=-Wno-error ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" --disable-nls
321 check_error $? "Error configuring binutils."
322
323 change_title "binutils: make (${PLATFORM})"
324 make all install
325 check_error $? "Error compiling/installing binutils."
326
327 echo ">>> Processing GCC (${PLATFORM})"
328 cd "${OBJDIR}"
329 check_error $? "Change directory failed."
330
331 change_title "GCC: configure (${PLATFORM})"
332 "${GCCDIR}/configure" "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" --with-gnu-as --with-gnu-ld --disable-nls --disable-threads --enable-languages=c,objc,c++,obj-c++ --disable-multilib --disable-libgcj --without-headers --disable-shared --enable-lto
333 check_error $? "Error configuring GCC."
334
335 change_title "GCC: make (${PLATFORM})"
336 PATH="${PATH}:${PREFIX}/bin" make all-gcc install-gcc
337 check_error $? "Error compiling/installing GCC."
338
339 echo ">>> Processing GDB (${PLATFORM})"
340 cd "${GDBDIR}"
341 check_error $? "Change directory failed."
342
343 change_title "GDB: configure (${PLATFORM})"
344 ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-"
345 check_error $? "Error configuring GDB."
346
347 change_title "GDB: make (${PLATFORM})"
348 make all install
349 check_error $? "Error compiling/installing GDB."
350
351 cd "${BASEDIR}"
352 check_error $? "Change directory failed."
353
354 echo ">>> Cleaning up"
355 cleanup_dir "${WORKDIR}"
356
357 echo
358 echo ">>> Cross-compiler for ${TARGET} installed."
359}
360
361if [ "$#" -lt "1" ]; then
362 show_usage
363fi
364
365case "$1" in
366 "amd64")
367 prepare
368 build_target "amd64" "amd64-linux-gnu"
369 ;;
370 "arm32")
371 prepare
372 build_target "arm32" "arm-linux-gnueabi"
373 ;;
374 "ia32")
375 prepare
376 build_target "ia32" "i686-pc-linux-gnu"
377 ;;
378 "ia64")
379 prepare
380 build_target "ia64" "ia64-pc-linux-gnu"
381 ;;
382 "mips32")
383 prepare
384 build_target "mips32" "mipsel-linux-gnu"
385 ;;
386 "mips32eb")
387 prepare
388 build_target "mips32eb" "mips-linux-gnu"
389 ;;
390 "mips64")
391 prepare
392 build_target "mips64" "mips64el-linux-gnu"
393 ;;
394 "ppc32")
395 prepare
396 build_target "ppc32" "ppc-linux-gnu"
397 ;;
398 "ppc64")
399 prepare
400 build_target "ppc64" "ppc64-linux-gnu"
401 ;;
402 "sparc64")
403 prepare
404 build_target "sparc64" "sparc64-linux-gnu"
405 ;;
406 "all")
407 prepare
408 build_target "amd64" "amd64-linux-gnu"
409 build_target "arm32" "arm-linux-gnueabi"
410 build_target "ia32" "i686-pc-linux-gnu"
411 build_target "ia64" "ia64-pc-linux-gnu"
412 build_target "mips32" "mipsel-linux-gnu"
413 build_target "mips32eb" "mips-linux-gnu"
414 build_target "mips64" "mips64el-linux-gnu"
415 build_target "ppc32" "ppc-linux-gnu"
416 build_target "ppc64" "ppc64-linux-gnu"
417 build_target "sparc64" "sparc64-linux-gnu"
418 ;;
419 "parallel")
420 prepare
421 build_target "amd64" "amd64-linux-gnu" &
422 build_target "arm32" "arm-linux-gnueabi" &
423 build_target "ia32" "i686-pc-linux-gnu" &
424 build_target "ia64" "ia64-pc-linux-gnu" &
425 build_target "mips32" "mipsel-linux-gnu" &
426 build_target "mips32eb" "mips-linux-gnu" &
427 build_target "mips64" "mips64el-linux-gnu" &
428 build_target "ppc32" "ppc-linux-gnu" &
429 build_target "ppc64" "ppc64-linux-gnu" &
430 build_target "sparc64" "sparc64-linux-gnu" &
431 wait
432 ;;
433 *)
434 show_usage
435 ;;
436esac
Note: See TracBrowser for help on using the repository browser.