source: mainline/tools/toolchain.sh@ 322ac35c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 322ac35c was 322ac35c, checked in by Vojtech Horky <vojtechhorky@…>, 12 years ago

Allow non-superuser toolchain compilation

  • Property mode set to 100755
File size: 12.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
65REAL_INSTALL=true
66INSTALL_DIR="${BASEDIR}/PKG"
67
68#
69# Check if the library described in the argument
70# exists and has acceptable version.
71#
72check_dependency() {
73 DEPENDENCY="$1"
74 HEADER="$2"
75 BODY="$3"
76
77 FNAME="/tmp/conftest-$$"
78
79 echo "#include ${HEADER}" > "${FNAME}.c"
80 echo >> "${FNAME}.c"
81 echo "int main()" >> "${FNAME}.c"
82 echo "{" >> "${FNAME}.c"
83 echo "${BODY}" >> "${FNAME}.c"
84 echo " return 0;" >> "${FNAME}.c"
85 echo "}" >> "${FNAME}.c"
86
87 cc -c -o "${FNAME}.o" "${FNAME}.c" 2> "${FNAME}.log"
88 RC="$?"
89
90 if [ "$RC" -ne "0" ] ; then
91 echo " ${DEPENDENCY} not found, too old or compiler error."
92 echo " Please recheck manually the source file \"${FNAME}.c\"."
93 echo " The compilation of the toolchain is probably going to fail,"
94 echo " you have been warned."
95 echo
96 echo " ===== Compiler output ====="
97 cat "${FNAME}.log"
98 echo " ==========================="
99 echo
100 else
101 echo " ${DEPENDENCY} found"
102 rm -f "${FNAME}.log" "${FNAME}.o" "${FNAME}.c"
103 fi
104}
105
106check_dependecies() {
107 echo ">>> Basic dependency check"
108 check_dependency "GMP" "<gmp.h>" "${GMP_MAIN}"
109 check_dependency "MPFR" "<mpfr.h>" "${MPFR_MAIN}"
110 check_dependency "MPC" "<mpc.h>" "${MPC_MAIN}"
111 echo
112}
113
114check_error() {
115 if [ "$1" -ne "0" ]; then
116 echo
117 echo "Script failed: $2"
118
119 exit 1
120 fi
121}
122
123check_md5() {
124 FILE="$1"
125 SUM="$2"
126
127 COMPUTED="`md5sum "${FILE}" | cut -d' ' -f1`"
128 if [ "${SUM}" != "${COMPUTED}" ] ; then
129 echo
130 echo "Checksum of ${FILE} does not match."
131
132 exit 2
133 fi
134}
135
136show_usage() {
137 echo "Cross-compiler toolchain build script"
138 echo
139 echo "Syntax:"
140 echo " $0 [--no-install] <platform>"
141 echo
142 echo "Possible target platforms are:"
143 echo " amd64 AMD64 (x86-64, x64)"
144 echo " arm32 ARM"
145 echo " ia32 IA-32 (x86, i386)"
146 echo " ia64 IA-64 (Itanium)"
147 echo " mips32 MIPS little-endian 32b"
148 echo " mips32eb MIPS big-endian 32b"
149 echo " mips64 MIPS little-endian 64b"
150 echo " ppc32 32-bit PowerPC"
151 echo " ppc64 64-bit PowerPC"
152 echo " sparc64 SPARC V9"
153 echo " all build all targets"
154 echo " parallel same as 'all', but all in parallel"
155 echo " 2-way same as 'all', but 2-way parallel"
156 echo
157 echo "The toolchain is installed into directory specified by the"
158 echo "CROSS_PREFIX environment variable. If the variable is not"
159 echo "defined, /usr/local/cross/ is used as default."
160 echo "If --no-install is present, the toolchain still uses the"
161 echo "CROSS_PREFIX as the target directory but the installation"
162 echo "copies the files into PKG/ subdirectory without affecting"
163 echo "the actual root file system. That is only useful if you do"
164 echo "not want to run the script under the super user."
165 echo
166
167 exit 3
168}
169
170change_title() {
171 echo -en "\e]0;$1\a"
172}
173
174show_countdown() {
175 TM="$1"
176
177 if [ "${TM}" -eq 0 ] ; then
178 echo
179 return 0
180 fi
181
182 echo -n "${TM} "
183 change_title "${TM}"
184 sleep 1
185
186 TM="`expr "${TM}" - 1`"
187 show_countdown "${TM}"
188}
189
190show_dependencies() {
191 echo "IMPORTANT NOTICE:"
192 echo
193 echo "For a successful compilation and use of the cross-compiler"
194 echo "toolchain you need at least the following dependencies."
195 echo
196 echo "Please make sure that the dependencies are present in your"
197 echo "system. Otherwise the compilation process might fail after"
198 echo "a few seconds or minutes."
199 echo
200 echo " - SED, AWK, Flex, Bison, gzip, bzip2, Bourne Shell"
201 echo " - gettext, zlib, Texinfo, libelf, libgomp"
202 echo " - terminfo"
203 echo " - GNU Multiple Precision Library (GMP)"
204 echo " - GNU Make"
205 echo " - GNU tar"
206 echo " - GNU Coreutils"
207 echo " - GNU Sharutils"
208 echo " - MPFR"
209 echo " - MPC"
210 echo " - Parma Polyhedra Library (PPL)"
211 echo " - ClooG-PPL"
212 echo " - native C compiler, assembler and linker"
213 echo " - native C library with headers"
214 echo
215}
216
217download_fetch() {
218 SOURCE="$1"
219 FILE="$2"
220 CHECKSUM="$3"
221
222 if [ ! -f "${FILE}" ]; then
223 change_title "Downloading ${FILE}"
224 wget -c "${SOURCE}${FILE}"
225 check_error $? "Error downloading ${FILE}."
226 fi
227
228 check_md5 "${FILE}" "${CHECKSUM}"
229}
230
231source_check() {
232 FILE="$1"
233
234 if [ ! -f "${FILE}" ]; then
235 echo
236 echo "File ${FILE} not found."
237
238 exit 4
239 fi
240}
241
242cleanup_dir() {
243 DIR="$1"
244
245 if [ -d "${DIR}" ]; then
246 change_title "Removing ${DIR}"
247 echo " >>> Removing ${DIR}"
248 rm -fr "${DIR}"
249 fi
250}
251
252create_dir() {
253 DIR="$1"
254 DESC="$2"
255
256 change_title "Creating ${DESC}"
257 echo ">>> Creating ${DESC}"
258
259 mkdir -p "${DIR}"
260 test -d "${DIR}"
261 check_error $? "Unable to create ${DIR}."
262}
263
264unpack_tarball() {
265 FILE="$1"
266 DESC="$2"
267
268 change_title "Unpacking ${DESC}"
269 echo " >>> Unpacking ${DESC}"
270
271 tar -xjf "${FILE}"
272 check_error $? "Error unpacking ${DESC}."
273}
274
275prepare() {
276 show_dependencies
277 check_dependecies
278 show_countdown 10
279
280 BINUTILS_SOURCE="ftp://ftp.gnu.org/gnu/binutils/"
281 GCC_SOURCE="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"
282 GDB_SOURCE="ftp://ftp.gnu.org/gnu/gdb/"
283
284 download_fetch "${BINUTILS_SOURCE}" "${BINUTILS}" "33adb18c3048d057ac58d07a3f1adb38"
285 download_fetch "${GCC_SOURCE}" "${GCC}" "3b2386c114cd74185aa3754b58a79304"
286 download_fetch "${GDB_SOURCE}" "${GDB}" "fda57170e4d11cdde74259ca575412a8"
287}
288
289build_target() {
290 PLATFORM="$1"
291 TARGET="$2"
292
293 WORKDIR="${BASEDIR}/${PLATFORM}"
294 BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}"
295 GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
296 OBJDIR="${WORKDIR}/gcc-obj"
297 GDBDIR="${WORKDIR}/gdb-${GDB_VERSION}"
298
299 if [ -z "${CROSS_PREFIX}" ] ; then
300 CROSS_PREFIX="/usr/local/cross"
301 fi
302
303 PREFIX="${CROSS_PREFIX}/${PLATFORM}"
304
305 echo ">>> Downloading tarballs"
306 source_check "${BASEDIR}/${BINUTILS}"
307 source_check "${BASEDIR}/${GCC}"
308 source_check "${BASEDIR}/${GDB}"
309
310 echo ">>> Removing previous content"
311 $REAL_INSTALL && cleanup_dir "${PREFIX}"
312 cleanup_dir "${WORKDIR}"
313
314 $REAL_INSTALL && create_dir "${PREFIX}" "destination directory"
315 create_dir "${OBJDIR}" "GCC object directory"
316
317 echo ">>> Unpacking tarballs"
318 cd "${WORKDIR}"
319 check_error $? "Change directory failed."
320
321 unpack_tarball "${BASEDIR}/${BINUTILS}" "binutils"
322 unpack_tarball "${BASEDIR}/${GCC}" "GCC"
323 unpack_tarball "${BASEDIR}/${GDB}" "GDB"
324
325
326 echo ">>> Processing binutils (${PLATFORM})"
327 cd "${BINUTILSDIR}"
328 check_error $? "Change directory failed."
329
330 change_title "binutils: configure (${PLATFORM})"
331 CFLAGS=-Wno-error ./configure \
332 "--target=${TARGET}" \
333 "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" \
334 --disable-nls --disable-werror
335 check_error $? "Error configuring binutils."
336
337 change_title "binutils: make (${PLATFORM})"
338 make all
339 check_error $? "Error compiling binutils."
340
341 change_title "binutils: install (${PLATFORM})"
342 if $REAL_INSTALL; then
343 make install
344 else
345 make install "DESTDIR=${INSTALL_DIR}"
346 fi
347 check_error $? "Error installing binutils."
348
349
350 echo ">>> Processing GCC (${PLATFORM})"
351 cd "${OBJDIR}"
352 check_error $? "Change directory failed."
353
354 change_title "GCC: configure (${PLATFORM})"
355 PATH="$PATH:${INSTALL_DIR}/${PREFIX}/bin" "${GCCDIR}/configure" \
356 "--target=${TARGET}" \
357 "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" \
358 --with-gnu-as --with-gnu-ld --disable-nls --disable-threads \
359 --enable-languages=c,objc,c++,obj-c++ \
360 --disable-multilib --disable-libgcj --without-headers \
361 --disable-shared --enable-lto --disable-werror
362 check_error $? "Error configuring GCC."
363
364 change_title "GCC: make (${PLATFORM})"
365 PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-gcc
366 check_error $? "Error compiling GCC."
367
368 change_title "GCC: install (${PLATFORM})"
369 if $REAL_INSTALL; then
370 PATH="${PATH}:${PREFIX}/bin" make install-gcc
371 else
372 PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-gcc "DESTDIR=${INSTALL_DIR}"
373 fi
374 check_error $? "Error installing GCC."
375
376
377 echo ">>> Processing GDB (${PLATFORM})"
378 cd "${GDBDIR}"
379 check_error $? "Change directory failed."
380
381 change_title "GDB: configure (${PLATFORM})"
382 PATH="$PATH:${INSTALL_DIR}/${PREFIX}/bin" ./configure \
383 "--target=${TARGET}" \
384 "--prefix=${PREFIX}" "--program-prefix=${TARGET}-"
385 check_error $? "Error configuring GDB."
386
387 change_title "GDB: make (${PLATFORM})"
388 PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all
389 check_error $? "Error compiling GDB."
390
391 change_title "GDB: make (${PLATFORM})"
392 if $REAL_INSTALL; then
393 PATH="${PATH}:${PREFIX}/bin" make install
394 else
395 PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install "DESTDIR=${INSTALL_DIR}"
396 fi
397 check_error $? "Error installing GDB."
398
399
400 cd "${BASEDIR}"
401 check_error $? "Change directory failed."
402
403 echo ">>> Cleaning up"
404 cleanup_dir "${WORKDIR}"
405
406 echo
407 echo ">>> Cross-compiler for ${TARGET} installed."
408}
409
410if [ "$1" = "--no-install" ]; then
411 REAL_INSTALL=false
412 shift
413fi
414
415if [ "$#" -lt "1" ]; then
416 show_usage
417fi
418
419case "$1" in
420 "amd64")
421 prepare
422 build_target "amd64" "amd64-linux-gnu"
423 ;;
424 "arm32")
425 prepare
426 build_target "arm32" "arm-linux-gnueabi"
427 ;;
428 "ia32")
429 prepare
430 build_target "ia32" "i686-pc-linux-gnu"
431 ;;
432 "ia64")
433 prepare
434 build_target "ia64" "ia64-pc-linux-gnu"
435 ;;
436 "mips32")
437 prepare
438 build_target "mips32" "mipsel-linux-gnu"
439 ;;
440 "mips32eb")
441 prepare
442 build_target "mips32eb" "mips-linux-gnu"
443 ;;
444 "mips64")
445 prepare
446 build_target "mips64" "mips64el-linux-gnu"
447 ;;
448 "ppc32")
449 prepare
450 build_target "ppc32" "ppc-linux-gnu"
451 ;;
452 "ppc64")
453 prepare
454 build_target "ppc64" "ppc64-linux-gnu"
455 ;;
456 "sparc64")
457 prepare
458 build_target "sparc64" "sparc64-linux-gnu"
459 ;;
460 "all")
461 prepare
462 build_target "amd64" "amd64-linux-gnu"
463 build_target "arm32" "arm-linux-gnueabi"
464 build_target "ia32" "i686-pc-linux-gnu"
465 build_target "ia64" "ia64-pc-linux-gnu"
466 build_target "mips32" "mipsel-linux-gnu"
467 build_target "mips32eb" "mips-linux-gnu"
468 build_target "mips64" "mips64el-linux-gnu"
469 build_target "ppc32" "ppc-linux-gnu"
470 build_target "ppc64" "ppc64-linux-gnu"
471 build_target "sparc64" "sparc64-linux-gnu"
472 ;;
473 "parallel")
474 prepare
475 build_target "amd64" "amd64-linux-gnu" &
476 build_target "arm32" "arm-linux-gnueabi" &
477 build_target "ia32" "i686-pc-linux-gnu" &
478 build_target "ia64" "ia64-pc-linux-gnu" &
479 build_target "mips32" "mipsel-linux-gnu" &
480 build_target "mips32eb" "mips-linux-gnu" &
481 build_target "mips64" "mips64el-linux-gnu" &
482 build_target "ppc32" "ppc-linux-gnu" &
483 build_target "ppc64" "ppc64-linux-gnu" &
484 build_target "sparc64" "sparc64-linux-gnu" &
485 wait
486 ;;
487 "2-way")
488 prepare
489 build_target "amd64" "amd64-linux-gnu" &
490 build_target "arm32" "arm-linux-gnueabi" &
491 wait
492
493 build_target "ia32" "i686-pc-linux-gnu" &
494 build_target "ia64" "ia64-pc-linux-gnu" &
495 wait
496
497 build_target "mips32" "mipsel-linux-gnu" &
498 build_target "mips32eb" "mips-linux-gnu" &
499 wait
500
501 build_target "mips64" "mips64el-linux-gnu" &
502 build_target "ppc32" "ppc-linux-gnu" &
503 wait
504
505 build_target "ppc64" "ppc64-linux-gnu" &
506 build_target "sparc64" "sparc64-linux-gnu" &
507 wait
508 ;;
509 *)
510 show_usage
511 ;;
512esac
Note: See TracBrowser for help on using the repository browser.