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 | # |
| 18 | # You should have received a copy of the GNU General Public License |
| 19 | # along with this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 20 | # Foundation, Inc. |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 21 | # |
| 22 | |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 23 | cd $(dirname $0) |
Patrick Georgi | 8135dba | 2015-03-17 21:05:20 +0100 | [diff] [blame] | 24 | |
Stefan Reinauer | bed95b2 | 2015-06-09 13:41:40 -0700 | [diff] [blame] | 25 | CROSSGCC_DATE="June 9th, 2015" |
| 26 | CROSSGCC_VERSION="1.30" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 27 | |
| 28 | # default settings |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 29 | TARGETDIR=$(pwd)/xgcc |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 30 | TARGETARCH=i386-elf |
| 31 | DESTDIR= |
| 32 | |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 33 | # GCC toolchain version numbers |
Patrick Georgi | 53c388f | 2015-03-07 09:55:18 +0100 | [diff] [blame] | 34 | GMP_VERSION=6.0.0 |
Stefan Reinauer | 0d2119d | 2013-07-10 14:27:56 -0700 | [diff] [blame] | 35 | MPFR_VERSION=3.1.2 |
Paul Menzel | e661942 | 2015-02-23 10:33:59 +0100 | [diff] [blame] | 36 | MPC_VERSION=1.0.3 |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 37 | LIBELF_VERSION=0.8.13 |
Patrick Georgi | 53c388f | 2015-03-07 09:55:18 +0100 | [diff] [blame] | 38 | GCC_VERSION=4.9.2 |
Stefan Reinauer | 0d2119d | 2013-07-10 14:27:56 -0700 | [diff] [blame] | 39 | GCC_AUTOCONF_VERSION=2.69 |
Patrick Georgi | 53c388f | 2015-03-07 09:55:18 +0100 | [diff] [blame] | 40 | BINUTILS_VERSION=2.25 |
Stefan Reinauer | bed95b2 | 2015-06-09 13:41:40 -0700 | [diff] [blame] | 41 | GDB_VERSION=7.9.1 |
Patrick Georgi | 53c388f | 2015-03-07 09:55:18 +0100 | [diff] [blame] | 42 | IASL_VERSION=20150204 |
| 43 | PYTHON_VERSION=3.4.3 |
Idwer Vollering | 296a015 | 2012-10-26 01:48:04 +0200 | [diff] [blame] | 44 | EXPAT_VERSION=2.1.0 |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 45 | # CLANG version number |
| 46 | CLANG_VERSION=3.6.1 |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 47 | |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 48 | # GCC toolchain archive locations |
Patrick Georgi | 53c388f | 2015-03-07 09:55:18 +0100 | [diff] [blame] | 49 | GMP_ARCHIVE="http://ftpmirror.gnu.org/gmp/gmp-${GMP_VERSION}a.tar.bz2" |
Patrick Georgi | 6e61ad3 | 2012-05-12 23:19:30 +0200 | [diff] [blame] | 50 | MPFR_ARCHIVE="http://ftpmirror.gnu.org/mpfr/mpfr-${MPFR_VERSION}.tar.bz2" |
Idwer Vollering | 7962fc7 | 2012-10-25 02:14:09 +0200 | [diff] [blame] | 51 | MPC_ARCHIVE="http://ftpmirror.gnu.org/mpc/mpc-${MPC_VERSION}.tar.gz" |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 52 | LIBELF_ARCHIVE="http://www.mr511.de/software/libelf-${LIBELF_VERSION}.tar.gz" |
Idwer Vollering | 1cfee0b | 2012-10-25 02:03:53 +0200 | [diff] [blame] | 53 | 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] | 54 | BINUTILS_ARCHIVE="http://ftpmirror.gnu.org/binutils/binutils-${BINUTILS_VERSION}.tar.bz2" |
Patrick Georgi | 53c388f | 2015-03-07 09:55:18 +0100 | [diff] [blame] | 55 | GDB_ARCHIVE="http://ftpmirror.gnu.org/gdb/gdb-${GDB_VERSION}.tar.xz" |
| 56 | IASL_ARCHIVE="https://acpica.org/sites/acpica/files/acpica-unix-${IASL_VERSION}.tar.gz" |
| 57 | 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] | 58 | 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] | 59 | # CLANG toolchain archive locations |
| 60 | LLVM_ARCHIVE="http://llvm.org/releases/${CLANG_VERSION}/llvm-${CLANG_VERSION}.src.tar.xz" |
| 61 | CFE_ARCHIVE="http://llvm.org/releases/${CLANG_VERSION}/cfe-${CLANG_VERSION}.src.tar.xz" |
| 62 | CRT_ARCHIVE="http://llvm.org/releases/${CLANG_VERSION}/compiler-rt-${CLANG_VERSION}.src.tar.xz" |
| 63 | CTE_ARCHIVE="http://llvm.org/releases/${CLANG_VERSION}/clang-tools-extra-${CLANG_VERSION}.src.tar.xz" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 64 | |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 65 | # GCC toolchain directories |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 66 | GMP_DIR="gmp-${GMP_VERSION}" |
| 67 | MPFR_DIR="mpfr-${MPFR_VERSION}" |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 68 | MPC_DIR="mpc-${MPC_VERSION}" |
| 69 | LIBELF_DIR="libelf-${LIBELF_VERSION}" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 70 | GCC_DIR="gcc-${GCC_VERSION}" |
| 71 | BINUTILS_DIR="binutils-${BINUTILS_VERSION}" |
| 72 | GDB_DIR="gdb-${GDB_VERSION}" |
Marc Jones | 2aac3f6 | 2011-08-08 16:07:50 -0600 | [diff] [blame] | 73 | IASL_DIR="acpica-unix-${IASL_VERSION}" |
Stefan Reinauer | 2c3cd12 | 2011-11-01 21:43:50 +0100 | [diff] [blame] | 74 | PYTHON_DIR="Python-${PYTHON_VERSION}" |
| 75 | EXPAT_DIR="expat-${EXPAT_VERSION}" |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 76 | # CLANG toolchain directories |
| 77 | LLVM_DIR="llvm-${CLANG_VERSION}.src" |
| 78 | CFE_DIR="cfe-${CLANG_VERSION}.src" |
| 79 | CRT_DIR="compiler-rt-${CLANG_VERSION}.src" |
| 80 | CTE_DIR="clang-tools-extra-${CLANG_VERSION}.src" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 81 | |
Patrick Georgi | 6321f52 | 2015-02-27 23:36:26 +0100 | [diff] [blame] | 82 | unset MAKELEVEL MAKEFLAGS |
| 83 | |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 84 | SAVETEMPS=0 |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 85 | BUILDCLANG=0 |
Stefan Reinauer | 2c3cd12 | 2011-11-01 21:43:50 +0100 | [diff] [blame] | 86 | SKIPGDB=1 |
| 87 | SKIPPYTHON=1 |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 88 | |
Patrick Georgi | 1861ff7 | 2011-10-31 12:15:55 +0100 | [diff] [blame] | 89 | red='\033[0;31m' |
| 90 | RED='\033[1;31m' |
| 91 | green='\033[0;32m' |
| 92 | GREEN='\033[1;32m' |
| 93 | blue='\033[0;34m' |
| 94 | BLUE='\033[1;34m' |
| 95 | cyan='\033[0;36m' |
| 96 | CYAN='\033[1;36m' |
| 97 | NC='\033[0m' # No Color |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 98 | |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 99 | UNAME=$(uname) |
Stefan Reinauer | 0d2119d | 2013-07-10 14:27:56 -0700 | [diff] [blame] | 100 | |
Patrick Georgi | 198d23c | 2012-12-08 08:02:44 +0100 | [diff] [blame] | 101 | normalize_dirs() |
| 102 | { |
| 103 | mkdir -p $DESTDIR$TARGETDIR/lib |
| 104 | test -d $DESTDIR$TARGETDIR/lib32 && mv $DESTDIR$TARGETDIR/lib32/* $DESTDIR$TARGETDIR/lib |
| 105 | test -d $DESTDIR$TARGETDIR/lib64 && mv $DESTDIR$TARGETDIR/lib64/* $DESTDIR$TARGETDIR/lib |
| 106 | rmdir -p $DESTDIR$TARGETDIR/lib32 $DESTDIR$TARGETDIR/lib64 |
| 107 | |
| 108 | perl -pi -e "s,/lib32,/lib," $DESTDIR$TARGETDIR/lib/*.la |
| 109 | perl -pi -e "s,/lib64,/lib," $DESTDIR$TARGETDIR/lib/*.la |
| 110 | } |
| 111 | |
Patrick Georgi | b706288 | 2015-02-24 10:52:14 +0100 | [diff] [blame] | 112 | searchtool() |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 113 | { |
| 114 | # $1 short name |
Patrick Georgi | b706288 | 2015-02-24 10:52:14 +0100 | [diff] [blame] | 115 | # $2 search string |
| 116 | # $3 soft fail if set |
| 117 | # result: file name of that tool on stdout |
| 118 | # or no output if nothing suitable was found |
| 119 | search=GNU |
| 120 | if [ -n "$2" ]; then |
| 121 | search="$2" |
| 122 | fi |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 123 | for i in "$1" "g$1" "gnu$1"; do |
Stefan Reinauer | dbc0087 | 2015-06-09 11:50:05 -0700 | [diff] [blame] | 124 | if [ -x "$(which $i 2>/dev/null)" ]; then |
| 125 | if [ "$(cat /dev/null | $i --version 2>&1 | grep -c "$search")" \ |
| 126 | -gt 0 ]; then |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 127 | echo $i |
| 128 | return |
| 129 | fi |
| 130 | fi |
| 131 | done |
Andrew Wu | b67e9a1 | 2014-04-28 18:13:44 +0800 | [diff] [blame] | 132 | # A workaround for OSX 10.9 and some BSDs, whose nongnu |
| 133 | # patch and tar also work. |
Patrick Georgi | 7cb26b4 | 2015-04-28 21:29:22 +0200 | [diff] [blame] | 134 | 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] | 135 | if [ "$1" = "patch" -o "$1" = "tar" ]; then |
Stefan Reinauer | dbc0087 | 2015-06-09 11:50:05 -0700 | [diff] [blame] | 136 | if [ -x "$(which $1 2>/dev/null)" ]; then |
Zheng Bao | 36156ff | 2012-09-28 16:18:58 +0800 | [diff] [blame] | 137 | echo $1 |
| 138 | return |
| 139 | fi |
| 140 | fi |
| 141 | fi |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 142 | if [ "$(echo $1 | cut -b -3)" = "sha" ]; then |
zbao | 939dc84 | 2015-04-30 04:44:07 +0800 | [diff] [blame] | 143 | if [ $UNAME = "FreeBSD" ]; then |
Stefan Reinauer | dbc0087 | 2015-06-09 11:50:05 -0700 | [diff] [blame] | 144 | if [ -x "$(which sha1 2>/dev/null)" ]; then |
zbao | 939dc84 | 2015-04-30 04:44:07 +0800 | [diff] [blame] | 145 | echo sha1 |
| 146 | return |
| 147 | fi |
| 148 | fi |
| 149 | if [ $UNAME = "NetBSD" ]; then |
Stefan Reinauer | dbc0087 | 2015-06-09 11:50:05 -0700 | [diff] [blame] | 150 | if [ -x "$(which cksum 2>/dev/null)" ]; then |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 151 | echo cksum -a $(echo $1 | sed -e 's,sum,,') |
zbao | 939dc84 | 2015-04-30 04:44:07 +0800 | [diff] [blame] | 152 | return |
| 153 | fi |
| 154 | fi |
| 155 | if [ $UNAME = "Darwin" ]; then |
Stefan Reinauer | dbc0087 | 2015-06-09 11:50:05 -0700 | [diff] [blame] | 156 | if [ -x "$(which openssl 2>/dev/null)" ]; then |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 157 | echo openssl $(echo $1 | sed -e 's,sum,,') |
zbao | 939dc84 | 2015-04-30 04:44:07 +0800 | [diff] [blame] | 158 | return |
| 159 | fi |
| 160 | fi |
| 161 | fi |
Patrick Georgi | ae5ab60 | 2015-04-29 23:30:15 +0200 | [diff] [blame] | 162 | printf "${RED}ERROR:${red} Missing tool: Please install $1 (eg using your OS packaging system)${NC}\n" >&2 |
Patrick Georgi | b706288 | 2015-02-24 10:52:14 +0100 | [diff] [blame] | 163 | [ -z "$3" ] && exit 1 |
| 164 | false |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 167 | TAR=$(searchtool tar) || exit $? |
| 168 | PATCH=$(searchtool patch) || exit $? |
| 169 | MAKE=$(searchtool make) || exit $? |
| 170 | CMAKE=$(searchtool cmake "cmake") || exit $? |
| 171 | SHA1SUM=$(searchtool sha1sum) |
| 172 | SHA512SUM=$(searchtool sha512sum) |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 173 | CHECKSUM=$SHA1SUM |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 174 | |
Patrick Georgi | b706288 | 2015-02-24 10:52:14 +0100 | [diff] [blame] | 175 | searchtool m4 > /dev/null |
| 176 | searchtool bison > /dev/null |
| 177 | searchtool flex flex > /dev/null |
| 178 | searchtool g++ "Free Software Foundation" nofail > /dev/null || \ |
Patrick Georgi | 915c4fc | 2015-03-09 13:58:23 +0100 | [diff] [blame] | 179 | searchtool clang "clang version" > /dev/null |
| 180 | searchtool wget > /dev/null |
| 181 | searchtool bzip2 "bzip2," > /dev/null |
Patrick Georgi | 5fb2b5c | 2012-05-12 23:25:23 +0200 | [diff] [blame] | 182 | |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 183 | download() { |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 184 | package=$1 |
| 185 | archive="$(eval echo \$$package"_ARCHIVE")" |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 186 | |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 187 | FILE=$(basename $archive) |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 188 | printf " * $FILE " |
| 189 | |
| 190 | test -f tarballs/$FILE && \ |
Stefan Reinauer | dbc0087 | 2015-06-09 11:50:05 -0700 | [diff] [blame] | 191 | ( test -z "$CHECKSUM" || \ |
| 192 | test "$(cat sum/$FILE.cksum 2>/dev/null | \ |
| 193 | sed -e 's,.*\([0-9a-f]\{40\}\).*,\1,')" = \ |
| 194 | "$($CHECKSUM tarballs/$FILE 2>/dev/null | \ |
| 195 | sed -e 's,.*\([0-9a-f]\{40\}\).*,\1,')" ) && \ |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 196 | printf "(cached)" || ( |
| 197 | printf "(downloading)" |
| 198 | rm -f tarballs/$FILE |
| 199 | cd tarballs |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 200 | wget --no-check-certificate -q $archive |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 201 | cd .. |
| 202 | test ! -f sum/$FILE.cksum && test -f tarballs/$FILE && \ |
| 203 | (test -z "$CHECKSUM" || $CHECKSUM tarballs/$FILE > sum/$FILE.cksum ) && \ |
| 204 | printf "(checksum created. ${RED}Note. Please upload sum/$FILE.cksum if the corresponding archive is upgraded.${NC})" |
| 205 | ) |
Stefan Reinauer | dbc0087 | 2015-06-09 11:50:05 -0700 | [diff] [blame] | 206 | if [ ! -f tarballs/$FILE ]; then |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 207 | printf "\n${RED}Failed to download $FILE.${NC}\n" |
Stefan Reinauer | dbc0087 | 2015-06-09 11:50:05 -0700 | [diff] [blame] | 208 | exit 1 |
| 209 | fi |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 210 | printf "\n" |
| 211 | } |
| 212 | |
| 213 | unpack_and_patch() { |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 214 | package=$1 |
| 215 | archive="$(eval echo \$$package"_ARCHIVE")" |
| 216 | dir="$(eval echo \$$package"_DIR")" |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 217 | test -d ${dir} && test -f ${dir}/.unpack_success || ( |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 218 | printf " * $(basename $archive)\n" |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 219 | FLAGS=zxf |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 220 | suffix=$(echo $archive | sed 's,.*\.,,') |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 221 | test "$suffix" = "gz" && FLAGS=zxf |
| 222 | test "$suffix" = "bz2" && FLAGS=jxf |
| 223 | test "$suffix" = "xz" && FLAGS="--xz -xf" |
| 224 | test "$suffix" = "lzma" && FLAGS="--lzma -xf" |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 225 | $TAR $FLAGS tarballs/$(basename $archive) |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 226 | for patch in patches/${dir}_*.patch; do |
| 227 | test -r $patch || continue |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 228 | printf " o $(basename $patch)\n" |
Stefan Reinauer | 916b845 | 2015-06-09 11:54:49 -0700 | [diff] [blame] | 229 | $PATCH -s -N -p0 < $(echo $patch) || { |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 230 | printf "\n${RED}Failed $patch.${NC}\n" |
Stefan Reinauer | 916b845 | 2015-06-09 11:54:49 -0700 | [diff] [blame] | 231 | exit 1 |
| 232 | } |
Stefan Reinauer | 8893548 | 2015-06-05 09:51:10 -0700 | [diff] [blame] | 233 | done |
| 234 | touch ${dir}/.unpack_success |
| 235 | ) |
| 236 | } |
| 237 | |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 238 | fn_exists() |
| 239 | { |
| 240 | type $1 2>/dev/null | grep -q 'is a function' |
Patrick Georgi | 74c0642 | 2015-03-25 18:40:13 +0100 | [diff] [blame] | 241 | } |
| 242 | |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 243 | build() { |
| 244 | package=$1 |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 245 | |
| 246 | fn_exists build_$package || return |
| 247 | |
Stefan Reinauer | 05bbc920 | 2015-06-09 12:21:42 -0700 | [diff] [blame] | 248 | version="$(eval echo \$$package"_VERSION")" |
| 249 | BUILDDIR=build-${TARGETARCH}-$package |
| 250 | |
| 251 | mkdir -p ${BUILDDIR} |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 252 | |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 253 | [[ "$PACKAGES" == *$package* ]] && \ |
Stefan Reinauer | 05bbc920 | 2015-06-09 12:21:42 -0700 | [diff] [blame] | 254 | if [ -f ${BUILDDIR}/.success ]; then |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 255 | printf "Skipping $package as it is already built\n" |
| 256 | else |
| 257 | printf "Building $package $version ... " |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 258 | DIR=$PWD |
Stefan Reinauer | 05bbc920 | 2015-06-09 12:21:42 -0700 | [diff] [blame] | 259 | cd ${BUILDDIR} |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 260 | rm -f .failed |
| 261 | build_${package} > build.log 2>&1 |
Stefan Reinauer | 05bbc920 | 2015-06-09 12:21:42 -0700 | [diff] [blame] | 262 | cd $DIR/${BUILDDIR} |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 263 | if [ ! -f .failed ]; then touch .success; fi |
| 264 | cd .. |
| 265 | |
Stefan Reinauer | 05bbc920 | 2015-06-09 12:21:42 -0700 | [diff] [blame] | 266 | if [ -r "${BUILDDIR}/.failed" ]; then |
| 267 | printf "${RED}failed${NC}. Check ${BUILDDIR}/build.log.\n" |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 268 | exit 1 |
| 269 | fi |
| 270 | printf "${green}ok${NC}\n" |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 271 | fi |
| 272 | } |
| 273 | |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 274 | cleanup() |
| 275 | { |
| 276 | printf "Cleaning up temporary files... " |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 277 | for package in $PACKAGES; do |
Stefan Reinauer | 05bbc920 | 2015-06-09 12:21:42 -0700 | [diff] [blame] | 278 | rm -rf build-${TARGETARCH}-$package $(eval echo \$$package"_DIR") |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 279 | done |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 280 | printf "${green}ok${NC}\n" |
| 281 | } |
| 282 | |
| 283 | myhelp() |
| 284 | { |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 285 | 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] | 286 | printf " $0 [-V|--version]\n" |
| 287 | printf " $0 [-h|--help]\n\n" |
| 288 | |
| 289 | printf "Options:\n" |
| 290 | printf " [-V|--version] print version number and exit\n" |
| 291 | printf " [-h|--help] print this help and exit\n" |
| 292 | printf " [-c|--clean] remove temporary files before build\n" |
| 293 | printf " [-t|--savetemps] don't remove temporary files after build\n" |
Patrick Georgi | c1a75b1 | 2011-11-04 21:37:14 +0100 | [diff] [blame] | 294 | printf " [-y|--ccache] Use ccache when building cross compiler\n" |
Patrick Georgi | 73166c7 | 2010-04-14 20:42:42 +0000 | [diff] [blame] | 295 | printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n" |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 296 | printf " [-C|--clang] build CLANG toolchain" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 297 | printf " [-p|--platform <platform>] target platform to build cross compiler for\n" |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 298 | printf " (defaults to $TARGETARCH) *)\n" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 299 | printf " [-d|--directory <target dir>] target directory to install cross compiler to\n" |
| 300 | printf " (defaults to $TARGETDIR)\n\n" |
| 301 | 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] | 302 | printf " (for RPM builds, default unset)\n" |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 303 | printf " [-G|--gdb] build GNU debugger *)\n" |
| 304 | printf " [-S|--scripting] build scripting support for GDB *)\n\n" |
| 305 | printf " *) option only available when building GCC toolchain (not with CLANG)\n\n" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | myversion() |
| 309 | { |
| 310 | # version tag is always printed, so just print the license here |
| 311 | |
| 312 | cat << EOF |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 313 | Copyright (C) 2008-2010 by coresystems GmbH |
Marc Jones | 2aac3f6 | 2011-08-08 16:07:50 -0600 | [diff] [blame] | 314 | Copyright (C) 2011 by Sage Electronic Engineering |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 315 | |
| 316 | This program is free software; you can redistribute it and/or modify |
| 317 | it under the terms of the GNU General Public License as published by |
| 318 | the Free Software Foundation; version 2 of the License. |
| 319 | |
| 320 | This program is distributed in the hope that it will be useful, |
| 321 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 322 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 323 | GNU General Public License for more details. |
| 324 | |
| 325 | EOF |
| 326 | } |
| 327 | |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 328 | build_GMP() { |
| 329 | CC="$CC" CFLAGS="-Os" ../${GMP_DIR}/configure --disable-shared --enable-fat --prefix=$TARGETDIR $OPTIONS \ |
| 330 | || touch .failed |
| 331 | $MAKE $JOBS || touch .failed |
| 332 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 333 | |
| 334 | normalize_dirs |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 335 | |
| 336 | # Now set CFLAGS to match GMP CFLAGS but strip out -pedantic |
| 337 | # as GCC 4.6.x fails if it's there. |
| 338 | export HOSTCFLAGS=$(grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2 |\ |
| 339 | sed s,-pedantic,,) |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | build_MPFR() { |
| 343 | test $UNAME = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL" |
| 344 | CC="$CC" ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \ |
| 345 | --infodir=$TARGETDIR/info \ |
| 346 | --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \ |
| 347 | touch .failed |
| 348 | $MAKE $JOBS || touch .failed |
| 349 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 350 | |
| 351 | normalize_dirs |
| 352 | |
| 353 | # work around build problem of libgmp.la |
| 354 | if [ "$DESTDIR" != "" ]; then |
| 355 | perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la |
| 356 | fi |
| 357 | } |
| 358 | |
| 359 | build_MPC() { |
| 360 | CC="$CC" ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \ |
| 361 | --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \ |
| 362 | --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \ |
| 363 | touch .failed |
| 364 | $MAKE $JOBS || touch .failed |
| 365 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 366 | |
| 367 | normalize_dirs |
| 368 | } |
| 369 | |
| 370 | build_LIBELF() { |
| 371 | CC="$CC" CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no \ |
| 372 | ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \ |
| 373 | --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed |
| 374 | $MAKE $JOBS || touch .failed |
| 375 | $MAKE install prefix=$DESTDIR$TARGETDIR || touch .failed |
| 376 | |
| 377 | normalize_dirs |
| 378 | } |
| 379 | |
| 380 | build_BINUTILS() { |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 381 | # Now build binutils |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 382 | CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \ |
| 383 | --target=${TARGETARCH} --disable-werror --disable-nls \ |
| 384 | $USE_GOLD CFLAGS="$HOSTCFLAGS" || touch .failed |
| 385 | $MAKE $JOBS || touch .failed |
| 386 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 387 | } |
| 388 | |
| 389 | |
| 390 | build_GCC() { |
Stefan Reinauer | d0f8372 | 2015-06-09 11:52:28 -0700 | [diff] [blame] | 391 | # GCC does not honor HOSTCFLAGS at all. CFLAGS are used for |
| 392 | # both target and host object files. |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 393 | # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET |
| 394 | # but it does not seem to work properly. At least the host library |
| 395 | # libiberty is not compiled with CFLAGS_FOR_BUILD. |
| 396 | CC="$CC" CFLAGS_FOR_TARGET="-O2" CFLAGS="$HOSTCFLAGS" \ |
| 397 | CFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \ |
| 398 | --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \ |
| 399 | --target=${TARGETARCH} --disable-werror --disable-shared \ |
| 400 | --disable-libssp --disable-bootstrap --disable-nls \ |
| 401 | --disable-libquadmath --without-headers \ |
| 402 | $GCC_OPTIONS --enable-languages="c" $USE_GOLD \ |
| 403 | --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \ |
| 404 | --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \ |
| 405 | --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \ |
| 406 | || touch .failed |
| 407 | $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-gcc || touch .failed |
| 408 | $MAKE install-gcc DESTDIR=$DESTDIR || touch .failed |
| 409 | |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 410 | if [ "$(echo $TARGETARCH | grep -c -- -mingw32)" -eq 0 ]; then |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 411 | $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-target-libgcc || touch .failed |
| 412 | $MAKE install-target-libgcc DESTDIR=$DESTDIR || touch .failed |
| 413 | fi |
| 414 | } |
| 415 | |
| 416 | build_EXPAT() { |
| 417 | CC="$CC" CFLAGS="$HOSTCFLAGS" ../${EXPAT_DIR}/configure --disable-shared \ |
| 418 | --prefix=$TARGETDIR --target=${TARGETARCH} || touch .failed |
| 419 | $MAKE || touch .failed |
| 420 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 421 | |
| 422 | normalize_dirs |
| 423 | } |
| 424 | |
| 425 | build_PYTHON() { |
| 426 | CC="$CC" CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$TARGETDIR \ |
| 427 | --target=${TARGETARCH} || touch .failed |
| 428 | $MAKE $JOBS || touch .failed |
| 429 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 430 | |
| 431 | normalize_dirs |
| 432 | } |
| 433 | |
| 434 | build_GDB() { |
| 435 | export PYTHONHOME=$DESTDIR$TARGETDIR |
| 436 | if [ $(uname) != "FreeBSD" -a $(uname) != "NetBSD" ]; then |
| 437 | LIBDL="-ldl" |
| 438 | fi |
| 439 | LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \ |
| 440 | -lpthread $LIBDL -lutil" \ |
| 441 | CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \ |
Stefan Reinauer | 7b40e42 | 2015-06-09 11:56:32 -0700 | [diff] [blame] | 442 | ../${GDB_DIR}/configure --prefix=$TARGETDIR \ |
Stefan Reinauer | e7757bd | 2015-06-05 13:59:44 -0700 | [diff] [blame] | 443 | --target=${TARGETARCH} --disable-werror --disable-nls |
| 444 | $MAKE $JOBS || touch .failed |
| 445 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 446 | } |
| 447 | |
| 448 | build_IASL() { |
| 449 | RDIR=$PWD |
| 450 | cd ../$IASL_DIR/generate/unix |
| 451 | CFLAGS="$HOSTCFLAGS" |
| 452 | HOST="_LINUX" |
| 453 | test $UNAME = "Darwin" && HOST="_APPLE" |
| 454 | test $UNAME = "FreeBSD" && HOST="_FreeBSD" |
| 455 | test $UNAME = "Cygwin" && HOST="_CYGWIN" |
| 456 | HOST="$HOST" OPT_CFLAGS="-O -D_FORTIFY_SOURCE=2" CFLAGS="$CFLAGS" $MAKE CC="$CC" iasl || touch $RDIR/.failed |
| 457 | rm -f $DESTDIR$TARGETDIR/bin/iasl || touch $RDIR/.failed |
| 458 | cp bin/iasl $DESTDIR$TARGETDIR/bin || touch $RDIR/.failed |
| 459 | } |
| 460 | |
| 461 | build_LLVM() { |
| 462 | cd .. |
| 463 | ln -sf $PWD/$CFE_DIR $LLVM_DIR/tools/clang |
| 464 | ln -sf $PWD/$CTE_DIR $LLVM_DIR/tools/clang/tools/extra |
| 465 | ln -sf $PWD/$CRT_DIR $LLVM_DIR/projects/compiler-rt |
| 466 | cd - |
| 467 | |
| 468 | $CMAKE -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=$DESTDIR$TARGETDIR \ |
| 469 | -DCMAKE_BUILD_TYPE=Release ../$LLVM_DIR || touch .failed |
| 470 | $MAKE $JOBS || touch .failed |
| 471 | $MAKE install || touch .failed |
| 472 | |
| 473 | cp -a ../$CFE_DIR/tools/scan-build/* $DESTDIR$TARGETDIR/bin |
| 474 | cp -a ../$CFE_DIR/tools/scan-view/* $DESTDIR$TARGETDIR/bin |
| 475 | } |
| 476 | |
Stefan Reinauer | 9491b4d | 2011-10-11 22:37:59 -0700 | [diff] [blame] | 477 | printf "${blue}Welcome to the ${red}coreboot${blue} cross toolchain builder v$CROSSGCC_VERSION ($CROSSGCC_DATE)${NC}\n\n" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 478 | |
Patrick Georgi | 6bba29f | 2010-01-29 17:40:52 +0000 | [diff] [blame] | 479 | # Look if we have getopt. If not, build it. |
| 480 | export PATH=$PATH:. |
| 481 | getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c |
| 482 | |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 483 | # parse parameters.. try to find out whether we're running GNU getopt |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 484 | getoptbrand="$(getopt -V | sed -e '1!d' -e 's,^\(......\).*,\1,')" |
Peter Stuge | 09377b7 | 2011-08-21 06:24:55 +0200 | [diff] [blame] | 485 | if [ "${getoptbrand}" = "getopt" ]; then |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 486 | # Detected GNU getopt that supports long options. |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 487 | args=$(getopt -l version,help,clean,directory:,platform:,jobs:,destdir:,savetemps,skip-gdb,ccache,clang Vhcd:p:j:D:tGyC -- "$@") |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 488 | eval set "$args" |
| 489 | else |
| 490 | # Detected non-GNU getopt |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 491 | args=$(getopt Vhcd:p:j:D:tGyC $*) |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 492 | set -- $args |
| 493 | fi |
| 494 | |
| 495 | if [ $? != 0 ]; then |
| 496 | myhelp |
| 497 | exit 1 |
| 498 | fi |
| 499 | |
| 500 | while true ; do |
| 501 | case "$1" in |
| 502 | -V|--version) shift; myversion; exit 0;; |
| 503 | -h|--help) shift; myhelp; exit 0;; |
Patrick Georgi | 44af57a | 2013-12-19 22:06:22 +0100 | [diff] [blame] | 504 | -c|--clean) shift; clean=1;; |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 505 | -t|--savetemps) shift; SAVETEMPS=1;; |
| 506 | -d|--directory) shift; TARGETDIR="$1"; shift;; |
| 507 | -p|--platform) shift; TARGETARCH="$1"; shift;; |
| 508 | -D|--destdir) shift; DESTDIR="$1"; shift;; |
Patrick Georgi | 73166c7 | 2010-04-14 20:42:42 +0000 | [diff] [blame] | 509 | -j|--jobs) shift; JOBS="-j $1"; shift;; |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 510 | -C|--clang) shift; BUILDCLANG=1;; |
Stefan Reinauer | 2c3cd12 | 2011-11-01 21:43:50 +0100 | [diff] [blame] | 511 | -G|--gdb) shift; SKIPGDB=0;; |
| 512 | -S|--scripting) shift; SKIPPYTHON=0;; |
Patrick Georgi | c1a75b1 | 2011-11-04 21:37:14 +0100 | [diff] [blame] | 513 | -y|--ccache) shift; USECCACHE=1;; |
Patrick Georgi | d2e0dd5 | 2013-06-09 08:05:45 +0200 | [diff] [blame] | 514 | --) shift; break;; |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 515 | -*) printf "Invalid option\n\n"; myhelp; exit 1;; |
Patrick Georgi | d2e0dd5 | 2013-06-09 08:05:45 +0200 | [diff] [blame] | 516 | *) break;; |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 517 | esac |
| 518 | done |
| 519 | |
Ronald G. Minnich | b460a66 | 2013-05-26 05:33:35 -0700 | [diff] [blame] | 520 | case "$TARGETARCH" in |
Stefan Reinauer | 24f9cb9 | 2015-03-13 22:50:22 +0100 | [diff] [blame] | 521 | x86_64-elf) ;; |
| 522 | x86_64*) TARGETARCH=x86_64-elf;; |
David Hubbard | 5b0420a | 2013-05-28 16:33:15 -0600 | [diff] [blame] | 523 | i386-elf) ;; |
| 524 | i386-mingw32) ;; |
Patrick Georgi | 9b7efa5 | 2015-03-08 09:20:36 +0100 | [diff] [blame] | 525 | mipsel-elf) ;; |
Patrick Georgi | f0bbc95 | 2015-03-07 10:57:25 +0100 | [diff] [blame] | 526 | riscv-elf) ;; |
Ronald G. Minnich | b460a66 | 2013-05-26 05:33:35 -0700 | [diff] [blame] | 527 | i386*) TARGETARCH=i386-elf;; |
Patrick Georgi | c888326 | 2013-09-19 10:57:58 +0200 | [diff] [blame] | 528 | arm*) TARGETARCH=armv7-a-eabi;; |
Stefan Reinauer | 0d2119d | 2013-07-10 14:27:56 -0700 | [diff] [blame] | 529 | aarch64*) TARGETARCH=aarch64-elf;; |
| 530 | *) printf "${red}WARNING: Unsupported architecture $TARGETARCH.${NC}\n\n"; ;; |
Ronald G. Minnich | b460a66 | 2013-05-26 05:33:35 -0700 | [diff] [blame] | 531 | esac |
| 532 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 533 | # Figure out which packages to build |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 534 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 535 | if [ "$BUILDCLANG" -eq 0 ]; then |
| 536 | echo "Target architecture is now $TARGETARCH" |
| 537 | NAME="${TARGETARCH} cross" |
| 538 | PACKAGES="GMP MPFR MPC LIBELF BINUTILS GCC IASL" |
| 539 | else |
| 540 | NAME=clang |
| 541 | PACKAGES="LLVM CFE CRT CTE" |
Patrick Georgi | 44af57a | 2013-12-19 22:06:22 +0100 | [diff] [blame] | 542 | fi |
| 543 | |
Peter Stuge | ceacd77 | 2011-06-09 04:54:16 +0200 | [diff] [blame] | 544 | if [ $SKIPGDB -eq 1 ]; then |
| 545 | printf "Will skip GDB ... ${green}ok${NC}\n" |
Stefan Reinauer | 2c3cd12 | 2011-11-01 21:43:50 +0100 | [diff] [blame] | 546 | if [ $SKIPPYTHON -eq 0 ]; then |
| 547 | printf "Python scripting needs GDB ... disabling ... ${green}ok${NC}\n" |
| 548 | SKIPPYTHON=1 |
| 549 | fi |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 550 | else |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 551 | if [ $SKIPPYTHON -eq 0 ]; then |
| 552 | PACKAGES="$PACKAGES EXPAT PYTHON" |
| 553 | fi |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 554 | PACKAGES="$PACKAGES GDB" |
Stefan Reinauer | 2c3cd12 | 2011-11-01 21:43:50 +0100 | [diff] [blame] | 555 | fi |
Peter Stuge | ceacd77 | 2011-06-09 04:54:16 +0200 | [diff] [blame] | 556 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 557 | # This initial cleanup is useful when updating the toolchain script. |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 558 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 559 | if [ "$clean" = "1" ]; then |
| 560 | cleanup |
| 561 | fi |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 562 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 563 | # Set up host compiler and flags needed for various OSes |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 564 | |
Stefan Reinauer | 9491b4d | 2011-10-11 22:37:59 -0700 | [diff] [blame] | 565 | CC=cc |
Stefan Reinauer | 429424f | 2015-06-09 13:45:46 -0700 | [diff] [blame] | 566 | if [[ "$PACKAGES" == *GCC* ]]; then |
Stefan Reinauer | 0d2119d | 2013-07-10 14:27:56 -0700 | [diff] [blame] | 567 | if [ $UNAME = "Darwin" ]; then |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 568 | #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix" |
| 569 | |
| 570 | # generally the OS X compiler can create x64 binaries. |
| 571 | # Per default it generated i386 binaries in 10.5 and x64 |
| 572 | # binaries in 10.6 (even if the kernel is 32bit) |
| 573 | # For some weird reason, 10.5 autodetects an ABI=64 though |
| 574 | # so we're setting the ABI explicitly here. |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 575 | 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] | 576 | OPTIONS="ABI=64" |
| 577 | else |
| 578 | OPTIONS="ABI=32" |
| 579 | fi |
Stefan Reinauer | 9491b4d | 2011-10-11 22:37:59 -0700 | [diff] [blame] | 580 | |
Stefan Reinauer | 4266b92 | 2012-12-05 16:18:32 -0800 | [diff] [blame] | 581 | # In Xcode 4.5.2 the default compiler is clang. |
| 582 | # However, this compiler fails to compile gcc 4.7.x. As a |
| 583 | # workaround it's possible to compile gcc with llvm-gcc. |
Stefan Reinauer | 9491b4d | 2011-10-11 22:37:59 -0700 | [diff] [blame] | 584 | if $CC -v 2>&1 | grep -q LLVM; then |
Stefan Reinauer | 4266b92 | 2012-12-05 16:18:32 -0800 | [diff] [blame] | 585 | CC=llvm-gcc |
Stefan Reinauer | 9491b4d | 2011-10-11 22:37:59 -0700 | [diff] [blame] | 586 | fi |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 587 | fi |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 588 | fi # GCC |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 589 | |
Patrick Georgi | c1a75b1 | 2011-11-04 21:37:14 +0100 | [diff] [blame] | 590 | if [ "$USECCACHE" = 1 ]; then |
| 591 | CC="ccache $CC" |
| 592 | fi |
| 593 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 594 | # coreboot does not like the GOLD linker |
| 595 | # USE_GOLD="--enable-gold" |
| 596 | USE_GOLD="" |
| 597 | GCC_OPTIONS="--enable-lto" |
| 598 | |
| 599 | # Prepare target directory for building GCC |
| 600 | # (dependencies must be in the PATH) |
Stefan Reinauer | 16bd789 | 2012-12-07 23:57:01 +0100 | [diff] [blame] | 601 | mkdir -p $DESTDIR$TARGETDIR/bin |
| 602 | export PATH=$DESTDIR$TARGETDIR/bin:$PATH |
| 603 | |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 604 | # Download, unpack, patch and build all packages |
| 605 | |
| 606 | printf "Downloading tar balls ... \n" |
| 607 | mkdir -p tarballs |
| 608 | for P in $PACKAGES; do |
| 609 | download $P |
| 610 | done |
| 611 | printf "Downloaded tar balls ... ${green}ok${NC}\n" |
| 612 | |
| 613 | printf "Unpacking and patching ... \n" |
| 614 | for P in $PACKAGES; do |
| 615 | unpack_and_patch $P || exit 1 |
| 616 | done |
| 617 | printf "Unpacked and patched ... ${green}ok${NC}\n" |
| 618 | |
| 619 | printf "Building packages ... \n" |
Stefan Reinauer | 1c70e05 | 2015-06-09 11:47:28 -0700 | [diff] [blame] | 620 | for package in $PACKAGES; do |
| 621 | build $package |
| 622 | done |
Stefan Reinauer | 5dd2635 | 2015-06-09 14:52:22 -0700 | [diff] [blame] | 623 | printf "Packages built ... ${green}ok${NC}\n" |
Stefan Reinauer | 14ce213 | 2015-06-05 13:01:13 -0700 | [diff] [blame] | 624 | |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 625 | # Adding git information of current tree to target directory |
| 626 | # for reproducibility |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 627 | PROGNAME=$(basename "$0") |
Patrick Georgi | 5602f2c | 2015-03-28 15:48:47 +0100 | [diff] [blame] | 628 | rm -f "$DESTDIR$TARGETDIR/$PROGNAME".commit.* |
Stefan Reinauer | d764912 | 2015-06-09 11:44:25 -0700 | [diff] [blame] | 629 | cp "$PROGNAME" $DESTDIR$TARGETDIR/"$PROGNAME.commit.$(git describe)" |
Zheng Bao | 30b895f | 2013-02-06 18:04:40 +0800 | [diff] [blame] | 630 | |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 631 | if [ $SAVETEMPS -eq 0 ]; then |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 632 | cleanup |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 633 | else |
| 634 | printf "Leaving temporary files around... ${green}ok${NC}\n" |
| 635 | fi |
| 636 | |
Stefan Reinauer | 699ac27 | 2015-06-05 12:43:28 -0700 | [diff] [blame] | 637 | printf "\n${green}You can now run your $NAME toolchain from $TARGETDIR.${NC}\n" |