Changeset f3a7b0d in mainline


Ignore:
Timestamp:
2021-04-20T18:21:55Z (3 years ago)
Author:
Martin Decky <martin@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
de227aba
Parents:
6186f9f
Message:

Use more appropriate cross-compiler installation locations

The toolchain.sh and configure.sh scripts use the
$XDG_DATA_HOME/HelenOS/cross (i.e. $HOME/.local/share/HelenOS/cross)
location by default now. This allows the cross-compiler to be
installed without super user privileges and thus hopefully lowers the
entry barrier for newcomers.

To install the cross-compiler to a system-wide location, run the
toolchain.sh script with the —system-wide option. The default
system-wide location is /opt/HelenOS/cross now.

The configure.sh script falls back to /opt/HelenOS/cross and the
previously used /usr/local/cross. Thus recompiling an already
installed cross-compiler toolchain is not necessary.

The possibility to override the cross-compiler location using
$CROSS_PREFIX or having the cross-compiler available in $PATH
retained.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • README.md

    r6186f9f rf3a7b0d  
    3535
    3636In order to build HelenOS, one must first build the cross-compiler toolchain
    37 (either as a root or by specifying the `CROSS_PREFIX` environment variable)
    38 by running (example for the amd64 architecture, further list of targets can be
    39 found in the `default` directory):
     37(the default installation location can be overridden by specifying the
     38`CROSS_PREFIX` environment variable) by running (example for the amd64
     39architecture, further list of targets can be found in the `default` directory):
    4040
    4141```
     
    6161```
    6262# sudo dnf group install 'Development Tools'
    63 # sudo dnf install wget texinfo libmpc-devel mpfr-devel gmp-devel PyYAML genisoimage flex bison
     63# sudo dnf install wget texinfo PyYAML genisoimage flex bison
    6464```
     65
    6566In case the toolchain script won't work no matter how hard you try, let us know.
    6667Please supply as many relevant information (your OS and distribution, list of
  • configure.sh

    r6186f9f rf3a7b0d  
    3939CONFIG_RULES="${SOURCE_DIR}/HelenOS.config"
    4040CONFIG_DEFAULTS="${SOURCE_DIR}/defaults"
    41 
    4241
    4342test "$#" -eq 1 && { test "$1" = "-h" || test "$1" = "--help"; }
     
    8584fi
    8685
    87 if ! which meson; then
     86if ! which meson >/dev/null 2>/dev/null; then
    8887        echo "Your system does not have Meson installed."
    8988        echo 'Please use `pip3 install meson`'
     
    9190fi
    9291
    93 if ! which ninja; then
     92if ! which ninja >/dev/null 2>/dev/null; then
    9493        echo "Your system does not have ninja installed."
    9594        echo 'Please use `pip3 install ninja`'
     
    9897
    9998# Link tools directory for convenience.
    100 ln -s "${SOURCE_DIR}/tools" tools
     99if [ ! -e tools ]; then
     100        ln -s "${SOURCE_DIR}/tools" tools
     101fi
    101102
    102103# Run HelenOS config tool.
     
    122123
    123124compname="$cc_arch-helenos-gcc"
     125unset compprefix
    124126
    125 if which "$compname"; then
     127if which "$compname" >/dev/null 2>/dev/null; then
    126128        # Compiler is in PATH
    127129        compprefix="$cc_arch-helenos-"
    128130
    129131elif [ -n "$CROSS_PREFIX" ]; then
    130         if ! which "$CROSS_PREFIX/bin/$compname"; then
     132        if which "$CROSS_PREFIX/bin/$compname" >/dev/null 2>/dev/null; then
     133                compprefix="$CROSS_PREFIX/bin/$cc_arch-helenos-"
     134        fi
     135
     136        if [ -z "$compprefix" ]; then
    131137                echo "ERROR: \$CROSS_PREFIX defined but $compname is not present in $CROSS_PREFIX/bin."
    132138                echo "Run tools/toolchain.sh to build cross-compiling toolchain."
    133139                exit 1
    134140        fi
     141else
     142        if [ -z "$XDG_DATA_HOME" ]; then
     143                        XDG_DATA_HOME="$HOME/.local/share"
     144        fi
    135145
    136         compprefix="$CROSS_PREFIX/bin/$cc_arch-helenos-"
    137 else
    138         if ! which "/usr/local/cross/bin/$compname"; then
    139                 echo "ERROR: \$CROSS_PREFIX is not defined and $compname is not present in /usr/local/cross/bin."
     146        if which "$XDG_DATA_HOME/HelenOS/cross/bin/$compname" >/dev/null 2>/dev/null; then
     147                compprefix="$XDG_DATA_HOME/HelenOS/cross/bin/$cc_arch-helenos-"
     148        elif which "/opt/HelenOS/cross/bin/$compname" >/dev/null 2>/dev/null; then
     149                compprefix="/opt/HelenOS/cross/bin/$cc_arch-helenos-"
     150        elif which "/usr/local/cross/bin/$compname" >/dev/null 2>/dev/null; then
     151                compprefix="/usr/local/cross/bin/$cc_arch-helenos-"
     152        fi
     153
     154        if [ -z "$compprefix" ]; then
     155                echo "ERROR: \$CROSS_PREFIX is not defined and $compname is not present in any of the following standard locations."
     156                echo " * $XDG_DATA_HOME/HelenOS/cross/bin"
     157                echo " * /opt/HelenOS/cross/bin"
     158                echo " * /usr/local/cross/bin"
    140159                echo "Run tools/toolchain.sh to build cross-compiling toolchain."
    141160                exit 1
    142161        fi
    143 
    144         compprefix="/usr/local/cross/bin/$cc_arch-helenos-"
    145162fi
    146163
  • tools/toolchain.sh

    r6186f9f rf3a7b0d  
    4141GCC_VERSION="8.2.0"
    4242
    43 BASEDIR="`pwd`"
     43BASEDIR="$PWD"
    4444SRCDIR="$(readlink -f $(dirname "$0"))"
    4545
     46SYSTEM_INSTALL=false
    4647REAL_INSTALL=true
    4748USE_HELENOS_TARGET=true
     
    5758
    5859show_usage() {
    59         echo "Cross-compiler toolchain build script"
     60        echo "HelenOS cross-compiler toolchain build script"
    6061        echo
    6162        echo "Syntax:"
    62         echo " $0 [--no-install] [--non-helenos-target] <platform>"
    63         echo " $0 --test-version [<platform>]"
     63        echo " $0 [--system-wide] [--no-install] [--non-helenos-target] <platform>"
     64        echo " $0 [--system-wide] --test-version [<platform>]"
    6465        echo
    6566        echo "Possible target platforms are:"
     
    7980        echo " 2-way      same as 'all', but 2-way parallel"
    8081        echo
    81         echo "The toolchain is installed into directory specified by the"
    82         echo "CROSS_PREFIX environment variable. If the variable is not"
    83         echo "defined, /usr/local/cross/ is used as default."
    84         echo
    85         echo "If --no-install is present, the toolchain still uses the"
    86         echo "CROSS_PREFIX as the target directory but the installation"
    87         echo "copies the files into PKG/ subdirectory without affecting"
    88         echo "the actual root file system. That is only useful if you do"
    89         echo "not want to run the script under the super user."
    90         echo
    91         echo "The --non-helenos-target will build non-HelenOS-specific toolchain"
    92         echo "(i.e. it will use *-linux-* triplet instead of *-helenos)."
     82        echo "The toolchain target installation directory is determined by matching"
     83        echo "the first of the following conditions:"
     84        echo
     85        echo " (1) If the \$CROSS_PREFIX environment variable is set, then it is"
     86        echo "     used as the target installation directory."
     87        echo " (2) If the --system-wide option is used, then /opt/HelenOS/cross"
     88        echo "     is used as the target installation directory. This usually"
     89        echo "     requires running this script with super user privileges."
     90        echo " (3) In other cases, \$XDG_DATA_HOME/HelenOS/cross is used as the"
     91        echo "     target installation directory. If the \$XDG_DATA_HOME environment"
     92        echo "     variable is not set, then the default value of \$HOME/.local/share"
     93        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."
     101        echo
     102        echo "The --non-helenos-target option will build non-HelenOS-specific"
     103        echo "toolchain (i.e. it will use *-linux-* triplet instead of *-helenos)."
    93104        echo "Using this toolchain for building HelenOS is not supported."
    94105        echo
     106        echo "The --test-version mode tests the currently installed version of the"
     107        echo "toolchain."
    95108
    96109        exit 3
    97110}
    98111
     112set_cross_prefix() {
     113        if [ -z "$CROSS_PREFIX" ] ; then
     114                if $SYSTEM_INSTALL ; then
     115                        CROSS_PREFIX="/opt/HelenOS/cross"
     116                else
     117                        if [ -z "$XDG_DATA_HOME" ] ; then
     118                                XDG_DATA_HOME="$HOME/.local/share"
     119                        fi
     120                        CROSS_PREFIX="$XDG_DATA_HOME/HelenOS/cross"
     121                fi
     122        fi
     123}
     124
    99125test_version() {
    100         echo "Cross-compiler toolchain build script"
    101         echo
    102         echo "Start testing the version of the installed software"
    103         echo
    104        
     126        set_cross_prefix
     127
     128        echo "HelenOS cross-compiler toolchain build script"
     129        echo
     130        echo "Testing the version of the installed software in $CROSS_PREFIX"
     131        echo
     132
    105133        if [ -z "$1" ] || [ "$1" = "all" ] ; then
    106134                PLATFORMS='amd64 arm32 arm64 ia32 ia64 mips32 mips32eb ppc32 riscv64 sparc64'
     
    108136                PLATFORMS="$1"
    109137        fi
    110        
    111        
    112         if [ -z "${CROSS_PREFIX}" ] ; then
    113                 CROSS_PREFIX="/usr/local/cross"
    114         fi
    115 
    116         for i in $PLATFORMS
    117         do
    118                 PLATFORM="$i"
     138
     139        for PLATFORM in $PLATFORMS ; do
    119140                set_target_from_platform "$PLATFORM"
    120141                PREFIX="${CROSS_PREFIX}/bin/${HELENOS_TARGET}"
     
    125146                test_app_version "GDB" "gdb" "GNU gdb (.*)[[:space:]]\+\([.0-9]*\)" "$GDB_VERSION"
    126147        done
    127 
    128         exit
    129148}
    130149
     
    135154        INS_VERSION="$4"
    136155
    137 
    138156        APP="${PREFIX}-${APPNAME}"
    139157        if [ ! -e $APP ]; then
     
    148166
    149167                if [ "$INS_VERSION" = "$VERSION" ]; then
    150                         echo "+ $PKGNAME is uptodate ($INS_VERSION)"
     168                        echo "+ $PKGNAME is up-to-date ($INS_VERSION)"
    151169                else
    152170                        echo "- $PKGNAME ($VERSION) is outdated ($INS_VERSION)"
     
    155173}
    156174
    157 
    158 
    159175change_title() {
    160176        printf "\e]0;$1\a"
     
    178194
    179195show_dependencies() {
     196        set_cross_prefix
     197
     198        echo "HelenOS cross-compiler toolchain build script"
     199        echo
     200        echo "Installing software to $CROSS_PREFIX"
     201        echo
     202        echo
    180203        echo "IMPORTANT NOTICE:"
    181204        echo
     
    255278        check_error $? "Change directory failed."
    256279
     280        change_title "Downloading sources"
    257281        echo ">>> Downloading sources"
    258282        git clone --depth 1 -b "$BINUTILS_BRANCH" "$BINUTILS_GDB_GIT" "binutils-$BINUTILS_VERSION"
     
    265289        git -C "gcc-$GCC_VERSION" pull
    266290
     291        change_title "Downloading GCC prerequisites"
    267292        echo ">>> Downloading GCC prerequisites"
    268293        cd "gcc-${GCC_VERSION}"
     
    325350        GDBDIR="${WORKDIR}/gdb-${GDB_VERSION}"
    326351
    327         if [ -z "${CROSS_PREFIX}" ] ; then
    328                 CROSS_PREFIX="/usr/local/cross"
    329         fi
     352        # This sets the CROSS_PREFIX variable
     353        set_cross_prefix
    330354
    331355        if [ -z "$JOBS" ] ; then
    332                 JOBS=`nproc`
     356                JOBS="`nproc`"
    333357        fi
    334358
     
    341365
    342366        if $USE_HELENOS_TARGET ; then
     367                change_title "Creating build sysroot"
    343368                echo ">>> Creating build sysroot"
    344369                mkdir -p "${WORKDIR}/sysroot/include"
     
    355380                check_error $? "Failed to create build sysroot."
    356381        fi
     382
    357383
    358384        echo ">>> Processing binutils (${PLATFORM})"
     
    416442                PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-target-libgcc -j$JOBS
    417443                check_error $? "Error compiling libgcc."
    418                 # TODO: needs some extra care
    419                 #PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-target-libatomic -j$JOBS
    420                 #check_error $? "Error compiling libatomic."
    421                 #PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-target-libstdc++-v3 -j$JOBS
    422                 #check_error $? "Error compiling libstdc++."
     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++."
    423449        fi
    424450
     
    427453        if $USE_HELENOS_TARGET ; then
    428454                PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-target-libgcc "DESTDIR=${INSTALL_DIR}"
    429                 #PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-target-libatomic "DESTDIR=${INSTALL_DIR}"
    430                 #PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-target-libstdc++-v3 "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}"
    431457        fi
    432458        check_error $? "Error installing GCC."
     
    463489        if $REAL_INSTALL ; then
    464490                echo ">>> Moving to the destination directory."
    465                 echo cp -r -t "${PREFIX}" "${INSTALL_DIR}/${PREFIX}/"*
    466491                cp -r -t "${PREFIX}" "${INSTALL_DIR}/${PREFIX}/"*
    467492        fi
     
    479504while [ "$#" -gt 1 ] ; do
    480505        case "$1" in
     506                --system-wide)
     507                        SYSTEM_INSTALL=true
     508                        shift
     509                        ;;
    481510                --test-version)
    482511                        test_version "$2"
     
    504533        --test-version)
    505534                test_version
     535                exit
    506536                ;;
    507537        amd64|arm32|arm64|ia32|ia64|mips32|mips32eb|ppc32|riscv64|sparc64)
Note: See TracChangeset for help on using the changeset viewer.