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 | { |
Stefan Reinauer | a344b68 | 2016-04-21 19:29:51 -0700 | [diff] [blame^] | 292 | if [ "$1" = "GCC" ] || [ "$1" = "GDB" ] || [ "$1" = "BINUTILS" ]; then |
Martin Roth | 444ece2 | 2016-04-01 18:46:29 -0600 | [diff] [blame] | 293 | true |
| 294 | else |
| 295 | false |
| 296 | fi |
| 297 | } |
| 298 | |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 299 | build() { |
| 300 | package=$1 |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 301 | |
| 302 | fn_exists build_$package || return |
| 303 | |
Stefan Reinauer | 05bbc920 | 2015-06-09 12:21:42 -0700 | [diff] [blame] | 304 | version="$(eval echo \$$package"_VERSION")" |
Martin Roth | 444ece2 | 2016-04-01 18:46:29 -0600 | [diff] [blame] | 305 | package_uses_targetarch "$package" && \ |
| 306 | BUILDDIR=build-${TARGETARCH}-$package || \ |
| 307 | BUILDDIR=build-$package |
Stefan Reinauer | 05bbc920 | 2015-06-09 12:21:42 -0700 | [diff] [blame] | 308 | |
| 309 | mkdir -p ${BUILDDIR} |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 310 | |
Patrick Georgi | f2c15f5 | 2015-06-11 21:07:31 +0200 | [diff] [blame] | 311 | is_package_enabled "$package" && \ |
Stefan Reinauer | 05bbc920 | 2015-06-09 12:21:42 -0700 | [diff] [blame] | 312 | if [ -f ${BUILDDIR}/.success ]; then |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 313 | printf "Skipping $package as it is already built\n" |
| 314 | else |
| 315 | printf "Building $package $version ... " |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 316 | DIR=$PWD |
Stefan Reinauer | 05bbc920 | 2015-06-09 12:21:42 -0700 | [diff] [blame] | 317 | cd ${BUILDDIR} |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 318 | rm -f .failed |
| 319 | build_${package} > build.log 2>&1 |
Stefan Reinauer | 05bbc920 | 2015-06-09 12:21:42 -0700 | [diff] [blame] | 320 | cd $DIR/${BUILDDIR} |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 321 | if [ ! -f .failed ]; then touch .success; fi |
| 322 | cd .. |
| 323 | |
Stefan Reinauer | 05bbc920 | 2015-06-09 12:21:42 -0700 | [diff] [blame] | 324 | if [ -r "${BUILDDIR}/.failed" ]; then |
| 325 | printf "${RED}failed${NC}. Check ${BUILDDIR}/build.log.\n" |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 326 | exit 1 |
| 327 | fi |
| 328 | printf "${green}ok${NC}\n" |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 329 | fi |
| 330 | } |
| 331 | |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 332 | cleanup() |
| 333 | { |
Stefan Reinauer | 88e83e5 | 2016-04-06 15:39:48 -0700 | [diff] [blame] | 334 | if [ $SAVETEMPS -ne 0 ]; then |
| 335 | printf "Leaving temporary files around... ${green}ok${NC}\n" |
| 336 | return |
| 337 | fi |
| 338 | |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 339 | printf "Cleaning up temporary files... " |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 340 | for package in $PACKAGES; do |
Martin Roth | 444ece2 | 2016-04-01 18:46:29 -0600 | [diff] [blame] | 341 | rm -rf build-${TARGETARCH}-$package build-$package $(eval echo \$$package"_DIR") |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 342 | done |
zbao | ff3f15c | 2015-08-26 22:00:31 -0400 | [diff] [blame] | 343 | rm -f getopt |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 344 | printf "${green}ok${NC}\n" |
| 345 | } |
| 346 | |
| 347 | myhelp() |
| 348 | { |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 349 | 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] | 350 | printf " $0 [-V|--version]\n" |
| 351 | printf " $0 [-h|--help]\n\n" |
| 352 | |
| 353 | printf "Options:\n" |
| 354 | printf " [-V|--version] print version number and exit\n" |
| 355 | printf " [-h|--help] print this help and exit\n" |
| 356 | printf " [-c|--clean] remove temporary files before build\n" |
| 357 | printf " [-t|--savetemps] don't remove temporary files after build\n" |
Patrick Georgi | c1a75b1 | 2011-11-04 21:37:14 +0100 | [diff] [blame] | 358 | printf " [-y|--ccache] Use ccache when building cross compiler\n" |
Martin Roth | 4a53db0 | 2016-03-01 15:21:07 -0700 | [diff] [blame] | 359 | printf " [--nocolor] don't print color codes in output\n" |
Martin Roth | 58c68d5 | 2016-03-01 15:22:42 -0700 | [diff] [blame] | 360 | printf " [--urls] print the urls for all packages\n" |
Patrick Georgi | 73166c7 | 2010-04-14 20:42:42 +0000 | [diff] [blame] | 361 | printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n" |
Martin Roth | 588c79d | 2016-03-20 12:03:20 -0600 | [diff] [blame] | 362 | printf " [-s]--supported <tool> print supported version of a tool\n" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 363 | 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] | 364 | printf " (defaults to $TARGETDIR)\n\n" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 365 | 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] | 366 | printf " (for RPM builds, default unset)\n" |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 367 | printf " [-P|--package <package>] Build a specific package: GCC, CLANG, IASL, GDB\n" |
| 368 | printf " (defaults to $PACKAGE)\n" |
| 369 | printf "GCC specific options:\n" |
| 370 | printf " [-p|--platform <platform>] target platform to build cross compiler for\n" |
| 371 | printf " (defaults to $TARGETARCH)\n" |
Nico Huber | bb313bf | 2015-09-08 12:30:27 +0200 | [diff] [blame] | 372 | printf " [-l|--languages <languages>] comma separated list of target languages\n" |
| 373 | printf " (defaults to $LANGUAGES)\n" |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 374 | printf "GDB specific options:\n" |
| 375 | printf " [-p|--platform <platform>] target platform to build cross compiler for\n" |
| 376 | printf " (defaults to $TARGETARCH)\n" |
| 377 | printf " [-S|--scripting] build scripting support for GDB\n\n" |
Martin Roth | d1da74f | 2015-06-21 12:06:28 -0600 | [diff] [blame] | 378 | printf "Platforms for GCC & GDB:\n" |
Martin Roth | 3e0f74d | 2016-03-08 12:07:04 -0700 | [diff] [blame] | 379 | 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] | 380 | printf " powerpc64le-linux-gnu nds32le-elf\n\n" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 381 | } |
| 382 | |
Martin Roth | edf965a | 2015-11-25 16:58:33 -0700 | [diff] [blame] | 383 | printversion() { |
| 384 | printf "${blue}Welcome to the ${red}coreboot${blue} cross toolchain builder v$CROSSGCC_VERSION ($CROSSGCC_DATE)${NC}\n\n" |
| 385 | } |
| 386 | |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 387 | myversion() |
| 388 | { |
Martin Roth | edf965a | 2015-11-25 16:58:33 -0700 | [diff] [blame] | 389 | printversion |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 390 | |
| 391 | cat << EOF |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 392 | Copyright (C) 2008-2010 by coresystems GmbH |
Marc Jones | 2aac3f6 | 2011-08-08 16:07:50 -0600 | [diff] [blame] | 393 | Copyright (C) 2011 by Sage Electronic Engineering |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 394 | |
| 395 | This program is free software; you can redistribute it and/or modify |
| 396 | it under the terms of the GNU General Public License as published by |
| 397 | the Free Software Foundation; version 2 of the License. |
| 398 | |
| 399 | This program is distributed in the hope that it will be useful, |
| 400 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 401 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 402 | GNU General Public License for more details. |
| 403 | |
| 404 | EOF |
| 405 | } |
| 406 | |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 407 | build_GMP() { |
| 408 | CC="$CC" CFLAGS="-Os" ../${GMP_DIR}/configure --disable-shared --enable-fat --prefix=$TARGETDIR $OPTIONS \ |
| 409 | || touch .failed |
| 410 | $MAKE $JOBS || touch .failed |
| 411 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 412 | |
| 413 | normalize_dirs |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 414 | |
| 415 | # Now set CFLAGS to match GMP CFLAGS but strip out -pedantic |
| 416 | # as GCC 4.6.x fails if it's there. |
| 417 | export HOSTCFLAGS=$(grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2 |\ |
| 418 | sed s,-pedantic,,) |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | build_MPFR() { |
| 422 | test $UNAME = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL" |
| 423 | CC="$CC" ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \ |
| 424 | --infodir=$TARGETDIR/info \ |
| 425 | --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \ |
| 426 | touch .failed |
| 427 | $MAKE $JOBS || touch .failed |
| 428 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 429 | |
| 430 | normalize_dirs |
| 431 | |
| 432 | # work around build problem of libgmp.la |
| 433 | if [ "$DESTDIR" != "" ]; then |
| 434 | perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la |
| 435 | fi |
| 436 | } |
| 437 | |
| 438 | build_MPC() { |
| 439 | CC="$CC" ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \ |
| 440 | --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \ |
| 441 | --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \ |
| 442 | touch .failed |
| 443 | $MAKE $JOBS || touch .failed |
| 444 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 445 | |
| 446 | normalize_dirs |
| 447 | } |
| 448 | |
| 449 | build_LIBELF() { |
| 450 | CC="$CC" CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no \ |
| 451 | ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \ |
| 452 | --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed |
| 453 | $MAKE $JOBS || touch .failed |
| 454 | $MAKE install prefix=$DESTDIR$TARGETDIR || touch .failed |
| 455 | |
| 456 | normalize_dirs |
| 457 | } |
| 458 | |
| 459 | build_BINUTILS() { |
Stefan Reinauer | 682a90c | 2015-06-09 14:59:58 -0700 | [diff] [blame] | 460 | if [ $TARGETARCH == "x86_64-elf" ]; then |
| 461 | ADDITIONALTARGET=",i386-elf" |
| 462 | fi |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 463 | CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \ |
Stefan Reinauer | 682a90c | 2015-06-09 14:59:58 -0700 | [diff] [blame] | 464 | --target=${TARGETARCH} --enable-targets=${TARGETARCH}${ADDITIONALTARGET} \ |
| 465 | --disable-werror --disable-nls --enable-lto --enable-gold \ |
Stefan Reinauer | 2fe2d3d | 2016-04-05 02:14:48 -0700 | [diff] [blame] | 466 | --enable-interwork --enable-multilib \ |
Stefan Reinauer | 682a90c | 2015-06-09 14:59:58 -0700 | [diff] [blame] | 467 | --enable-plugins --enable-multilibs CFLAGS="$HOSTCFLAGS" || touch .failed |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 468 | $MAKE $JOBS || touch .failed |
| 469 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 470 | } |
| 471 | |
| 472 | |
| 473 | build_GCC() { |
Stefan Reinauer | 45f77b8 | 2016-04-03 20:52:01 -0700 | [diff] [blame] | 474 | # Work around crazy code generator in GCC that confuses CLANG. |
Aaron Durbin | b2229dc | 2016-04-07 16:58:10 -0500 | [diff] [blame] | 475 | $CC --version | grep clang >/dev/null 2>&1 && \ |
Stefan Reinauer | 45f77b8 | 2016-04-03 20:52:01 -0700 | [diff] [blame] | 476 | HOSTCFLAGS="$HOSTCFLAGS -fbracket-depth=1024" |
| 477 | |
Stefan Reinauer | d0f8372 | 2015-06-09 11:52:28 -0700 | [diff] [blame] | 478 | # GCC does not honor HOSTCFLAGS at all. CFLAGS are used for |
| 479 | # both target and host object files. |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 480 | # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET |
| 481 | # but it does not seem to work properly. At least the host library |
| 482 | # libiberty is not compiled with CFLAGS_FOR_BUILD. |
Stefan Reinauer | 45f77b8 | 2016-04-03 20:52:01 -0700 | [diff] [blame] | 483 | # Also set the CXX version of the flags because GCC is now compiled |
| 484 | # using C++. |
Patrick Georgi | 0a97d7e | 2016-01-25 09:51:22 +0100 | [diff] [blame] | 485 | CC="$CC" CFLAGS_FOR_TARGET="-O2 -Dinhibit_libc" CFLAGS="$HOSTCFLAGS" \ |
Stefan Reinauer | 45f77b8 | 2016-04-03 20:52:01 -0700 | [diff] [blame] | 486 | CFLAGS_FOR_BUILD="$HOSTCFLAGS" CXXFLAGS="$HOSTCFLAGS" \ |
| 487 | CXXFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \ |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 488 | --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \ |
| 489 | --target=${TARGETARCH} --disable-werror --disable-shared \ |
Stefan Reinauer | 2f97ebc | 2015-06-09 12:24:54 -0700 | [diff] [blame] | 490 | --enable-lto --enable-plugins --enable-gold --enable-ld=default \ |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 491 | --disable-libssp --disable-bootstrap --disable-nls \ |
| 492 | --disable-libquadmath --without-headers \ |
Patrick Georgi | 0a97d7e | 2016-01-25 09:51:22 +0100 | [diff] [blame] | 493 | --disable-threads \ |
Patrick Georgi | 1fc02d1 | 2016-03-23 21:44:43 +0100 | [diff] [blame] | 494 | --enable-interwork --enable-multilib --enable-targets=all \ |
Patrick Georgi | 0a97d7e | 2016-01-25 09:51:22 +0100 | [diff] [blame] | 495 | --disable-libatomic --disable-libcc1 --disable-decimal-float \ |
Nico Huber | bb313bf | 2015-09-08 12:30:27 +0200 | [diff] [blame] | 496 | ${GCC_OPTIONS} --enable-languages="${LANGUAGES}" \ |
Ronald G. Minnich | 7ee16b7 | 2016-02-12 21:54:59 +0000 | [diff] [blame] | 497 | --with-system-zlib \ |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 498 | --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \ |
| 499 | --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \ |
| 500 | --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \ |
| 501 | || touch .failed |
| 502 | $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-gcc || touch .failed |
| 503 | $MAKE install-gcc DESTDIR=$DESTDIR || touch .failed |
| 504 | |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 505 | if [ "$(echo $TARGETARCH | grep -c -- -mingw32)" -eq 0 ]; then |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 506 | $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-target-libgcc || touch .failed |
| 507 | $MAKE install-target-libgcc DESTDIR=$DESTDIR || touch .failed |
| 508 | fi |
| 509 | } |
| 510 | |
| 511 | build_EXPAT() { |
| 512 | CC="$CC" CFLAGS="$HOSTCFLAGS" ../${EXPAT_DIR}/configure --disable-shared \ |
Stefan Reinauer | a344b68 | 2016-04-21 19:29:51 -0700 | [diff] [blame^] | 513 | --prefix=$TARGETDIR || touch .failed |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 514 | $MAKE || touch .failed |
| 515 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 516 | |
| 517 | normalize_dirs |
| 518 | } |
| 519 | |
| 520 | build_PYTHON() { |
| 521 | CC="$CC" CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$TARGETDIR \ |
Stefan Reinauer | a344b68 | 2016-04-21 19:29:51 -0700 | [diff] [blame^] | 522 | || touch .failed |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 523 | $MAKE $JOBS || touch .failed |
| 524 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 525 | |
| 526 | normalize_dirs |
| 527 | } |
| 528 | |
| 529 | build_GDB() { |
| 530 | export PYTHONHOME=$DESTDIR$TARGETDIR |
| 531 | if [ $(uname) != "FreeBSD" -a $(uname) != "NetBSD" ]; then |
| 532 | LIBDL="-ldl" |
| 533 | fi |
| 534 | LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \ |
| 535 | -lpthread $LIBDL -lutil" \ |
| 536 | CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \ |
Stefan Reinauer | 7b40e42 | 2015-06-09 11:56:32 -0700 | [diff] [blame] | 537 | ../${GDB_DIR}/configure --prefix=$TARGETDIR \ |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 538 | --target=${TARGETARCH} --disable-werror --disable-nls |
| 539 | $MAKE $JOBS || touch .failed |
| 540 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 541 | } |
| 542 | |
| 543 | build_IASL() { |
| 544 | RDIR=$PWD |
| 545 | cd ../$IASL_DIR/generate/unix |
| 546 | CFLAGS="$HOSTCFLAGS" |
| 547 | HOST="_LINUX" |
| 548 | test $UNAME = "Darwin" && HOST="_APPLE" |
| 549 | test $UNAME = "FreeBSD" && HOST="_FreeBSD" |
| 550 | test $UNAME = "Cygwin" && HOST="_CYGWIN" |
Martin Roth | 6f65613 | 2015-12-08 11:14:10 -0700 | [diff] [blame] | 551 | 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] | 552 | rm -f $DESTDIR$TARGETDIR/bin/iasl || touch $RDIR/.failed |
| 553 | cp bin/iasl $DESTDIR$TARGETDIR/bin || touch $RDIR/.failed |
| 554 | } |
| 555 | |
| 556 | build_LLVM() { |
| 557 | cd .. |
| 558 | ln -sf $PWD/$CFE_DIR $LLVM_DIR/tools/clang |
| 559 | ln -sf $PWD/$CTE_DIR $LLVM_DIR/tools/clang/tools/extra |
| 560 | ln -sf $PWD/$CRT_DIR $LLVM_DIR/projects/compiler-rt |
| 561 | cd - |
| 562 | |
| 563 | $CMAKE -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=$DESTDIR$TARGETDIR \ |
Martin Roth | fb5647a | 2015-12-18 09:26:45 -0700 | [diff] [blame] | 564 | -DCLANG_VENDOR="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE - " \ |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 565 | -DCMAKE_BUILD_TYPE=Release ../$LLVM_DIR || touch .failed |
| 566 | $MAKE $JOBS || touch .failed |
| 567 | $MAKE install || touch .failed |
| 568 | |
| 569 | cp -a ../$CFE_DIR/tools/scan-build/* $DESTDIR$TARGETDIR/bin |
| 570 | cp -a ../$CFE_DIR/tools/scan-view/* $DESTDIR$TARGETDIR/bin |
Stefan Reinauer | e9e6e3d | 2015-07-07 00:20:42 +0200 | [diff] [blame] | 571 | |
| 572 | # create symlinks to work around broken --print-librt-file-name |
| 573 | # when used with -target. |
| 574 | cd $DESTDIR$TARGETDIR/lib/clang/${CLANG_VERSION}/lib |
| 575 | for i in */libclang_rt.builtins*.a; do |
| 576 | ln -s $i . |
| 577 | done |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Stefan Reinauer | a851bbb | 2016-01-29 18:03:26 -0800 | [diff] [blame] | 580 | build_MAKE() { |
| 581 | CC="$CC" CFLAGS="$HOSTCFLAGS" ../${MAKE_DIR}/configure --prefix=$TARGETDIR \ |
| 582 | --disable-nls || touch .failed |
| 583 | $MAKE $JOBS || touch .failed |
| 584 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 585 | |
| 586 | normalize_dirs |
| 587 | } |
| 588 | |
Martin Roth | edf965a | 2015-11-25 16:58:33 -0700 | [diff] [blame] | 589 | print_stable() { |
| 590 | case "$PRINTSTABLE" in |
| 591 | AUTOCONF|autoconf) printf "%s\n" "$GCC_AUTOCONF_VERSION";; |
| 592 | BINUTILS|binutils) printf "%s\n" "$BINUTILS_VERSION";; |
| 593 | CLANG|clang) printf "%s\n" "$CLANG_VERSION";; |
| 594 | EXPAT|expat) printf "%s\n" "$EXPAT_VERSION";; |
| 595 | GCC|gcc) printf "%s\n" "$GCC_VERSION";; |
| 596 | GDB|gdb) printf "%s\n" "$GDB_VERSION";; |
| 597 | GMP|gmp) printf "%s\n" "$GMP_VERSION";; |
| 598 | IASL|iasl) printf "%s\n" "$IASL_VERSION";; |
| 599 | LIBELF|libelf) printf "%s\n" "$LIBELF_VERSION";; |
| 600 | MPC|mpc) printf "%s\n" "$MPC_VERSION";; |
| 601 | MPFR|mpfr) printf "%s\n" "$MPFR_VERSION";; |
| 602 | PYTHON|python) printf "%s\n" "$PYTHON_VERSION";; |
Stefan Reinauer | a851bbb | 2016-01-29 18:03:26 -0800 | [diff] [blame] | 603 | MAKE|make) printf "%s\n" "$MAKE_VERSION";; |
Martin Roth | edf965a | 2015-11-25 16:58:33 -0700 | [diff] [blame] | 604 | *) printf "Unknown tool %s\n" "$PRINTSTABLE";; |
| 605 | esac |
| 606 | } |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 607 | |
Patrick Georgi | 6bba29f | 2010-01-29 17:40:52 +0000 | [diff] [blame] | 608 | # Look if we have getopt. If not, build it. |
| 609 | export PATH=$PATH:. |
| 610 | getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c |
| 611 | |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 612 | # parse parameters.. try to find out whether we're running GNU getopt |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 613 | getoptbrand="$(getopt -V | sed -e '1!d' -e 's,^\(......\).*,\1,')" |
Peter Stuge | 09377b7 | 2011-08-21 06:24:55 +0200 | [diff] [blame] | 614 | if [ "${getoptbrand}" = "getopt" ]; then |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 615 | # Detected GNU getopt that supports long options. |
Martin Roth | edf965a | 2015-11-25 16:58:33 -0700 | [diff] [blame] | 616 | 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] | 617 | eval set "$args" |
| 618 | else |
| 619 | # Detected non-GNU getopt |
Martin Roth | edf965a | 2015-11-25 16:58:33 -0700 | [diff] [blame] | 620 | args=$(getopt Vhcd:p:l:P:j:D:tSys: $*) |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 621 | set -- $args |
| 622 | fi |
| 623 | |
| 624 | if [ $? != 0 ]; then |
| 625 | myhelp |
| 626 | exit 1 |
| 627 | fi |
| 628 | |
| 629 | while true ; do |
| 630 | case "$1" in |
| 631 | -V|--version) shift; myversion; exit 0;; |
| 632 | -h|--help) shift; myhelp; exit 0;; |
Patrick Georgi | 44af57a | 2013-12-19 22:06:22 +0100 | [diff] [blame] | 633 | -c|--clean) shift; clean=1;; |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 634 | -t|--savetemps) shift; SAVETEMPS=1;; |
| 635 | -d|--directory) shift; TARGETDIR="$1"; shift;; |
| 636 | -p|--platform) shift; TARGETARCH="$1"; shift;; |
Nico Huber | bb313bf | 2015-09-08 12:30:27 +0200 | [diff] [blame] | 637 | -l|--languages) shift; LANGUAGES="$1"; shift;; |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 638 | -D|--destdir) shift; DESTDIR="$1"; shift;; |
Patrick Georgi | 73166c7 | 2010-04-14 20:42:42 +0000 | [diff] [blame] | 639 | -j|--jobs) shift; JOBS="-j $1"; shift;; |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 640 | -P|--package) shift; PACKAGE="$1"; shift;; |
Stefan Reinauer | 2c3cd12 | 2011-11-01 21:43:50 +0100 | [diff] [blame] | 641 | -S|--scripting) shift; SKIPPYTHON=0;; |
Patrick Georgi | c1a75b1 | 2011-11-04 21:37:14 +0100 | [diff] [blame] | 642 | -y|--ccache) shift; USECCACHE=1;; |
Martin Roth | edf965a | 2015-11-25 16:58:33 -0700 | [diff] [blame] | 643 | -s|--supported) shift; PRINTSTABLE="$1"; shift;; |
Martin Roth | 58c68d5 | 2016-03-01 15:22:42 -0700 | [diff] [blame] | 644 | --urls) shift; printf "%s\n" "$ALL_ARCHIVES"; exit 0;; |
Martin Roth | 4a53db0 | 2016-03-01 15:21:07 -0700 | [diff] [blame] | 645 | --nocolor) shift; \ |
| 646 | unset red RED green GREEN blue BLUE cyan CYAN NC;; |
Patrick Georgi | d2e0dd5 | 2013-06-09 08:05:45 +0200 | [diff] [blame] | 647 | --) shift; break;; |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 648 | -*) printf "Invalid option\n\n"; myhelp; exit 1;; |
Patrick Georgi | d2e0dd5 | 2013-06-09 08:05:45 +0200 | [diff] [blame] | 649 | *) break;; |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 650 | esac |
| 651 | done |
| 652 | |
Martin Roth | edf965a | 2015-11-25 16:58:33 -0700 | [diff] [blame] | 653 | if [ -n "$PRINTSTABLE" ]; then |
| 654 | print_stable |
| 655 | exit 0 |
| 656 | fi |
| 657 | |
| 658 | #print toolchain builder version string as the header |
| 659 | printversion |
| 660 | |
Ronald G. Minnich | b460a66 | 2013-05-26 05:33:35 -0700 | [diff] [blame] | 661 | case "$TARGETARCH" in |
Timothy Pearson | a9f6235 | 2015-12-30 18:59:00 -0600 | [diff] [blame] | 662 | x86_64-elf) ;; |
| 663 | x86_64*) TARGETARCH=x86_64-elf;; |
| 664 | i386-elf) ;; |
| 665 | i386-mingw32) ;; |
| 666 | mipsel-elf) ;; |
| 667 | riscv-elf) ;; |
Patrick Georgi | 0a97d7e | 2016-01-25 09:51:22 +0100 | [diff] [blame] | 668 | powerpc64*-linux*) ;; |
Timothy Pearson | a9f6235 | 2015-12-30 18:59:00 -0600 | [diff] [blame] | 669 | i386*) TARGETARCH=i386-elf;; |
Stefan Reinauer | 27522ad | 2016-01-29 17:31:34 -0800 | [diff] [blame] | 670 | arm*) TARGETARCH=arm-eabi;; |
Timothy Pearson | a9f6235 | 2015-12-30 18:59:00 -0600 | [diff] [blame] | 671 | aarch64*) TARGETARCH=aarch64-elf;; |
Martin Roth | 3e0f74d | 2016-03-08 12:07:04 -0700 | [diff] [blame] | 672 | nds32le-elf) ;; |
Timothy Pearson | a9f6235 | 2015-12-30 18:59:00 -0600 | [diff] [blame] | 673 | *) printf "${red}WARNING: Unsupported architecture $TARGETARCH.${NC}\n\n"; ;; |
Ronald G. Minnich | b460a66 | 2013-05-26 05:33:35 -0700 | [diff] [blame] | 674 | esac |
| 675 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 676 | # Figure out which packages to build |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 677 | |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 678 | case "$PACKAGE" in |
| 679 | GCC|gcc) |
| 680 | echo "Target architecture is now $TARGETARCH" |
| 681 | NAME="${TARGETARCH} cross GCC" |
Stefan Reinauer | bd8b2e3 | 2015-06-17 11:55:02 -0700 | [diff] [blame] | 682 | PACKAGES="GMP MPFR MPC LIBELF BINUTILS GCC" |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 683 | ;; |
| 684 | GDB|gdb) |
| 685 | NAME="${TARGETARCH} cross GDB" |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 686 | if [ $SKIPPYTHON -eq 0 ]; then |
Ronald G. Minnich | fb944f4 | 2016-02-27 04:06:42 +0000 | [diff] [blame] | 687 | PACKAGES="EXPAT PYTHON GDB" |
| 688 | else |
| 689 | PACKAGES="EXPAT GDB" |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 690 | fi |
| 691 | ;; |
| 692 | CLANG|clang) |
| 693 | NAME=clang |
| 694 | PACKAGES="LLVM CFE CRT CTE" |
David Hendricks | cd5cdd3 | 2015-06-15 17:03:22 -0700 | [diff] [blame] | 695 | CMAKE=$(searchtool cmake "cmake") || exit $? |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 696 | ;; |
| 697 | IASL|iasl) |
| 698 | NAME="IASL ACPI compiler" |
| 699 | PACKAGES=IASL |
| 700 | ;; |
Stefan Reinauer | a851bbb | 2016-01-29 18:03:26 -0800 | [diff] [blame] | 701 | MAKE|make) |
| 702 | NAME="GNU Make" |
| 703 | PACKAGES=MAKE |
| 704 | ;; |
Stefan Reinauer | 85b07d6 | 2015-06-09 14:45:14 -0700 | [diff] [blame] | 705 | *) |
Stefan Reinauer | a851bbb | 2016-01-29 18:03:26 -0800 | [diff] [blame] | 706 | 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] | 707 | exit 1 |
| 708 | ;; |
| 709 | esac |
Peter Stuge | ceacd77 | 2011-06-09 04:54:16 +0200 | [diff] [blame] | 710 | |
Stefan Reinauer | 66e9335 | 2015-06-16 22:38:23 +0200 | [diff] [blame] | 711 | # Find all the required tools: |
| 712 | |
| 713 | TAR=$(searchtool tar) || exit $? |
| 714 | PATCH=$(searchtool patch) || exit $? |
| 715 | MAKE=$(searchtool make) || exit $? |
| 716 | SHA1SUM=$(searchtool sha1sum) |
| 717 | SHA512SUM=$(searchtool sha512sum) |
| 718 | CHECKSUM=$SHA1SUM |
Martin Roth | 95f7b22 | 2016-03-20 12:38:48 -0600 | [diff] [blame] | 719 | LBZIP2=$(searchtool lbzip2 "" nofail) |
| 720 | PIGZ=$(searchtool pigz "" nofail) |
Stefan Reinauer | 66e9335 | 2015-06-16 22:38:23 +0200 | [diff] [blame] | 721 | |
| 722 | searchtool m4 > /dev/null |
| 723 | searchtool bison > /dev/null |
| 724 | searchtool flex flex > /dev/null |
| 725 | searchtool g++ "Free Software Foundation" nofail > /dev/null || \ |
Marc Jones | 5ee6951 | 2015-06-17 15:38:17 -0600 | [diff] [blame] | 726 | searchtool clang "clang version" nofail > /dev/null || \ |
Martin Roth | e396317 | 2016-01-06 13:54:32 -0700 | [diff] [blame] | 727 | searchtool clang "LLVM" "" "g++" > /dev/null |
Stefan Reinauer | 66e9335 | 2015-06-16 22:38:23 +0200 | [diff] [blame] | 728 | searchtool wget > /dev/null |
| 729 | searchtool bzip2 "bzip2," > /dev/null |
| 730 | |
Martin Roth | 591790f | 2016-03-20 20:39:04 -0600 | [diff] [blame] | 731 | check_for_library "-lz" "zlib (zlib1g-dev or zlib-devel)" |
| 732 | |
Martin Roth | 8846382 | 2016-01-07 11:03:36 -0700 | [diff] [blame] | 733 | if [ "$HALT_FOR_TOOLS" -ne 0 ]; then |
| 734 | exit 1 |
| 735 | fi |
| 736 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 737 | # This initial cleanup is useful when updating the toolchain script. |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 738 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 739 | if [ "$clean" = "1" ]; then |
| 740 | cleanup |
| 741 | fi |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 742 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 743 | # Set up host compiler and flags needed for various OSes |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 744 | |
Stefan Reinauer | 9491b4d | 2011-10-11 22:37:59 -0700 | [diff] [blame] | 745 | CC=cc |
Patrick Georgi | f2c15f5 | 2015-06-11 21:07:31 +0200 | [diff] [blame] | 746 | if is_package_enabled "GCC"; then |
Stefan Reinauer | 0d2119d | 2013-07-10 14:27:56 -0700 | [diff] [blame] | 747 | if [ $UNAME = "Darwin" ]; then |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 748 | #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix" |
| 749 | |
| 750 | # generally the OS X compiler can create x64 binaries. |
| 751 | # Per default it generated i386 binaries in 10.5 and x64 |
| 752 | # binaries in 10.6 (even if the kernel is 32bit) |
| 753 | # For some weird reason, 10.5 autodetects an ABI=64 though |
| 754 | # so we're setting the ABI explicitly here. |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 755 | 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] | 756 | OPTIONS="ABI=64" |
| 757 | else |
| 758 | OPTIONS="ABI=32" |
| 759 | fi |
Stefan Reinauer | 9491b4d | 2011-10-11 22:37:59 -0700 | [diff] [blame] | 760 | |
Stefan Reinauer | 4266b92 | 2012-12-05 16:18:32 -0800 | [diff] [blame] | 761 | # In Xcode 4.5.2 the default compiler is clang. |
| 762 | # However, this compiler fails to compile gcc 4.7.x. As a |
| 763 | # workaround it's possible to compile gcc with llvm-gcc. |
Stefan Reinauer | 9491b4d | 2011-10-11 22:37:59 -0700 | [diff] [blame] | 764 | if $CC -v 2>&1 | grep -q LLVM; then |
Stefan Reinauer | 4266b92 | 2012-12-05 16:18:32 -0800 | [diff] [blame] | 765 | CC=llvm-gcc |
Stefan Reinauer | 9491b4d | 2011-10-11 22:37:59 -0700 | [diff] [blame] | 766 | fi |
zbao | 11f1d31 | 2015-08-05 23:15:54 -0400 | [diff] [blame] | 767 | elif [ $UNAME = "Linux" -o $UNAME = "Cygwin" ]; then |
Patrick Georgi | ddb8f80 | 2015-07-04 17:45:54 +0200 | [diff] [blame] | 768 | # gmp is overeager with detecting 64bit CPUs even if they run |
| 769 | # a 32bit kernel and userland. |
| 770 | if [ "$(uname -m 2>/dev/null)" = "i686" ]; then |
| 771 | OPTIONS="ABI=32" |
| 772 | fi |
Nico Huber | de45c59 | 2016-01-20 23:22:33 +0100 | [diff] [blame] | 773 | elif [ $UNAME = "NetBSD" ]; then |
| 774 | # same for NetBSD but this one reports an i386 |
| 775 | if [ "$(uname -m 2>/dev/null)" = "i386" ]; then |
| 776 | OPTIONS="ABI=32" |
| 777 | fi |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 778 | fi |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 779 | fi # GCC |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 780 | |
Patrick Georgi | c1a75b1 | 2011-11-04 21:37:14 +0100 | [diff] [blame] | 781 | if [ "$USECCACHE" = 1 ]; then |
| 782 | CC="ccache $CC" |
| 783 | fi |
| 784 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 785 | # Prepare target directory for building GCC |
| 786 | # (dependencies must be in the PATH) |
Stefan Reinauer | 16bd789 | 2012-12-07 23:57:01 +0100 | [diff] [blame] | 787 | mkdir -p $DESTDIR$TARGETDIR/bin |
Stefan Reinauer | 88352d7 | 2016-04-06 15:57:03 -0700 | [diff] [blame] | 788 | mkdir -p $DESTDIR$TARGETDIR/share |
Stefan Reinauer | 16bd789 | 2012-12-07 23:57:01 +0100 | [diff] [blame] | 789 | export PATH=$DESTDIR$TARGETDIR/bin:$PATH |
| 790 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 791 | # Download, unpack, patch and build all packages |
| 792 | |
Martin Roth | 0362517 | 2016-02-17 14:44:14 -0700 | [diff] [blame] | 793 | printf "Downloading tarballs ... \n" |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 794 | mkdir -p tarballs |
| 795 | for P in $PACKAGES; do |
| 796 | download $P |
| 797 | done |
Martin Roth | 0362517 | 2016-02-17 14:44:14 -0700 | [diff] [blame] | 798 | printf "Downloaded tarballs ... ${green}ok${NC}\n" |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 799 | |
| 800 | printf "Unpacking and patching ... \n" |
| 801 | for P in $PACKAGES; do |
| 802 | unpack_and_patch $P || exit 1 |
| 803 | done |
| 804 | printf "Unpacked and patched ... ${green}ok${NC}\n" |
| 805 | |
| 806 | printf "Building packages ... \n" |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 807 | for package in $PACKAGES; do |
| 808 | build $package |
| 809 | done |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 810 | printf "Packages built ... ${green}ok${NC}\n" |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 811 | |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 812 | # Adding git information of current tree to target directory |
| 813 | # for reproducibility |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 814 | PROGNAME=$(basename "$0") |
Stefan Reinauer | 88352d7 | 2016-04-06 15:57:03 -0700 | [diff] [blame] | 815 | rm -f "$DESTDIR$TARGETDIR/share/$PROGNAME-*" |
| 816 | cp "$PROGNAME" "$DESTDIR$TARGETDIR/share/$PROGNAME-$CROSSGCC_VERSION-$CROSGCC_COMMIT" |
Zheng Bao | 30b895f | 2013-02-06 18:04:40 +0800 | [diff] [blame] | 817 | |
Stefan Reinauer | 88e83e5 | 2016-04-06 15:39:48 -0700 | [diff] [blame] | 818 | cleanup |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 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" |