blob: 87e6132dc2e407e62134fb0ad79f53a617ef4bc1 [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 Volleringcbd63122012-10-23 19:49:36 +020023CROSSGCC_DATE="October 23rd, 2012"
Idwer Volleringfedb63a2012-10-25 02:06:57 +020024CROSSGCC_VERSION="1.10"
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
Stefan Reinauer9491b4d2011-10-11 22:37:59 -070033MPFR_VERSION=3.1.0
34MPC_VERSION=0.9
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
Patrick Georgi6e61ad32012-05-12 23:19:30 +020038BINUTILS_VERSION=2.22
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
Patrick Georgi73166c72010-04-14 20:42:42 +000042MINGWRT_VERSION=3.18
Patrick Georgi6e61ad32012-05-12 23:19:30 +020043IASL_VERSION=20120420
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010044PYTHON_VERSION=2.7.2
45EXPAT_VERSION=2.0.1
Stefan Reinauer074d9132009-09-26 16:43:17 +000046
47# archive locations
Patrick Georgi6e61ad32012-05-12 23:19:30 +020048GMP_ARCHIVE="http://ftpmirror.gnu.org/gmp/gmp-${GMP_VERSION}.tar.bz2"
49MPFR_ARCHIVE="http://ftpmirror.gnu.org/mpfr/mpfr-${MPFR_VERSION}.tar.bz2"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000050MPC_ARCHIVE="http://www.multiprecision.org/mpc/download/mpc-${MPC_VERSION}.tar.gz"
51LIBELF_ARCHIVE="http://www.mr511.de/software/libelf-${LIBELF_VERSION}.tar.gz"
Idwer Vollering1cfee0b2012-10-25 02:03:53 +020052GCC_ARCHIVE="http://ftpmirror.gnu.org/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.bz2"
Patrick Georgi6e61ad32012-05-12 23:19:30 +020053BINUTILS_ARCHIVE="http://ftpmirror.gnu.org/binutils/binutils-${BINUTILS_VERSION}.tar.bz2"
54GDB_ARCHIVE="http://ftpmirror.gnu.org/gdb/gdb-${GDB_VERSION}.tar.bz2"
Patrick Georgice377652011-07-23 23:29:44 +020055W32API_ARCHIVE="http://downloads.sourceforge.net/project/mingw/MinGW/BaseSystem/RuntimeLibrary/Win32-API/w32api-${W32API_VERSION_SHORT}/w32api-${W32API_VERSION}-mingw32-src.tar.lzma"
Marc Jones36932662010-12-03 00:45:56 +000056MINGWRT_ARCHIVE="http://downloads.sourceforge.net/project/mingw/MinGW/BaseSystem/RuntimeLibrary/MinGW-RT/mingwrt-${MINGWRT_VERSION}/mingwrt-${MINGWRT_VERSION}-mingw32-src.tar.gz"
Marc Jones2aac3f62011-08-08 16:07:50 -060057IASL_ARCHIVE="http://www.acpica.org/download/acpica-unix-${IASL_VERSION}.tar.gz"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010058PYTHON_ARCHIVE="http://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.bz2"
59EXPAT_ARCHIVE="http://downloads.sourceforge.net/sourceforge/expat/expat-${EXPAT_VERSION}.tar.gz"
Stefan Reinauer074d9132009-09-26 16:43:17 +000060
61GMP_DIR="gmp-${GMP_VERSION}"
62MPFR_DIR="mpfr-${MPFR_VERSION}"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000063MPC_DIR="mpc-${MPC_VERSION}"
64LIBELF_DIR="libelf-${LIBELF_VERSION}"
Stefan Reinauer074d9132009-09-26 16:43:17 +000065GCC_DIR="gcc-${GCC_VERSION}"
66BINUTILS_DIR="binutils-${BINUTILS_VERSION}"
67GDB_DIR="gdb-${GDB_VERSION}"
Stefan Reinauer6ade1612010-01-16 16:44:20 +000068W32API_DIR="w32api-${W32API_VERSION}-mingw32"
69MINGWRT_DIR="mingwrt-${MINGWRT_VERSION}-mingw32"
Marc Jones2aac3f62011-08-08 16:07:50 -060070IASL_DIR="acpica-unix-${IASL_VERSION}"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010071PYTHON_DIR="Python-${PYTHON_VERSION}"
72EXPAT_DIR="expat-${EXPAT_VERSION}"
Stefan Reinauer074d9132009-09-26 16:43:17 +000073
74SAVETEMPS=0
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010075SKIPGDB=1
76SKIPPYTHON=1
Stefan Reinauer074d9132009-09-26 16:43:17 +000077
Patrick Georgi1861ff72011-10-31 12:15:55 +010078red='\033[0;31m'
79RED='\033[1;31m'
80green='\033[0;32m'
81GREEN='\033[1;32m'
82blue='\033[0;34m'
83BLUE='\033[1;34m'
84cyan='\033[0;36m'
85CYAN='\033[1;36m'
86NC='\033[0m' # No Color
Stefan Reinauer074d9132009-09-26 16:43:17 +000087
88searchgnu()
89{
90 # $1 short name
91 # result: GNU version of that tool on stdout
92 # or no output if no GNU version was found
93 for i in "$1" "g$1" "gnu$1"; do
94 if test -x "`which $i 2>/dev/null`"; then
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010095 if test `$i --version 2>/dev/null |grep -c GNU` \
96 -gt 0; then
Stefan Reinauer074d9132009-09-26 16:43:17 +000097 echo $i
98 return
99 fi
100 fi
101 done
Zheng Bao36156ff2012-09-28 16:18:58 +0800102 # A workaround for XxxBSD, whose nongnu patch and tar also work.
103 if [ `uname` = "FreeBSD" -o `uname` = "NetBSD" ]; then
104 if [ $1 != "make" ]; then
105 if test -x "`which $1 2>/dev/null`"; then
106 echo $1
107 return
108 fi
109 fi
110 fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000111 printf "${RED}ERROR:${red} Missing toolchain: $1${NC}\n" >&2
112 exit 1
113}
114
Patrick Georgi68df8042011-07-17 11:36:10 +0200115TAR=`searchgnu tar` || exit $?
116PATCH=`searchgnu patch` || exit $?
117MAKE=`searchgnu make` || exit $?
Stefan Reinauer074d9132009-09-26 16:43:17 +0000118
Patrick Georgi5fb2b5c2012-05-12 23:25:23 +0200119searchgnu m4 > /dev/null
120searchgnu bison > /dev/null
121
Stefan Reinauer074d9132009-09-26 16:43:17 +0000122cleanup()
123{
124 printf "Cleaning up temporary files... "
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100125 rm -rf build-* combined gcc-* gmp-* mpfr-* mpc-* libelf-* binutils-*
126 rm -rf gdb-* w32api-* mingwrt-* acpica-* python-* expat-*
Stefan Reinauer074d9132009-09-26 16:43:17 +0000127 printf "${green}ok${NC}\n"
128}
129
130myhelp()
131{
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100132 printf "Usage: $0 [-V] [-c] [-p <platform>] [-d <target directory>] [-D <dest dir>] [-G] [-S]\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000133 printf " $0 [-V|--version]\n"
134 printf " $0 [-h|--help]\n\n"
135
136 printf "Options:\n"
137 printf " [-V|--version] print version number and exit\n"
138 printf " [-h|--help] print this help and exit\n"
139 printf " [-c|--clean] remove temporary files before build\n"
140 printf " [-t|--savetemps] don't remove temporary files after build\n"
Patrick Georgic1a75b12011-11-04 21:37:14 +0100141 printf " [-y|--ccache] Use ccache when building cross compiler\n"
Patrick Georgi73166c72010-04-14 20:42:42 +0000142 printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000143 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
144 printf " (defaults to $TARGETARCH)\n"
145 printf " [-d|--directory <target dir>] target directory to install cross compiler to\n"
146 printf " (defaults to $TARGETDIR)\n\n"
147 printf " [-D|--destdir <dest dir>] destination directory to install cross compiler to\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100148 printf " (for RPM builds, default unset)\n"
149 printf " [-G|--gdb] build GNU debugger\n"
150 printf " [-S|--scripting] build scripting support for GDB\n\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000151}
152
153myversion()
154{
155 # version tag is always printed, so just print the license here
156
157 cat << EOF
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000158Copyright (C) 2008-2010 by coresystems GmbH
Marc Jones2aac3f62011-08-08 16:07:50 -0600159Copyright (C) 2011 by Sage Electronic Engineering
Stefan Reinauer074d9132009-09-26 16:43:17 +0000160
161This program is free software; you can redistribute it and/or modify
162it under the terms of the GNU General Public License as published by
163the Free Software Foundation; version 2 of the License.
164
165This program is distributed in the hope that it will be useful,
166but WITHOUT ANY WARRANTY; without even the implied warranty of
167MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
168GNU General Public License for more details.
169
170EOF
171}
172
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700173printf "${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 +0000174
Patrick Georgi6bba29f2010-01-29 17:40:52 +0000175# Look if we have getopt. If not, build it.
176export PATH=$PATH:.
177getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c
178
Stefan Reinauer074d9132009-09-26 16:43:17 +0000179# parse parameters.. try to find out whether we're running GNU getopt
Peter Stuge09377b72011-08-21 06:24:55 +0200180getoptbrand="`getopt -V | sed -e '1!d' -e 's,^\(......\).*,\1,'`"
181if [ "${getoptbrand}" = "getopt" ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000182 # Detected GNU getopt that supports long options.
Patrick Georgic1a75b12011-11-04 21:37:14 +0100183 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 +0000184 eval set "$args"
185else
186 # Detected non-GNU getopt
Patrick Georgic1a75b12011-11-04 21:37:14 +0100187 args=`getopt Vhcd:p:j:D:tGy $*`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000188 set -- $args
189fi
190
191if [ $? != 0 ]; then
192 myhelp
193 exit 1
194fi
195
196while true ; do
197 case "$1" in
198 -V|--version) shift; myversion; exit 0;;
199 -h|--help) shift; myhelp; exit 0;;
200 -c|--clean) shift; cleanup;;
201 -t|--savetemps) shift; SAVETEMPS=1;;
202 -d|--directory) shift; TARGETDIR="$1"; shift;;
203 -p|--platform) shift; TARGETARCH="$1"; shift;;
204 -D|--destdir) shift; DESTDIR="$1"; shift;;
Patrick Georgi73166c72010-04-14 20:42:42 +0000205 -j|--jobs) shift; JOBS="-j $1"; shift;;
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100206 -G|--gdb) shift; SKIPGDB=0;;
207 -S|--scripting) shift; SKIPPYTHON=0;;
Patrick Georgic1a75b12011-11-04 21:37:14 +0100208 -y|--ccache) shift; USECCACHE=1;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000209 --) shift; break;;
210 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
211 *) break;;
212 esac
213done
214
Peter Stugeceacd772011-06-09 04:54:16 +0200215GDB_PACKAGE="GDB"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100216PYTHON_PACKAGE="PYTHON"
217EXPAT_PACKAGE="EXPAT"
Peter Stugeceacd772011-06-09 04:54:16 +0200218if [ $SKIPGDB -eq 1 ]; then
219 printf "Will skip GDB ... ${green}ok${NC}\n"
Peter Stuge0e8ee812011-08-28 11:04:23 +0200220 GDB_ARCHIVE=""
Peter Stugeceacd772011-06-09 04:54:16 +0200221 GDB_PACKAGE=""
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100222 if [ $SKIPPYTHON -eq 0 ]; then
223 printf "Python scripting needs GDB ... disabling ... ${green}ok${NC}\n"
224 SKIPPYTHON=1
225 fi
226fi
227if [ $SKIPPYTHON -eq 1 ]; then
Jonathan A. Kollasch2d7ab4c2011-11-07 13:05:18 -0600228 PYTHON_ARCHIVE=""
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100229 PYTHON_PACKAGE=""
Jonathan A. Kollasch2d7ab4c2011-11-07 13:05:18 -0600230 EXPAT_ARCHIVE=""
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100231 EXPAT_PACKAGE=""
Peter Stugeceacd772011-06-09 04:54:16 +0200232fi
233
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000234MINGW_ARCHIVES=""
235if [ "$TARGETARCH" = "i386-mingw32" ]; then
236 MINGW_ARCHIVES="$W32API_ARCHIVE $MINGWRT_ARCHIVE"
237fi
238
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700239# coreboot does not like the GOLD linker
240# USE_GOLD="--enable-gold"
241USE_GOLD=""
242GCC_OPTIONS="--enable-lto"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000243
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100244if [ ${GCC_VERSION} = "trunk" ]; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000245 if [ ! -r tarballs/gcc-core-${GCC_VERSION}.tar.bz2 ]; then
246 printf "Pre-Release GCC ${GCC_VERSION}, checking out subversion trunk\n"
247 mkdir -p tarballs/.tmp
248 cd tarballs/.tmp
249 rm -rf gcc-${GCC_VERSION}
250 svn export -q svn://gcc.gnu.org/svn/gcc/trunk gcc-${GCC_VERSION}
251 printf "done. Now creating tar ball...\n"
252 tar cjf ../gcc-core-${GCC_VERSION}.tar.bz2 gcc-${GCC_VERSION}
253 printf "done. Now cleaning up...\n"
254 cd ..
255 rm -rf .tmp
256 cd ..
257 printf "done.\n"
258 fi
259fi
260
Stefan Reinauer074d9132009-09-26 16:43:17 +0000261printf "Downloading tar balls ... \n"
262mkdir -p tarballs
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100263for ARCHIVE in $GMP_ARCHIVE $MPFR_ARCHIVE $MPC_ARCHIVE $LIBELF_ARCHIVE \
264 $GCC_ARCHIVE $BINUTILS_ARCHIVE $GDB_ARCHIVE $MINGW_ARCHIVES \
265 $IASL_ARCHIVE $PYTHON_ARCHIVE $EXPAT_ARCHIVE; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000266 FILE=`basename $ARCHIVE`
267 printf " * $FILE "
268 test -f tarballs/$FILE && printf "(cached)" || (
269 printf "(downloading)"
270 cd tarballs
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200271 wget --no-check-certificate -q $ARCHIVE
Stefan Reinauer074d9132009-09-26 16:43:17 +0000272 )
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100273 test -f tarballs/$FILE || \
Zheng Bao5b209c02012-09-20 16:09:51 +0800274 printf "\n${RED}Failed to download $FILE.${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000275 test -f tarballs/$FILE || exit 1
276 printf "\n"
277done
278printf "Downloaded tar balls ... "
279printf "${green}ok${NC}\n"
280
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000281MINGW_PACKAGES=""
282if [ "$TARGETARCH" = "i386-mingw32" ]; then
283 MINGW_PACKAGES="W32API MINGWRT"
284fi
285
Stefan Reinauer074d9132009-09-26 16:43:17 +0000286printf "Unpacking and patching ... \n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100287for PACKAGE in GMP MPFR MPC LIBELF GCC BINUTILS $PYTHON_PACKAGE \
288 $EXPAT_PACKAGE $GDB_PACKAGE $MINGW_PACKAGES IASL; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000289 archive=$PACKAGE"_ARCHIVE"
Peter Stuge09377b72011-08-21 06:24:55 +0200290 archive="`eval echo '$'$archive`"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000291 dir=$PACKAGE"_DIR"
Peter Stuge09377b72011-08-21 06:24:55 +0200292 dir="`eval echo '$'${dir}`"
293 test -d ${dir} || (
Stefan Reinauer074d9132009-09-26 16:43:17 +0000294 printf " * `basename $archive`\n"
295 FLAGS=zxf
Peter Stuge09377b72011-08-21 06:24:55 +0200296 suffix=`echo $archive | sed 's,.*\.,,'`
297 test "$suffix" = "gz" && FLAGS=zxf
298 test "$suffix" = "bz2" && FLAGS=jxf
299 test "$suffix" = "lzma" && FLAGS="--lzma -xf"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000300 $TAR $FLAGS tarballs/`basename $archive`
Peter Stuge09377b72011-08-21 06:24:55 +0200301 for patch in patches/${dir}_*.patch; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000302 test -r $patch || continue
303 printf " o `basename $patch`\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100304 $PATCH -s -N -p0 < `echo $patch` || \
Zheng Bao5b209c02012-09-20 16:09:51 +0800305 printf "\n${RED}Failed $patch.${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000306 done
307 )
308done
309printf "Unpacked and patched ... "
310printf "${green}ok${NC}\n"
311
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000312if [ "$TARGETARCH" = "i386-mingw32" ]; then
313 mkdir -p $TARGETDIR/i386-mingw32/sys-include
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100314 mv $MINGWRT_DIR/include/* $W32API_DIR/include/* \
315 $TARGETDIR/i386-mingw32/sys-include
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000316fi
317
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700318CC=cc
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000319if [ `uname` = "Darwin" ]; then
320 #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix"
321
322 # generally the OS X compiler can create x64 binaries.
323 # Per default it generated i386 binaries in 10.5 and x64
324 # binaries in 10.6 (even if the kernel is 32bit)
325 # For some weird reason, 10.5 autodetects an ABI=64 though
326 # so we're setting the ABI explicitly here.
327 if [ `sysctl -n hw.optional.x86_64` -eq 1 ]; then
328 OPTIONS="ABI=64"
329 else
330 OPTIONS="ABI=32"
331 fi
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700332
333 # In Xcode 4 the default compiler was switched to gcc-llvm.
334 # However, this compiler fails to compile gcc 4.6.x. As a
335 # workaround it's possible to compile gcc with gcc-4.2 or
336 # clang.
337 if $CC -v 2>&1 | grep -q LLVM; then
338 CC=clang
339 fi
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000340fi
341
Patrick Georgic1a75b12011-11-04 21:37:14 +0100342if [ "$USECCACHE" = 1 ]; then
343 CC="ccache $CC"
344fi
345
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100346mkdir -p build-gmp build-mpfr build-mpc build-libelf build-binutils \
347 build-gcc build-python build-expat
Peter Stugeceacd772011-06-09 04:54:16 +0200348if [ $SKIPGDB -eq 0 ]; then
349 mkdir -p build-gdb
350fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000351if [ -f build-gmp/.success ]; then
352 printf "Skipping GMP as it is already built\n"
353else
354printf "Building GMP ${GMP_VERSION} ... "
355(
356 cd build-gmp
357 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100358 CC="$CC" ../${GMP_DIR}/configure --disable-shared --prefix=$TARGETDIR $OPTIONS \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000359 || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000360 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000361 $MAKE install DESTDIR=$DESTDIR || touch .failed
362 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200363) > build-gmp/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100364test -r build-gmp/.failed && printf "${RED}failed${NC}\n" || \
365 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000366test -r build-gmp/.failed && exit 1
367fi
368
369#if [ "$DESTDIR" != "" -a ! -x $TARGETDIR ]; then
370# # create compat link
371# ln -s $DESTDIR$TARGETDIR $TARGETDIR
372#fi
373
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700374# Now set CFLAGS to match GMP CFLAGS but strip out -pedantic
375# as GCC 4.6.x fails if it's there.
376HOSTCFLAGS=`grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2 |\
377 sed s,-pedantic,,`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000378
379if [ -f build-mpfr/.success ]; then
380 printf "Skipping MPFR as it is already built\n"
381else
382printf "Building MPFR ${MPFR_VERSION} ... "
383(
384 test `uname` = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
385 cd build-mpfr
386 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100387 CC="$CC" ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000388 --infodir=$TARGETDIR/info \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100389 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
390 touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000391 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000392 $MAKE install DESTDIR=$DESTDIR || touch .failed
393
394 # work around build problem of libgmp.la
395 if [ "$DESTDIR" != "" ]; then
396 perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la
397 fi
398
399 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200400) > build-mpfr/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100401test -r build-mpfr/.failed && printf "${RED}failed${NC}\n" || \
402 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000403test -r build-mpfr/.failed && exit 1
404fi
405
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000406if [ -f build-mpc/.success ]; then
407 printf "Skipping MPC as it is already built\n"
408else
409printf "Building MPC ${MPC_VERSION} ... "
410(
411 #test `uname` = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
412 cd build-mpc
413 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100414 CC="$CC" ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000415 --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100416 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
417 touch .failed
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000418 $MAKE $JOBS || touch .failed
419 $MAKE install DESTDIR=$DESTDIR || touch .failed
420
421 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200422) > build-mpc/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100423test -r build-mpc/.failed && printf "${RED}failed${NC}\n" || \
424 printf "${green}ok${NC}\n"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000425test -r build-mpc/.failed && exit 1
426fi
427
428if [ -f build-libelf/.success ]; then
429 printf "Skipping libelf as it is already built\n"
430else
431printf "Building libelf ${LIBELF_VERSION} ... "
432(
433 cd build-libelf
434 rm -f .failed
435 echo "$HOSTCFLAGS"
Patrick Georgi643c9e82011-11-04 21:30:49 +0100436 CC="$CC" CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100437 ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000438 --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed
439 $MAKE $JOBS || touch .failed
440 $MAKE install DESTDIR=$DESTDIR || touch .failed
441
442 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200443) > build-libelf/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100444test -r build-libelf/.failed && printf "${RED}failed${NC}\n" || \
445 printf "${green}ok${NC}\n"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000446test -r build-libelf/.failed && exit 1
447fi
448
Stefan Reinauer074d9132009-09-26 16:43:17 +0000449if [ -f build-binutils/.success ]; then
450 printf "Skipping binutils as it is already built\n"
451else
452printf "Building binutils ${BINUTILS_VERSION} ... "
453(
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700454 # What a pain: binutils don't come with configure
455 # script anymore. Create it:
456 cd binutils-${BINUTILS_VERSION}/
457 autoconf
458 cd ..
459 # Now build binutils
Stefan Reinauer074d9132009-09-26 16:43:17 +0000460 cd build-binutils
461 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100462 CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100463 --target=${TARGETARCH} --disable-werror --disable-nls \
464 $USE_GOLD CFLAGS="$HOSTCFLAGS" || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000465 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000466 $MAKE install DESTDIR=$DESTDIR || touch .failed
467 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200468) > build-binutils/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100469test -r build-binutils/.failed && printf "${RED}failed${NC}\n" || \
470 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000471test -r build-binutils/.failed && exit 1
472fi
473
474if [ -f build-gcc/.success ]; then
475 printf "Skipping GCC as it is already built\n"
476else
477printf "Building GCC ${GCC_VERSION} ... "
478(
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700479 # Even worse than binutils: GCC does not come with configure
480 # script anymore, but also enforces an obsolete autoconf version
481 # to create it. This is a poster child of how autotools help make
482 # software portable.
483 cd gcc-${GCC_VERSION}
484 sed '/dnl Ensure exactly this Autoconf version is used/d' \
485 config/override.m4 > config/override.m4.new
486 autoconf_version=`autoconf -V | grep "autoconf" | tr ' ' '\n' | tail -1`
487 sed "s/${GCC_AUTOCONF_VERSION}/${autoconf_version}/g" \
488 config/override.m4.new > config/override.m4
489 autoconf
490 cd ..
491 # Now, finally, we can build gcc:
Stefan Reinauer074d9132009-09-26 16:43:17 +0000492 cd build-gcc
Patrick Georgiba3b0eb2010-09-03 08:53:06 +0000493 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
Stefan Reinauer074d9132009-09-26 16:43:17 +0000494 rm -f .failed
495 # GCC does not honour HOSTCFLAGS at all. CFLAGS are used for
496 # both target and host object files. This is pretty misdesigned.
497 # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
498 # but it does not seem to work properly. At least the host library
499 # libiberty is not compiled with CFLAGS_FOR_BUILD.
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700500 CC="$CC" CFLAGS_FOR_TARGET="-O2" CFLAGS="$HOSTCFLAGS" \
501 CFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000502 --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000503 --target=${TARGETARCH} --disable-werror --disable-shared \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000504 --disable-libssp --disable-bootstrap --disable-nls \
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700505 --disable-libquadmath \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000506 $GCC_OPTIONS --enable-languages="c" $USE_GOLD \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000507 --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000508 --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \
509 --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000510 || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000511 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000512 $MAKE install DESTDIR=$DESTDIR || touch .failed
513 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200514) > build-gcc/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100515test -r build-gcc/.failed && printf "${RED}failed${NC}\n" || \
516 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000517test -r build-gcc/.failed && exit 1
518fi
519
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100520if [ -f build-expat/.success ]; then
521 printf "Skipping Expat as it is already built\n"
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100522elif [ $SKIPPYTHON -eq 1 ]; then
523 printf "Skipping Expat (Python scripting not enabled)\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100524else
525printf "Building Expat ${EXPAT_VERSION} ... "
526(
527 cd build-expat
528 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
529 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100530 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${EXPAT_DIR}/configure --disable-shared \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100531 --prefix=$TARGETDIR --target=${TARGETARCH} || touch .failed
532 $MAKE || touch .failed
533 $MAKE install DESTDIR=$DESTDIR || touch .failed
534 if [ ! -f .failed ]; then touch .success; fi
535) &> build-expat/crossgcc-build.log
536test -r build-expat/.failed && printf "${RED}failed${NC}\n" || \
537 printf "${green}ok${NC}\n"
538test -r build-expat/.failed && exit 1
539fi
540
541
542if [ -f build-python/.success ]; then
543 printf "Skipping Python as it is already built\n"
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100544elif [ $SKIPPYTHON -eq 1 ]; then
545 printf "Skipping Python (Python scripting not enabled)\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100546else
547printf "Building Python ${PYTHON_VERSION} ... "
548(
549 cd build-python
550 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
551 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100552 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100553 --target=${TARGETARCH} || touch .failed
554 $MAKE $JOBS || touch .failed
555 $MAKE install DESTDIR=$DESTDIR || touch .failed
556 if [ ! -f .failed ]; then touch .success; fi
557) &> build-gdb/crossgcc-build.log
558test -r build-python/.failed && printf "${RED}failed${NC}\n" || \
559 printf "${green}ok${NC}\n"
560test -r build-python/.failed && exit 1
561fi
562
563
Stefan Reinauer074d9132009-09-26 16:43:17 +0000564if [ -f build-gdb/.success ]; then
565 printf "Skipping GDB as it is already built\n"
Peter Stugeceacd772011-06-09 04:54:16 +0200566elif [ $SKIPGDB -eq 1 ]; then
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100567 printf "Skipping GDB (GDB support not enabled)\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000568else
569printf "Building GDB ${GDB_VERSION} ... "
570(
571 cd build-gdb
Patrick Georgiba3b0eb2010-09-03 08:53:06 +0000572 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100573 export PYTHONHOME=$DESTDIR$TARGETDIR
Stefan Reinauer074d9132009-09-26 16:43:17 +0000574 rm -f .failed
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100575 LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \
576 -lpthread -ldl -lutil" \
Patrick Georgi643c9e82011-11-04 21:30:49 +0100577 CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100578 ../gdb-${GDB_VERSION}/configure --prefix=$TARGETDIR \
579 --target=${TARGETARCH} --disable-werror --disable-nls
Patrick Georgi73166c72010-04-14 20:42:42 +0000580 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000581 $MAKE install DESTDIR=$DESTDIR || touch .failed
582 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200583) > build-gdb/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100584test -r build-gdb/.failed && printf "${RED}failed${NC}\n" || \
585 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000586test -r build-gdb/.failed && exit 1
587fi
588
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200589if [ -f $IASL_DIR/source/compiler/.success ]; then
Marc Jones2aac3f62011-08-08 16:07:50 -0600590 printf "Skipping IASL as it is already built\n"
591else
592printf "Building IASL ${IASL_VERSION} ... "
593(
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200594 cd $IASL_DIR/source/compiler
Marc Jones2aac3f62011-08-08 16:07:50 -0600595 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
596 rm -f .failed
597 CFLAGS="$HOSTCFLAGS"
Patrick Georgi643c9e82011-11-04 21:30:49 +0100598 $MAKE CC="$CC" || touch .failed
Jonathan A. Kollaschf44bb4f2011-08-11 14:44:55 -0500599 rm -f $DESTDIR$TARGETDIR/bin/iasl || touch .failed
600 cp iasl $DESTDIR$TARGETDIR/bin || touch .failed
Marc Jones2aac3f62011-08-08 16:07:50 -0600601 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200602) > $IASL_DIR/source/compiler/crossgcc-build.log 2>&1
603test -r $IASL_DIR/source/compiler/.failed && printf "${RED}failed${NC}\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100604 printf "${green}ok${NC}\n"
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200605test -r $IASL_DIR/source/compiler/.failed && exit 1
Marc Jones2aac3f62011-08-08 16:07:50 -0600606fi
607
Stefan Reinauer074d9132009-09-26 16:43:17 +0000608if [ $SAVETEMPS -eq 0 ]; then
609 printf "Cleaning up... "
610 rm -rf ${GMP_DIR} build-gmp
611 rm -rf ${MPFR_DIR} build-mpfr
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000612 rm -rf ${MPC_DIR} build-mpc
613 rm -rf ${LIBELF_DIR} build-libelf
Stefan Reinauer074d9132009-09-26 16:43:17 +0000614 rm -rf ${BINUTILS_DIR} build-binutils
615 rm -rf ${GCC_DIR} build-gcc
616 rm -rf ${GDB_DIR} build-gdb
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100617 rm -rf ${EXPAT_DIR} build-expat
618 rm -rf ${PYTHON_DIR} build-python
Marc Jones2aac3f62011-08-08 16:07:50 -0600619 rm -rf ${IASL_DIR}
Stefan Reinauer074d9132009-09-26 16:43:17 +0000620 printf "${green}ok${NC}\n"
621else
622 printf "Leaving temporary files around... ${green}ok${NC}\n"
623fi
624
625printf "\n${green}You can now run your $TARGETARCH cross toolchain from $TARGETDIR.${NC}\n"
626
627