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