source: mainline/tools/toolchain.sh@ 1fd2f81

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1fd2f81 was 0f6b50f, checked in by Petr Manek <petr.manek@…>, 8 years ago

Added DDF device to HCD initialization to prepare RH data structures before it is started.

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