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