source: mainline/tools/toolchain.sh@ 36cb22f

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

upgrade binutils and GDB to the newest releases

  • Property mode set to 100755
File size: 11.2 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.21.1"
56BINUTILS_RELEASE="a"
57GCC_VERSION="4.6.1"
58GDB_VERSION="7.3.1"
59
60BASEDIR="`pwd`"
61BINUTILS="binutils-${BINUTILS_VERSION}${BINUTILS_RELEASE}.tar.bz2"
62GCC_CORE="gcc-core-${GCC_VERSION}.tar.bz2"
63GCC_OBJC="gcc-objc-${GCC_VERSION}.tar.bz2"
64GCC_CPP="gcc-g++-${GCC_VERSION}.tar.bz2"
65GDB="gdb-${GDB_VERSION}.tar.bz2"
66
67#
68# Check if the library described in the argument
69# exists and has acceptable version.
70#
71check_dependency() {
72 DEPENDENCY="$1"
73 HEADER="$2"
74 BODY="$3"
75
76 FNAME="/tmp/conftest-$$"
77
78 echo "#include ${HEADER}" > "${FNAME}.c"
79 echo >> "${FNAME}.c"
80 echo "int main()" >> "${FNAME}.c"
81 echo "{" >> "${FNAME}.c"
82 echo "${BODY}" >> "${FNAME}.c"
83 echo " return 0;" >> "${FNAME}.c"
84 echo "}" >> "${FNAME}.c"
85
86 cc -c -o "${FNAME}.o" "${FNAME}.c" 2> "${FNAME}.log"
87 RC="$?"
88
89 if [ "$RC" -ne "0" ] ; then
90 echo " ${DEPENDENCY} not found, too old or compiler error."
91 echo " Please recheck manually the source file \"${FNAME}.c\"."
92 echo " The compilation of the toolchain is probably going to fail,"
93 echo " you have been warned."
94 echo
95 echo " ===== Compiler output ====="
96 cat "${FNAME}.log"
97 echo " ==========================="
98 echo
99 else
100 echo " ${DEPENDENCY} found"
101 rm -f "${FNAME}.log" "${FNAME}.o" "${FNAME}.c"
102 fi
103}
104
105check_dependecies() {
106 echo ">>> Basic dependency check"
107 check_dependency "GMP" "<gmp.h>" "${GMP_MAIN}"
108 check_dependency "MPFR" "<mpfr.h>" "${MPFR_MAIN}"
109 check_dependency "MPC" "<mpc.h>" "${MPC_MAIN}"
110 echo
111}
112
113check_error() {
114 if [ "$1" -ne "0" ]; then
115 echo
116 echo "Script failed: $2"
117
118 exit 1
119 fi
120}
121
122check_md5() {
123 FILE="$1"
124 SUM="$2"
125
126 COMPUTED="`md5sum "${FILE}" | cut -d' ' -f1`"
127 if [ "${SUM}" != "${COMPUTED}" ] ; then
128 echo
129 echo "Checksum of ${FILE} does not match."
130
131 exit 2
132 fi
133}
134
135show_usage() {
136 echo "Cross-compiler toolchain build script"
137 echo
138 echo "Syntax:"
139 echo " $0 <platform>"
140 echo
141 echo "Possible target platforms are:"
142 echo " amd64 AMD64 (x86-64, x64)"
143 echo " arm32 ARM"
144 echo " ia32 IA-32 (x86, i386)"
145 echo " ia64 IA-64 (Itanium)"
146 echo " mips32 MIPS little-endian 32b"
147 echo " mips32eb MIPS big-endian 32b"
148 echo " mips64 MIPS little-endian 64b"
149 echo " ppc32 32-bit PowerPC"
150 echo " ppc64 64-bit PowerPC"
151 echo " sparc64 SPARC V9"
152 echo " all build all targets"
153 echo " parallel same as 'all', but in parallel"
154 echo
155 echo "The toolchain will be installed to the directory specified by"
156 echo "the CROSS_PREFIX environment variable. If the variable is not"
157 echo "defined, /usr/local/cross will be used by default."
158 echo
159
160 exit 3
161}
162
163change_title() {
164 echo -en "\e]0;$1\a"
165}
166
167show_countdown() {
168 TM="$1"
169
170 if [ "${TM}" -eq 0 ] ; then
171 echo
172 return 0
173 fi
174
175 echo -n "${TM} "
176 change_title "${TM}"
177 sleep 1
178
179 TM="`expr "${TM}" - 1`"
180 show_countdown "${TM}"
181}
182
183show_dependencies() {
184 echo "IMPORTANT NOTICE:"
185 echo
186 echo "For a successful compilation and use of the cross-compiler"
187 echo "toolchain you need at least the following dependencies."
188 echo
189 echo "Please make sure that the dependencies are present in your"
190 echo "system. Otherwise the compilation process might fail after"
191 echo "a few seconds or minutes."
192 echo
193 echo " - SED, AWK, Flex, Bison, gzip, bzip2, Bourne Shell"
194 echo " - gettext, zlib, Texinfo, libelf, libgomp"
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
209download_fetch() {
210 SOURCE="$1"
211 FILE="$2"
212 CHECKSUM="$3"
213
214 if [ ! -f "${FILE}" ]; then
215 change_title "Downloading ${FILE}"
216 wget -c "${SOURCE}${FILE}"
217 check_error $? "Error downloading ${FILE}."
218 fi
219
220 check_md5 "${FILE}" "${CHECKSUM}"
221}
222
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
234cleanup_dir() {
235 DIR="$1"
236
237 if [ -d "${DIR}" ]; then
238 change_title "Removing ${DIR}"
239 echo " >>> Removing ${DIR}"
240 rm -fr "${DIR}"
241 fi
242}
243
244create_dir() {
245 DIR="$1"
246 DESC="$2"
247
248 change_title "Creating ${DESC}"
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
260 change_title "Unpacking ${DESC}"
261 echo " >>> Unpacking ${DESC}"
262
263 tar -xjf "${FILE}"
264 check_error $? "Error unpacking ${DESC}."
265}
266
267prepare() {
268 show_dependencies
269 check_dependecies
270 show_countdown 10
271
272 BINUTILS_SOURCE="ftp://ftp.gnu.org/gnu/binutils/"
273 GCC_SOURCE="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"
274 GDB_SOURCE="ftp://ftp.gnu.org/gnu/gdb/"
275
276 download_fetch "${BINUTILS_SOURCE}" "${BINUTILS}" "bde820eac53fa3a8d8696667418557ad"
277 download_fetch "${GCC_SOURCE}" "${GCC_CORE}" "0c0e7e35d2215e19de9c97efba507553"
278 download_fetch "${GCC_SOURCE}" "${GCC_OBJC}" "cbf0d4b701827922cf37ba6a4ace0079"
279 download_fetch "${GCC_SOURCE}" "${GCC_CPP}" "0d75ca7ca35b1e7f252223f9d23a6ad1"
280 download_fetch "${GDB_SOURCE}" "${GDB}" "b89a5fac359c618dda97b88645ceab47"
281}
282
283build_target() {
284 PLATFORM="$1"
285 TARGET="$2"
286
287 WORKDIR="${BASEDIR}/${PLATFORM}"
288 BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}"
289 GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
290 OBJDIR="${WORKDIR}/gcc-obj"
291 GDBDIR="${WORKDIR}/gdb-${GDB_VERSION}"
292
293 if [ -z "${CROSS_PREFIX}" ] ; then
294 CROSS_PREFIX="/usr/local/cross"
295 fi
296
297 PREFIX="${CROSS_PREFIX}/${PLATFORM}"
298
299 echo ">>> Downloading tarballs"
300 source_check "${BASEDIR}/${BINUTILS}"
301 source_check "${BASEDIR}/${GCC_CORE}"
302 source_check "${BASEDIR}/${GCC_OBJC}"
303 source_check "${BASEDIR}/${GCC_CPP}"
304 source_check "${BASEDIR}/${GDB}"
305
306 echo ">>> Removing previous content"
307 cleanup_dir "${PREFIX}"
308 cleanup_dir "${WORKDIR}"
309
310 create_dir "${PREFIX}" "destination directory"
311 create_dir "${OBJDIR}" "GCC object directory"
312
313 echo ">>> Unpacking tarballs"
314 cd "${WORKDIR}"
315 check_error $? "Change directory failed."
316
317 unpack_tarball "${BASEDIR}/${BINUTILS}" "binutils"
318 unpack_tarball "${BASEDIR}/${GCC_CORE}" "GCC Core"
319 unpack_tarball "${BASEDIR}/${GCC_OBJC}" "Objective C"
320 unpack_tarball "${BASEDIR}/${GCC_CPP}" "C++"
321 unpack_tarball "${BASEDIR}/${GDB}" "GDB"
322
323 echo ">>> Processing binutils (${PLATFORM})"
324 cd "${BINUTILSDIR}"
325 check_error $? "Change directory failed."
326
327 change_title "binutils: configure (${PLATFORM})"
328 CFLAGS=-Wno-error ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" --disable-nls
329 check_error $? "Error configuring binutils."
330
331 change_title "binutils: make (${PLATFORM})"
332 make all install
333 check_error $? "Error compiling/installing binutils."
334
335 echo ">>> Processing GCC (${PLATFORM})"
336 cd "${OBJDIR}"
337 check_error $? "Change directory failed."
338
339 change_title "GCC: configure (${PLATFORM})"
340 "${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
341 check_error $? "Error configuring GCC."
342
343 change_title "GCC: make (${PLATFORM})"
344 PATH="${PATH}:${PREFIX}/bin" make all-gcc install-gcc
345 check_error $? "Error compiling/installing GCC."
346
347 echo ">>> Processing GDB (${PLATFORM})"
348 cd "${GDBDIR}"
349 check_error $? "Change directory failed."
350
351 change_title "GDB: configure (${PLATFORM})"
352 ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-"
353 check_error $? "Error configuring GDB."
354
355 change_title "GDB: make (${PLATFORM})"
356 make all install
357 check_error $? "Error compiling/installing GDB."
358
359 cd "${BASEDIR}"
360 check_error $? "Change directory failed."
361
362 echo ">>> Cleaning up"
363 cleanup_dir "${WORKDIR}"
364
365 echo
366 echo ">>> Cross-compiler for ${TARGET} installed."
367}
368
369if [ "$#" -lt "1" ]; then
370 show_usage
371fi
372
373case "$1" in
374 "amd64")
375 prepare
376 build_target "amd64" "amd64-linux-gnu"
377 ;;
378 "arm32")
379 prepare
380 build_target "arm32" "arm-linux-gnu"
381 ;;
382 "ia32")
383 prepare
384 build_target "ia32" "i686-pc-linux-gnu"
385 ;;
386 "ia64")
387 prepare
388 build_target "ia64" "ia64-pc-linux-gnu"
389 ;;
390 "mips32")
391 prepare
392 build_target "mips32" "mipsel-linux-gnu"
393 ;;
394 "mips32eb")
395 prepare
396 build_target "mips32eb" "mips-linux-gnu"
397 ;;
398 "mips64")
399 prepare
400 build_target "mips64" "mips64el-linux-gnu"
401 ;;
402 "ppc32")
403 prepare
404 build_target "ppc32" "ppc-linux-gnu"
405 ;;
406 "ppc64")
407 prepare
408 build_target "ppc64" "ppc64-linux-gnu"
409 ;;
410 "sparc64")
411 prepare
412 build_target "sparc64" "sparc64-linux-gnu"
413 ;;
414 "all")
415 prepare
416 build_target "amd64" "amd64-linux-gnu"
417 build_target "arm32" "arm-linux-gnu"
418 build_target "ia32" "i686-pc-linux-gnu"
419 build_target "ia64" "ia64-pc-linux-gnu"
420 build_target "mips32" "mipsel-linux-gnu"
421 build_target "mips32eb" "mips-linux-gnu"
422 build_target "mips64" "mips64el-linux-gnu"
423 build_target "ppc32" "ppc-linux-gnu"
424 build_target "ppc64" "ppc64-linux-gnu"
425 build_target "sparc64" "sparc64-linux-gnu"
426 ;;
427 "parallel")
428 prepare
429 build_target "amd64" "amd64-linux-gnu" &
430 build_target "arm32" "arm-linux-gnu" &
431 build_target "ia32" "i686-pc-linux-gnu" &
432 build_target "ia64" "ia64-pc-linux-gnu" &
433 build_target "mips32" "mipsel-linux-gnu" &
434 build_target "mips32eb" "mips-linux-gnu" &
435 build_target "mips64" "mips64el-linux-gnu" &
436 build_target "ppc32" "ppc-linux-gnu" &
437 build_target "ppc64" "ppc64-linux-gnu" &
438 build_target "sparc64" "sparc64-linux-gnu" &
439 wait
440 ;;
441 *)
442 show_usage
443 ;;
444esac
Note: See TracBrowser for help on using the repository browser.