blob: bca309c00c135d09626d2aa5290977bbfb2a06ca [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
Paul Menzela46a7122013-02-23 18:37:27 +010020# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
Stefan Reinauer074d9132009-09-26 16:43:17 +000021#
22
Patrick Georgi8135dba2015-03-17 21:05:20 +010023cd `dirname $0`
24
Patrick Georgi53c388f2015-03-07 09:55:18 +010025CROSSGCC_DATE="March 8th, 2015"
26CROSSGCC_VERSION="1.27"
Stefan Reinauer074d9132009-09-26 16:43:17 +000027
28# default settings
29TARGETDIR=`pwd`/xgcc
30TARGETARCH=i386-elf
31DESTDIR=
32
33# version numbers
Patrick Georgi53c388f2015-03-07 09:55:18 +010034GMP_VERSION=6.0.0
Stefan Reinauer0d2119d2013-07-10 14:27:56 -070035MPFR_VERSION=3.1.2
Paul Menzele6619422015-02-23 10:33:59 +010036MPC_VERSION=1.0.3
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000037LIBELF_VERSION=0.8.13
Patrick Georgi53c388f2015-03-07 09:55:18 +010038GCC_VERSION=4.9.2
Stefan Reinauer0d2119d2013-07-10 14:27:56 -070039GCC_AUTOCONF_VERSION=2.69
Patrick Georgi53c388f2015-03-07 09:55:18 +010040BINUTILS_VERSION=2.25
41GDB_VERSION=7.9
42IASL_VERSION=20150204
43PYTHON_VERSION=3.4.3
Idwer Vollering296a0152012-10-26 01:48:04 +020044EXPAT_VERSION=2.1.0
Stefan Reinauer074d9132009-09-26 16:43:17 +000045
46# archive locations
Patrick Georgi53c388f2015-03-07 09:55:18 +010047GMP_ARCHIVE="http://ftpmirror.gnu.org/gmp/gmp-${GMP_VERSION}a.tar.bz2"
Patrick Georgi6e61ad32012-05-12 23:19:30 +020048MPFR_ARCHIVE="http://ftpmirror.gnu.org/mpfr/mpfr-${MPFR_VERSION}.tar.bz2"
Idwer Vollering7962fc72012-10-25 02:14:09 +020049MPC_ARCHIVE="http://ftpmirror.gnu.org/mpc/mpc-${MPC_VERSION}.tar.gz"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000050LIBELF_ARCHIVE="http://www.mr511.de/software/libelf-${LIBELF_VERSION}.tar.gz"
Idwer Vollering1cfee0b2012-10-25 02:03:53 +020051GCC_ARCHIVE="http://ftpmirror.gnu.org/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.bz2"
Stefan Reinauer0d2119d2013-07-10 14:27:56 -070052BINUTILS_ARCHIVE="http://ftpmirror.gnu.org/binutils/binutils-${BINUTILS_VERSION}.tar.bz2"
Patrick Georgi53c388f2015-03-07 09:55:18 +010053GDB_ARCHIVE="http://ftpmirror.gnu.org/gdb/gdb-${GDB_VERSION}.tar.xz"
54IASL_ARCHIVE="https://acpica.org/sites/acpica/files/acpica-unix-${IASL_VERSION}.tar.gz"
55PYTHON_ARCHIVE="http://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010056EXPAT_ARCHIVE="http://downloads.sourceforge.net/sourceforge/expat/expat-${EXPAT_VERSION}.tar.gz"
Stefan Reinauer074d9132009-09-26 16:43:17 +000057
58GMP_DIR="gmp-${GMP_VERSION}"
59MPFR_DIR="mpfr-${MPFR_VERSION}"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000060MPC_DIR="mpc-${MPC_VERSION}"
61LIBELF_DIR="libelf-${LIBELF_VERSION}"
Stefan Reinauer074d9132009-09-26 16:43:17 +000062GCC_DIR="gcc-${GCC_VERSION}"
63BINUTILS_DIR="binutils-${BINUTILS_VERSION}"
64GDB_DIR="gdb-${GDB_VERSION}"
Marc Jones2aac3f62011-08-08 16:07:50 -060065IASL_DIR="acpica-unix-${IASL_VERSION}"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010066PYTHON_DIR="Python-${PYTHON_VERSION}"
67EXPAT_DIR="expat-${EXPAT_VERSION}"
Stefan Reinauer074d9132009-09-26 16:43:17 +000068
Patrick Georgi6321f522015-02-27 23:36:26 +010069unset MAKELEVEL MAKEFLAGS
70
Stefan Reinauer074d9132009-09-26 16:43:17 +000071SAVETEMPS=0
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010072SKIPGDB=1
73SKIPPYTHON=1
Stefan Reinauer074d9132009-09-26 16:43:17 +000074
Patrick Georgi1861ff72011-10-31 12:15:55 +010075red='\033[0;31m'
76RED='\033[1;31m'
77green='\033[0;32m'
78GREEN='\033[1;32m'
79blue='\033[0;34m'
80BLUE='\033[1;34m'
81cyan='\033[0;36m'
82CYAN='\033[1;36m'
83NC='\033[0m' # No Color
Stefan Reinauer074d9132009-09-26 16:43:17 +000084
Stefan Reinauer0d2119d2013-07-10 14:27:56 -070085UNAME=`uname`
86
Patrick Georgi198d23c2012-12-08 08:02:44 +010087normalize_dirs()
88{
89 mkdir -p $DESTDIR$TARGETDIR/lib
90 test -d $DESTDIR$TARGETDIR/lib32 && mv $DESTDIR$TARGETDIR/lib32/* $DESTDIR$TARGETDIR/lib
91 test -d $DESTDIR$TARGETDIR/lib64 && mv $DESTDIR$TARGETDIR/lib64/* $DESTDIR$TARGETDIR/lib
92 rmdir -p $DESTDIR$TARGETDIR/lib32 $DESTDIR$TARGETDIR/lib64
93
94 perl -pi -e "s,/lib32,/lib," $DESTDIR$TARGETDIR/lib/*.la
95 perl -pi -e "s,/lib64,/lib," $DESTDIR$TARGETDIR/lib/*.la
96}
97
Patrick Georgib7062882015-02-24 10:52:14 +010098searchtool()
Stefan Reinauer074d9132009-09-26 16:43:17 +000099{
100 # $1 short name
Patrick Georgib7062882015-02-24 10:52:14 +0100101 # $2 search string
102 # $3 soft fail if set
103 # result: file name of that tool on stdout
104 # or no output if nothing suitable was found
105 search=GNU
106 if [ -n "$2" ]; then
107 search="$2"
108 fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000109 for i in "$1" "g$1" "gnu$1"; do
110 if test -x "`which $i 2>/dev/null`"; then
Patrick Georgi915c4fc2015-03-09 13:58:23 +0100111 if test `$i --version 2>&1 |grep -c "$search"` \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100112 -gt 0; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000113 echo $i
114 return
115 fi
116 fi
117 done
Andrew Wub67e9a12014-04-28 18:13:44 +0800118 # A workaround for OSX 10.9 and some BSDs, whose nongnu
119 # patch and tar also work.
120 if [ $UNAME = "Darwin" -o $UNAME = "FreeBSD" -o $UNAME = "NetBSD" ]; then
Patrick Georgib7062882015-02-24 10:52:14 +0100121 if [ "$1" = "patch" -o "$1" = "tar" ]; then
Zheng Bao36156ff2012-09-28 16:18:58 +0800122 if test -x "`which $1 2>/dev/null`"; then
123 echo $1
124 return
125 fi
126 fi
127 fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000128 printf "${RED}ERROR:${red} Missing toolchain: $1${NC}\n" >&2
Patrick Georgib7062882015-02-24 10:52:14 +0100129 [ -z "$3" ] && exit 1
130 false
Stefan Reinauer074d9132009-09-26 16:43:17 +0000131}
132
Patrick Georgib7062882015-02-24 10:52:14 +0100133TAR=`searchtool tar` || exit $?
134PATCH=`searchtool patch` || exit $?
135MAKE=`searchtool make` || exit $?
Stefan Reinauer074d9132009-09-26 16:43:17 +0000136
Patrick Georgib7062882015-02-24 10:52:14 +0100137searchtool m4 > /dev/null
138searchtool bison > /dev/null
139searchtool flex flex > /dev/null
140searchtool g++ "Free Software Foundation" nofail > /dev/null || \
Patrick Georgi915c4fc2015-03-09 13:58:23 +0100141searchtool clang "clang version" > /dev/null
142searchtool wget > /dev/null
143searchtool bzip2 "bzip2," > /dev/null
Patrick Georgi5fb2b5c2012-05-12 23:25:23 +0200144
Stefan Reinauer074d9132009-09-26 16:43:17 +0000145cleanup()
146{
147 printf "Cleaning up temporary files... "
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200148 rm -rf ${BUILDDIRPREFIX}-* combined gcc-* gmp-* mpfr-* mpc-* libelf-* binutils-*
Patrick Georgi969cd932012-12-07 13:13:53 +0100149 rm -rf gdb-* acpica-* python-* expat-*
Stefan Reinauer074d9132009-09-26 16:43:17 +0000150 printf "${green}ok${NC}\n"
151}
152
153myhelp()
154{
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100155 printf "Usage: $0 [-V] [-c] [-p <platform>] [-d <target directory>] [-D <dest dir>] [-G] [-S]\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000156 printf " $0 [-V|--version]\n"
157 printf " $0 [-h|--help]\n\n"
158
159 printf "Options:\n"
160 printf " [-V|--version] print version number and exit\n"
161 printf " [-h|--help] print this help and exit\n"
162 printf " [-c|--clean] remove temporary files before build\n"
163 printf " [-t|--savetemps] don't remove temporary files after build\n"
Patrick Georgic1a75b12011-11-04 21:37:14 +0100164 printf " [-y|--ccache] Use ccache when building cross compiler\n"
Patrick Georgi73166c72010-04-14 20:42:42 +0000165 printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000166 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
167 printf " (defaults to $TARGETARCH)\n"
168 printf " [-d|--directory <target dir>] target directory to install cross compiler to\n"
169 printf " (defaults to $TARGETDIR)\n\n"
170 printf " [-D|--destdir <dest dir>] destination directory to install cross compiler to\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100171 printf " (for RPM builds, default unset)\n"
172 printf " [-G|--gdb] build GNU debugger\n"
173 printf " [-S|--scripting] build scripting support for GDB\n\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000174}
175
176myversion()
177{
178 # version tag is always printed, so just print the license here
179
180 cat << EOF
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000181Copyright (C) 2008-2010 by coresystems GmbH
Marc Jones2aac3f62011-08-08 16:07:50 -0600182Copyright (C) 2011 by Sage Electronic Engineering
Stefan Reinauer074d9132009-09-26 16:43:17 +0000183
184This program is free software; you can redistribute it and/or modify
185it under the terms of the GNU General Public License as published by
186the Free Software Foundation; version 2 of the License.
187
188This program is distributed in the hope that it will be useful,
189but WITHOUT ANY WARRANTY; without even the implied warranty of
190MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
191GNU General Public License for more details.
192
193EOF
194}
195
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700196printf "${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 +0000197
Patrick Georgi6bba29f2010-01-29 17:40:52 +0000198# Look if we have getopt. If not, build it.
199export PATH=$PATH:.
200getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c
201
Stefan Reinauer074d9132009-09-26 16:43:17 +0000202# parse parameters.. try to find out whether we're running GNU getopt
Peter Stuge09377b72011-08-21 06:24:55 +0200203getoptbrand="`getopt -V | sed -e '1!d' -e 's,^\(......\).*,\1,'`"
204if [ "${getoptbrand}" = "getopt" ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000205 # Detected GNU getopt that supports long options.
Patrick Georgic1a75b12011-11-04 21:37:14 +0100206 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 +0000207 eval set "$args"
208else
209 # Detected non-GNU getopt
Patrick Georgic1a75b12011-11-04 21:37:14 +0100210 args=`getopt Vhcd:p:j:D:tGy $*`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000211 set -- $args
212fi
213
214if [ $? != 0 ]; then
215 myhelp
216 exit 1
217fi
218
219while true ; do
220 case "$1" in
221 -V|--version) shift; myversion; exit 0;;
222 -h|--help) shift; myhelp; exit 0;;
Patrick Georgi44af57a2013-12-19 22:06:22 +0100223 -c|--clean) shift; clean=1;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000224 -t|--savetemps) shift; SAVETEMPS=1;;
225 -d|--directory) shift; TARGETDIR="$1"; shift;;
226 -p|--platform) shift; TARGETARCH="$1"; shift;;
227 -D|--destdir) shift; DESTDIR="$1"; shift;;
Patrick Georgi73166c72010-04-14 20:42:42 +0000228 -j|--jobs) shift; JOBS="-j $1"; shift;;
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100229 -G|--gdb) shift; SKIPGDB=0;;
230 -S|--scripting) shift; SKIPPYTHON=0;;
Patrick Georgic1a75b12011-11-04 21:37:14 +0100231 -y|--ccache) shift; USECCACHE=1;;
Patrick Georgid2e0dd52013-06-09 08:05:45 +0200232 --) shift; break;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000233 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
Patrick Georgid2e0dd52013-06-09 08:05:45 +0200234 *) break;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000235 esac
236done
237
Ronald G. Minnichb460a662013-05-26 05:33:35 -0700238case "$TARGETARCH" in
Stefan Reinauer24f9cb92015-03-13 22:50:22 +0100239 x86_64-elf) ;;
240 x86_64*) TARGETARCH=x86_64-elf;;
David Hubbard5b0420a2013-05-28 16:33:15 -0600241 i386-elf) ;;
242 i386-mingw32) ;;
Patrick Georgi9b7efa52015-03-08 09:20:36 +0100243 mipsel-elf) ;;
Patrick Georgif0bbc952015-03-07 10:57:25 +0100244 riscv-elf) ;;
Ronald G. Minnichb460a662013-05-26 05:33:35 -0700245 i386*) TARGETARCH=i386-elf;;
Patrick Georgic8883262013-09-19 10:57:58 +0200246 arm*) TARGETARCH=armv7-a-eabi;;
Stefan Reinauer0d2119d2013-07-10 14:27:56 -0700247 aarch64*) TARGETARCH=aarch64-elf;;
248 *) printf "${red}WARNING: Unsupported architecture $TARGETARCH.${NC}\n\n"; ;;
Ronald G. Minnichb460a662013-05-26 05:33:35 -0700249esac
250
251echo "Target arch is now $TARGETARCH"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200252BUILDDIRPREFIX=build-${TARGETARCH}
253
Patrick Georgi44af57a2013-12-19 22:06:22 +0100254if [ "$clean" = "1" ]; then
255 cleanup
256fi
257
Peter Stugeceacd772011-06-09 04:54:16 +0200258GDB_PACKAGE="GDB"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100259PYTHON_PACKAGE="PYTHON"
260EXPAT_PACKAGE="EXPAT"
Peter Stugeceacd772011-06-09 04:54:16 +0200261if [ $SKIPGDB -eq 1 ]; then
262 printf "Will skip GDB ... ${green}ok${NC}\n"
Peter Stuge0e8ee812011-08-28 11:04:23 +0200263 GDB_ARCHIVE=""
Peter Stugeceacd772011-06-09 04:54:16 +0200264 GDB_PACKAGE=""
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100265 if [ $SKIPPYTHON -eq 0 ]; then
266 printf "Python scripting needs GDB ... disabling ... ${green}ok${NC}\n"
267 SKIPPYTHON=1
268 fi
269fi
270if [ $SKIPPYTHON -eq 1 ]; then
Jonathan A. Kollasch2d7ab4c2011-11-07 13:05:18 -0600271 PYTHON_ARCHIVE=""
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100272 PYTHON_PACKAGE=""
Jonathan A. Kollasch2d7ab4c2011-11-07 13:05:18 -0600273 EXPAT_ARCHIVE=""
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100274 EXPAT_PACKAGE=""
Peter Stugeceacd772011-06-09 04:54:16 +0200275fi
276
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700277# coreboot does not like the GOLD linker
278# USE_GOLD="--enable-gold"
279USE_GOLD=""
280GCC_OPTIONS="--enable-lto"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000281
Stefan Reinauer074d9132009-09-26 16:43:17 +0000282printf "Downloading tar balls ... \n"
283mkdir -p tarballs
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100284for ARCHIVE in $GMP_ARCHIVE $MPFR_ARCHIVE $MPC_ARCHIVE $LIBELF_ARCHIVE \
Patrick Georgi969cd932012-12-07 13:13:53 +0100285 $GCC_ARCHIVE $BINUTILS_ARCHIVE $GDB_ARCHIVE \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100286 $IASL_ARCHIVE $PYTHON_ARCHIVE $EXPAT_ARCHIVE; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000287 FILE=`basename $ARCHIVE`
288 printf " * $FILE "
289 test -f tarballs/$FILE && printf "(cached)" || (
290 printf "(downloading)"
291 cd tarballs
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200292 wget --no-check-certificate -q $ARCHIVE
Stefan Reinauer074d9132009-09-26 16:43:17 +0000293 )
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100294 test -f tarballs/$FILE || \
Zheng Bao5b209c02012-09-20 16:09:51 +0800295 printf "\n${RED}Failed to download $FILE.${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000296 test -f tarballs/$FILE || exit 1
297 printf "\n"
298done
299printf "Downloaded tar balls ... "
300printf "${green}ok${NC}\n"
301
302printf "Unpacking and patching ... \n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100303for PACKAGE in GMP MPFR MPC LIBELF GCC BINUTILS $PYTHON_PACKAGE \
Patrick Georgi969cd932012-12-07 13:13:53 +0100304 $EXPAT_PACKAGE $GDB_PACKAGE IASL; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000305 archive=$PACKAGE"_ARCHIVE"
Peter Stuge09377b72011-08-21 06:24:55 +0200306 archive="`eval echo '$'$archive`"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000307 dir=$PACKAGE"_DIR"
Peter Stuge09377b72011-08-21 06:24:55 +0200308 dir="`eval echo '$'${dir}`"
Zheng Baof95bb2d2013-12-13 12:30:46 +0800309 test -d ${dir} && test -f ${dir}/.unpack_success || (
Stefan Reinauer074d9132009-09-26 16:43:17 +0000310 printf " * `basename $archive`\n"
311 FLAGS=zxf
Peter Stuge09377b72011-08-21 06:24:55 +0200312 suffix=`echo $archive | sed 's,.*\.,,'`
313 test "$suffix" = "gz" && FLAGS=zxf
314 test "$suffix" = "bz2" && FLAGS=jxf
Patrick Georgi53c388f2015-03-07 09:55:18 +0100315 test "$suffix" = "xz" && FLAGS="--xz -xf"
Peter Stuge09377b72011-08-21 06:24:55 +0200316 test "$suffix" = "lzma" && FLAGS="--lzma -xf"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000317 $TAR $FLAGS tarballs/`basename $archive`
Peter Stuge09377b72011-08-21 06:24:55 +0200318 for patch in patches/${dir}_*.patch; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000319 test -r $patch || continue
320 printf " o `basename $patch`\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100321 $PATCH -s -N -p0 < `echo $patch` || \
Zheng Bao5b209c02012-09-20 16:09:51 +0800322 printf "\n${RED}Failed $patch.${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000323 done
Zheng Bao691b313c2013-12-09 14:09:07 +0800324 touch ${dir}/.unpack_success
Stefan Reinauer074d9132009-09-26 16:43:17 +0000325 )
326done
327printf "Unpacked and patched ... "
328printf "${green}ok${NC}\n"
329
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700330CC=cc
Stefan Reinauer0d2119d2013-07-10 14:27:56 -0700331if [ $UNAME = "Darwin" ]; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000332 #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix"
333
334 # generally the OS X compiler can create x64 binaries.
335 # Per default it generated i386 binaries in 10.5 and x64
336 # binaries in 10.6 (even if the kernel is 32bit)
337 # For some weird reason, 10.5 autodetects an ABI=64 though
338 # so we're setting the ABI explicitly here.
Zheng Bao04ceed62012-10-23 19:41:25 +0800339 if [ `sysctl -n hw.optional.x86_64 2>/dev/null` -eq 1 ] 2>/dev/null; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000340 OPTIONS="ABI=64"
341 else
342 OPTIONS="ABI=32"
343 fi
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700344
Stefan Reinauer4266b922012-12-05 16:18:32 -0800345 # In Xcode 4.5.2 the default compiler is clang.
346 # However, this compiler fails to compile gcc 4.7.x. As a
347 # workaround it's possible to compile gcc with llvm-gcc.
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700348 if $CC -v 2>&1 | grep -q LLVM; then
Stefan Reinauer4266b922012-12-05 16:18:32 -0800349 CC=llvm-gcc
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700350 fi
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000351fi
352
Patrick Georgic1a75b12011-11-04 21:37:14 +0100353if [ "$USECCACHE" = 1 ]; then
354 CC="ccache $CC"
355fi
356
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200357mkdir -p ${BUILDDIRPREFIX}-gmp ${BUILDDIRPREFIX}-mpfr ${BUILDDIRPREFIX}-mpc ${BUILDDIRPREFIX}-libelf ${BUILDDIRPREFIX}-binutils \
358 ${BUILDDIRPREFIX}-gcc ${BUILDDIRPREFIX}-python ${BUILDDIRPREFIX}-expat
Stefan Reinauer16bd7892012-12-07 23:57:01 +0100359
360mkdir -p $DESTDIR$TARGETDIR/bin
361export PATH=$DESTDIR$TARGETDIR/bin:$PATH
362
Peter Stugeceacd772011-06-09 04:54:16 +0200363if [ $SKIPGDB -eq 0 ]; then
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200364 mkdir -p ${BUILDDIRPREFIX}-gdb
Peter Stugeceacd772011-06-09 04:54:16 +0200365fi
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200366if [ -f ${BUILDDIRPREFIX}-gmp/.success ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000367 printf "Skipping GMP as it is already built\n"
368else
369printf "Building GMP ${GMP_VERSION} ... "
370(
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200371 cd ${BUILDDIRPREFIX}-gmp
Stefan Reinauer074d9132009-09-26 16:43:17 +0000372 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100373 CC="$CC" ../${GMP_DIR}/configure --disable-shared --prefix=$TARGETDIR $OPTIONS \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000374 || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000375 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000376 $MAKE install DESTDIR=$DESTDIR || touch .failed
Patrick Georgi198d23c2012-12-08 08:02:44 +0100377
378 normalize_dirs
379
Stefan Reinauer074d9132009-09-26 16:43:17 +0000380 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200381) > ${BUILDDIRPREFIX}-gmp/crossgcc-build.log 2>&1
Patrick Georgi79643542015-03-24 23:31:44 +0100382test -r ${BUILDDIRPREFIX}-gmp/.failed && printf "${RED}failed${NC}. Check ${BUILDDIRPREFIX}-gmp/crossgcc-build.log.\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100383 printf "${green}ok${NC}\n"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200384test -r ${BUILDDIRPREFIX}-gmp/.failed && exit 1
Stefan Reinauer074d9132009-09-26 16:43:17 +0000385fi
386
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700387# Now set CFLAGS to match GMP CFLAGS but strip out -pedantic
388# as GCC 4.6.x fails if it's there.
389HOSTCFLAGS=`grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2 |\
390 sed s,-pedantic,,`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000391
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200392if [ -f ${BUILDDIRPREFIX}-mpfr/.success ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000393 printf "Skipping MPFR as it is already built\n"
394else
395printf "Building MPFR ${MPFR_VERSION} ... "
396(
Stefan Reinauer0d2119d2013-07-10 14:27:56 -0700397 test $UNAME = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200398 cd ${BUILDDIRPREFIX}-mpfr
Stefan Reinauer074d9132009-09-26 16:43:17 +0000399 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100400 CC="$CC" ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000401 --infodir=$TARGETDIR/info \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100402 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
403 touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000404 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000405 $MAKE install DESTDIR=$DESTDIR || touch .failed
406
Patrick Georgi198d23c2012-12-08 08:02:44 +0100407 normalize_dirs
408
Stefan Reinauer074d9132009-09-26 16:43:17 +0000409 # work around build problem of libgmp.la
410 if [ "$DESTDIR" != "" ]; then
411 perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la
412 fi
413
414 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200415) > ${BUILDDIRPREFIX}-mpfr/crossgcc-build.log 2>&1
Patrick Georgi79643542015-03-24 23:31:44 +0100416test -r ${BUILDDIRPREFIX}-mpfr/.failed && printf "${RED}failed${NC}. Check ${BUILDDIRPREFIX}-mpfr/crossgcc-build.log.\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100417 printf "${green}ok${NC}\n"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200418test -r ${BUILDDIRPREFIX}-mpfr/.failed && exit 1
Stefan Reinauer074d9132009-09-26 16:43:17 +0000419fi
420
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200421if [ -f ${BUILDDIRPREFIX}-mpc/.success ]; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000422 printf "Skipping MPC as it is already built\n"
423else
424printf "Building MPC ${MPC_VERSION} ... "
425(
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200426 cd ${BUILDDIRPREFIX}-mpc
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000427 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100428 CC="$CC" ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000429 --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100430 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
431 touch .failed
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000432 $MAKE $JOBS || touch .failed
433 $MAKE install DESTDIR=$DESTDIR || touch .failed
434
Patrick Georgi198d23c2012-12-08 08:02:44 +0100435 normalize_dirs
436
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000437 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200438) > ${BUILDDIRPREFIX}-mpc/crossgcc-build.log 2>&1
Patrick Georgi79643542015-03-24 23:31:44 +0100439test -r ${BUILDDIRPREFIX}-mpc/.failed && printf "${RED}failed${NC}. Check ${BUILDDIRPREFIX}-mpc/crossgcc-build.log.\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100440 printf "${green}ok${NC}\n"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200441test -r ${BUILDDIRPREFIX}-mpc/.failed && exit 1
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000442fi
443
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200444if [ -f ${BUILDDIRPREFIX}-libelf/.success ]; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000445 printf "Skipping libelf as it is already built\n"
446else
447printf "Building libelf ${LIBELF_VERSION} ... "
448(
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200449 cd ${BUILDDIRPREFIX}-libelf
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000450 rm -f .failed
451 echo "$HOSTCFLAGS"
Patrick Georgi643c9e82011-11-04 21:30:49 +0100452 CC="$CC" CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100453 ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000454 --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed
455 $MAKE $JOBS || touch .failed
Scott Duplichan4270a972014-12-12 20:21:40 -0600456 $MAKE install prefix=$DESTDIR$TARGETDIR || touch .failed
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000457
Patrick Georgi198d23c2012-12-08 08:02:44 +0100458 normalize_dirs
459
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000460 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200461) > ${BUILDDIRPREFIX}-libelf/crossgcc-build.log 2>&1
Patrick Georgi79643542015-03-24 23:31:44 +0100462test -r ${BUILDDIRPREFIX}-libelf/.failed && printf "${RED}failed${NC}. Check ${BUILDDIRPREFIX}-libelf/crossgcc-build.log.\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100463 printf "${green}ok${NC}\n"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200464test -r ${BUILDDIRPREFIX}-libelf/.failed && exit 1
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000465fi
466
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200467if [ -f ${BUILDDIRPREFIX}-binutils/.success ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000468 printf "Skipping binutils as it is already built\n"
469else
470printf "Building binutils ${BINUTILS_VERSION} ... "
471(
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700472 # What a pain: binutils don't come with configure
473 # script anymore. Create it:
474 cd binutils-${BINUTILS_VERSION}/
475 autoconf
476 cd ..
477 # Now build binutils
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200478 cd ${BUILDDIRPREFIX}-binutils
Stefan Reinauer074d9132009-09-26 16:43:17 +0000479 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100480 CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100481 --target=${TARGETARCH} --disable-werror --disable-nls \
482 $USE_GOLD CFLAGS="$HOSTCFLAGS" || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000483 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000484 $MAKE install DESTDIR=$DESTDIR || touch .failed
485 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200486) > ${BUILDDIRPREFIX}-binutils/crossgcc-build.log 2>&1
Patrick Georgi79643542015-03-24 23:31:44 +0100487test -r ${BUILDDIRPREFIX}-binutils/.failed && printf "${RED}failed${NC}. Check ${BUILDDIRPREFIX}-binutils/crossgcc-build.log.\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100488 printf "${green}ok${NC}\n"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200489test -r ${BUILDDIRPREFIX}-binutils/.failed && exit 1
Stefan Reinauer074d9132009-09-26 16:43:17 +0000490fi
491
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200492if [ -f ${BUILDDIRPREFIX}-gcc/.success ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000493 printf "Skipping GCC as it is already built\n"
494else
495printf "Building GCC ${GCC_VERSION} ... "
496(
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700497 # Even worse than binutils: GCC does not come with configure
498 # script anymore, but also enforces an obsolete autoconf version
499 # to create it. This is a poster child of how autotools help make
500 # software portable.
501 cd gcc-${GCC_VERSION}
502 sed '/dnl Ensure exactly this Autoconf version is used/d' \
503 config/override.m4 > config/override.m4.new
504 autoconf_version=`autoconf -V | grep "autoconf" | tr ' ' '\n' | tail -1`
505 sed "s/${GCC_AUTOCONF_VERSION}/${autoconf_version}/g" \
506 config/override.m4.new > config/override.m4
507 autoconf
508 cd ..
509 # Now, finally, we can build gcc:
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200510 cd ${BUILDDIRPREFIX}-gcc
Stefan Reinauer074d9132009-09-26 16:43:17 +0000511 rm -f .failed
512 # GCC does not honour HOSTCFLAGS at all. CFLAGS are used for
513 # both target and host object files. This is pretty misdesigned.
514 # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
515 # but it does not seem to work properly. At least the host library
516 # libiberty is not compiled with CFLAGS_FOR_BUILD.
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700517 CC="$CC" CFLAGS_FOR_TARGET="-O2" CFLAGS="$HOSTCFLAGS" \
518 CFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000519 --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000520 --target=${TARGETARCH} --disable-werror --disable-shared \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000521 --disable-libssp --disable-bootstrap --disable-nls \
Patrick Georgi969cd932012-12-07 13:13:53 +0100522 --disable-libquadmath --without-headers \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000523 $GCC_OPTIONS --enable-languages="c" $USE_GOLD \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000524 --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000525 --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \
526 --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000527 || touch .failed
Patrick Georgi969cd932012-12-07 13:13:53 +0100528 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-gcc || touch .failed
529 $MAKE install-gcc DESTDIR=$DESTDIR || touch .failed
530
531 if [ "`echo $TARGETARCH | grep -c -- -mingw32`" -eq 0 ]; then
532 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-target-libgcc || touch .failed
533 $MAKE install-target-libgcc DESTDIR=$DESTDIR || touch .failed
534 fi
535
Stefan Reinauer074d9132009-09-26 16:43:17 +0000536 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200537) > ${BUILDDIRPREFIX}-gcc/crossgcc-build.log 2>&1
Patrick Georgi79643542015-03-24 23:31:44 +0100538test -r ${BUILDDIRPREFIX}-gcc/.failed && printf "${RED}failed${NC}. Check ${BUILDDIRPREFIX}-gcc/crossgcc-build.log.\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100539 printf "${green}ok${NC}\n"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200540test -r ${BUILDDIRPREFIX}-gcc/.failed && exit 1
Stefan Reinauer074d9132009-09-26 16:43:17 +0000541fi
542
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200543if [ -f ${BUILDDIRPREFIX}-expat/.success ]; then
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100544 printf "Skipping Expat as it is already built\n"
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100545elif [ $SKIPPYTHON -eq 1 ]; then
546 printf "Skipping Expat (Python scripting not enabled)\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100547else
548printf "Building Expat ${EXPAT_VERSION} ... "
549(
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200550 cd ${BUILDDIRPREFIX}-expat
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100551 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100552 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${EXPAT_DIR}/configure --disable-shared \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100553 --prefix=$TARGETDIR --target=${TARGETARCH} || touch .failed
554 $MAKE || touch .failed
555 $MAKE install DESTDIR=$DESTDIR || touch .failed
Patrick Georgi198d23c2012-12-08 08:02:44 +0100556
557 normalize_dirs
558
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100559 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200560) > ${BUILDDIRPREFIX}-expat/crossgcc-build.log 2>&1
Patrick Georgi79643542015-03-24 23:31:44 +0100561test -r ${BUILDDIRPREFIX}-expat/.failed && printf "${RED}failed${NC}. Check ${BUILDDIRPREFIX}-expat/crossgcc-build.log\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100562 printf "${green}ok${NC}\n"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200563test -r ${BUILDDIRPREFIX}-expat/.failed && exit 1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100564fi
565
566
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200567if [ -f ${BUILDDIRPREFIX}-python/.success ]; then
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100568 printf "Skipping Python as it is already built\n"
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100569elif [ $SKIPPYTHON -eq 1 ]; then
570 printf "Skipping Python (Python scripting not enabled)\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100571else
572printf "Building Python ${PYTHON_VERSION} ... "
573(
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200574 cd ${BUILDDIRPREFIX}-python
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100575 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100576 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100577 --target=${TARGETARCH} || touch .failed
578 $MAKE $JOBS || touch .failed
579 $MAKE install DESTDIR=$DESTDIR || touch .failed
Patrick Georgi198d23c2012-12-08 08:02:44 +0100580
581 normalize_dirs
582
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100583 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200584) > ${BUILDDIRPREFIX}-python/crossgcc-build.log 2>&1
Patrick Georgi79643542015-03-24 23:31:44 +0100585test -r ${BUILDDIRPREFIX}-python/.failed && printf "${RED}failed${NC}. Check ${BUILDDIRPREFIX}-python/crossgcc-build.log.\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100586 printf "${green}ok${NC}\n"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200587test -r ${BUILDDIRPREFIX}-python/.failed && exit 1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100588fi
589
590
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200591if [ -f ${BUILDDIRPREFIX}-gdb/.success ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000592 printf "Skipping GDB as it is already built\n"
Peter Stugeceacd772011-06-09 04:54:16 +0200593elif [ $SKIPGDB -eq 1 ]; then
Stefan Reinauer1200ec52011-11-01 22:39:41 +0100594 printf "Skipping GDB (GDB support not enabled)\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000595else
596printf "Building GDB ${GDB_VERSION} ... "
597(
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200598 cd ${BUILDDIRPREFIX}-gdb
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100599 export PYTHONHOME=$DESTDIR$TARGETDIR
Stefan Reinauer074d9132009-09-26 16:43:17 +0000600 rm -f .failed
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100601 LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \
602 -lpthread -ldl -lutil" \
Patrick Georgi643c9e82011-11-04 21:30:49 +0100603 CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100604 ../gdb-${GDB_VERSION}/configure --prefix=$TARGETDIR \
605 --target=${TARGETARCH} --disable-werror --disable-nls
Patrick Georgi73166c72010-04-14 20:42:42 +0000606 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000607 $MAKE install DESTDIR=$DESTDIR || touch .failed
608 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200609) > ${BUILDDIRPREFIX}-gdb/crossgcc-build.log 2>&1
Patrick Georgi79643542015-03-24 23:31:44 +0100610test -r ${BUILDDIRPREFIX}-gdb/.failed && printf "${RED}failed${NC}. Check ${BUILDDIRPREFIX}-gdb/crossgcc-build.log.\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100611 printf "${green}ok${NC}\n"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200612test -r ${BUILDDIRPREFIX}-gdb/.failed && exit 1
Stefan Reinauer074d9132009-09-26 16:43:17 +0000613fi
614
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200615if [ -f $IASL_DIR/source/compiler/.success ]; then
Marc Jones2aac3f62011-08-08 16:07:50 -0600616 printf "Skipping IASL as it is already built\n"
617else
618printf "Building IASL ${IASL_VERSION} ... "
619(
Idwer Vollering6b11c8b2012-11-15 21:14:36 +0100620 cd $IASL_DIR/generate/unix
Stefan Reinauer4266b922012-12-05 16:18:32 -0800621 rm -f .failed
Marc Jones2aac3f62011-08-08 16:07:50 -0600622 CFLAGS="$HOSTCFLAGS"
Stefan Reinauer0d2119d2013-07-10 14:27:56 -0700623 HOST="_LINUX"
624 test $UNAME = "Darwin" && HOST="_APPLE"
625 test $UNAME = "FreeBSD" && HOST="_FreeBSD"
626 test $UNAME = "Cygwin" && HOST="_CYGWIN"
627 HOST="$HOST" OPT_CFLAGS="-O -D_FORTIFY_SOURCE=2" CFLAGS="$CFLAGS" $MAKE CC="$CC" iasl || touch .failed
Stefan Reinauer4266b922012-12-05 16:18:32 -0800628 rm -f $DESTDIR$TARGETDIR/bin/iasl || touch .failed
Zheng Bao3c4bd912013-08-27 10:23:13 +0800629 cp bin/iasl $DESTDIR$TARGETDIR/bin || touch .failed
Stefan Reinauer4266b922012-12-05 16:18:32 -0800630 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200631) > $IASL_DIR/source/compiler/crossgcc-build.log 2>&1
Patrick Georgi79643542015-03-24 23:31:44 +0100632test -r $IASL_DIR/generate/unix/.failed && printf "${RED}failed${NC}. Check ${IASL_DIR}/source/compiler/crossgcc-build.log.\n" || \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100633 printf "${green}ok${NC}\n"
Stefan Reinauer4266b922012-12-05 16:18:32 -0800634test -r $IASL_DIR/generate/unix/.failed && exit 1
Marc Jones2aac3f62011-08-08 16:07:50 -0600635fi
636
Zheng Bao30b895f2013-02-06 18:04:40 +0800637rm -f $DESTDIR$TARGETDIR/$0.commit.*
638cp $0 $DESTDIR$TARGETDIR/"$0.commit.`git describe`"
639
Stefan Reinauer074d9132009-09-26 16:43:17 +0000640if [ $SAVETEMPS -eq 0 ]; then
641 printf "Cleaning up... "
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200642 rm -rf ${GMP_DIR} ${BUILDDIRPREFIX}-gmp
643 rm -rf ${MPFR_DIR} ${BUILDDIRPREFIX}-mpfr
644 rm -rf ${MPC_DIR} ${BUILDDIRPREFIX}-mpc
645 rm -rf ${LIBELF_DIR} ${BUILDDIRPREFIX}-libelf
646 rm -rf ${BINUTILS_DIR} ${BUILDDIRPREFIX}-binutils
647 rm -rf ${GCC_DIR} ${BUILDDIRPREFIX}-gcc
648 rm -rf ${GDB_DIR} ${BUILDDIRPREFIX}-gdb
649 rm -rf ${EXPAT_DIR} ${BUILDDIRPREFIX}-expat
650 rm -rf ${PYTHON_DIR} ${BUILDDIRPREFIX}-python
Marc Jones2aac3f62011-08-08 16:07:50 -0600651 rm -rf ${IASL_DIR}
Stefan Reinauer074d9132009-09-26 16:43:17 +0000652 printf "${green}ok${NC}\n"
653else
654 printf "Leaving temporary files around... ${green}ok${NC}\n"
655fi
656
657printf "\n${green}You can now run your $TARGETARCH cross toolchain from $TARGETDIR.${NC}\n"
658
659