source: mainline/tools/toolchain.sh@ 5a324d99

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

make sure that CROSS_PREFIX is set to some sane value

  • Property mode set to 100755
File size: 11.9 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=""
[8876b0d]57GCC_VERSION="4.8.1"
58GDB_VERSION="7.6"
[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
[285589b]256check_dirs() {
257 OUTSIDE="$1"
258 BASE="$2"
259 ORIGINAL="`pwd`"
260
261 cd "${OUTSIDE}"
262 check_error $? "Unable to change directory to ${OUTSIDE}."
263 ABS_OUTSIDE="`pwd`"
264
265 cd "${BASE}"
266 check_error $? "Unable to change directory to ${BASE}."
267 ABS_BASE="`pwd`"
268
269 cd "${ORIGINAL}"
270 check_error $? "Unable to change directory to ${ORIGINAL}."
271
272 BASE_LEN="${#ABS_BASE}"
273 OUTSIDE_TRIM="${ABS_OUTSIDE:0:${BASE_LEN}}"
274
275 if [ "${OUTSIDE_TRIM}" == "${ABS_BASE}" ] ; then
276 echo
277 echo "CROSS_PREFIX cannot reside within the working directory."
278
279 exit 5
280 fi
281}
282
[ff211d2]283unpack_tarball() {
284 FILE="$1"
285 DESC="$2"
286
[3fe57ea7]287 change_title "Unpacking ${DESC}"
288 echo " >>> Unpacking ${DESC}"
[ff211d2]289
290 tar -xjf "${FILE}"
291 check_error $? "Error unpacking ${DESC}."
292}
293
[603c8740]294prepare() {
295 show_dependencies
296 check_dependecies
297 show_countdown 10
[fd8bf6a]298
[603c8740]299 BINUTILS_SOURCE="ftp://ftp.gnu.org/gnu/binutils/"
300 GCC_SOURCE="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"
[2a922c8]301 GDB_SOURCE="ftp://ftp.gnu.org/gnu/gdb/"
[603c8740]302
[6e634d6]303 download_fetch "${BINUTILS_SOURCE}" "${BINUTILS}" "33adb18c3048d057ac58d07a3f1adb38"
[8876b0d]304 download_fetch "${GCC_SOURCE}" "${GCC}" "3b2386c114cd74185aa3754b58a79304"
305 download_fetch "${GDB_SOURCE}" "${GDB}" "fda57170e4d11cdde74259ca575412a8"
[fd8bf6a]306}
307
[ff211d2]308build_target() {
309 PLATFORM="$1"
310 TARGET="$2"
311
[603c8740]312 WORKDIR="${BASEDIR}/${PLATFORM}"
[ff211d2]313 BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}"
314 GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
315 OBJDIR="${WORKDIR}/gcc-obj"
[2a922c8]316 GDBDIR="${WORKDIR}/gdb-${GDB_VERSION}"
[ff211d2]317
318 if [ -z "${CROSS_PREFIX}" ] ; then
[603c8740]319 CROSS_PREFIX="/usr/local/cross"
[ff211d2]320 fi
321
322 PREFIX="${CROSS_PREFIX}/${PLATFORM}"
323
324 echo ">>> Downloading tarballs"
[603c8740]325 source_check "${BASEDIR}/${BINUTILS}"
[2385952]326 source_check "${BASEDIR}/${GCC}"
[2a922c8]327 source_check "${BASEDIR}/${GDB}"
[ff211d2]328
329 echo ">>> Removing previous content"
330 cleanup_dir "${PREFIX}"
[603c8740]331 cleanup_dir "${WORKDIR}"
[ff211d2]332
[f2f89315]333 create_dir "${PREFIX}" "destination directory"
[ff211d2]334 create_dir "${OBJDIR}" "GCC object directory"
335
[285589b]336 check_dirs "${PREFIX}" "${WORKDIR}"
337
[ff211d2]338 echo ">>> Unpacking tarballs"
[603c8740]339 cd "${WORKDIR}"
340 check_error $? "Change directory failed."
341
342 unpack_tarball "${BASEDIR}/${BINUTILS}" "binutils"
[2385952]343 unpack_tarball "${BASEDIR}/${GCC}" "GCC"
[2a922c8]344 unpack_tarball "${BASEDIR}/${GDB}" "GDB"
[ff211d2]345
[3fe57ea7]346 echo ">>> Processing binutils (${PLATFORM})"
[ff211d2]347 cd "${BINUTILSDIR}"
348 check_error $? "Change directory failed."
[3fe57ea7]349
350 change_title "binutils: configure (${PLATFORM})"
[baf8fbb]351 CFLAGS=-Wno-error ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" --disable-nls --disable-werror
[ff211d2]352 check_error $? "Error configuring binutils."
[3fe57ea7]353
354 change_title "binutils: make (${PLATFORM})"
[ff211d2]355 make all install
356 check_error $? "Error compiling/installing binutils."
357
[3fe57ea7]358 echo ">>> Processing GCC (${PLATFORM})"
[ff211d2]359 cd "${OBJDIR}"
360 check_error $? "Change directory failed."
[3fe57ea7]361
362 change_title "GCC: configure (${PLATFORM})"
[baf8fbb]363 "${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]364 check_error $? "Error configuring GCC."
[3fe57ea7]365
366 change_title "GCC: make (${PLATFORM})"
[ff211d2]367 PATH="${PATH}:${PREFIX}/bin" make all-gcc install-gcc
368 check_error $? "Error compiling/installing GCC."
369
[2a922c8]370 echo ">>> Processing GDB (${PLATFORM})"
371 cd "${GDBDIR}"
372 check_error $? "Change directory failed."
373
374 change_title "GDB: configure (${PLATFORM})"
375 ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-"
376 check_error $? "Error configuring GDB."
377
378 change_title "GDB: make (${PLATFORM})"
379 make all install
380 check_error $? "Error compiling/installing GDB."
381
[603c8740]382 cd "${BASEDIR}"
[ff211d2]383 check_error $? "Change directory failed."
384
385 echo ">>> Cleaning up"
[603c8740]386 cleanup_dir "${WORKDIR}"
[ff211d2]387
388 echo
389 echo ">>> Cross-compiler for ${TARGET} installed."
390}
391
392if [ "$#" -lt "1" ]; then
393 show_usage
394fi
395
396case "$1" in
397 "amd64")
[603c8740]398 prepare
[ff211d2]399 build_target "amd64" "amd64-linux-gnu"
400 ;;
401 "arm32")
[603c8740]402 prepare
[2385952]403 build_target "arm32" "arm-linux-gnueabi"
[ff211d2]404 ;;
405 "ia32")
[603c8740]406 prepare
[ff211d2]407 build_target "ia32" "i686-pc-linux-gnu"
408 ;;
409 "ia64")
[603c8740]410 prepare
[ff211d2]411 build_target "ia64" "ia64-pc-linux-gnu"
412 ;;
413 "mips32")
[603c8740]414 prepare
[ff211d2]415 build_target "mips32" "mipsel-linux-gnu"
416 ;;
417 "mips32eb")
[603c8740]418 prepare
[ff211d2]419 build_target "mips32eb" "mips-linux-gnu"
420 ;;
[71e3289]421 "mips64")
[603c8740]422 prepare
[71e3289]423 build_target "mips64" "mips64el-linux-gnu"
424 ;;
[ff211d2]425 "ppc32")
[603c8740]426 prepare
[ff211d2]427 build_target "ppc32" "ppc-linux-gnu"
428 ;;
429 "ppc64")
[603c8740]430 prepare
[ff211d2]431 build_target "ppc64" "ppc64-linux-gnu"
432 ;;
433 "sparc64")
[603c8740]434 prepare
[ff211d2]435 build_target "sparc64" "sparc64-linux-gnu"
436 ;;
437 "all")
[603c8740]438 prepare
[ff211d2]439 build_target "amd64" "amd64-linux-gnu"
[2385952]440 build_target "arm32" "arm-linux-gnueabi"
[ff211d2]441 build_target "ia32" "i686-pc-linux-gnu"
442 build_target "ia64" "ia64-pc-linux-gnu"
443 build_target "mips32" "mipsel-linux-gnu"
444 build_target "mips32eb" "mips-linux-gnu"
[71e3289]445 build_target "mips64" "mips64el-linux-gnu"
[ff211d2]446 build_target "ppc32" "ppc-linux-gnu"
447 build_target "ppc64" "ppc64-linux-gnu"
448 build_target "sparc64" "sparc64-linux-gnu"
449 ;;
[603c8740]450 "parallel")
451 prepare
452 build_target "amd64" "amd64-linux-gnu" &
[2385952]453 build_target "arm32" "arm-linux-gnueabi" &
[603c8740]454 build_target "ia32" "i686-pc-linux-gnu" &
455 build_target "ia64" "ia64-pc-linux-gnu" &
456 build_target "mips32" "mipsel-linux-gnu" &
457 build_target "mips32eb" "mips-linux-gnu" &
458 build_target "mips64" "mips64el-linux-gnu" &
459 build_target "ppc32" "ppc-linux-gnu" &
[6abb346]460 build_target "ppc64" "ppc64-linux-gnu" &
461 build_target "sparc64" "sparc64-linux-gnu" &
462 wait
463 ;;
464 "2-way")
465 prepare
466 build_target "amd64" "amd64-linux-gnu" &
467 build_target "arm32" "arm-linux-gnueabi" &
468 wait
469
470 build_target "ia32" "i686-pc-linux-gnu" &
471 build_target "ia64" "ia64-pc-linux-gnu" &
472 wait
473
474 build_target "mips32" "mipsel-linux-gnu" &
475 build_target "mips32eb" "mips-linux-gnu" &
476 wait
477
478 build_target "mips64" "mips64el-linux-gnu" &
479 build_target "ppc32" "ppc-linux-gnu" &
480 wait
481
[603c8740]482 build_target "ppc64" "ppc64-linux-gnu" &
483 build_target "sparc64" "sparc64-linux-gnu" &
484 wait
485 ;;
[ff211d2]486 *)
487 show_usage
488 ;;
489esac
Note: See TracBrowser for help on using the repository browser.