blob: c69e7cd2196ce506b445159bd2b8ee961588567f [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
Patrick Georgi198d23c2012-12-08 08:02:44 +010081normalize_dirs()
82{
83 mkdir -p $DESTDIR$TARGETDIR/lib
84 test -d $DESTDIR$TARGETDIR/lib32 && mv $DESTDIR$TARGETDIR/lib32/* $DESTDIR$TARGETDIR/lib
85 test -d $DESTDIR$TARGETDIR/lib64 && mv $DESTDIR$TARGETDIR/lib64/* $DESTDIR$TARGETDIR/lib
86 rmdir -p $DESTDIR$TARGETDIR/lib32 $DESTDIR$TARGETDIR/lib64
87
88 perl -pi -e "s,/lib32,/lib," $DESTDIR$TARGETDIR/lib/*.la
89 perl -pi -e "s,/lib64,/lib," $DESTDIR$TARGETDIR/lib/*.la
90}
91
Stefan Reinauer074d9132009-09-26 16:43:17 +000092searchgnu()
93{
94 # $1 short name
95 # result: GNU version of that tool on stdout
96 # or no output if no GNU version was found
97 for i in "$1" "g$1" "gnu$1"; do
98 if test -x "`which $i 2>/dev/null`"; then
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010099 if test `$i --version 2>/dev/null |grep -c GNU` \
100 -gt 0; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000101 echo $i
102 return
103 fi
104 fi
105 done
Zheng Bao36156ff2012-09-28 16:18:58 +0800106 # A workaround for XxxBSD, whose nongnu patch and tar also work.
107 if [ `uname` = "FreeBSD" -o `uname` = "NetBSD" ]; then
108 if [ $1 != "make" ]; then
109 if test -x "`which $1 2>/dev/null`"; then
110 echo $1
111 return
112 fi
113 fi
114 fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000115 printf "${RED}ERROR:${red} Missing toolchain: $1${NC}\n" >&2
116 exit 1
117}
118
Patrick Georgi68df8042011-07-17 11:36:10 +0200119TAR=`searchgnu tar` || exit $?
120PATCH=`searchgnu patch` || exit $?
121MAKE=`searchgnu make` || exit $?
Stefan Reinauer074d9132009-09-26 16:43:17 +0000122
Patrick Georgi5fb2b5c2012-05-12 23:25:23 +0200123searchgnu m4 > /dev/null
124searchgnu bison > /dev/null
Patrick Georgi0a3f2392012-11-20 12:04:32 +0100125
126if ! flex --version > /dev/null 2> /dev/null; then
127 printf "${RED}ERROR:${red} Missing toolchain: flex${NC}\n" >&2
128 exit 1
129fi
Patrick Georgi5fb2b5c2012-05-12 23:25:23 +0200130
Stefan Reinauer074d9132009-09-26 16:43:17 +0000131cleanup()
132{
133 printf "Cleaning up temporary files... "
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100134 rm -rf build-* combined gcc-* gmp-* mpfr-* mpc-* libelf-* binutils-*
Patrick Georgi969cd932012-12-07 13:13:53 +0100135 rm -rf gdb-* acpica-* python-* expat-*
Stefan Reinauer074d9132009-09-26 16:43:17 +0000136 printf "${green}ok${NC}\n"
137}
138
139myhelp()
140{
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100141 printf "Usage: $0 [-V] [-c] [-p <platform>] [-d <target directory>] [-D <dest dir>] [-G] [-S]\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000142 printf " $0 [-V|--version]\n"
143 printf " $0 [-h|--help]\n\n"
144
145 printf "Options:\n"
146 printf " [-V|--version] print version number and exit\n"
147 printf " [-h|--help] print this help and exit\n"
148 printf " [-c|--clean] remove temporary files before build\n"
149 printf " [-t|--savetemps] don't remove temporary files after build\n"
Patrick Georgic1a75b12011-11-04 21:37:14 +0100150 printf " [-y|--ccache] Use ccache when building cross compiler\n"
Patrick Georgi73166c72010-04-14 20:42:42 +0000151 printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000152 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
153 printf " (defaults to $TARGETARCH)\n"
154 printf " [-d|--directory <target dir>] target directory to install cross compiler to\n"
155 printf " (defaults to $TARGETDIR)\n\n"
156 printf " [-D|--destdir <dest dir>] destination directory to install cross compiler to\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100157 printf " (for RPM builds, default unset)\n"
158 printf " [-G|--gdb] build GNU debugger\n"
159 printf " [-S|--scripting] build scripting support for GDB\n\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000160}
161
162myversion()
163{
164 # version tag is always printed, so just print the license here
165
166 cat << EOF
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000167Copyright (C) 2008-2010 by coresystems GmbH
Marc Jones2aac3f62011-08-08 16:07:50 -0600168Copyright (C) 2011 by Sage Electronic Engineering
Stefan Reinauer074d9132009-09-26 16:43:17 +0000169
170This program is free software; you can redistribute it and/or modify
171it under the terms of the GNU General Public License as published by
172the Free Software Foundation; version 2 of the License.
173
174This program is distributed in the hope that it will be useful,
175but WITHOUT ANY WARRANTY; without even the implied warranty of
176MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
177GNU General Public License for more details.
178
179EOF
180}
181
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700182printf "${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 +0000183
Patrick Georgi6bba29f2010-01-29 17:40:52 +0000184# Look if we have getopt. If not, build it.
185export PATH=$PATH:.
186getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c
187
Stefan Reinauer074d9132009-09-26 16:43:17 +0000188# parse parameters.. try to find out whether we're running GNU getopt
Peter Stuge09377b72011-08-21 06:24:55 +0200189getoptbrand="`getopt -V | sed -e '1!d' -e 's,^\(......\).*,\1,'`"
190if [ "${getoptbrand}" = "getopt" ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000191 # Detected GNU getopt that supports long options.
Patrick Georgic1a75b12011-11-04 21:37:14 +0100192 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 +0000193 eval set "$args"
194else
195 # Detected non-GNU getopt
Patrick Georgic1a75b12011-11-04 21:37:14 +0100196 args=`getopt Vhcd:p:j:D:tGy $*`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000197 set -- $args
198fi
199
200if [ $? != 0 ]; then
201 myhelp
202 exit 1
203fi
204
205while true ; do
206 case "$1" in
207 -V|--version) shift; myversion; exit 0;;
208 -h|--help) shift; myhelp; exit 0;;
209 -c|--clean) shift; cleanup;;
210 -t|--savetemps) shift; SAVETEMPS=1;;
211 -d|--directory) shift; TARGETDIR="$1"; shift;;
212 -p|--platform) shift; TARGETARCH="$1"; shift;;
213 -D|--destdir) shift; DESTDIR="$1"; shift;;
Patrick Georgi73166c72010-04-14 20:42:42 +0000214 -j|--jobs) shift; JOBS="-j $1"; shift;;
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100215 -G|--gdb) shift; SKIPGDB=0;;
216 -S|--scripting) shift; SKIPPYTHON=0;;
Patrick Georgic1a75b12011-11-04 21:37:14 +0100217 -y|--ccache) shift; USECCACHE=1;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000218 --) shift; break;;
219 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
220 *) break;;
221 esac
222done
223
Peter Stugeceacd772011-06-09 04:54:16 +0200224GDB_PACKAGE="GDB"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100225PYTHON_PACKAGE="PYTHON"
226EXPAT_PACKAGE="EXPAT"
Peter Stugeceacd772011-06-09 04:54:16 +0200227if [ $SKIPGDB -eq 1 ]; then
228 printf "Will skip GDB ... ${green}ok${NC}\n"
Peter Stuge0e8ee812011-08-28 11:04:23 +0200229 GDB_ARCHIVE=""
Peter Stugeceacd772011-06-09 04:54:16 +0200230 GDB_PACKAGE=""
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100231 if [ $SKIPPYTHON -eq 0 ]; then
232 printf "Python scripting needs GDB ... disabling ... ${green}ok${NC}\n"
233 SKIPPYTHON=1
234 fi
235fi
236if [ $SKIPPYTHON -eq 1 ]; then
Jonathan A. Kollasch2d7ab4c2011-11-07 13:05:18 -0600237 PYTHON_ARCHIVE=""
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100238 PYTHON_PACKAGE=""
Jonathan A. Kollasch2d7ab4c2011-11-07 13:05:18 -0600239 EXPAT_ARCHIVE=""
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100240 EXPAT_PACKAGE=""
Peter Stugeceacd772011-06-09 04:54:16 +0200241fi
242
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700243# coreboot does not like the GOLD linker
244# USE_GOLD="--enable-gold"
245USE_GOLD=""
246GCC_OPTIONS="--enable-lto"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000247
Stefan Reinauer074d9132009-09-26 16:43:17 +0000248printf "Downloading tar balls ... \n"
249mkdir -p tarballs
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100250for ARCHIVE in $GMP_ARCHIVE $MPFR_ARCHIVE $MPC_ARCHIVE $LIBELF_ARCHIVE \
Patrick Georgi969cd932012-12-07 13:13:53 +0100251 $GCC_ARCHIVE $BINUTILS_ARCHIVE $GDB_ARCHIVE \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100252 $IASL_ARCHIVE $PYTHON_ARCHIVE $EXPAT_ARCHIVE; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000253 FILE=`basename $ARCHIVE`
254 printf " * $FILE "
255 test -f tarballs/$FILE && printf "(cached)" || (
256 printf "(downloading)"
257 cd tarballs
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200258 wget --no-check-certificate -q $ARCHIVE
Stefan Reinauer074d9132009-09-26 16:43:17 +0000259 )
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100260 test -f tarballs/$FILE || \
Zheng Bao5b209c02012-09-20 16:09:51 +0800261 printf "\n${RED}Failed to download $FILE.${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000262 test -f tarballs/$FILE || exit 1
263 printf "\n"
264done
265printf "Downloaded tar balls ... "
266printf "${green}ok${NC}\n"
267
268printf "Unpacking and patching ... \n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100269for PACKAGE in GMP MPFR MPC LIBELF GCC BINUTILS $PYTHON_PACKAGE \
Patrick Georgi969cd932012-12-07 13:13:53 +0100270 $EXPAT_PACKAGE $GDB_PACKAGE IASL; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000271 archive=$PACKAGE"_ARCHIVE"
Peter Stuge09377b72011-08-21 06:24:55 +0200272 archive="`eval echo '$'$archive`"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000273 dir=$PACKAGE"_DIR"
Peter Stuge09377b72011-08-21 06:24:55 +0200274 dir="`eval echo '$'${dir}`"
275 test -d ${dir} || (
Stefan Reinauer074d9132009-09-26 16:43:17 +0000276 printf " * `basename $archive`\n"
277 FLAGS=zxf
Peter Stuge09377b72011-08-21 06:24:55 +0200278 suffix=`echo $archive | sed 's,.*\.,,'`
279 test "$suffix" = "gz" && FLAGS=zxf
280 test "$suffix" = "bz2" && FLAGS=jxf
281 test "$suffix" = "lzma" && FLAGS="--lzma -xf"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000282 $TAR $FLAGS tarballs/`basename $archive`
Peter Stuge09377b72011-08-21 06:24:55 +0200283 for patch in patches/${dir}_*.patch; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000284 test -r $patch || continue
285 printf " o `basename $patch`\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100286 $PATCH -s -N -p0 < `echo $patch` || \
Zheng Bao5b209c02012-09-20 16:09:51 +0800287 printf "\n${RED}Failed $patch.${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000288 done
289 )
290done
291printf "Unpacked and patched ... "
292printf "${green}ok${NC}\n"
293
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700294CC=cc
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000295if [ `uname` = "Darwin" ]; then
296 #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix"
297
298 # generally the OS X compiler can create x64 binaries.
299 # Per default it generated i386 binaries in 10.5 and x64
300 # binaries in 10.6 (even if the kernel is 32bit)
301 # For some weird reason, 10.5 autodetects an ABI=64 though
302 # so we're setting the ABI explicitly here.
Zheng Bao04ceed62012-10-23 19:41:25 +0800303 if [ `sysctl -n hw.optional.x86_64 2>/dev/null` -eq 1 ] 2>/dev/null; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000304 OPTIONS="ABI=64"
305 else
306 OPTIONS="ABI=32"
307 fi
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700308
Stefan Reinauer4266b922012-12-05 16:18:32 -0800309 # In Xcode 4.5.2 the default compiler is clang.
310 # However, this compiler fails to compile gcc 4.7.x. As a
311 # workaround it's possible to compile gcc with llvm-gcc.
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700312 if $CC -v 2>&1 | grep -q LLVM; then
Stefan Reinauer4266b922012-12-05 16:18:32 -0800313 CC=llvm-gcc
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700314 fi
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000315fi
316
Patrick Georgic1a75b12011-11-04 21:37:14 +0100317if [ "$USECCACHE" = 1 ]; then
318 CC="ccache $CC"
319fi
320
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100321mkdir -p build-gmp build-mpfr build-mpc build-libelf build-binutils \
322 build-gcc build-python build-expat
Stefan Reinauer16bd7892012-12-07 23:57:01 +0100323
324mkdir -p $DESTDIR$TARGETDIR/bin
325export PATH=$DESTDIR$TARGETDIR/bin:$PATH
326
Peter Stugeceacd772011-06-09 04:54:16 +0200327if [ $SKIPGDB -eq 0 ]; then
328 mkdir -p build-gdb
329fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000330if [ -f build-gmp/.success ]; then
331 printf "Skipping GMP as it is already built\n"
332else
333printf "Building GMP ${GMP_VERSION} ... "
334(
335 cd build-gmp
336 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100337 CC="$CC" ../${GMP_DIR}/configure --disable-shared --prefix=$TARGETDIR $OPTIONS \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000338 || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000339 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000340 $MAKE install DESTDIR=$DESTDIR || touch .failed
Patrick Georgi198d23c2012-12-08 08:02:44 +0100341
342 normalize_dirs
343
Stefan Reinauer074d9132009-09-26 16:43:17 +0000344 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200345) > build-gmp/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100346test -r build-gmp/.failed && printf "${RED}failed${NC}\n" || \
347 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000348test -r build-gmp/.failed && exit 1
349fi
350
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700351# Now set CFLAGS to match GMP CFLAGS but strip out -pedantic
352# as GCC 4.6.x fails if it's there.
353HOSTCFLAGS=`grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2 |\
354 sed s,-pedantic,,`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000355
356if [ -f build-mpfr/.success ]; then
357 printf "Skipping MPFR as it is already built\n"
358else
359printf "Building MPFR ${MPFR_VERSION} ... "
360(
361 test `uname` = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
362 cd build-mpfr
363 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100364 CC="$CC" ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000365 --infodir=$TARGETDIR/info \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100366 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
367 touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000368 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000369 $MAKE install DESTDIR=$DESTDIR || touch .failed
370
Patrick Georgi198d23c2012-12-08 08:02:44 +0100371 normalize_dirs
372
Stefan Reinauer074d9132009-09-26 16:43:17 +0000373 # work around build problem of libgmp.la
374 if [ "$DESTDIR" != "" ]; then
375 perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la
376 fi
377
378 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200379) > build-mpfr/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100380test -r build-mpfr/.failed && printf "${RED}failed${NC}\n" || \
381 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000382test -r build-mpfr/.failed && exit 1
383fi
384
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000385if [ -f build-mpc/.success ]; then
386 printf "Skipping MPC as it is already built\n"
387else
388printf "Building MPC ${MPC_VERSION} ... "
389(
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000390 cd build-mpc
391 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100392 CC="$CC" ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000393 --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100394 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
395 touch .failed
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000396 $MAKE $JOBS || touch .failed
397 $MAKE install DESTDIR=$DESTDIR || touch .failed
398
Patrick Georgi198d23c2012-12-08 08:02:44 +0100399 normalize_dirs
400
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000401 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200402) > build-mpc/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100403test -r build-mpc/.failed && printf "${RED}failed${NC}\n" || \
404 printf "${green}ok${NC}\n"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000405test -r build-mpc/.failed && exit 1
406fi
407
408if [ -f build-libelf/.success ]; then
409 printf "Skipping libelf as it is already built\n"
410else
411printf "Building libelf ${LIBELF_VERSION} ... "
412(
413 cd build-libelf
414 rm -f .failed
415 echo "$HOSTCFLAGS"
Patrick Georgi643c9e82011-11-04 21:30:49 +0100416 CC="$CC" CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100417 ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000418 --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed
419 $MAKE $JOBS || touch .failed
420 $MAKE install DESTDIR=$DESTDIR || touch .failed
421
Patrick Georgi198d23c2012-12-08 08:02:44 +0100422 normalize_dirs
423
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000424 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200425) > build-libelf/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100426test -r build-libelf/.failed && printf "${RED}failed${NC}\n" || \
427 printf "${green}ok${NC}\n"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000428test -r build-libelf/.failed && exit 1
429fi
430
Stefan Reinauer074d9132009-09-26 16:43:17 +0000431if [ -f build-binutils/.success ]; then
432 printf "Skipping binutils as it is already built\n"
433else
434printf "Building binutils ${BINUTILS_VERSION} ... "
435(
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700436 # What a pain: binutils don't come with configure
437 # script anymore. Create it:
438 cd binutils-${BINUTILS_VERSION}/
439 autoconf
440 cd ..
441 # Now build binutils
Stefan Reinauer074d9132009-09-26 16:43:17 +0000442 cd build-binutils
443 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100444 CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100445 --target=${TARGETARCH} --disable-werror --disable-nls \
446 $USE_GOLD CFLAGS="$HOSTCFLAGS" || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000447 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000448 $MAKE install DESTDIR=$DESTDIR || touch .failed
449 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200450) > build-binutils/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100451test -r build-binutils/.failed && printf "${RED}failed${NC}\n" || \
452 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000453test -r build-binutils/.failed && exit 1
454fi
455
456if [ -f build-gcc/.success ]; then
457 printf "Skipping GCC as it is already built\n"
458else
459printf "Building GCC ${GCC_VERSION} ... "
460(
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700461 # Even worse than binutils: GCC does not come with configure
462 # script anymore, but also enforces an obsolete autoconf version
463 # to create it. This is a poster child of how autotools help make
464 # software portable.
465 cd gcc-${GCC_VERSION}
466 sed '/dnl Ensure exactly this Autoconf version is used/d' \
467 config/override.m4 > config/override.m4.new
468 autoconf_version=`autoconf -V | grep "autoconf" | tr ' ' '\n' | tail -1`
469 sed "s/${GCC_AUTOCONF_VERSION}/${autoconf_version}/g" \
470 config/override.m4.new > config/override.m4
471 autoconf
472 cd ..
473 # Now, finally, we can build gcc:
Stefan Reinauer074d9132009-09-26 16:43:17 +0000474 cd build-gcc
475 rm -f .failed
476 # GCC does not honour HOSTCFLAGS at all. CFLAGS are used for
477 # both target and host object files. This is pretty misdesigned.
478 # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
479 # but it does not seem to work properly. At least the host library
480 # libiberty is not compiled with CFLAGS_FOR_BUILD.
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700481 CC="$CC" CFLAGS_FOR_TARGET="-O2" CFLAGS="$HOSTCFLAGS" \
482 CFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000483 --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000484 --target=${TARGETARCH} --disable-werror --disable-shared \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000485 --disable-libssp --disable-bootstrap --disable-nls \
Patrick Georgi969cd932012-12-07 13:13:53 +0100486 --disable-libquadmath --without-headers \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000487 $GCC_OPTIONS --enable-languages="c" $USE_GOLD \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000488 --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000489 --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \
490 --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000491 || touch .failed
Patrick Georgi969cd932012-12-07 13:13:53 +0100492 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-gcc || touch .failed
493 $MAKE install-gcc DESTDIR=$DESTDIR || touch .failed
494
495 if [ "`echo $TARGETARCH | grep -c -- -mingw32`" -eq 0 ]; then
496 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-target-libgcc || touch .failed
497 $MAKE install-target-libgcc DESTDIR=$DESTDIR || touch .failed
498 fi
499
Stefan Reinauer074d9132009-09-26 16:43:17 +0000500 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200501) > build-gcc/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100502test -r build-gcc/.failed && printf "${RED}failed${NC}\n" || \
503 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000504test -r build-gcc/.failed && exit 1
505fi
506
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100507if [ -f build-expat/.success ]; then
508 printf "Skipping Expat as it is already built\n"
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100509elif [ $SKIPPYTHON -eq 1 ]; then
510 printf "Skipping Expat (Python scripting not enabled)\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100511else
512printf "Building Expat ${EXPAT_VERSION} ... "
513(
514 cd build-expat
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100515 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100516 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${EXPAT_DIR}/configure --disable-shared \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100517 --prefix=$TARGETDIR --target=${TARGETARCH} || touch .failed
518 $MAKE || touch .failed
519 $MAKE install DESTDIR=$DESTDIR || touch .failed
Patrick Georgi198d23c2012-12-08 08:02:44 +0100520
521 normalize_dirs
522
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100523 if [ ! -f .failed ]; then touch .success; fi
Idwer Vollering336db542012-11-01 23:03:46 +0100524) > build-expat/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100525test -r build-expat/.failed && printf "${RED}failed${NC}\n" || \
526 printf "${green}ok${NC}\n"
527test -r build-expat/.failed && exit 1
528fi
529
530
531if [ -f build-python/.success ]; then
532 printf "Skipping Python as it is already built\n"
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100533elif [ $SKIPPYTHON -eq 1 ]; then
534 printf "Skipping Python (Python scripting not enabled)\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100535else
536printf "Building Python ${PYTHON_VERSION} ... "
537(
538 cd build-python
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100539 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100540 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100541 --target=${TARGETARCH} || touch .failed
542 $MAKE $JOBS || touch .failed
543 $MAKE install DESTDIR=$DESTDIR || touch .failed
Patrick Georgi198d23c2012-12-08 08:02:44 +0100544
545 normalize_dirs
546
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100547 if [ ! -f .failed ]; then touch .success; fi
Idwer Vollering336db542012-11-01 23:03:46 +0100548) > build-python/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100549test -r build-python/.failed && printf "${RED}failed${NC}\n" || \
550 printf "${green}ok${NC}\n"
551test -r build-python/.failed && exit 1
552fi
553
554
Stefan Reinauer074d9132009-09-26 16:43:17 +0000555if [ -f build-gdb/.success ]; then
556 printf "Skipping GDB as it is already built\n"
Peter Stugeceacd772011-06-09 04:54:16 +0200557elif [ $SKIPGDB -eq 1 ]; then
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100558 printf "Skipping GDB (GDB support not enabled)\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000559else
560printf "Building GDB ${GDB_VERSION} ... "
561(
562 cd build-gdb
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100563 export PYTHONHOME=$DESTDIR$TARGETDIR
Stefan Reinauer074d9132009-09-26 16:43:17 +0000564 rm -f .failed
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100565 LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \
566 -lpthread -ldl -lutil" \
Patrick Georgi643c9e82011-11-04 21:30:49 +0100567 CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100568 ../gdb-${GDB_VERSION}/configure --prefix=$TARGETDIR \
569 --target=${TARGETARCH} --disable-werror --disable-nls
Patrick Georgi73166c72010-04-14 20:42:42 +0000570 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000571 $MAKE install DESTDIR=$DESTDIR || touch .failed
572 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200573) > build-gdb/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100574test -r build-gdb/.failed && printf "${RED}failed${NC}\n" || \
575 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000576test -r build-gdb/.failed && exit 1
577fi
578
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200579if [ -f $IASL_DIR/source/compiler/.success ]; then
Marc Jones2aac3f62011-08-08 16:07:50 -0600580 printf "Skipping IASL as it is already built\n"
581else
582printf "Building IASL ${IASL_VERSION} ... "
583(
Idwer Vollering6b11c8b2012-11-15 21:14:36 +0100584 cd $IASL_DIR/generate/unix
Stefan Reinauer4266b922012-12-05 16:18:32 -0800585 rm -f .failed
Marc Jones2aac3f62011-08-08 16:07:50 -0600586 CFLAGS="$HOSTCFLAGS"
Stefan Reinauer4266b922012-12-05 16:18:32 -0800587 $MAKE CC="$CC" iasl || touch .failed
588 rm -f $DESTDIR$TARGETDIR/bin/iasl || touch .failed
589 if [ -d bin32 ]; then cp bin32/iasl $DESTDIR$TARGETDIR/bin || touch .failed ; fi
590 if [ -d bin64 ]; then cp bin64/iasl $DESTDIR$TARGETDIR/bin || touch .failed ; fi
591 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200592) > $IASL_DIR/source/compiler/crossgcc-build.log 2>&1
Stefan Reinauer4266b922012-12-05 16:18:32 -0800593test -r $IASL_DIR/generate/unix/.failed && printf "${RED}failed${NC}\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100594 printf "${green}ok${NC}\n"
Stefan Reinauer4266b922012-12-05 16:18:32 -0800595test -r $IASL_DIR/generate/unix/.failed && exit 1
Marc Jones2aac3f62011-08-08 16:07:50 -0600596fi
597
Stefan Reinauer074d9132009-09-26 16:43:17 +0000598if [ $SAVETEMPS -eq 0 ]; then
599 printf "Cleaning up... "
600 rm -rf ${GMP_DIR} build-gmp
601 rm -rf ${MPFR_DIR} build-mpfr
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000602 rm -rf ${MPC_DIR} build-mpc
603 rm -rf ${LIBELF_DIR} build-libelf
Stefan Reinauer074d9132009-09-26 16:43:17 +0000604 rm -rf ${BINUTILS_DIR} build-binutils
605 rm -rf ${GCC_DIR} build-gcc
606 rm -rf ${GDB_DIR} build-gdb
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100607 rm -rf ${EXPAT_DIR} build-expat
608 rm -rf ${PYTHON_DIR} build-python
Marc Jones2aac3f62011-08-08 16:07:50 -0600609 rm -rf ${IASL_DIR}
Stefan Reinauer074d9132009-09-26 16:43:17 +0000610 printf "${green}ok${NC}\n"
611else
612 printf "Leaving temporary files around... ${green}ok${NC}\n"
613fi
614
615printf "\n${green}You can now run your $TARGETARCH cross toolchain from $TARGETDIR.${NC}\n"
616
617