source: mainline/tools/toolchain.sh@ 166c26f3

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

bump to GCC 4.6.1

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