Peter Stuge | 09377b7 | 2011-08-21 06:24:55 +0200 | [diff] [blame] | 1 | #!/bin/sh |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 2 | # |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 3 | # Copyright (C) 2008-2010 by coresystems GmbH |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 4 | # written by Patrick Georgi <patrick.georgi@coresystems.de> and |
| 5 | # Stefan Reinauer <stefan.reinauer@coresystems.de> |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 6 | # |
Marc Jones | 2aac3f6 | 2011-08-08 16:07:50 -0600 | [diff] [blame] | 7 | # Copyright (C) 2011 by Sage Electronic Engineering |
| 8 | # |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 9 | # This program is free software; you can redistribute it and/or modify |
| 10 | # it under the terms of the GNU General Public License as published by |
| 11 | # the Free Software Foundation; version 2 of the License. |
| 12 | # |
| 13 | # This program is distributed in the hope that it will be useful, |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | # GNU General Public License for more details. |
| 17 | # |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 18 | |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 19 | cd $(dirname $0) |
Patrick Georgi | 8135dba | 2015-03-17 21:05:20 +0100 | [diff] [blame] | 20 | |
Iru Cai | 03353de | 2016-10-29 23:37:42 +0800 | [diff] [blame] | 21 | CROSSGCC_DATE="March 3rd, 2017" |
| 22 | CROSSGCC_VERSION="1.44" |
Stefan Reinauer | 88352d7 | 2016-04-06 15:57:03 -0700 | [diff] [blame] | 23 | CROSSGCC_COMMIT=$( git describe ) |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 24 | |
| 25 | # default settings |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 26 | PACKAGE=GCC |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 27 | TARGETDIR=$(pwd)/xgcc |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 28 | TARGETARCH=i386-elf |
Nico Huber | 66c2c1a | 2016-09-20 13:09:29 +0200 | [diff] [blame] | 29 | DEFAULT_LANGUAGES=c |
| 30 | LANGUAGES= |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 31 | DESTDIR= |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 32 | SAVETEMPS=0 |
| 33 | SKIPPYTHON=1 |
Nico Huber | 234d246 | 2016-01-26 16:10:17 +0100 | [diff] [blame] | 34 | BOOTSTRAP=0 |
Martin Roth | 2c6a806 | 2016-11-14 11:58:39 -0700 | [diff] [blame] | 35 | THREADS=1 |
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 |
Iru Cai | 03353de | 2016-10-29 23:37:42 +0800 | [diff] [blame] | 38 | GMP_VERSION=6.1.2 |
| 39 | MPFR_VERSION=3.1.5 |
Paul Menzel | e661942 | 2015-02-23 10:33:59 +0100 | [diff] [blame] | 40 | MPC_VERSION=1.0.3 |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 41 | LIBELF_VERSION=0.8.13 |
Iru Cai | 03353de | 2016-10-29 23:37:42 +0800 | [diff] [blame] | 42 | GCC_VERSION=6.3.0 |
Stefan Reinauer | 0d2119d | 2013-07-10 14:27:56 -0700 | [diff] [blame] | 43 | GCC_AUTOCONF_VERSION=2.69 |
Iru Cai | 03353de | 2016-10-29 23:37:42 +0800 | [diff] [blame] | 44 | BINUTILS_VERSION=2.28 |
| 45 | GDB_VERSION=7.12 |
| 46 | IASL_VERSION=20161222 |
Stefan Reinauer | 3dc5d07 | 2016-04-21 19:29:03 -0700 | [diff] [blame] | 47 | PYTHON_VERSION=3.5.1 |
Stefan Reinauer | 498f3d0 | 2016-04-21 18:10:15 -0700 | [diff] [blame] | 48 | EXPAT_VERSION=2.1.1 |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 49 | # CLANG version number |
Iru Cai | 03353de | 2016-10-29 23:37:42 +0800 | [diff] [blame] | 50 | CLANG_VERSION=3.9.1 |
Martin Roth | 589ef9d | 2016-08-11 18:35:06 -0600 | [diff] [blame] | 51 | MAKE_VERSION=4.2.1 |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 52 | |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 53 | # GCC toolchain archive locations |
Martin Roth | 1484c03 | 2016-03-08 09:37:14 -0700 | [diff] [blame] | 54 | # These are sanitized by the jenkins toolchain test builder, so if |
| 55 | # a completely new URL is added here, it probably needs to be added |
| 56 | # to the jenkins build as well, or the builder won't download it. |
Stefan Reinauer | d9d2102 | 2016-04-21 18:16:30 -0700 | [diff] [blame] | 57 | GMP_ARCHIVE="http://ftpmirror.gnu.org/gmp/gmp-${GMP_VERSION}.tar.xz" |
| 58 | MPFR_ARCHIVE="http://ftpmirror.gnu.org/mpfr/mpfr-${MPFR_VERSION}.tar.xz" |
Idwer Vollering | 7962fc7 | 2012-10-25 02:14:09 +0200 | [diff] [blame] | 59 | MPC_ARCHIVE="http://ftpmirror.gnu.org/mpc/mpc-${MPC_VERSION}.tar.gz" |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 60 | LIBELF_ARCHIVE="http://www.mr511.de/software/libelf-${LIBELF_VERSION}.tar.gz" |
Idwer Vollering | 1cfee0b | 2012-10-25 02:03:53 +0200 | [diff] [blame] | 61 | GCC_ARCHIVE="http://ftpmirror.gnu.org/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.bz2" |
Stefan Reinauer | 0d2119d | 2013-07-10 14:27:56 -0700 | [diff] [blame] | 62 | BINUTILS_ARCHIVE="http://ftpmirror.gnu.org/binutils/binutils-${BINUTILS_VERSION}.tar.bz2" |
Patrick Georgi | 53c388f | 2015-03-07 09:55:18 +0100 | [diff] [blame] | 63 | GDB_ARCHIVE="http://ftpmirror.gnu.org/gdb/gdb-${GDB_VERSION}.tar.xz" |
Patrick Georgi | 85bb946 | 2016-02-11 17:22:16 +0100 | [diff] [blame] | 64 | IASL_ARCHIVE="https://acpica.org/sites/acpica/files/acpica-unix2-${IASL_VERSION}.tar.gz" |
Patrick Georgi | 53c388f | 2015-03-07 09:55:18 +0100 | [diff] [blame] | 65 | PYTHON_ARCHIVE="http://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz" |
Stefan Reinauer | 498f3d0 | 2016-04-21 18:10:15 -0700 | [diff] [blame] | 66 | EXPAT_ARCHIVE="http://downloads.sourceforge.net/sourceforge/expat/expat-${EXPAT_VERSION}.tar.bz2" |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 67 | # CLANG toolchain archive locations |
| 68 | LLVM_ARCHIVE="http://llvm.org/releases/${CLANG_VERSION}/llvm-${CLANG_VERSION}.src.tar.xz" |
| 69 | CFE_ARCHIVE="http://llvm.org/releases/${CLANG_VERSION}/cfe-${CLANG_VERSION}.src.tar.xz" |
| 70 | CRT_ARCHIVE="http://llvm.org/releases/${CLANG_VERSION}/compiler-rt-${CLANG_VERSION}.src.tar.xz" |
| 71 | CTE_ARCHIVE="http://llvm.org/releases/${CLANG_VERSION}/clang-tools-extra-${CLANG_VERSION}.src.tar.xz" |
Stefan Reinauer | a851bbb | 2016-01-29 18:03:26 -0800 | [diff] [blame] | 72 | MAKE_ARCHIVE="http://ftpmirror.gnu.org/make/make-${MAKE_VERSION}.tar.bz2" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 73 | |
Martin Roth | 58c68d5 | 2016-03-01 15:22:42 -0700 | [diff] [blame] | 74 | ALL_ARCHIVES="$GMP_ARCHIVE $MPFR_ARCHIVE $MPC_ARCHIVE $LIBELF_ARCHIVE \ |
| 75 | $GCC_ARCHIVE $BINUTILS_ARCHIVE $GDB_ARCHIVE $IASL_ARCHIVE \ |
| 76 | $PYTHON_ARCHIVE $EXPAT_ARCHIVE $LLVM_ARCHIVE $CFE_ARCHIVE \ |
| 77 | $CRT_ARCHIVE $CTE_ARCHIVE $MAKE_ARCHIVE" |
| 78 | |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 79 | # GCC toolchain directories |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 80 | GMP_DIR="gmp-${GMP_VERSION}" |
| 81 | MPFR_DIR="mpfr-${MPFR_VERSION}" |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 82 | MPC_DIR="mpc-${MPC_VERSION}" |
| 83 | LIBELF_DIR="libelf-${LIBELF_VERSION}" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 84 | GCC_DIR="gcc-${GCC_VERSION}" |
| 85 | BINUTILS_DIR="binutils-${BINUTILS_VERSION}" |
| 86 | GDB_DIR="gdb-${GDB_VERSION}" |
Patrick Georgi | 85bb946 | 2016-02-11 17:22:16 +0100 | [diff] [blame] | 87 | IASL_DIR="acpica-unix2-${IASL_VERSION}" |
Stefan Reinauer | 2c3cd12 | 2011-11-01 21:43:50 +0100 | [diff] [blame] | 88 | PYTHON_DIR="Python-${PYTHON_VERSION}" |
| 89 | EXPAT_DIR="expat-${EXPAT_VERSION}" |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 90 | # CLANG toolchain directories |
| 91 | LLVM_DIR="llvm-${CLANG_VERSION}.src" |
| 92 | CFE_DIR="cfe-${CLANG_VERSION}.src" |
| 93 | CRT_DIR="compiler-rt-${CLANG_VERSION}.src" |
| 94 | CTE_DIR="clang-tools-extra-${CLANG_VERSION}.src" |
Stefan Reinauer | a851bbb | 2016-01-29 18:03:26 -0800 | [diff] [blame] | 95 | MAKE_DIR="make-${MAKE_VERSION}" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 96 | |
Patrick Georgi | 6321f52 | 2015-02-27 23:36:26 +0100 | [diff] [blame] | 97 | unset MAKELEVEL MAKEFLAGS |
| 98 | |
Patrick Georgi | 1861ff7 | 2011-10-31 12:15:55 +0100 | [diff] [blame] | 99 | red='\033[0;31m' |
| 100 | RED='\033[1;31m' |
| 101 | green='\033[0;32m' |
| 102 | GREEN='\033[1;32m' |
| 103 | blue='\033[0;34m' |
| 104 | BLUE='\033[1;34m' |
| 105 | cyan='\033[0;36m' |
| 106 | CYAN='\033[1;36m' |
| 107 | NC='\033[0m' # No Color |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 108 | |
zbao | e05c1ea | 2015-08-05 23:10:05 -0400 | [diff] [blame] | 109 | UNAME=$(uname | grep -iq cygwin && echo Cygwin || uname) |
Martin Roth | 8846382 | 2016-01-07 11:03:36 -0700 | [diff] [blame] | 110 | HALT_FOR_TOOLS=0 |
Stefan Reinauer | 0d2119d | 2013-07-10 14:27:56 -0700 | [diff] [blame] | 111 | |
Patrick Georgi | 198d23c | 2012-12-08 08:02:44 +0100 | [diff] [blame] | 112 | normalize_dirs() |
| 113 | { |
| 114 | mkdir -p $DESTDIR$TARGETDIR/lib |
| 115 | test -d $DESTDIR$TARGETDIR/lib32 && mv $DESTDIR$TARGETDIR/lib32/* $DESTDIR$TARGETDIR/lib |
| 116 | test -d $DESTDIR$TARGETDIR/lib64 && mv $DESTDIR$TARGETDIR/lib64/* $DESTDIR$TARGETDIR/lib |
| 117 | rmdir -p $DESTDIR$TARGETDIR/lib32 $DESTDIR$TARGETDIR/lib64 |
| 118 | |
| 119 | perl -pi -e "s,/lib32,/lib," $DESTDIR$TARGETDIR/lib/*.la |
| 120 | perl -pi -e "s,/lib64,/lib," $DESTDIR$TARGETDIR/lib/*.la |
| 121 | } |
| 122 | |
Stefan Reinauer | 93a9630 | 2015-06-15 12:36:53 -0700 | [diff] [blame] | 123 | please_install() |
| 124 | { |
Martin Roth | 8846382 | 2016-01-07 11:03:36 -0700 | [diff] [blame] | 125 | HALT_FOR_TOOLS=1 |
Patrick Georgi | 5da95dc | 2015-07-17 23:33:05 +0200 | [diff] [blame] | 126 | test -r /etc/os-release && . /etc/os-release |
Stefan Reinauer | 93a9630 | 2015-06-15 12:36:53 -0700 | [diff] [blame] | 127 | case "$ID_LIKE" in |
| 128 | debian) solution="sudo apt-get install $1" ;; |
| 129 | suse) solution="sudo zypper install $1" ;; |
| 130 | *) solution="using your OS packaging system" ;; |
| 131 | esac |
| 132 | |
Patrick Georgi | df1ff23 | 2017-01-07 09:28:43 +0100 | [diff] [blame] | 133 | 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] | 134 | if [ -n "$2" ]; then |
Patrick Georgi | df1ff23 | 2017-01-07 09:28:43 +0100 | [diff] [blame] | 135 | printf "${RED}ERROR:${red} or install '$2'.${NC}\n" >&2 |
Martin Roth | e396317 | 2016-01-06 13:54:32 -0700 | [diff] [blame] | 136 | fi |
Stefan Reinauer | 93a9630 | 2015-06-15 12:36:53 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Patrick Georgi | b706288 | 2015-02-24 10:52:14 +0100 | [diff] [blame] | 139 | searchtool() |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 140 | { |
| 141 | # $1 short name |
Patrick Georgi | b706288 | 2015-02-24 10:52:14 +0100 | [diff] [blame] | 142 | # $2 search string |
| 143 | # $3 soft fail if set |
Martin Roth | e396317 | 2016-01-06 13:54:32 -0700 | [diff] [blame] | 144 | # $4 alternative package to install on failure |
Patrick Georgi | b706288 | 2015-02-24 10:52:14 +0100 | [diff] [blame] | 145 | # result: file name of that tool on stdout |
| 146 | # or no output if nothing suitable was found |
| 147 | search=GNU |
| 148 | if [ -n "$2" ]; then |
| 149 | search="$2" |
| 150 | fi |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 151 | for i in "$1" "g$1" "gnu$1"; do |
Stefan Reinauer | dbc0087 | 2015-06-09 11:50:05 -0700 | [diff] [blame] | 152 | if [ -x "$(which $i 2>/dev/null)" ]; then |
| 153 | if [ "$(cat /dev/null | $i --version 2>&1 | grep -c "$search")" \ |
| 154 | -gt 0 ]; then |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 155 | echo $i |
| 156 | return |
| 157 | fi |
| 158 | fi |
| 159 | done |
Andrew Wu | b67e9a1 | 2014-04-28 18:13:44 +0800 | [diff] [blame] | 160 | # A workaround for OSX 10.9 and some BSDs, whose nongnu |
| 161 | # patch and tar also work. |
Patrick Georgi | 7cb26b4 | 2015-04-28 21:29:22 +0200 | [diff] [blame] | 162 | if [ $UNAME = "Darwin" -o $UNAME = "FreeBSD" -o $UNAME = "NetBSD" -o $UNAME = "OpenBSD" ]; then |
Patrick Georgi | b706288 | 2015-02-24 10:52:14 +0100 | [diff] [blame] | 163 | if [ "$1" = "patch" -o "$1" = "tar" ]; then |
Stefan Reinauer | dbc0087 | 2015-06-09 11:50:05 -0700 | [diff] [blame] | 164 | if [ -x "$(which $1 2>/dev/null)" ]; then |
Zheng Bao | 36156ff | 2012-09-28 16:18:58 +0800 | [diff] [blame] | 165 | echo $1 |
| 166 | return |
| 167 | fi |
| 168 | fi |
| 169 | fi |
zbao | 5cf758d | 2015-09-01 22:28:57 -0400 | [diff] [blame] | 170 | if echo $1 | grep -q "sum" ; then |
| 171 | algor=$(echo $1 | sed -e 's,sum,,') |
| 172 | if [ -x "$(which $1 2>/dev/null)" ]; then |
| 173 | #xxxsum [file] |
| 174 | echo $1 |
| 175 | return |
| 176 | elif [ -x "$(which $algor 2>/dev/null)" ]; then |
| 177 | #xxx [file] |
| 178 | echo $algor |
| 179 | return |
| 180 | elif [ -x "$(which openssl 2>/dev/null)" ]; then |
| 181 | #openssl xxx [file] |
| 182 | echo openssl $algor |
| 183 | return |
| 184 | elif [ -x "$(which cksum 2>/dev/null)" ]; then |
| 185 | #cksum -a xxx [file] |
| 186 | #cksum has special options in NetBSD. Actually, NetBSD will use the second case above. |
| 187 | echo "buildgcc" | cksum -a $algor > /dev/null 2>/dev/null && \ |
| 188 | echo cksum -a $algor |
| 189 | return |
zbao | 939dc84 | 2015-04-30 04:44:07 +0800 | [diff] [blame] | 190 | fi |
| 191 | fi |
Martin Roth | e396317 | 2016-01-06 13:54:32 -0700 | [diff] [blame] | 192 | |
Martin Roth | 8846382 | 2016-01-07 11:03:36 -0700 | [diff] [blame] | 193 | [ -z "$3" ] && please_install $1 $4 |
Patrick Georgi | b706288 | 2015-02-24 10:52:14 +0100 | [diff] [blame] | 194 | false |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Martin Roth | 591790f | 2016-03-20 20:39:04 -0600 | [diff] [blame] | 197 | # Run a compile check of the specified library option to see if it's installed |
| 198 | check_for_library() { |
| 199 | local LIBRARY_FLAGS=$1 |
Aaron Durbin | 0ac4e5a | 2016-04-07 16:56:25 -0500 | [diff] [blame] | 200 | local LIBRARY_PACKAGES="$2" |
Martin Roth | 591790f | 2016-03-20 20:39:04 -0600 | [diff] [blame] | 201 | local LIBTEST_FILE=.libtest |
| 202 | |
| 203 | echo "int main(int argc, char **argv) { (void) argc; (void) argv; return 0; }" > "${LIBTEST_FILE}.c" |
| 204 | |
| 205 | cc $CFLAGS $LIBRARY_FLAGS "${LIBTEST_FILE}.c" -o "${LIBTEST_FILE}" >/dev/null 2>&1 || \ |
| 206 | please_install "$LIBRARY_PACKAGES" |
| 207 | rm -rf "${LIBTEST_FILE}.c" "${LIBTEST_FILE}" |
| 208 | } |
| 209 | |
Nico Huber | aee7f46 | 2016-09-20 12:55:19 +0200 | [diff] [blame] | 210 | buildcc_major() { |
| 211 | echo "${GCC_VERSION}" | cut -d. -f1 |
| 212 | } |
| 213 | |
Nico Huber | 26267a7 | 2016-12-04 02:45:58 +0100 | [diff] [blame] | 214 | buildcc_minor() { |
| 215 | echo "${GCC_VERSION}" | cut -d. -f2 |
| 216 | } |
| 217 | |
Nico Huber | aee7f46 | 2016-09-20 12:55:19 +0200 | [diff] [blame] | 218 | buildcc_version() { |
| 219 | echo "${GCC_VERSION}" | cut -d. -f1-2 |
| 220 | } |
| 221 | |
| 222 | hostcc_major() { |
| 223 | (echo __GNUC__ | ${CC} -E - 2>/dev/null || echo 0) | tail -1 |
| 224 | } |
| 225 | |
| 226 | hostcc_minor() { |
| 227 | (echo __GNUC_MINOR__ | ${CC} -E - 2>/dev/null || echo 0) | tail -1 |
| 228 | } |
| 229 | |
| 230 | hostcc_version() { |
| 231 | printf "%d.%d" "$(hostcc_major)" "$(hostcc_minor)" |
| 232 | } |
| 233 | |
Nico Huber | 7579716 | 2016-09-20 13:01:57 +0200 | [diff] [blame] | 234 | hostcc_has_gnat1() { |
| 235 | [ -x "$(${CC} -print-prog-name=gnat1)" ] |
| 236 | } |
| 237 | |
| 238 | ada_requested() { |
| 239 | echo "${LANGUAGES}" | grep -q '\<ada\>' |
| 240 | } |
| 241 | |
| 242 | check_gnat() { |
| 243 | if hostcc_has_gnat1; then |
Nico Huber | 26267a7 | 2016-12-04 02:45:58 +0100 | [diff] [blame] | 244 | if [ \( "$(hostcc_major)" -lt "$(buildcc_major)" -o \ |
| 245 | \( "$(hostcc_major)" -eq "$(buildcc_major)" -a \ |
| 246 | "$(hostcc_minor)" -lt "$(buildcc_minor)" \) \) \ |
| 247 | -a \ |
| 248 | "${BOOTSTRAP}" != "1" ]; \ |
| 249 | then |
Nico Huber | 7579716 | 2016-09-20 13:01:57 +0200 | [diff] [blame] | 250 | printf "\n${RED}ERROR:${red} Building the Ada compiler (gnat $(buildcc_version)) " |
Nico Huber | 26267a7 | 2016-12-04 02:45:58 +0100 | [diff] [blame] | 251 | printf "with an older host compiler\n version ($(hostcc_version)) " |
Nico Huber | 7579716 | 2016-09-20 13:01:57 +0200 | [diff] [blame] | 252 | printf "requires bootstrapping (-b).${NC}\n\n" |
| 253 | HALT_FOR_TOOLS=1 |
| 254 | fi |
Nico Huber | 04a1f6a | 2016-09-20 13:07:49 +0200 | [diff] [blame] | 255 | else |
| 256 | please_install gnat |
Nico Huber | 7579716 | 2016-09-20 13:01:57 +0200 | [diff] [blame] | 257 | fi |
| 258 | } |
| 259 | |
Nico Huber | 156d87c | 2016-09-20 12:59:53 +0200 | [diff] [blame] | 260 | check_cc() { |
| 261 | if is_package_enabled "GCC"; then |
| 262 | if [ "$(hostcc_major)" != "$(buildcc_major)" -a "${BOOTSTRAP}" != "1" ]; then |
| 263 | printf "\n${red}warning: Building GCC $(buildcc_version) with a different major " |
| 264 | printf "version ($(hostcc_version)).\n" |
| 265 | printf " Bootstrapping (-b) is recommended.${NC}\n\n" |
| 266 | fi |
Nico Huber | 7579716 | 2016-09-20 13:01:57 +0200 | [diff] [blame] | 267 | if ada_requested; then |
| 268 | check_gnat |
| 269 | fi |
Nico Huber | 156d87c | 2016-09-20 12:59:53 +0200 | [diff] [blame] | 270 | fi |
| 271 | } |
| 272 | |
zbao | 06e85ac | 2015-08-24 22:08:36 -0400 | [diff] [blame] | 273 | check_sum() { |
| 274 | test -z "$CHECKSUM" || \ |
| 275 | test "$(cat sum/$1.cksum 2>/dev/null | sed -e 's@.*\([0-9a-f]\{40,\}\).*@\1@')" = \ |
| 276 | "$($CHECKSUM tarballs/$1 2>/dev/null | sed -e 's@.*\([0-9a-f]\{40,\}\).*@\1@')" |
| 277 | } |
| 278 | |
| 279 | compute_sum() { |
| 280 | test ! -f sum/$1.cksum && test -f tarballs/$1 && \ |
| 281 | (test -z "$CHECKSUM" || $CHECKSUM tarballs/$1 > sum/$1.cksum ) && \ |
| 282 | printf "(checksum created. ${RED}Note. Please upload sum/$1.cksum if the corresponding archive is upgraded.)${NC}" |
| 283 | } |
| 284 | |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 285 | download() { |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 286 | package=$1 |
| 287 | archive="$(eval echo \$$package"_ARCHIVE")" |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 288 | |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 289 | FILE=$(basename $archive) |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 290 | printf " * $FILE " |
| 291 | |
zbao | d22b9ea | 2015-08-30 23:35:16 -0400 | [diff] [blame] | 292 | if test -f tarballs/$FILE && check_sum $FILE ; then |
Patrick Georgi | df1ff23 | 2017-01-07 09:28:43 +0100 | [diff] [blame] | 293 | echo "(cached)" |
zbao | d22b9ea | 2015-08-30 23:35:16 -0400 | [diff] [blame] | 294 | else |
Paul Menzel | b2ba395 | 2015-06-12 11:58:14 +0200 | [diff] [blame] | 295 | printf "(downloading from $archive)" |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 296 | rm -f tarballs/$FILE |
| 297 | cd tarballs |
zbao | 282dd95 | 2015-09-06 05:00:04 -0400 | [diff] [blame] | 298 | download_showing_percentage $archive |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 299 | cd .. |
zbao | 06e85ac | 2015-08-24 22:08:36 -0400 | [diff] [blame] | 300 | compute_sum $FILE |
zbao | d22b9ea | 2015-08-30 23:35:16 -0400 | [diff] [blame] | 301 | fi |
| 302 | |
Stefan Reinauer | dbc0087 | 2015-06-09 11:50:05 -0700 | [diff] [blame] | 303 | if [ ! -f tarballs/$FILE ]; then |
Patrick Georgi | df1ff23 | 2017-01-07 09:28:43 +0100 | [diff] [blame] | 304 | printf "${RED}Failed to download $FILE.${NC}\n" |
Stefan Reinauer | dbc0087 | 2015-06-09 11:50:05 -0700 | [diff] [blame] | 305 | exit 1 |
| 306 | fi |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | unpack_and_patch() { |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 310 | package=$1 |
| 311 | archive="$(eval echo \$$package"_ARCHIVE")" |
| 312 | dir="$(eval echo \$$package"_DIR")" |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 313 | test -d ${dir} && test -f ${dir}/.unpack_success || ( |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 314 | printf " * $(basename $archive)\n" |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 315 | FLAGS=zxf |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 316 | suffix=$(echo $archive | sed 's,.*\.,,') |
Martin Roth | 95f7b22 | 2016-03-20 12:38:48 -0600 | [diff] [blame] | 317 | if [ "$suffix" = "gz" ] && [ -n "$PIGZ" ]; then FLAGS="-I pigz -xf" |
| 318 | elif [ "$suffix" = "gz" ]; then FLAGS=zxf |
| 319 | elif [ "$suffix" = "bz2" ] && [ -n "$LBZIP2" ]; then FLAGS="-I lbzip2 -xf" |
| 320 | elif [ "$suffix" = "bz2" ]; then FLAGS=jxf |
| 321 | elif [ "$suffix" = "xz" ]; then FLAGS="--xz -xf" |
| 322 | elif [ "$suffix" = "lzma" ]; then FLAGS="--lzma -xf" |
| 323 | fi |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 324 | $TAR $FLAGS tarballs/$(basename $archive) |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 325 | for patch in patches/${dir}_*.patch; do |
| 326 | test -r $patch || continue |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 327 | printf " o $(basename $patch)\n" |
Nico Huber | 4b48ed8 | 2016-07-27 00:28:03 +0200 | [diff] [blame] | 328 | (cd ${dir} && $PATCH -s -N -p1 <../${patch}) || { |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 329 | printf "\n${RED}Failed $patch.${NC}\n" |
Stefan Reinauer | 916b845 | 2015-06-09 11:54:49 -0700 | [diff] [blame] | 330 | exit 1 |
| 331 | } |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 332 | done |
| 333 | touch ${dir}/.unpack_success |
| 334 | ) |
| 335 | } |
| 336 | |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 337 | fn_exists() |
| 338 | { |
Patrick Georgi | c866591 | 2015-06-11 21:04:31 +0200 | [diff] [blame] | 339 | type $1 >/dev/null 2>&1 |
Patrick Georgi | 74c0642 | 2015-03-25 18:40:13 +0100 | [diff] [blame] | 340 | } |
| 341 | |
Patrick Georgi | f2c15f5 | 2015-06-11 21:07:31 +0200 | [diff] [blame] | 342 | is_package_enabled() |
| 343 | { |
| 344 | echo "$PACKAGES" |grep -q "\<$1\>" |
| 345 | } |
| 346 | |
Martin Roth | 444ece2 | 2016-04-01 18:46:29 -0600 | [diff] [blame] | 347 | package_uses_targetarch() |
| 348 | { |
Stefan Reinauer | a344b68 | 2016-04-21 19:29:51 -0700 | [diff] [blame] | 349 | if [ "$1" = "GCC" ] || [ "$1" = "GDB" ] || [ "$1" = "BINUTILS" ]; then |
Martin Roth | 444ece2 | 2016-04-01 18:46:29 -0600 | [diff] [blame] | 350 | true |
| 351 | else |
| 352 | false |
| 353 | fi |
| 354 | } |
| 355 | |
Nico Huber | 11ea2b3 | 2016-01-26 16:09:31 +0100 | [diff] [blame] | 356 | generic_build() |
| 357 | { |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 358 | package=$1 |
Nico Huber | 11ea2b3 | 2016-01-26 16:09:31 +0100 | [diff] [blame] | 359 | host_target=$2 |
| 360 | builddir=$3 |
| 361 | success=$4 |
Martin Roth | c295d5e | 2016-11-14 11:56:11 -0700 | [diff] [blame] | 362 | version=$5 |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 363 | |
| 364 | fn_exists build_$package || return |
| 365 | |
Nico Huber | 11ea2b3 | 2016-01-26 16:09:31 +0100 | [diff] [blame] | 366 | mkdir -p "$builddir" |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 367 | |
Nico Huber | 11ea2b3 | 2016-01-26 16:09:31 +0100 | [diff] [blame] | 368 | if [ -f "$success" ]; then |
Martin Roth | 2c6a806 | 2016-11-14 11:58:39 -0700 | [diff] [blame] | 369 | 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] | 370 | else |
Martin Roth | 2c6a806 | 2016-11-14 11:58:39 -0700 | [diff] [blame] | 371 | printf "Building $package v$version for $host_target ... " |
Nico Huber | 11ea2b3 | 2016-01-26 16:09:31 +0100 | [diff] [blame] | 372 | DIR="$PWD" |
| 373 | cd "$builddir" |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 374 | rm -f .failed |
Nico Huber | 11ea2b3 | 2016-01-26 16:09:31 +0100 | [diff] [blame] | 375 | build_${package} $host_target > build.log 2>&1 |
| 376 | cd "$DIR" |
| 377 | if [ ! -f "$builddir/.failed" ]; then |
| 378 | touch "$success"; |
| 379 | else |
| 380 | printf "${RED}failed${NC}. Check $builddir/build.log.\n" |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 381 | exit 1 |
| 382 | fi |
| 383 | printf "${green}ok${NC}\n" |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 384 | fi |
| 385 | } |
| 386 | |
Nico Huber | 11ea2b3 | 2016-01-26 16:09:31 +0100 | [diff] [blame] | 387 | build_for_host() |
| 388 | { |
Martin Roth | c295d5e | 2016-11-14 11:56:11 -0700 | [diff] [blame] | 389 | package="$1" |
| 390 | version="$(eval echo \$$package"_VERSION")" |
Patrick Georgi | 1b593e5 | 2016-11-25 15:27:41 +0100 | [diff] [blame] | 391 | generic_build "$package" host "build-$package" "${DESTDIR}${TARGETDIR}/.${package}.${version}.success" "$version" |
Nico Huber | 11ea2b3 | 2016-01-26 16:09:31 +0100 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | build_for_target() |
| 395 | { |
Martin Roth | c295d5e | 2016-11-14 11:56:11 -0700 | [diff] [blame] | 396 | package="$1" |
| 397 | version="$(eval echo \$$package"_VERSION")" |
Patrick Georgi | 1b593e5 | 2016-11-25 15:27:41 +0100 | [diff] [blame] | 398 | 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] | 399 | } |
| 400 | |
| 401 | build() |
| 402 | { |
| 403 | if package_uses_targetarch $1; then |
Patrick Georgi | 1b593e5 | 2016-11-25 15:27:41 +0100 | [diff] [blame] | 404 | if [ $BOOTSTRAP -eq 1 -a ! -f "${DESTDIR}${TARGETDIR}/.GCC.success" ]; then |
Nico Huber | 234d246 | 2016-01-26 16:10:17 +0100 | [diff] [blame] | 405 | build_for_host GCC |
| 406 | fi |
Nico Huber | 11ea2b3 | 2016-01-26 16:09:31 +0100 | [diff] [blame] | 407 | build_for_target $1 |
| 408 | else |
| 409 | build_for_host $1 |
| 410 | fi |
| 411 | } |
| 412 | |
Zheng Bao | bb003c8 | 2016-08-05 13:41:51 +0800 | [diff] [blame] | 413 | quit() |
| 414 | { |
| 415 | printf "${NC}Stop\n" |
| 416 | exit 1 |
| 417 | } |
| 418 | |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 419 | cleanup() |
| 420 | { |
Stefan Reinauer | 88e83e5 | 2016-04-06 15:39:48 -0700 | [diff] [blame] | 421 | if [ $SAVETEMPS -ne 0 ]; then |
| 422 | printf "Leaving temporary files around... ${green}ok${NC}\n" |
| 423 | return |
| 424 | fi |
| 425 | |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 426 | printf "Cleaning up temporary files... " |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 427 | for package in $PACKAGES; do |
Martin Roth | 444ece2 | 2016-04-01 18:46:29 -0600 | [diff] [blame] | 428 | rm -rf build-${TARGETARCH}-$package build-$package $(eval echo \$$package"_DIR") |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 429 | done |
zbao | ff3f15c | 2015-08-26 22:00:31 -0400 | [diff] [blame] | 430 | rm -f getopt |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 431 | printf "${green}ok${NC}\n" |
| 432 | } |
| 433 | |
| 434 | myhelp() |
| 435 | { |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 436 | 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] | 437 | printf " $0 [-V|--version]\n" |
| 438 | printf " $0 [-h|--help]\n\n" |
| 439 | |
| 440 | printf "Options:\n" |
| 441 | printf " [-V|--version] print version number and exit\n" |
| 442 | printf " [-h|--help] print this help and exit\n" |
| 443 | printf " [-c|--clean] remove temporary files before build\n" |
| 444 | printf " [-t|--savetemps] don't remove temporary files after build\n" |
Patrick Georgi | c1a75b1 | 2011-11-04 21:37:14 +0100 | [diff] [blame] | 445 | printf " [-y|--ccache] Use ccache when building cross compiler\n" |
Nico Huber | 152e78e | 2016-09-20 15:38:40 +0200 | [diff] [blame] | 446 | printf " [-n|--nocolor] don't print color codes in output\n" |
| 447 | printf " [-u|--urls] print the urls for all packages\n" |
Patrick Georgi | 73166c7 | 2010-04-14 20:42:42 +0000 | [diff] [blame] | 448 | printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n" |
Martin Roth | 588c79d | 2016-03-20 12:03:20 -0600 | [diff] [blame] | 449 | printf " [-s]--supported <tool> print supported version of a tool\n" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 450 | 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] | 451 | printf " (defaults to $TARGETDIR)\n\n" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 452 | 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] | 453 | printf " (for RPM builds, default unset)\n" |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 454 | printf " [-P|--package <package>] Build a specific package: GCC, CLANG, IASL, GDB\n" |
| 455 | printf " (defaults to $PACKAGE)\n" |
| 456 | printf "GCC specific options:\n" |
Nico Huber | 234d246 | 2016-01-26 16:10:17 +0100 | [diff] [blame] | 457 | printf " [-b|--bootstrap] bootstrap the host compiler before building\n" |
| 458 | printf " the cross compiler\n" |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 459 | printf " [-p|--platform <platform>] target platform to build cross compiler for\n" |
| 460 | printf " (defaults to $TARGETARCH)\n" |
Nico Huber | bb313bf | 2015-09-08 12:30:27 +0200 | [diff] [blame] | 461 | printf " [-l|--languages <languages>] comma separated list of target languages\n" |
Nico Huber | 66c2c1a | 2016-09-20 13:09:29 +0200 | [diff] [blame] | 462 | printf " (defaults to $DEFAULT_LANGUAGES)\n" |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 463 | printf "GDB specific options:\n" |
| 464 | printf " [-p|--platform <platform>] target platform to build cross compiler for\n" |
| 465 | printf " (defaults to $TARGETARCH)\n" |
| 466 | printf " [-S|--scripting] build scripting support for GDB\n\n" |
Martin Roth | d1da74f | 2015-06-21 12:06:28 -0600 | [diff] [blame] | 467 | printf "Platforms for GCC & GDB:\n" |
Martin Roth | 3e0f74d | 2016-03-08 12:07:04 -0700 | [diff] [blame] | 468 | printf " x86_64 i386-elf i386-mingw32 mipsel-elf riscv-elf arm aarch64\n" |
Jonathan Neuschäfer | f14f640 | 2016-03-11 20:22:23 +0100 | [diff] [blame] | 469 | printf " powerpc64le-linux-gnu nds32le-elf\n\n" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 470 | } |
| 471 | |
Martin Roth | edf965a | 2015-11-25 16:58:33 -0700 | [diff] [blame] | 472 | printversion() { |
| 473 | printf "${blue}Welcome to the ${red}coreboot${blue} cross toolchain builder v$CROSSGCC_VERSION ($CROSSGCC_DATE)${NC}\n\n" |
| 474 | } |
| 475 | |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 476 | myversion() |
| 477 | { |
Martin Roth | edf965a | 2015-11-25 16:58:33 -0700 | [diff] [blame] | 478 | printversion |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 479 | |
| 480 | cat << EOF |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 481 | Copyright (C) 2008-2010 by coresystems GmbH |
Marc Jones | 2aac3f6 | 2011-08-08 16:07:50 -0600 | [diff] [blame] | 482 | Copyright (C) 2011 by Sage Electronic Engineering |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 483 | |
| 484 | This program is free software; you can redistribute it and/or modify |
| 485 | it under the terms of the GNU General Public License as published by |
| 486 | the Free Software Foundation; version 2 of the License. |
| 487 | |
| 488 | This program is distributed in the hope that it will be useful, |
| 489 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 490 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 491 | GNU General Public License for more details. |
| 492 | |
| 493 | EOF |
| 494 | } |
| 495 | |
Nico Huber | 5f72f96 | 2016-01-31 23:05:19 +0100 | [diff] [blame] | 496 | have_hostcflags_from_gmp() { |
| 497 | grep -q __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h >/dev/null 2>&1 |
| 498 | } |
| 499 | |
| 500 | set_hostcflags_from_gmp() { |
| 501 | # Now set CFLAGS to match GMP CFLAGS but strip out -pedantic |
| 502 | # as GCC 4.6.x fails if it's there. |
Idwer Vollering | ba349ab | 2016-07-24 02:10:19 +0200 | [diff] [blame] | 503 | export HOSTCFLAGS="$(grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2 |\ |
| 504 | sed s,-pedantic,,)" |
Nico Huber | 5f72f96 | 2016-01-31 23:05:19 +0100 | [diff] [blame] | 505 | } |
| 506 | |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 507 | build_GMP() { |
Nico Huber | 8bbd596 | 2016-12-22 16:05:54 +0100 | [diff] [blame] | 508 | # Check if GCC enables `-pie` by default (possible since GCC 6). |
| 509 | # We need PIC in all static libraries then. |
Nico Huber | 2c1c02e | 2017-01-02 20:51:28 +0100 | [diff] [blame] | 510 | if $CC -dumpspecs 2>/dev/null | grep -q '[{;][[:space:]]*:-pie\>' |
Nico Huber | 8bbd596 | 2016-12-22 16:05:54 +0100 | [diff] [blame] | 511 | then |
| 512 | OPTIONS="$OPTIONS --with-pic" |
| 513 | fi |
| 514 | |
Paul Kocialkowski | 7899db2 | 2016-06-17 21:41:00 -0700 | [diff] [blame] | 515 | CC="$CC" ../${GMP_DIR}/configure --disable-shared --enable-fat \ |
Nico Huber | 5f72f96 | 2016-01-31 23:05:19 +0100 | [diff] [blame] | 516 | --prefix=$TARGETDIR $OPTIONS \ |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 517 | || touch .failed |
| 518 | $MAKE $JOBS || touch .failed |
| 519 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 520 | |
| 521 | normalize_dirs |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 522 | |
Nico Huber | 5f72f96 | 2016-01-31 23:05:19 +0100 | [diff] [blame] | 523 | set_hostcflags_from_gmp |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | build_MPFR() { |
| 527 | test $UNAME = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL" |
| 528 | CC="$CC" ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \ |
| 529 | --infodir=$TARGETDIR/info \ |
| 530 | --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \ |
| 531 | touch .failed |
| 532 | $MAKE $JOBS || touch .failed |
| 533 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 534 | |
| 535 | normalize_dirs |
| 536 | |
| 537 | # work around build problem of libgmp.la |
| 538 | if [ "$DESTDIR" != "" ]; then |
| 539 | perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la |
| 540 | fi |
| 541 | } |
| 542 | |
| 543 | build_MPC() { |
| 544 | CC="$CC" ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \ |
| 545 | --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \ |
| 546 | --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \ |
| 547 | touch .failed |
| 548 | $MAKE $JOBS || touch .failed |
| 549 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 550 | |
| 551 | normalize_dirs |
| 552 | } |
| 553 | |
| 554 | build_LIBELF() { |
| 555 | CC="$CC" CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no \ |
| 556 | ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \ |
| 557 | --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed |
| 558 | $MAKE $JOBS || touch .failed |
| 559 | $MAKE install prefix=$DESTDIR$TARGETDIR || touch .failed |
| 560 | |
| 561 | normalize_dirs |
| 562 | } |
| 563 | |
| 564 | build_BINUTILS() { |
Nico Huber | ae6187f | 2016-12-22 22:16:39 +0100 | [diff] [blame] | 565 | if [ $TARGETARCH = "x86_64-elf" ]; then |
Stefan Reinauer | 682a90c | 2015-06-09 14:59:58 -0700 | [diff] [blame] | 566 | ADDITIONALTARGET=",i386-elf" |
| 567 | fi |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 568 | CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \ |
Stefan Reinauer | 682a90c | 2015-06-09 14:59:58 -0700 | [diff] [blame] | 569 | --target=${TARGETARCH} --enable-targets=${TARGETARCH}${ADDITIONALTARGET} \ |
| 570 | --disable-werror --disable-nls --enable-lto --enable-gold \ |
Stefan Reinauer | 2fe2d3d | 2016-04-05 02:14:48 -0700 | [diff] [blame] | 571 | --enable-interwork --enable-multilib \ |
Nico Huber | 010ecf80 | 2016-12-22 16:19:37 +0100 | [diff] [blame] | 572 | --enable-plugins --enable-multilibs |
| 573 | CFLAGS="$HOSTCFLAGS" \ |
| 574 | CXXFLAGS="$HOSTCFLAGS" \ |
| 575 | || touch .failed |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 576 | $MAKE $JOBS || touch .failed |
| 577 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 578 | } |
| 579 | |
Nico Huber | 234d246 | 2016-01-26 16:10:17 +0100 | [diff] [blame] | 580 | bootstrap_GCC() { |
| 581 | CC="$CC" \ |
| 582 | CFLAGS="$HOSTCFLAGS" \ |
| 583 | CFLAGS_FOR_BUILD="$HOSTCFLAGS" \ |
| 584 | CFLAGS_FOR_TARGET="$HOSTCFLAGS -fPIC" \ |
| 585 | CXXFLAGS="$HOSTCFLAGS" \ |
| 586 | CXXFLAGS_FOR_BUILD="$HOSTCFLAGS" \ |
| 587 | CXXFLAGS_FOR_TARGET="$HOSTCFLAGS -fPIC" \ |
| 588 | ../gcc-${GCC_VERSION}/configure \ |
| 589 | --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \ |
| 590 | --enable-bootstrap \ |
| 591 | --disable-werror --disable-nls \ |
| 592 | --disable-shared --disable-multilib \ |
| 593 | --disable-libssp --disable-libquadmath --disable-libcc1 \ |
| 594 | ${GCC_OPTIONS} --enable-languages="${LANGUAGES}" \ |
| 595 | --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \ |
| 596 | --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \ |
| 597 | --with-pkgversion="coreboot bootstrap v$CROSSGCC_VERSION $CROSSGCC_DATE" \ |
| 598 | && \ |
| 599 | $MAKE $JOBS BOOT_CFLAGS="$HOSTCFLAGS" BUILD_CONFIG="" bootstrap && \ |
| 600 | $MAKE install-gcc \ |
| 601 | install-target-libgcc \ |
| 602 | maybe-install-target-libada \ |
| 603 | maybe-install-target-libstdc++-v3 \ |
| 604 | DESTDIR=$DESTDIR && \ |
| 605 | ln -s gcc $DESTDIR$TARGETDIR/bin/cc || touch .failed |
| 606 | } |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 607 | |
Nico Huber | 234d246 | 2016-01-26 16:10:17 +0100 | [diff] [blame] | 608 | build_cross_GCC() { |
Stefan Reinauer | 45f77b8 | 2016-04-03 20:52:01 -0700 | [diff] [blame] | 609 | # Work around crazy code generator in GCC that confuses CLANG. |
Aaron Durbin | b2229dc | 2016-04-07 16:58:10 -0500 | [diff] [blame] | 610 | $CC --version | grep clang >/dev/null 2>&1 && \ |
Stefan Reinauer | 45f77b8 | 2016-04-03 20:52:01 -0700 | [diff] [blame] | 611 | HOSTCFLAGS="$HOSTCFLAGS -fbracket-depth=1024" |
| 612 | |
Stefan Reinauer | d0f8372 | 2015-06-09 11:52:28 -0700 | [diff] [blame] | 613 | # GCC does not honor HOSTCFLAGS at all. CFLAGS are used for |
| 614 | # both target and host object files. |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 615 | # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET |
| 616 | # but it does not seem to work properly. At least the host library |
| 617 | # libiberty is not compiled with CFLAGS_FOR_BUILD. |
Stefan Reinauer | 45f77b8 | 2016-04-03 20:52:01 -0700 | [diff] [blame] | 618 | # Also set the CXX version of the flags because GCC is now compiled |
| 619 | # using C++. |
Patrick Georgi | 0a97d7e | 2016-01-25 09:51:22 +0100 | [diff] [blame] | 620 | CC="$CC" CFLAGS_FOR_TARGET="-O2 -Dinhibit_libc" CFLAGS="$HOSTCFLAGS" \ |
Stefan Reinauer | 45f77b8 | 2016-04-03 20:52:01 -0700 | [diff] [blame] | 621 | CFLAGS_FOR_BUILD="$HOSTCFLAGS" CXXFLAGS="$HOSTCFLAGS" \ |
| 622 | CXXFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \ |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 623 | --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \ |
| 624 | --target=${TARGETARCH} --disable-werror --disable-shared \ |
Stefan Reinauer | 2f97ebc | 2015-06-09 12:24:54 -0700 | [diff] [blame] | 625 | --enable-lto --enable-plugins --enable-gold --enable-ld=default \ |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 626 | --disable-libssp --disable-bootstrap --disable-nls \ |
| 627 | --disable-libquadmath --without-headers \ |
Patrick Georgi | 0a97d7e | 2016-01-25 09:51:22 +0100 | [diff] [blame] | 628 | --disable-threads \ |
Patrick Georgi | 1fc02d1 | 2016-03-23 21:44:43 +0100 | [diff] [blame] | 629 | --enable-interwork --enable-multilib --enable-targets=all \ |
Patrick Georgi | 0a97d7e | 2016-01-25 09:51:22 +0100 | [diff] [blame] | 630 | --disable-libatomic --disable-libcc1 --disable-decimal-float \ |
Nico Huber | bb313bf | 2015-09-08 12:30:27 +0200 | [diff] [blame] | 631 | ${GCC_OPTIONS} --enable-languages="${LANGUAGES}" \ |
Ronald G. Minnich | 7ee16b7 | 2016-02-12 21:54:59 +0000 | [diff] [blame] | 632 | --with-system-zlib \ |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 633 | --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \ |
| 634 | --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \ |
| 635 | --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \ |
| 636 | || touch .failed |
| 637 | $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-gcc || touch .failed |
| 638 | $MAKE install-gcc DESTDIR=$DESTDIR || touch .failed |
| 639 | |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 640 | if [ "$(echo $TARGETARCH | grep -c -- -mingw32)" -eq 0 ]; then |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 641 | $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-target-libgcc || touch .failed |
| 642 | $MAKE install-target-libgcc DESTDIR=$DESTDIR || touch .failed |
| 643 | fi |
| 644 | } |
| 645 | |
Nico Huber | 234d246 | 2016-01-26 16:10:17 +0100 | [diff] [blame] | 646 | build_GCC() { |
| 647 | if [ "$1" = host ]; then |
| 648 | bootstrap_GCC |
| 649 | else |
| 650 | build_cross_GCC |
| 651 | fi |
| 652 | } |
| 653 | |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 654 | build_EXPAT() { |
| 655 | CC="$CC" CFLAGS="$HOSTCFLAGS" ../${EXPAT_DIR}/configure --disable-shared \ |
Stefan Reinauer | a344b68 | 2016-04-21 19:29:51 -0700 | [diff] [blame] | 656 | --prefix=$TARGETDIR || touch .failed |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 657 | $MAKE || touch .failed |
| 658 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 659 | |
| 660 | normalize_dirs |
| 661 | } |
| 662 | |
| 663 | build_PYTHON() { |
| 664 | CC="$CC" CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$TARGETDIR \ |
Stefan Reinauer | a344b68 | 2016-04-21 19:29:51 -0700 | [diff] [blame] | 665 | || touch .failed |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 666 | $MAKE $JOBS || touch .failed |
| 667 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 668 | |
| 669 | normalize_dirs |
| 670 | } |
| 671 | |
| 672 | build_GDB() { |
| 673 | export PYTHONHOME=$DESTDIR$TARGETDIR |
| 674 | if [ $(uname) != "FreeBSD" -a $(uname) != "NetBSD" ]; then |
| 675 | LIBDL="-ldl" |
| 676 | fi |
| 677 | LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \ |
| 678 | -lpthread $LIBDL -lutil" \ |
| 679 | CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \ |
Stefan Reinauer | 7b40e42 | 2015-06-09 11:56:32 -0700 | [diff] [blame] | 680 | ../${GDB_DIR}/configure --prefix=$TARGETDIR \ |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 681 | --target=${TARGETARCH} --disable-werror --disable-nls |
| 682 | $MAKE $JOBS || touch .failed |
| 683 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 684 | } |
| 685 | |
| 686 | build_IASL() { |
| 687 | RDIR=$PWD |
| 688 | cd ../$IASL_DIR/generate/unix |
| 689 | CFLAGS="$HOSTCFLAGS" |
| 690 | HOST="_LINUX" |
| 691 | test $UNAME = "Darwin" && HOST="_APPLE" |
| 692 | test $UNAME = "FreeBSD" && HOST="_FreeBSD" |
| 693 | test $UNAME = "Cygwin" && HOST="_CYGWIN" |
Martin Roth | 6f65613 | 2015-12-08 11:14:10 -0700 | [diff] [blame] | 694 | HOST="$HOST" OPT_CFLAGS="-O -D_FORTIFY_SOURCE=2 -D COREBOOT_TOOLCHAIN_VERSION='\"coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE\"' " CFLAGS="$CFLAGS" $MAKE CC="$CC" iasl || touch $RDIR/.failed |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 695 | rm -f $DESTDIR$TARGETDIR/bin/iasl || touch $RDIR/.failed |
| 696 | cp bin/iasl $DESTDIR$TARGETDIR/bin || touch $RDIR/.failed |
| 697 | } |
| 698 | |
| 699 | build_LLVM() { |
| 700 | cd .. |
| 701 | ln -sf $PWD/$CFE_DIR $LLVM_DIR/tools/clang |
| 702 | ln -sf $PWD/$CTE_DIR $LLVM_DIR/tools/clang/tools/extra |
| 703 | ln -sf $PWD/$CRT_DIR $LLVM_DIR/projects/compiler-rt |
| 704 | cd - |
| 705 | |
| 706 | $CMAKE -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=$DESTDIR$TARGETDIR \ |
Martin Roth | fb5647a | 2015-12-18 09:26:45 -0700 | [diff] [blame] | 707 | -DCLANG_VENDOR="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE - " \ |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 708 | -DCMAKE_BUILD_TYPE=Release ../$LLVM_DIR || touch .failed |
| 709 | $MAKE $JOBS || touch .failed |
| 710 | $MAKE install || touch .failed |
| 711 | |
| 712 | cp -a ../$CFE_DIR/tools/scan-build/* $DESTDIR$TARGETDIR/bin |
| 713 | cp -a ../$CFE_DIR/tools/scan-view/* $DESTDIR$TARGETDIR/bin |
Stefan Reinauer | e9e6e3d | 2015-07-07 00:20:42 +0200 | [diff] [blame] | 714 | |
| 715 | # create symlinks to work around broken --print-librt-file-name |
| 716 | # when used with -target. |
| 717 | cd $DESTDIR$TARGETDIR/lib/clang/${CLANG_VERSION}/lib |
| 718 | for i in */libclang_rt.builtins*.a; do |
| 719 | ln -s $i . |
| 720 | done |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 721 | } |
| 722 | |
Stefan Reinauer | a851bbb | 2016-01-29 18:03:26 -0800 | [diff] [blame] | 723 | build_MAKE() { |
| 724 | CC="$CC" CFLAGS="$HOSTCFLAGS" ../${MAKE_DIR}/configure --prefix=$TARGETDIR \ |
| 725 | --disable-nls || touch .failed |
| 726 | $MAKE $JOBS || touch .failed |
| 727 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 728 | |
| 729 | normalize_dirs |
| 730 | } |
| 731 | |
Martin Roth | edf965a | 2015-11-25 16:58:33 -0700 | [diff] [blame] | 732 | print_stable() { |
| 733 | case "$PRINTSTABLE" in |
| 734 | AUTOCONF|autoconf) printf "%s\n" "$GCC_AUTOCONF_VERSION";; |
| 735 | BINUTILS|binutils) printf "%s\n" "$BINUTILS_VERSION";; |
| 736 | CLANG|clang) printf "%s\n" "$CLANG_VERSION";; |
| 737 | EXPAT|expat) printf "%s\n" "$EXPAT_VERSION";; |
| 738 | GCC|gcc) printf "%s\n" "$GCC_VERSION";; |
| 739 | GDB|gdb) printf "%s\n" "$GDB_VERSION";; |
| 740 | GMP|gmp) printf "%s\n" "$GMP_VERSION";; |
| 741 | IASL|iasl) printf "%s\n" "$IASL_VERSION";; |
| 742 | LIBELF|libelf) printf "%s\n" "$LIBELF_VERSION";; |
| 743 | MPC|mpc) printf "%s\n" "$MPC_VERSION";; |
| 744 | MPFR|mpfr) printf "%s\n" "$MPFR_VERSION";; |
| 745 | PYTHON|python) printf "%s\n" "$PYTHON_VERSION";; |
Stefan Reinauer | a851bbb | 2016-01-29 18:03:26 -0800 | [diff] [blame] | 746 | MAKE|make) printf "%s\n" "$MAKE_VERSION";; |
Martin Roth | edf965a | 2015-11-25 16:58:33 -0700 | [diff] [blame] | 747 | *) printf "Unknown tool %s\n" "$PRINTSTABLE";; |
| 748 | esac |
| 749 | } |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 750 | |
Zheng Bao | bb003c8 | 2016-08-05 13:41:51 +0800 | [diff] [blame] | 751 | trap quit 1 2 3 15 |
| 752 | |
Patrick Georgi | 6bba29f | 2010-01-29 17:40:52 +0000 | [diff] [blame] | 753 | # Look if we have getopt. If not, build it. |
| 754 | export PATH=$PATH:. |
| 755 | getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c |
| 756 | |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 757 | # parse parameters.. try to find out whether we're running GNU getopt |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 758 | getoptbrand="$(getopt -V | sed -e '1!d' -e 's,^\(......\).*,\1,')" |
Peter Stuge | 09377b7 | 2011-08-21 06:24:55 +0200 | [diff] [blame] | 759 | if [ "${getoptbrand}" = "getopt" ]; then |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 760 | # Detected GNU getopt that supports long options. |
Nico Huber | cc414dd | 2016-09-20 13:59:38 +0200 | [diff] [blame] | 761 | args=$(getopt -l version,help,clean,directory:,bootstrap,platform:,languages:,package:,jobs:,destdir:,savetemps,scripting,ccache,supported:,urls,nocolor -o Vhcd:bp:l:P:j:D:tSys:un -- "$@") |
Nico Huber | 78df0bf | 2016-09-20 14:11:53 +0200 | [diff] [blame] | 762 | getopt_ret=$? |
Nico Huber | cc414dd | 2016-09-20 13:59:38 +0200 | [diff] [blame] | 763 | eval set -- "$args" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 764 | else |
| 765 | # Detected non-GNU getopt |
Nico Huber | 152e78e | 2016-09-20 15:38:40 +0200 | [diff] [blame] | 766 | args=$(getopt Vhcd:bp:l:P:j:D:tSys:un $*) |
Nico Huber | 78df0bf | 2016-09-20 14:11:53 +0200 | [diff] [blame] | 767 | getopt_ret=$? |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 768 | set -- $args |
| 769 | fi |
| 770 | |
Nico Huber | 78df0bf | 2016-09-20 14:11:53 +0200 | [diff] [blame] | 771 | if [ $getopt_ret != 0 ]; then |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 772 | myhelp |
| 773 | exit 1 |
| 774 | fi |
| 775 | |
| 776 | while true ; do |
| 777 | case "$1" in |
| 778 | -V|--version) shift; myversion; exit 0;; |
| 779 | -h|--help) shift; myhelp; exit 0;; |
Patrick Georgi | 44af57a | 2013-12-19 22:06:22 +0100 | [diff] [blame] | 780 | -c|--clean) shift; clean=1;; |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 781 | -t|--savetemps) shift; SAVETEMPS=1;; |
| 782 | -d|--directory) shift; TARGETDIR="$1"; shift;; |
Nico Huber | 234d246 | 2016-01-26 16:10:17 +0100 | [diff] [blame] | 783 | -b|--bootstrap) shift; BOOTSTRAP=1;; |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 784 | -p|--platform) shift; TARGETARCH="$1"; shift;; |
Nico Huber | bb313bf | 2015-09-08 12:30:27 +0200 | [diff] [blame] | 785 | -l|--languages) shift; LANGUAGES="$1"; shift;; |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 786 | -D|--destdir) shift; DESTDIR="$1"; shift;; |
Martin Roth | 2c6a806 | 2016-11-14 11:58:39 -0700 | [diff] [blame] | 787 | -j|--jobs) shift; THREADS="$1"; JOBS="-j $1"; shift;; |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 788 | -P|--package) shift; PACKAGE="$1"; shift;; |
Stefan Reinauer | 2c3cd12 | 2011-11-01 21:43:50 +0100 | [diff] [blame] | 789 | -S|--scripting) shift; SKIPPYTHON=0;; |
Patrick Georgi | c1a75b1 | 2011-11-04 21:37:14 +0100 | [diff] [blame] | 790 | -y|--ccache) shift; USECCACHE=1;; |
Martin Roth | edf965a | 2015-11-25 16:58:33 -0700 | [diff] [blame] | 791 | -s|--supported) shift; PRINTSTABLE="$1"; shift;; |
Nico Huber | 152e78e | 2016-09-20 15:38:40 +0200 | [diff] [blame] | 792 | -u|--urls) shift; printf "%s\n" "$ALL_ARCHIVES"; exit 0;; |
| 793 | -n|--nocolor) shift; \ |
Martin Roth | 4a53db0 | 2016-03-01 15:21:07 -0700 | [diff] [blame] | 794 | unset red RED green GREEN blue BLUE cyan CYAN NC;; |
Patrick Georgi | d2e0dd5 | 2013-06-09 08:05:45 +0200 | [diff] [blame] | 795 | --) shift; break;; |
Patrick Georgi | d2e0dd5 | 2013-06-09 08:05:45 +0200 | [diff] [blame] | 796 | *) break;; |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 797 | esac |
| 798 | done |
| 799 | |
Nico Huber | bd74d56 | 2016-09-20 14:16:43 +0200 | [diff] [blame] | 800 | if [ $# -gt 0 ]; then |
| 801 | printf "Excessive arguments: $*\n" |
| 802 | myhelp |
| 803 | exit 1 |
| 804 | fi |
| 805 | |
Martin Roth | edf965a | 2015-11-25 16:58:33 -0700 | [diff] [blame] | 806 | if [ -n "$PRINTSTABLE" ]; then |
| 807 | print_stable |
| 808 | exit 0 |
| 809 | fi |
| 810 | |
| 811 | #print toolchain builder version string as the header |
| 812 | printversion |
| 813 | |
Martin Roth | 2c6a806 | 2016-11-14 11:58:39 -0700 | [diff] [blame] | 814 | printf "Building toolchain using %d thread(s).\n\n" "$THREADS" |
| 815 | |
Ronald G. Minnich | b460a66 | 2013-05-26 05:33:35 -0700 | [diff] [blame] | 816 | case "$TARGETARCH" in |
Timothy Pearson | a9f6235 | 2015-12-30 18:59:00 -0600 | [diff] [blame] | 817 | x86_64-elf) ;; |
| 818 | x86_64*) TARGETARCH=x86_64-elf;; |
| 819 | i386-elf) ;; |
| 820 | i386-mingw32) ;; |
| 821 | mipsel-elf) ;; |
Iru Cai | ae8e3a0 | 2016-04-02 10:50:59 +0800 | [diff] [blame] | 822 | riscv-elf) TARGETARCH=riscv64-elf;; |
Patrick Georgi | 0a97d7e | 2016-01-25 09:51:22 +0100 | [diff] [blame] | 823 | powerpc64*-linux*) ;; |
Timothy Pearson | a9f6235 | 2015-12-30 18:59:00 -0600 | [diff] [blame] | 824 | i386*) TARGETARCH=i386-elf;; |
Stefan Reinauer | 27522ad | 2016-01-29 17:31:34 -0800 | [diff] [blame] | 825 | arm*) TARGETARCH=arm-eabi;; |
Timothy Pearson | a9f6235 | 2015-12-30 18:59:00 -0600 | [diff] [blame] | 826 | aarch64*) TARGETARCH=aarch64-elf;; |
Martin Roth | 3e0f74d | 2016-03-08 12:07:04 -0700 | [diff] [blame] | 827 | nds32le-elf) ;; |
Timothy Pearson | a9f6235 | 2015-12-30 18:59:00 -0600 | [diff] [blame] | 828 | *) printf "${red}WARNING: Unsupported architecture $TARGETARCH.${NC}\n\n"; ;; |
Ronald G. Minnich | b460a66 | 2013-05-26 05:33:35 -0700 | [diff] [blame] | 829 | esac |
| 830 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 831 | # Figure out which packages to build |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 832 | |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 833 | case "$PACKAGE" in |
| 834 | GCC|gcc) |
| 835 | echo "Target architecture is now $TARGETARCH" |
| 836 | NAME="${TARGETARCH} cross GCC" |
Stefan Reinauer | bd8b2e3 | 2015-06-17 11:55:02 -0700 | [diff] [blame] | 837 | PACKAGES="GMP MPFR MPC LIBELF BINUTILS GCC" |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 838 | ;; |
| 839 | GDB|gdb) |
| 840 | NAME="${TARGETARCH} cross GDB" |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 841 | if [ $SKIPPYTHON -eq 0 ]; then |
Ronald G. Minnich | fb944f4 | 2016-02-27 04:06:42 +0000 | [diff] [blame] | 842 | PACKAGES="EXPAT PYTHON GDB" |
| 843 | else |
| 844 | PACKAGES="EXPAT GDB" |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 845 | fi |
| 846 | ;; |
| 847 | CLANG|clang) |
| 848 | NAME=clang |
| 849 | PACKAGES="LLVM CFE CRT CTE" |
David Hendricks | cd5cdd3 | 2015-06-15 17:03:22 -0700 | [diff] [blame] | 850 | CMAKE=$(searchtool cmake "cmake") || exit $? |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 851 | ;; |
| 852 | IASL|iasl) |
| 853 | NAME="IASL ACPI compiler" |
| 854 | PACKAGES=IASL |
| 855 | ;; |
Stefan Reinauer | a851bbb | 2016-01-29 18:03:26 -0800 | [diff] [blame] | 856 | MAKE|make) |
| 857 | NAME="GNU Make" |
| 858 | PACKAGES=MAKE |
| 859 | ;; |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 860 | *) |
Stefan Reinauer | a851bbb | 2016-01-29 18:03:26 -0800 | [diff] [blame] | 861 | printf "${red}ERROR: Unsupported package $PACKAGE. (Supported packages are GCC, GDB, CLANG, IASL, MAKE)${NC}\n\n"; |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 862 | exit 1 |
| 863 | ;; |
| 864 | esac |
Peter Stuge | ceacd77 | 2011-06-09 04:54:16 +0200 | [diff] [blame] | 865 | |
Stefan Reinauer | 66e9335 | 2015-06-16 22:38:23 +0200 | [diff] [blame] | 866 | # Find all the required tools: |
| 867 | |
| 868 | TAR=$(searchtool tar) || exit $? |
| 869 | PATCH=$(searchtool patch) || exit $? |
| 870 | MAKE=$(searchtool make) || exit $? |
| 871 | SHA1SUM=$(searchtool sha1sum) |
zbao | 5cf758d | 2015-09-01 22:28:57 -0400 | [diff] [blame] | 872 | #SHA512SUM=$(searchtool sha512sum) |
| 873 | #MD5SUM=$(searchtool md5sum) |
Stefan Reinauer | 66e9335 | 2015-06-16 22:38:23 +0200 | [diff] [blame] | 874 | CHECKSUM=$SHA1SUM |
Martin Roth | 95f7b22 | 2016-03-20 12:38:48 -0600 | [diff] [blame] | 875 | LBZIP2=$(searchtool lbzip2 "" nofail) |
| 876 | PIGZ=$(searchtool pigz "" nofail) |
Stefan Reinauer | 66e9335 | 2015-06-16 22:38:23 +0200 | [diff] [blame] | 877 | |
| 878 | searchtool m4 > /dev/null |
| 879 | searchtool bison > /dev/null |
| 880 | searchtool flex flex > /dev/null |
| 881 | searchtool g++ "Free Software Foundation" nofail > /dev/null || \ |
Marc Jones | 5ee6951 | 2015-06-17 15:38:17 -0600 | [diff] [blame] | 882 | searchtool clang "clang version" nofail > /dev/null || \ |
Martin Roth | e396317 | 2016-01-06 13:54:32 -0700 | [diff] [blame] | 883 | searchtool clang "LLVM" "" "g++" > /dev/null |
Stefan Reinauer | 66e9335 | 2015-06-16 22:38:23 +0200 | [diff] [blame] | 884 | searchtool bzip2 "bzip2," > /dev/null |
Nico Huber | 0ff3b39 | 2017-03-12 16:07:33 +0100 | [diff] [blame] | 885 | searchtool xz "XZ Utils" "" "xz-utils" > /dev/null |
Stefan Reinauer | 66e9335 | 2015-06-16 22:38:23 +0200 | [diff] [blame] | 886 | |
Patrick Georgi | df1ff23 | 2017-01-07 09:28:43 +0100 | [diff] [blame] | 887 | if searchtool wget "GNU" nofail > /dev/null; then |
| 888 | download_showing_percentage() { |
| 889 | url=$1 |
| 890 | printf " ..${red} 0%%" |
| 891 | wget $url 2>&1 | while read line; do |
| 892 | echo $line | grep -o "[0-9]\+%" | awk '{printf("\b\b\b\b%4s", $1)}' |
| 893 | done |
| 894 | echo "${NC}" |
| 895 | } |
| 896 | elif searchtool curl "^curl " > /dev/null; then |
| 897 | download_showing_percentage() { |
| 898 | url=$1 |
| 899 | echo |
| 900 | curl -#OL $url |
| 901 | } |
| 902 | fi |
| 903 | |
Martin Roth | 591790f | 2016-03-20 20:39:04 -0600 | [diff] [blame] | 904 | check_for_library "-lz" "zlib (zlib1g-dev or zlib-devel)" |
| 905 | |
Nico Huber | 156d87c | 2016-09-20 12:59:53 +0200 | [diff] [blame] | 906 | CC=cc |
| 907 | check_cc |
| 908 | |
Martin Roth | 8846382 | 2016-01-07 11:03:36 -0700 | [diff] [blame] | 909 | if [ "$HALT_FOR_TOOLS" -ne 0 ]; then |
| 910 | exit 1 |
| 911 | fi |
| 912 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 913 | # This initial cleanup is useful when updating the toolchain script. |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 914 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 915 | if [ "$clean" = "1" ]; then |
| 916 | cleanup |
| 917 | fi |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 918 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 919 | # Set up host compiler and flags needed for various OSes |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 920 | |
Patrick Georgi | f2c15f5 | 2015-06-11 21:07:31 +0200 | [diff] [blame] | 921 | if is_package_enabled "GCC"; then |
Stefan Reinauer | 0d2119d | 2013-07-10 14:27:56 -0700 | [diff] [blame] | 922 | if [ $UNAME = "Darwin" ]; then |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 923 | #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix" |
| 924 | |
| 925 | # generally the OS X compiler can create x64 binaries. |
| 926 | # Per default it generated i386 binaries in 10.5 and x64 |
| 927 | # binaries in 10.6 (even if the kernel is 32bit) |
| 928 | # For some weird reason, 10.5 autodetects an ABI=64 though |
| 929 | # so we're setting the ABI explicitly here. |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 930 | 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] | 931 | OPTIONS="ABI=64" |
| 932 | else |
| 933 | OPTIONS="ABI=32" |
| 934 | fi |
Stefan Reinauer | 9491b4d | 2011-10-11 22:37:59 -0700 | [diff] [blame] | 935 | |
Stefan Reinauer | 4266b92 | 2012-12-05 16:18:32 -0800 | [diff] [blame] | 936 | # In Xcode 4.5.2 the default compiler is clang. |
| 937 | # However, this compiler fails to compile gcc 4.7.x. As a |
| 938 | # workaround it's possible to compile gcc with llvm-gcc. |
Stefan Reinauer | 9491b4d | 2011-10-11 22:37:59 -0700 | [diff] [blame] | 939 | if $CC -v 2>&1 | grep -q LLVM; then |
Stefan Reinauer | 4266b92 | 2012-12-05 16:18:32 -0800 | [diff] [blame] | 940 | CC=llvm-gcc |
Stefan Reinauer | 9491b4d | 2011-10-11 22:37:59 -0700 | [diff] [blame] | 941 | fi |
zbao | 11f1d31 | 2015-08-05 23:15:54 -0400 | [diff] [blame] | 942 | elif [ $UNAME = "Linux" -o $UNAME = "Cygwin" ]; then |
Patrick Georgi | ddb8f80 | 2015-07-04 17:45:54 +0200 | [diff] [blame] | 943 | # gmp is overeager with detecting 64bit CPUs even if they run |
| 944 | # a 32bit kernel and userland. |
| 945 | if [ "$(uname -m 2>/dev/null)" = "i686" ]; then |
| 946 | OPTIONS="ABI=32" |
| 947 | fi |
Nico Huber | de45c59 | 2016-01-20 23:22:33 +0100 | [diff] [blame] | 948 | elif [ $UNAME = "NetBSD" ]; then |
| 949 | # same for NetBSD but this one reports an i386 |
| 950 | if [ "$(uname -m 2>/dev/null)" = "i386" ]; then |
| 951 | OPTIONS="ABI=32" |
| 952 | fi |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 953 | fi |
Nico Huber | 66c2c1a | 2016-09-20 13:09:29 +0200 | [diff] [blame] | 954 | if [ -z "${LANGUAGES}" ]; then |
| 955 | if hostcc_has_gnat1 && \ |
| 956 | [ "$(hostcc_version)" = "$(buildcc_version)" -o "${BOOTSTRAP}" = "1" ]; |
| 957 | then |
| 958 | printf "\nFound compatible Ada compiler, enabling Ada support by default.\n\n" |
| 959 | LANGUAGES="ada,${DEFAULT_LANGUAGES}" |
| 960 | else |
| 961 | LANGUAGES="${DEFAULT_LANGUAGES}" |
| 962 | fi |
| 963 | fi |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 964 | fi # GCC |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 965 | |
Nico Huber | 5f72f96 | 2016-01-31 23:05:19 +0100 | [diff] [blame] | 966 | export HOSTCFLAGS="-Os" |
| 967 | if have_hostcflags_from_gmp; then |
| 968 | set_hostcflags_from_gmp |
| 969 | fi |
| 970 | |
Patrick Georgi | c1a75b1 | 2011-11-04 21:37:14 +0100 | [diff] [blame] | 971 | if [ "$USECCACHE" = 1 ]; then |
| 972 | CC="ccache $CC" |
| 973 | fi |
| 974 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 975 | # Prepare target directory for building GCC |
| 976 | # (dependencies must be in the PATH) |
Stefan Reinauer | 16bd789 | 2012-12-07 23:57:01 +0100 | [diff] [blame] | 977 | mkdir -p $DESTDIR$TARGETDIR/bin |
Stefan Reinauer | 88352d7 | 2016-04-06 15:57:03 -0700 | [diff] [blame] | 978 | mkdir -p $DESTDIR$TARGETDIR/share |
Stefan Reinauer | 16bd789 | 2012-12-07 23:57:01 +0100 | [diff] [blame] | 979 | export PATH=$DESTDIR$TARGETDIR/bin:$PATH |
| 980 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 981 | # Download, unpack, patch and build all packages |
| 982 | |
Martin Roth | 0362517 | 2016-02-17 14:44:14 -0700 | [diff] [blame] | 983 | printf "Downloading tarballs ... \n" |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 984 | mkdir -p tarballs |
| 985 | for P in $PACKAGES; do |
| 986 | download $P |
| 987 | done |
Martin Roth | 0362517 | 2016-02-17 14:44:14 -0700 | [diff] [blame] | 988 | printf "Downloaded tarballs ... ${green}ok${NC}\n" |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 989 | |
| 990 | printf "Unpacking and patching ... \n" |
| 991 | for P in $PACKAGES; do |
| 992 | unpack_and_patch $P || exit 1 |
| 993 | done |
| 994 | printf "Unpacked and patched ... ${green}ok${NC}\n" |
| 995 | |
| 996 | printf "Building packages ... \n" |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 997 | for package in $PACKAGES; do |
| 998 | build $package |
| 999 | done |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 1000 | printf "Packages built ... ${green}ok${NC}\n" |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 1001 | |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 1002 | # Adding git information of current tree to target directory |
| 1003 | # for reproducibility |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 1004 | PROGNAME=$(basename "$0") |
Stefan Reinauer | 88352d7 | 2016-04-06 15:57:03 -0700 | [diff] [blame] | 1005 | rm -f "$DESTDIR$TARGETDIR/share/$PROGNAME-*" |
| 1006 | cp "$PROGNAME" "$DESTDIR$TARGETDIR/share/$PROGNAME-$CROSSGCC_VERSION-$CROSGCC_COMMIT" |
Zheng Bao | 30b895f | 2013-02-06 18:04:40 +0800 | [diff] [blame] | 1007 | |
Stefan Reinauer | 88e83e5 | 2016-04-06 15:39:48 -0700 | [diff] [blame] | 1008 | cleanup |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 1009 | |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 1010 | printf "\n${green}You can now run your $NAME toolchain from $TARGETDIR.${NC}\n" |