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


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/toolchain.sh

    rf3a7b0d re6b4d2d  
    3131BINUTILS_GDB_GIT="https://github.com/HelenOS/binutils-gdb.git"
    3232
    33 BINUTILS_BRANCH="binutils-2_31_1-helenos"
    34 BINUTILS_VERSION="2.31.1"
    35 
    36 GDB_BRANCH="gdb-8_2-helenos"
    37 GDB_VERSION="8.2"
     33BINUTILS_BRANCH="binutils-2_45-helenos"
     34BINUTILS_VERSION="2.45"
    3835
    3936GCC_GIT="https://github.com/HelenOS/gcc.git"
    40 GCC_BRANCH="8_2_0-helenos"
    41 GCC_VERSION="8.2.0"
     37GCC_BRANCH="15_2_0-helenos"
     38GCC_VERSION="15.2"
    4239
    4340BASEDIR="$PWD"
    4441SRCDIR="$(readlink -f $(dirname "$0"))"
    4542
     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.
     46INSTALL_DIR="${BASEDIR}/PKG"
     47
    4648SYSTEM_INSTALL=false
    47 REAL_INSTALL=true
    48 USE_HELENOS_TARGET=true
     49
     50BUILD_BINUTILS=true
     51BUILD_GCC=true
     52
     53if [ -z "$JOBS" ] ; then
     54        JOBS="`nproc`"
     55fi
    4956
    5057check_error() {
     
    6168        echo
    6269        echo "Syntax:"
    63         echo " $0 [--system-wide] [--no-install] [--non-helenos-target] <platform>"
    6470        echo " $0 [--system-wide] --test-version [<platform>]"
    6571        echo
     
    7682        echo " sparc64    SPARC V9"
    7783        echo " all        build all targets"
    78         echo " essential  build only targets currently needed for HelenOS development"
    7984        echo " parallel   same as 'all', but all in parallel"
    8085        echo " 2-way      same as 'all', but 2-way parallel"
     
    9297        echo "     variable is not set, then the default value of \$HOME/.local/share"
    9398        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."
    10199        echo
    102100        echo "The --non-helenos-target option will build non-HelenOS-specific"
     
    139137        for PLATFORM in $PLATFORMS ; do
    140138                set_target_from_platform "$PLATFORM"
    141                 PREFIX="${CROSS_PREFIX}/bin/${HELENOS_TARGET}"
     139                PREFIX="${CROSS_PREFIX}/bin/${TARGET}"
    142140
    143141                echo "== $PLATFORM =="
    144142                test_app_version "Binutils" "ld" "GNU ld (.*) \([.0-9]*\)" "$BINUTILS_VERSION"
    145143                test_app_version "GCC" "gcc" "gcc version \([.0-9]*\)" "$GCC_VERSION"
    146                 test_app_version "GDB" "gdb" "GNU gdb (.*)[[:space:]]\+\([.0-9]*\)" "$GDB_VERSION"
    147144        done
    148145}
     
    177174}
    178175
     176ring_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
    179188show_countdown() {
    180189        TM="$1"
     
    241250
    242251check_dirs() {
    243         OUTSIDE="$1"
    244         BASE="$2"
    245         ORIGINAL="$PWD"
    246 
    247         cd "${BASE}"
    248         check_error $? "Unable to change directory to ${BASE}."
     252        cd "${BASEDIR}"
     253        check_error $? "Unable to change directory to ${BASEDIR}."
    249254        ABS_BASE="$PWD"
    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}."
     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}."
    256265
    257266        while [ "${#PWD}" -gt "${#ABS_BASE}" ]; do
     
    266275        fi
    267276
    268         cd "${ORIGINAL}"
    269         check_error $? "Unable to change directory to ${ORIGINAL}."
     277        cd "${BASEDIR}"
    270278}
    271279
     
    280288        change_title "Downloading sources"
    281289        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 ..
     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
    296314}
    297315
     
    321339        esac
    322340
    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
     341        TARGET="${GNU_ARCH}-helenos"
     342}
     343
     344build_binutils() {
     345        # This sets the TARGET variable
     346        set_target_from_platform "$1"
    345347
    346348        WORKDIR="${BASEDIR}/${TARGET}"
    347         INSTALL_DIR="${BASEDIR}/PKG"
    348349        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}"
    360350
    361351        echo ">>> Removing previous content"
    362352        cleanup_dir "${WORKDIR}"
    363353        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 
    383 
    384         echo ">>> Processing binutils (${PLATFORM})"
     354
     355        echo ">>> Processing binutils (${TARGET})"
    385356        mkdir -p "${BINUTILSDIR}"
    386357        cd "${BINUTILSDIR}"
    387358        check_error $? "Change directory failed."
    388359
    389         change_title "binutils: configure (${PLATFORM})"
     360        change_title "binutils: configure (${TARGET})"
    390361        CFLAGS="-Wno-error -fcommon" "${BASEDIR}/downloads/binutils-${BINUTILS_VERSION}/configure" \
    391362                "--target=${TARGET}" \
    392                 "--prefix=${PREFIX}" \
     363                "--prefix=${CROSS_PREFIX}" \
    393364                "--program-prefix=${TARGET}-" \
    394365                --disable-nls \
    395366                --disable-werror \
    396                 --enable-gold \
     367                --disable-gold \
    397368                --enable-deterministic-archives \
    398369                --disable-gdb \
     
    400371        check_error $? "Error configuring binutils."
    401372
    402         change_title "binutils: make (${PLATFORM})"
     373        change_title "binutils: make (${TARGET})"
    403374        make all -j$JOBS
    404375        check_error $? "Error compiling binutils."
    405376
    406         change_title "binutils: install (${PLATFORM})"
    407         make install "DESTDIR=${INSTALL_DIR}"
     377        change_title "binutils: install (${TARGET})"
     378        make install $DESTDIR_SPEC
    408379        check_error $? "Error installing binutils."
    409 
    410 
    411         echo ">>> Processing GCC (${PLATFORM})"
     380}
     381
     382build_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})"
    412394        mkdir -p "${GCCDIR}"
    413395        cd "${GCCDIR}"
    414396        check_error $? "Change directory failed."
    415397
    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" \
     398        BUILDPATH="${CROSS_PREFIX}/bin:${PATH}"
     399
     400        change_title "GCC: configure (${TARGET})"
     401        PATH="${BUILDPATH}" "${BASEDIR}/downloads/gcc-${GCC_VERSION}/configure" \
    424402                "--target=${TARGET}" \
    425                 "--prefix=${PREFIX}" \
     403                "--prefix=${CROSS_PREFIX}" \
    426404                "--program-prefix=${TARGET}-" \
    427405                --with-gnu-as \
     
    430408                --enable-languages=c,c++,go \
    431409                --enable-lto \
     410                --enable-obsolete \
    432411                --disable-shared \
    433412                --disable-werror \
    434                 $SYSROOT
     413                --without-headers  # TODO: Replace with proper sysroot so we can build more libs
    435414        check_error $? "Error configuring GCC."
    436415
    437         change_title "GCC: make (${PLATFORM})"
    438         PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-gcc -j$JOBS
     416        change_title "GCC: make (${TARGET})"
     417        PATH="${BUILDPATH}" make all-gcc -j$JOBS
    439418        check_error $? "Error compiling GCC."
    440419
    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
     420        change_title "GCC: install (${TARGET})"
     421        PATH="${BUILDPATH}" make install-gcc $DESTDIR_SPEC
    458422        check_error $? "Error installing GCC."
    459 
    460 
    461         echo ">>> Processing GDB (${PLATFORM})"
    462         mkdir -p "${GDBDIR}"
    463         cd "${GDBDIR}"
     423}
     424
     425build_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}"
    464435        check_error $? "Change directory failed."
    465436
    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 
     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
     457install_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
     467link_clang() {
    482468        # Symlink clang and lld to the install path.
    483469        CLANG="`which clang 2> /dev/null || echo "/usr/bin/clang"`"
     470        CLANGPP="`which clang++ 2> /dev/null || echo "/usr/bin/clang++"`"
    484471        LLD="`which ld.lld 2> /dev/null || echo "/usr/bin/ld.lld"`"
    485472
    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."
     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"
    502476}
    503477
     
    512486                        exit
    513487                        ;;
    514                 --no-install)
    515                         REAL_INSTALL=false
    516                         shift
    517                         ;;
    518                 --non-helenos-target)
    519                         USE_HELENOS_TARGET=false
    520                         shift
    521                         ;;
    522488                *)
    523489                        show_usage
     
    529495        show_usage
    530496fi
     497
     498PLATFORMS="amd64 arm32 arm64 ia32 ia64 mips32 mips32eb ppc32 riscv64 sparc64"
     499
     500run_one() {
     501        $1 $PLATFORM
     502}
     503
     504run_all() {
     505        for x in $PLATFORMS ; do
     506                $1 $x
     507        done
     508}
     509
     510run_parallel() {
     511        for x in $PLATFORMS ; do
     512                $1 $x &
     513        done
     514        wait
     515}
     516
     517run_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
     539everything() {
     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}
    531569
    532570case "$1" in
     
    536574                ;;
    537575        amd64|arm32|arm64|ia32|ia64|mips32|mips32eb|ppc32|riscv64|sparc64)
    538                 prepare
    539                 build_target "$1"
     576                PLATFORM="$1"
     577                everything run_one
    540578                ;;
    541579        "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"
     580                everything run_all
    565581                ;;
    566582        "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
     583                everything run_parallel
    579584                ;;
    580585        "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
     586                everything run_2way
    601587                ;;
    602588        *)
Note: See TracChangeset for help on using the changeset viewer.