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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5b89d43b was 12735849, checked in by Martin Sucha <sucha14@…>, 12 years ago

Read toolchain patches from the correct directory.

When running toolchain.sh with current directory other than tools
subdirectory of the HelenOS sources, the script was unable to
correctly read toolchain patches, as it was trying to read them
from BASEDIR (i.e. the current working directory when running
the script).

This changeset explicitly uses path to the patches relative to
the location of the directory where the toolchain script resides
(the newly introduced SRCDIR variable).

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