blob: ceb1d1d4f1cbaa3c5c590acd88ffa198227dbf00 [file] [log] [blame]
Peter Stuge09377b72011-08-21 06:24:55 +02001#!/bin/sh
Stefan Reinauer074d9132009-09-26 16:43:17 +00002#
Stefan Reinauer5f1ad892010-05-17 11:02:25 +00003# Copyright (C) 2008-2010 by coresystems GmbH
Stefan Reinauer074d9132009-09-26 16:43:17 +00004# written by Patrick Georgi <patrick.georgi@coresystems.de> and
5# Stefan Reinauer <stefan.reinauer@coresystems.de>
Stefan Reinauer14e22772010-04-27 06:56:47 +00006#
Marc Jones2aac3f62011-08-08 16:07:50 -06007# Copyright (C) 2011 by Sage Electronic Engineering
8#
Stefan Reinauer074d9132009-09-26 16:43:17 +00009# 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
Paul Menzela46a7122013-02-23 18:37:27 +010020# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
Stefan Reinauer074d9132009-09-26 16:43:17 +000021#
22
Patrick Georgi53c388f2015-03-07 09:55:18 +010023CROSSGCC_DATE="March 8th, 2015"
24CROSSGCC_VERSION="1.27"
Stefan Reinauer074d9132009-09-26 16:43:17 +000025
26# default settings
27TARGETDIR=`pwd`/xgcc
28TARGETARCH=i386-elf
29DESTDIR=
30
31# version numbers
Patrick Georgi53c388f2015-03-07 09:55:18 +010032GMP_VERSION=6.0.0
Stefan Reinauer0d2119d2013-07-10 14:27:56 -070033MPFR_VERSION=3.1.2
Paul Menzele6619422015-02-23 10:33:59 +010034MPC_VERSION=1.0.3
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000035LIBELF_VERSION=0.8.13
Patrick Georgi53c388f2015-03-07 09:55:18 +010036GCC_VERSION=4.9.2
Stefan Reinauer0d2119d2013-07-10 14:27:56 -070037GCC_AUTOCONF_VERSION=2.69
Patrick Georgi53c388f2015-03-07 09:55:18 +010038BINUTILS_VERSION=2.25
39GDB_VERSION=7.9
40IASL_VERSION=20150204
41PYTHON_VERSION=3.4.3
Idwer Vollering296a0152012-10-26 01:48:04 +020042EXPAT_VERSION=2.1.0
Stefan Reinauer074d9132009-09-26 16:43:17 +000043
44# archive locations
Patrick Georgi53c388f2015-03-07 09:55:18 +010045GMP_ARCHIVE="http://ftpmirror.gnu.org/gmp/gmp-${GMP_VERSION}a.tar.bz2"
Patrick Georgi6e61ad32012-05-12 23:19:30 +020046MPFR_ARCHIVE="http://ftpmirror.gnu.org/mpfr/mpfr-${MPFR_VERSION}.tar.bz2"
Idwer Vollering7962fc72012-10-25 02:14:09 +020047MPC_ARCHIVE="http://ftpmirror.gnu.org/mpc/mpc-${MPC_VERSION}.tar.gz"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000048LIBELF_ARCHIVE="http://www.mr511.de/software/libelf-${LIBELF_VERSION}.tar.gz"
Idwer Vollering1cfee0b2012-10-25 02:03:53 +020049GCC_ARCHIVE="http://ftpmirror.gnu.org/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.bz2"
Stefan Reinauer0d2119d2013-07-10 14:27:56 -070050BINUTILS_ARCHIVE="http://ftpmirror.gnu.org/binutils/binutils-${BINUTILS_VERSION}.tar.bz2"
Patrick Georgi53c388f2015-03-07 09:55:18 +010051GDB_ARCHIVE="http://ftpmirror.gnu.org/gdb/gdb-${GDB_VERSION}.tar.xz"
52IASL_ARCHIVE="https://acpica.org/sites/acpica/files/acpica-unix-${IASL_VERSION}.tar.gz"
53PYTHON_ARCHIVE="http://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010054EXPAT_ARCHIVE="http://downloads.sourceforge.net/sourceforge/expat/expat-${EXPAT_VERSION}.tar.gz"
Stefan Reinauer074d9132009-09-26 16:43:17 +000055
56GMP_DIR="gmp-${GMP_VERSION}"
57MPFR_DIR="mpfr-${MPFR_VERSION}"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000058MPC_DIR="mpc-${MPC_VERSION}"
59LIBELF_DIR="libelf-${LIBELF_VERSION}"
Stefan Reinauer074d9132009-09-26 16:43:17 +000060GCC_DIR="gcc-${GCC_VERSION}"
61BINUTILS_DIR="binutils-${BINUTILS_VERSION}"
62GDB_DIR="gdb-${GDB_VERSION}"
Marc Jones2aac3f62011-08-08 16:07:50 -060063IASL_DIR="acpica-unix-${IASL_VERSION}"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010064PYTHON_DIR="Python-${PYTHON_VERSION}"
65EXPAT_DIR="expat-${EXPAT_VERSION}"
Stefan Reinauer074d9132009-09-26 16:43:17 +000066
Patrick Georgi6321f522015-02-27 23:36:26 +010067unset MAKELEVEL MAKEFLAGS
68
Stefan Reinauer074d9132009-09-26 16:43:17 +000069SAVETEMPS=0
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010070SKIPGDB=1
71SKIPPYTHON=1
Stefan Reinauer074d9132009-09-26 16:43:17 +000072
Patrick Georgi1861ff72011-10-31 12:15:55 +010073red='\033[0;31m'
74RED='\033[1;31m'
75green='\033[0;32m'
76GREEN='\033[1;32m'
77blue='\033[0;34m'
78BLUE='\033[1;34m'
79cyan='\033[0;36m'
80CYAN='\033[1;36m'
81NC='\033[0m' # No Color
Stefan Reinauer074d9132009-09-26 16:43:17 +000082
Stefan Reinauer0d2119d2013-07-10 14:27:56 -070083UNAME=`uname`
84
Patrick Georgi198d23c2012-12-08 08:02:44 +010085normalize_dirs()
86{
87 mkdir -p $DESTDIR$TARGETDIR/lib
88 test -d $DESTDIR$TARGETDIR/lib32 && mv $DESTDIR$TARGETDIR/lib32/* $DESTDIR$TARGETDIR/lib
89 test -d $DESTDIR$TARGETDIR/lib64 && mv $DESTDIR$TARGETDIR/lib64/* $DESTDIR$TARGETDIR/lib
90 rmdir -p $DESTDIR$TARGETDIR/lib32 $DESTDIR$TARGETDIR/lib64
91
92 perl -pi -e "s,/lib32,/lib," $DESTDIR$TARGETDIR/lib/*.la
93 perl -pi -e "s,/lib64,/lib," $DESTDIR$TARGETDIR/lib/*.la
94}
95
Patrick Georgib7062882015-02-24 10:52:14 +010096searchtool()
Stefan Reinauer074d9132009-09-26 16:43:17 +000097{
98 # $1 short name
Patrick Georgib7062882015-02-24 10:52:14 +010099 # $2 search string
100 # $3 soft fail if set
101 # result: file name of that tool on stdout
102 # or no output if nothing suitable was found
103 search=GNU
104 if [ -n "$2" ]; then
105 search="$2"
106 fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000107 for i in "$1" "g$1" "gnu$1"; do
108 if test -x "`which $i 2>/dev/null`"; then
Patrick Georgib7062882015-02-24 10:52:14 +0100109 if test `$i --version 2>/dev/null |grep -c "$search"` \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100110 -gt 0; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000111 echo $i
112 return
113 fi
114 fi
115 done
Andrew Wub67e9a12014-04-28 18:13:44 +0800116 # A workaround for OSX 10.9 and some BSDs, whose nongnu
117 # patch and tar also work.
118 if [ $UNAME = "Darwin" -o $UNAME = "FreeBSD" -o $UNAME = "NetBSD" ]; then
Patrick Georgib7062882015-02-24 10:52:14 +0100119 if [ "$1" = "patch" -o "$1" = "tar" ]; then
Zheng Bao36156ff2012-09-28 16:18:58 +0800120 if test -x "`which $1 2>/dev/null`"; then
121 echo $1
122 return
123 fi
124 fi
125 fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000126 printf "${RED}ERROR:${red} Missing toolchain: $1${NC}\n" >&2
Patrick Georgib7062882015-02-24 10:52:14 +0100127 [ -z "$3" ] && exit 1
128 false
Stefan Reinauer074d9132009-09-26 16:43:17 +0000129}
130
Patrick Georgib7062882015-02-24 10:52:14 +0100131TAR=`searchtool tar` || exit $?
132PATCH=`searchtool patch` || exit $?
133MAKE=`searchtool make` || exit $?
Stefan Reinauer074d9132009-09-26 16:43:17 +0000134
Patrick Georgib7062882015-02-24 10:52:14 +0100135searchtool m4 > /dev/null
136searchtool bison > /dev/null
137searchtool flex flex > /dev/null
138searchtool g++ "Free Software Foundation" nofail > /dev/null || \
139searchtool clang "clang version"
Patrick Georgi5fb2b5c2012-05-12 23:25:23 +0200140
Stefan Reinauer074d9132009-09-26 16:43:17 +0000141cleanup()
142{
143 printf "Cleaning up temporary files... "
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200144 rm -rf ${BUILDDIRPREFIX}-* combined gcc-* gmp-* mpfr-* mpc-* libelf-* binutils-*
Patrick Georgi969cd932012-12-07 13:13:53 +0100145 rm -rf gdb-* acpica-* python-* expat-*
Stefan Reinauer074d9132009-09-26 16:43:17 +0000146 printf "${green}ok${NC}\n"
147}
148
149myhelp()
150{
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100151 printf "Usage: $0 [-V] [-c] [-p <platform>] [-d <target directory>] [-D <dest dir>] [-G] [-S]\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000152 printf " $0 [-V|--version]\n"
153 printf " $0 [-h|--help]\n\n"
154
155 printf "Options:\n"
156 printf " [-V|--version] print version number and exit\n"
157 printf " [-h|--help] print this help and exit\n"
158 printf " [-c|--clean] remove temporary files before build\n"
159 printf " [-t|--savetemps] don't remove temporary files after build\n"
Patrick Georgic1a75b12011-11-04 21:37:14 +0100160 printf " [-y|--ccache] Use ccache when building cross compiler\n"
Patrick Georgi73166c72010-04-14 20:42:42 +0000161 printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000162 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
163 printf " (defaults to $TARGETARCH)\n"
164 printf " [-d|--directory <target dir>] target directory to install cross compiler to\n"
165 printf " (defaults to $TARGETDIR)\n\n"
166 printf " [-D|--destdir <dest dir>] destination directory to install cross compiler to\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100167 printf " (for RPM builds, default unset)\n"
168 printf " [-G|--gdb] build GNU debugger\n"
169 printf " [-S|--scripting] build scripting support for GDB\n\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000170}
171
172myversion()
173{
174 # version tag is always printed, so just print the license here
175
176 cat << EOF
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000177Copyright (C) 2008-2010 by coresystems GmbH
Marc Jones2aac3f62011-08-08 16:07:50 -0600178Copyright (C) 2011 by Sage Electronic Engineering
Stefan Reinauer074d9132009-09-26 16:43:17 +0000179
180This program is free software; you can redistribute it and/or modify
181it under the terms of the GNU General Public License as published by
182the Free Software Foundation; version 2 of the License.
183
184This program is distributed in the hope that it will be useful,
185but WITHOUT ANY WARRANTY; without even the implied warranty of
186MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
187GNU General Public License for more details.
188
189EOF
190}
191
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700192printf "${blue}Welcome to the ${red}coreboot${blue} cross toolchain builder v$CROSSGCC_VERSION ($CROSSGCC_DATE)${NC}\n\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000193
Patrick Georgi6bba29f2010-01-29 17:40:52 +0000194# Look if we have getopt. If not, build it.
195export PATH=$PATH:.
196getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c
197
Stefan Reinauer074d9132009-09-26 16:43:17 +0000198# parse parameters.. try to find out whether we're running GNU getopt
Peter Stuge09377b72011-08-21 06:24:55 +0200199getoptbrand="`getopt -V | sed -e '1!d' -e 's,^\(......\).*,\1,'`"
200if [ "${getoptbrand}" = "getopt" ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000201 # Detected GNU getopt that supports long options.
Patrick Georgic1a75b12011-11-04 21:37:14 +0100202 args=`getopt -l version,help,clean,directory:,platform:,jobs:,destdir:,savetemps,skip-gdb,ccache Vhcd:p:j:D:tGy -- "$@"`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000203 eval set "$args"
204else
205 # Detected non-GNU getopt
Patrick Georgic1a75b12011-11-04 21:37:14 +0100206 args=`getopt Vhcd:p:j:D:tGy $*`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000207 set -- $args
208fi
209
210if [ $? != 0 ]; then
211 myhelp
212 exit 1
213fi
214
215while true ; do
216 case "$1" in
217 -V|--version) shift; myversion; exit 0;;
218 -h|--help) shift; myhelp; exit 0;;
Patrick Georgi44af57a2013-12-19 22:06:22 +0100219 -c|--clean) shift; clean=1;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000220 -t|--savetemps) shift; SAVETEMPS=1;;
221 -d|--directory) shift; TARGETDIR="$1"; shift;;
222 -p|--platform) shift; TARGETARCH="$1"; shift;;
223 -D|--destdir) shift; DESTDIR="$1"; shift;;
Patrick Georgi73166c72010-04-14 20:42:42 +0000224 -j|--jobs) shift; JOBS="-j $1"; shift;;
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100225 -G|--gdb) shift; SKIPGDB=0;;
226 -S|--scripting) shift; SKIPPYTHON=0;;
Patrick Georgic1a75b12011-11-04 21:37:14 +0100227 -y|--ccache) shift; USECCACHE=1;;
Patrick Georgid2e0dd52013-06-09 08:05:45 +0200228 --) shift; break;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000229 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
Patrick Georgid2e0dd52013-06-09 08:05:45 +0200230 *) break;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000231 esac
232done
233
Ronald G. Minnichb460a662013-05-26 05:33:35 -0700234case "$TARGETARCH" in
Stefan Reinauer24f9cb92015-03-13 22:50:22 +0100235 x86_64-elf) ;;
236 x86_64*) TARGETARCH=x86_64-elf;;
David Hubbard5b0420a2013-05-28 16:33:15 -0600237 i386-elf) ;;
238 i386-mingw32) ;;
Patrick Georgi9b7efa52015-03-08 09:20:36 +0100239 mipsel-elf) ;;
Patrick Georgif0bbc952015-03-07 10:57:25 +0100240 riscv-elf) ;;
Ronald G. Minnichb460a662013-05-26 05:33:35 -0700241 i386*) TARGETARCH=i386-elf;;
Patrick Georgic8883262013-09-19 10:57:58 +0200242 arm*) TARGETARCH=armv7-a-eabi;;
Stefan Reinauer0d2119d2013-07-10 14:27:56 -0700243 aarch64*) TARGETARCH=aarch64-elf;;
244 *) printf "${red}WARNING: Unsupported architecture $TARGETARCH.${NC}\n\n"; ;;
Ronald G. Minnichb460a662013-05-26 05:33:35 -0700245esac
246
247echo "Target arch is now $TARGETARCH"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200248BUILDDIRPREFIX=build-${TARGETARCH}
249
Patrick Georgi44af57a2013-12-19 22:06:22 +0100250if [ "$clean" = "1" ]; then
251 cleanup
252fi
253
Peter Stugeceacd772011-06-09 04:54:16 +0200254GDB_PACKAGE="GDB"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100255PYTHON_PACKAGE="PYTHON"
256EXPAT_PACKAGE="EXPAT"
Peter Stugeceacd772011-06-09 04:54:16 +0200257if [ $SKIPGDB -eq 1 ]; then
258 printf "Will skip GDB ... ${green}ok${NC}\n"
Peter Stuge0e8ee812011-08-28 11:04:23 +0200259 GDB_ARCHIVE=""
Peter Stugeceacd772011-06-09 04:54:16 +0200260 GDB_PACKAGE=""
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100261 if [ $SKIPPYTHON -eq 0 ]; then
262 printf "Python scripting needs GDB ... disabling ... ${green}ok${NC}\n"
263 SKIPPYTHON=1
264 fi
265fi
266if [ $SKIPPYTHON -eq 1 ]; then
Jonathan A. Kollasch2d7ab4c2011-11-07 13:05:18 -0600267 PYTHON_ARCHIVE=""
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100268 PYTHON_PACKAGE=""
Jonathan A. Kollasch2d7ab4c2011-11-07 13:05:18 -0600269 EXPAT_ARCHIVE=""
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100270 EXPAT_PACKAGE=""
Peter Stugeceacd772011-06-09 04:54:16 +0200271fi
272
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700273# coreboot does not like the GOLD linker
274# USE_GOLD="--enable-gold"
275USE_GOLD=""
276GCC_OPTIONS="--enable-lto"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000277
Stefan Reinauer074d9132009-09-26 16:43:17 +0000278printf "Downloading tar balls ... \n"
279mkdir -p tarballs
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100280for ARCHIVE in $GMP_ARCHIVE $MPFR_ARCHIVE $MPC_ARCHIVE $LIBELF_ARCHIVE \
Patrick Georgi969cd932012-12-07 13:13:53 +0100281 $GCC_ARCHIVE $BINUTILS_ARCHIVE $GDB_ARCHIVE \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100282 $IASL_ARCHIVE $PYTHON_ARCHIVE $EXPAT_ARCHIVE; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000283 FILE=`basename $ARCHIVE`
284 printf " * $FILE "
285 test -f tarballs/$FILE && printf "(cached)" || (
286 printf "(downloading)"
287 cd tarballs
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200288 wget --no-check-certificate -q $ARCHIVE
Stefan Reinauer074d9132009-09-26 16:43:17 +0000289 )
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100290 test -f tarballs/$FILE || \
Zheng Bao5b209c02012-09-20 16:09:51 +0800291 printf "\n${RED}Failed to download $FILE.${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000292 test -f tarballs/$FILE || exit 1
293 printf "\n"
294done
295printf "Downloaded tar balls ... "
296printf "${green}ok${NC}\n"
297
298printf "Unpacking and patching ... \n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100299for PACKAGE in GMP MPFR MPC LIBELF GCC BINUTILS $PYTHON_PACKAGE \
Patrick Georgi969cd932012-12-07 13:13:53 +0100300 $EXPAT_PACKAGE $GDB_PACKAGE IASL; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000301 archive=$PACKAGE"_ARCHIVE"
Peter Stuge09377b72011-08-21 06:24:55 +0200302 archive="`eval echo '$'$archive`"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000303 dir=$PACKAGE"_DIR"
Peter Stuge09377b72011-08-21 06:24:55 +0200304 dir="`eval echo '$'${dir}`"
Zheng Baof95bb2d2013-12-13 12:30:46 +0800305 test -d ${dir} && test -f ${dir}/.unpack_success || (
Stefan Reinauer074d9132009-09-26 16:43:17 +0000306 printf " * `basename $archive`\n"
307 FLAGS=zxf
Peter Stuge09377b72011-08-21 06:24:55 +0200308 suffix=`echo $archive | sed 's,.*\.,,'`
309 test "$suffix" = "gz" && FLAGS=zxf
310 test "$suffix" = "bz2" && FLAGS=jxf
Patrick Georgi53c388f2015-03-07 09:55:18 +0100311 test "$suffix" = "xz" && FLAGS="--xz -xf"
Peter Stuge09377b72011-08-21 06:24:55 +0200312 test "$suffix" = "lzma" && FLAGS="--lzma -xf"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000313 $TAR $FLAGS tarballs/`basename $archive`
Peter Stuge09377b72011-08-21 06:24:55 +0200314 for patch in patches/${dir}_*.patch; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000315 test -r $patch || continue
316 printf " o `basename $patch`\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100317 $PATCH -s -N -p0 < `echo $patch` || \
Zheng Bao5b209c02012-09-20 16:09:51 +0800318 printf "\n${RED}Failed $patch.${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000319 done
Zheng Bao691b313c2013-12-09 14:09:07 +0800320 touch ${dir}/.unpack_success
Stefan Reinauer074d9132009-09-26 16:43:17 +0000321 )
322done
323printf "Unpacked and patched ... "
324printf "${green}ok${NC}\n"
325
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700326CC=cc
Stefan Reinauer0d2119d2013-07-10 14:27:56 -0700327if [ $UNAME = "Darwin" ]; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000328 #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix"
329
330 # generally the OS X compiler can create x64 binaries.
331 # Per default it generated i386 binaries in 10.5 and x64
332 # binaries in 10.6 (even if the kernel is 32bit)
333 # For some weird reason, 10.5 autodetects an ABI=64 though
334 # so we're setting the ABI explicitly here.
Zheng Bao04ceed62012-10-23 19:41:25 +0800335 if [ `sysctl -n hw.optional.x86_64 2>/dev/null` -eq 1 ] 2>/dev/null; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000336 OPTIONS="ABI=64"
337 else
338 OPTIONS="ABI=32"
339 fi
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700340
Stefan Reinauer4266b922012-12-05 16:18:32 -0800341 # In Xcode 4.5.2 the default compiler is clang.
342 # However, this compiler fails to compile gcc 4.7.x. As a
343 # workaround it's possible to compile gcc with llvm-gcc.
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700344 if $CC -v 2>&1 | grep -q LLVM; then
Stefan Reinauer4266b922012-12-05 16:18:32 -0800345 CC=llvm-gcc
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700346 fi
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000347fi
348
Patrick Georgic1a75b12011-11-04 21:37:14 +0100349if [ "$USECCACHE" = 1 ]; then
350 CC="ccache $CC"
351fi
352
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200353mkdir -p ${BUILDDIRPREFIX}-gmp ${BUILDDIRPREFIX}-mpfr ${BUILDDIRPREFIX}-mpc ${BUILDDIRPREFIX}-libelf ${BUILDDIRPREFIX}-binutils \
354 ${BUILDDIRPREFIX}-gcc ${BUILDDIRPREFIX}-python ${BUILDDIRPREFIX}-expat
Stefan Reinauer16bd7892012-12-07 23:57:01 +0100355
356mkdir -p $DESTDIR$TARGETDIR/bin
357export PATH=$DESTDIR$TARGETDIR/bin:$PATH
358
Peter Stugeceacd772011-06-09 04:54:16 +0200359if [ $SKIPGDB -eq 0 ]; then
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200360 mkdir -p ${BUILDDIRPREFIX}-gdb
Peter Stugeceacd772011-06-09 04:54:16 +0200361fi
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200362if [ -f ${BUILDDIRPREFIX}-gmp/.success ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000363 printf "Skipping GMP as it is already built\n"
364else
365printf "Building GMP ${GMP_VERSION} ... "
366(
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200367 cd ${BUILDDIRPREFIX}-gmp
Stefan Reinauer074d9132009-09-26 16:43:17 +0000368 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100369 CC="$CC" ../${GMP_DIR}/configure --disable-shared --prefix=$TARGETDIR $OPTIONS \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000370 || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000371 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000372 $MAKE install DESTDIR=$DESTDIR || touch .failed
Patrick Georgi198d23c2012-12-08 08:02:44 +0100373
374 normalize_dirs
375
Stefan Reinauer074d9132009-09-26 16:43:17 +0000376 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200377) > ${BUILDDIRPREFIX}-gmp/crossgcc-build.log 2>&1
378test -r ${BUILDDIRPREFIX}-gmp/.failed && printf "${RED}failed${NC}\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100379 printf "${green}ok${NC}\n"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200380test -r ${BUILDDIRPREFIX}-gmp/.failed && exit 1
Stefan Reinauer074d9132009-09-26 16:43:17 +0000381fi
382
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700383# Now set CFLAGS to match GMP CFLAGS but strip out -pedantic
384# as GCC 4.6.x fails if it's there.
385HOSTCFLAGS=`grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2 |\
386 sed s,-pedantic,,`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000387
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200388if [ -f ${BUILDDIRPREFIX}-mpfr/.success ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000389 printf "Skipping MPFR as it is already built\n"
390else
391printf "Building MPFR ${MPFR_VERSION} ... "
392(
Stefan Reinauer0d2119d2013-07-10 14:27:56 -0700393 test $UNAME = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200394 cd ${BUILDDIRPREFIX}-mpfr
Stefan Reinauer074d9132009-09-26 16:43:17 +0000395 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100396 CC="$CC" ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000397 --infodir=$TARGETDIR/info \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100398 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
399 touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000400 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000401 $MAKE install DESTDIR=$DESTDIR || touch .failed
402
Patrick Georgi198d23c2012-12-08 08:02:44 +0100403 normalize_dirs
404
Stefan Reinauer074d9132009-09-26 16:43:17 +0000405 # work around build problem of libgmp.la
406 if [ "$DESTDIR" != "" ]; then
407 perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la
408 fi
409
410 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200411) > ${BUILDDIRPREFIX}-mpfr/crossgcc-build.log 2>&1
412test -r ${BUILDDIRPREFIX}-mpfr/.failed && printf "${RED}failed${NC}\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100413 printf "${green}ok${NC}\n"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200414test -r ${BUILDDIRPREFIX}-mpfr/.failed && exit 1
Stefan Reinauer074d9132009-09-26 16:43:17 +0000415fi
416
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200417if [ -f ${BUILDDIRPREFIX}-mpc/.success ]; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000418 printf "Skipping MPC as it is already built\n"
419else
420printf "Building MPC ${MPC_VERSION} ... "
421(
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200422 cd ${BUILDDIRPREFIX}-mpc
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000423 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100424 CC="$CC" ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000425 --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100426 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
427 touch .failed
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000428 $MAKE $JOBS || touch .failed
429 $MAKE install DESTDIR=$DESTDIR || touch .failed
430
Patrick Georgi198d23c2012-12-08 08:02:44 +0100431 normalize_dirs
432
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000433 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200434) > ${BUILDDIRPREFIX}-mpc/crossgcc-build.log 2>&1
435test -r ${BUILDDIRPREFIX}-mpc/.failed && printf "${RED}failed${NC}\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100436 printf "${green}ok${NC}\n"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200437test -r ${BUILDDIRPREFIX}-mpc/.failed && exit 1
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000438fi
439
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200440if [ -f ${BUILDDIRPREFIX}-libelf/.success ]; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000441 printf "Skipping libelf as it is already built\n"
442else
443printf "Building libelf ${LIBELF_VERSION} ... "
444(
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200445 cd ${BUILDDIRPREFIX}-libelf
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000446 rm -f .failed
447 echo "$HOSTCFLAGS"
Patrick Georgi643c9e82011-11-04 21:30:49 +0100448 CC="$CC" CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100449 ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000450 --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed
451 $MAKE $JOBS || touch .failed
Scott Duplichan4270a972014-12-12 20:21:40 -0600452 $MAKE install prefix=$DESTDIR$TARGETDIR || touch .failed
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000453
Patrick Georgi198d23c2012-12-08 08:02:44 +0100454 normalize_dirs
455
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000456 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200457) > ${BUILDDIRPREFIX}-libelf/crossgcc-build.log 2>&1
458test -r ${BUILDDIRPREFIX}-libelf/.failed && printf "${RED}failed${NC}\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100459 printf "${green}ok${NC}\n"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200460test -r ${BUILDDIRPREFIX}-libelf/.failed && exit 1
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000461fi
462
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200463if [ -f ${BUILDDIRPREFIX}-binutils/.success ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000464 printf "Skipping binutils as it is already built\n"
465else
466printf "Building binutils ${BINUTILS_VERSION} ... "
467(
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700468 # What a pain: binutils don't come with configure
469 # script anymore. Create it:
470 cd binutils-${BINUTILS_VERSION}/
471 autoconf
472 cd ..
473 # Now build binutils
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200474 cd ${BUILDDIRPREFIX}-binutils
Stefan Reinauer074d9132009-09-26 16:43:17 +0000475 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100476 CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100477 --target=${TARGETARCH} --disable-werror --disable-nls \
478 $USE_GOLD CFLAGS="$HOSTCFLAGS" || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000479 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000480 $MAKE install DESTDIR=$DESTDIR || touch .failed
481 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200482) > ${BUILDDIRPREFIX}-binutils/crossgcc-build.log 2>&1
483test -r ${BUILDDIRPREFIX}-binutils/.failed && printf "${RED}failed${NC}\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100484 printf "${green}ok${NC}\n"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200485test -r ${BUILDDIRPREFIX}-binutils/.failed && exit 1
Stefan Reinauer074d9132009-09-26 16:43:17 +0000486fi
487
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200488if [ -f ${BUILDDIRPREFIX}-gcc/.success ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000489 printf "Skipping GCC as it is already built\n"
490else
491printf "Building GCC ${GCC_VERSION} ... "
492(
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700493 # Even worse than binutils: GCC does not come with configure
494 # script anymore, but also enforces an obsolete autoconf version
495 # to create it. This is a poster child of how autotools help make
496 # software portable.
497 cd gcc-${GCC_VERSION}
498 sed '/dnl Ensure exactly this Autoconf version is used/d' \
499 config/override.m4 > config/override.m4.new
500 autoconf_version=`autoconf -V | grep "autoconf" | tr ' ' '\n' | tail -1`
501 sed "s/${GCC_AUTOCONF_VERSION}/${autoconf_version}/g" \
502 config/override.m4.new > config/override.m4
503 autoconf
504 cd ..
505 # Now, finally, we can build gcc:
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200506 cd ${BUILDDIRPREFIX}-gcc
Stefan Reinauer074d9132009-09-26 16:43:17 +0000507 rm -f .failed
508 # GCC does not honour HOSTCFLAGS at all. CFLAGS are used for
509 # both target and host object files. This is pretty misdesigned.
510 # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
511 # but it does not seem to work properly. At least the host library
512 # libiberty is not compiled with CFLAGS_FOR_BUILD.
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700513 CC="$CC" CFLAGS_FOR_TARGET="-O2" CFLAGS="$HOSTCFLAGS" \
514 CFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000515 --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000516 --target=${TARGETARCH} --disable-werror --disable-shared \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000517 --disable-libssp --disable-bootstrap --disable-nls \
Patrick Georgi969cd932012-12-07 13:13:53 +0100518 --disable-libquadmath --without-headers \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000519 $GCC_OPTIONS --enable-languages="c" $USE_GOLD \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000520 --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000521 --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \
522 --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000523 || touch .failed
Patrick Georgi969cd932012-12-07 13:13:53 +0100524 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-gcc || touch .failed
525 $MAKE install-gcc DESTDIR=$DESTDIR || touch .failed
526
527 if [ "`echo $TARGETARCH | grep -c -- -mingw32`" -eq 0 ]; then
528 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-target-libgcc || touch .failed
529 $MAKE install-target-libgcc DESTDIR=$DESTDIR || touch .failed
530 fi
531
Stefan Reinauer074d9132009-09-26 16:43:17 +0000532 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200533) > ${BUILDDIRPREFIX}-gcc/crossgcc-build.log 2>&1
534test -r ${BUILDDIRPREFIX}-gcc/.failed && printf "${RED}failed${NC}\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100535 printf "${green}ok${NC}\n"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200536test -r ${BUILDDIRPREFIX}-gcc/.failed && exit 1
Stefan Reinauer074d9132009-09-26 16:43:17 +0000537fi
538
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200539if [ -f ${BUILDDIRPREFIX}-expat/.success ]; then
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100540 printf "Skipping Expat as it is already built\n"
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100541elif [ $SKIPPYTHON -eq 1 ]; then
542 printf "Skipping Expat (Python scripting not enabled)\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100543else
544printf "Building Expat ${EXPAT_VERSION} ... "
545(
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200546 cd ${BUILDDIRPREFIX}-expat
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100547 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100548 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${EXPAT_DIR}/configure --disable-shared \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100549 --prefix=$TARGETDIR --target=${TARGETARCH} || touch .failed
550 $MAKE || touch .failed
551 $MAKE install DESTDIR=$DESTDIR || touch .failed
Patrick Georgi198d23c2012-12-08 08:02:44 +0100552
553 normalize_dirs
554
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100555 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200556) > ${BUILDDIRPREFIX}-expat/crossgcc-build.log 2>&1
557test -r ${BUILDDIRPREFIX}-expat/.failed && printf "${RED}failed${NC}\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100558 printf "${green}ok${NC}\n"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200559test -r ${BUILDDIRPREFIX}-expat/.failed && exit 1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100560fi
561
562
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200563if [ -f ${BUILDDIRPREFIX}-python/.success ]; then
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100564 printf "Skipping Python as it is already built\n"
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100565elif [ $SKIPPYTHON -eq 1 ]; then
566 printf "Skipping Python (Python scripting not enabled)\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100567else
568printf "Building Python ${PYTHON_VERSION} ... "
569(
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200570 cd ${BUILDDIRPREFIX}-python
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100571 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100572 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100573 --target=${TARGETARCH} || touch .failed
574 $MAKE $JOBS || touch .failed
575 $MAKE install DESTDIR=$DESTDIR || touch .failed
Patrick Georgi198d23c2012-12-08 08:02:44 +0100576
577 normalize_dirs
578
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100579 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200580) > ${BUILDDIRPREFIX}-python/crossgcc-build.log 2>&1
581test -r ${BUILDDIRPREFIX}-python/.failed && printf "${RED}failed${NC}\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100582 printf "${green}ok${NC}\n"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200583test -r ${BUILDDIRPREFIX}-python/.failed && exit 1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100584fi
585
586
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200587if [ -f ${BUILDDIRPREFIX}-gdb/.success ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000588 printf "Skipping GDB as it is already built\n"
Peter Stugeceacd772011-06-09 04:54:16 +0200589elif [ $SKIPGDB -eq 1 ]; then
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100590 printf "Skipping GDB (GDB support not enabled)\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000591else
592printf "Building GDB ${GDB_VERSION} ... "
593(
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200594 cd ${BUILDDIRPREFIX}-gdb
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100595 export PYTHONHOME=$DESTDIR$TARGETDIR
Stefan Reinauer074d9132009-09-26 16:43:17 +0000596 rm -f .failed
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100597 LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \
598 -lpthread -ldl -lutil" \
Patrick Georgi643c9e82011-11-04 21:30:49 +0100599 CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100600 ../gdb-${GDB_VERSION}/configure --prefix=$TARGETDIR \
601 --target=${TARGETARCH} --disable-werror --disable-nls
Patrick Georgi73166c72010-04-14 20:42:42 +0000602 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000603 $MAKE install DESTDIR=$DESTDIR || touch .failed
604 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200605) > ${BUILDDIRPREFIX}-gdb/crossgcc-build.log 2>&1
606test -r ${BUILDDIRPREFIX}-gdb/.failed && printf "${RED}failed${NC}\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100607 printf "${green}ok${NC}\n"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200608test -r ${BUILDDIRPREFIX}-gdb/.failed && exit 1
Stefan Reinauer074d9132009-09-26 16:43:17 +0000609fi
610
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200611if [ -f $IASL_DIR/source/compiler/.success ]; then
Marc Jones2aac3f62011-08-08 16:07:50 -0600612 printf "Skipping IASL as it is already built\n"
613else
614printf "Building IASL ${IASL_VERSION} ... "
615(
Idwer Vollering6b11c8b2012-11-15 21:14:36 +0100616 cd $IASL_DIR/generate/unix
Stefan Reinauer4266b922012-12-05 16:18:32 -0800617 rm -f .failed
Marc Jones2aac3f62011-08-08 16:07:50 -0600618 CFLAGS="$HOSTCFLAGS"
Stefan Reinauer0d2119d2013-07-10 14:27:56 -0700619 HOST="_LINUX"
620 test $UNAME = "Darwin" && HOST="_APPLE"
621 test $UNAME = "FreeBSD" && HOST="_FreeBSD"
622 test $UNAME = "Cygwin" && HOST="_CYGWIN"
623 HOST="$HOST" OPT_CFLAGS="-O -D_FORTIFY_SOURCE=2" CFLAGS="$CFLAGS" $MAKE CC="$CC" iasl || touch .failed
Stefan Reinauer4266b922012-12-05 16:18:32 -0800624 rm -f $DESTDIR$TARGETDIR/bin/iasl || touch .failed
Zheng Bao3c4bd912013-08-27 10:23:13 +0800625 cp bin/iasl $DESTDIR$TARGETDIR/bin || touch .failed
Stefan Reinauer4266b922012-12-05 16:18:32 -0800626 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200627) > $IASL_DIR/source/compiler/crossgcc-build.log 2>&1
Stefan Reinauer4266b922012-12-05 16:18:32 -0800628test -r $IASL_DIR/generate/unix/.failed && printf "${RED}failed${NC}\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100629 printf "${green}ok${NC}\n"
Stefan Reinauer4266b922012-12-05 16:18:32 -0800630test -r $IASL_DIR/generate/unix/.failed && exit 1
Marc Jones2aac3f62011-08-08 16:07:50 -0600631fi
632
Zheng Bao30b895f2013-02-06 18:04:40 +0800633rm -f $DESTDIR$TARGETDIR/$0.commit.*
634cp $0 $DESTDIR$TARGETDIR/"$0.commit.`git describe`"
635
Stefan Reinauer074d9132009-09-26 16:43:17 +0000636if [ $SAVETEMPS -eq 0 ]; then
637 printf "Cleaning up... "
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200638 rm -rf ${GMP_DIR} ${BUILDDIRPREFIX}-gmp
639 rm -rf ${MPFR_DIR} ${BUILDDIRPREFIX}-mpfr
640 rm -rf ${MPC_DIR} ${BUILDDIRPREFIX}-mpc
641 rm -rf ${LIBELF_DIR} ${BUILDDIRPREFIX}-libelf
642 rm -rf ${BINUTILS_DIR} ${BUILDDIRPREFIX}-binutils
643 rm -rf ${GCC_DIR} ${BUILDDIRPREFIX}-gcc
644 rm -rf ${GDB_DIR} ${BUILDDIRPREFIX}-gdb
645 rm -rf ${EXPAT_DIR} ${BUILDDIRPREFIX}-expat
646 rm -rf ${PYTHON_DIR} ${BUILDDIRPREFIX}-python
Marc Jones2aac3f62011-08-08 16:07:50 -0600647 rm -rf ${IASL_DIR}
Stefan Reinauer074d9132009-09-26 16:43:17 +0000648 printf "${green}ok${NC}\n"
649else
650 printf "Leaving temporary files around... ${green}ok${NC}\n"
651fi
652
653printf "\n${green}You can now run your $TARGETARCH cross toolchain from $TARGETDIR.${NC}\n"
654
655