source: mainline/tools/toolchain.sh@ 6e634d6

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 6e634d6 was 6e634d6, checked in by Jan Vesely <jano.vesely@…>, 13 years ago

toolchain: bump binutils to 2.23.1

Fixes https://lists.gnu.org/archive/html/bug-binutils/2012-03/msg00096.html

  • Property mode set to 100755
File size: 11.3 KB
RevLine 
[9d5bb4e]1#! /bin/bash
[ff211d2]2
3#
[04c3a21f]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.
[ff211d2]29#
30
[3f7efa79]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)
[7d248e3]45 choke me
46#endif
[3f7efa79]47EOF
48
49MPC_MAIN=<<EOF
50#if MPC_VERSION < MPC_VERSION_NUM(0, 8, 1)
51 choke me
52#endif
53EOF
54
[6e634d6]55BINUTILS_VERSION="2.23.1"
[145d16f8]56BINUTILS_RELEASE=""
[190976f]57GCC_VERSION="4.7.2"
58GDB_VERSION="7.5"
[603c8740]59
60BASEDIR="`pwd`"
[7e9fce6]61BINUTILS="binutils-${BINUTILS_VERSION}${BINUTILS_RELEASE}.tar.bz2"
[2385952]62GCC="gcc-${GCC_VERSION}.tar.bz2"
[2a922c8]63GDB="gdb-${GDB_VERSION}.tar.bz2"
[603c8740]64
[3f7efa79]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
[ff211d2]111check_error() {
112 if [ "$1" -ne "0" ]; then
113 echo
114 echo "Script failed: $2"
[3fe57ea7]115
[ff211d2]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."
[3fe57ea7]128
[ff211d2]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:"
[f2f89315]140 echo " amd64 AMD64 (x86-64, x64)"
141 echo " arm32 ARM"
[ff211d2]142 echo " ia32 IA-32 (x86, i386)"
143 echo " ia64 IA-64 (Itanium)"
[71e3289]144 echo " mips32 MIPS little-endian 32b"
145 echo " mips32eb MIPS big-endian 32b"
146 echo " mips64 MIPS little-endian 64b"
[f2f89315]147 echo " ppc32 32-bit PowerPC"
148 echo " ppc64 64-bit PowerPC"
149 echo " sparc64 SPARC V9"
[ff211d2]150 echo " all build all targets"
[6abb346]151 echo " parallel same as 'all', but all in parallel"
152 echo " 2-way same as 'all', but 2-way parallel"
[ff211d2]153 echo
[38eaf41]154 echo "The toolchain will be installed to the directory specified by"
155 echo "the CROSS_PREFIX environment variable. If the variable is not"
[603c8740]156 echo "defined, /usr/local/cross will be used by default."
[38eaf41]157 echo
[ff211d2]158
159 exit 3
160}
161
[3fe57ea7]162change_title() {
163 echo -en "\e]0;$1\a"
164}
165
166show_countdown() {
167 TM="$1"
168
169 if [ "${TM}" -eq 0 ] ; then
170 echo
171 return 0
172 fi
173
174 echo -n "${TM} "
175 change_title "${TM}"
176 sleep 1
177
178 TM="`expr "${TM}" - 1`"
179 show_countdown "${TM}"
180}
181
182show_dependencies() {
183 echo "IMPORTANT NOTICE:"
184 echo
185 echo "For a successful compilation and use of the cross-compiler"
186 echo "toolchain you need at least the following dependencies."
187 echo
188 echo "Please make sure that the dependencies are present in your"
189 echo "system. Otherwise the compilation process might fail after"
190 echo "a few seconds or minutes."
191 echo
192 echo " - SED, AWK, Flex, Bison, gzip, bzip2, Bourne Shell"
193 echo " - gettext, zlib, Texinfo, libelf, libgomp"
[190976f]194 echo " - terminfo"
[3fe57ea7]195 echo " - GNU Multiple Precision Library (GMP)"
196 echo " - GNU Make"
197 echo " - GNU tar"
198 echo " - GNU Coreutils"
199 echo " - GNU Sharutils"
200 echo " - MPFR"
201 echo " - MPC"
202 echo " - Parma Polyhedra Library (PPL)"
203 echo " - ClooG-PPL"
204 echo " - native C compiler, assembler and linker"
205 echo " - native C library with headers"
206 echo
207}
208
[603c8740]209download_fetch() {
[ff211d2]210 SOURCE="$1"
211 FILE="$2"
212 CHECKSUM="$3"
213
214 if [ ! -f "${FILE}" ]; then
[3fe57ea7]215 change_title "Downloading ${FILE}"
[ff211d2]216 wget -c "${SOURCE}${FILE}"
217 check_error $? "Error downloading ${FILE}."
218 fi
219
220 check_md5 "${FILE}" "${CHECKSUM}"
221}
222
[603c8740]223source_check() {
224 FILE="$1"
225
226 if [ ! -f "${FILE}" ]; then
227 echo
228 echo "File ${FILE} not found."
229
230 exit 4
231 fi
232}
233
[ff211d2]234cleanup_dir() {
235 DIR="$1"
236
237 if [ -d "${DIR}" ]; then
[3fe57ea7]238 change_title "Removing ${DIR}"
[ff211d2]239 echo " >>> Removing ${DIR}"
240 rm -fr "${DIR}"
241 fi
242}
243
244create_dir() {
245 DIR="$1"
246 DESC="$2"
247
[3fe57ea7]248 change_title "Creating ${DESC}"
[ff211d2]249 echo ">>> Creating ${DESC}"
250
251 mkdir -p "${DIR}"
252 test -d "${DIR}"
253 check_error $? "Unable to create ${DIR}."
254}
255
256unpack_tarball() {
257 FILE="$1"
258 DESC="$2"
259
[3fe57ea7]260 change_title "Unpacking ${DESC}"
261 echo " >>> Unpacking ${DESC}"
[ff211d2]262
263 tar -xjf "${FILE}"
264 check_error $? "Error unpacking ${DESC}."
265}
266
[603c8740]267prepare() {
268 show_dependencies
269 check_dependecies
270 show_countdown 10
[fd8bf6a]271
[603c8740]272 BINUTILS_SOURCE="ftp://ftp.gnu.org/gnu/binutils/"
273 GCC_SOURCE="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"
[2a922c8]274 GDB_SOURCE="ftp://ftp.gnu.org/gnu/gdb/"
[603c8740]275
[6e634d6]276 download_fetch "${BINUTILS_SOURCE}" "${BINUTILS}" "33adb18c3048d057ac58d07a3f1adb38"
[190976f]277 download_fetch "${GCC_SOURCE}" "${GCC}" "cc308a0891e778cfda7a151ab8a6e762"
278 download_fetch "${GDB_SOURCE}" "${GDB}" "24a6779a9fe0260667710de1b082ef61"
[fd8bf6a]279}
280
[ff211d2]281build_target() {
282 PLATFORM="$1"
283 TARGET="$2"
284
[603c8740]285 WORKDIR="${BASEDIR}/${PLATFORM}"
[ff211d2]286 BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}"
287 GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
288 OBJDIR="${WORKDIR}/gcc-obj"
[2a922c8]289 GDBDIR="${WORKDIR}/gdb-${GDB_VERSION}"
[ff211d2]290
291 if [ -z "${CROSS_PREFIX}" ] ; then
[603c8740]292 CROSS_PREFIX="/usr/local/cross"
[ff211d2]293 fi
294
295 PREFIX="${CROSS_PREFIX}/${PLATFORM}"
296
297 echo ">>> Downloading tarballs"
[603c8740]298 source_check "${BASEDIR}/${BINUTILS}"
[2385952]299 source_check "${BASEDIR}/${GCC}"
[2a922c8]300 source_check "${BASEDIR}/${GDB}"
[ff211d2]301
302 echo ">>> Removing previous content"
303 cleanup_dir "${PREFIX}"
[603c8740]304 cleanup_dir "${WORKDIR}"
[ff211d2]305
[f2f89315]306 create_dir "${PREFIX}" "destination directory"
[ff211d2]307 create_dir "${OBJDIR}" "GCC object directory"
308
309 echo ">>> Unpacking tarballs"
[603c8740]310 cd "${WORKDIR}"
311 check_error $? "Change directory failed."
312
313 unpack_tarball "${BASEDIR}/${BINUTILS}" "binutils"
[2385952]314 unpack_tarball "${BASEDIR}/${GCC}" "GCC"
[2a922c8]315 unpack_tarball "${BASEDIR}/${GDB}" "GDB"
[ff211d2]316
[3fe57ea7]317 echo ">>> Processing binutils (${PLATFORM})"
[ff211d2]318 cd "${BINUTILSDIR}"
319 check_error $? "Change directory failed."
[3fe57ea7]320
321 change_title "binutils: configure (${PLATFORM})"
[baf8fbb]322 CFLAGS=-Wno-error ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" --disable-nls --disable-werror
[ff211d2]323 check_error $? "Error configuring binutils."
[3fe57ea7]324
325 change_title "binutils: make (${PLATFORM})"
[ff211d2]326 make all install
327 check_error $? "Error compiling/installing binutils."
328
[3fe57ea7]329 echo ">>> Processing GCC (${PLATFORM})"
[ff211d2]330 cd "${OBJDIR}"
331 check_error $? "Change directory failed."
[3fe57ea7]332
333 change_title "GCC: configure (${PLATFORM})"
[baf8fbb]334 "${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 --disable-werror
[ff211d2]335 check_error $? "Error configuring GCC."
[3fe57ea7]336
337 change_title "GCC: make (${PLATFORM})"
[ff211d2]338 PATH="${PATH}:${PREFIX}/bin" make all-gcc install-gcc
339 check_error $? "Error compiling/installing GCC."
340
[2a922c8]341 echo ">>> Processing GDB (${PLATFORM})"
342 cd "${GDBDIR}"
343 check_error $? "Change directory failed."
344
345 change_title "GDB: configure (${PLATFORM})"
346 ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-"
347 check_error $? "Error configuring GDB."
348
349 change_title "GDB: make (${PLATFORM})"
350 make all install
351 check_error $? "Error compiling/installing GDB."
352
[603c8740]353 cd "${BASEDIR}"
[ff211d2]354 check_error $? "Change directory failed."
355
356 echo ">>> Cleaning up"
[603c8740]357 cleanup_dir "${WORKDIR}"
[ff211d2]358
359 echo
360 echo ">>> Cross-compiler for ${TARGET} installed."
361}
362
363if [ "$#" -lt "1" ]; then
364 show_usage
365fi
366
367case "$1" in
368 "amd64")
[603c8740]369 prepare
[ff211d2]370 build_target "amd64" "amd64-linux-gnu"
371 ;;
372 "arm32")
[603c8740]373 prepare
[2385952]374 build_target "arm32" "arm-linux-gnueabi"
[ff211d2]375 ;;
376 "ia32")
[603c8740]377 prepare
[ff211d2]378 build_target "ia32" "i686-pc-linux-gnu"
379 ;;
380 "ia64")
[603c8740]381 prepare
[ff211d2]382 build_target "ia64" "ia64-pc-linux-gnu"
383 ;;
384 "mips32")
[603c8740]385 prepare
[ff211d2]386 build_target "mips32" "mipsel-linux-gnu"
387 ;;
388 "mips32eb")
[603c8740]389 prepare
[ff211d2]390 build_target "mips32eb" "mips-linux-gnu"
391 ;;
[71e3289]392 "mips64")
[603c8740]393 prepare
[71e3289]394 build_target "mips64" "mips64el-linux-gnu"
395 ;;
[ff211d2]396 "ppc32")
[603c8740]397 prepare
[ff211d2]398 build_target "ppc32" "ppc-linux-gnu"
399 ;;
400 "ppc64")
[603c8740]401 prepare
[ff211d2]402 build_target "ppc64" "ppc64-linux-gnu"
403 ;;
404 "sparc64")
[603c8740]405 prepare
[ff211d2]406 build_target "sparc64" "sparc64-linux-gnu"
407 ;;
408 "all")
[603c8740]409 prepare
[ff211d2]410 build_target "amd64" "amd64-linux-gnu"
[2385952]411 build_target "arm32" "arm-linux-gnueabi"
[ff211d2]412 build_target "ia32" "i686-pc-linux-gnu"
413 build_target "ia64" "ia64-pc-linux-gnu"
414 build_target "mips32" "mipsel-linux-gnu"
415 build_target "mips32eb" "mips-linux-gnu"
[71e3289]416 build_target "mips64" "mips64el-linux-gnu"
[ff211d2]417 build_target "ppc32" "ppc-linux-gnu"
418 build_target "ppc64" "ppc64-linux-gnu"
419 build_target "sparc64" "sparc64-linux-gnu"
420 ;;
[603c8740]421 "parallel")
422 prepare
423 build_target "amd64" "amd64-linux-gnu" &
[2385952]424 build_target "arm32" "arm-linux-gnueabi" &
[603c8740]425 build_target "ia32" "i686-pc-linux-gnu" &
426 build_target "ia64" "ia64-pc-linux-gnu" &
427 build_target "mips32" "mipsel-linux-gnu" &
428 build_target "mips32eb" "mips-linux-gnu" &
429 build_target "mips64" "mips64el-linux-gnu" &
430 build_target "ppc32" "ppc-linux-gnu" &
[6abb346]431 build_target "ppc64" "ppc64-linux-gnu" &
432 build_target "sparc64" "sparc64-linux-gnu" &
433 wait
434 ;;
435 "2-way")
436 prepare
437 build_target "amd64" "amd64-linux-gnu" &
438 build_target "arm32" "arm-linux-gnueabi" &
439 wait
440
441 build_target "ia32" "i686-pc-linux-gnu" &
442 build_target "ia64" "ia64-pc-linux-gnu" &
443 wait
444
445 build_target "mips32" "mipsel-linux-gnu" &
446 build_target "mips32eb" "mips-linux-gnu" &
447 wait
448
449 build_target "mips64" "mips64el-linux-gnu" &
450 build_target "ppc32" "ppc-linux-gnu" &
451 wait
452
[603c8740]453 build_target "ppc64" "ppc64-linux-gnu" &
454 build_target "sparc64" "sparc64-linux-gnu" &
455 wait
456 ;;
[ff211d2]457 *)
458 show_usage
459 ;;
460esac
Note: See TracBrowser for help on using the repository browser.