blob: f7f21f061212635dbd1bdc452a07e4e9b858da3c [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
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010020# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
Stefan Reinauer074d9132009-09-26 16:43:17 +000021#
22
Stefan Reinauer4266b922012-12-05 16:18:32 -080023CROSSGCC_DATE="December 4th, 2012"
24CROSSGCC_VERSION="1.20"
Stefan Reinauer074d9132009-09-26 16:43:17 +000025
26# default settings
27TARGETDIR=`pwd`/xgcc
28TARGETARCH=i386-elf
29DESTDIR=
30
31# version numbers
Patrick Georgi6e61ad32012-05-12 23:19:30 +020032GMP_VERSION=5.0.5
Idwer Vollering27efb4c2012-10-25 02:12:46 +020033MPFR_VERSION=3.1.1
Idwer Vollering7962fc72012-10-25 02:14:09 +020034MPC_VERSION=1.0.1
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000035LIBELF_VERSION=0.8.13
Idwer Vollering1cfee0b2012-10-25 02:03:53 +020036GCC_VERSION=4.7.2
Stefan Reinauer9491b4d2011-10-11 22:37:59 -070037GCC_AUTOCONF_VERSION=2.64
Idwer Vollering655a65c2012-10-25 02:15:01 +020038BINUTILS_VERSION=2.23
Idwer Volleringfedb63a2012-10-25 02:06:57 +020039GDB_VERSION=7.5
Idwer Vollering6b11c8b2012-11-15 21:14:36 +010040IASL_VERSION=20121114
Idwer Vollering573d37d2012-10-26 01:56:56 +020041PYTHON_VERSION=2.7.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 Georgi6e61ad32012-05-12 23:19:30 +020045GMP_ARCHIVE="http://ftpmirror.gnu.org/gmp/gmp-${GMP_VERSION}.tar.bz2"
46MPFR_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"
Idwer Vollering655a65c2012-10-25 02:15:01 +020050BINUTILS_ARCHIVE="http://ftpmirror.gnu.org/binutils/binutils-${BINUTILS_VERSION}.tar.gz"
Patrick Georgi6e61ad32012-05-12 23:19:30 +020051GDB_ARCHIVE="http://ftpmirror.gnu.org/gdb/gdb-${GDB_VERSION}.tar.bz2"
Marc Jones2aac3f62011-08-08 16:07:50 -060052IASL_ARCHIVE="http://www.acpica.org/download/acpica-unix-${IASL_VERSION}.tar.gz"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010053PYTHON_ARCHIVE="http://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.bz2"
54EXPAT_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
67SAVETEMPS=0
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010068SKIPGDB=1
69SKIPPYTHON=1
Stefan Reinauer074d9132009-09-26 16:43:17 +000070
Patrick Georgi1861ff72011-10-31 12:15:55 +010071red='\033[0;31m'
72RED='\033[1;31m'
73green='\033[0;32m'
74GREEN='\033[1;32m'
75blue='\033[0;34m'
76BLUE='\033[1;34m'
77cyan='\033[0;36m'
78CYAN='\033[1;36m'
79NC='\033[0m' # No Color
Stefan Reinauer074d9132009-09-26 16:43:17 +000080
81searchgnu()
82{
83 # $1 short name
84 # result: GNU version of that tool on stdout
85 # or no output if no GNU version was found
86 for i in "$1" "g$1" "gnu$1"; do
87 if test -x "`which $i 2>/dev/null`"; then
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010088 if test `$i --version 2>/dev/null |grep -c GNU` \
89 -gt 0; then
Stefan Reinauer074d9132009-09-26 16:43:17 +000090 echo $i
91 return
92 fi
93 fi
94 done
Zheng Bao36156ff2012-09-28 16:18:58 +080095 # A workaround for XxxBSD, whose nongnu patch and tar also work.
96 if [ `uname` = "FreeBSD" -o `uname` = "NetBSD" ]; then
97 if [ $1 != "make" ]; then
98 if test -x "`which $1 2>/dev/null`"; then
99 echo $1
100 return
101 fi
102 fi
103 fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000104 printf "${RED}ERROR:${red} Missing toolchain: $1${NC}\n" >&2
105 exit 1
106}
107
Patrick Georgi68df8042011-07-17 11:36:10 +0200108TAR=`searchgnu tar` || exit $?
109PATCH=`searchgnu patch` || exit $?
110MAKE=`searchgnu make` || exit $?
Stefan Reinauer074d9132009-09-26 16:43:17 +0000111
Patrick Georgi5fb2b5c2012-05-12 23:25:23 +0200112searchgnu m4 > /dev/null
113searchgnu bison > /dev/null
Patrick Georgi0a3f2392012-11-20 12:04:32 +0100114
115if ! flex --version > /dev/null 2> /dev/null; then
116 printf "${RED}ERROR:${red} Missing toolchain: flex${NC}\n" >&2
117 exit 1
118fi
Patrick Georgi5fb2b5c2012-05-12 23:25:23 +0200119
Stefan Reinauer074d9132009-09-26 16:43:17 +0000120cleanup()
121{
122 printf "Cleaning up temporary files... "
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100123 rm -rf build-* combined gcc-* gmp-* mpfr-* mpc-* libelf-* binutils-*
Patrick Georgi969cd932012-12-07 13:13:53 +0100124 rm -rf gdb-* acpica-* python-* expat-*
Stefan Reinauer074d9132009-09-26 16:43:17 +0000125 printf "${green}ok${NC}\n"
126}
127
128myhelp()
129{
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100130 printf "Usage: $0 [-V] [-c] [-p <platform>] [-d <target directory>] [-D <dest dir>] [-G] [-S]\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000131 printf " $0 [-V|--version]\n"
132 printf " $0 [-h|--help]\n\n"
133
134 printf "Options:\n"
135 printf " [-V|--version] print version number and exit\n"
136 printf " [-h|--help] print this help and exit\n"
137 printf " [-c|--clean] remove temporary files before build\n"
138 printf " [-t|--savetemps] don't remove temporary files after build\n"
Patrick Georgic1a75b12011-11-04 21:37:14 +0100139 printf " [-y|--ccache] Use ccache when building cross compiler\n"
Patrick Georgi73166c72010-04-14 20:42:42 +0000140 printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000141 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
142 printf " (defaults to $TARGETARCH)\n"
143 printf " [-d|--directory <target dir>] target directory to install cross compiler to\n"
144 printf " (defaults to $TARGETDIR)\n\n"
145 printf " [-D|--destdir <dest dir>] destination directory to install cross compiler to\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100146 printf " (for RPM builds, default unset)\n"
147 printf " [-G|--gdb] build GNU debugger\n"
148 printf " [-S|--scripting] build scripting support for GDB\n\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000149}
150
151myversion()
152{
153 # version tag is always printed, so just print the license here
154
155 cat << EOF
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000156Copyright (C) 2008-2010 by coresystems GmbH
Marc Jones2aac3f62011-08-08 16:07:50 -0600157Copyright (C) 2011 by Sage Electronic Engineering
Stefan Reinauer074d9132009-09-26 16:43:17 +0000158
159This program is free software; you can redistribute it and/or modify
160it under the terms of the GNU General Public License as published by
161the Free Software Foundation; version 2 of the License.
162
163This program is distributed in the hope that it will be useful,
164but WITHOUT ANY WARRANTY; without even the implied warranty of
165MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
166GNU General Public License for more details.
167
168EOF
169}
170
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700171printf "${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 +0000172
Patrick Georgi6bba29f2010-01-29 17:40:52 +0000173# Look if we have getopt. If not, build it.
174export PATH=$PATH:.
175getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c
176
Stefan Reinauer074d9132009-09-26 16:43:17 +0000177# parse parameters.. try to find out whether we're running GNU getopt
Peter Stuge09377b72011-08-21 06:24:55 +0200178getoptbrand="`getopt -V | sed -e '1!d' -e 's,^\(......\).*,\1,'`"
179if [ "${getoptbrand}" = "getopt" ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000180 # Detected GNU getopt that supports long options.
Patrick Georgic1a75b12011-11-04 21:37:14 +0100181 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 +0000182 eval set "$args"
183else
184 # Detected non-GNU getopt
Patrick Georgic1a75b12011-11-04 21:37:14 +0100185 args=`getopt Vhcd:p:j:D:tGy $*`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000186 set -- $args
187fi
188
189if [ $? != 0 ]; then
190 myhelp
191 exit 1
192fi
193
194while true ; do
195 case "$1" in
196 -V|--version) shift; myversion; exit 0;;
197 -h|--help) shift; myhelp; exit 0;;
198 -c|--clean) shift; cleanup;;
199 -t|--savetemps) shift; SAVETEMPS=1;;
200 -d|--directory) shift; TARGETDIR="$1"; shift;;
201 -p|--platform) shift; TARGETARCH="$1"; shift;;
202 -D|--destdir) shift; DESTDIR="$1"; shift;;
Patrick Georgi73166c72010-04-14 20:42:42 +0000203 -j|--jobs) shift; JOBS="-j $1"; shift;;
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100204 -G|--gdb) shift; SKIPGDB=0;;
205 -S|--scripting) shift; SKIPPYTHON=0;;
Patrick Georgic1a75b12011-11-04 21:37:14 +0100206 -y|--ccache) shift; USECCACHE=1;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000207 --) shift; break;;
208 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
209 *) break;;
210 esac
211done
212
Peter Stugeceacd772011-06-09 04:54:16 +0200213GDB_PACKAGE="GDB"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100214PYTHON_PACKAGE="PYTHON"
215EXPAT_PACKAGE="EXPAT"
Peter Stugeceacd772011-06-09 04:54:16 +0200216if [ $SKIPGDB -eq 1 ]; then
217 printf "Will skip GDB ... ${green}ok${NC}\n"
Peter Stuge0e8ee812011-08-28 11:04:23 +0200218 GDB_ARCHIVE=""
Peter Stugeceacd772011-06-09 04:54:16 +0200219 GDB_PACKAGE=""
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100220 if [ $SKIPPYTHON -eq 0 ]; then
221 printf "Python scripting needs GDB ... disabling ... ${green}ok${NC}\n"
222 SKIPPYTHON=1
223 fi
224fi
225if [ $SKIPPYTHON -eq 1 ]; then
Jonathan A. Kollasch2d7ab4c2011-11-07 13:05:18 -0600226 PYTHON_ARCHIVE=""
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100227 PYTHON_PACKAGE=""
Jonathan A. Kollasch2d7ab4c2011-11-07 13:05:18 -0600228 EXPAT_ARCHIVE=""
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100229 EXPAT_PACKAGE=""
Peter Stugeceacd772011-06-09 04:54:16 +0200230fi
231
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700232# coreboot does not like the GOLD linker
233# USE_GOLD="--enable-gold"
234USE_GOLD=""
235GCC_OPTIONS="--enable-lto"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000236
Stefan Reinauer074d9132009-09-26 16:43:17 +0000237printf "Downloading tar balls ... \n"
238mkdir -p tarballs
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100239for ARCHIVE in $GMP_ARCHIVE $MPFR_ARCHIVE $MPC_ARCHIVE $LIBELF_ARCHIVE \
Patrick Georgi969cd932012-12-07 13:13:53 +0100240 $GCC_ARCHIVE $BINUTILS_ARCHIVE $GDB_ARCHIVE \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100241 $IASL_ARCHIVE $PYTHON_ARCHIVE $EXPAT_ARCHIVE; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000242 FILE=`basename $ARCHIVE`
243 printf " * $FILE "
244 test -f tarballs/$FILE && printf "(cached)" || (
245 printf "(downloading)"
246 cd tarballs
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200247 wget --no-check-certificate -q $ARCHIVE
Stefan Reinauer074d9132009-09-26 16:43:17 +0000248 )
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100249 test -f tarballs/$FILE || \
Zheng Bao5b209c02012-09-20 16:09:51 +0800250 printf "\n${RED}Failed to download $FILE.${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000251 test -f tarballs/$FILE || exit 1
252 printf "\n"
253done
254printf "Downloaded tar balls ... "
255printf "${green}ok${NC}\n"
256
257printf "Unpacking and patching ... \n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100258for PACKAGE in GMP MPFR MPC LIBELF GCC BINUTILS $PYTHON_PACKAGE \
Patrick Georgi969cd932012-12-07 13:13:53 +0100259 $EXPAT_PACKAGE $GDB_PACKAGE IASL; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000260 archive=$PACKAGE"_ARCHIVE"
Peter Stuge09377b72011-08-21 06:24:55 +0200261 archive="`eval echo '$'$archive`"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000262 dir=$PACKAGE"_DIR"
Peter Stuge09377b72011-08-21 06:24:55 +0200263 dir="`eval echo '$'${dir}`"
264 test -d ${dir} || (
Stefan Reinauer074d9132009-09-26 16:43:17 +0000265 printf " * `basename $archive`\n"
266 FLAGS=zxf
Peter Stuge09377b72011-08-21 06:24:55 +0200267 suffix=`echo $archive | sed 's,.*\.,,'`
268 test "$suffix" = "gz" && FLAGS=zxf
269 test "$suffix" = "bz2" && FLAGS=jxf
270 test "$suffix" = "lzma" && FLAGS="--lzma -xf"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000271 $TAR $FLAGS tarballs/`basename $archive`
Peter Stuge09377b72011-08-21 06:24:55 +0200272 for patch in patches/${dir}_*.patch; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000273 test -r $patch || continue
274 printf " o `basename $patch`\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100275 $PATCH -s -N -p0 < `echo $patch` || \
Zheng Bao5b209c02012-09-20 16:09:51 +0800276 printf "\n${RED}Failed $patch.${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000277 done
278 )
279done
280printf "Unpacked and patched ... "
281printf "${green}ok${NC}\n"
282
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700283CC=cc
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000284if [ `uname` = "Darwin" ]; then
285 #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix"
286
287 # generally the OS X compiler can create x64 binaries.
288 # Per default it generated i386 binaries in 10.5 and x64
289 # binaries in 10.6 (even if the kernel is 32bit)
290 # For some weird reason, 10.5 autodetects an ABI=64 though
291 # so we're setting the ABI explicitly here.
Zheng Bao04ceed62012-10-23 19:41:25 +0800292 if [ `sysctl -n hw.optional.x86_64 2>/dev/null` -eq 1 ] 2>/dev/null; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000293 OPTIONS="ABI=64"
294 else
295 OPTIONS="ABI=32"
296 fi
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700297
Stefan Reinauer4266b922012-12-05 16:18:32 -0800298 # In Xcode 4.5.2 the default compiler is clang.
299 # However, this compiler fails to compile gcc 4.7.x. As a
300 # workaround it's possible to compile gcc with llvm-gcc.
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700301 if $CC -v 2>&1 | grep -q LLVM; then
Stefan Reinauer4266b922012-12-05 16:18:32 -0800302 CC=llvm-gcc
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700303 fi
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000304fi
305
Patrick Georgic1a75b12011-11-04 21:37:14 +0100306if [ "$USECCACHE" = 1 ]; then
307 CC="ccache $CC"
308fi
309
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100310mkdir -p build-gmp build-mpfr build-mpc build-libelf build-binutils \
311 build-gcc build-python build-expat
Stefan Reinauer16bd7892012-12-07 23:57:01 +0100312
313mkdir -p $DESTDIR$TARGETDIR/bin
314export PATH=$DESTDIR$TARGETDIR/bin:$PATH
315
Peter Stugeceacd772011-06-09 04:54:16 +0200316if [ $SKIPGDB -eq 0 ]; then
317 mkdir -p build-gdb
318fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000319if [ -f build-gmp/.success ]; then
320 printf "Skipping GMP as it is already built\n"
321else
322printf "Building GMP ${GMP_VERSION} ... "
323(
324 cd build-gmp
325 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100326 CC="$CC" ../${GMP_DIR}/configure --disable-shared --prefix=$TARGETDIR $OPTIONS \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000327 || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000328 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000329 $MAKE install DESTDIR=$DESTDIR || touch .failed
330 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200331) > build-gmp/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100332test -r build-gmp/.failed && printf "${RED}failed${NC}\n" || \
333 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000334test -r build-gmp/.failed && exit 1
335fi
336
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700337# Now set CFLAGS to match GMP CFLAGS but strip out -pedantic
338# as GCC 4.6.x fails if it's there.
339HOSTCFLAGS=`grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2 |\
340 sed s,-pedantic,,`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000341
342if [ -f build-mpfr/.success ]; then
343 printf "Skipping MPFR as it is already built\n"
344else
345printf "Building MPFR ${MPFR_VERSION} ... "
346(
347 test `uname` = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
348 cd build-mpfr
349 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100350 CC="$CC" ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000351 --infodir=$TARGETDIR/info \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100352 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
353 touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000354 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000355 $MAKE install DESTDIR=$DESTDIR || touch .failed
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 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200363) > build-mpfr/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100364test -r build-mpfr/.failed && printf "${RED}failed${NC}\n" || \
365 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000366test -r build-mpfr/.failed && exit 1
367fi
368
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000369if [ -f build-mpc/.success ]; then
370 printf "Skipping MPC as it is already built\n"
371else
372printf "Building MPC ${MPC_VERSION} ... "
373(
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000374 cd build-mpc
375 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100376 CC="$CC" ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000377 --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100378 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
379 touch .failed
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000380 $MAKE $JOBS || touch .failed
381 $MAKE install DESTDIR=$DESTDIR || touch .failed
382
383 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200384) > build-mpc/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100385test -r build-mpc/.failed && printf "${RED}failed${NC}\n" || \
386 printf "${green}ok${NC}\n"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000387test -r build-mpc/.failed && exit 1
388fi
389
390if [ -f build-libelf/.success ]; then
391 printf "Skipping libelf as it is already built\n"
392else
393printf "Building libelf ${LIBELF_VERSION} ... "
394(
395 cd build-libelf
396 rm -f .failed
397 echo "$HOSTCFLAGS"
Patrick Georgi643c9e82011-11-04 21:30:49 +0100398 CC="$CC" CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100399 ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000400 --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed
401 $MAKE $JOBS || touch .failed
402 $MAKE install DESTDIR=$DESTDIR || touch .failed
403
404 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200405) > build-libelf/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100406test -r build-libelf/.failed && printf "${RED}failed${NC}\n" || \
407 printf "${green}ok${NC}\n"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000408test -r build-libelf/.failed && exit 1
409fi
410
Stefan Reinauer074d9132009-09-26 16:43:17 +0000411if [ -f build-binutils/.success ]; then
412 printf "Skipping binutils as it is already built\n"
413else
414printf "Building binutils ${BINUTILS_VERSION} ... "
415(
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700416 # What a pain: binutils don't come with configure
417 # script anymore. Create it:
418 cd binutils-${BINUTILS_VERSION}/
419 autoconf
420 cd ..
421 # Now build binutils
Stefan Reinauer074d9132009-09-26 16:43:17 +0000422 cd build-binutils
423 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100424 CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100425 --target=${TARGETARCH} --disable-werror --disable-nls \
426 $USE_GOLD CFLAGS="$HOSTCFLAGS" || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000427 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000428 $MAKE install DESTDIR=$DESTDIR || touch .failed
429 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200430) > build-binutils/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100431test -r build-binutils/.failed && printf "${RED}failed${NC}\n" || \
432 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000433test -r build-binutils/.failed && exit 1
434fi
435
436if [ -f build-gcc/.success ]; then
437 printf "Skipping GCC as it is already built\n"
438else
439printf "Building GCC ${GCC_VERSION} ... "
440(
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700441 # Even worse than binutils: GCC does not come with configure
442 # script anymore, but also enforces an obsolete autoconf version
443 # to create it. This is a poster child of how autotools help make
444 # software portable.
445 cd gcc-${GCC_VERSION}
446 sed '/dnl Ensure exactly this Autoconf version is used/d' \
447 config/override.m4 > config/override.m4.new
448 autoconf_version=`autoconf -V | grep "autoconf" | tr ' ' '\n' | tail -1`
449 sed "s/${GCC_AUTOCONF_VERSION}/${autoconf_version}/g" \
450 config/override.m4.new > config/override.m4
451 autoconf
452 cd ..
453 # Now, finally, we can build gcc:
Stefan Reinauer074d9132009-09-26 16:43:17 +0000454 cd build-gcc
455 rm -f .failed
456 # GCC does not honour HOSTCFLAGS at all. CFLAGS are used for
457 # both target and host object files. This is pretty misdesigned.
458 # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
459 # but it does not seem to work properly. At least the host library
460 # libiberty is not compiled with CFLAGS_FOR_BUILD.
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700461 CC="$CC" CFLAGS_FOR_TARGET="-O2" CFLAGS="$HOSTCFLAGS" \
462 CFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000463 --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000464 --target=${TARGETARCH} --disable-werror --disable-shared \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000465 --disable-libssp --disable-bootstrap --disable-nls \
Patrick Georgi969cd932012-12-07 13:13:53 +0100466 --disable-libquadmath --without-headers \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000467 $GCC_OPTIONS --enable-languages="c" $USE_GOLD \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000468 --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000469 --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \
470 --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000471 || touch .failed
Patrick Georgi969cd932012-12-07 13:13:53 +0100472 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-gcc || touch .failed
473 $MAKE install-gcc DESTDIR=$DESTDIR || touch .failed
474
475 if [ "`echo $TARGETARCH | grep -c -- -mingw32`" -eq 0 ]; then
476 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-target-libgcc || touch .failed
477 $MAKE install-target-libgcc DESTDIR=$DESTDIR || touch .failed
478 fi
479
Stefan Reinauer074d9132009-09-26 16:43:17 +0000480 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200481) > build-gcc/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100482test -r build-gcc/.failed && printf "${RED}failed${NC}\n" || \
483 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000484test -r build-gcc/.failed && exit 1
485fi
486
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100487if [ -f build-expat/.success ]; then
488 printf "Skipping Expat as it is already built\n"
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100489elif [ $SKIPPYTHON -eq 1 ]; then
490 printf "Skipping Expat (Python scripting not enabled)\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100491else
492printf "Building Expat ${EXPAT_VERSION} ... "
493(
494 cd build-expat
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100495 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100496 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${EXPAT_DIR}/configure --disable-shared \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100497 --prefix=$TARGETDIR --target=${TARGETARCH} || touch .failed
498 $MAKE || touch .failed
499 $MAKE install DESTDIR=$DESTDIR || touch .failed
500 if [ ! -f .failed ]; then touch .success; fi
Idwer Vollering336db542012-11-01 23:03:46 +0100501) > build-expat/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100502test -r build-expat/.failed && printf "${RED}failed${NC}\n" || \
503 printf "${green}ok${NC}\n"
504test -r build-expat/.failed && exit 1
505fi
506
507
508if [ -f build-python/.success ]; then
509 printf "Skipping Python as it is already built\n"
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100510elif [ $SKIPPYTHON -eq 1 ]; then
511 printf "Skipping Python (Python scripting not enabled)\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100512else
513printf "Building Python ${PYTHON_VERSION} ... "
514(
515 cd build-python
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100516 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100517 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100518 --target=${TARGETARCH} || touch .failed
519 $MAKE $JOBS || touch .failed
520 $MAKE install DESTDIR=$DESTDIR || touch .failed
521 if [ ! -f .failed ]; then touch .success; fi
Idwer Vollering336db542012-11-01 23:03:46 +0100522) > build-python/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100523test -r build-python/.failed && printf "${RED}failed${NC}\n" || \
524 printf "${green}ok${NC}\n"
525test -r build-python/.failed && exit 1
526fi
527
528
Stefan Reinauer074d9132009-09-26 16:43:17 +0000529if [ -f build-gdb/.success ]; then
530 printf "Skipping GDB as it is already built\n"
Peter Stugeceacd772011-06-09 04:54:16 +0200531elif [ $SKIPGDB -eq 1 ]; then
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100532 printf "Skipping GDB (GDB support not enabled)\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000533else
534printf "Building GDB ${GDB_VERSION} ... "
535(
536 cd build-gdb
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100537 export PYTHONHOME=$DESTDIR$TARGETDIR
Stefan Reinauer074d9132009-09-26 16:43:17 +0000538 rm -f .failed
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100539 LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \
540 -lpthread -ldl -lutil" \
Patrick Georgi643c9e82011-11-04 21:30:49 +0100541 CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100542 ../gdb-${GDB_VERSION}/configure --prefix=$TARGETDIR \
543 --target=${TARGETARCH} --disable-werror --disable-nls
Patrick Georgi73166c72010-04-14 20:42:42 +0000544 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000545 $MAKE install DESTDIR=$DESTDIR || touch .failed
546 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200547) > build-gdb/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100548test -r build-gdb/.failed && printf "${RED}failed${NC}\n" || \
549 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000550test -r build-gdb/.failed && exit 1
551fi
552
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200553if [ -f $IASL_DIR/source/compiler/.success ]; then
Marc Jones2aac3f62011-08-08 16:07:50 -0600554 printf "Skipping IASL as it is already built\n"
555else
556printf "Building IASL ${IASL_VERSION} ... "
557(
Idwer Vollering6b11c8b2012-11-15 21:14:36 +0100558 cd $IASL_DIR/generate/unix
Stefan Reinauer4266b922012-12-05 16:18:32 -0800559 rm -f .failed
Marc Jones2aac3f62011-08-08 16:07:50 -0600560 CFLAGS="$HOSTCFLAGS"
Stefan Reinauer4266b922012-12-05 16:18:32 -0800561 $MAKE CC="$CC" iasl || touch .failed
562 rm -f $DESTDIR$TARGETDIR/bin/iasl || touch .failed
563 if [ -d bin32 ]; then cp bin32/iasl $DESTDIR$TARGETDIR/bin || touch .failed ; fi
564 if [ -d bin64 ]; then cp bin64/iasl $DESTDIR$TARGETDIR/bin || touch .failed ; fi
565 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200566) > $IASL_DIR/source/compiler/crossgcc-build.log 2>&1
Stefan Reinauer4266b922012-12-05 16:18:32 -0800567test -r $IASL_DIR/generate/unix/.failed && printf "${RED}failed${NC}\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100568 printf "${green}ok${NC}\n"
Stefan Reinauer4266b922012-12-05 16:18:32 -0800569test -r $IASL_DIR/generate/unix/.failed && exit 1
Marc Jones2aac3f62011-08-08 16:07:50 -0600570fi
571
Stefan Reinauer074d9132009-09-26 16:43:17 +0000572if [ $SAVETEMPS -eq 0 ]; then
573 printf "Cleaning up... "
574 rm -rf ${GMP_DIR} build-gmp
575 rm -rf ${MPFR_DIR} build-mpfr
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000576 rm -rf ${MPC_DIR} build-mpc
577 rm -rf ${LIBELF_DIR} build-libelf
Stefan Reinauer074d9132009-09-26 16:43:17 +0000578 rm -rf ${BINUTILS_DIR} build-binutils
579 rm -rf ${GCC_DIR} build-gcc
580 rm -rf ${GDB_DIR} build-gdb
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100581 rm -rf ${EXPAT_DIR} build-expat
582 rm -rf ${PYTHON_DIR} build-python
Marc Jones2aac3f62011-08-08 16:07:50 -0600583 rm -rf ${IASL_DIR}
Stefan Reinauer074d9132009-09-26 16:43:17 +0000584 printf "${green}ok${NC}\n"
585else
586 printf "Leaving temporary files around... ${green}ok${NC}\n"
587fi
588
589printf "\n${green}You can now run your $TARGETARCH cross toolchain from $TARGETDIR.${NC}\n"
590
591