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