blob: b79c5f6ac9b2500aa8d66edf399947dfe4d954c0 [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 Reinauer2c3cd122011-11-01 21:43:50 +010023CROSSGCC_DATE="November 1st, 2011"
Stefan Reinauer1200ec52011-11-01 22:39:41 +010024CROSSGCC_VERSION="1.07"
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
Patrick Georgi6e61ad32012-05-12 23:19:30 +020036GCC_VERSION=4.6.3
Stefan Reinauer9491b4d2011-10-11 22:37:59 -070037GCC_AUTOCONF_VERSION=2.64
Patrick Georgi6e61ad32012-05-12 23:19:30 +020038BINUTILS_VERSION=2.22
39GDB_VERSION=7.4.1
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"
Patrick Georgi6e61ad32012-05-12 23:19:30 +020052GCC_ARCHIVE="http://ftpmirror.gnu.org/gcc/gcc-${GCC_VERSION}/gcc-core-${GCC_VERSION}.tar.bz2"
53BINUTILS_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
102 printf "${RED}ERROR:${red} Missing toolchain: $1${NC}\n" >&2
103 exit 1
104}
105
Patrick Georgi68df8042011-07-17 11:36:10 +0200106TAR=`searchgnu tar` || exit $?
107PATCH=`searchgnu patch` || exit $?
108MAKE=`searchgnu make` || exit $?
Stefan Reinauer074d9132009-09-26 16:43:17 +0000109
Patrick Georgi5fb2b5c2012-05-12 23:25:23 +0200110searchgnu m4 > /dev/null
111searchgnu bison > /dev/null
112
Stefan Reinauer074d9132009-09-26 16:43:17 +0000113cleanup()
114{
115 printf "Cleaning up temporary files... "
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100116 rm -rf build-* combined gcc-* gmp-* mpfr-* mpc-* libelf-* binutils-*
117 rm -rf gdb-* w32api-* mingwrt-* acpica-* python-* expat-*
Stefan Reinauer074d9132009-09-26 16:43:17 +0000118 printf "${green}ok${NC}\n"
119}
120
121myhelp()
122{
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100123 printf "Usage: $0 [-V] [-c] [-p <platform>] [-d <target directory>] [-D <dest dir>] [-G] [-S]\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000124 printf " $0 [-V|--version]\n"
125 printf " $0 [-h|--help]\n\n"
126
127 printf "Options:\n"
128 printf " [-V|--version] print version number and exit\n"
129 printf " [-h|--help] print this help and exit\n"
130 printf " [-c|--clean] remove temporary files before build\n"
131 printf " [-t|--savetemps] don't remove temporary files after build\n"
Patrick Georgic1a75b12011-11-04 21:37:14 +0100132 printf " [-y|--ccache] Use ccache when building cross compiler\n"
Patrick Georgi73166c72010-04-14 20:42:42 +0000133 printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000134 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
135 printf " (defaults to $TARGETARCH)\n"
136 printf " [-d|--directory <target dir>] target directory to install cross compiler to\n"
137 printf " (defaults to $TARGETDIR)\n\n"
138 printf " [-D|--destdir <dest dir>] destination directory to install cross compiler to\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100139 printf " (for RPM builds, default unset)\n"
140 printf " [-G|--gdb] build GNU debugger\n"
141 printf " [-S|--scripting] build scripting support for GDB\n\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000142}
143
144myversion()
145{
146 # version tag is always printed, so just print the license here
147
148 cat << EOF
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000149Copyright (C) 2008-2010 by coresystems GmbH
Marc Jones2aac3f62011-08-08 16:07:50 -0600150Copyright (C) 2011 by Sage Electronic Engineering
Stefan Reinauer074d9132009-09-26 16:43:17 +0000151
152This program is free software; you can redistribute it and/or modify
153it under the terms of the GNU General Public License as published by
154the Free Software Foundation; version 2 of the License.
155
156This program is distributed in the hope that it will be useful,
157but WITHOUT ANY WARRANTY; without even the implied warranty of
158MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
159GNU General Public License for more details.
160
161EOF
162}
163
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700164printf "${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 +0000165
Patrick Georgi6bba29f2010-01-29 17:40:52 +0000166# Look if we have getopt. If not, build it.
167export PATH=$PATH:.
168getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c
169
Stefan Reinauer074d9132009-09-26 16:43:17 +0000170# parse parameters.. try to find out whether we're running GNU getopt
Peter Stuge09377b72011-08-21 06:24:55 +0200171getoptbrand="`getopt -V | sed -e '1!d' -e 's,^\(......\).*,\1,'`"
172if [ "${getoptbrand}" = "getopt" ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000173 # Detected GNU getopt that supports long options.
Patrick Georgic1a75b12011-11-04 21:37:14 +0100174 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 +0000175 eval set "$args"
176else
177 # Detected non-GNU getopt
Patrick Georgic1a75b12011-11-04 21:37:14 +0100178 args=`getopt Vhcd:p:j:D:tGy $*`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000179 set -- $args
180fi
181
182if [ $? != 0 ]; then
183 myhelp
184 exit 1
185fi
186
187while true ; do
188 case "$1" in
189 -V|--version) shift; myversion; exit 0;;
190 -h|--help) shift; myhelp; exit 0;;
191 -c|--clean) shift; cleanup;;
192 -t|--savetemps) shift; SAVETEMPS=1;;
193 -d|--directory) shift; TARGETDIR="$1"; shift;;
194 -p|--platform) shift; TARGETARCH="$1"; shift;;
195 -D|--destdir) shift; DESTDIR="$1"; shift;;
Patrick Georgi73166c72010-04-14 20:42:42 +0000196 -j|--jobs) shift; JOBS="-j $1"; shift;;
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100197 -G|--gdb) shift; SKIPGDB=0;;
198 -S|--scripting) shift; SKIPPYTHON=0;;
Patrick Georgic1a75b12011-11-04 21:37:14 +0100199 -y|--ccache) shift; USECCACHE=1;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000200 --) shift; break;;
201 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
202 *) break;;
203 esac
204done
205
Peter Stugeceacd772011-06-09 04:54:16 +0200206GDB_PACKAGE="GDB"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100207PYTHON_PACKAGE="PYTHON"
208EXPAT_PACKAGE="EXPAT"
Peter Stugeceacd772011-06-09 04:54:16 +0200209if [ $SKIPGDB -eq 1 ]; then
210 printf "Will skip GDB ... ${green}ok${NC}\n"
Peter Stuge0e8ee812011-08-28 11:04:23 +0200211 GDB_ARCHIVE=""
Peter Stugeceacd772011-06-09 04:54:16 +0200212 GDB_PACKAGE=""
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100213 if [ $SKIPPYTHON -eq 0 ]; then
214 printf "Python scripting needs GDB ... disabling ... ${green}ok${NC}\n"
215 SKIPPYTHON=1
216 fi
217fi
218if [ $SKIPPYTHON -eq 1 ]; then
Jonathan A. Kollasch2d7ab4c2011-11-07 13:05:18 -0600219 PYTHON_ARCHIVE=""
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100220 PYTHON_PACKAGE=""
Jonathan A. Kollasch2d7ab4c2011-11-07 13:05:18 -0600221 EXPAT_ARCHIVE=""
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100222 EXPAT_PACKAGE=""
Peter Stugeceacd772011-06-09 04:54:16 +0200223fi
224
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000225MINGW_ARCHIVES=""
226if [ "$TARGETARCH" = "i386-mingw32" ]; then
227 MINGW_ARCHIVES="$W32API_ARCHIVE $MINGWRT_ARCHIVE"
228fi
229
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700230# coreboot does not like the GOLD linker
231# USE_GOLD="--enable-gold"
232USE_GOLD=""
233GCC_OPTIONS="--enable-lto"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000234
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100235if [ ${GCC_VERSION} = "trunk" ]; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000236 if [ ! -r tarballs/gcc-core-${GCC_VERSION}.tar.bz2 ]; then
237 printf "Pre-Release GCC ${GCC_VERSION}, checking out subversion trunk\n"
238 mkdir -p tarballs/.tmp
239 cd tarballs/.tmp
240 rm -rf gcc-${GCC_VERSION}
241 svn export -q svn://gcc.gnu.org/svn/gcc/trunk gcc-${GCC_VERSION}
242 printf "done. Now creating tar ball...\n"
243 tar cjf ../gcc-core-${GCC_VERSION}.tar.bz2 gcc-${GCC_VERSION}
244 printf "done. Now cleaning up...\n"
245 cd ..
246 rm -rf .tmp
247 cd ..
248 printf "done.\n"
249 fi
250fi
251
Stefan Reinauer074d9132009-09-26 16:43:17 +0000252printf "Downloading tar balls ... \n"
253mkdir -p tarballs
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100254for ARCHIVE in $GMP_ARCHIVE $MPFR_ARCHIVE $MPC_ARCHIVE $LIBELF_ARCHIVE \
255 $GCC_ARCHIVE $BINUTILS_ARCHIVE $GDB_ARCHIVE $MINGW_ARCHIVES \
256 $IASL_ARCHIVE $PYTHON_ARCHIVE $EXPAT_ARCHIVE; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000257 FILE=`basename $ARCHIVE`
258 printf " * $FILE "
259 test -f tarballs/$FILE && printf "(cached)" || (
260 printf "(downloading)"
261 cd tarballs
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200262 wget --no-check-certificate -q $ARCHIVE
Stefan Reinauer074d9132009-09-26 16:43:17 +0000263 )
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100264 test -f tarballs/$FILE || \
Zheng Bao5b209c02012-09-20 16:09:51 +0800265 printf "\n${RED}Failed to download $FILE.${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000266 test -f tarballs/$FILE || exit 1
267 printf "\n"
268done
269printf "Downloaded tar balls ... "
270printf "${green}ok${NC}\n"
271
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000272MINGW_PACKAGES=""
273if [ "$TARGETARCH" = "i386-mingw32" ]; then
274 MINGW_PACKAGES="W32API MINGWRT"
275fi
276
Stefan Reinauer074d9132009-09-26 16:43:17 +0000277printf "Unpacking and patching ... \n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100278for PACKAGE in GMP MPFR MPC LIBELF GCC BINUTILS $PYTHON_PACKAGE \
279 $EXPAT_PACKAGE $GDB_PACKAGE $MINGW_PACKAGES IASL; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000280 archive=$PACKAGE"_ARCHIVE"
Peter Stuge09377b72011-08-21 06:24:55 +0200281 archive="`eval echo '$'$archive`"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000282 dir=$PACKAGE"_DIR"
Peter Stuge09377b72011-08-21 06:24:55 +0200283 dir="`eval echo '$'${dir}`"
284 test -d ${dir} || (
Stefan Reinauer074d9132009-09-26 16:43:17 +0000285 printf " * `basename $archive`\n"
286 FLAGS=zxf
Peter Stuge09377b72011-08-21 06:24:55 +0200287 suffix=`echo $archive | sed 's,.*\.,,'`
288 test "$suffix" = "gz" && FLAGS=zxf
289 test "$suffix" = "bz2" && FLAGS=jxf
290 test "$suffix" = "lzma" && FLAGS="--lzma -xf"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000291 $TAR $FLAGS tarballs/`basename $archive`
Peter Stuge09377b72011-08-21 06:24:55 +0200292 for patch in patches/${dir}_*.patch; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000293 test -r $patch || continue
294 printf " o `basename $patch`\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100295 $PATCH -s -N -p0 < `echo $patch` || \
Zheng Bao5b209c02012-09-20 16:09:51 +0800296 printf "\n${RED}Failed $patch.${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000297 done
298 )
299done
300printf "Unpacked and patched ... "
301printf "${green}ok${NC}\n"
302
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000303if [ "$TARGETARCH" = "i386-mingw32" ]; then
304 mkdir -p $TARGETDIR/i386-mingw32/sys-include
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100305 mv $MINGWRT_DIR/include/* $W32API_DIR/include/* \
306 $TARGETDIR/i386-mingw32/sys-include
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000307fi
308
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700309CC=cc
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000310if [ `uname` = "Darwin" ]; then
311 #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix"
312
313 # generally the OS X compiler can create x64 binaries.
314 # Per default it generated i386 binaries in 10.5 and x64
315 # binaries in 10.6 (even if the kernel is 32bit)
316 # For some weird reason, 10.5 autodetects an ABI=64 though
317 # so we're setting the ABI explicitly here.
318 if [ `sysctl -n hw.optional.x86_64` -eq 1 ]; then
319 OPTIONS="ABI=64"
320 else
321 OPTIONS="ABI=32"
322 fi
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700323
324 # In Xcode 4 the default compiler was switched to gcc-llvm.
325 # However, this compiler fails to compile gcc 4.6.x. As a
326 # workaround it's possible to compile gcc with gcc-4.2 or
327 # clang.
328 if $CC -v 2>&1 | grep -q LLVM; then
329 CC=clang
330 fi
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000331fi
332
Patrick Georgic1a75b12011-11-04 21:37:14 +0100333if [ "$USECCACHE" = 1 ]; then
334 CC="ccache $CC"
335fi
336
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100337mkdir -p build-gmp build-mpfr build-mpc build-libelf build-binutils \
338 build-gcc build-python build-expat
Peter Stugeceacd772011-06-09 04:54:16 +0200339if [ $SKIPGDB -eq 0 ]; then
340 mkdir -p build-gdb
341fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000342if [ -f build-gmp/.success ]; then
343 printf "Skipping GMP as it is already built\n"
344else
345printf "Building GMP ${GMP_VERSION} ... "
346(
347 cd build-gmp
348 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100349 CC="$CC" ../${GMP_DIR}/configure --disable-shared --prefix=$TARGETDIR $OPTIONS \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000350 || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000351 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000352 $MAKE install DESTDIR=$DESTDIR || touch .failed
353 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200354) > build-gmp/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100355test -r build-gmp/.failed && printf "${RED}failed${NC}\n" || \
356 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000357test -r build-gmp/.failed && exit 1
358fi
359
360#if [ "$DESTDIR" != "" -a ! -x $TARGETDIR ]; then
361# # create compat link
362# ln -s $DESTDIR$TARGETDIR $TARGETDIR
363#fi
364
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700365# Now set CFLAGS to match GMP CFLAGS but strip out -pedantic
366# as GCC 4.6.x fails if it's there.
367HOSTCFLAGS=`grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2 |\
368 sed s,-pedantic,,`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000369
370if [ -f build-mpfr/.success ]; then
371 printf "Skipping MPFR as it is already built\n"
372else
373printf "Building MPFR ${MPFR_VERSION} ... "
374(
375 test `uname` = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
376 cd build-mpfr
377 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100378 CC="$CC" ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000379 --infodir=$TARGETDIR/info \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100380 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
381 touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000382 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000383 $MAKE install DESTDIR=$DESTDIR || touch .failed
384
385 # work around build problem of libgmp.la
386 if [ "$DESTDIR" != "" ]; then
387 perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la
388 fi
389
390 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200391) > build-mpfr/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100392test -r build-mpfr/.failed && printf "${RED}failed${NC}\n" || \
393 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000394test -r build-mpfr/.failed && exit 1
395fi
396
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000397if [ -f build-mpc/.success ]; then
398 printf "Skipping MPC as it is already built\n"
399else
400printf "Building MPC ${MPC_VERSION} ... "
401(
402 #test `uname` = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
403 cd build-mpc
404 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100405 CC="$CC" ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000406 --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100407 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
408 touch .failed
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000409 $MAKE $JOBS || touch .failed
410 $MAKE install DESTDIR=$DESTDIR || touch .failed
411
412 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200413) > build-mpc/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100414test -r build-mpc/.failed && printf "${RED}failed${NC}\n" || \
415 printf "${green}ok${NC}\n"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000416test -r build-mpc/.failed && exit 1
417fi
418
419if [ -f build-libelf/.success ]; then
420 printf "Skipping libelf as it is already built\n"
421else
422printf "Building libelf ${LIBELF_VERSION} ... "
423(
424 cd build-libelf
425 rm -f .failed
426 echo "$HOSTCFLAGS"
Patrick Georgi643c9e82011-11-04 21:30:49 +0100427 CC="$CC" CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100428 ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000429 --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed
430 $MAKE $JOBS || touch .failed
431 $MAKE install DESTDIR=$DESTDIR || touch .failed
432
433 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200434) > build-libelf/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100435test -r build-libelf/.failed && printf "${RED}failed${NC}\n" || \
436 printf "${green}ok${NC}\n"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000437test -r build-libelf/.failed && exit 1
438fi
439
Stefan Reinauer074d9132009-09-26 16:43:17 +0000440if [ -f build-binutils/.success ]; then
441 printf "Skipping binutils as it is already built\n"
442else
443printf "Building binutils ${BINUTILS_VERSION} ... "
444(
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700445 # What a pain: binutils don't come with configure
446 # script anymore. Create it:
447 cd binutils-${BINUTILS_VERSION}/
448 autoconf
449 cd ..
450 # Now build binutils
Stefan Reinauer074d9132009-09-26 16:43:17 +0000451 cd build-binutils
452 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100453 CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100454 --target=${TARGETARCH} --disable-werror --disable-nls \
455 $USE_GOLD CFLAGS="$HOSTCFLAGS" || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000456 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000457 $MAKE install DESTDIR=$DESTDIR || touch .failed
458 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200459) > build-binutils/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100460test -r build-binutils/.failed && printf "${RED}failed${NC}\n" || \
461 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000462test -r build-binutils/.failed && exit 1
463fi
464
465if [ -f build-gcc/.success ]; then
466 printf "Skipping GCC as it is already built\n"
467else
468printf "Building GCC ${GCC_VERSION} ... "
469(
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700470 # Even worse than binutils: GCC does not come with configure
471 # script anymore, but also enforces an obsolete autoconf version
472 # to create it. This is a poster child of how autotools help make
473 # software portable.
474 cd gcc-${GCC_VERSION}
475 sed '/dnl Ensure exactly this Autoconf version is used/d' \
476 config/override.m4 > config/override.m4.new
477 autoconf_version=`autoconf -V | grep "autoconf" | tr ' ' '\n' | tail -1`
478 sed "s/${GCC_AUTOCONF_VERSION}/${autoconf_version}/g" \
479 config/override.m4.new > config/override.m4
480 autoconf
481 cd ..
482 # Now, finally, we can build gcc:
Stefan Reinauer074d9132009-09-26 16:43:17 +0000483 cd build-gcc
Patrick Georgiba3b0eb2010-09-03 08:53:06 +0000484 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
Stefan Reinauer074d9132009-09-26 16:43:17 +0000485 rm -f .failed
486 # GCC does not honour HOSTCFLAGS at all. CFLAGS are used for
487 # both target and host object files. This is pretty misdesigned.
488 # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
489 # but it does not seem to work properly. At least the host library
490 # libiberty is not compiled with CFLAGS_FOR_BUILD.
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700491 CC="$CC" CFLAGS_FOR_TARGET="-O2" CFLAGS="$HOSTCFLAGS" \
492 CFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000493 --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000494 --target=${TARGETARCH} --disable-werror --disable-shared \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000495 --disable-libssp --disable-bootstrap --disable-nls \
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700496 --disable-libquadmath \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000497 $GCC_OPTIONS --enable-languages="c" $USE_GOLD \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000498 --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000499 --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \
500 --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000501 || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000502 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000503 $MAKE install DESTDIR=$DESTDIR || touch .failed
504 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200505) > build-gcc/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100506test -r build-gcc/.failed && printf "${RED}failed${NC}\n" || \
507 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000508test -r build-gcc/.failed && exit 1
509fi
510
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100511if [ -f build-expat/.success ]; then
512 printf "Skipping Expat as it is already built\n"
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100513elif [ $SKIPPYTHON -eq 1 ]; then
514 printf "Skipping Expat (Python scripting not enabled)\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100515else
516printf "Building Expat ${EXPAT_VERSION} ... "
517(
518 cd build-expat
519 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
520 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100521 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${EXPAT_DIR}/configure --disable-shared \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100522 --prefix=$TARGETDIR --target=${TARGETARCH} || touch .failed
523 $MAKE || touch .failed
524 $MAKE install DESTDIR=$DESTDIR || touch .failed
525 if [ ! -f .failed ]; then touch .success; fi
526) &> build-expat/crossgcc-build.log
527test -r build-expat/.failed && printf "${RED}failed${NC}\n" || \
528 printf "${green}ok${NC}\n"
529test -r build-expat/.failed && exit 1
530fi
531
532
533if [ -f build-python/.success ]; then
534 printf "Skipping Python as it is already built\n"
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100535elif [ $SKIPPYTHON -eq 1 ]; then
536 printf "Skipping Python (Python scripting not enabled)\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100537else
538printf "Building Python ${PYTHON_VERSION} ... "
539(
540 cd build-python
541 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
542 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100543 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100544 --target=${TARGETARCH} || touch .failed
545 $MAKE $JOBS || touch .failed
546 $MAKE install DESTDIR=$DESTDIR || touch .failed
547 if [ ! -f .failed ]; then touch .success; fi
548) &> build-gdb/crossgcc-build.log
549test -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
Patrick Georgiba3b0eb2010-09-03 08:53:06 +0000563 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100564 export PYTHONHOME=$DESTDIR$TARGETDIR
Stefan Reinauer074d9132009-09-26 16:43:17 +0000565 rm -f .failed
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100566 LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \
567 -lpthread -ldl -lutil" \
Patrick Georgi643c9e82011-11-04 21:30:49 +0100568 CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100569 ../gdb-${GDB_VERSION}/configure --prefix=$TARGETDIR \
570 --target=${TARGETARCH} --disable-werror --disable-nls
Patrick Georgi73166c72010-04-14 20:42:42 +0000571 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000572 $MAKE install DESTDIR=$DESTDIR || touch .failed
573 if [ ! -f .failed ]; then touch .success; fi
Peter Stuge09377b72011-08-21 06:24:55 +0200574) > build-gdb/crossgcc-build.log 2>&1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100575test -r build-gdb/.failed && printf "${RED}failed${NC}\n" || \
576 printf "${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000577test -r build-gdb/.failed && exit 1
578fi
579
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200580if [ -f $IASL_DIR/source/compiler/.success ]; then
Marc Jones2aac3f62011-08-08 16:07:50 -0600581 printf "Skipping IASL as it is already built\n"
582else
583printf "Building IASL ${IASL_VERSION} ... "
584(
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200585 cd $IASL_DIR/source/compiler
Marc Jones2aac3f62011-08-08 16:07:50 -0600586 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
587 rm -f .failed
588 CFLAGS="$HOSTCFLAGS"
Patrick Georgi643c9e82011-11-04 21:30:49 +0100589 $MAKE CC="$CC" || touch .failed
Jonathan A. Kollaschf44bb4f2011-08-11 14:44:55 -0500590 rm -f $DESTDIR$TARGETDIR/bin/iasl || touch .failed
591 cp iasl $DESTDIR$TARGETDIR/bin || touch .failed
Marc Jones2aac3f62011-08-08 16:07:50 -0600592 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200593) > $IASL_DIR/source/compiler/crossgcc-build.log 2>&1
594test -r $IASL_DIR/source/compiler/.failed && printf "${RED}failed${NC}\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100595 printf "${green}ok${NC}\n"
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200596test -r $IASL_DIR/source/compiler/.failed && exit 1
Marc Jones2aac3f62011-08-08 16:07:50 -0600597fi
598
Stefan Reinauer074d9132009-09-26 16:43:17 +0000599if [ $SAVETEMPS -eq 0 ]; then
600 printf "Cleaning up... "
601 rm -rf ${GMP_DIR} build-gmp
602 rm -rf ${MPFR_DIR} build-mpfr
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000603 rm -rf ${MPC_DIR} build-mpc
604 rm -rf ${LIBELF_DIR} build-libelf
Stefan Reinauer074d9132009-09-26 16:43:17 +0000605 rm -rf ${BINUTILS_DIR} build-binutils
606 rm -rf ${GCC_DIR} build-gcc
607 rm -rf ${GDB_DIR} build-gdb
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100608 rm -rf ${EXPAT_DIR} build-expat
609 rm -rf ${PYTHON_DIR} build-python
Marc Jones2aac3f62011-08-08 16:07:50 -0600610 rm -rf ${IASL_DIR}
Stefan Reinauer074d9132009-09-26 16:43:17 +0000611 printf "${green}ok${NC}\n"
612else
613 printf "Leaving temporary files around... ${green}ok${NC}\n"
614fi
615
616printf "\n${green}You can now run your $TARGETARCH cross toolchain from $TARGETDIR.${NC}\n"
617
618