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