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