Peter Stuge | 09377b7 | 2011-08-21 06:24:55 +0200 | [diff] [blame] | 1 | #!/bin/sh |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 2 | # shellcheck disable=SC2030,SC2031,SC2059 |
| 3 | # The above line must be directly after the shebang line. |
| 4 | # Disables these warnings: |
| 5 | # 2030 - Modification of var is local (to subshell caused by pipeline). |
| 6 | # shell check 0.4.6 gets confused by the read -t 1 command and interprets |
| 7 | # the '1' as $1 getting modified. |
| 8 | # 2031 - var was modified in a subshell. That change might be lost. |
| 9 | # caused by shell check bug with SC2030? This causes any $1 from that |
| 10 | # point on to be flagged. |
| 11 | # 2059 - Don't use variables in the printf format string. Use printf "..%s.." "$foo". |
| 12 | # This is used for all of our color printing. |
| 13 | |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 14 | # |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 15 | # Copyright (C) 2008-2010 by coresystems GmbH |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 16 | # written by Patrick Georgi <patrick.georgi@coresystems.de> and |
| 17 | # Stefan Reinauer <stefan.reinauer@coresystems.de> |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 18 | # |
Marc Jones | 2aac3f6 | 2011-08-08 16:07:50 -0600 | [diff] [blame] | 19 | # Copyright (C) 2011 by Sage Electronic Engineering |
| 20 | # |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 21 | # This program is free software; you can redistribute it and/or modify |
| 22 | # it under the terms of the GNU General Public License as published by |
| 23 | # the Free Software Foundation; version 2 of the License. |
| 24 | # |
| 25 | # This program is distributed in the hope that it will be useful, |
| 26 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 28 | # GNU General Public License for more details. |
| 29 | # |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 30 | |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 31 | cd "$(dirname "$0")" || exit 1 |
Patrick Georgi | 8135dba | 2015-03-17 21:05:20 +0100 | [diff] [blame] | 32 | |
Patrick Georgi | 5ce73e9 | 2019-01-10 14:07:56 +0100 | [diff] [blame] | 33 | CROSSGCC_DATE="$(git log -n 1 --pretty=%ad --date=short .)" |
Wonkyu Kim | 31eeda1 | 2019-01-18 17:33:55 -0800 | [diff] [blame] | 34 | CROSSGCC_VERSION="$(git log -n 1 --pretty=%h .)" |
Stefan Reinauer | 88352d7 | 2016-04-06 15:57:03 -0700 | [diff] [blame] | 35 | CROSSGCC_COMMIT=$( git describe ) |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 36 | |
| 37 | # default settings |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 38 | PACKAGE=GCC |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 39 | TARGETDIR=$(pwd)/xgcc |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 40 | TARGETARCH=i386-elf |
Nico Huber | 66c2c1a | 2016-09-20 13:09:29 +0200 | [diff] [blame] | 41 | DEFAULT_LANGUAGES=c |
| 42 | LANGUAGES= |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 43 | DESTDIR= |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 44 | SAVETEMPS=0 |
| 45 | SKIPPYTHON=1 |
Nico Huber | 234d246 | 2016-01-26 16:10:17 +0100 | [diff] [blame] | 46 | BOOTSTRAP=0 |
Martin Roth | 2c6a806 | 2016-11-14 11:58:39 -0700 | [diff] [blame] | 47 | THREADS=1 |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 48 | |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 49 | # GCC toolchain version numbers |
Iru Cai | 03353de | 2016-10-29 23:37:42 +0800 | [diff] [blame] | 50 | GMP_VERSION=6.1.2 |
Elyes HAOUAS | c3c9afb | 2019-02-03 15:51:42 +0100 | [diff] [blame] | 51 | MPFR_VERSION=4.0.2 |
Stefan Reinauer | aedb1df | 2018-10-02 16:00:22 -0700 | [diff] [blame] | 52 | MPC_VERSION=1.1.0 |
Patrick Rudolph | 6b88f90 | 2020-03-15 07:29:14 +0100 | [diff] [blame] | 53 | GCC_VERSION=8.3.0 |
Stefan Reinauer | 0d2119d | 2013-07-10 14:27:56 -0700 | [diff] [blame] | 54 | GCC_AUTOCONF_VERSION=2.69 |
Elyes HAOUAS | 18ecdbf | 2019-10-14 10:16:29 +0200 | [diff] [blame] | 55 | BINUTILS_VERSION=2.33.1 |
Elyes HAOUAS | 2368681 | 2019-09-21 12:23:16 +0200 | [diff] [blame] | 56 | GDB_VERSION=8.3.1 |
Elyes HAOUAS | 6571876 | 2020-02-04 07:33:47 +0100 | [diff] [blame] | 57 | IASL_VERSION=20200110 |
Elyes HAOUAS | a87a741 | 2019-12-19 11:50:43 +0100 | [diff] [blame] | 58 | PYTHON_VERSION=3.8.1 |
Elyes HAOUAS | a2fbddf | 2019-10-03 10:38:39 +0200 | [diff] [blame] | 59 | EXPAT_VERSION=2.2.9 |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 60 | # CLANG version number |
Elyes HAOUAS | 3ba84c5 | 2019-09-20 09:01:53 +0200 | [diff] [blame] | 61 | CLANG_VERSION=9.0.0 |
Martin Roth | 589ef9d | 2016-08-11 18:35:06 -0600 | [diff] [blame] | 62 | MAKE_VERSION=4.2.1 |
Elyes HAOUAS | 40f539f | 2020-01-03 16:09:35 +0100 | [diff] [blame] | 63 | CMAKE_VERSION=3.16.2 |
Martin Roth | d70f5fa | 2019-05-26 17:24:19 -0600 | [diff] [blame] | 64 | NASM_VERSION=2.14.02 |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 65 | |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 66 | # GCC toolchain archive locations |
Martin Roth | 1484c03 | 2016-03-08 09:37:14 -0700 | [diff] [blame] | 67 | # These are sanitized by the jenkins toolchain test builder, so if |
| 68 | # a completely new URL is added here, it probably needs to be added |
| 69 | # to the jenkins build as well, or the builder won't download it. |
Doug Gale | 43ae433 | 2017-09-27 22:10:16 -0400 | [diff] [blame] | 70 | GMP_ARCHIVE="https://ftpmirror.gnu.org/gmp/gmp-${GMP_VERSION}.tar.xz" |
| 71 | MPFR_ARCHIVE="https://ftpmirror.gnu.org/mpfr/mpfr-${MPFR_VERSION}.tar.xz" |
| 72 | MPC_ARCHIVE="https://ftpmirror.gnu.org/mpc/mpc-${MPC_VERSION}.tar.gz" |
Patrick Georgi | b1d26f0 | 2018-05-02 17:13:34 +0200 | [diff] [blame] | 73 | GCC_ARCHIVE="https://ftpmirror.gnu.org/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.xz" |
Iru Cai | 776b5ba | 2017-07-28 21:40:34 +0800 | [diff] [blame] | 74 | BINUTILS_ARCHIVE="https://ftpmirror.gnu.org/binutils/binutils-${BINUTILS_VERSION}.tar.xz" |
Doug Gale | 43ae433 | 2017-09-27 22:10:16 -0400 | [diff] [blame] | 75 | GDB_ARCHIVE="https://ftpmirror.gnu.org/gdb/gdb-${GDB_VERSION}.tar.xz" |
Patrick Georgi | 85bb946 | 2016-02-11 17:22:16 +0100 | [diff] [blame] | 76 | IASL_ARCHIVE="https://acpica.org/sites/acpica/files/acpica-unix2-${IASL_VERSION}.tar.gz" |
Doug Gale | 43ae433 | 2017-09-27 22:10:16 -0400 | [diff] [blame] | 77 | PYTHON_ARCHIVE="https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz" |
| 78 | EXPAT_ARCHIVE="https://downloads.sourceforge.net/sourceforge/expat/expat-${EXPAT_VERSION}.tar.bz2" |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 79 | # CLANG toolchain archive locations |
Doug Gale | 43ae433 | 2017-09-27 22:10:16 -0400 | [diff] [blame] | 80 | LLVM_ARCHIVE="https://releases.llvm.org/${CLANG_VERSION}/llvm-${CLANG_VERSION}.src.tar.xz" |
| 81 | CFE_ARCHIVE="https://releases.llvm.org/${CLANG_VERSION}/cfe-${CLANG_VERSION}.src.tar.xz" |
| 82 | CRT_ARCHIVE="https://releases.llvm.org/${CLANG_VERSION}/compiler-rt-${CLANG_VERSION}.src.tar.xz" |
| 83 | CTE_ARCHIVE="https://releases.llvm.org/${CLANG_VERSION}/clang-tools-extra-${CLANG_VERSION}.src.tar.xz" |
| 84 | MAKE_ARCHIVE="https://ftpmirror.gnu.org/make/make-${MAKE_VERSION}.tar.bz2" |
Elyes HAOUAS | 18315db | 2019-11-26 19:12:21 +0100 | [diff] [blame] | 85 | CMAKE_ARCHIVE="https://cmake.org/files/v3.16/cmake-${CMAKE_VERSION}.tar.gz" |
Martin Roth | d70f5fa | 2019-05-26 17:24:19 -0600 | [diff] [blame] | 86 | NASM_ARCHIVE="https://www.nasm.us/pub/nasm/releasebuilds/${NASM_VERSION}/nasm-${NASM_VERSION}.tar.bz2" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 87 | |
Nico Huber | afda56e | 2017-12-07 17:50:53 +0100 | [diff] [blame] | 88 | ALL_ARCHIVES="$GMP_ARCHIVE $MPFR_ARCHIVE $MPC_ARCHIVE \ |
Martin Roth | 58c68d5 | 2016-03-01 15:22:42 -0700 | [diff] [blame] | 89 | $GCC_ARCHIVE $BINUTILS_ARCHIVE $GDB_ARCHIVE $IASL_ARCHIVE \ |
| 90 | $PYTHON_ARCHIVE $EXPAT_ARCHIVE $LLVM_ARCHIVE $CFE_ARCHIVE \ |
Martin Roth | d70f5fa | 2019-05-26 17:24:19 -0600 | [diff] [blame] | 91 | $CRT_ARCHIVE $CTE_ARCHIVE $MAKE_ARCHIVE $CMAKE_ARCHIVE \ |
| 92 | $NASM_ARCHIVE" |
Martin Roth | 58c68d5 | 2016-03-01 15:22:42 -0700 | [diff] [blame] | 93 | |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 94 | # GCC toolchain directories |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 95 | GMP_DIR="gmp-${GMP_VERSION}" |
| 96 | MPFR_DIR="mpfr-${MPFR_VERSION}" |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 97 | MPC_DIR="mpc-${MPC_VERSION}" |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 98 | # shellcheck disable=SC2034 |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 99 | GCC_DIR="gcc-${GCC_VERSION}" |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 100 | # shellcheck disable=SC2034 |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 101 | BINUTILS_DIR="binutils-${BINUTILS_VERSION}" |
| 102 | GDB_DIR="gdb-${GDB_VERSION}" |
Patrick Georgi | 85bb946 | 2016-02-11 17:22:16 +0100 | [diff] [blame] | 103 | IASL_DIR="acpica-unix2-${IASL_VERSION}" |
Stefan Reinauer | 2c3cd12 | 2011-11-01 21:43:50 +0100 | [diff] [blame] | 104 | PYTHON_DIR="Python-${PYTHON_VERSION}" |
| 105 | EXPAT_DIR="expat-${EXPAT_VERSION}" |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 106 | # CLANG toolchain directories |
| 107 | LLVM_DIR="llvm-${CLANG_VERSION}.src" |
| 108 | CFE_DIR="cfe-${CLANG_VERSION}.src" |
| 109 | CRT_DIR="compiler-rt-${CLANG_VERSION}.src" |
| 110 | CTE_DIR="clang-tools-extra-${CLANG_VERSION}.src" |
Stefan Reinauer | a851bbb | 2016-01-29 18:03:26 -0800 | [diff] [blame] | 111 | MAKE_DIR="make-${MAKE_VERSION}" |
Stefan Reinauer | 3b59349 | 2017-06-19 17:28:54 -0700 | [diff] [blame] | 112 | CMAKE_DIR="cmake-${CMAKE_VERSION}" |
Martin Roth | d70f5fa | 2019-05-26 17:24:19 -0600 | [diff] [blame] | 113 | NASM_DIR="nasm-${NASM_VERSION}" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 114 | |
Patrick Georgi | 6321f52 | 2015-02-27 23:36:26 +0100 | [diff] [blame] | 115 | unset MAKELEVEL MAKEFLAGS |
| 116 | |
Patrick Georgi | 1861ff7 | 2011-10-31 12:15:55 +0100 | [diff] [blame] | 117 | red='\033[0;31m' |
| 118 | RED='\033[1;31m' |
| 119 | green='\033[0;32m' |
| 120 | GREEN='\033[1;32m' |
| 121 | blue='\033[0;34m' |
Patrick Georgi | 1861ff7 | 2011-10-31 12:15:55 +0100 | [diff] [blame] | 122 | CYAN='\033[1;36m' |
| 123 | NC='\033[0m' # No Color |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 124 | |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 125 | UNAME=$(if uname | grep -iq cygwin; then echo Cygwin; else uname; fi) |
Martin Roth | 8846382 | 2016-01-07 11:03:36 -0700 | [diff] [blame] | 126 | HALT_FOR_TOOLS=0 |
Stefan Reinauer | 0d2119d | 2013-07-10 14:27:56 -0700 | [diff] [blame] | 127 | |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 128 | hostcc() |
| 129 | { |
| 130 | # $1 "host" or "target" |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 131 | if [ "$BOOTSTRAP" = 1 ] && [ "$1" = target ]; then |
| 132 | echo "$DESTDIR$TARGETDIR/bin/gcc" |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 133 | else |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 134 | echo "$CC" |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 135 | fi |
| 136 | } |
| 137 | |
| 138 | hostcxx() |
| 139 | { |
| 140 | # $1 "host" or "target" |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 141 | if [ "$BOOTSTRAP" = 1 ] && [ "$1" = target ]; then |
| 142 | echo "$DESTDIR$TARGETDIR/bin/g++" |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 143 | else |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 144 | echo "$CXX" |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 145 | fi |
| 146 | } |
| 147 | |
Patrick Georgi | 198d23c | 2012-12-08 08:02:44 +0100 | [diff] [blame] | 148 | normalize_dirs() |
| 149 | { |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 150 | mkdir -p "$DESTDIR$TARGETDIR/lib" |
| 151 | test -d "$DESTDIR$TARGETDIR/lib32" && mv "$DESTDIR$TARGETDIR"/lib32/* "$DESTDIR$TARGETDIR/lib" |
| 152 | test -d "$DESTDIR$TARGETDIR/lib64" && mv "$DESTDIR$TARGETDIR"/lib64/* "$DESTDIR$TARGETDIR/lib" |
| 153 | rmdir -p "$DESTDIR$TARGETDIR/lib32" "$DESTDIR$TARGETDIR/lib64" |
Patrick Georgi | 198d23c | 2012-12-08 08:02:44 +0100 | [diff] [blame] | 154 | |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 155 | perl -pi -e "s,/lib32,/lib," "$DESTDIR$TARGETDIR"/lib/*.la |
| 156 | perl -pi -e "s,/lib64,/lib," "$DESTDIR$TARGETDIR"/lib/*.la |
Patrick Georgi | 198d23c | 2012-12-08 08:02:44 +0100 | [diff] [blame] | 157 | } |
| 158 | |
Nico Huber | cd87e1b | 2017-06-24 20:35:59 +0200 | [diff] [blame] | 159 | countdown() |
| 160 | { |
| 161 | tout=${1:-10} |
| 162 | |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 163 | printf "\nPress Ctrl-C to abort, Enter to continue... %2ds" "$tout" |
| 164 | while [ "$tout" -gt 0 ]; do |
Nico Huber | cd87e1b | 2017-06-24 20:35:59 +0200 | [diff] [blame] | 165 | sleep 1 |
| 166 | tout=$((tout - 1)) |
| 167 | printf "\b\b\b%2ds" $tout |
| 168 | done |
| 169 | printf "\n" |
| 170 | } |
| 171 | |
| 172 | timeout() |
| 173 | { |
| 174 | tout=${1:-10} |
| 175 | |
| 176 | # Ignore SIGUSR1, should interrupt `read` though. |
| 177 | trap false USR1 |
| 178 | # Clean up in case the user aborts. |
| 179 | trap 'kill $counter > /dev/null 2>&1' EXIT |
| 180 | |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 181 | (countdown "$tout"; kill -USR1 $$)& |
Nico Huber | cd87e1b | 2017-06-24 20:35:59 +0200 | [diff] [blame] | 182 | counter=$! |
| 183 | |
| 184 | # Some shells with sh compatibility mode (e.g. zsh, mksh) only |
| 185 | # let us interrupt `read` if a non-standard -t parameter is given. |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 186 | # shellcheck disable=SC2034,SC2039,SC2162 |
Nico Huber | cd87e1b | 2017-06-24 20:35:59 +0200 | [diff] [blame] | 187 | if echo | read -t 1 foo 2>/dev/null; then |
| 188 | read -t $((tout + 1)) foo |
| 189 | else |
| 190 | read foo |
| 191 | fi |
| 192 | |
| 193 | kill $counter > /dev/null 2>&1 |
| 194 | trap - USR1 EXIT |
| 195 | } |
| 196 | |
Stefan Reinauer | 93a9630 | 2015-06-15 12:36:53 -0700 | [diff] [blame] | 197 | please_install() |
| 198 | { |
Martin Roth | 8846382 | 2016-01-07 11:03:36 -0700 | [diff] [blame] | 199 | HALT_FOR_TOOLS=1 |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 200 | # shellcheck disable=SC1091 |
Patrick Georgi | 5da95dc | 2015-07-17 23:33:05 +0200 | [diff] [blame] | 201 | test -r /etc/os-release && . /etc/os-release |
Alex Thiessen | 72d1089 | 2018-01-12 01:45:53 +0000 | [diff] [blame] | 202 | # vanilla debian doesn't define `ID_LIKE`, just `ID` |
| 203 | if [ -z "${ID_LIKE}" ] && [ -n "${ID}" ]; then |
| 204 | ID_LIKE=${ID} |
| 205 | fi |
Stefan Reinauer | 93a9630 | 2015-06-15 12:36:53 -0700 | [diff] [blame] | 206 | case "$ID_LIKE" in |
| 207 | debian) solution="sudo apt-get install $1" ;; |
| 208 | suse) solution="sudo zypper install $1" ;; |
| 209 | *) solution="using your OS packaging system" ;; |
| 210 | esac |
| 211 | |
Patrick Georgi | df1ff23 | 2017-01-07 09:28:43 +0100 | [diff] [blame] | 212 | printf "${RED}ERROR:${red} Missing tool: Please install '$1'. (eg $solution)${NC}\n" >&2 |
Martin Roth | e396317 | 2016-01-06 13:54:32 -0700 | [diff] [blame] | 213 | if [ -n "$2" ]; then |
Patrick Georgi | df1ff23 | 2017-01-07 09:28:43 +0100 | [diff] [blame] | 214 | printf "${RED}ERROR:${red} or install '$2'.${NC}\n" >&2 |
Martin Roth | e396317 | 2016-01-06 13:54:32 -0700 | [diff] [blame] | 215 | fi |
Stefan Reinauer | 93a9630 | 2015-06-15 12:36:53 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Patrick Georgi | b706288 | 2015-02-24 10:52:14 +0100 | [diff] [blame] | 218 | searchtool() |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 219 | { |
| 220 | # $1 short name |
Patrick Georgi | b706288 | 2015-02-24 10:52:14 +0100 | [diff] [blame] | 221 | # $2 search string |
| 222 | # $3 soft fail if set |
Martin Roth | e396317 | 2016-01-06 13:54:32 -0700 | [diff] [blame] | 223 | # $4 alternative package to install on failure |
Patrick Georgi | b706288 | 2015-02-24 10:52:14 +0100 | [diff] [blame] | 224 | # result: file name of that tool on stdout |
| 225 | # or no output if nothing suitable was found |
| 226 | search=GNU |
| 227 | if [ -n "$2" ]; then |
| 228 | search="$2" |
| 229 | fi |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 230 | for i in "$1" "g$1" "gnu$1"; do |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 231 | if [ -x "$(command -v "$i" 2>/dev/null)" ]; then |
Stefan Reinauer | dbc0087 | 2015-06-09 11:50:05 -0700 | [diff] [blame] | 232 | if [ "$(cat /dev/null | $i --version 2>&1 | grep -c "$search")" \ |
| 233 | -gt 0 ]; then |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 234 | echo "$i" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 235 | return |
| 236 | fi |
| 237 | fi |
| 238 | done |
Andrew Wu | b67e9a1 | 2014-04-28 18:13:44 +0800 | [diff] [blame] | 239 | # A workaround for OSX 10.9 and some BSDs, whose nongnu |
| 240 | # patch and tar also work. |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 241 | if [ "$UNAME" = "Darwin" ] || [ "$UNAME" = "FreeBSD" ] || [ "$UNAME" = "NetBSD" ] || [ "$UNAME" = "OpenBSD" ]; then |
| 242 | if [ "$1" = "patch" ] || [ "$1" = "tar" ]; then |
| 243 | if [ -x "$(command -v "$1" 2>/dev/null)" ]; then |
| 244 | echo "$1" |
Zheng Bao | 36156ff | 2012-09-28 16:18:58 +0800 | [diff] [blame] | 245 | return |
| 246 | fi |
| 247 | fi |
| 248 | fi |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 249 | if echo "$1" | grep -q "sum" ; then |
| 250 | algor=$(echo "$1" | sed -e 's,sum,,') |
| 251 | if [ -x "$(command -v "$1" 2>/dev/null)" ]; then |
zbao | 5cf758d | 2015-09-01 22:28:57 -0400 | [diff] [blame] | 252 | #xxxsum [file] |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 253 | echo "$1" |
zbao | 5cf758d | 2015-09-01 22:28:57 -0400 | [diff] [blame] | 254 | return |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 255 | elif [ -x "$(command -v "$algor" 2>/dev/null)" ]; then |
zbao | 5cf758d | 2015-09-01 22:28:57 -0400 | [diff] [blame] | 256 | #xxx [file] |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 257 | echo "$algor" |
zbao | 5cf758d | 2015-09-01 22:28:57 -0400 | [diff] [blame] | 258 | return |
Martin Roth | d55f5eb | 2017-06-15 11:37:26 -0600 | [diff] [blame] | 259 | elif [ -x "$(command -v openssl 2>/dev/null)" ]; then |
zbao | 5cf758d | 2015-09-01 22:28:57 -0400 | [diff] [blame] | 260 | #openssl xxx [file] |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 261 | echo openssl "$algor" |
zbao | 5cf758d | 2015-09-01 22:28:57 -0400 | [diff] [blame] | 262 | return |
Martin Roth | d55f5eb | 2017-06-15 11:37:26 -0600 | [diff] [blame] | 263 | elif [ -x "$(command -v cksum 2>/dev/null)" ]; then |
zbao | 5cf758d | 2015-09-01 22:28:57 -0400 | [diff] [blame] | 264 | #cksum -a xxx [file] |
| 265 | #cksum has special options in NetBSD. Actually, NetBSD will use the second case above. |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 266 | echo "buildgcc" | cksum -a "$algor" > /dev/null 2>/dev/null && \ |
| 267 | echo cksum -a "$algor" |
zbao | 5cf758d | 2015-09-01 22:28:57 -0400 | [diff] [blame] | 268 | return |
zbao | 939dc84 | 2015-04-30 04:44:07 +0800 | [diff] [blame] | 269 | fi |
| 270 | fi |
Martin Roth | e396317 | 2016-01-06 13:54:32 -0700 | [diff] [blame] | 271 | |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 272 | [ -z "$3" ] && please_install "$1" "$4" |
Patrick Georgi | b706288 | 2015-02-24 10:52:14 +0100 | [diff] [blame] | 273 | false |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Martin Roth | 591790f | 2016-03-20 20:39:04 -0600 | [diff] [blame] | 276 | # Run a compile check of the specified library option to see if it's installed |
| 277 | check_for_library() { |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 278 | LIBRARY_FLAGS="$1" |
| 279 | LIBRARY_PACKAGES="$2" |
| 280 | LIBTEST_FILE=.libtest |
Martin Roth | 591790f | 2016-03-20 20:39:04 -0600 | [diff] [blame] | 281 | |
| 282 | echo "int main(int argc, char **argv) { (void) argc; (void) argv; return 0; }" > "${LIBTEST_FILE}.c" |
| 283 | |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 284 | # shellcheck disable=SC2086 |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 285 | "$CC" $CFLAGS $LIBRARY_FLAGS "${LIBTEST_FILE}.c" -o "${LIBTEST_FILE}" >/dev/null 2>&1 || \ |
Martin Roth | 591790f | 2016-03-20 20:39:04 -0600 | [diff] [blame] | 286 | please_install "$LIBRARY_PACKAGES" |
| 287 | rm -rf "${LIBTEST_FILE}.c" "${LIBTEST_FILE}" |
| 288 | } |
| 289 | |
Nico Huber | aee7f46 | 2016-09-20 12:55:19 +0200 | [diff] [blame] | 290 | buildcc_major() { |
| 291 | echo "${GCC_VERSION}" | cut -d. -f1 |
| 292 | } |
| 293 | |
Nico Huber | 26267a7 | 2016-12-04 02:45:58 +0100 | [diff] [blame] | 294 | buildcc_minor() { |
| 295 | echo "${GCC_VERSION}" | cut -d. -f2 |
| 296 | } |
| 297 | |
Nico Huber | aee7f46 | 2016-09-20 12:55:19 +0200 | [diff] [blame] | 298 | buildcc_version() { |
| 299 | echo "${GCC_VERSION}" | cut -d. -f1-2 |
| 300 | } |
| 301 | |
| 302 | hostcc_major() { |
| 303 | (echo __GNUC__ | ${CC} -E - 2>/dev/null || echo 0) | tail -1 |
| 304 | } |
| 305 | |
| 306 | hostcc_minor() { |
| 307 | (echo __GNUC_MINOR__ | ${CC} -E - 2>/dev/null || echo 0) | tail -1 |
| 308 | } |
| 309 | |
| 310 | hostcc_version() { |
| 311 | printf "%d.%d" "$(hostcc_major)" "$(hostcc_minor)" |
| 312 | } |
| 313 | |
Nico Huber | 7579716 | 2016-09-20 13:01:57 +0200 | [diff] [blame] | 314 | hostcc_has_gnat1() { |
| 315 | [ -x "$(${CC} -print-prog-name=gnat1)" ] |
| 316 | } |
| 317 | |
Nico Huber | cd87e1b | 2017-06-24 20:35:59 +0200 | [diff] [blame] | 318 | have_gnat() { |
| 319 | hostcc_has_gnat1 && \ |
| 320 | searchtool gnatbind "Free Software Foundation" nofail > /dev/null |
| 321 | } |
| 322 | |
Nico Huber | 7579716 | 2016-09-20 13:01:57 +0200 | [diff] [blame] | 323 | ada_requested() { |
| 324 | echo "${LANGUAGES}" | grep -q '\<ada\>' |
| 325 | } |
| 326 | |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 327 | download() { |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 328 | package=$1 |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 329 | # shellcheck disable=SC2086 |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 330 | archive="$(eval echo \$$package"_ARCHIVE")" |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 331 | |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 332 | FILE=$(basename "$archive") |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 333 | printf " * $FILE " |
| 334 | |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 335 | if test -f "tarballs/$FILE"; then |
Jonathan Neuschäfer | 92d483a | 2017-09-26 22:33:53 +0200 | [diff] [blame] | 336 | printf "(cached)... " |
zbao | d22b9ea | 2015-08-30 23:35:16 -0400 | [diff] [blame] | 337 | else |
Paul Menzel | b2ba395 | 2015-06-12 11:58:14 +0200 | [diff] [blame] | 338 | printf "(downloading from $archive)" |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 339 | rm -f "tarballs/$FILE" |
| 340 | cd tarballs || exit 1 |
| 341 | download_showing_percentage "$archive" |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 342 | cd .. |
zbao | d22b9ea | 2015-08-30 23:35:16 -0400 | [diff] [blame] | 343 | fi |
| 344 | |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 345 | if [ ! -f "tarballs/$FILE" ]; then |
Patrick Georgi | df1ff23 | 2017-01-07 09:28:43 +0100 | [diff] [blame] | 346 | printf "${RED}Failed to download $FILE.${NC}\n" |
Stefan Reinauer | dbc0087 | 2015-06-09 11:50:05 -0700 | [diff] [blame] | 347 | exit 1 |
| 348 | fi |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Jonathan Neuschäfer | 92d483a | 2017-09-26 22:33:53 +0200 | [diff] [blame] | 351 | # Compute the hash of the package given in $1, and print it raw (just the |
| 352 | # hexadecimal hash). |
| 353 | compute_hash() { |
| 354 | package=$1 |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 355 | # shellcheck disable=SC2086 |
Jonathan Neuschäfer | 92d483a | 2017-09-26 22:33:53 +0200 | [diff] [blame] | 356 | archive="$(eval echo \$$package"_ARCHIVE")" |
| 357 | file="$(basename "$archive")" |
| 358 | |
| 359 | if test -z "$CHECKSUM"; then |
| 360 | echo "${RED}\$CHECKSUM program missing. This is bad.${NC}" 1>&2 |
| 361 | exit 1 |
| 362 | fi |
| 363 | |
| 364 | $CHECKSUM "tarballs/$file" 2>/dev/null | sed -e 's@.*\([0-9a-f]\{40,\}\).*@\1@' |
| 365 | } |
| 366 | |
| 367 | error_hash_missing() { |
| 368 | package="$1" |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 369 | # shellcheck disable=SC2086 |
Jonathan Neuschäfer | 92d483a | 2017-09-26 22:33:53 +0200 | [diff] [blame] | 370 | archive="$(eval echo \$$package"_ARCHIVE")" |
| 371 | file="$(basename "$archive")" |
| 372 | |
| 373 | fullhashfile="util/crossgcc/sum/$file.cksum" |
| 374 | printf "${RED}hash file missing:${NC}\n\n" 1>&2 |
| 375 | printf "Please verify util/crossgcc/tarball/$file carefully\n" 1>&2 |
| 376 | printf "(using PGP if possible), and then rename\n" 1>&2 |
| 377 | printf " ${CYAN}${fullhashfile}.calc${NC}\n" 1>&2 |
| 378 | printf " to ${CYAN}${fullhashfile}${NC}\n\n" 1>&2 |
| 379 | |
| 380 | exit 1 |
| 381 | } |
| 382 | |
| 383 | # Read the known hash file of the package given in $1, and print it raw. |
| 384 | get_known_hash() { |
| 385 | package=$1 |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 386 | # shellcheck disable=SC2086 |
Jonathan Neuschäfer | 92d483a | 2017-09-26 22:33:53 +0200 | [diff] [blame] | 387 | archive="$(eval echo \$$package"_ARCHIVE")" |
| 388 | file="$(basename "$archive")" |
| 389 | hashfile="sum/$file.cksum" |
| 390 | |
| 391 | if [ ! -f "$hashfile" ]; then |
| 392 | calc_hash="$(compute_hash "$package")" || exit 1 |
| 393 | echo "$calc_hash tarballs/$file" > "${hashfile}.calc" |
| 394 | |
| 395 | error_hash_missing "$package" |
| 396 | exit 1 |
| 397 | fi |
| 398 | |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 399 | sed -e 's@.*\([0-9a-f]\{40,\}\).*@\1@' < "$hashfile" |
Jonathan Neuschäfer | 92d483a | 2017-09-26 22:33:53 +0200 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | error_hash_mismatch() { |
| 403 | package=$1 |
| 404 | known_hash="$2" |
| 405 | computed_hash="$3" |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 406 | # shellcheck disable=SC2086 |
Jonathan Neuschäfer | 92d483a | 2017-09-26 22:33:53 +0200 | [diff] [blame] | 407 | archive="$(eval echo \$$package"_ARCHIVE")" |
| 408 | file="$(basename "$archive")" |
| 409 | |
| 410 | printf "${RED}hash mismatch:${NC}\n\n" |
| 411 | printf " expected (known) hash: $known_hash\n" |
| 412 | printf "calculated hash of downloaded file: $computed_hash\n\n" |
| 413 | |
| 414 | printf "If you think this is due to a network error, please delete\n" |
| 415 | printf " ${CYAN}util/crossgcc/tarballs/$file${NC}\n" |
| 416 | printf "and try again. If the problem persists, it may be due to an\n" |
| 417 | printf "administration error on the file server, or you might be\n" |
| 418 | printf "subject to a Man-in-the-Middle attack\n\n" |
| 419 | |
| 420 | exit 1 |
| 421 | } |
| 422 | |
| 423 | # verify_hash - Check that the hash of the file given in $1 matches the known |
| 424 | # hash; Bail out on mismatch or missing hash file. |
| 425 | verify_hash() { |
| 426 | package=$1 |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 427 | # shellcheck disable=SC2086 |
Jonathan Neuschäfer | 92d483a | 2017-09-26 22:33:53 +0200 | [diff] [blame] | 428 | archive="$(eval echo \$$package"_ARCHIVE")" |
| 429 | |
| 430 | known_hash="$(get_known_hash "$package")" || exit "$?" |
| 431 | computed_hash="$(compute_hash "$package")" || exit "$?" |
| 432 | |
| 433 | if [ "$known_hash" != "$computed_hash" ]; then |
| 434 | error_hash_mismatch "$package" "$known_hash" "$computed_hash" |
| 435 | exit 1 |
| 436 | fi |
| 437 | |
Jonathan Neuschäfer | cb76069e | 2018-10-01 09:45:49 +0200 | [diff] [blame] | 438 | printf "${GREEN}hash verified (${known_hash})${NC}\n" |
Jonathan Neuschäfer | 92d483a | 2017-09-26 22:33:53 +0200 | [diff] [blame] | 439 | } |
| 440 | |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 441 | unpack_and_patch() { |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 442 | package="$1" |
| 443 | # shellcheck disable=SC2086 |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 444 | archive="$(eval echo \$$package"_ARCHIVE")" |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 445 | # shellcheck disable=SC2086 |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 446 | dir="$(eval echo \$$package"_DIR")" |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 447 | test -d "${dir}" && test -f "${dir}/.unpack_success" || ( |
| 448 | printf " * $(basename "$archive")\n" |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 449 | FLAGS=zxf |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 450 | suffix=$(echo "$archive" | sed 's,.*\.,,') |
Martin Roth | 95f7b22 | 2016-03-20 12:38:48 -0600 | [diff] [blame] | 451 | if [ "$suffix" = "gz" ] && [ -n "$PIGZ" ]; then FLAGS="-I pigz -xf" |
| 452 | elif [ "$suffix" = "gz" ]; then FLAGS=zxf |
| 453 | elif [ "$suffix" = "bz2" ] && [ -n "$LBZIP2" ]; then FLAGS="-I lbzip2 -xf" |
| 454 | elif [ "$suffix" = "bz2" ]; then FLAGS=jxf |
| 455 | elif [ "$suffix" = "xz" ]; then FLAGS="--xz -xf" |
| 456 | elif [ "$suffix" = "lzma" ]; then FLAGS="--lzma -xf" |
| 457 | fi |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 458 | # shellcheck disable=SC2086 |
| 459 | $TAR $FLAGS "tarballs/$(basename "$archive")" |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 460 | for patch in patches/${dir}_*.patch; do |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 461 | test -r "$patch" || continue |
| 462 | printf " o $(basename "$patch")\n" |
| 463 | (cd "${dir}" || exit 1; $PATCH -s -N -p1 <"../${patch}") || { |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 464 | printf "\n${RED}Failed $patch.${NC}\n" |
Stefan Reinauer | 916b845 | 2015-06-09 11:54:49 -0700 | [diff] [blame] | 465 | exit 1 |
| 466 | } |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 467 | done |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 468 | touch "${dir}/.unpack_success" |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 469 | ) |
| 470 | } |
| 471 | |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 472 | fn_exists() |
| 473 | { |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 474 | # shellcheck disable=SC2039 |
| 475 | type "$1" >/dev/null 2>&1 |
Patrick Georgi | 74c0642 | 2015-03-25 18:40:13 +0100 | [diff] [blame] | 476 | } |
| 477 | |
Patrick Georgi | f2c15f5 | 2015-06-11 21:07:31 +0200 | [diff] [blame] | 478 | is_package_enabled() |
| 479 | { |
| 480 | echo "$PACKAGES" |grep -q "\<$1\>" |
| 481 | } |
| 482 | |
Martin Roth | 444ece2 | 2016-04-01 18:46:29 -0600 | [diff] [blame] | 483 | package_uses_targetarch() |
| 484 | { |
Stefan Reinauer | a344b68 | 2016-04-21 19:29:51 -0700 | [diff] [blame] | 485 | if [ "$1" = "GCC" ] || [ "$1" = "GDB" ] || [ "$1" = "BINUTILS" ]; then |
Martin Roth | 444ece2 | 2016-04-01 18:46:29 -0600 | [diff] [blame] | 486 | true |
| 487 | else |
| 488 | false |
| 489 | fi |
| 490 | } |
| 491 | |
Nico Huber | 11ea2b3 | 2016-01-26 16:09:31 +0100 | [diff] [blame] | 492 | generic_build() |
| 493 | { |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 494 | package=$1 |
Nico Huber | 11ea2b3 | 2016-01-26 16:09:31 +0100 | [diff] [blame] | 495 | host_target=$2 |
| 496 | builddir=$3 |
| 497 | success=$4 |
Martin Roth | c295d5e | 2016-11-14 11:56:11 -0700 | [diff] [blame] | 498 | version=$5 |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 499 | |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 500 | fn_exists "build_$package" || return |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 501 | |
Nico Huber | 11ea2b3 | 2016-01-26 16:09:31 +0100 | [diff] [blame] | 502 | mkdir -p "$builddir" |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 503 | |
Nico Huber | 11ea2b3 | 2016-01-26 16:09:31 +0100 | [diff] [blame] | 504 | if [ -f "$success" ]; then |
Martin Roth | 2c6a806 | 2016-11-14 11:58:39 -0700 | [diff] [blame] | 505 | printf "Skipping $package v$version for $host_target as it is already built\n" |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 506 | else |
Martin Roth | 2c6a806 | 2016-11-14 11:58:39 -0700 | [diff] [blame] | 507 | printf "Building $package v$version for $host_target ... " |
Nico Huber | 11ea2b3 | 2016-01-26 16:09:31 +0100 | [diff] [blame] | 508 | DIR="$PWD" |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 509 | cd "$builddir" || exit 1 |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 510 | rm -f .failed |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 511 | "build_${package}" "$host_target" > build.log 2>&1 |
| 512 | cd "$DIR" || exit 1 |
Nico Huber | 11ea2b3 | 2016-01-26 16:09:31 +0100 | [diff] [blame] | 513 | if [ ! -f "$builddir/.failed" ]; then |
| 514 | touch "$success"; |
| 515 | else |
Idwer Vollering | e2ef3cf | 2017-08-15 00:53:13 +0200 | [diff] [blame] | 516 | printf "${RED}failed${NC}. Check '$builddir/build.log'.\n" |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 517 | exit 1 |
| 518 | fi |
| 519 | printf "${green}ok${NC}\n" |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 520 | fi |
| 521 | } |
| 522 | |
Nico Huber | 11ea2b3 | 2016-01-26 16:09:31 +0100 | [diff] [blame] | 523 | build_for_host() |
| 524 | { |
Martin Roth | c295d5e | 2016-11-14 11:56:11 -0700 | [diff] [blame] | 525 | package="$1" |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 526 | # shellcheck disable=SC2086 |
Martin Roth | c295d5e | 2016-11-14 11:56:11 -0700 | [diff] [blame] | 527 | version="$(eval echo \$$package"_VERSION")" |
Patrick Georgi | 1b593e5 | 2016-11-25 15:27:41 +0100 | [diff] [blame] | 528 | generic_build "$package" host "build-$package" "${DESTDIR}${TARGETDIR}/.${package}.${version}.success" "$version" |
Nico Huber | 11ea2b3 | 2016-01-26 16:09:31 +0100 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | build_for_target() |
| 532 | { |
Martin Roth | c295d5e | 2016-11-14 11:56:11 -0700 | [diff] [blame] | 533 | package="$1" |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 534 | # shellcheck disable=SC2086 |
Martin Roth | c295d5e | 2016-11-14 11:56:11 -0700 | [diff] [blame] | 535 | version="$(eval echo \$$package"_VERSION")" |
Patrick Georgi | 1b593e5 | 2016-11-25 15:27:41 +0100 | [diff] [blame] | 536 | generic_build "$package" target "build-${TARGETARCH}-$package" "${DESTDIR}${TARGETDIR}/.${TARGETARCH}-${package}.${version}.success" "$version" |
Nico Huber | 11ea2b3 | 2016-01-26 16:09:31 +0100 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | build() |
| 540 | { |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 541 | if package_uses_targetarch "$1"; then |
| 542 | if [ $BOOTSTRAP -eq 1 ] && [ ! -f "${DESTDIR}${TARGETDIR}/.GCC.${GCC_VERSION}.success" ]; then |
Nico Huber | 234d246 | 2016-01-26 16:10:17 +0100 | [diff] [blame] | 543 | build_for_host GCC |
| 544 | fi |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 545 | build_for_target "$1" |
Nico Huber | 11ea2b3 | 2016-01-26 16:09:31 +0100 | [diff] [blame] | 546 | else |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 547 | build_for_host "$1" |
Nico Huber | 11ea2b3 | 2016-01-26 16:09:31 +0100 | [diff] [blame] | 548 | fi |
| 549 | } |
| 550 | |
Nico Huber | 18c74d6 | 2017-06-24 20:35:59 +0200 | [diff] [blame] | 551 | exit_handler() |
Zheng Bao | bb003c8 | 2016-08-05 13:41:51 +0800 | [diff] [blame] | 552 | { |
| 553 | printf "${NC}Stop\n" |
| 554 | exit 1 |
| 555 | } |
| 556 | |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 557 | cleanup() |
| 558 | { |
Stefan Reinauer | 88e83e5 | 2016-04-06 15:39:48 -0700 | [diff] [blame] | 559 | if [ $SAVETEMPS -ne 0 ]; then |
| 560 | printf "Leaving temporary files around... ${green}ok${NC}\n" |
| 561 | return |
| 562 | fi |
| 563 | |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 564 | printf "Cleaning up temporary files... " |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 565 | for package in $PACKAGES; do |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 566 | # shellcheck disable=SC2086 |
| 567 | rm -rf "build-${TARGETARCH}-$package" "build-$package" "$(eval echo \$$package"_DIR")" |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 568 | done |
zbao | ff3f15c | 2015-08-26 22:00:31 -0400 | [diff] [blame] | 569 | rm -f getopt |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 570 | printf "${green}ok${NC}\n" |
| 571 | } |
| 572 | |
| 573 | myhelp() |
| 574 | { |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 575 | printf "Usage: $0 [-V] [-c] [-p <platform>] [-d <target directory>] [-D <dest dir>] [-C] [-G] [-S]\n" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 576 | printf " $0 [-V|--version]\n" |
| 577 | printf " $0 [-h|--help]\n\n" |
| 578 | |
| 579 | printf "Options:\n" |
| 580 | printf " [-V|--version] print version number and exit\n" |
| 581 | printf " [-h|--help] print this help and exit\n" |
| 582 | printf " [-c|--clean] remove temporary files before build\n" |
| 583 | printf " [-t|--savetemps] don't remove temporary files after build\n" |
Patrick Georgi | c1a75b1 | 2011-11-04 21:37:14 +0100 | [diff] [blame] | 584 | printf " [-y|--ccache] Use ccache when building cross compiler\n" |
Nico Huber | 152e78e | 2016-09-20 15:38:40 +0200 | [diff] [blame] | 585 | printf " [-n|--nocolor] don't print color codes in output\n" |
| 586 | printf " [-u|--urls] print the urls for all packages\n" |
Patrick Georgi | 73166c7 | 2010-04-14 20:42:42 +0000 | [diff] [blame] | 587 | printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n" |
Martin Roth | 588c79d | 2016-03-20 12:03:20 -0600 | [diff] [blame] | 588 | printf " [-s]--supported <tool> print supported version of a tool\n" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 589 | printf " [-d|--directory <target dir>] target directory to install cross compiler to\n" |
Martin Roth | 588c79d | 2016-03-20 12:03:20 -0600 | [diff] [blame] | 590 | printf " (defaults to $TARGETDIR)\n\n" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 591 | printf " [-D|--destdir <dest dir>] destination directory to install cross compiler to\n" |
Stefan Reinauer | 2c3cd12 | 2011-11-01 21:43:50 +0100 | [diff] [blame] | 592 | printf " (for RPM builds, default unset)\n" |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 593 | printf " [-P|--package <package>] Build a specific package: GCC, CLANG, IASL, GDB\n" |
| 594 | printf " (defaults to $PACKAGE)\n" |
| 595 | printf "GCC specific options:\n" |
Nico Huber | 234d246 | 2016-01-26 16:10:17 +0100 | [diff] [blame] | 596 | printf " [-b|--bootstrap] bootstrap the host compiler before building\n" |
| 597 | printf " the cross compiler\n" |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 598 | printf " [-p|--platform <platform>] target platform to build cross compiler for\n" |
| 599 | printf " (defaults to $TARGETARCH)\n" |
Nico Huber | bb313bf | 2015-09-08 12:30:27 +0200 | [diff] [blame] | 600 | printf " [-l|--languages <languages>] comma separated list of target languages\n" |
Nico Huber | 66c2c1a | 2016-09-20 13:09:29 +0200 | [diff] [blame] | 601 | printf " (defaults to $DEFAULT_LANGUAGES)\n" |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 602 | printf "GDB specific options:\n" |
| 603 | printf " [-p|--platform <platform>] target platform to build cross compiler for\n" |
| 604 | printf " (defaults to $TARGETARCH)\n" |
| 605 | printf " [-S|--scripting] build scripting support for GDB\n\n" |
Martin Roth | d1da74f | 2015-06-21 12:06:28 -0600 | [diff] [blame] | 606 | printf "Platforms for GCC & GDB:\n" |
Julius Werner | f96d905 | 2019-08-16 15:35:39 -0700 | [diff] [blame] | 607 | printf " x86_64 i386-elf i386-mingw32 riscv-elf arm aarch64\n" |
Jonathan Neuschäfer | f14f640 | 2016-03-11 20:22:23 +0100 | [diff] [blame] | 608 | printf " powerpc64le-linux-gnu nds32le-elf\n\n" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Martin Roth | edf965a | 2015-11-25 16:58:33 -0700 | [diff] [blame] | 611 | printversion() { |
| 612 | printf "${blue}Welcome to the ${red}coreboot${blue} cross toolchain builder v$CROSSGCC_VERSION ($CROSSGCC_DATE)${NC}\n\n" |
| 613 | } |
| 614 | |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 615 | myversion() |
| 616 | { |
Martin Roth | edf965a | 2015-11-25 16:58:33 -0700 | [diff] [blame] | 617 | printversion |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 618 | |
| 619 | cat << EOF |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 620 | Copyright (C) 2008-2010 by coresystems GmbH |
Marc Jones | 2aac3f6 | 2011-08-08 16:07:50 -0600 | [diff] [blame] | 621 | Copyright (C) 2011 by Sage Electronic Engineering |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 622 | |
| 623 | This program is free software; you can redistribute it and/or modify |
| 624 | it under the terms of the GNU General Public License as published by |
| 625 | the Free Software Foundation; version 2 of the License. |
| 626 | |
| 627 | This program is distributed in the hope that it will be useful, |
| 628 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 629 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 630 | GNU General Public License for more details. |
| 631 | |
| 632 | EOF |
| 633 | } |
| 634 | |
Nico Huber | 5f72f96 | 2016-01-31 23:05:19 +0100 | [diff] [blame] | 635 | have_hostcflags_from_gmp() { |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 636 | grep -q __GMP_CFLAGS "$DESTDIR$TARGETDIR/include/gmp.h" >/dev/null 2>&1 |
Nico Huber | 5f72f96 | 2016-01-31 23:05:19 +0100 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | set_hostcflags_from_gmp() { |
| 640 | # Now set CFLAGS to match GMP CFLAGS but strip out -pedantic |
| 641 | # as GCC 4.6.x fails if it's there. |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 642 | HOSTCFLAGS="$(grep __GMP_CFLAGS "$DESTDIR$TARGETDIR/include/gmp.h" |cut -d\" -f2 |\ |
Idwer Vollering | ba349ab | 2016-07-24 02:10:19 +0200 | [diff] [blame] | 643 | sed s,-pedantic,,)" |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 644 | export HOSTCFLAGS |
Nico Huber | 5f72f96 | 2016-01-31 23:05:19 +0100 | [diff] [blame] | 645 | } |
| 646 | |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 647 | build_GMP() { |
Nico Huber | 8bbd596 | 2016-12-22 16:05:54 +0100 | [diff] [blame] | 648 | # Check if GCC enables `-pie` by default (possible since GCC 6). |
| 649 | # We need PIC in all static libraries then. |
Nico Huber | 2c1c02e | 2017-01-02 20:51:28 +0100 | [diff] [blame] | 650 | if $CC -dumpspecs 2>/dev/null | grep -q '[{;][[:space:]]*:-pie\>' |
Nico Huber | 8bbd596 | 2016-12-22 16:05:54 +0100 | [diff] [blame] | 651 | then |
| 652 | OPTIONS="$OPTIONS --with-pic" |
| 653 | fi |
| 654 | |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 655 | # shellcheck disable=SC2086 |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 656 | CC="$(hostcc host)" CXX="$(hostcxx host)" \ |
| 657 | ../${GMP_DIR}/configure --disable-shared --enable-fat \ |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 658 | --prefix="$TARGETDIR" $OPTIONS \ |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 659 | || touch .failed |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 660 | # shellcheck disable=SC2086 |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 661 | $MAKE $JOBS || touch .failed |
| 662 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 663 | |
| 664 | normalize_dirs |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 665 | |
Nico Huber | 5f72f96 | 2016-01-31 23:05:19 +0100 | [diff] [blame] | 666 | set_hostcflags_from_gmp |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | build_MPFR() { |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 670 | test "$UNAME" = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL" |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 671 | CC="$(hostcc host)" CXX="$(hostcxx host)" \ |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 672 | ../${MPFR_DIR}/configure --disable-shared --prefix="$TARGETDIR" \ |
| 673 | --infodir="$TARGETDIR/info" \ |
| 674 | --with-gmp="$DESTDIR$TARGETDIR" CFLAGS="$HOSTCFLAGS" || \ |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 675 | touch .failed |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 676 | # shellcheck disable=SC2086 |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 677 | $MAKE $JOBS || touch .failed |
| 678 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 679 | |
| 680 | normalize_dirs |
| 681 | |
| 682 | # work around build problem of libgmp.la |
| 683 | if [ "$DESTDIR" != "" ]; then |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 684 | perl -pi -e "s,$DESTDIR,," "$DESTDIR$TARGETDIR/lib/libgmp.la" |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 685 | fi |
| 686 | } |
| 687 | |
| 688 | build_MPC() { |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 689 | CC="$(hostcc host)" CXX="$(hostcxx host)" \ |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 690 | ../${MPC_DIR}/configure --disable-shared --prefix="$TARGETDIR" \ |
| 691 | --infodir="$TARGETDIR/info" --with-mpfr="$DESTDIR$TARGETDIR" \ |
| 692 | --with-gmp="$DESTDIR$TARGETDIR" CFLAGS="$HOSTCFLAGS" || \ |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 693 | touch .failed |
Patrick Georgi | 790aab6 | 2017-04-26 17:35:35 +0200 | [diff] [blame] | 694 | |
| 695 | # work around build problem of libmpfr.la |
| 696 | if [ "$DESTDIR" != "" ]; then |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 697 | perl -pi -e "s,$TARGETDIR/lib/libgmp.la,$DESTDIR\$&," "$DESTDIR$TARGETDIR/lib/libmpfr.la" |
Patrick Georgi | 790aab6 | 2017-04-26 17:35:35 +0200 | [diff] [blame] | 698 | fi |
| 699 | |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 700 | # shellcheck disable=SC2086 |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 701 | $MAKE $JOBS || touch .failed |
| 702 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 703 | |
Patrick Georgi | 790aab6 | 2017-04-26 17:35:35 +0200 | [diff] [blame] | 704 | # work around build problem of libmpfr.la |
| 705 | if [ "$DESTDIR" != "" ]; then |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 706 | perl -pi -e "s,$DESTDIR,," "$DESTDIR$TARGETDIR/lib/libmpfr.la" |
Patrick Georgi | 790aab6 | 2017-04-26 17:35:35 +0200 | [diff] [blame] | 707 | fi |
| 708 | |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 709 | normalize_dirs |
| 710 | } |
| 711 | |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 712 | build_BINUTILS() { |
Nico Huber | ae6187f | 2016-12-22 22:16:39 +0100 | [diff] [blame] | 713 | if [ $TARGETARCH = "x86_64-elf" ]; then |
Stefan Reinauer | 682a90c | 2015-06-09 14:59:58 -0700 | [diff] [blame] | 714 | ADDITIONALTARGET=",i386-elf" |
| 715 | fi |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 716 | CC="$(hostcc target)" CXX="$(hostcxx target)" \ |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 717 | ../binutils-${BINUTILS_VERSION}/configure --prefix="$TARGETDIR" \ |
Stefan Reinauer | 682a90c | 2015-06-09 14:59:58 -0700 | [diff] [blame] | 718 | --target=${TARGETARCH} --enable-targets=${TARGETARCH}${ADDITIONALTARGET} \ |
| 719 | --disable-werror --disable-nls --enable-lto --enable-gold \ |
Stefan Reinauer | 2fe2d3d | 2016-04-05 02:14:48 -0700 | [diff] [blame] | 720 | --enable-interwork --enable-multilib \ |
Vivia Nikolaidou | 8108436 | 2018-04-28 01:21:44 +0300 | [diff] [blame] | 721 | --enable-plugins --enable-multilibs \ |
Nico Huber | 010ecf80 | 2016-12-22 16:19:37 +0100 | [diff] [blame] | 722 | CFLAGS="$HOSTCFLAGS" \ |
| 723 | CXXFLAGS="$HOSTCFLAGS" \ |
| 724 | || touch .failed |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 725 | # shellcheck disable=SC2086 |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 726 | $MAKE $JOBS || touch .failed |
| 727 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 728 | } |
| 729 | |
Nico Huber | 234d246 | 2016-01-26 16:10:17 +0100 | [diff] [blame] | 730 | bootstrap_GCC() { |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 731 | # shellcheck disable=SC2086 |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 732 | CC="$(hostcc host)" CXX="$(hostcxx host)" \ |
Nico Huber | 234d246 | 2016-01-26 16:10:17 +0100 | [diff] [blame] | 733 | CFLAGS="$HOSTCFLAGS" \ |
| 734 | CFLAGS_FOR_BUILD="$HOSTCFLAGS" \ |
| 735 | CFLAGS_FOR_TARGET="$HOSTCFLAGS -fPIC" \ |
| 736 | CXXFLAGS="$HOSTCFLAGS" \ |
| 737 | CXXFLAGS_FOR_BUILD="$HOSTCFLAGS" \ |
| 738 | CXXFLAGS_FOR_TARGET="$HOSTCFLAGS -fPIC" \ |
| 739 | ../gcc-${GCC_VERSION}/configure \ |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 740 | --prefix="$TARGETDIR" --libexecdir="$TARGETDIR/lib" \ |
Nico Huber | 234d246 | 2016-01-26 16:10:17 +0100 | [diff] [blame] | 741 | --enable-bootstrap \ |
| 742 | --disable-werror --disable-nls \ |
| 743 | --disable-shared --disable-multilib \ |
| 744 | --disable-libssp --disable-libquadmath --disable-libcc1 \ |
Patrick Georgi | 97a9df4 | 2017-04-26 22:18:18 +0200 | [diff] [blame] | 745 | --disable-libsanitizer \ |
Nico Huber | 234d246 | 2016-01-26 16:10:17 +0100 | [diff] [blame] | 746 | ${GCC_OPTIONS} --enable-languages="${LANGUAGES}" \ |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 747 | --with-gmp="$DESTDIR$TARGETDIR" --with-mpfr="$DESTDIR$TARGETDIR" \ |
| 748 | --with-mpc="$DESTDIR$TARGETDIR" \ |
Nico Huber | 234d246 | 2016-01-26 16:10:17 +0100 | [diff] [blame] | 749 | --with-pkgversion="coreboot bootstrap v$CROSSGCC_VERSION $CROSSGCC_DATE" \ |
| 750 | && \ |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 751 | # shellcheck disable=SC2086 |
Nico Huber | 234d246 | 2016-01-26 16:10:17 +0100 | [diff] [blame] | 752 | $MAKE $JOBS BOOT_CFLAGS="$HOSTCFLAGS" BUILD_CONFIG="" bootstrap && \ |
| 753 | $MAKE install-gcc \ |
| 754 | install-target-libgcc \ |
| 755 | maybe-install-target-libada \ |
| 756 | maybe-install-target-libstdc++-v3 \ |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 757 | DESTDIR=$DESTDIR || touch .failed |
Nico Huber | 234d246 | 2016-01-26 16:10:17 +0100 | [diff] [blame] | 758 | } |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 759 | |
Nico Huber | 234d246 | 2016-01-26 16:10:17 +0100 | [diff] [blame] | 760 | build_cross_GCC() { |
Stefan Reinauer | 45f77b8 | 2016-04-03 20:52:01 -0700 | [diff] [blame] | 761 | # Work around crazy code generator in GCC that confuses CLANG. |
Aaron Durbin | b2229dc | 2016-04-07 16:58:10 -0500 | [diff] [blame] | 762 | $CC --version | grep clang >/dev/null 2>&1 && \ |
Patrick Georgi | a7a5a56 | 2017-06-26 07:21:46 +0200 | [diff] [blame] | 763 | CLANGFLAGS="-fbracket-depth=1024" |
Nico Huber | 3f12d93 | 2017-08-31 23:11:18 +0200 | [diff] [blame] | 764 | [ -n "$CXX" ] && $CXX --version | grep clang >/dev/null 2>&1 && \ |
Patrick Georgi | a7a5a56 | 2017-06-26 07:21:46 +0200 | [diff] [blame] | 765 | CLANGCXXFLAGS="-fbracket-depth=1024" |
Stefan Reinauer | 45f77b8 | 2016-04-03 20:52:01 -0700 | [diff] [blame] | 766 | |
Stefan Reinauer | d0f8372 | 2015-06-09 11:52:28 -0700 | [diff] [blame] | 767 | # GCC does not honor HOSTCFLAGS at all. CFLAGS are used for |
| 768 | # both target and host object files. |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 769 | # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET |
| 770 | # but it does not seem to work properly. At least the host library |
| 771 | # libiberty is not compiled with CFLAGS_FOR_BUILD. |
Stefan Reinauer | 45f77b8 | 2016-04-03 20:52:01 -0700 | [diff] [blame] | 772 | # Also set the CXX version of the flags because GCC is now compiled |
| 773 | # using C++. |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 774 | # shellcheck disable=SC2086 |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 775 | CC="$(hostcc target)" CXX="$(hostcxx target)" \ |
Nico Huber | 3f12d93 | 2017-08-31 23:11:18 +0200 | [diff] [blame] | 776 | CFLAGS_FOR_TARGET="-O2 -Dinhibit_libc" \ |
Patrick Georgi | a7a5a56 | 2017-06-26 07:21:46 +0200 | [diff] [blame] | 777 | CFLAGS="$HOSTCFLAGS $CLANGFLAGS" \ |
| 778 | CFLAGS_FOR_BUILD="$HOSTCFLAGS $CLANGFLAGS" \ |
| 779 | CXXFLAGS="$HOSTCFLAGS $CLANGCXXFLAGS" \ |
| 780 | CXXFLAGS_FOR_BUILD="$HOSTCFLAGS $CLANGCXXFLAGS" \ |
| 781 | ../gcc-${GCC_VERSION}/configure \ |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 782 | --prefix="$TARGETDIR" --libexecdir="$TARGETDIR/lib" \ |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 783 | --target=${TARGETARCH} --disable-werror --disable-shared \ |
Stefan Reinauer | 2f97ebc | 2015-06-09 12:24:54 -0700 | [diff] [blame] | 784 | --enable-lto --enable-plugins --enable-gold --enable-ld=default \ |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 785 | --disable-libssp --disable-bootstrap --disable-nls \ |
| 786 | --disable-libquadmath --without-headers \ |
Patrick Georgi | 0a97d7e | 2016-01-25 09:51:22 +0100 | [diff] [blame] | 787 | --disable-threads \ |
Patrick Georgi | 1fc02d1 | 2016-03-23 21:44:43 +0100 | [diff] [blame] | 788 | --enable-interwork --enable-multilib --enable-targets=all \ |
Patrick Georgi | 0a97d7e | 2016-01-25 09:51:22 +0100 | [diff] [blame] | 789 | --disable-libatomic --disable-libcc1 --disable-decimal-float \ |
Nico Huber | bb313bf | 2015-09-08 12:30:27 +0200 | [diff] [blame] | 790 | ${GCC_OPTIONS} --enable-languages="${LANGUAGES}" \ |
Ronald G. Minnich | 7ee16b7 | 2016-02-12 21:54:59 +0000 | [diff] [blame] | 791 | --with-system-zlib \ |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 792 | --with-gmp="$DESTDIR$TARGETDIR" --with-mpfr="$DESTDIR$TARGETDIR" \ |
| 793 | --with-mpc="$DESTDIR$TARGETDIR" \ |
Patrick Georgi | dce4d46 | 2018-09-07 01:00:54 +0200 | [diff] [blame] | 794 | --with-gnu-as --with-gnu-ld \ |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 795 | --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \ |
Nico Huber | 659f40b | 2018-05-23 17:06:53 +0200 | [diff] [blame] | 796 | && \ |
Patrick Georgi | 095db33 | 2018-06-26 21:00:58 +0200 | [diff] [blame] | 797 | mkdir -p gcc/$TARGETARCH && \ |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 798 | ln -s "$DESTDIR$TARGETDIR/$TARGETARCH/bin" "gcc/$TARGETARCH/$GCC_VERSION" && \ |
Nico Huber | 659f40b | 2018-05-23 17:06:53 +0200 | [diff] [blame] | 799 | $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-gcc && \ |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 800 | $MAKE install-gcc DESTDIR="$DESTDIR" || touch .failed |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 801 | |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 802 | if [ ! -f .failed ] && [ "$(echo $TARGETARCH | grep -c -- -mingw32)" -eq 0 ]; then |
| 803 | # shellcheck disable=SC2086 |
Nico Huber | 659f40b | 2018-05-23 17:06:53 +0200 | [diff] [blame] | 804 | $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-target-libgcc && \ |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 805 | $MAKE install-target-libgcc DESTDIR=$DESTDIR || touch .failed |
| 806 | fi |
| 807 | } |
| 808 | |
Nico Huber | 234d246 | 2016-01-26 16:10:17 +0100 | [diff] [blame] | 809 | build_GCC() { |
| 810 | if [ "$1" = host ]; then |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 811 | bootstrap_GCC "$1" |
Nico Huber | 234d246 | 2016-01-26 16:10:17 +0100 | [diff] [blame] | 812 | else |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 813 | build_cross_GCC "$1" |
Nico Huber | 234d246 | 2016-01-26 16:10:17 +0100 | [diff] [blame] | 814 | fi |
| 815 | } |
| 816 | |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 817 | build_EXPAT() { |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 818 | CC="$(hostcc host)" CXX="$(hostcxx host)" CFLAGS="$HOSTCFLAGS" |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 819 | ../${EXPAT_DIR}/configure --disable-shared --prefix="$TARGETDIR" \ |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 820 | || touch .failed |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 821 | $MAKE || touch .failed |
| 822 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 823 | |
| 824 | normalize_dirs |
| 825 | } |
| 826 | |
| 827 | build_PYTHON() { |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 828 | CC="$(hostcc host)" CXX="$(hostcxx host)" CFLAGS="$HOSTCFLAGS" |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 829 | ../${PYTHON_DIR}/configure --prefix="$TARGETDIR" \ |
Stefan Reinauer | a344b68 | 2016-04-21 19:29:51 -0700 | [diff] [blame] | 830 | || touch .failed |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 831 | # shellcheck disable=SC2086 |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 832 | $MAKE $JOBS || touch .failed |
| 833 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 834 | |
| 835 | normalize_dirs |
| 836 | } |
| 837 | |
| 838 | build_GDB() { |
| 839 | export PYTHONHOME=$DESTDIR$TARGETDIR |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 840 | if [ "$UNAME" != "FreeBSD" ] && [ "$UNAME" != "NetBSD" ]; then |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 841 | LIBDL="-ldl" |
| 842 | fi |
| 843 | LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \ |
| 844 | -lpthread $LIBDL -lutil" \ |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 845 | CC="$(hostcc target)" CXX="$(hostcxx target)" \ |
| 846 | CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \ |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 847 | ../${GDB_DIR}/configure --prefix="$TARGETDIR" \ |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 848 | --target=${TARGETARCH} --disable-werror --disable-nls |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 849 | # shellcheck disable=SC2086 |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 850 | $MAKE $JOBS || touch .failed |
| 851 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 852 | } |
| 853 | |
| 854 | build_IASL() { |
| 855 | RDIR=$PWD |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 856 | cd ../$IASL_DIR/generate/unix || exit 1 |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 857 | CFLAGS="$HOSTCFLAGS" |
| 858 | HOST="_LINUX" |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 859 | test "$UNAME" = "Darwin" && HOST="_APPLE" |
| 860 | test "$UNAME" = "FreeBSD" && HOST="_FreeBSD" |
| 861 | test "$UNAME" = "Cygwin" && HOST="_CYGWIN" |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 862 | HOST="$HOST" CFLAGS="$CFLAGS" \ |
| 863 | OPT_CFLAGS="-O -D_FORTIFY_SOURCE=2 -D COREBOOT_TOOLCHAIN_VERSION='\"coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE\"' " \ |
Stefan Reinauer | 7385b656 | 2019-10-27 00:39:47 -0700 | [diff] [blame] | 864 | $MAKE $JOBS CC="$(hostcc host)" iasl acpibin acpidump acpiexec acpihelp acpinames acpisrc acpixtract |
| 865 | rm -f "$DESTDIR$TARGETDIR/bin/{iasl,acpibin,acpidump,acpiexec,acpihelp,acpinames,acpisrc,acpixtract}" || touch "$RDIR/.failed" |
| 866 | cp bin/{iasl,acpibin,acpidump,acpiexec,acpihelp,acpinames,acpisrc,acpixtract} "$DESTDIR$TARGETDIR/bin" || touch "$RDIR/.failed" |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | build_LLVM() { |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 870 | |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 871 | cd .. || exit 1 |
| 872 | ln -sf "$PWD/$CFE_DIR" "$LLVM_DIR/tools/clang" |
| 873 | ln -sf "$PWD/$CTE_DIR" "$LLVM_DIR/tools/clang/tools/extra" |
| 874 | ln -sf "$PWD/$CRT_DIR" "$LLVM_DIR/projects/compiler-rt" |
| 875 | cd - || exit 1 |
| 876 | |
| 877 | $CMAKE -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$DESTDIR$TARGETDIR" \ |
Martin Roth | fb5647a | 2015-12-18 09:26:45 -0700 | [diff] [blame] | 878 | -DCLANG_VENDOR="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE - " \ |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 879 | -DCMAKE_BUILD_TYPE=Release ../$LLVM_DIR || touch .failed |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 880 | # shellcheck disable=SC2086 |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 881 | $MAKE $JOBS || touch .failed |
| 882 | $MAKE install || touch .failed |
| 883 | |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 884 | cp -a ../$CFE_DIR/tools/scan-build/* "$DESTDIR$TARGETDIR/bin" |
| 885 | cp -a ../$CFE_DIR/tools/scan-view/* "$DESTDIR$TARGETDIR/bin" |
Stefan Reinauer | e9e6e3d | 2015-07-07 00:20:42 +0200 | [diff] [blame] | 886 | |
| 887 | # create symlinks to work around broken --print-librt-file-name |
| 888 | # when used with -target. |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 889 | cd "$DESTDIR$TARGETDIR/lib/clang/${CLANG_VERSION}/lib" || exit 1 |
Stefan Reinauer | e9e6e3d | 2015-07-07 00:20:42 +0200 | [diff] [blame] | 890 | for i in */libclang_rt.builtins*.a; do |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 891 | ln -s "$i" . |
Stefan Reinauer | e9e6e3d | 2015-07-07 00:20:42 +0200 | [diff] [blame] | 892 | done |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 893 | } |
| 894 | |
Stefan Reinauer | a851bbb | 2016-01-29 18:03:26 -0800 | [diff] [blame] | 895 | build_MAKE() { |
Stefan Reinauer | f5fa96f | 2019-09-21 17:39:30 -0700 | [diff] [blame] | 896 | ( cd ../${MAKE_DIR}/ && aclocal && autoconf ) |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 897 | CC="$(hostcc host)" CXX="$(hostcxx host)" CFLAGS="$HOSTCFLAGS" \ |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 898 | ../${MAKE_DIR}/configure --prefix="$TARGETDIR" --disable-nls \ |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 899 | || touch .failed |
Stefan Reinauer | f5fa96f | 2019-09-21 17:39:30 -0700 | [diff] [blame] | 900 | $MAKE -k clean |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 901 | # shellcheck disable=SC2086 |
Stefan Reinauer | a851bbb | 2016-01-29 18:03:26 -0800 | [diff] [blame] | 902 | $MAKE $JOBS || touch .failed |
| 903 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 904 | |
| 905 | normalize_dirs |
| 906 | } |
| 907 | |
Stefan Reinauer | 3b59349 | 2017-06-19 17:28:54 -0700 | [diff] [blame] | 908 | build_CMAKE() { |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 909 | CC="$(hostcc host)" CXX="$(hostcxx host)" CFLAGS="$HOSTCFLAGS" \ |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 910 | ../${CMAKE_DIR}/configure --prefix="$TARGETDIR" \ |
Stefan Reinauer | 3b59349 | 2017-06-19 17:28:54 -0700 | [diff] [blame] | 911 | || touch .failed |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 912 | # shellcheck disable=SC2086 |
Stefan Reinauer | 3b59349 | 2017-06-19 17:28:54 -0700 | [diff] [blame] | 913 | $MAKE $JOBS || touch .failed |
| 914 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 915 | |
| 916 | normalize_dirs |
| 917 | } |
| 918 | |
Martin Roth | d70f5fa | 2019-05-26 17:24:19 -0600 | [diff] [blame] | 919 | build_NASM() { |
| 920 | CC="$(hostcc host)" CXX="$(hostcxx host)" CFLAGS="$HOSTCFLAGS" |
| 921 | ../${NASM_DIR}/configure --prefix="$TARGETDIR" \ |
| 922 | || touch .failed |
| 923 | # shellcheck disable=SC2086 |
| 924 | $MAKE $JOBS || touch .failed |
| 925 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 926 | |
| 927 | normalize_dirs |
| 928 | } |
| 929 | |
Stefan Reinauer | c66fd3c | 2017-06-21 14:57:28 -0700 | [diff] [blame] | 930 | print_supported() { |
| 931 | case "$PRINTSUPPORTED" in |
Martin Roth | edf965a | 2015-11-25 16:58:33 -0700 | [diff] [blame] | 932 | AUTOCONF|autoconf) printf "%s\n" "$GCC_AUTOCONF_VERSION";; |
| 933 | BINUTILS|binutils) printf "%s\n" "$BINUTILS_VERSION";; |
| 934 | CLANG|clang) printf "%s\n" "$CLANG_VERSION";; |
| 935 | EXPAT|expat) printf "%s\n" "$EXPAT_VERSION";; |
| 936 | GCC|gcc) printf "%s\n" "$GCC_VERSION";; |
| 937 | GDB|gdb) printf "%s\n" "$GDB_VERSION";; |
| 938 | GMP|gmp) printf "%s\n" "$GMP_VERSION";; |
| 939 | IASL|iasl) printf "%s\n" "$IASL_VERSION";; |
Martin Roth | edf965a | 2015-11-25 16:58:33 -0700 | [diff] [blame] | 940 | MPC|mpc) printf "%s\n" "$MPC_VERSION";; |
| 941 | MPFR|mpfr) printf "%s\n" "$MPFR_VERSION";; |
| 942 | PYTHON|python) printf "%s\n" "$PYTHON_VERSION";; |
Stefan Reinauer | a851bbb | 2016-01-29 18:03:26 -0800 | [diff] [blame] | 943 | MAKE|make) printf "%s\n" "$MAKE_VERSION";; |
Martin Roth | d70f5fa | 2019-05-26 17:24:19 -0600 | [diff] [blame] | 944 | NASM|nasm) printf "%s\n" "${NASM_VERSION}";; |
Stefan Reinauer | c66fd3c | 2017-06-21 14:57:28 -0700 | [diff] [blame] | 945 | *) printf "Unknown tool %s\n" "$PRINTSUPPORTED";; |
Martin Roth | edf965a | 2015-11-25 16:58:33 -0700 | [diff] [blame] | 946 | esac |
| 947 | } |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 948 | |
Nico Huber | 18c74d6 | 2017-06-24 20:35:59 +0200 | [diff] [blame] | 949 | trap exit_handler 1 2 3 15 |
Zheng Bao | bb003c8 | 2016-08-05 13:41:51 +0800 | [diff] [blame] | 950 | |
Patrick Georgi | 6bba29f | 2010-01-29 17:40:52 +0000 | [diff] [blame] | 951 | # Look if we have getopt. If not, build it. |
| 952 | export PATH=$PATH:. |
| 953 | getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c |
| 954 | |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 955 | # parse parameters.. try to find out whether we're running GNU getopt |
Nico Huber | 27e8412b | 2017-12-05 22:02:21 +0100 | [diff] [blame] | 956 | getoptbrand="$(getopt -V 2>/dev/null | sed -e '1!d' -e 's,^\(......\).*,\1,')" |
Peter Stuge | 09377b7 | 2011-08-21 06:24:55 +0200 | [diff] [blame] | 957 | if [ "${getoptbrand}" = "getopt" ]; then |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 958 | # Detected GNU getopt that supports long options. |
Patrick Georgi | 9681cdc | 2017-09-22 18:57:10 +0200 | [diff] [blame] | 959 | args=$(getopt -l version,help,clean,directory:,bootstrap,bootstrap-only,platform:,languages:,package:,jobs:,destdir:,savetemps,scripting,ccache,supported:,urls,nocolor -o Vhcd:bBp:l:P:j:D:tSys:un -- "$@") |
Nico Huber | 78df0bf | 2016-09-20 14:11:53 +0200 | [diff] [blame] | 960 | getopt_ret=$? |
Nico Huber | cc414dd | 2016-09-20 13:59:38 +0200 | [diff] [blame] | 961 | eval set -- "$args" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 962 | else |
| 963 | # Detected non-GNU getopt |
Patrick Georgi | 9681cdc | 2017-09-22 18:57:10 +0200 | [diff] [blame] | 964 | args=$(getopt Vhcd:bBp:l:P:j:D:tSys:un $*) |
Nico Huber | 78df0bf | 2016-09-20 14:11:53 +0200 | [diff] [blame] | 965 | getopt_ret=$? |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 966 | # shellcheck disable=SC2086 |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 967 | set -- $args |
| 968 | fi |
| 969 | |
Nico Huber | 78df0bf | 2016-09-20 14:11:53 +0200 | [diff] [blame] | 970 | if [ $getopt_ret != 0 ]; then |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 971 | myhelp |
| 972 | exit 1 |
| 973 | fi |
| 974 | |
| 975 | while true ; do |
| 976 | case "$1" in |
Patrick Georgi | 9681cdc | 2017-09-22 18:57:10 +0200 | [diff] [blame] | 977 | -V|--version) shift; myversion; exit 0;; |
| 978 | -h|--help) shift; myhelp; exit 0;; |
| 979 | -c|--clean) shift; clean=1;; |
| 980 | -t|--savetemps) shift; SAVETEMPS=1;; |
| 981 | -d|--directory) shift; TARGETDIR="$1"; shift;; |
| 982 | -b|--bootstrap) shift; BOOTSTRAP=1;; |
| 983 | -B|--bootstrap-only) shift; BOOTSTRAPONLY=1; BOOTSTRAP=1;; |
| 984 | -p|--platform) shift; TARGETARCH="$1"; shift;; |
| 985 | -l|--languages) shift; LANGUAGES="$1"; shift;; |
| 986 | -D|--destdir) shift; DESTDIR="$1"; shift;; |
| 987 | -j|--jobs) shift; THREADS="$1"; JOBS="-j $1"; shift;; |
| 988 | -P|--package) shift; PACKAGE="$1"; shift;; |
| 989 | -S|--scripting) shift; SKIPPYTHON=0;; |
| 990 | -y|--ccache) shift; USECCACHE=1;; |
| 991 | -s|--supported) shift; PRINTSUPPORTED="$1"; shift;; |
| 992 | -u|--urls) shift; printf "%s\n" "$ALL_ARCHIVES"; exit 0;; |
| 993 | -n|--nocolor) shift; \ |
Martin Roth | 4a53db0 | 2016-03-01 15:21:07 -0700 | [diff] [blame] | 994 | unset red RED green GREEN blue BLUE cyan CYAN NC;; |
Patrick Georgi | d2e0dd5 | 2013-06-09 08:05:45 +0200 | [diff] [blame] | 995 | --) shift; break;; |
Patrick Georgi | d2e0dd5 | 2013-06-09 08:05:45 +0200 | [diff] [blame] | 996 | *) break;; |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 997 | esac |
| 998 | done |
| 999 | |
Nico Huber | bd74d56 | 2016-09-20 14:16:43 +0200 | [diff] [blame] | 1000 | if [ $# -gt 0 ]; then |
| 1001 | printf "Excessive arguments: $*\n" |
| 1002 | myhelp |
| 1003 | exit 1 |
| 1004 | fi |
| 1005 | |
Stefan Reinauer | c66fd3c | 2017-06-21 14:57:28 -0700 | [diff] [blame] | 1006 | if [ -n "$PRINTSUPPORTED" ]; then |
| 1007 | print_supported |
Martin Roth | edf965a | 2015-11-25 16:58:33 -0700 | [diff] [blame] | 1008 | exit 0 |
| 1009 | fi |
| 1010 | |
| 1011 | #print toolchain builder version string as the header |
| 1012 | printversion |
| 1013 | |
Martin Roth | 2c6a806 | 2016-11-14 11:58:39 -0700 | [diff] [blame] | 1014 | printf "Building toolchain using %d thread(s).\n\n" "$THREADS" |
| 1015 | |
Ronald G. Minnich | b460a66 | 2013-05-26 05:33:35 -0700 | [diff] [blame] | 1016 | case "$TARGETARCH" in |
Timothy Pearson | a9f6235 | 2015-12-30 18:59:00 -0600 | [diff] [blame] | 1017 | x86_64-elf) ;; |
| 1018 | x86_64*) TARGETARCH=x86_64-elf;; |
| 1019 | i386-elf) ;; |
| 1020 | i386-mingw32) ;; |
Iru Cai | ae8e3a0 | 2016-04-02 10:50:59 +0800 | [diff] [blame] | 1021 | riscv-elf) TARGETARCH=riscv64-elf;; |
Patrick Georgi | 0a97d7e | 2016-01-25 09:51:22 +0100 | [diff] [blame] | 1022 | powerpc64*-linux*) ;; |
Timothy Pearson | a9f6235 | 2015-12-30 18:59:00 -0600 | [diff] [blame] | 1023 | i386*) TARGETARCH=i386-elf;; |
Stefan Reinauer | 27522ad | 2016-01-29 17:31:34 -0800 | [diff] [blame] | 1024 | arm*) TARGETARCH=arm-eabi;; |
Timothy Pearson | a9f6235 | 2015-12-30 18:59:00 -0600 | [diff] [blame] | 1025 | aarch64*) TARGETARCH=aarch64-elf;; |
Martin Roth | 3e0f74d | 2016-03-08 12:07:04 -0700 | [diff] [blame] | 1026 | nds32le-elf) ;; |
Timothy Pearson | a9f6235 | 2015-12-30 18:59:00 -0600 | [diff] [blame] | 1027 | *) printf "${red}WARNING: Unsupported architecture $TARGETARCH.${NC}\n\n"; ;; |
Ronald G. Minnich | b460a66 | 2013-05-26 05:33:35 -0700 | [diff] [blame] | 1028 | esac |
| 1029 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 1030 | # Figure out which packages to build |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 1031 | |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 1032 | case "$PACKAGE" in |
| 1033 | GCC|gcc) |
Stefan Reinauer | 81693d4 | 2017-06-21 15:25:36 -0700 | [diff] [blame] | 1034 | echo "Target architecture is $TARGETARCH" |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 1035 | NAME="${TARGETARCH} cross GCC" |
Nico Huber | afda56e | 2017-12-07 17:50:53 +0100 | [diff] [blame] | 1036 | PACKAGES="GMP MPFR MPC BINUTILS GCC" |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 1037 | ;; |
| 1038 | GDB|gdb) |
| 1039 | NAME="${TARGETARCH} cross GDB" |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 1040 | if [ $SKIPPYTHON -eq 0 ]; then |
Ronald G. Minnich | fb944f4 | 2016-02-27 04:06:42 +0000 | [diff] [blame] | 1041 | PACKAGES="EXPAT PYTHON GDB" |
| 1042 | else |
| 1043 | PACKAGES="EXPAT GDB" |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 1044 | fi |
| 1045 | ;; |
| 1046 | CLANG|clang) |
Stefan Reinauer | 81693d4 | 2017-06-21 15:25:36 -0700 | [diff] [blame] | 1047 | NAME="LLVM clang" |
| 1048 | LLVM_VERSION=${CLANG_VERSION} |
Stefan Reinauer | ca117e7 | 2017-06-19 17:29:08 -0700 | [diff] [blame] | 1049 | PACKAGES="CMAKE LLVM CFE CRT CTE" |
| 1050 | CMAKE=${DESTDIR}${TARGETDIR}/bin/cmake |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 1051 | ;; |
| 1052 | IASL|iasl) |
| 1053 | NAME="IASL ACPI compiler" |
| 1054 | PACKAGES=IASL |
| 1055 | ;; |
Stefan Reinauer | a851bbb | 2016-01-29 18:03:26 -0800 | [diff] [blame] | 1056 | MAKE|make) |
| 1057 | NAME="GNU Make" |
| 1058 | PACKAGES=MAKE |
| 1059 | ;; |
Stefan Reinauer | 3b59349 | 2017-06-19 17:28:54 -0700 | [diff] [blame] | 1060 | CMAKE|cmake) |
| 1061 | NAME="CMake" |
| 1062 | PACKAGES=CMAKE |
| 1063 | ;; |
Martin Roth | d70f5fa | 2019-05-26 17:24:19 -0600 | [diff] [blame] | 1064 | NASM|nasm) |
| 1065 | NAME="NASM" |
| 1066 | PACKAGES=NASM |
| 1067 | ;; |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 1068 | *) |
Martin Roth | d70f5fa | 2019-05-26 17:24:19 -0600 | [diff] [blame] | 1069 | printf "${red}ERROR: Unsupported package $PACKAGE. (Supported packages are GCC, GDB, CLANG, IASL, MAKE, and NASM)${NC}\n\n"; |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 1070 | exit 1 |
| 1071 | ;; |
| 1072 | esac |
Peter Stuge | ceacd77 | 2011-06-09 04:54:16 +0200 | [diff] [blame] | 1073 | |
Stefan Reinauer | 66e9335 | 2015-06-16 22:38:23 +0200 | [diff] [blame] | 1074 | # Find all the required tools: |
| 1075 | |
| 1076 | TAR=$(searchtool tar) || exit $? |
| 1077 | PATCH=$(searchtool patch) || exit $? |
| 1078 | MAKE=$(searchtool make) || exit $? |
| 1079 | SHA1SUM=$(searchtool sha1sum) |
zbao | 5cf758d | 2015-09-01 22:28:57 -0400 | [diff] [blame] | 1080 | #SHA512SUM=$(searchtool sha512sum) |
| 1081 | #MD5SUM=$(searchtool md5sum) |
Stefan Reinauer | 66e9335 | 2015-06-16 22:38:23 +0200 | [diff] [blame] | 1082 | CHECKSUM=$SHA1SUM |
Martin Roth | 95f7b22 | 2016-03-20 12:38:48 -0600 | [diff] [blame] | 1083 | LBZIP2=$(searchtool lbzip2 "" nofail) |
| 1084 | PIGZ=$(searchtool pigz "" nofail) |
Stefan Reinauer | 66e9335 | 2015-06-16 22:38:23 +0200 | [diff] [blame] | 1085 | |
| 1086 | searchtool m4 > /dev/null |
| 1087 | searchtool bison > /dev/null |
| 1088 | searchtool flex flex > /dev/null |
Stefan Reinauer | 66e9335 | 2015-06-16 22:38:23 +0200 | [diff] [blame] | 1089 | searchtool bzip2 "bzip2," > /dev/null |
Nico Huber | 0ff3b39 | 2017-03-12 16:07:33 +0100 | [diff] [blame] | 1090 | searchtool xz "XZ Utils" "" "xz-utils" > /dev/null |
Stefan Reinauer | 66e9335 | 2015-06-16 22:38:23 +0200 | [diff] [blame] | 1091 | |
Patrick Georgi | df1ff23 | 2017-01-07 09:28:43 +0100 | [diff] [blame] | 1092 | if searchtool wget "GNU" nofail > /dev/null; then |
| 1093 | download_showing_percentage() { |
| 1094 | url=$1 |
Stefan Reinauer | 81693d4 | 2017-06-21 15:25:36 -0700 | [diff] [blame] | 1095 | printf "... ${red} 0%%" |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 1096 | wget "$url" 2>&1 | while read -r line; do |
| 1097 | echo "$line" | grep -o "[0-9]\+%" | awk '{printf("\b\b\b\b%4s", $1)}' |
Patrick Georgi | df1ff23 | 2017-01-07 09:28:43 +0100 | [diff] [blame] | 1098 | done |
Jonathan Neuschäfer | 92d483a | 2017-09-26 22:33:53 +0200 | [diff] [blame] | 1099 | printf "${NC}... " |
Patrick Georgi | df1ff23 | 2017-01-07 09:28:43 +0100 | [diff] [blame] | 1100 | } |
| 1101 | elif searchtool curl "^curl " > /dev/null; then |
| 1102 | download_showing_percentage() { |
| 1103 | url=$1 |
| 1104 | echo |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 1105 | curl -#OL "$url" |
Patrick Georgi | df1ff23 | 2017-01-07 09:28:43 +0100 | [diff] [blame] | 1106 | } |
| 1107 | fi |
| 1108 | |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 1109 | # Allow $CC override from the environment. |
| 1110 | if [ -n "$CC" ]; then |
| 1111 | if [ ! -x "$(command -v "$CC" 2>/dev/null)" ]; then |
| 1112 | printf "${RED}ERROR:${red} CC is set to '%s' but wasn't found.${NC}\n" "$CC" |
| 1113 | HALT_FOR_TOOLS=1 |
| 1114 | fi |
| 1115 | else |
Patrick Georgi | 8f2cdad | 2017-07-10 11:48:34 +0200 | [diff] [blame] | 1116 | if searchtool gnatgcc "Free Software Foundation" nofail > /dev/null; then |
| 1117 | CC=gnatgcc |
| 1118 | elif searchtool gcc "Free Software Foundation" nofail > /dev/null; then |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 1119 | CC=gcc |
| 1120 | else |
| 1121 | searchtool cc '^' nofail > /dev/null || please_install gcc |
| 1122 | CC=cc |
| 1123 | fi |
| 1124 | fi |
Martin Roth | 591790f | 2016-03-20 20:39:04 -0600 | [diff] [blame] | 1125 | |
Nico Huber | 08bb837 | 2017-06-24 19:50:35 +0200 | [diff] [blame] | 1126 | # We can leave $CXX empty if it's not set since *buildgcc* never |
| 1127 | # calls it directly. This way configure scripts can search for |
| 1128 | # themselves and we still override it when a bootstrapped g++ is |
| 1129 | # to be used (cf. hostcxx()). |
| 1130 | if [ -n "$CXX" ]; then |
| 1131 | if [ ! -x "$(command -v "$CXX" 2>/dev/null)" ]; then |
| 1132 | printf "${RED}ERROR:${red} CXX is set to '%s' but wasn't found.${NC}\n" "$CXX" |
| 1133 | HALT_FOR_TOOLS=1 |
| 1134 | fi |
| 1135 | else |
| 1136 | searchtool g++ "Free Software Foundation" nofail > /dev/null || \ |
| 1137 | searchtool clang "clang version" nofail > /dev/null || \ |
| 1138 | searchtool clang "LLVM" "" "g++" > /dev/null |
| 1139 | fi |
| 1140 | |
| 1141 | check_for_library "-lz" "zlib (zlib1g-dev or zlib-devel)" |
Nico Huber | 156d87c | 2016-09-20 12:59:53 +0200 | [diff] [blame] | 1142 | |
Martin Roth | 8846382 | 2016-01-07 11:03:36 -0700 | [diff] [blame] | 1143 | if [ "$HALT_FOR_TOOLS" -ne 0 ]; then |
| 1144 | exit 1 |
| 1145 | fi |
| 1146 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 1147 | # This initial cleanup is useful when updating the toolchain script. |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 1148 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 1149 | if [ "$clean" = "1" ]; then |
| 1150 | cleanup |
| 1151 | fi |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 1152 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 1153 | # Set up host compiler and flags needed for various OSes |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 1154 | |
Patrick Georgi | f2c15f5 | 2015-06-11 21:07:31 +0200 | [diff] [blame] | 1155 | if is_package_enabled "GCC"; then |
Patrick Georgi | e8253fe | 2017-07-18 11:35:35 +0200 | [diff] [blame] | 1156 | # sane preset: let the configure script figure out things by itself |
| 1157 | # more importantly, avoid any values that might already linger in the variable |
| 1158 | OPTIONS="ABI=" |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 1159 | if [ "$UNAME" = "Darwin" ]; then |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 1160 | #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix" |
| 1161 | |
| 1162 | # generally the OS X compiler can create x64 binaries. |
| 1163 | # Per default it generated i386 binaries in 10.5 and x64 |
| 1164 | # binaries in 10.6 (even if the kernel is 32bit) |
| 1165 | # For some weird reason, 10.5 autodetects an ABI=64 though |
| 1166 | # so we're setting the ABI explicitly here. |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 1167 | if [ "$(sysctl -n hw.optional.x86_64 2>/dev/null)" -eq 1 ] 2>/dev/null; then |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 1168 | OPTIONS="ABI=64" |
| 1169 | else |
| 1170 | OPTIONS="ABI=32" |
| 1171 | fi |
Stefan Reinauer | 9491b4d | 2011-10-11 22:37:59 -0700 | [diff] [blame] | 1172 | |
Stefan Reinauer | 4266b92 | 2012-12-05 16:18:32 -0800 | [diff] [blame] | 1173 | # In Xcode 4.5.2 the default compiler is clang. |
| 1174 | # However, this compiler fails to compile gcc 4.7.x. As a |
| 1175 | # workaround it's possible to compile gcc with llvm-gcc. |
Stefan Reinauer | 9491b4d | 2011-10-11 22:37:59 -0700 | [diff] [blame] | 1176 | if $CC -v 2>&1 | grep -q LLVM; then |
Stefan Reinauer | 4266b92 | 2012-12-05 16:18:32 -0800 | [diff] [blame] | 1177 | CC=llvm-gcc |
Stefan Reinauer | 9491b4d | 2011-10-11 22:37:59 -0700 | [diff] [blame] | 1178 | fi |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 1179 | elif [ "$UNAME" = "Linux" ] || [ "$UNAME" = "Cygwin" ]; then |
Patrick Georgi | ddb8f80 | 2015-07-04 17:45:54 +0200 | [diff] [blame] | 1180 | # gmp is overeager with detecting 64bit CPUs even if they run |
| 1181 | # a 32bit kernel and userland. |
| 1182 | if [ "$(uname -m 2>/dev/null)" = "i686" ]; then |
| 1183 | OPTIONS="ABI=32" |
| 1184 | fi |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 1185 | elif [ "$UNAME" = "NetBSD" ]; then |
Nico Huber | de45c59 | 2016-01-20 23:22:33 +0100 | [diff] [blame] | 1186 | # same for NetBSD but this one reports an i386 |
| 1187 | if [ "$(uname -m 2>/dev/null)" = "i386" ]; then |
| 1188 | OPTIONS="ABI=32" |
| 1189 | fi |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 1190 | fi |
Nico Huber | 66c2c1a | 2016-09-20 13:09:29 +0200 | [diff] [blame] | 1191 | if [ -z "${LANGUAGES}" ]; then |
Nico Huber | cd87e1b | 2017-06-24 20:35:59 +0200 | [diff] [blame] | 1192 | if have_gnat; then |
Nico Huber | 66c2c1a | 2016-09-20 13:09:29 +0200 | [diff] [blame] | 1193 | printf "\nFound compatible Ada compiler, enabling Ada support by default.\n\n" |
| 1194 | LANGUAGES="ada,${DEFAULT_LANGUAGES}" |
| 1195 | else |
Nico Huber | cd87e1b | 2017-06-24 20:35:59 +0200 | [diff] [blame] | 1196 | printf "\n${red}WARNING${NC}\n" |
| 1197 | printf "No compatible Ada compiler (GNAT) found. You can continue without\n" |
| 1198 | printf "Ada support, but this will limit the features of ${blue}coreboot${NC} (e.g.\n" |
| 1199 | printf "native graphics initialization won't be available on most Intel\n" |
| 1200 | printf "boards).\n\n" |
| 1201 | |
| 1202 | printf "Usually, you can install GNAT with your package management system\n" |
| 1203 | printf "(the package is called \`gnat\` or \`gcc-ada\`). It has to match the\n" |
| 1204 | printf "\`gcc\` package in version. If there are multiple versions of GCC in-\n" |
| 1205 | printf "stalled, you can point this script to the matching version through\n" |
| 1206 | printf "the \`CC\` and \`CXX\` environment variables.\n\n" |
| 1207 | |
| 1208 | printf "e.g. on Ubuntu 14.04, if \`gcc\` is \`gcc-4.8\`:\n" |
| 1209 | printf " apt-get install gnat-4.8 && make crossgcc\n\n" |
| 1210 | |
| 1211 | printf "on Ubuntu 16.04, if \`gcc\` is \`gcc-5\`:\n" |
| 1212 | printf " apt-get install gnat-5 && make crossgcc\n" |
| 1213 | timeout 30 |
Nico Huber | 66c2c1a | 2016-09-20 13:09:29 +0200 | [diff] [blame] | 1214 | LANGUAGES="${DEFAULT_LANGUAGES}" |
| 1215 | fi |
| 1216 | fi |
Nico Huber | cd87e1b | 2017-06-24 20:35:59 +0200 | [diff] [blame] | 1217 | if ada_requested; then |
| 1218 | if have_gnat; then |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 1219 | if [ "$BOOTSTRAP" != 1 ] && \ |
Stefan Tauner | b75a08b | 2018-08-01 06:57:36 +0200 | [diff] [blame] | 1220 | { [ "$(hostcc_major)" -lt 4 ] || \ |
| 1221 | { [ "$(hostcc_major)" -eq 4 ] && \ |
| 1222 | [ "$(hostcc_minor)" -lt 9 ] ; } ; } |
Nico Huber | cd87e1b | 2017-06-24 20:35:59 +0200 | [diff] [blame] | 1223 | then |
| 1224 | printf "\n${red}WARNING${NC}\n" |
| 1225 | printf "Building the Ada compiler (GNAT $(buildcc_version)) with a host compiler older\n" |
| 1226 | printf "than 4.9.x (yours $(hostcc_version)) requires bootstrapping. This will take\n" |
| 1227 | printf "significantly longer than a usual build. You can abort and update\n" |
| 1228 | printf "your host GNAT or disable Ada support with BUILD_LANGUAGES=c (or\n" |
| 1229 | printf "\`-l c\` in case you invoke \`buildgcc\` directly).\n" |
| 1230 | timeout 15 |
| 1231 | BOOTSTRAP=1 |
| 1232 | fi |
| 1233 | else |
| 1234 | please_install gnat gcc-ada |
| 1235 | exit 1 |
| 1236 | fi |
| 1237 | else |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 1238 | if [ "$(hostcc_major)" -lt 4 ] && [ "$BOOTSTRAP" != 1 ]; then |
Nico Huber | cd87e1b | 2017-06-24 20:35:59 +0200 | [diff] [blame] | 1239 | printf "\n${red}WARNING${NC}\n" |
| 1240 | printf "Building GCC $(buildcc_version) with a very old host compiler ($(hostcc_version)).\n" |
| 1241 | printf "Bootstrapping (-b) is recommended.\n" |
| 1242 | timeout 10 |
| 1243 | fi |
| 1244 | fi |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 1245 | fi # GCC |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 1246 | |
Nico Huber | 5f72f96 | 2016-01-31 23:05:19 +0100 | [diff] [blame] | 1247 | export HOSTCFLAGS="-Os" |
| 1248 | if have_hostcflags_from_gmp; then |
| 1249 | set_hostcflags_from_gmp |
| 1250 | fi |
| 1251 | |
Patrick Georgi | c1a75b1 | 2011-11-04 21:37:14 +0100 | [diff] [blame] | 1252 | if [ "$USECCACHE" = 1 ]; then |
| 1253 | CC="ccache $CC" |
| 1254 | fi |
| 1255 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 1256 | # Prepare target directory for building GCC |
| 1257 | # (dependencies must be in the PATH) |
Martin Roth | 987d42d | 2018-07-22 11:45:29 -0600 | [diff] [blame] | 1258 | mkdir -p "$DESTDIR$TARGETDIR/bin" |
| 1259 | mkdir -p "$DESTDIR$TARGETDIR/share" |
Stefan Reinauer | 16bd789 | 2012-12-07 23:57:01 +0100 | [diff] [blame] | 1260 | export PATH=$DESTDIR$TARGETDIR/bin:$PATH |
| 1261 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 1262 | # Download, unpack, patch and build all packages |
| 1263 | |
Elyes HAOUAS | b0f1988 | 2018-06-09 11:59:00 +0200 | [diff] [blame] | 1264 | printf "Downloading and verifing tarballs ...\n" |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 1265 | mkdir -p tarballs |
| 1266 | for P in $PACKAGES; do |
Jonathan Neuschäfer | 92d483a | 2017-09-26 22:33:53 +0200 | [diff] [blame] | 1267 | download "$P" || exit "$?" |
| 1268 | verify_hash "$P" || exit "$?" |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 1269 | done |
Martin Roth | 0362517 | 2016-02-17 14:44:14 -0700 | [diff] [blame] | 1270 | printf "Downloaded tarballs ... ${green}ok${NC}\n" |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 1271 | |
Elyes HAOUAS | b0f1988 | 2018-06-09 11:59:00 +0200 | [diff] [blame] | 1272 | printf "Unpacking and patching ...\n" |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 1273 | for P in $PACKAGES; do |
| 1274 | unpack_and_patch $P || exit 1 |
| 1275 | done |
| 1276 | printf "Unpacked and patched ... ${green}ok${NC}\n" |
| 1277 | |
Patrick Georgi | 9681cdc | 2017-09-22 18:57:10 +0200 | [diff] [blame] | 1278 | if [ -n "$BOOTSTRAPONLY" ]; then |
Elyes HAOUAS | b0f1988 | 2018-06-09 11:59:00 +0200 | [diff] [blame] | 1279 | printf "Building bootstrap compiler only ...\n" |
Nico Huber | afda56e | 2017-12-07 17:50:53 +0100 | [diff] [blame] | 1280 | for pkg in GMP MPFR MPC GCC; do |
Patrick Georgi | 9681cdc | 2017-09-22 18:57:10 +0200 | [diff] [blame] | 1281 | build_for_host $pkg |
| 1282 | done |
| 1283 | exit 0 |
| 1284 | fi |
| 1285 | |
Elyes HAOUAS | b0f1988 | 2018-06-09 11:59:00 +0200 | [diff] [blame] | 1286 | printf "Building packages ...\n" |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 1287 | for package in $PACKAGES; do |
| 1288 | build $package |
| 1289 | done |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 1290 | printf "Packages built ... ${green}ok${NC}\n" |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 1291 | |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 1292 | # Adding git information of current tree to target directory |
| 1293 | # for reproducibility |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 1294 | PROGNAME=$(basename "$0") |
Stefan Reinauer | 88352d7 | 2016-04-06 15:57:03 -0700 | [diff] [blame] | 1295 | rm -f "$DESTDIR$TARGETDIR/share/$PROGNAME-*" |
Patrick Georgi | 4eb84cf | 2017-07-07 11:18:46 +0200 | [diff] [blame] | 1296 | cp "$PROGNAME" "$DESTDIR$TARGETDIR/share/$PROGNAME-$CROSSGCC_VERSION-$CROSSGCC_COMMIT" |
Zheng Bao | 30b895f | 2013-02-06 18:04:40 +0800 | [diff] [blame] | 1297 | |
Patrick Georgi | 0c2df6f | 2017-11-22 16:14:09 -0500 | [diff] [blame] | 1298 | # Adding edk2 tools template |
| 1299 | mkdir -p "$DESTDIR$TARGETDIR/share/edk2config" |
| 1300 | sed -e "s,@@PREFIX@@,$TARGETDIR,g" edk2tools.txt > "$DESTDIR$TARGETDIR/share/edk2config/tools_def.txt" |
| 1301 | printf "Copied EDK2 tools template ... ${green}ok${NC}\n" |
| 1302 | |
Stefan Reinauer | 88e83e5 | 2016-04-06 15:39:48 -0700 | [diff] [blame] | 1303 | cleanup |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 1304 | |
Stefan Reinauer | 81693d4 | 2017-06-21 15:25:36 -0700 | [diff] [blame] | 1305 | printf "\n${green}You can now run $NAME from $TARGETDIR.${NC}\n" |