[40c0483] | 1 | #!/bin/sh
|
---|
[ff211d2] | 2 |
|
---|
| 3 | #
|
---|
[04c3a21f] | 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.
|
---|
[ff211d2] | 29 | #
|
---|
| 30 |
|
---|
[232ec3a1] | 31 | BINUTILS_GDB_GIT="https://github.com/HelenOS/binutils-gdb.git"
|
---|
| 32 |
|
---|
[56210a7a] | 33 | BINUTILS_BRANCH="binutils-2_43-helenos"
|
---|
| 34 | BINUTILS_VERSION="2.43"
|
---|
[232ec3a1] | 35 |
|
---|
[1152c18d] | 36 | GDB_BRANCH="gdb-13.2-helenos"
|
---|
| 37 | GDB_VERSION="13.2"
|
---|
[603c8740] | 38 |
|
---|
[232ec3a1] | 39 | GCC_GIT="https://github.com/HelenOS/gcc.git"
|
---|
[56210a7a] | 40 | GCC_BRANCH="14_2_0-helenos"
|
---|
| 41 | GCC_VERSION="14.2"
|
---|
[232ec3a1] | 42 |
|
---|
[f3a7b0d] | 43 | BASEDIR="$PWD"
|
---|
[12735849] | 44 | SRCDIR="$(readlink -f $(dirname "$0"))"
|
---|
[603c8740] | 45 |
|
---|
[0b5aa1f0] | 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 |
|
---|
[f3a7b0d] | 51 | SYSTEM_INSTALL=false
|
---|
[0b5aa1f0] | 52 |
|
---|
| 53 | BUILD_GDB=false
|
---|
| 54 | BUILD_BINUTILS=true
|
---|
| 55 | BUILD_GCC=true
|
---|
| 56 |
|
---|
| 57 | if [ -z "$JOBS" ] ; then
|
---|
| 58 | JOBS="`nproc`"
|
---|
| 59 | fi
|
---|
[3f7efa79] | 60 |
|
---|
[ff211d2] | 61 | check_error() {
|
---|
[75b24cd] | 62 | if [ "$1" -ne "0" ] ; then
|
---|
[ff211d2] | 63 | echo
|
---|
| 64 | echo "Script failed: $2"
|
---|
[a35b458] | 65 |
|
---|
[ff211d2] | 66 | exit 1
|
---|
| 67 | fi
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | show_usage() {
|
---|
[f3a7b0d] | 71 | echo "HelenOS cross-compiler toolchain build script"
|
---|
[ff211d2] | 72 | echo
|
---|
| 73 | echo "Syntax:"
|
---|
[0b5aa1f0] | 74 | echo " $0 [--system-wide] [--with-gdb|--only-gdb] <platform>"
|
---|
[f3a7b0d] | 75 | echo " $0 [--system-wide] --test-version [<platform>]"
|
---|
[ff211d2] | 76 | echo
|
---|
| 77 | echo "Possible target platforms are:"
|
---|
[f2f89315] | 78 | echo " amd64 AMD64 (x86-64, x64)"
|
---|
[d2bd00f0] | 79 | echo " arm32 ARM 32b"
|
---|
[c7c3508] | 80 | echo " arm64 AArch64"
|
---|
[ff211d2] | 81 | echo " ia32 IA-32 (x86, i386)"
|
---|
| 82 | echo " ia64 IA-64 (Itanium)"
|
---|
[71e3289] | 83 | echo " mips32 MIPS little-endian 32b"
|
---|
| 84 | echo " mips32eb MIPS big-endian 32b"
|
---|
[d2bd00f0] | 85 | echo " ppc32 PowerPC 32b"
|
---|
| 86 | echo " riscv64 RISC-V 64b"
|
---|
[f2f89315] | 87 | echo " sparc64 SPARC V9"
|
---|
[ff211d2] | 88 | echo " all build all targets"
|
---|
[6abb346] | 89 | echo " parallel same as 'all', but all in parallel"
|
---|
| 90 | echo " 2-way same as 'all', but 2-way parallel"
|
---|
[ff211d2] | 91 | echo
|
---|
[f3a7b0d] | 92 | echo "The toolchain target installation directory is determined by matching"
|
---|
| 93 | echo "the first of the following conditions:"
|
---|
[5a65d29] | 94 | echo
|
---|
[f3a7b0d] | 95 | echo " (1) If the \$CROSS_PREFIX environment variable is set, then it is"
|
---|
| 96 | echo " used as the target installation directory."
|
---|
| 97 | echo " (2) If the --system-wide option is used, then /opt/HelenOS/cross"
|
---|
| 98 | echo " is used as the target installation directory. This usually"
|
---|
| 99 | echo " requires running this script with super user privileges."
|
---|
| 100 | echo " (3) In other cases, \$XDG_DATA_HOME/HelenOS/cross is used as the"
|
---|
| 101 | echo " target installation directory. If the \$XDG_DATA_HOME environment"
|
---|
| 102 | echo " variable is not set, then the default value of \$HOME/.local/share"
|
---|
| 103 | echo " is assumed."
|
---|
[38eaf41] | 104 | echo
|
---|
[f3a7b0d] | 105 | echo "The --non-helenos-target option will build non-HelenOS-specific"
|
---|
| 106 | echo "toolchain (i.e. it will use *-linux-* triplet instead of *-helenos)."
|
---|
[bbe5e34] | 107 | echo "Using this toolchain for building HelenOS is not supported."
|
---|
[38eaf41] | 108 | echo
|
---|
[f3a7b0d] | 109 | echo "The --test-version mode tests the currently installed version of the"
|
---|
| 110 | echo "toolchain."
|
---|
[a35b458] | 111 |
|
---|
[ff211d2] | 112 | exit 3
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[f3a7b0d] | 115 | set_cross_prefix() {
|
---|
| 116 | if [ -z "$CROSS_PREFIX" ] ; then
|
---|
| 117 | if $SYSTEM_INSTALL ; then
|
---|
| 118 | CROSS_PREFIX="/opt/HelenOS/cross"
|
---|
| 119 | else
|
---|
| 120 | if [ -z "$XDG_DATA_HOME" ] ; then
|
---|
| 121 | XDG_DATA_HOME="$HOME/.local/share"
|
---|
| 122 | fi
|
---|
| 123 | CROSS_PREFIX="$XDG_DATA_HOME/HelenOS/cross"
|
---|
| 124 | fi
|
---|
| 125 | fi
|
---|
| 126 | }
|
---|
| 127 |
|
---|
[4aba581] | 128 | test_version() {
|
---|
[f3a7b0d] | 129 | set_cross_prefix
|
---|
| 130 |
|
---|
| 131 | echo "HelenOS cross-compiler toolchain build script"
|
---|
[4aba581] | 132 | echo
|
---|
[f3a7b0d] | 133 | echo "Testing the version of the installed software in $CROSS_PREFIX"
|
---|
[4aba581] | 134 | echo
|
---|
[f3a7b0d] | 135 |
|
---|
[40c0483] | 136 | if [ -z "$1" ] || [ "$1" = "all" ] ; then
|
---|
| 137 | PLATFORMS='amd64 arm32 arm64 ia32 ia64 mips32 mips32eb ppc32 riscv64 sparc64'
|
---|
[cb15b49c] | 138 | else
|
---|
[40c0483] | 139 | PLATFORMS="$1"
|
---|
[cb15b49c] | 140 | fi
|
---|
[4aba581] | 141 |
|
---|
[f3a7b0d] | 142 | for PLATFORM in $PLATFORMS ; do
|
---|
[4aba581] | 143 | set_target_from_platform "$PLATFORM"
|
---|
[3e05a69] | 144 | PREFIX="${CROSS_PREFIX}/bin/${TARGET}"
|
---|
[4aba581] | 145 |
|
---|
| 146 | echo "== $PLATFORM =="
|
---|
[40c0483] | 147 | test_app_version "Binutils" "ld" "GNU ld (.*) \([.0-9]*\)" "$BINUTILS_VERSION"
|
---|
| 148 | test_app_version "GCC" "gcc" "gcc version \([.0-9]*\)" "$GCC_VERSION"
|
---|
| 149 | test_app_version "GDB" "gdb" "GNU gdb (.*)[[:space:]]\+\([.0-9]*\)" "$GDB_VERSION"
|
---|
[4aba581] | 150 | done
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | test_app_version() {
|
---|
| 154 | PKGNAME="$1"
|
---|
| 155 | APPNAME="$2"
|
---|
| 156 | REGEX="$3"
|
---|
| 157 | INS_VERSION="$4"
|
---|
| 158 |
|
---|
| 159 | APP="${PREFIX}-${APPNAME}"
|
---|
| 160 | if [ ! -e $APP ]; then
|
---|
| 161 | echo "- $PKGNAME is missing"
|
---|
| 162 | else
|
---|
[40c0483] | 163 | VERSION=`${APP} -v 2>&1 | sed -n "s:^${REGEX}.*:\1:p"`
|
---|
| 164 |
|
---|
| 165 | if [ -z "$VERSION" ]; then
|
---|
| 166 | echo "- $PKGNAME Unexpected output"
|
---|
| 167 | return 1
|
---|
| 168 | fi
|
---|
| 169 |
|
---|
| 170 | if [ "$INS_VERSION" = "$VERSION" ]; then
|
---|
[f3a7b0d] | 171 | echo "+ $PKGNAME is up-to-date ($INS_VERSION)"
|
---|
[40c0483] | 172 | else
|
---|
| 173 | echo "- $PKGNAME ($VERSION) is outdated ($INS_VERSION)"
|
---|
| 174 | fi
|
---|
[4aba581] | 175 | fi
|
---|
| 176 | }
|
---|
| 177 |
|
---|
[3fe57ea7] | 178 | change_title() {
|
---|
[40c0483] | 179 | printf "\e]0;$1\a"
|
---|
[3fe57ea7] | 180 | }
|
---|
| 181 |
|
---|
[0b5aa1f0] | 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 |
|
---|
[3fe57ea7] | 194 | show_countdown() {
|
---|
| 195 | TM="$1"
|
---|
[a35b458] | 196 |
|
---|
[3fe57ea7] | 197 | if [ "${TM}" -eq 0 ] ; then
|
---|
| 198 | echo
|
---|
| 199 | return 0
|
---|
| 200 | fi
|
---|
[a35b458] | 201 |
|
---|
[40c0483] | 202 | printf "${TM} "
|
---|
[3fe57ea7] | 203 | change_title "${TM}"
|
---|
| 204 | sleep 1
|
---|
[a35b458] | 205 |
|
---|
[3fe57ea7] | 206 | TM="`expr "${TM}" - 1`"
|
---|
| 207 | show_countdown "${TM}"
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | show_dependencies() {
|
---|
[f3a7b0d] | 211 | set_cross_prefix
|
---|
| 212 |
|
---|
| 213 | echo "HelenOS cross-compiler toolchain build script"
|
---|
| 214 | echo
|
---|
| 215 | echo "Installing software to $CROSS_PREFIX"
|
---|
| 216 | echo
|
---|
| 217 | echo
|
---|
[3fe57ea7] | 218 | echo "IMPORTANT NOTICE:"
|
---|
| 219 | echo
|
---|
| 220 | echo "For a successful compilation and use of the cross-compiler"
|
---|
| 221 | echo "toolchain you need at least the following dependencies."
|
---|
| 222 | echo
|
---|
| 223 | echo "Please make sure that the dependencies are present in your"
|
---|
| 224 | echo "system. Otherwise the compilation process might fail after"
|
---|
| 225 | echo "a few seconds or minutes."
|
---|
| 226 | echo
|
---|
| 227 | echo " - SED, AWK, Flex, Bison, gzip, bzip2, Bourne Shell"
|
---|
| 228 | echo " - gettext, zlib, Texinfo, libelf, libgomp"
|
---|
[f6017ee] | 229 | echo " - GNU Make, Coreutils, Sharutils, tar"
|
---|
| 230 | echo " - native C and C++ compiler, assembler and linker"
|
---|
| 231 | echo " - native C and C++ standard library with headers"
|
---|
[3fe57ea7] | 232 | echo
|
---|
| 233 | }
|
---|
| 234 |
|
---|
[ff211d2] | 235 | cleanup_dir() {
|
---|
| 236 | DIR="$1"
|
---|
[a35b458] | 237 |
|
---|
[75b24cd] | 238 | if [ -d "${DIR}" ] ; then
|
---|
[3fe57ea7] | 239 | change_title "Removing ${DIR}"
|
---|
[ff211d2] | 240 | echo " >>> Removing ${DIR}"
|
---|
| 241 | rm -fr "${DIR}"
|
---|
| 242 | fi
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | create_dir() {
|
---|
| 246 | DIR="$1"
|
---|
| 247 | DESC="$2"
|
---|
[a35b458] | 248 |
|
---|
[3fe57ea7] | 249 | change_title "Creating ${DESC}"
|
---|
[ff211d2] | 250 | echo ">>> Creating ${DESC}"
|
---|
[a35b458] | 251 |
|
---|
[ff211d2] | 252 | mkdir -p "${DIR}"
|
---|
| 253 | test -d "${DIR}"
|
---|
| 254 | check_error $? "Unable to create ${DIR}."
|
---|
| 255 | }
|
---|
| 256 |
|
---|
[285589b] | 257 | check_dirs() {
|
---|
[85b41bc] | 258 | cd "${BASEDIR}"
|
---|
| 259 | check_error $? "Unable to change directory to ${BASEDIR}."
|
---|
[40c0483] | 260 | ABS_BASE="$PWD"
|
---|
[a35b458] | 261 |
|
---|
[85b41bc] | 262 | if $SYSTEM_INSTALL && [ ! -d "${CROSS_PREFIX}" ]; then
|
---|
[0b5aa1f0] | 263 | ring_bell
|
---|
[85b41bc] | 264 | ( set -x ; sudo -k mkdir -p "${CROSS_PREFIX}" )
|
---|
[0b5aa1f0] | 265 | else
|
---|
[85b41bc] | 266 | mkdir -p "${CROSS_PREFIX}"
|
---|
[0b5aa1f0] | 267 | fi
|
---|
| 268 |
|
---|
[85b41bc] | 269 | cd "${CROSS_PREFIX}"
|
---|
| 270 | check_error $? "Unable to change directory to ${CROSS_PREFIX}."
|
---|
[40c0483] | 271 |
|
---|
| 272 | while [ "${#PWD}" -gt "${#ABS_BASE}" ]; do
|
---|
| 273 | cd ..
|
---|
| 274 | done
|
---|
[a35b458] | 275 |
|
---|
[40c0483] | 276 | if [ "$PWD" = "$ABS_BASE" ]; then
|
---|
[285589b] | 277 | echo
|
---|
| 278 | echo "CROSS_PREFIX cannot reside within the working directory."
|
---|
[a35b458] | 279 |
|
---|
[285589b] | 280 | exit 5
|
---|
| 281 | fi
|
---|
[40c0483] | 282 |
|
---|
[85b41bc] | 283 | cd "${BASEDIR}"
|
---|
[285589b] | 284 | }
|
---|
| 285 |
|
---|
[603c8740] | 286 | prepare() {
|
---|
| 287 | show_dependencies
|
---|
| 288 | show_countdown 10
|
---|
[a35b458] | 289 |
|
---|
[530f2de] | 290 | mkdir -p "${BASEDIR}/downloads"
|
---|
| 291 | cd "${BASEDIR}/downloads"
|
---|
| 292 | check_error $? "Change directory failed."
|
---|
| 293 |
|
---|
[f3a7b0d] | 294 | change_title "Downloading sources"
|
---|
[232ec3a1] | 295 | echo ">>> Downloading sources"
|
---|
[0b5aa1f0] | 296 |
|
---|
| 297 | if $BUILD_BINUTILS ; then
|
---|
| 298 | git clone --depth 1 -b "$BINUTILS_BRANCH" "$BINUTILS_GDB_GIT" "binutils-$BINUTILS_VERSION"
|
---|
| 299 | # If the directory already existed, pull upstream changes.
|
---|
| 300 | git -C "binutils-$BINUTILS_VERSION" pull
|
---|
| 301 | fi
|
---|
| 302 |
|
---|
| 303 | if $BUILD_GCC ; then
|
---|
| 304 | git clone --depth 1 -b "$GCC_BRANCH" "$GCC_GIT" "gcc-$GCC_VERSION"
|
---|
| 305 | git -C "gcc-$GCC_VERSION" pull
|
---|
| 306 |
|
---|
| 307 | change_title "Downloading GCC prerequisites"
|
---|
| 308 | echo ">>> Downloading GCC prerequisites"
|
---|
| 309 | cd "gcc-${GCC_VERSION}"
|
---|
| 310 | ./contrib/download_prerequisites
|
---|
| 311 | cd ..
|
---|
| 312 | fi
|
---|
| 313 |
|
---|
| 314 | if $BUILD_GDB ; then
|
---|
| 315 | git clone --depth 1 -b "$GDB_BRANCH" "$BINUTILS_GDB_GIT" "gdb-$GDB_VERSION"
|
---|
| 316 | git -C "gdb-$GDB_VERSION" pull
|
---|
| 317 | fi
|
---|
| 318 |
|
---|
| 319 | # This sets the CROSS_PREFIX variable
|
---|
| 320 | set_cross_prefix
|
---|
| 321 |
|
---|
| 322 | DESTDIR_SPEC="DESTDIR=${INSTALL_DIR}"
|
---|
[85b41bc] | 323 |
|
---|
| 324 | check_dirs
|
---|
[fd8bf6a] | 325 | }
|
---|
| 326 |
|
---|
[6c9f1a6] | 327 | set_target_from_platform() {
|
---|
| 328 | case "$1" in
|
---|
| 329 | "arm32")
|
---|
[232ec3a1] | 330 | GNU_ARCH="arm"
|
---|
[6c9f1a6] | 331 | ;;
|
---|
[c7c3508] | 332 | "arm64")
|
---|
| 333 | GNU_ARCH="aarch64"
|
---|
| 334 | ;;
|
---|
[6c9f1a6] | 335 | "ia32")
|
---|
[232ec3a1] | 336 | GNU_ARCH="i686"
|
---|
[6c9f1a6] | 337 | ;;
|
---|
| 338 | "mips32")
|
---|
[232ec3a1] | 339 | GNU_ARCH="mipsel"
|
---|
[6c9f1a6] | 340 | ;;
|
---|
| 341 | "mips32eb")
|
---|
[232ec3a1] | 342 | GNU_ARCH="mips"
|
---|
[6c9f1a6] | 343 | ;;
|
---|
| 344 | "ppc32")
|
---|
[232ec3a1] | 345 | GNU_ARCH="ppc"
|
---|
[6c9f1a6] | 346 | ;;
|
---|
[232ec3a1] | 347 | *)
|
---|
| 348 | GNU_ARCH="$1"
|
---|
[6c9f1a6] | 349 | ;;
|
---|
[232ec3a1] | 350 | esac
|
---|
| 351 |
|
---|
[0b5aa1f0] | 352 | TARGET="${GNU_ARCH}-helenos"
|
---|
[fd8bf6a] | 353 | }
|
---|
| 354 |
|
---|
[0b5aa1f0] | 355 | build_binutils() {
|
---|
| 356 | # This sets the TARGET variable
|
---|
| 357 | set_target_from_platform "$1"
|
---|
[a35b458] | 358 |
|
---|
[591b989] | 359 | WORKDIR="${BASEDIR}/${TARGET}"
|
---|
[ff211d2] | 360 | BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}"
|
---|
[a35b458] | 361 |
|
---|
[ff211d2] | 362 | echo ">>> Removing previous content"
|
---|
[603c8740] | 363 | cleanup_dir "${WORKDIR}"
|
---|
[530f2de] | 364 | mkdir -p "${WORKDIR}"
|
---|
[f3a7b0d] | 365 |
|
---|
[59d469b] | 366 | echo ">>> Processing binutils (${TARGET})"
|
---|
[530f2de] | 367 | mkdir -p "${BINUTILSDIR}"
|
---|
[ff211d2] | 368 | cd "${BINUTILSDIR}"
|
---|
| 369 | check_error $? "Change directory failed."
|
---|
[a35b458] | 370 |
|
---|
[59d469b] | 371 | change_title "binutils: configure (${TARGET})"
|
---|
[ce52c333] | 372 | CFLAGS="-Wno-error -fcommon" "${BASEDIR}/downloads/binutils-${BINUTILS_VERSION}/configure" \
|
---|
[322ac35c] | 373 | "--target=${TARGET}" \
|
---|
[0b5aa1f0] | 374 | "--prefix=${CROSS_PREFIX}" \
|
---|
[232ec3a1] | 375 | "--program-prefix=${TARGET}-" \
|
---|
| 376 | --disable-nls \
|
---|
| 377 | --disable-werror \
|
---|
| 378 | --enable-gold \
|
---|
| 379 | --enable-deterministic-archives \
|
---|
| 380 | --disable-gdb \
|
---|
| 381 | --with-sysroot
|
---|
[ff211d2] | 382 | check_error $? "Error configuring binutils."
|
---|
[a35b458] | 383 |
|
---|
[59d469b] | 384 | change_title "binutils: make (${TARGET})"
|
---|
[232ec3a1] | 385 | make all -j$JOBS
|
---|
[322ac35c] | 386 | check_error $? "Error compiling binutils."
|
---|
[a35b458] | 387 |
|
---|
[59d469b] | 388 | change_title "binutils: install (${TARGET})"
|
---|
[0b5aa1f0] | 389 | make install $DESTDIR_SPEC
|
---|
[322ac35c] | 390 | check_error $? "Error installing binutils."
|
---|
[0b5aa1f0] | 391 | }
|
---|
[a35b458] | 392 |
|
---|
[0b5aa1f0] | 393 | build_gcc() {
|
---|
| 394 | # This sets the TARGET variable
|
---|
| 395 | set_target_from_platform "$1"
|
---|
| 396 |
|
---|
| 397 | WORKDIR="${BASEDIR}/${TARGET}"
|
---|
| 398 | GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
|
---|
| 399 |
|
---|
| 400 | echo ">>> Removing previous content"
|
---|
| 401 | cleanup_dir "${WORKDIR}"
|
---|
| 402 | mkdir -p "${WORKDIR}"
|
---|
[a35b458] | 403 |
|
---|
[59d469b] | 404 | echo ">>> Processing GCC (${TARGET})"
|
---|
[530f2de] | 405 | mkdir -p "${GCCDIR}"
|
---|
| 406 | cd "${GCCDIR}"
|
---|
[ff211d2] | 407 | check_error $? "Change directory failed."
|
---|
[a35b458] | 408 |
|
---|
[0b5aa1f0] | 409 | BUILDPATH="${CROSS_PREFIX}/bin:${PATH}"
|
---|
[232ec3a1] | 410 |
|
---|
[59d469b] | 411 | change_title "GCC: configure (${TARGET})"
|
---|
[0b5aa1f0] | 412 | PATH="${BUILDPATH}" "${BASEDIR}/downloads/gcc-${GCC_VERSION}/configure" \
|
---|
[322ac35c] | 413 | "--target=${TARGET}" \
|
---|
[0b5aa1f0] | 414 | "--prefix=${CROSS_PREFIX}" \
|
---|
[232ec3a1] | 415 | "--program-prefix=${TARGET}-" \
|
---|
| 416 | --with-gnu-as \
|
---|
| 417 | --with-gnu-ld \
|
---|
| 418 | --disable-nls \
|
---|
| 419 | --enable-languages=c,c++,go \
|
---|
| 420 | --enable-lto \
|
---|
[56210a7a] | 421 | --enable-obsolete \
|
---|
[232ec3a1] | 422 | --disable-shared \
|
---|
| 423 | --disable-werror \
|
---|
[0b5aa1f0] | 424 | --without-headers # TODO: Replace with proper sysroot so we can build more libs
|
---|
[ff211d2] | 425 | check_error $? "Error configuring GCC."
|
---|
[a35b458] | 426 |
|
---|
[59d469b] | 427 | change_title "GCC: make (${TARGET})"
|
---|
[0b5aa1f0] | 428 | PATH="${BUILDPATH}" make all-gcc -j$JOBS
|
---|
[322ac35c] | 429 | check_error $? "Error compiling GCC."
|
---|
[a35b458] | 430 |
|
---|
[59d469b] | 431 | change_title "GCC: install (${TARGET})"
|
---|
[0b5aa1f0] | 432 | PATH="${BUILDPATH}" make install-gcc $DESTDIR_SPEC
|
---|
[322ac35c] | 433 | check_error $? "Error installing GCC."
|
---|
[0b5aa1f0] | 434 | }
|
---|
| 435 |
|
---|
| 436 | build_libgcc() {
|
---|
| 437 | # This sets the TARGET variable
|
---|
| 438 | set_target_from_platform "$1"
|
---|
| 439 |
|
---|
| 440 | WORKDIR="${BASEDIR}/${TARGET}"
|
---|
| 441 | GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
|
---|
[a35b458] | 442 |
|
---|
[0b5aa1f0] | 443 | # No removing previous content here, we need the previous GCC build
|
---|
| 444 |
|
---|
| 445 | cd "${GCCDIR}"
|
---|
| 446 | check_error $? "Change directory failed."
|
---|
| 447 |
|
---|
| 448 | BUILDPATH="${CROSS_PREFIX}/bin:${PATH}"
|
---|
| 449 |
|
---|
[59d469b] | 450 | change_title "libgcc: make (${TARGET})"
|
---|
[0b5aa1f0] | 451 |
|
---|
| 452 | PATH="${BUILDPATH}" make all-target-libgcc -j$JOBS
|
---|
| 453 | check_error $? "Error compiling libgcc."
|
---|
| 454 | # TODO: libatomic and libstdc++ need some extra care
|
---|
| 455 | # PATH="${BUILDPATH}" make all-target-libatomic -j$JOBS
|
---|
| 456 | # check_error $? "Error compiling libatomic."
|
---|
| 457 | # PATH="${BUILDPATH}" make all-target-libstdc++-v3 -j$JOBS
|
---|
| 458 | # check_error $? "Error compiling libstdc++."
|
---|
| 459 |
|
---|
[59d469b] | 460 | change_title "libgcc: install (${TARGET})"
|
---|
[0b5aa1f0] | 461 |
|
---|
| 462 | PATH="${BUILDPATH}" make install-target-libgcc $DESTDIR_SPEC
|
---|
| 463 | # PATH="${BUILDPATH}" make install-target-libatomic $DESTDIR_SPEC
|
---|
| 464 | # PATH="${BUILDPATH}" make install-target-libstdc++-v3 $DESTDIR_SPEC
|
---|
| 465 | check_error $? "Error installing libgcc."
|
---|
| 466 | }
|
---|
| 467 |
|
---|
| 468 | build_gdb() {
|
---|
| 469 | # This sets the TARGET variable
|
---|
| 470 | set_target_from_platform "$1"
|
---|
| 471 |
|
---|
| 472 | WORKDIR="${BASEDIR}/${TARGET}"
|
---|
| 473 | GDBDIR="${WORKDIR}/gdb-${GDB_VERSION}"
|
---|
| 474 |
|
---|
| 475 | echo ">>> Removing previous content"
|
---|
| 476 | cleanup_dir "${WORKDIR}"
|
---|
| 477 | mkdir -p "${WORKDIR}"
|
---|
[a35b458] | 478 |
|
---|
[59d469b] | 479 | echo ">>> Processing GDB (${TARGET})"
|
---|
[105fcf0] | 480 | mkdir -p "${GDBDIR}"
|
---|
| 481 | cd "${GDBDIR}"
|
---|
| 482 | check_error $? "Change directory failed."
|
---|
[a35b458] | 483 |
|
---|
[59d469b] | 484 | change_title "GDB: configure (${TARGET})"
|
---|
[0b5aa1f0] | 485 | CFLAGS="-fcommon" "${BASEDIR}/downloads/gdb-${GDB_VERSION}/configure" \
|
---|
[105fcf0] | 486 | "--target=${TARGET}" \
|
---|
[0b5aa1f0] | 487 | "--prefix=${CROSS_PREFIX}" \
|
---|
[232ec3a1] | 488 | "--program-prefix=${TARGET}-" \
|
---|
| 489 | --enable-werror=no
|
---|
[105fcf0] | 490 | check_error $? "Error configuring GDB."
|
---|
[a35b458] | 491 |
|
---|
[59d469b] | 492 | change_title "GDB: make (${TARGET})"
|
---|
[0b5aa1f0] | 493 | make all-gdb -j$JOBS
|
---|
[105fcf0] | 494 | check_error $? "Error compiling GDB."
|
---|
[a35b458] | 495 |
|
---|
[59d469b] | 496 | change_title "GDB: install (${TARGET})"
|
---|
[0b5aa1f0] | 497 | make install-gdb $DESTDIR_SPEC
|
---|
[105fcf0] | 498 | check_error $? "Error installing GDB."
|
---|
[0b5aa1f0] | 499 | }
|
---|
| 500 |
|
---|
| 501 | install_pkg() {
|
---|
| 502 | echo ">>> Moving to the destination directory."
|
---|
| 503 | if $SYSTEM_INSTALL ; then
|
---|
| 504 | ring_bell
|
---|
| 505 | ( set -x ; sudo -k cp -r -t "${CROSS_PREFIX}" "${INSTALL_DIR}${CROSS_PREFIX}/"* )
|
---|
| 506 | else
|
---|
[4792e74] | 507 | ( set -x ; cp -r -t "${CROSS_PREFIX}" "${INSTALL_DIR}${CROSS_PREFIX}/"* )
|
---|
[0b5aa1f0] | 508 | fi
|
---|
| 509 | }
|
---|
[a35b458] | 510 |
|
---|
[0b5aa1f0] | 511 | link_clang() {
|
---|
[0f28387] | 512 | # Symlink clang and lld to the install path.
|
---|
[8192d8a] | 513 | CLANG="`which clang 2> /dev/null || echo "/usr/bin/clang"`"
|
---|
[d231a54] | 514 | CLANGPP="`which clang++ 2> /dev/null || echo "/usr/bin/clang++"`"
|
---|
[8192d8a] | 515 | LLD="`which ld.lld 2> /dev/null || echo "/usr/bin/ld.lld"`"
|
---|
[a35b458] | 516 |
|
---|
[0b5aa1f0] | 517 | ln -s $CLANG "${INSTALL_DIR}${CROSS_PREFIX}/bin/${TARGET}-clang"
|
---|
[d231a54] | 518 | ln -s $CLANGPP "${INSTALL_DIR}${CROSS_PREFIX}/bin/${TARGET}-clang++"
|
---|
[0b5aa1f0] | 519 | ln -s $LLD "${INSTALL_DIR}${CROSS_PREFIX}/bin/${TARGET}-ld.lld"
|
---|
[ff211d2] | 520 | }
|
---|
| 521 |
|
---|
[75b24cd] | 522 | while [ "$#" -gt 1 ] ; do
|
---|
[5a65d29] | 523 | case "$1" in
|
---|
[f3a7b0d] | 524 | --system-wide)
|
---|
| 525 | SYSTEM_INSTALL=true
|
---|
| 526 | shift
|
---|
| 527 | ;;
|
---|
[cb15b49c] | 528 | --test-version)
|
---|
| 529 | test_version "$2"
|
---|
| 530 | exit
|
---|
| 531 | ;;
|
---|
[0b5aa1f0] | 532 | --with-gdb)
|
---|
| 533 | BUILD_GDB=true
|
---|
[5a65d29] | 534 | shift
|
---|
| 535 | ;;
|
---|
[0b5aa1f0] | 536 | --only-gdb)
|
---|
| 537 | BUILD_GDB=true
|
---|
| 538 | BUILD_BINUTILS=false
|
---|
| 539 | BUILD_GCC=false
|
---|
[5a65d29] | 540 | shift
|
---|
| 541 | ;;
|
---|
| 542 | *)
|
---|
| 543 | show_usage
|
---|
| 544 | ;;
|
---|
| 545 | esac
|
---|
| 546 | done
|
---|
[322ac35c] | 547 |
|
---|
[75b24cd] | 548 | if [ "$#" -lt "1" ] ; then
|
---|
[ff211d2] | 549 | show_usage
|
---|
| 550 | fi
|
---|
| 551 |
|
---|
[0b5aa1f0] | 552 | PLATFORMS="amd64 arm32 arm64 ia32 ia64 mips32 mips32eb ppc32 riscv64 sparc64"
|
---|
| 553 |
|
---|
| 554 | run_one() {
|
---|
| 555 | $1 $PLATFORM
|
---|
| 556 | }
|
---|
| 557 |
|
---|
| 558 | run_all() {
|
---|
| 559 | for x in $PLATFORMS ; do
|
---|
| 560 | $1 $x
|
---|
| 561 | done
|
---|
| 562 | }
|
---|
| 563 |
|
---|
| 564 | run_parallel() {
|
---|
| 565 | for x in $PLATFORMS ; do
|
---|
| 566 | $1 $x &
|
---|
| 567 | done
|
---|
| 568 | wait
|
---|
| 569 | }
|
---|
| 570 |
|
---|
| 571 | run_2way() {
|
---|
| 572 | $1 amd64 &
|
---|
| 573 | $1 arm32 &
|
---|
| 574 | wait
|
---|
| 575 |
|
---|
| 576 | $1 arm64 &
|
---|
| 577 | $1 ia32 &
|
---|
| 578 | wait
|
---|
| 579 |
|
---|
| 580 | $1 ia64 &
|
---|
| 581 | $1 mips32 &
|
---|
| 582 | wait
|
---|
| 583 |
|
---|
| 584 | $1 mips32eb &
|
---|
| 585 | $1 ppc32 &
|
---|
| 586 | wait
|
---|
| 587 |
|
---|
| 588 | $1 riscv64 &
|
---|
| 589 | $1 sparc64 &
|
---|
| 590 | wait
|
---|
| 591 | }
|
---|
| 592 |
|
---|
| 593 | everything() {
|
---|
| 594 | RUNNER="$1"
|
---|
| 595 |
|
---|
| 596 | prepare
|
---|
| 597 |
|
---|
| 598 | if $BUILD_BINUTILS ; then
|
---|
| 599 | $RUNNER build_binutils
|
---|
| 600 |
|
---|
| 601 | if $BUILD_GCC ; then
|
---|
| 602 | # gcc/libgcc may fail to build correctly if binutils is not installed first
|
---|
| 603 | echo ">>> Installing binutils"
|
---|
| 604 | install_pkg
|
---|
| 605 | fi
|
---|
| 606 | fi
|
---|
| 607 |
|
---|
| 608 | if $BUILD_GCC ; then
|
---|
| 609 | $RUNNER build_gcc
|
---|
| 610 |
|
---|
| 611 | # libgcc may fail to build correctly if gcc is not installed first
|
---|
| 612 | echo ">>> Installing GCC"
|
---|
| 613 | install_pkg
|
---|
| 614 |
|
---|
[59d469b] | 615 | $RUNNER build_libgcc
|
---|
[0b5aa1f0] | 616 | fi
|
---|
| 617 |
|
---|
| 618 | if $BUILD_GDB ; then
|
---|
| 619 | $RUNNER build_gdb
|
---|
| 620 | fi
|
---|
| 621 |
|
---|
| 622 | echo ">>> Installing all files"
|
---|
| 623 | install_pkg
|
---|
| 624 |
|
---|
| 625 | link_clang
|
---|
| 626 | }
|
---|
| 627 |
|
---|
[ff211d2] | 628 | case "$1" in
|
---|
[cb15b49c] | 629 | --test-version)
|
---|
[4aba581] | 630 | test_version
|
---|
[f3a7b0d] | 631 | exit
|
---|
[4aba581] | 632 | ;;
|
---|
[c7c3508] | 633 | amd64|arm32|arm64|ia32|ia64|mips32|mips32eb|ppc32|riscv64|sparc64)
|
---|
[0b5aa1f0] | 634 | PLATFORM="$1"
|
---|
| 635 | everything run_one
|
---|
[b886b60] | 636 | ;;
|
---|
[ff211d2] | 637 | "all")
|
---|
[0b5aa1f0] | 638 | everything run_all
|
---|
[951f6b9e] | 639 | ;;
|
---|
[603c8740] | 640 | "parallel")
|
---|
[0b5aa1f0] | 641 | everything run_parallel
|
---|
[6abb346] | 642 | ;;
|
---|
| 643 | "2-way")
|
---|
[0b5aa1f0] | 644 | everything run_2way
|
---|
[603c8740] | 645 | ;;
|
---|
[ff211d2] | 646 | *)
|
---|
| 647 | show_usage
|
---|
| 648 | ;;
|
---|
| 649 | esac
|
---|