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