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