Changes in tools/toolchain.sh [e6b4d2d:f3a7b0d] in mainline


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/toolchain.sh

    re6b4d2d rf3a7b0d  
    3131BINUTILS_GDB_GIT="https://github.com/HelenOS/binutils-gdb.git"
    3232
    33 BINUTILS_BRANCH="binutils-2_45-helenos"
    34 BINUTILS_VERSION="2.45"
     33BINUTILS_BRANCH="binutils-2_31_1-helenos"
     34BINUTILS_VERSION="2.31.1"
     35
     36GDB_BRANCH="gdb-8_2-helenos"
     37GDB_VERSION="8.2"
    3538
    3639GCC_GIT="https://github.com/HelenOS/gcc.git"
    37 GCC_BRANCH="15_2_0-helenos"
    38 GCC_VERSION="15.2"
     40GCC_BRANCH="8_2_0-helenos"
     41GCC_VERSION="8.2.0"
    3942
    4043BASEDIR="$PWD"
    4144SRCDIR="$(readlink -f $(dirname "$0"))"
    4245
    43 # If we install into a temporary directory and copy from there,
    44 # we don't have to trust the upstream makefiles respect the prefix for
    45 # all files, and we also have a ready-made package for distribution.
    46 INSTALL_DIR="${BASEDIR}/PKG"
    47 
    4846SYSTEM_INSTALL=false
    49 
    50 BUILD_BINUTILS=true
    51 BUILD_GCC=true
    52 
    53 if [ -z "$JOBS" ] ; then
    54         JOBS="`nproc`"
    55 fi
     47REAL_INSTALL=true
     48USE_HELENOS_TARGET=true
    5649
    5750check_error() {
     
    6861        echo
    6962        echo "Syntax:"
     63        echo " $0 [--system-wide] [--no-install] [--non-helenos-target] <platform>"
    7064        echo " $0 [--system-wide] --test-version [<platform>]"
    7165        echo
     
    8276        echo " sparc64    SPARC V9"
    8377        echo " all        build all targets"
     78        echo " essential  build only targets currently needed for HelenOS development"
    8479        echo " parallel   same as 'all', but all in parallel"
    8580        echo " 2-way      same as 'all', but 2-way parallel"
     
    9792        echo "     variable is not set, then the default value of \$HOME/.local/share"
    9893        echo "     is assumed."
     94        echo
     95        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."
    99101        echo
    100102        echo "The --non-helenos-target option will build non-HelenOS-specific"
     
    137139        for PLATFORM in $PLATFORMS ; do
    138140                set_target_from_platform "$PLATFORM"
    139                 PREFIX="${CROSS_PREFIX}/bin/${TARGET}"
     141                PREFIX="${CROSS_PREFIX}/bin/${HELENOS_TARGET}"
    140142
    141143                echo "== $PLATFORM =="
    142144                test_app_version "Binutils" "ld" "GNU ld (.*) \([.0-9]*\)" "$BINUTILS_VERSION"
    143145                test_app_version "GCC" "gcc" "gcc version \([.0-9]*\)" "$GCC_VERSION"
     146                test_app_version "GDB" "gdb" "GNU gdb (.*)[[:space:]]\+\([.0-9]*\)" "$GDB_VERSION"
    144147        done
    145148}
     
    174177}
    175178
    176 ring_bell() {
    177         printf '\a'
    178         sleep 0.1
    179         printf '\a'
    180         sleep 0.1
    181         printf '\a'
    182         sleep 0.1
    183         printf '\a'
    184         sleep 0.1
    185         printf '\a'
    186 }
    187 
    188179show_countdown() {
    189180        TM="$1"
     
    250241
    251242check_dirs() {
    252         cd "${BASEDIR}"
    253         check_error $? "Unable to change directory to ${BASEDIR}."
     243        OUTSIDE="$1"
     244        BASE="$2"
     245        ORIGINAL="$PWD"
     246
     247        cd "${BASE}"
     248        check_error $? "Unable to change directory to ${BASE}."
    254249        ABS_BASE="$PWD"
    255 
    256         if $SYSTEM_INSTALL && [ ! -d "${CROSS_PREFIX}" ]; then
    257                 ring_bell
    258                 ( set -x ; sudo -k mkdir -p "${CROSS_PREFIX}" )
    259         else
    260                 ( set -x ; mkdir -p "${CROSS_PREFIX}" )
    261         fi
    262 
    263         cd "${CROSS_PREFIX}"
    264         check_error $? "Unable to change directory to ${CROSS_PREFIX}."
     250        cd "${ORIGINAL}"
     251        check_error $? "Unable to change directory to ${ORIGINAL}."
     252
     253        mkdir -p "${OUTSIDE}"
     254        cd "${OUTSIDE}"
     255        check_error $? "Unable to change directory to ${OUTSIDE}."
    265256
    266257        while [ "${#PWD}" -gt "${#ABS_BASE}" ]; do
     
    275266        fi
    276267
    277         cd "${BASEDIR}"
     268        cd "${ORIGINAL}"
     269        check_error $? "Unable to change directory to ${ORIGINAL}."
    278270}
    279271
     
    288280        change_title "Downloading sources"
    289281        echo ">>> Downloading sources"
    290 
    291         if $BUILD_BINUTILS ; then
    292                 git clone --depth 1 -b "$BINUTILS_BRANCH" "$BINUTILS_GDB_GIT" "binutils-$BINUTILS_VERSION"
    293                 # If the directory already existed, pull upstream changes.
    294                 git -C "binutils-$BINUTILS_VERSION" pull
    295         fi
    296 
    297         if $BUILD_GCC ; then
    298                 git clone --depth 1 -b "$GCC_BRANCH" "$GCC_GIT" "gcc-$GCC_VERSION"
    299                 git -C "gcc-$GCC_VERSION" pull
    300 
    301                 change_title "Downloading GCC prerequisites"
    302                 echo ">>> Downloading GCC prerequisites"
    303                 cd "gcc-${GCC_VERSION}"
    304                 ./contrib/download_prerequisites
    305                 cd ..
    306         fi
    307 
    308         # This sets the CROSS_PREFIX variable
    309         set_cross_prefix
    310 
    311         DESTDIR_SPEC="DESTDIR=${INSTALL_DIR}"
    312 
    313         check_dirs
     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 ..
    314296}
    315297
     
    339321        esac
    340322
    341         TARGET="${GNU_ARCH}-helenos"
    342 }
    343 
    344 build_binutils() {
    345         # This sets the TARGET variable
    346         set_target_from_platform "$1"
     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
     335build_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
    347345
    348346        WORKDIR="${BASEDIR}/${TARGET}"
     347        INSTALL_DIR="${BASEDIR}/PKG"
    349348        BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}"
     349        GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
     350        GDBDIR="${WORKDIR}/gdb-${GDB_VERSION}"
     351
     352        # This sets the CROSS_PREFIX variable
     353        set_cross_prefix
     354
     355        if [ -z "$JOBS" ] ; then
     356                JOBS="`nproc`"
     357        fi
     358
     359        PREFIX="${CROSS_PREFIX}"
    350360
    351361        echo ">>> Removing previous content"
    352362        cleanup_dir "${WORKDIR}"
    353363        mkdir -p "${WORKDIR}"
    354 
    355         echo ">>> Processing binutils (${TARGET})"
     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
     383
     384        echo ">>> Processing binutils (${PLATFORM})"
    356385        mkdir -p "${BINUTILSDIR}"
    357386        cd "${BINUTILSDIR}"
    358387        check_error $? "Change directory failed."
    359388
    360         change_title "binutils: configure (${TARGET})"
     389        change_title "binutils: configure (${PLATFORM})"
    361390        CFLAGS="-Wno-error -fcommon" "${BASEDIR}/downloads/binutils-${BINUTILS_VERSION}/configure" \
    362391                "--target=${TARGET}" \
    363                 "--prefix=${CROSS_PREFIX}" \
     392                "--prefix=${PREFIX}" \
    364393                "--program-prefix=${TARGET}-" \
    365394                --disable-nls \
    366395                --disable-werror \
    367                 --disable-gold \
     396                --enable-gold \
    368397                --enable-deterministic-archives \
    369398                --disable-gdb \
     
    371400        check_error $? "Error configuring binutils."
    372401
    373         change_title "binutils: make (${TARGET})"
     402        change_title "binutils: make (${PLATFORM})"
    374403        make all -j$JOBS
    375404        check_error $? "Error compiling binutils."
    376405
    377         change_title "binutils: install (${TARGET})"
    378         make install $DESTDIR_SPEC
     406        change_title "binutils: install (${PLATFORM})"
     407        make install "DESTDIR=${INSTALL_DIR}"
    379408        check_error $? "Error installing binutils."
    380 }
    381 
    382 build_gcc() {
    383         # This sets the TARGET variable
    384         set_target_from_platform "$1"
    385 
    386         WORKDIR="${BASEDIR}/${TARGET}"
    387         GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
    388 
    389         echo ">>> Removing previous content"
    390         cleanup_dir "${WORKDIR}"
    391         mkdir -p "${WORKDIR}"
    392 
    393         echo ">>> Processing GCC (${TARGET})"
     409
     410
     411        echo ">>> Processing GCC (${PLATFORM})"
    394412        mkdir -p "${GCCDIR}"
    395413        cd "${GCCDIR}"
    396414        check_error $? "Change directory failed."
    397415
    398         BUILDPATH="${CROSS_PREFIX}/bin:${PATH}"
    399 
    400         change_title "GCC: configure (${TARGET})"
    401         PATH="${BUILDPATH}" "${BASEDIR}/downloads/gcc-${GCC_VERSION}/configure" \
     416        if $USE_HELENOS_TARGET ; then
     417                SYSROOT=--with-sysroot --with-build-sysroot="${WORKDIR}/sysroot"
     418        else
     419                SYSROOT=--without-headers
     420        fi
     421
     422        change_title "GCC: configure (${PLATFORM})"
     423        PATH="$PATH:${INSTALL_DIR}/${PREFIX}/bin" "${BASEDIR}/downloads/gcc-${GCC_VERSION}/configure" \
    402424                "--target=${TARGET}" \
    403                 "--prefix=${CROSS_PREFIX}" \
     425                "--prefix=${PREFIX}" \
    404426                "--program-prefix=${TARGET}-" \
    405427                --with-gnu-as \
     
    408430                --enable-languages=c,c++,go \
    409431                --enable-lto \
    410                 --enable-obsolete \
    411432                --disable-shared \
    412433                --disable-werror \
    413                 --without-headers  # TODO: Replace with proper sysroot so we can build more libs
     434                $SYSROOT
    414435        check_error $? "Error configuring GCC."
    415436
    416         change_title "GCC: make (${TARGET})"
    417         PATH="${BUILDPATH}" make all-gcc -j$JOBS
     437        change_title "GCC: make (${PLATFORM})"
     438        PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-gcc -j$JOBS
    418439        check_error $? "Error compiling GCC."
    419440
    420         change_title "GCC: install (${TARGET})"
    421         PATH="${BUILDPATH}" make install-gcc $DESTDIR_SPEC
     441        if $USE_HELENOS_TARGET ; then
     442                PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-target-libgcc -j$JOBS
     443                check_error $? "Error compiling libgcc."
     444                # TODO: libatomic and libstdc++ need some extra care
     445                #    PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-target-libatomic -j$JOBS
     446                #    check_error $? "Error compiling libatomic."
     447                #    PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-target-libstdc++-v3 -j$JOBS
     448                #    check_error $? "Error compiling libstdc++."
     449        fi
     450
     451        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
    422458        check_error $? "Error installing GCC."
    423 }
    424 
    425 build_libgcc() {
    426         # This sets the TARGET variable
    427         set_target_from_platform "$1"
    428 
    429         WORKDIR="${BASEDIR}/${TARGET}"
    430         GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
    431 
    432         # No removing previous content here, we need the previous GCC build
    433 
    434         cd "${GCCDIR}"
     459
     460
     461        echo ">>> Processing GDB (${PLATFORM})"
     462        mkdir -p "${GDBDIR}"
     463        cd "${GDBDIR}"
    435464        check_error $? "Change directory failed."
    436465
    437         BUILDPATH="${CROSS_PREFIX}/bin:${PATH}"
    438 
    439         change_title "libgcc: make (${TARGET})"
    440 
    441         PATH="${BUILDPATH}" make all-target-libgcc -j$JOBS
    442         check_error $? "Error compiling libgcc."
    443         # TODO: libatomic and libstdc++ need some extra care
    444         #    PATH="${BUILDPATH}" make all-target-libatomic -j$JOBS
    445         #    check_error $? "Error compiling libatomic."
    446         #    PATH="${BUILDPATH}" make all-target-libstdc++-v3 -j$JOBS
    447         #    check_error $? "Error compiling libstdc++."
    448 
    449         change_title "libgcc: install (${TARGET})"
    450 
    451         PATH="${BUILDPATH}" make install-target-libgcc $DESTDIR_SPEC
    452         #    PATH="${BUILDPATH}" make install-target-libatomic $DESTDIR_SPEC
    453         #    PATH="${BUILDPATH}" make install-target-libstdc++-v3 $DESTDIR_SPEC
    454         check_error $? "Error installing libgcc."
    455 }
    456 
    457 install_pkg() {
    458         echo ">>> Moving to the destination directory."
    459         if $SYSTEM_INSTALL ; then
    460                 ring_bell
    461                 ( set -x ; tar -C "${INSTALL_DIR}${CROSS_PREFIX}" -cpf - . | sudo -k tar -C "${CROSS_PREFIX}" -xpf - )
    462         else
    463                 ( set -x ; tar -C "${INSTALL_DIR}${CROSS_PREFIX}" -cpf - . | tar -C "${CROSS_PREFIX}" -xpf - )
    464         fi
    465 }
    466 
    467 link_clang() {
     466        change_title "GDB: configure (${PLATFORM})"
     467        CFLAGS="-fcommon" PATH="$PATH:${INSTALL_DIR}/${PREFIX}/bin" "${BASEDIR}/downloads/gdb-${GDB_VERSION}/configure" \
     468                "--target=${TARGET}" \
     469                "--prefix=${PREFIX}" \
     470                "--program-prefix=${TARGET}-" \
     471                --enable-werror=no
     472        check_error $? "Error configuring GDB."
     473
     474        change_title "GDB: make (${PLATFORM})"
     475        PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-gdb -j$JOBS
     476        check_error $? "Error compiling GDB."
     477
     478        change_title "GDB: make (${PLATFORM})"
     479        PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-gdb "DESTDIR=${INSTALL_DIR}"
     480        check_error $? "Error installing GDB."
     481
    468482        # Symlink clang and lld to the install path.
    469483        CLANG="`which clang 2> /dev/null || echo "/usr/bin/clang"`"
    470         CLANGPP="`which clang++ 2> /dev/null || echo "/usr/bin/clang++"`"
    471484        LLD="`which ld.lld 2> /dev/null || echo "/usr/bin/ld.lld"`"
    472485
    473         ln -s $CLANG "${INSTALL_DIR}${CROSS_PREFIX}/bin/${TARGET}-clang"
    474         ln -s $CLANGPP "${INSTALL_DIR}${CROSS_PREFIX}/bin/${TARGET}-clang++"
    475         ln -s $LLD "${INSTALL_DIR}${CROSS_PREFIX}/bin/${TARGET}-ld.lld"
     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."
    476502}
    477503
     
    486512                        exit
    487513                        ;;
     514                --no-install)
     515                        REAL_INSTALL=false
     516                        shift
     517                        ;;
     518                --non-helenos-target)
     519                        USE_HELENOS_TARGET=false
     520                        shift
     521                        ;;
    488522                *)
    489523                        show_usage
     
    495529        show_usage
    496530fi
    497 
    498 PLATFORMS="amd64 arm32 arm64 ia32 ia64 mips32 mips32eb ppc32 riscv64 sparc64"
    499 
    500 run_one() {
    501         $1 $PLATFORM
    502 }
    503 
    504 run_all() {
    505         for x in $PLATFORMS ; do
    506                 $1 $x
    507         done
    508 }
    509 
    510 run_parallel() {
    511         for x in $PLATFORMS ; do
    512                 $1 $x &
    513         done
    514         wait
    515 }
    516 
    517 run_2way() {
    518         $1 amd64 &
    519         $1 arm32 &
    520         wait
    521 
    522         $1 arm64 &
    523         $1 ia32 &
    524         wait
    525 
    526         $1 ia64 &
    527         $1 mips32 &
    528         wait
    529 
    530         $1 mips32eb &
    531         $1 ppc32 &
    532         wait
    533 
    534         $1 riscv64 &
    535         $1 sparc64 &
    536         wait
    537 }
    538 
    539 everything() {
    540         RUNNER="$1"
    541 
    542         prepare
    543 
    544         if $BUILD_BINUTILS ; then
    545                 $RUNNER build_binutils
    546 
    547                 if $BUILD_GCC ; then
    548                         # gcc/libgcc may fail to build correctly if binutils is not installed first
    549                         echo ">>> Installing binutils"
    550                         install_pkg
    551                 fi
    552         fi
    553 
    554         if $BUILD_GCC ; then
    555                 $RUNNER build_gcc
    556 
    557                 # libgcc may fail to build correctly if gcc is not installed first
    558                 echo ">>> Installing GCC"
    559                 install_pkg
    560 
    561                 $RUNNER build_libgcc
    562         fi
    563 
    564         echo ">>> Installing all files"
    565         install_pkg
    566 
    567         link_clang
    568 }
    569531
    570532case "$1" in
     
    574536                ;;
    575537        amd64|arm32|arm64|ia32|ia64|mips32|mips32eb|ppc32|riscv64|sparc64)
    576                 PLATFORM="$1"
    577                 everything run_one
     538                prepare
     539                build_target "$1"
    578540                ;;
    579541        "all")
    580                 everything run_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"
    581565                ;;
    582566        "parallel")
    583                 everything run_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
    584579                ;;
    585580        "2-way")
    586                 everything run_2way
     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
    587601                ;;
    588602        *)
Note: See TracChangeset for help on using the changeset viewer.