source: mainline/tools/toolchain.sh@ b886b60

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b886b60 was b886b60, checked in by Jakub Klama <jakub.klama@…>, 12 years ago

Introduce SPARCv8 toolchain in toolchain.sh script.

  • Property mode set to 100755
File size: 11.6 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)
45 choke 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.23.1"
56BINUTILS_RELEASE=""
57GCC_VERSION="4.8.1"
58GDB_VERSION="7.6"
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 " sparc32 SPARC V8"
151 echo " all build all targets"
152 echo " parallel same as 'all', but all in parallel"
153 echo " 2-way same as 'all', but 2-way 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 " - terminfo"
196 echo " - GNU Multiple Precision Library (GMP)"
197 echo " - GNU Make"
198 echo " - GNU tar"
199 echo " - GNU Coreutils"
200 echo " - GNU Sharutils"
201 echo " - MPFR"
202 echo " - MPC"
203 echo " - Parma Polyhedra Library (PPL)"
204 echo " - ClooG-PPL"
205 echo " - native C compiler, assembler and linker"
206 echo " - native C library with headers"
207 echo
208}
209
210download_fetch() {
211 SOURCE="$1"
212 FILE="$2"
213 CHECKSUM="$3"
214
215 if [ ! -f "${FILE}" ]; then
216 change_title "Downloading ${FILE}"
217 wget -c "${SOURCE}${FILE}"
218 check_error $? "Error downloading ${FILE}."
219 fi
220
221 check_md5 "${FILE}" "${CHECKSUM}"
222}
223
224source_check() {
225 FILE="$1"
226
227 if [ ! -f "${FILE}" ]; then
228 echo
229 echo "File ${FILE} not found."
230
231 exit 4
232 fi
233}
234
235cleanup_dir() {
236 DIR="$1"
237
238 if [ -d "${DIR}" ]; then
239 change_title "Removing ${DIR}"
240 echo " >>> Removing ${DIR}"
241 rm -fr "${DIR}"
242 fi
243}
244
245create_dir() {
246 DIR="$1"
247 DESC="$2"
248
249 change_title "Creating ${DESC}"
250 echo ">>> Creating ${DESC}"
251
252 mkdir -p "${DIR}"
253 test -d "${DIR}"
254 check_error $? "Unable to create ${DIR}."
255}
256
257unpack_tarball() {
258 FILE="$1"
259 DESC="$2"
260
261 change_title "Unpacking ${DESC}"
262 echo " >>> Unpacking ${DESC}"
263
264 tar -xjf "${FILE}"
265 check_error $? "Error unpacking ${DESC}."
266}
267
268prepare() {
269 show_dependencies
270 check_dependecies
271 show_countdown 10
272
273 BINUTILS_SOURCE="ftp://ftp.gnu.org/gnu/binutils/"
274 GCC_SOURCE="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"
275 GDB_SOURCE="ftp://ftp.gnu.org/gnu/gdb/"
276
277 download_fetch "${BINUTILS_SOURCE}" "${BINUTILS}" "33adb18c3048d057ac58d07a3f1adb38"
278 download_fetch "${GCC_SOURCE}" "${GCC}" "3b2386c114cd74185aa3754b58a79304"
279 download_fetch "${GDB_SOURCE}" "${GDB}" "fda57170e4d11cdde74259ca575412a8"
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}"
301 source_check "${BASEDIR}/${GDB}"
302
303 echo ">>> Removing previous content"
304 cleanup_dir "${PREFIX}"
305 cleanup_dir "${WORKDIR}"
306
307 create_dir "${PREFIX}" "destination directory"
308 create_dir "${OBJDIR}" "GCC object directory"
309
310 echo ">>> Unpacking tarballs"
311 cd "${WORKDIR}"
312 check_error $? "Change directory failed."
313
314 unpack_tarball "${BASEDIR}/${BINUTILS}" "binutils"
315 unpack_tarball "${BASEDIR}/${GCC}" "GCC"
316 unpack_tarball "${BASEDIR}/${GDB}" "GDB"
317
318 echo ">>> Processing binutils (${PLATFORM})"
319 cd "${BINUTILSDIR}"
320 check_error $? "Change directory failed."
321
322 change_title "binutils: configure (${PLATFORM})"
323 CFLAGS=-Wno-error ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" --disable-nls --disable-werror
324 check_error $? "Error configuring binutils."
325
326 change_title "binutils: make (${PLATFORM})"
327 make all install
328 check_error $? "Error compiling/installing binutils."
329
330 echo ">>> Processing GCC (${PLATFORM})"
331 cd "${OBJDIR}"
332 check_error $? "Change directory failed."
333
334 change_title "GCC: configure (${PLATFORM})"
335 "${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
336 check_error $? "Error configuring GCC."
337
338 change_title "GCC: make (${PLATFORM})"
339 PATH="${PATH}:${PREFIX}/bin" make all-gcc install-gcc
340 check_error $? "Error compiling/installing GCC."
341
342 echo ">>> Processing GDB (${PLATFORM})"
343 cd "${GDBDIR}"
344 check_error $? "Change directory failed."
345
346 change_title "GDB: configure (${PLATFORM})"
347 ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-"
348 check_error $? "Error configuring GDB."
349
350 change_title "GDB: make (${PLATFORM})"
351 make all install
352 check_error $? "Error compiling/installing GDB."
353
354 cd "${BASEDIR}"
355 check_error $? "Change directory failed."
356
357 echo ">>> Cleaning up"
358 cleanup_dir "${WORKDIR}"
359
360 echo
361 echo ">>> Cross-compiler for ${TARGET} installed."
362}
363
364if [ "$#" -lt "1" ]; then
365 show_usage
366fi
367
368case "$1" in
369 "amd64")
370 prepare
371 build_target "amd64" "amd64-linux-gnu"
372 ;;
373 "arm32")
374 prepare
375 build_target "arm32" "arm-linux-gnueabi"
376 ;;
377 "ia32")
378 prepare
379 build_target "ia32" "i686-pc-linux-gnu"
380 ;;
381 "ia64")
382 prepare
383 build_target "ia64" "ia64-pc-linux-gnu"
384 ;;
385 "mips32")
386 prepare
387 build_target "mips32" "mipsel-linux-gnu"
388 ;;
389 "mips32eb")
390 prepare
391 build_target "mips32eb" "mips-linux-gnu"
392 ;;
393 "mips64")
394 prepare
395 build_target "mips64" "mips64el-linux-gnu"
396 ;;
397 "ppc32")
398 prepare
399 build_target "ppc32" "ppc-linux-gnu"
400 ;;
401 "ppc64")
402 prepare
403 build_target "ppc64" "ppc64-linux-gnu"
404 ;;
405 "sparc64")
406 prepare
407 build_target "sparc64" "sparc64-linux-gnu"
408 ;;
409 "sparc32")
410 prepare
411 build_target "sparc32" "sparc-leon3-linux-gnu"
412 ;;
413 "all")
414 prepare
415 build_target "amd64" "amd64-linux-gnu"
416 build_target "arm32" "arm-linux-gnueabi"
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 build_target "sparc32" "sparc-leon3-linux-gnu"
426 ;;
427 "parallel")
428 prepare
429 build_target "amd64" "amd64-linux-gnu" &
430 build_target "arm32" "arm-linux-gnueabi" &
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 build_target "sparc32" "sparc-leon3-linux-gnu" &
440 wait
441 ;;
442 "2-way")
443 prepare
444 build_target "amd64" "amd64-linux-gnu" &
445 build_target "arm32" "arm-linux-gnueabi" &
446 wait
447
448 build_target "ia32" "i686-pc-linux-gnu" &
449 build_target "ia64" "ia64-pc-linux-gnu" &
450 wait
451
452 build_target "mips32" "mipsel-linux-gnu" &
453 build_target "mips32eb" "mips-linux-gnu" &
454 wait
455
456 build_target "mips64" "mips64el-linux-gnu" &
457 build_target "ppc32" "ppc-linux-gnu" &
458 wait
459
460 build_target "ppc64" "ppc64-linux-gnu" &
461 build_target "sparc64" "sparc64-linux-gnu" &
462 wait
463
464 build_target "sparc32" "sparc-leon3-linux-gnu" &
465 wait
466 ;;
467 *)
468 show_usage
469 ;;
470esac
Note: See TracBrowser for help on using the repository browser.