blob: f17ec89b1afc5a1485e810782119e471f0385bab [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
Idwer Vollering336db542012-11-01 23:03:46 +010023CROSSGCC_DATE="November 1st, 2012"
24CROSSGCC_VERSION="1.18"
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
Patrick Georgice377652011-07-23 23:29:44 +020040W32API_VERSION=3.17-2
41W32API_VERSION_SHORT=3.17
Idwer Vollering908b0432012-10-25 03:00:59 +020042MINGWRT_VERSION=3.20-2
43MINGWRT_VERSION_SHORT=3.20
Patrick Georgi6e61ad32012-05-12 23:19:30 +020044IASL_VERSION=20120420
Idwer Vollering573d37d2012-10-26 01:56:56 +020045PYTHON_VERSION=2.7.3
Idwer Vollering296a0152012-10-26 01:48:04 +020046EXPAT_VERSION=2.1.0
Stefan Reinauer074d9132009-09-26 16:43:17 +000047
48# archive locations
Patrick Georgi6e61ad32012-05-12 23:19:30 +020049GMP_ARCHIVE="http://ftpmirror.gnu.org/gmp/gmp-${GMP_VERSION}.tar.bz2"
50MPFR_ARCHIVE="http://ftpmirror.gnu.org/mpfr/mpfr-${MPFR_VERSION}.tar.bz2"
Idwer Vollering7962fc72012-10-25 02:14:09 +020051MPC_ARCHIVE="http://ftpmirror.gnu.org/mpc/mpc-${MPC_VERSION}.tar.gz"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000052LIBELF_ARCHIVE="http://www.mr511.de/software/libelf-${LIBELF_VERSION}.tar.gz"
Idwer Vollering1cfee0b2012-10-25 02:03:53 +020053GCC_ARCHIVE="http://ftpmirror.gnu.org/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.bz2"
Idwer Vollering655a65c2012-10-25 02:15:01 +020054BINUTILS_ARCHIVE="http://ftpmirror.gnu.org/binutils/binutils-${BINUTILS_VERSION}.tar.gz"
Patrick Georgi6e61ad32012-05-12 23:19:30 +020055GDB_ARCHIVE="http://ftpmirror.gnu.org/gdb/gdb-${GDB_VERSION}.tar.bz2"
Idwer Volleringcd027932012-10-26 01:22:41 +020056W32API_ARCHIVE="http://downloads.sourceforge.net/project/mingw/MinGW/Base/w32api/w32api-${W32API_VERSION_SHORT}/w32api-${W32API_VERSION}-mingw32-src.tar.lzma"
Idwer Vollering908b0432012-10-25 03:00:59 +020057MINGWRT_ARCHIVE="http://downloads.sourceforge.net/project/mingw/MinGW/Base/mingw-rt/mingwrt-${MINGWRT_VERSION_SHORT}/mingwrt-${MINGWRT_VERSION}-mingw32-src.tar.lzma"
Marc Jones2aac3f62011-08-08 16:07:50 -060058IASL_ARCHIVE="http://www.acpica.org/download/acpica-unix-${IASL_VERSION}.tar.gz"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010059PYTHON_ARCHIVE="http://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.bz2"
60EXPAT_ARCHIVE="http://downloads.sourceforge.net/sourceforge/expat/expat-${EXPAT_VERSION}.tar.gz"
Stefan Reinauer074d9132009-09-26 16:43:17 +000061
62GMP_DIR="gmp-${GMP_VERSION}"
63MPFR_DIR="mpfr-${MPFR_VERSION}"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000064MPC_DIR="mpc-${MPC_VERSION}"
65LIBELF_DIR="libelf-${LIBELF_VERSION}"
Stefan Reinauer074d9132009-09-26 16:43:17 +000066GCC_DIR="gcc-${GCC_VERSION}"
67BINUTILS_DIR="binutils-${BINUTILS_VERSION}"
68GDB_DIR="gdb-${GDB_VERSION}"
Stefan Reinauer6ade1612010-01-16 16:44:20 +000069W32API_DIR="w32api-${W32API_VERSION}-mingw32"
70MINGWRT_DIR="mingwrt-${MINGWRT_VERSION}-mingw32"
Marc Jones2aac3f62011-08-08 16:07:50 -060071IASL_DIR="acpica-unix-${IASL_VERSION}"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010072PYTHON_DIR="Python-${PYTHON_VERSION}"
73EXPAT_DIR="expat-${EXPAT_VERSION}"
Stefan Reinauer074d9132009-09-26 16:43:17 +000074
75SAVETEMPS=0
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010076SKIPGDB=1
77SKIPPYTHON=1
Stefan Reinauer074d9132009-09-26 16:43:17 +000078
Patrick Georgi1861ff72011-10-31 12:15:55 +010079red='\033[0;31m'
80RED='\033[1;31m'
81green='\033[0;32m'
82GREEN='\033[1;32m'
83blue='\033[0;34m'
84BLUE='\033[1;34m'
85cyan='\033[0;36m'
86CYAN='\033[1;36m'
87NC='\033[0m' # No Color
Stefan Reinauer074d9132009-09-26 16:43:17 +000088
89searchgnu()
90{
91 # $1 short name
92 # result: GNU version of that tool on stdout
93 # or no output if no GNU version was found
94 for i in "$1" "g$1" "gnu$1"; do
95 if test -x "`which $i 2>/dev/null`"; then
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010096 if test `$i --version 2>/dev/null |grep -c GNU` \
97 -gt 0; then
Stefan Reinauer074d9132009-09-26 16:43:17 +000098 echo $i
99 return
100 fi
101 fi
102 done
Zheng Bao36156ff2012-09-28 16:18:58 +0800103 # A workaround for XxxBSD, whose nongnu patch and tar also work.
104 if [ `uname` = "FreeBSD" -o `uname` = "NetBSD" ]; then
105 if [ $1 != "make" ]; then
106 if test -x "`which $1 2>/dev/null`"; then
107 echo $1
108 return
109 fi
110 fi
111 fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000112 printf "${RED}ERROR:${red} Missing toolchain: $1${NC}\n" >&2
113 exit 1
114}
115
Patrick Georgi68df8042011-07-17 11:36:10 +0200116TAR=`searchgnu tar` || exit $?
117PATCH=`searchgnu patch` || exit $?
118MAKE=`searchgnu make` || exit $?
Stefan Reinauer074d9132009-09-26 16:43:17 +0000119
Patrick Georgi5fb2b5c2012-05-12 23:25:23 +0200120searchgnu m4 > /dev/null
121searchgnu bison > /dev/null
122
Stefan Reinauer074d9132009-09-26 16:43:17 +0000123cleanup()
124{
125 printf "Cleaning up temporary files... "
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100126 rm -rf build-* combined gcc-* gmp-* mpfr-* mpc-* libelf-* binutils-*
127 rm -rf gdb-* w32api-* mingwrt-* acpica-* python-* expat-*
Stefan Reinauer074d9132009-09-26 16:43:17 +0000128 printf "${green}ok${NC}\n"
129}
130
131myhelp()
132{
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100133 printf "Usage: $0 [-V] [-c] [-p <platform>] [-d <target directory>] [-D <dest dir>] [-G] [-S]\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000134 printf " $0 [-V|--version]\n"
135 printf " $0 [-h|--help]\n\n"
136
137 printf "Options:\n"
138 printf " [-V|--version] print version number and exit\n"
139 printf " [-h|--help] print this help and exit\n"
140 printf " [-c|--clean] remove temporary files before build\n"
141 printf " [-t|--savetemps] don't remove temporary files after build\n"
Patrick Georgic1a75b12011-11-04 21:37:14 +0100142 printf " [-y|--ccache] Use ccache when building cross compiler\n"
Patrick Georgi73166c72010-04-14 20:42:42 +0000143 printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000144 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
145 printf " (defaults to $TARGETARCH)\n"
146 printf " [-d|--directory <target dir>] target directory to install cross compiler to\n"
147 printf " (defaults to $TARGETDIR)\n\n"
148 printf " [-D|--destdir <dest dir>] destination directory to install cross compiler to\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100149 printf " (for RPM builds, default unset)\n"
150 printf " [-G|--gdb] build GNU debugger\n"
151 printf " [-S|--scripting] build scripting support for GDB\n\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000152}
153
154myversion()
155{
156 # version tag is always printed, so just print the license here
157
158 cat << EOF
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000159Copyright (C) 2008-2010 by coresystems GmbH
Marc Jones2aac3f62011-08-08 16:07:50 -0600160Copyright (C) 2011 by Sage Electronic Engineering
Stefan Reinauer074d9132009-09-26 16:43:17 +0000161
162This program is free software; you can redistribute it and/or modify
163it under the terms of the GNU General Public License as published by
164the Free Software Foundation; version 2 of the License.
165
166This program is distributed in the hope that it will be useful,
167but WITHOUT ANY WARRANTY; without even the implied warranty of
168MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
169GNU General Public License for more details.
170
171EOF
172}
173
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700174printf "${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 +0000175
Patrick Georgi6bba29f2010-01-29 17:40:52 +0000176# Look if we have getopt. If not, build it.
177export PATH=$PATH:.
178getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c
179
Stefan Reinauer074d9132009-09-26 16:43:17 +0000180# parse parameters.. try to find out whether we're running GNU getopt
Peter Stuge09377b72011-08-21 06:24:55 +0200181getoptbrand="`getopt -V | sed -e '1!d' -e 's,^\(......\).*,\1,'`"
182if [ "${getoptbrand}" = "getopt" ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000183 # Detected GNU getopt that supports long options.
Patrick Georgic1a75b12011-11-04 21:37:14 +0100184 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 +0000185 eval set "$args"
186else
187 # Detected non-GNU getopt
Patrick Georgic1a75b12011-11-04 21:37:14 +0100188 args=`getopt Vhcd:p:j:D:tGy $*`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000189 set -- $args
190fi
191
192if [ $? != 0 ]; then
193 myhelp
194 exit 1
195fi
196
197while true ; do
198 case "$1" in
199 -V|--version) shift; myversion; exit 0;;
200 -h|--help) shift; myhelp; exit 0;;
201 -c|--clean) shift; cleanup;;
202 -t|--savetemps) shift; SAVETEMPS=1;;
203 -d|--directory) shift; TARGETDIR="$1"; shift;;
204 -p|--platform) shift; TARGETARCH="$1"; shift;;
205 -D|--destdir) shift; DESTDIR="$1"; shift;;
Patrick Georgi73166c72010-04-14 20:42:42 +0000206 -j|--jobs) shift; JOBS="-j $1"; shift;;
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100207 -G|--gdb) shift; SKIPGDB=0;;
208 -S|--scripting) shift; SKIPPYTHON=0;;
Patrick Georgic1a75b12011-11-04 21:37:14 +0100209 -y|--ccache) shift; USECCACHE=1;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000210 --) shift; break;;
211 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
212 *) break;;
213 esac
214done
215
Peter Stugeceacd772011-06-09 04:54:16 +0200216GDB_PACKAGE="GDB"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100217PYTHON_PACKAGE="PYTHON"
218EXPAT_PACKAGE="EXPAT"
Peter Stugeceacd772011-06-09 04:54:16 +0200219if [ $SKIPGDB -eq 1 ]; then
220 printf "Will skip GDB ... ${green}ok${NC}\n"
Peter Stuge0e8ee812011-08-28 11:04:23 +0200221 GDB_ARCHIVE=""
Peter Stugeceacd772011-06-09 04:54:16 +0200222 GDB_PACKAGE=""
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100223 if [ $SKIPPYTHON -eq 0 ]; then
224 printf "Python scripting needs GDB ... disabling ... ${green}ok${NC}\n"
225 SKIPPYTHON=1
226 fi
227fi
228if [ $SKIPPYTHON -eq 1 ]; then
Jonathan A. Kollasch2d7ab4c2011-11-07 13:05:18 -0600229 PYTHON_ARCHIVE=""
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100230 PYTHON_PACKAGE=""
Jonathan A. Kollasch2d7ab4c2011-11-07 13:05:18 -0600231 EXPAT_ARCHIVE=""
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100232 EXPAT_PACKAGE=""
Peter Stugeceacd772011-06-09 04:54:16 +0200233fi
234
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000235MINGW_ARCHIVES=""
236if [ "$TARGETARCH" = "i386-mingw32" ]; then
237 MINGW_ARCHIVES="$W32API_ARCHIVE $MINGWRT_ARCHIVE"
238fi
239
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700240# coreboot does not like the GOLD linker
241# USE_GOLD="--enable-gold"
242USE_GOLD=""
243GCC_OPTIONS="--enable-lto"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000244
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100245if [ ${GCC_VERSION} = "trunk" ]; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000246 if [ ! -r tarballs/gcc-core-${GCC_VERSION}.tar.bz2 ]; then
247 printf "Pre-Release GCC ${GCC_VERSION}, checking out subversion trunk\n"
248 mkdir -p tarballs/.tmp
249 cd tarballs/.tmp
250 rm -rf gcc-${GCC_VERSION}
251 svn export -q svn://gcc.gnu.org/svn/gcc/trunk gcc-${GCC_VERSION}
252 printf "done. Now creating tar ball...\n"
253 tar cjf ../gcc-core-${GCC_VERSION}.tar.bz2 gcc-${GCC_VERSION}
254 printf "done. Now cleaning up...\n"
255 cd ..
256 rm -rf .tmp
257 cd ..
258 printf "done.\n"
259 fi
260fi
261
Stefan Reinauer074d9132009-09-26 16:43:17 +0000262printf "Downloading tar balls ... \n"
263mkdir -p tarballs
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100264for ARCHIVE in $GMP_ARCHIVE $MPFR_ARCHIVE $MPC_ARCHIVE $LIBELF_ARCHIVE \
265 $GCC_ARCHIVE $BINUTILS_ARCHIVE $GDB_ARCHIVE $MINGW_ARCHIVES \
266 $IASL_ARCHIVE $PYTHON_ARCHIVE $EXPAT_ARCHIVE; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000267 FILE=`basename $ARCHIVE`
268 printf " * $FILE "
269 test -f tarballs/$FILE && printf "(cached)" || (
270 printf "(downloading)"
271 cd tarballs
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200272 wget --no-check-certificate -q $ARCHIVE
Stefan Reinauer074d9132009-09-26 16:43:17 +0000273 )
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100274 test -f tarballs/$FILE || \
Zheng Bao5b209c02012-09-20 16:09:51 +0800275 printf "\n${RED}Failed to download $FILE.${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000276 test -f tarballs/$FILE || exit 1
277 printf "\n"
278done
279printf "Downloaded tar balls ... "
280printf "${green}ok${NC}\n"
281
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000282MINGW_PACKAGES=""
283if [ "$TARGETARCH" = "i386-mingw32" ]; then
284 MINGW_PACKAGES="W32API MINGWRT"
285fi
286
Stefan Reinauer074d9132009-09-26 16:43:17 +0000287printf "Unpacking and patching ... \n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100288for PACKAGE in GMP MPFR MPC LIBELF GCC BINUTILS $PYTHON_PACKAGE \
289 $EXPAT_PACKAGE $GDB_PACKAGE $MINGW_PACKAGES IASL; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000290 archive=$PACKAGE"_ARCHIVE"
Peter Stuge09377b72011-08-21 06:24:55 +0200291 archive="`eval echo '$'$archive`"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000292 dir=$PACKAGE"_DIR"
Peter Stuge09377b72011-08-21 06:24:55 +0200293 dir="`eval echo '$'${dir}`"
294 test -d ${dir} || (
Stefan Reinauer074d9132009-09-26 16:43:17 +0000295 printf " * `basename $archive`\n"
296 FLAGS=zxf
Peter Stuge09377b72011-08-21 06:24:55 +0200297 suffix=`echo $archive | sed 's,.*\.,,'`
298 test "$suffix" = "gz" && FLAGS=zxf
299 test "$suffix" = "bz2" && FLAGS=jxf
300 test "$suffix" = "lzma" && FLAGS="--lzma -xf"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000301 $TAR $FLAGS tarballs/`basename $archive`
Peter Stuge09377b72011-08-21 06:24:55 +0200302 for patch in patches/${dir}_*.patch; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000303 test -r $patch || continue
304 printf " o `basename $patch`\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100305 $PATCH -s -N -p0 < `echo $patch` || \
Zheng Bao5b209c02012-09-20 16:09:51 +0800306 printf "\n${RED}Failed $patch.${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000307 done
308 )
309done
310printf "Unpacked and patched ... "
311printf "${green}ok${NC}\n"
312
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000313if [ "$TARGETARCH" = "i386-mingw32" ]; then
314 mkdir -p $TARGETDIR/i386-mingw32/sys-include
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100315 mv $MINGWRT_DIR/include/* $W32API_DIR/include/* \
316 $TARGETDIR/i386-mingw32/sys-include
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000317fi
318
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700319CC=cc
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000320if [ `uname` = "Darwin" ]; then
321 #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix"
322
323 # generally the OS X compiler can create x64 binaries.
324 # Per default it generated i386 binaries in 10.5 and x64
325 # binaries in 10.6 (even if the kernel is 32bit)
326 # For some weird reason, 10.5 autodetects an ABI=64 though
327 # so we're setting the ABI explicitly here.
Zheng Bao04ceed62012-10-23 19:41:25 +0800328 if [ `sysctl -n hw.optional.x86_64 2>/dev/null` -eq 1 ] 2>/dev/null; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000329 OPTIONS="ABI=64"
330 else
331 OPTIONS="ABI=32"
332 fi
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700333
334 # In Xcode 4 the default compiler was switched to gcc-llvm.
335 # However, this compiler fails to compile gcc 4.6.x. As a
336 # workaround it's possible to compile gcc with gcc-4.2 or
337 # clang.
338 if $CC -v 2>&1 | grep -q LLVM; then
339 CC=clang
340 fi
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000341fi
342
Patrick Georgic1a75b12011-11-04 21:37:14 +0100343if [ "$USECCACHE" = 1 ]; then
344 CC="ccache $CC"
345fi
346
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100347mkdir -p build-gmp build-mpfr build-mpc build-libelf build-binutils \
348 build-gcc build-python build-expat
Peter Stugeceacd772011-06-09 04:54:16 +0200349if [ $SKIPGDB -eq 0 ]; then
350 mkdir -p build-gdb
351fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000352if [ -f build-gmp/.success ]; then
353 printf "Skipping GMP as it is already built\n"
354else
355printf "Building GMP ${GMP_VERSION} ... "
356(
357 cd build-gmp
358 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100359 CC="$CC" ../${GMP_DIR}/configure --disable-shared --prefix=$TARGETDIR $OPTIONS \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000360 || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000361 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000362 $MAKE install DESTDIR=$DESTDIR || touch .failed
363 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200364) > build-gmp/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100365test -r build-gmp/.failed && printf "${RED}failed${NC}\n" || \
366 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000367test -r build-gmp/.failed && exit 1
368fi
369
370#if [ "$DESTDIR" != "" -a ! -x $TARGETDIR ]; then
371# # create compat link
372# ln -s $DESTDIR$TARGETDIR $TARGETDIR
373#fi
374
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700375# Now set CFLAGS to match GMP CFLAGS but strip out -pedantic
376# as GCC 4.6.x fails if it's there.
377HOSTCFLAGS=`grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2 |\
378 sed s,-pedantic,,`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000379
380if [ -f build-mpfr/.success ]; then
381 printf "Skipping MPFR as it is already built\n"
382else
383printf "Building MPFR ${MPFR_VERSION} ... "
384(
385 test `uname` = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
386 cd build-mpfr
387 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100388 CC="$CC" ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000389 --infodir=$TARGETDIR/info \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100390 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
391 touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000392 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000393 $MAKE install DESTDIR=$DESTDIR || touch .failed
394
395 # work around build problem of libgmp.la
396 if [ "$DESTDIR" != "" ]; then
397 perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la
398 fi
399
400 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200401) > build-mpfr/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100402test -r build-mpfr/.failed && printf "${RED}failed${NC}\n" || \
403 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000404test -r build-mpfr/.failed && exit 1
405fi
406
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000407if [ -f build-mpc/.success ]; then
408 printf "Skipping MPC as it is already built\n"
409else
410printf "Building MPC ${MPC_VERSION} ... "
411(
412 #test `uname` = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
413 cd build-mpc
414 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100415 CC="$CC" ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000416 --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100417 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
418 touch .failed
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000419 $MAKE $JOBS || touch .failed
420 $MAKE install DESTDIR=$DESTDIR || touch .failed
421
422 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200423) > build-mpc/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100424test -r build-mpc/.failed && printf "${RED}failed${NC}\n" || \
425 printf "${green}ok${NC}\n"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000426test -r build-mpc/.failed && exit 1
427fi
428
429if [ -f build-libelf/.success ]; then
430 printf "Skipping libelf as it is already built\n"
431else
432printf "Building libelf ${LIBELF_VERSION} ... "
433(
434 cd build-libelf
435 rm -f .failed
436 echo "$HOSTCFLAGS"
Patrick Georgi643c9e82011-11-04 21:30:49 +0100437 CC="$CC" CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100438 ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000439 --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed
440 $MAKE $JOBS || touch .failed
441 $MAKE install DESTDIR=$DESTDIR || touch .failed
442
443 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200444) > build-libelf/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100445test -r build-libelf/.failed && printf "${RED}failed${NC}\n" || \
446 printf "${green}ok${NC}\n"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000447test -r build-libelf/.failed && exit 1
448fi
449
Stefan Reinauer074d9132009-09-26 16:43:17 +0000450if [ -f build-binutils/.success ]; then
451 printf "Skipping binutils as it is already built\n"
452else
453printf "Building binutils ${BINUTILS_VERSION} ... "
454(
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700455 # What a pain: binutils don't come with configure
456 # script anymore. Create it:
457 cd binutils-${BINUTILS_VERSION}/
458 autoconf
459 cd ..
460 # Now build binutils
Stefan Reinauer074d9132009-09-26 16:43:17 +0000461 cd build-binutils
462 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100463 CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100464 --target=${TARGETARCH} --disable-werror --disable-nls \
465 $USE_GOLD CFLAGS="$HOSTCFLAGS" || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000466 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000467 $MAKE install DESTDIR=$DESTDIR || touch .failed
468 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200469) > build-binutils/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100470test -r build-binutils/.failed && printf "${RED}failed${NC}\n" || \
471 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000472test -r build-binutils/.failed && exit 1
473fi
474
475if [ -f build-gcc/.success ]; then
476 printf "Skipping GCC as it is already built\n"
477else
478printf "Building GCC ${GCC_VERSION} ... "
479(
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700480 # Even worse than binutils: GCC does not come with configure
481 # script anymore, but also enforces an obsolete autoconf version
482 # to create it. This is a poster child of how autotools help make
483 # software portable.
484 cd gcc-${GCC_VERSION}
485 sed '/dnl Ensure exactly this Autoconf version is used/d' \
486 config/override.m4 > config/override.m4.new
487 autoconf_version=`autoconf -V | grep "autoconf" | tr ' ' '\n' | tail -1`
488 sed "s/${GCC_AUTOCONF_VERSION}/${autoconf_version}/g" \
489 config/override.m4.new > config/override.m4
490 autoconf
491 cd ..
492 # Now, finally, we can build gcc:
Stefan Reinauer074d9132009-09-26 16:43:17 +0000493 cd build-gcc
Patrick Georgiba3b0eb2010-09-03 08:53:06 +0000494 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
Stefan Reinauer074d9132009-09-26 16:43:17 +0000495 rm -f .failed
496 # GCC does not honour HOSTCFLAGS at all. CFLAGS are used for
497 # both target and host object files. This is pretty misdesigned.
498 # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
499 # but it does not seem to work properly. At least the host library
500 # libiberty is not compiled with CFLAGS_FOR_BUILD.
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700501 CC="$CC" CFLAGS_FOR_TARGET="-O2" CFLAGS="$HOSTCFLAGS" \
502 CFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000503 --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000504 --target=${TARGETARCH} --disable-werror --disable-shared \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000505 --disable-libssp --disable-bootstrap --disable-nls \
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700506 --disable-libquadmath \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000507 $GCC_OPTIONS --enable-languages="c" $USE_GOLD \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000508 --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000509 --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \
510 --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000511 || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000512 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000513 $MAKE install DESTDIR=$DESTDIR || touch .failed
514 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200515) > build-gcc/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100516test -r build-gcc/.failed && printf "${RED}failed${NC}\n" || \
517 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000518test -r build-gcc/.failed && exit 1
519fi
520
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100521if [ -f build-expat/.success ]; then
522 printf "Skipping Expat as it is already built\n"
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100523elif [ $SKIPPYTHON -eq 1 ]; then
524 printf "Skipping Expat (Python scripting not enabled)\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100525else
526printf "Building Expat ${EXPAT_VERSION} ... "
527(
528 cd build-expat
529 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
530 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100531 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${EXPAT_DIR}/configure --disable-shared \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100532 --prefix=$TARGETDIR --target=${TARGETARCH} || touch .failed
533 $MAKE || touch .failed
534 $MAKE install DESTDIR=$DESTDIR || touch .failed
535 if [ ! -f .failed ]; then touch .success; fi
Idwer Vollering336db542012-11-01 23:03:46 +0100536) > build-expat/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100537test -r build-expat/.failed && printf "${RED}failed${NC}\n" || \
538 printf "${green}ok${NC}\n"
539test -r build-expat/.failed && exit 1
540fi
541
542
543if [ -f build-python/.success ]; then
544 printf "Skipping Python as it is already built\n"
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100545elif [ $SKIPPYTHON -eq 1 ]; then
546 printf "Skipping Python (Python scripting not enabled)\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100547else
548printf "Building Python ${PYTHON_VERSION} ... "
549(
550 cd build-python
551 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
552 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100553 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100554 --target=${TARGETARCH} || touch .failed
555 $MAKE $JOBS || touch .failed
556 $MAKE install DESTDIR=$DESTDIR || touch .failed
557 if [ ! -f .failed ]; then touch .success; fi
Idwer Vollering336db542012-11-01 23:03:46 +0100558) > build-python/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100559test -r build-python/.failed && printf "${RED}failed${NC}\n" || \
560 printf "${green}ok${NC}\n"
561test -r build-python/.failed && exit 1
562fi
563
564
Stefan Reinauer074d9132009-09-26 16:43:17 +0000565if [ -f build-gdb/.success ]; then
566 printf "Skipping GDB as it is already built\n"
Peter Stugeceacd772011-06-09 04:54:16 +0200567elif [ $SKIPGDB -eq 1 ]; then
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100568 printf "Skipping GDB (GDB support not enabled)\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000569else
570printf "Building GDB ${GDB_VERSION} ... "
571(
572 cd build-gdb
Patrick Georgiba3b0eb2010-09-03 08:53:06 +0000573 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100574 export PYTHONHOME=$DESTDIR$TARGETDIR
Stefan Reinauer074d9132009-09-26 16:43:17 +0000575 rm -f .failed
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100576 LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \
577 -lpthread -ldl -lutil" \
Patrick Georgi643c9e82011-11-04 21:30:49 +0100578 CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100579 ../gdb-${GDB_VERSION}/configure --prefix=$TARGETDIR \
580 --target=${TARGETARCH} --disable-werror --disable-nls
Patrick Georgi73166c72010-04-14 20:42:42 +0000581 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000582 $MAKE install DESTDIR=$DESTDIR || touch .failed
583 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200584) > build-gdb/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100585test -r build-gdb/.failed && printf "${RED}failed${NC}\n" || \
586 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000587test -r build-gdb/.failed && exit 1
588fi
589
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200590if [ -f $IASL_DIR/source/compiler/.success ]; then
Marc Jones2aac3f62011-08-08 16:07:50 -0600591 printf "Skipping IASL as it is already built\n"
592else
593printf "Building IASL ${IASL_VERSION} ... "
594(
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200595 cd $IASL_DIR/source/compiler
Marc Jones2aac3f62011-08-08 16:07:50 -0600596 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
597 rm -f .failed
598 CFLAGS="$HOSTCFLAGS"
Patrick Georgi643c9e82011-11-04 21:30:49 +0100599 $MAKE CC="$CC" || touch .failed
Jonathan A. Kollaschf44bb4f2011-08-11 14:44:55 -0500600 rm -f $DESTDIR$TARGETDIR/bin/iasl || touch .failed
601 cp iasl $DESTDIR$TARGETDIR/bin || touch .failed
Marc Jones2aac3f62011-08-08 16:07:50 -0600602 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200603) > $IASL_DIR/source/compiler/crossgcc-build.log 2>&1
604test -r $IASL_DIR/source/compiler/.failed && printf "${RED}failed${NC}\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100605 printf "${green}ok${NC}\n"
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200606test -r $IASL_DIR/source/compiler/.failed && exit 1
Marc Jones2aac3f62011-08-08 16:07:50 -0600607fi
608
Stefan Reinauer074d9132009-09-26 16:43:17 +0000609if [ $SAVETEMPS -eq 0 ]; then
610 printf "Cleaning up... "
611 rm -rf ${GMP_DIR} build-gmp
612 rm -rf ${MPFR_DIR} build-mpfr
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000613 rm -rf ${MPC_DIR} build-mpc
614 rm -rf ${LIBELF_DIR} build-libelf
Stefan Reinauer074d9132009-09-26 16:43:17 +0000615 rm -rf ${BINUTILS_DIR} build-binutils
616 rm -rf ${GCC_DIR} build-gcc
617 rm -rf ${GDB_DIR} build-gdb
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100618 rm -rf ${EXPAT_DIR} build-expat
619 rm -rf ${PYTHON_DIR} build-python
Marc Jones2aac3f62011-08-08 16:07:50 -0600620 rm -rf ${IASL_DIR}
Stefan Reinauer074d9132009-09-26 16:43:17 +0000621 printf "${green}ok${NC}\n"
622else
623 printf "Leaving temporary files around... ${green}ok${NC}\n"
624fi
625
626printf "\n${green}You can now run your $TARGETARCH cross toolchain from $TARGETDIR.${NC}\n"
627
628