Changeset 0b5aa1f0 in mainline
- Timestamp:
- 2023-10-24T16:38:29Z (13 months ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 29ed06d
- Parents:
- cc73f6d4
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2023-10-24 16:25:02)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2023-10-24 16:38:29)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/toolchain.sh
rcc73f6d4 r0b5aa1f0 44 44 SRCDIR="$(readlink -f $(dirname "$0"))" 45 45 46 # If we install into a temporary directory and copy from there, 47 # we don't have to trust the upstream makefiles respect the prefix for 48 # all files, and we also have a ready-made package for distribution. 49 INSTALL_DIR="${BASEDIR}/PKG" 50 46 51 SYSTEM_INSTALL=false 47 REAL_INSTALL=true 48 USE_HELENOS_TARGET=true 52 53 BUILD_GDB=false 54 BUILD_BINUTILS=true 55 BUILD_GCC=true 56 57 if [ -z "$JOBS" ] ; then 58 JOBS="`nproc`" 59 fi 49 60 50 61 check_error() { … … 61 72 echo 62 73 echo "Syntax:" 63 echo " $0 [--system-wide] [-- no-install] [--non-helenos-target] <platform>"74 echo " $0 [--system-wide] [--with-gdb|--only-gdb] <platform>" 64 75 echo " $0 [--system-wide] --test-version [<platform>]" 65 76 echo … … 76 87 echo " sparc64 SPARC V9" 77 88 echo " all build all targets" 78 echo " essential build only targets currently needed for HelenOS development"79 89 echo " parallel same as 'all', but all in parallel" 80 90 echo " 2-way same as 'all', but 2-way parallel" … … 92 102 echo " variable is not set, then the default value of \$HOME/.local/share" 93 103 echo " is assumed." 94 echo95 echo "If the --no-install option is used, the toolchain still uses the"96 echo "target installation directory as determined above, but the files"97 echo "are actually copied into the PKG/ subdirectory during the installation"98 echo "without affecting the actual target file system. This might be useful"99 echo "when preparing a system-wide installation, but avoiding running this"100 echo "script under the super user."101 104 echo 102 105 echo "The --non-helenos-target option will build non-HelenOS-specific" … … 177 180 } 178 181 182 ring_bell() { 183 printf '\a' 184 sleep 0.1 185 printf '\a' 186 sleep 0.1 187 printf '\a' 188 sleep 0.1 189 printf '\a' 190 sleep 0.1 191 printf '\a' 192 } 193 179 194 show_countdown() { 180 195 TM="$1" … … 251 266 check_error $? "Unable to change directory to ${ORIGINAL}." 252 267 253 mkdir -p "${OUTSIDE}" 268 if $SYSTEM_INSTALL && [ ! -d "${OUTSIDE}" ]; then 269 ring_bell 270 ( set -x ; sudo -k mkdir -p "${OUTSIDE}" ) 271 else 272 mkdir -p "${OUTSIDE}" 273 fi 274 254 275 cd "${OUTSIDE}" 255 276 check_error $? "Unable to change directory to ${OUTSIDE}." … … 280 301 change_title "Downloading sources" 281 302 echo ">>> Downloading sources" 282 git clone --depth 1 -b "$BINUTILS_BRANCH" "$BINUTILS_GDB_GIT" "binutils-$BINUTILS_VERSION" 283 git clone --depth 1 -b "$GDB_BRANCH" "$BINUTILS_GDB_GIT" "gdb-$GDB_VERSION" 284 git clone --depth 1 -b "$GCC_BRANCH" "$GCC_GIT" "gcc-$GCC_VERSION" 285 286 # If the directory already existed, pull upstream changes. 287 git -C "binutils-$BINUTILS_VERSION" pull 288 git -C "gdb-$GDB_VERSION" pull 289 git -C "gcc-$GCC_VERSION" pull 290 291 change_title "Downloading GCC prerequisites" 292 echo ">>> Downloading GCC prerequisites" 293 cd "gcc-${GCC_VERSION}" 294 ./contrib/download_prerequisites 295 cd .. 303 304 if $BUILD_BINUTILS ; then 305 git clone --depth 1 -b "$BINUTILS_BRANCH" "$BINUTILS_GDB_GIT" "binutils-$BINUTILS_VERSION" 306 # If the directory already existed, pull upstream changes. 307 git -C "binutils-$BINUTILS_VERSION" pull 308 fi 309 310 if $BUILD_GCC ; then 311 git clone --depth 1 -b "$GCC_BRANCH" "$GCC_GIT" "gcc-$GCC_VERSION" 312 git -C "gcc-$GCC_VERSION" pull 313 314 change_title "Downloading GCC prerequisites" 315 echo ">>> Downloading GCC prerequisites" 316 cd "gcc-${GCC_VERSION}" 317 ./contrib/download_prerequisites 318 cd .. 319 fi 320 321 if $BUILD_GDB ; then 322 git clone --depth 1 -b "$GDB_BRANCH" "$BINUTILS_GDB_GIT" "gdb-$GDB_VERSION" 323 git -C "gdb-$GDB_VERSION" pull 324 fi 325 326 # This sets the CROSS_PREFIX variable 327 set_cross_prefix 328 329 DESTDIR_SPEC="DESTDIR=${INSTALL_DIR}" 296 330 } 297 331 … … 321 355 esac 322 356 323 HELENOS_TARGET="${GNU_ARCH}-helenos" 324 325 case "$1" in 326 "arm32") 327 LINUX_TARGET="${GNU_ARCH}-linux-gnueabi" 328 ;; 329 *) 330 LINUX_TARGET="${GNU_ARCH}-linux-gnu" 331 ;; 332 esac 333 } 334 335 build_target() { 336 PLATFORM="$1" 337 338 # This sets the *_TARGET variables 339 set_target_from_platform "$PLATFORM" 340 if $USE_HELENOS_TARGET ; then 341 TARGET="$HELENOS_TARGET" 342 else 343 TARGET="$LINUX_TARGET" 344 fi 357 TARGET="${GNU_ARCH}-helenos" 358 } 359 360 build_binutils() { 361 # This sets the TARGET variable 362 set_target_from_platform "$1" 345 363 346 364 WORKDIR="${BASEDIR}/${TARGET}" 347 INSTALL_DIR="${BASEDIR}/PKG"348 365 BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}" 349 GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"350 GDBDIR="${WORKDIR}/gdb-${GDB_VERSION}"351 352 # This sets the CROSS_PREFIX variable353 set_cross_prefix354 355 if [ -z "$JOBS" ] ; then356 JOBS="`nproc`"357 fi358 359 PREFIX="${CROSS_PREFIX}"360 366 361 367 echo ">>> Removing previous content" 362 368 cleanup_dir "${WORKDIR}" 363 369 mkdir -p "${WORKDIR}" 364 check_dirs "${PREFIX}" "${WORKDIR}" 365 366 if $USE_HELENOS_TARGET ; then 367 change_title "Creating build sysroot" 368 echo ">>> Creating build sysroot" 369 mkdir -p "${WORKDIR}/sysroot/include" 370 mkdir "${WORKDIR}/sysroot/lib" 371 ARCH="$PLATFORM" 372 if [ "$ARCH" = "mips32eb" ]; then 373 ARCH=mips32 374 fi 375 376 cp -r -L -t "${WORKDIR}/sysroot/include" \ 377 ${SRCDIR}/../abi/include/* \ 378 ${SRCDIR}/../uspace/lib/c/arch/${ARCH}/include/* \ 379 ${SRCDIR}/../uspace/lib/c/include/* 380 check_error $? "Failed to create build sysroot." 381 fi 382 370 check_dirs "${CROSS_PREFIX}" "${WORKDIR}" 383 371 384 372 echo ">>> Processing binutils (${PLATFORM})" … … 390 378 CFLAGS="-Wno-error -fcommon" "${BASEDIR}/downloads/binutils-${BINUTILS_VERSION}/configure" \ 391 379 "--target=${TARGET}" \ 392 "--prefix=${ PREFIX}" \380 "--prefix=${CROSS_PREFIX}" \ 393 381 "--program-prefix=${TARGET}-" \ 394 382 --disable-nls \ … … 405 393 406 394 change_title "binutils: install (${PLATFORM})" 407 make install "DESTDIR=${INSTALL_DIR}"395 make install $DESTDIR_SPEC 408 396 check_error $? "Error installing binutils." 409 397 } 398 399 build_gcc() { 400 # This sets the TARGET variable 401 set_target_from_platform "$1" 402 403 WORKDIR="${BASEDIR}/${TARGET}" 404 GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}" 405 406 echo ">>> Removing previous content" 407 cleanup_dir "${WORKDIR}" 408 mkdir -p "${WORKDIR}" 409 check_dirs "${CROSS_PREFIX}" "${WORKDIR}" 410 410 411 411 echo ">>> Processing GCC (${PLATFORM})" … … 414 414 check_error $? "Change directory failed." 415 415 416 if $USE_HELENOS_TARGET ; then 417 SYSROOT=--with-sysroot --with-build-sysroot="${WORKDIR}/sysroot" 418 else 419 SYSROOT=--without-headers 420 fi 416 BUILDPATH="${CROSS_PREFIX}/bin:${PATH}" 421 417 422 418 change_title "GCC: configure (${PLATFORM})" 423 PATH="$ PATH:${INSTALL_DIR}/${PREFIX}/bin" "${BASEDIR}/downloads/gcc-${GCC_VERSION}/configure" \419 PATH="${BUILDPATH}" "${BASEDIR}/downloads/gcc-${GCC_VERSION}/configure" \ 424 420 "--target=${TARGET}" \ 425 "--prefix=${ PREFIX}" \421 "--prefix=${CROSS_PREFIX}" \ 426 422 "--program-prefix=${TARGET}-" \ 427 423 --with-gnu-as \ … … 432 428 --disable-shared \ 433 429 --disable-werror \ 434 $SYSROOT430 --without-headers # TODO: Replace with proper sysroot so we can build more libs 435 431 check_error $? "Error configuring GCC." 436 432 437 433 change_title "GCC: make (${PLATFORM})" 438 PATH="${ PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-gcc -j$JOBS434 PATH="${BUILDPATH}" make all-gcc -j$JOBS 439 435 check_error $? "Error compiling GCC." 440 436 441 if $USE_HELENOS_TARGET ; then442 PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-target-libgcc -j$JOBS443 check_error $? "Error compiling libgcc."444 # TODO: libatomic and libstdc++ need some extra care445 # PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-target-libatomic -j$JOBS446 # check_error $? "Error compiling libatomic."447 # PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-target-libstdc++-v3 -j$JOBS448 # check_error $? "Error compiling libstdc++."449 fi450 451 437 change_title "GCC: install (${PLATFORM})" 452 PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-gcc "DESTDIR=${INSTALL_DIR}" 453 if $USE_HELENOS_TARGET ; then 454 PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-target-libgcc "DESTDIR=${INSTALL_DIR}" 455 # PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-target-libatomic "DESTDIR=${INSTALL_DIR}" 456 # PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-target-libstdc++-v3 "DESTDIR=${INSTALL_DIR}" 457 fi 438 PATH="${BUILDPATH}" make install-gcc $DESTDIR_SPEC 458 439 check_error $? "Error installing GCC." 459 440 } 441 442 build_libgcc() { 443 # This sets the TARGET variable 444 set_target_from_platform "$1" 445 446 WORKDIR="${BASEDIR}/${TARGET}" 447 GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}" 448 449 # No removing previous content here, we need the previous GCC build 450 451 cd "${GCCDIR}" 452 check_error $? "Change directory failed." 453 454 BUILDPATH="${CROSS_PREFIX}/bin:${PATH}" 455 456 change_title "libgcc: make (${PLATFORM})" 457 458 PATH="${BUILDPATH}" make all-target-libgcc -j$JOBS 459 check_error $? "Error compiling libgcc." 460 # TODO: libatomic and libstdc++ need some extra care 461 # PATH="${BUILDPATH}" make all-target-libatomic -j$JOBS 462 # check_error $? "Error compiling libatomic." 463 # PATH="${BUILDPATH}" make all-target-libstdc++-v3 -j$JOBS 464 # check_error $? "Error compiling libstdc++." 465 466 change_title "libgcc: install (${PLATFORM})" 467 468 PATH="${BUILDPATH}" make install-target-libgcc $DESTDIR_SPEC 469 # PATH="${BUILDPATH}" make install-target-libatomic $DESTDIR_SPEC 470 # PATH="${BUILDPATH}" make install-target-libstdc++-v3 $DESTDIR_SPEC 471 check_error $? "Error installing libgcc." 472 } 473 474 build_gdb() { 475 # This sets the TARGET variable 476 set_target_from_platform "$1" 477 478 WORKDIR="${BASEDIR}/${TARGET}" 479 GDBDIR="${WORKDIR}/gdb-${GDB_VERSION}" 480 481 echo ">>> Removing previous content" 482 cleanup_dir "${WORKDIR}" 483 mkdir -p "${WORKDIR}" 484 check_dirs "${CROSS_PREFIX}" "${WORKDIR}" 460 485 461 486 echo ">>> Processing GDB (${PLATFORM})" … … 465 490 466 491 change_title "GDB: configure (${PLATFORM})" 467 CFLAGS="-fcommon" PATH="$PATH:${INSTALL_DIR}/${PREFIX}/bin""${BASEDIR}/downloads/gdb-${GDB_VERSION}/configure" \492 CFLAGS="-fcommon" "${BASEDIR}/downloads/gdb-${GDB_VERSION}/configure" \ 468 493 "--target=${TARGET}" \ 469 "--prefix=${ PREFIX}" \494 "--prefix=${CROSS_PREFIX}" \ 470 495 "--program-prefix=${TARGET}-" \ 471 496 --enable-werror=no … … 473 498 474 499 change_title "GDB: make (${PLATFORM})" 475 PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin"make all-gdb -j$JOBS500 make all-gdb -j$JOBS 476 501 check_error $? "Error compiling GDB." 477 502 478 change_title "GDB: make(${PLATFORM})"479 PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-gdb "DESTDIR=${INSTALL_DIR}"503 change_title "GDB: install (${PLATFORM})" 504 make install-gdb $DESTDIR_SPEC 480 505 check_error $? "Error installing GDB." 481 506 } 507 508 install_pkg() { 509 echo ">>> Moving to the destination directory." 510 if $SYSTEM_INSTALL ; then 511 ring_bell 512 ( set -x ; sudo -k cp -r -t "${CROSS_PREFIX}" "${INSTALL_DIR}${CROSS_PREFIX}/"* ) 513 else 514 cp -r -t "${CROSS_PREFIX}" "${INSTALL_DIR}${CROSS_PREFIX}/"* 515 fi 516 } 517 518 link_clang() { 482 519 # Symlink clang and lld to the install path. 483 520 CLANG="`which clang 2> /dev/null || echo "/usr/bin/clang"`" 484 521 LLD="`which ld.lld 2> /dev/null || echo "/usr/bin/ld.lld"`" 485 522 486 ln -s $CLANG "${INSTALL_DIR}/${PREFIX}/bin/${TARGET}-clang" 487 ln -s $LLD "${INSTALL_DIR}/${PREFIX}/bin/${TARGET}-ld.lld" 488 489 if $REAL_INSTALL ; then 490 echo ">>> Moving to the destination directory." 491 cp -r -t "${PREFIX}" "${INSTALL_DIR}/${PREFIX}/"* 492 fi 493 494 cd "${BASEDIR}" 495 check_error $? "Change directory failed." 496 497 echo ">>> Cleaning up" 498 cleanup_dir "${WORKDIR}" 499 500 echo 501 echo ">>> Cross-compiler for ${TARGET} installed." 523 ln -s $CLANG "${INSTALL_DIR}${CROSS_PREFIX}/bin/${TARGET}-clang" 524 ln -s $LLD "${INSTALL_DIR}${CROSS_PREFIX}/bin/${TARGET}-ld.lld" 502 525 } 503 526 … … 512 535 exit 513 536 ;; 514 -- no-install)515 REAL_INSTALL=false537 --with-gdb) 538 BUILD_GDB=true 516 539 shift 517 540 ;; 518 --non-helenos-target) 519 USE_HELENOS_TARGET=false 541 --only-gdb) 542 BUILD_GDB=true 543 BUILD_BINUTILS=false 544 BUILD_GCC=false 520 545 shift 521 546 ;; … … 529 554 show_usage 530 555 fi 556 557 PLATFORMS="amd64 arm32 arm64 ia32 ia64 mips32 mips32eb ppc32 riscv64 sparc64" 558 559 run_one() { 560 $1 $PLATFORM 561 } 562 563 run_all() { 564 for x in $PLATFORMS ; do 565 $1 $x 566 done 567 } 568 569 run_parallel() { 570 for x in $PLATFORMS ; do 571 $1 $x & 572 done 573 wait 574 } 575 576 run_2way() { 577 $1 amd64 & 578 $1 arm32 & 579 wait 580 581 $1 arm64 & 582 $1 ia32 & 583 wait 584 585 $1 ia64 & 586 $1 mips32 & 587 wait 588 589 $1 mips32eb & 590 $1 ppc32 & 591 wait 592 593 $1 riscv64 & 594 $1 sparc64 & 595 wait 596 } 597 598 everything() { 599 RUNNER="$1" 600 601 prepare 602 603 if $BUILD_BINUTILS ; then 604 $RUNNER build_binutils 605 606 if $BUILD_GCC ; then 607 # gcc/libgcc may fail to build correctly if binutils is not installed first 608 echo ">>> Installing binutils" 609 install_pkg 610 fi 611 fi 612 613 if $BUILD_GCC ; then 614 $RUNNER build_gcc 615 616 # libgcc may fail to build correctly if gcc is not installed first 617 echo ">>> Installing GCC" 618 install_pkg 619 620 for x in $PLATFORMS ; do 621 build_libgcc $x 622 done 623 fi 624 625 if $BUILD_GDB ; then 626 $RUNNER build_gdb 627 fi 628 629 echo ">>> Installing all files" 630 install_pkg 631 632 link_clang 633 } 531 634 532 635 case "$1" in … … 536 639 ;; 537 640 amd64|arm32|arm64|ia32|ia64|mips32|mips32eb|ppc32|riscv64|sparc64) 538 prepare539 build_target "$1"641 PLATFORM="$1" 642 everything run_one 540 643 ;; 541 644 "all") 542 prepare 543 build_target "amd64" 544 build_target "arm32" 545 build_target "arm64" 546 build_target "ia32" 547 build_target "ia64" 548 build_target "mips32" 549 build_target "mips32eb" 550 build_target "ppc32" 551 build_target "riscv64" 552 build_target "sparc64" 553 ;; 554 "essential") 555 prepare 556 build_target "amd64" 557 build_target "arm32" 558 build_target "arm64" 559 build_target "ia32" 560 build_target "ia64" 561 build_target "mips32" 562 build_target "mips32eb" 563 build_target "ppc32" 564 build_target "sparc64" 645 everything run_all 565 646 ;; 566 647 "parallel") 567 prepare 568 build_target "amd64" & 569 build_target "arm32" & 570 build_target "arm64" & 571 build_target "ia32" & 572 build_target "ia64" & 573 build_target "mips32" & 574 build_target "mips32eb" & 575 build_target "ppc32" & 576 build_target "riscv64" & 577 build_target "sparc64" & 578 wait 648 everything run_parallel 579 649 ;; 580 650 "2-way") 581 prepare 582 build_target "amd64" & 583 build_target "arm32" & 584 wait 585 586 build_target "arm64" & 587 build_target "ia32" & 588 wait 589 590 build_target "ia64" & 591 build_target "mips32" & 592 wait 593 594 build_target "mips32eb" & 595 build_target "ppc32" & 596 wait 597 598 build_target "riscv64" & 599 build_target "sparc64" & 600 wait 651 everything run_2way 601 652 ;; 602 653 *)
Note:
See TracChangeset
for help on using the changeset viewer.