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