[9d5bb4e] | 1 | #! /bin/bash
|
---|
[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 |
|
---|
[3f7efa79] | 31 | GMP_MAIN=<<EOF
|
---|
| 32 | #define GCC_GMP_VERSION_NUM(a, b, c) \
|
---|
| 33 | (((a) << 16L) | ((b) << 8) | (c))
|
---|
| 34 |
|
---|
| 35 | #define GCC_GMP_VERSION \
|
---|
| 36 | GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
|
---|
| 37 |
|
---|
[d7f2cd6] | 38 | #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4, 3, 2)
|
---|
[3f7efa79] | 39 | choke me
|
---|
| 40 | #endif
|
---|
| 41 | EOF
|
---|
| 42 |
|
---|
| 43 | MPFR_MAIN=<<EOF
|
---|
| 44 | #if MPFR_VERSION < MPFR_VERSION_NUM(2, 4, 2)
|
---|
[7d248e3] | 45 | choke me
|
---|
| 46 | #endif
|
---|
[3f7efa79] | 47 | EOF
|
---|
| 48 |
|
---|
| 49 | MPC_MAIN=<<EOF
|
---|
| 50 | #if MPC_VERSION < MPC_VERSION_NUM(0, 8, 1)
|
---|
| 51 | choke me
|
---|
| 52 | #endif
|
---|
| 53 | EOF
|
---|
| 54 |
|
---|
[f6017ee] | 55 | ISL_MAIN=<<EOF
|
---|
| 56 | isl_ctx_get_max_operations (isl_ctx_alloc ());
|
---|
| 57 | EOF
|
---|
| 58 |
|
---|
[d2bd00f0] | 59 | BINUTILS_VERSION="2.28"
|
---|
[145d16f8] | 60 | BINUTILS_RELEASE=""
|
---|
[f6017ee] | 61 | ## BINUTILS_PATCHES="toolchain-binutils-2.23.1.patch"
|
---|
[d2bd00f0] | 62 | GCC_VERSION="7.1.0"
|
---|
[f6017ee] | 63 | ## GCC_PATCHES="toolchain-gcc-4.8.1-targets.patch toolchain-gcc-4.8.1-headers.patch"
|
---|
[3a75cb8] | 64 | GDB_VERSION="7.12.1"
|
---|
[f6017ee] | 65 | ## GDB_PATCHES="toolchain-gdb-7.6.1.patch"
|
---|
[367db39a] | 66 | ISL_VERSION="0.18"
|
---|
[603c8740] | 67 |
|
---|
| 68 | BASEDIR="`pwd`"
|
---|
[12735849] | 69 | SRCDIR="$(readlink -f $(dirname "$0"))"
|
---|
[7e9fce6] | 70 | BINUTILS="binutils-${BINUTILS_VERSION}${BINUTILS_RELEASE}.tar.bz2"
|
---|
[2385952] | 71 | GCC="gcc-${GCC_VERSION}.tar.bz2"
|
---|
[d249b9d] | 72 | GDB="gdb-${GDB_VERSION}.tar.gz"
|
---|
[367db39a] | 73 | ISL="isl-${ISL_VERSION}.tar.bz2"
|
---|
[603c8740] | 74 |
|
---|
[322ac35c] | 75 | REAL_INSTALL=true
|
---|
[5a65d29] | 76 | USE_HELENOS_TARGET=false
|
---|
[367db39a] | 77 | BUILD_ISL=false
|
---|
[322ac35c] | 78 |
|
---|
[3f7efa79] | 79 | #
|
---|
| 80 | # Check if the library described in the argument
|
---|
| 81 | # exists and has acceptable version.
|
---|
| 82 | #
|
---|
| 83 | check_dependency() {
|
---|
| 84 | DEPENDENCY="$1"
|
---|
| 85 | HEADER="$2"
|
---|
| 86 | BODY="$3"
|
---|
| 87 |
|
---|
| 88 | FNAME="/tmp/conftest-$$"
|
---|
| 89 |
|
---|
| 90 | echo "#include ${HEADER}" > "${FNAME}.c"
|
---|
| 91 | echo >> "${FNAME}.c"
|
---|
| 92 | echo "int main()" >> "${FNAME}.c"
|
---|
| 93 | echo "{" >> "${FNAME}.c"
|
---|
| 94 | echo "${BODY}" >> "${FNAME}.c"
|
---|
| 95 | echo " return 0;" >> "${FNAME}.c"
|
---|
| 96 | echo "}" >> "${FNAME}.c"
|
---|
| 97 |
|
---|
[a4170d5] | 98 | cc $CFLAGS -c -o "${FNAME}.o" "${FNAME}.c" 2> "${FNAME}.log"
|
---|
[3f7efa79] | 99 | RC="$?"
|
---|
| 100 |
|
---|
| 101 | if [ "$RC" -ne "0" ] ; then
|
---|
[367db39a] | 102 | if [ "${DEPENDENCY}" == "isl" ]; then
|
---|
| 103 | BUILD_ISL=true
|
---|
| 104 |
|
---|
| 105 | echo " isl not found. Will be downloaded and built with GCC."
|
---|
| 106 | else
|
---|
| 107 | echo " ${DEPENDENCY} not found, too old or compiler error."
|
---|
| 108 | echo " Please recheck manually the source file \"${FNAME}.c\"."
|
---|
| 109 | echo " The compilation of the toolchain is probably going to fail,"
|
---|
| 110 | echo " you have been warned."
|
---|
| 111 | echo
|
---|
| 112 | echo " ===== Compiler output ====="
|
---|
| 113 | cat "${FNAME}.log"
|
---|
| 114 | echo " ==========================="
|
---|
| 115 | echo
|
---|
| 116 | fi
|
---|
[3f7efa79] | 117 | else
|
---|
| 118 | echo " ${DEPENDENCY} found"
|
---|
| 119 | rm -f "${FNAME}.log" "${FNAME}.o" "${FNAME}.c"
|
---|
| 120 | fi
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | check_dependecies() {
|
---|
| 124 | echo ">>> Basic dependency check"
|
---|
| 125 | check_dependency "GMP" "<gmp.h>" "${GMP_MAIN}"
|
---|
| 126 | check_dependency "MPFR" "<mpfr.h>" "${MPFR_MAIN}"
|
---|
| 127 | check_dependency "MPC" "<mpc.h>" "${MPC_MAIN}"
|
---|
[f6017ee] | 128 | check_dependency "isl" "<isl/ctx.h>" "${ISL_MAIN}"
|
---|
[3f7efa79] | 129 | echo
|
---|
| 130 | }
|
---|
| 131 |
|
---|
[ff211d2] | 132 | check_error() {
|
---|
[75b24cd] | 133 | if [ "$1" -ne "0" ] ; then
|
---|
[ff211d2] | 134 | echo
|
---|
| 135 | echo "Script failed: $2"
|
---|
[3fe57ea7] | 136 |
|
---|
[ff211d2] | 137 | exit 1
|
---|
| 138 | fi
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | check_md5() {
|
---|
| 142 | FILE="$1"
|
---|
| 143 | SUM="$2"
|
---|
| 144 |
|
---|
| 145 | COMPUTED="`md5sum "${FILE}" | cut -d' ' -f1`"
|
---|
| 146 | if [ "${SUM}" != "${COMPUTED}" ] ; then
|
---|
| 147 | echo
|
---|
| 148 | echo "Checksum of ${FILE} does not match."
|
---|
[3fe57ea7] | 149 |
|
---|
[ff211d2] | 150 | exit 2
|
---|
| 151 | fi
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | show_usage() {
|
---|
| 155 | echo "Cross-compiler toolchain build script"
|
---|
| 156 | echo
|
---|
| 157 | echo "Syntax:"
|
---|
[5a65d29] | 158 | echo " $0 [--no-install] [--helenos-target] <platform>"
|
---|
[ff211d2] | 159 | echo
|
---|
| 160 | echo "Possible target platforms are:"
|
---|
[f2f89315] | 161 | echo " amd64 AMD64 (x86-64, x64)"
|
---|
[d2bd00f0] | 162 | echo " arm32 ARM 32b"
|
---|
[ff211d2] | 163 | echo " ia32 IA-32 (x86, i386)"
|
---|
| 164 | echo " ia64 IA-64 (Itanium)"
|
---|
[71e3289] | 165 | echo " mips32 MIPS little-endian 32b"
|
---|
| 166 | echo " mips32eb MIPS big-endian 32b"
|
---|
| 167 | echo " mips64 MIPS little-endian 64b"
|
---|
[d2bd00f0] | 168 | echo " ppc32 PowerPC 32b"
|
---|
| 169 | echo " ppc64 PowerPC 64v"
|
---|
| 170 | echo " riscv64 RISC-V 64b"
|
---|
[f2f89315] | 171 | echo " sparc64 SPARC V9"
|
---|
[ff211d2] | 172 | echo " all build all targets"
|
---|
[951f6b9e] | 173 | echo " essential build only targets currently needed for HelenOS development"
|
---|
[6abb346] | 174 | echo " parallel same as 'all', but all in parallel"
|
---|
| 175 | echo " 2-way same as 'all', but 2-way parallel"
|
---|
[ff211d2] | 176 | echo
|
---|
[322ac35c] | 177 | echo "The toolchain is installed into directory specified by the"
|
---|
| 178 | echo "CROSS_PREFIX environment variable. If the variable is not"
|
---|
| 179 | echo "defined, /usr/local/cross/ is used as default."
|
---|
[5a65d29] | 180 | echo
|
---|
[322ac35c] | 181 | echo "If --no-install is present, the toolchain still uses the"
|
---|
| 182 | echo "CROSS_PREFIX as the target directory but the installation"
|
---|
| 183 | echo "copies the files into PKG/ subdirectory without affecting"
|
---|
| 184 | echo "the actual root file system. That is only useful if you do"
|
---|
| 185 | echo "not want to run the script under the super user."
|
---|
[38eaf41] | 186 | echo
|
---|
[5a65d29] | 187 | echo "The --helenos-target will build HelenOS-specific toolchain"
|
---|
| 188 | echo "(i.e. it will use *-helenos-* triplet instead of *-linux-*)."
|
---|
| 189 | echo "This toolchain is installed into /usr/local/cross-helenos by"
|
---|
| 190 | echo "default. The settings can be changed by setting environment"
|
---|
| 191 | echo "variable CROSS_HELENOS_PREFIX."
|
---|
[f3287e5] | 192 | echo "Using the HelenOS-specific toolchain is still an experimental"
|
---|
| 193 | echo "feature that is not fully supported."
|
---|
[38eaf41] | 194 | echo
|
---|
[ff211d2] | 195 |
|
---|
| 196 | exit 3
|
---|
| 197 | }
|
---|
| 198 |
|
---|
[3fe57ea7] | 199 | change_title() {
|
---|
| 200 | echo -en "\e]0;$1\a"
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | show_countdown() {
|
---|
| 204 | TM="$1"
|
---|
| 205 |
|
---|
| 206 | if [ "${TM}" -eq 0 ] ; then
|
---|
| 207 | echo
|
---|
| 208 | return 0
|
---|
| 209 | fi
|
---|
| 210 |
|
---|
| 211 | echo -n "${TM} "
|
---|
| 212 | change_title "${TM}"
|
---|
| 213 | sleep 1
|
---|
| 214 |
|
---|
| 215 | TM="`expr "${TM}" - 1`"
|
---|
| 216 | show_countdown "${TM}"
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | show_dependencies() {
|
---|
| 220 | echo "IMPORTANT NOTICE:"
|
---|
| 221 | echo
|
---|
| 222 | echo "For a successful compilation and use of the cross-compiler"
|
---|
| 223 | echo "toolchain you need at least the following dependencies."
|
---|
| 224 | echo
|
---|
| 225 | echo "Please make sure that the dependencies are present in your"
|
---|
| 226 | echo "system. Otherwise the compilation process might fail after"
|
---|
| 227 | echo "a few seconds or minutes."
|
---|
| 228 | echo
|
---|
| 229 | echo " - SED, AWK, Flex, Bison, gzip, bzip2, Bourne Shell"
|
---|
| 230 | echo " - gettext, zlib, Texinfo, libelf, libgomp"
|
---|
[f6017ee] | 231 | echo " - GNU Make, Coreutils, Sharutils, tar"
|
---|
[3fe57ea7] | 232 | echo " - GNU Multiple Precision Library (GMP)"
|
---|
| 233 | echo " - MPFR"
|
---|
| 234 | echo " - MPC"
|
---|
[f6017ee] | 235 | echo " - integer point manipulation library (isl)"
|
---|
| 236 | echo " - native C and C++ compiler, assembler and linker"
|
---|
| 237 | echo " - native C and C++ standard library with headers"
|
---|
[3fe57ea7] | 238 | echo
|
---|
| 239 | }
|
---|
| 240 |
|
---|
[603c8740] | 241 | download_fetch() {
|
---|
[ff211d2] | 242 | SOURCE="$1"
|
---|
| 243 | FILE="$2"
|
---|
| 244 | CHECKSUM="$3"
|
---|
| 245 |
|
---|
[75b24cd] | 246 | if [ ! -f "${FILE}" ] ; then
|
---|
[3fe57ea7] | 247 | change_title "Downloading ${FILE}"
|
---|
[3277fb0] | 248 | wget -c "${SOURCE}${FILE}" -O "${FILE}".part
|
---|
[ff211d2] | 249 | check_error $? "Error downloading ${FILE}."
|
---|
[3277fb0] | 250 |
|
---|
| 251 | mv "${FILE}".part "${FILE}"
|
---|
[ff211d2] | 252 | fi
|
---|
| 253 |
|
---|
| 254 | check_md5 "${FILE}" "${CHECKSUM}"
|
---|
| 255 | }
|
---|
| 256 |
|
---|
[603c8740] | 257 | source_check() {
|
---|
| 258 | FILE="$1"
|
---|
| 259 |
|
---|
[75b24cd] | 260 | if [ ! -f "${FILE}" ] ; then
|
---|
[603c8740] | 261 | echo
|
---|
| 262 | echo "File ${FILE} not found."
|
---|
| 263 |
|
---|
| 264 | exit 4
|
---|
| 265 | fi
|
---|
| 266 | }
|
---|
| 267 |
|
---|
[ff211d2] | 268 | cleanup_dir() {
|
---|
| 269 | DIR="$1"
|
---|
| 270 |
|
---|
[75b24cd] | 271 | if [ -d "${DIR}" ] ; then
|
---|
[3fe57ea7] | 272 | change_title "Removing ${DIR}"
|
---|
[ff211d2] | 273 | echo " >>> Removing ${DIR}"
|
---|
| 274 | rm -fr "${DIR}"
|
---|
| 275 | fi
|
---|
| 276 | }
|
---|
| 277 |
|
---|
| 278 | create_dir() {
|
---|
| 279 | DIR="$1"
|
---|
| 280 | DESC="$2"
|
---|
| 281 |
|
---|
[3fe57ea7] | 282 | change_title "Creating ${DESC}"
|
---|
[ff211d2] | 283 | echo ">>> Creating ${DESC}"
|
---|
| 284 |
|
---|
| 285 | mkdir -p "${DIR}"
|
---|
| 286 | test -d "${DIR}"
|
---|
| 287 | check_error $? "Unable to create ${DIR}."
|
---|
| 288 | }
|
---|
| 289 |
|
---|
[285589b] | 290 | check_dirs() {
|
---|
| 291 | OUTSIDE="$1"
|
---|
| 292 | BASE="$2"
|
---|
| 293 | ORIGINAL="`pwd`"
|
---|
| 294 |
|
---|
[0f28387] | 295 | mkdir -p "${OUTSIDE}"
|
---|
| 296 |
|
---|
[285589b] | 297 | cd "${OUTSIDE}"
|
---|
| 298 | check_error $? "Unable to change directory to ${OUTSIDE}."
|
---|
| 299 | ABS_OUTSIDE="`pwd`"
|
---|
| 300 |
|
---|
| 301 | cd "${BASE}"
|
---|
| 302 | check_error $? "Unable to change directory to ${BASE}."
|
---|
| 303 | ABS_BASE="`pwd`"
|
---|
| 304 |
|
---|
| 305 | cd "${ORIGINAL}"
|
---|
| 306 | check_error $? "Unable to change directory to ${ORIGINAL}."
|
---|
| 307 |
|
---|
| 308 | BASE_LEN="${#ABS_BASE}"
|
---|
| 309 | OUTSIDE_TRIM="${ABS_OUTSIDE:0:${BASE_LEN}}"
|
---|
| 310 |
|
---|
| 311 | if [ "${OUTSIDE_TRIM}" == "${ABS_BASE}" ] ; then
|
---|
| 312 | echo
|
---|
| 313 | echo "CROSS_PREFIX cannot reside within the working directory."
|
---|
| 314 |
|
---|
| 315 | exit 5
|
---|
| 316 | fi
|
---|
| 317 | }
|
---|
| 318 |
|
---|
[ff211d2] | 319 | unpack_tarball() {
|
---|
| 320 | FILE="$1"
|
---|
| 321 | DESC="$2"
|
---|
| 322 |
|
---|
[3fe57ea7] | 323 | change_title "Unpacking ${DESC}"
|
---|
| 324 | echo " >>> Unpacking ${DESC}"
|
---|
[ff211d2] | 325 |
|
---|
[11af58b] | 326 | case "${FILE}" in
|
---|
| 327 | *.gz)
|
---|
| 328 | tar -xzf "${FILE}"
|
---|
| 329 | ;;
|
---|
| 330 | *.xz)
|
---|
| 331 | tar -xJf "${FILE}"
|
---|
| 332 | ;;
|
---|
| 333 | *.bz2)
|
---|
| 334 | tar -xjf "${FILE}"
|
---|
| 335 | ;;
|
---|
| 336 | *)
|
---|
| 337 | check_error 1 "Don't know how to unpack ${DESC}."
|
---|
| 338 | ;;
|
---|
| 339 | esac
|
---|
[ff211d2] | 340 | check_error $? "Error unpacking ${DESC}."
|
---|
| 341 | }
|
---|
| 342 |
|
---|
[5a65d29] | 343 | patch_sources() {
|
---|
| 344 | PATCH_FILE="$1"
|
---|
| 345 | PATCH_STRIP="$2"
|
---|
| 346 | DESC="$3"
|
---|
| 347 |
|
---|
| 348 | change_title "Patching ${DESC}"
|
---|
| 349 | echo " >>> Patching ${DESC} with ${PATCH_FILE}"
|
---|
| 350 |
|
---|
| 351 | patch -t "-p${PATCH_STRIP}" <"$PATCH_FILE"
|
---|
| 352 | check_error $? "Error patching ${DESC}."
|
---|
| 353 | }
|
---|
| 354 |
|
---|
[603c8740] | 355 | prepare() {
|
---|
| 356 | show_dependencies
|
---|
| 357 | check_dependecies
|
---|
| 358 | show_countdown 10
|
---|
[fd8bf6a] | 359 |
|
---|
[603c8740] | 360 | BINUTILS_SOURCE="ftp://ftp.gnu.org/gnu/binutils/"
|
---|
| 361 | GCC_SOURCE="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"
|
---|
[2a922c8] | 362 | GDB_SOURCE="ftp://ftp.gnu.org/gnu/gdb/"
|
---|
[367db39a] | 363 | ISL_SOURCE="http://isl.gforge.inria.fr/"
|
---|
[603c8740] | 364 |
|
---|
[d2bd00f0] | 365 | download_fetch "${BINUTILS_SOURCE}" "${BINUTILS}" "9e8340c96626b469a603c15c9d843727"
|
---|
| 366 | download_fetch "${GCC_SOURCE}" "${GCC}" "6bf56a2bca9dac9dbbf8e8d1036964a8"
|
---|
[3a75cb8] | 367 | download_fetch "${GDB_SOURCE}" "${GDB}" "06c8f40521ed65fe36ebc2be29b56942"
|
---|
[367db39a] | 368 |
|
---|
| 369 | if $BUILD_ISL ; then
|
---|
| 370 | download_fetch "${ISL_SOURCE}" "${ISL}" "11436d6b205e516635b666090b94ab32"
|
---|
| 371 | fi
|
---|
[fd8bf6a] | 372 | }
|
---|
| 373 |
|
---|
[6c9f1a6] | 374 | set_target_from_platform() {
|
---|
| 375 | case "$1" in
|
---|
| 376 | "amd64")
|
---|
[bfdb7c63] | 377 | LINUX_TARGET="amd64-unknown-elf"
|
---|
[5a65d29] | 378 | HELENOS_TARGET="amd64-helenos"
|
---|
[6c9f1a6] | 379 | ;;
|
---|
| 380 | "arm32")
|
---|
[5a65d29] | 381 | LINUX_TARGET="arm-linux-gnueabi"
|
---|
| 382 | HELENOS_TARGET="arm-helenos-gnueabi"
|
---|
[6c9f1a6] | 383 | ;;
|
---|
| 384 | "ia32")
|
---|
[5a65d29] | 385 | LINUX_TARGET="i686-pc-linux-gnu"
|
---|
| 386 | HELENOS_TARGET="i686-pc-helenos"
|
---|
[6c9f1a6] | 387 | ;;
|
---|
| 388 | "ia64")
|
---|
[5a65d29] | 389 | LINUX_TARGET="ia64-pc-linux-gnu"
|
---|
| 390 | HELENOS_TARGET="ia64-pc-helenos"
|
---|
[6c9f1a6] | 391 | ;;
|
---|
| 392 | "mips32")
|
---|
[5a65d29] | 393 | LINUX_TARGET="mipsel-linux-gnu"
|
---|
| 394 | HELENOS_TARGET="mipsel-helenos"
|
---|
[6c9f1a6] | 395 | ;;
|
---|
| 396 | "mips32eb")
|
---|
[5a65d29] | 397 | LINUX_TARGET="mips-linux-gnu"
|
---|
| 398 | HELENOS_TARGET="mips-helenos"
|
---|
[6c9f1a6] | 399 | ;;
|
---|
| 400 | "mips64")
|
---|
[5a65d29] | 401 | LINUX_TARGET="mips64el-linux-gnu"
|
---|
| 402 | HELENOS_TARGET="mips64el-helenos"
|
---|
[6c9f1a6] | 403 | ;;
|
---|
| 404 | "ppc32")
|
---|
[5a65d29] | 405 | LINUX_TARGET="ppc-linux-gnu"
|
---|
| 406 | HELENOS_TARGET="ppc-helenos"
|
---|
[6c9f1a6] | 407 | ;;
|
---|
| 408 | "ppc64")
|
---|
[5a65d29] | 409 | LINUX_TARGET="ppc64-linux-gnu"
|
---|
| 410 | HELENOS_TARGET="ppc64-helenos"
|
---|
[6c9f1a6] | 411 | ;;
|
---|
[d2bd00f0] | 412 | "riscv64")
|
---|
| 413 | LINUX_TARGET="riscv64-unknown-linux-gnu"
|
---|
| 414 | HELENOS_TARGET="riscv64-helenos"
|
---|
| 415 | ;;
|
---|
[6c9f1a6] | 416 | "sparc64")
|
---|
[5a65d29] | 417 | LINUX_TARGET="sparc64-linux-gnu"
|
---|
| 418 | HELENOS_TARGET="sparc64-helenos"
|
---|
[6c9f1a6] | 419 | ;;
|
---|
| 420 | *)
|
---|
| 421 | check_error 1 "No target known for $1."
|
---|
| 422 | ;;
|
---|
| 423 | esac
|
---|
[fd8bf6a] | 424 | }
|
---|
| 425 |
|
---|
[ff211d2] | 426 | build_target() {
|
---|
| 427 | PLATFORM="$1"
|
---|
[75b24cd] | 428 |
|
---|
[5a65d29] | 429 | # This sets the *_TARGET variables
|
---|
[6c9f1a6] | 430 | set_target_from_platform "$PLATFORM"
|
---|
[75b24cd] | 431 | if $USE_HELENOS_TARGET ; then
|
---|
[5a65d29] | 432 | TARGET="$HELENOS_TARGET"
|
---|
| 433 | else
|
---|
| 434 | TARGET="$LINUX_TARGET"
|
---|
| 435 | fi
|
---|
[ff211d2] | 436 |
|
---|
[591b989] | 437 | WORKDIR="${BASEDIR}/${TARGET}"
|
---|
| 438 | INSTALL_DIR="${WORKDIR}/PKG"
|
---|
[ff211d2] | 439 | BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}"
|
---|
| 440 | GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
|
---|
[367db39a] | 441 | ISLDIR="${WORKDIR}/isl-${ISL_VERSION}"
|
---|
[ff211d2] | 442 | OBJDIR="${WORKDIR}/gcc-obj"
|
---|
[2a922c8] | 443 | GDBDIR="${WORKDIR}/gdb-${GDB_VERSION}"
|
---|
[ff211d2] | 444 |
|
---|
| 445 | if [ -z "${CROSS_PREFIX}" ] ; then
|
---|
[603c8740] | 446 | CROSS_PREFIX="/usr/local/cross"
|
---|
[ff211d2] | 447 | fi
|
---|
| 448 |
|
---|
[591b989] | 449 | PREFIX="${CROSS_PREFIX}/${TARGET}"
|
---|
[ff211d2] | 450 |
|
---|
| 451 | echo ">>> Downloading tarballs"
|
---|
[603c8740] | 452 | source_check "${BASEDIR}/${BINUTILS}"
|
---|
[2385952] | 453 | source_check "${BASEDIR}/${GCC}"
|
---|
[2a922c8] | 454 | source_check "${BASEDIR}/${GDB}"
|
---|
[367db39a] | 455 | if $BUILD_ISL ; then
|
---|
| 456 | source_check "${BASEDIR}/${ISL}"
|
---|
| 457 | fi
|
---|
[ff211d2] | 458 |
|
---|
| 459 | echo ">>> Removing previous content"
|
---|
[603c8740] | 460 | cleanup_dir "${WORKDIR}"
|
---|
[ff211d2] | 461 |
|
---|
| 462 | create_dir "${OBJDIR}" "GCC object directory"
|
---|
| 463 |
|
---|
[285589b] | 464 | check_dirs "${PREFIX}" "${WORKDIR}"
|
---|
| 465 |
|
---|
[ff211d2] | 466 | echo ">>> Unpacking tarballs"
|
---|
[603c8740] | 467 | cd "${WORKDIR}"
|
---|
| 468 | check_error $? "Change directory failed."
|
---|
| 469 |
|
---|
| 470 | unpack_tarball "${BASEDIR}/${BINUTILS}" "binutils"
|
---|
[2385952] | 471 | unpack_tarball "${BASEDIR}/${GCC}" "GCC"
|
---|
[2a922c8] | 472 | unpack_tarball "${BASEDIR}/${GDB}" "GDB"
|
---|
[367db39a] | 473 | if $BUILD_ISL ; then
|
---|
| 474 | unpack_tarball "${BASEDIR}/${ISL}" "isl"
|
---|
| 475 | mv "${ISLDIR}" "${GCCDIR}"/isl
|
---|
| 476 | fi
|
---|
[ff211d2] | 477 |
|
---|
[5a65d29] | 478 | echo ">>> Applying patches"
|
---|
[75b24cd] | 479 | for p in $BINUTILS_PATCHES ; do
|
---|
[12735849] | 480 | patch_sources "${SRCDIR}/${p}" 0 "binutils"
|
---|
[5a65d29] | 481 | done
|
---|
[75b24cd] | 482 | for p in $GCC_PATCHES ; do
|
---|
[12735849] | 483 | patch_sources "${SRCDIR}/${p}" 0 "GCC"
|
---|
[5a65d29] | 484 | done
|
---|
[75b24cd] | 485 | for p in $GDB_PATCHES ; do
|
---|
[12735849] | 486 | patch_sources "${SRCDIR}/${p}" 0 "GDB"
|
---|
[5a65d29] | 487 | done
|
---|
[322ac35c] | 488 |
|
---|
[3fe57ea7] | 489 | echo ">>> Processing binutils (${PLATFORM})"
|
---|
[ff211d2] | 490 | cd "${BINUTILSDIR}"
|
---|
| 491 | check_error $? "Change directory failed."
|
---|
[3fe57ea7] | 492 |
|
---|
| 493 | change_title "binutils: configure (${PLATFORM})"
|
---|
[322ac35c] | 494 | CFLAGS=-Wno-error ./configure \
|
---|
| 495 | "--target=${TARGET}" \
|
---|
| 496 | "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" \
|
---|
[5265c1eb] | 497 | --disable-nls --disable-werror --enable-gold \
|
---|
| 498 | --enable-deterministic-archives
|
---|
[ff211d2] | 499 | check_error $? "Error configuring binutils."
|
---|
[3fe57ea7] | 500 |
|
---|
| 501 | change_title "binutils: make (${PLATFORM})"
|
---|
[322ac35c] | 502 | make all
|
---|
| 503 | check_error $? "Error compiling binutils."
|
---|
| 504 |
|
---|
| 505 | change_title "binutils: install (${PLATFORM})"
|
---|
[0f28387] | 506 | make install "DESTDIR=${INSTALL_DIR}"
|
---|
[322ac35c] | 507 | check_error $? "Error installing binutils."
|
---|
| 508 |
|
---|
[ff211d2] | 509 |
|
---|
[3fe57ea7] | 510 | echo ">>> Processing GCC (${PLATFORM})"
|
---|
[ff211d2] | 511 | cd "${OBJDIR}"
|
---|
| 512 | check_error $? "Change directory failed."
|
---|
[3fe57ea7] | 513 |
|
---|
| 514 | change_title "GCC: configure (${PLATFORM})"
|
---|
[322ac35c] | 515 | PATH="$PATH:${INSTALL_DIR}/${PREFIX}/bin" "${GCCDIR}/configure" \
|
---|
| 516 | "--target=${TARGET}" \
|
---|
| 517 | "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" \
|
---|
| 518 | --with-gnu-as --with-gnu-ld --disable-nls --disable-threads \
|
---|
| 519 | --enable-languages=c,objc,c++,obj-c++ \
|
---|
| 520 | --disable-multilib --disable-libgcj --without-headers \
|
---|
| 521 | --disable-shared --enable-lto --disable-werror
|
---|
[ff211d2] | 522 | check_error $? "Error configuring GCC."
|
---|
[3fe57ea7] | 523 |
|
---|
| 524 | change_title "GCC: make (${PLATFORM})"
|
---|
[322ac35c] | 525 | PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-gcc
|
---|
| 526 | check_error $? "Error compiling GCC."
|
---|
| 527 |
|
---|
| 528 | change_title "GCC: install (${PLATFORM})"
|
---|
[0f28387] | 529 | PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-gcc "DESTDIR=${INSTALL_DIR}"
|
---|
[322ac35c] | 530 | check_error $? "Error installing GCC."
|
---|
| 531 |
|
---|
[ff211d2] | 532 |
|
---|
[d2bd00f0] | 533 | # No GDB support for RISC-V so far
|
---|
| 534 | if [ "$PLATFORM" != "riscv64" ] ; then
|
---|
| 535 | echo ">>> Processing GDB (${PLATFORM})"
|
---|
| 536 | cd "${GDBDIR}"
|
---|
| 537 | check_error $? "Change directory failed."
|
---|
| 538 |
|
---|
| 539 | change_title "GDB: configure (${PLATFORM})"
|
---|
| 540 | PATH="$PATH:${INSTALL_DIR}/${PREFIX}/bin" ./configure \
|
---|
| 541 | "--target=${TARGET}" \
|
---|
| 542 | "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" \
|
---|
[0f28387] | 543 | --enable-werror=no --without-guile
|
---|
[d2bd00f0] | 544 | check_error $? "Error configuring GDB."
|
---|
| 545 |
|
---|
| 546 | change_title "GDB: make (${PLATFORM})"
|
---|
| 547 | PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all
|
---|
| 548 | check_error $? "Error compiling GDB."
|
---|
| 549 |
|
---|
| 550 | change_title "GDB: make (${PLATFORM})"
|
---|
[0f28387] | 551 | PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install "DESTDIR=${INSTALL_DIR}"
|
---|
[d2bd00f0] | 552 | check_error $? "Error installing GDB."
|
---|
[322ac35c] | 553 | fi
|
---|
| 554 |
|
---|
[0f28387] | 555 | # Symlink clang and lld to the install path.
|
---|
| 556 | CLANG=`which clang 2> /dev/null || echo "/usr/bin/clang"`
|
---|
| 557 | LLD=`which ld.lld 2> /dev/null || echo "/usr/bin/ld.lld"`
|
---|
| 558 |
|
---|
| 559 | ln -s $CLANG "${INSTALL_DIR}/${PREFIX}/bin/${TARGET}-clang"
|
---|
| 560 | ln -s $LLD "${INSTALL_DIR}/${PREFIX}/bin/${TARGET}-ld.lld"
|
---|
| 561 |
|
---|
| 562 | if $REAL_INSTALL ; then
|
---|
| 563 | echo ">>> Moving to the destination directory."
|
---|
| 564 | cleanup_dir "${PREFIX}"
|
---|
| 565 | echo mv "${INSTALL_DIR}/${PREFIX}" "${PREFIX}"
|
---|
| 566 | mv "${INSTALL_DIR}/${PREFIX}" "${PREFIX}"
|
---|
| 567 | fi
|
---|
[2a922c8] | 568 |
|
---|
[603c8740] | 569 | cd "${BASEDIR}"
|
---|
[ff211d2] | 570 | check_error $? "Change directory failed."
|
---|
| 571 |
|
---|
| 572 | echo ">>> Cleaning up"
|
---|
[603c8740] | 573 | cleanup_dir "${WORKDIR}"
|
---|
[ff211d2] | 574 |
|
---|
| 575 | echo
|
---|
| 576 | echo ">>> Cross-compiler for ${TARGET} installed."
|
---|
| 577 | }
|
---|
| 578 |
|
---|
[75b24cd] | 579 | while [ "$#" -gt 1 ] ; do
|
---|
[5a65d29] | 580 | case "$1" in
|
---|
| 581 | --no-install)
|
---|
| 582 | REAL_INSTALL=false
|
---|
| 583 | shift
|
---|
| 584 | ;;
|
---|
| 585 | --helenos-target)
|
---|
| 586 | USE_HELENOS_TARGET=true
|
---|
| 587 | shift
|
---|
| 588 | ;;
|
---|
| 589 | *)
|
---|
| 590 | show_usage
|
---|
| 591 | ;;
|
---|
| 592 | esac
|
---|
| 593 | done
|
---|
[322ac35c] | 594 |
|
---|
[75b24cd] | 595 | if [ "$#" -lt "1" ] ; then
|
---|
[ff211d2] | 596 | show_usage
|
---|
| 597 | fi
|
---|
| 598 |
|
---|
| 599 | case "$1" in
|
---|
[d2bd00f0] | 600 | amd64|arm32|ia32|ia64|mips32|mips32eb|mips64|ppc32|ppc64|riscv64|sparc64)
|
---|
[603c8740] | 601 | prepare
|
---|
[6c9f1a6] | 602 | build_target "$1"
|
---|
[b886b60] | 603 | ;;
|
---|
[ff211d2] | 604 | "all")
|
---|
[603c8740] | 605 | prepare
|
---|
[6c9f1a6] | 606 | build_target "amd64"
|
---|
| 607 | build_target "arm32"
|
---|
| 608 | build_target "ia32"
|
---|
| 609 | build_target "ia64"
|
---|
| 610 | build_target "mips32"
|
---|
| 611 | build_target "mips32eb"
|
---|
| 612 | build_target "mips64"
|
---|
| 613 | build_target "ppc32"
|
---|
| 614 | build_target "ppc64"
|
---|
[d2bd00f0] | 615 | build_target "riscv64"
|
---|
[6c9f1a6] | 616 | build_target "sparc64"
|
---|
[ff211d2] | 617 | ;;
|
---|
[951f6b9e] | 618 | "essential")
|
---|
| 619 | prepare
|
---|
| 620 | build_target "amd64"
|
---|
| 621 | build_target "arm32"
|
---|
| 622 | build_target "ia32"
|
---|
| 623 | build_target "ia64"
|
---|
| 624 | build_target "mips32"
|
---|
| 625 | build_target "mips32eb"
|
---|
| 626 | build_target "ppc32"
|
---|
| 627 | build_target "sparc64"
|
---|
| 628 | ;;
|
---|
[603c8740] | 629 | "parallel")
|
---|
| 630 | prepare
|
---|
[6c9f1a6] | 631 | build_target "amd64" &
|
---|
| 632 | build_target "arm32" &
|
---|
| 633 | build_target "ia32" &
|
---|
| 634 | build_target "ia64" &
|
---|
| 635 | build_target "mips32" &
|
---|
| 636 | build_target "mips32eb" &
|
---|
| 637 | build_target "mips64" &
|
---|
| 638 | build_target "ppc32" &
|
---|
| 639 | build_target "ppc64" &
|
---|
[d2bd00f0] | 640 | build_target "riscv64" &
|
---|
[6c9f1a6] | 641 | build_target "sparc64" &
|
---|
[6abb346] | 642 | wait
|
---|
| 643 | ;;
|
---|
| 644 | "2-way")
|
---|
| 645 | prepare
|
---|
[6c9f1a6] | 646 | build_target "amd64" &
|
---|
| 647 | build_target "arm32" &
|
---|
[6abb346] | 648 | wait
|
---|
| 649 |
|
---|
[6c9f1a6] | 650 | build_target "ia32" &
|
---|
| 651 | build_target "ia64" &
|
---|
[6abb346] | 652 | wait
|
---|
| 653 |
|
---|
[6c9f1a6] | 654 | build_target "mips32" &
|
---|
| 655 | build_target "mips32eb" &
|
---|
[6abb346] | 656 | wait
|
---|
| 657 |
|
---|
[6c9f1a6] | 658 | build_target "mips64" &
|
---|
| 659 | build_target "ppc32" &
|
---|
[6abb346] | 660 | wait
|
---|
| 661 |
|
---|
[d2bd00f0] | 662 | build_target "riscv64" &
|
---|
[6c9f1a6] | 663 | build_target "ppc64" &
|
---|
[d2bd00f0] | 664 | wait
|
---|
| 665 |
|
---|
[6c9f1a6] | 666 | build_target "sparc64" &
|
---|
[b886b60] | 667 | wait
|
---|
[603c8740] | 668 | ;;
|
---|
[ff211d2] | 669 | *)
|
---|
| 670 | show_usage
|
---|
| 671 | ;;
|
---|
| 672 | esac
|
---|