blob: 45ee3c1f8f9a33cc9f420ff1f692774c75752619 [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
Patrick Georgib890a122015-03-26 15:17:45 +010020# Foundation, Inc.
Stefan Reinauer074d9132009-09-26 16:43:17 +000021#
22
Patrick Georgi8135dba2015-03-17 21:05:20 +010023cd `dirname $0`
24
Patrick Georgi31bf37e2015-06-04 00:09:12 +020025CROSSGCC_DATE="June 3th, 2015"
26CROSSGCC_VERSION="1.28"
Stefan Reinauer074d9132009-09-26 16:43:17 +000027
28# default settings
29TARGETDIR=`pwd`/xgcc
30TARGETARCH=i386-elf
31DESTDIR=
32
Stefan Reinauer699ac272015-06-05 12:43:28 -070033# GCC toolchain 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
Stefan Reinauer699ac272015-06-05 12:43:28 -070046# GCC toolchain 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
Stefan Reinauer699ac272015-06-05 12:43:28 -070058# GCC toolchain directories
Stefan Reinauer074d9132009-09-26 16:43:17 +000059GMP_DIR="gmp-${GMP_VERSION}"
60MPFR_DIR="mpfr-${MPFR_VERSION}"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000061MPC_DIR="mpc-${MPC_VERSION}"
62LIBELF_DIR="libelf-${LIBELF_VERSION}"
Stefan Reinauer074d9132009-09-26 16:43:17 +000063GCC_DIR="gcc-${GCC_VERSION}"
64BINUTILS_DIR="binutils-${BINUTILS_VERSION}"
65GDB_DIR="gdb-${GDB_VERSION}"
Marc Jones2aac3f62011-08-08 16:07:50 -060066IASL_DIR="acpica-unix-${IASL_VERSION}"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010067PYTHON_DIR="Python-${PYTHON_VERSION}"
68EXPAT_DIR="expat-${EXPAT_VERSION}"
Stefan Reinauer074d9132009-09-26 16:43:17 +000069
Patrick Georgi6321f522015-02-27 23:36:26 +010070unset MAKELEVEL MAKEFLAGS
71
Stefan Reinauer074d9132009-09-26 16:43:17 +000072SAVETEMPS=0
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010073SKIPGDB=1
74SKIPPYTHON=1
Stefan Reinauer074d9132009-09-26 16:43:17 +000075
Patrick Georgi1861ff72011-10-31 12:15:55 +010076red='\033[0;31m'
77RED='\033[1;31m'
78green='\033[0;32m'
79GREEN='\033[1;32m'
80blue='\033[0;34m'
81BLUE='\033[1;34m'
82cyan='\033[0;36m'
83CYAN='\033[1;36m'
84NC='\033[0m' # No Color
Stefan Reinauer074d9132009-09-26 16:43:17 +000085
Stefan Reinauer0d2119d2013-07-10 14:27:56 -070086UNAME=`uname`
87
Patrick Georgi198d23c2012-12-08 08:02:44 +010088normalize_dirs()
89{
90 mkdir -p $DESTDIR$TARGETDIR/lib
91 test -d $DESTDIR$TARGETDIR/lib32 && mv $DESTDIR$TARGETDIR/lib32/* $DESTDIR$TARGETDIR/lib
92 test -d $DESTDIR$TARGETDIR/lib64 && mv $DESTDIR$TARGETDIR/lib64/* $DESTDIR$TARGETDIR/lib
93 rmdir -p $DESTDIR$TARGETDIR/lib32 $DESTDIR$TARGETDIR/lib64
94
95 perl -pi -e "s,/lib32,/lib," $DESTDIR$TARGETDIR/lib/*.la
96 perl -pi -e "s,/lib64,/lib," $DESTDIR$TARGETDIR/lib/*.la
97}
98
Patrick Georgib7062882015-02-24 10:52:14 +010099searchtool()
Stefan Reinauer074d9132009-09-26 16:43:17 +0000100{
101 # $1 short name
Patrick Georgib7062882015-02-24 10:52:14 +0100102 # $2 search string
103 # $3 soft fail if set
104 # result: file name of that tool on stdout
105 # or no output if nothing suitable was found
106 search=GNU
107 if [ -n "$2" ]; then
108 search="$2"
109 fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000110 for i in "$1" "g$1" "gnu$1"; do
111 if test -x "`which $i 2>/dev/null`"; then
Alexander Couzensd268ab32015-04-13 17:15:12 +0200112 if test `cat /dev/null | $i --version 2>&1 |grep -c "$search"` \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100113 -gt 0; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000114 echo $i
115 return
116 fi
117 fi
118 done
Andrew Wub67e9a12014-04-28 18:13:44 +0800119 # A workaround for OSX 10.9 and some BSDs, whose nongnu
120 # patch and tar also work.
Patrick Georgi7cb26b42015-04-28 21:29:22 +0200121 if [ $UNAME = "Darwin" -o $UNAME = "FreeBSD" -o $UNAME = "NetBSD" -o $UNAME = "OpenBSD" ]; then
Patrick Georgib7062882015-02-24 10:52:14 +0100122 if [ "$1" = "patch" -o "$1" = "tar" ]; then
Zheng Bao36156ff2012-09-28 16:18:58 +0800123 if test -x "`which $1 2>/dev/null`"; then
124 echo $1
125 return
126 fi
127 fi
128 fi
zbao939dc842015-04-30 04:44:07 +0800129 if [ "`echo $1 | cut -b -3`" = "sha" ]; then
130 if [ $UNAME = "FreeBSD" ]; then
131 if test -x "`which sha1 2>/dev/null`"; then
132 echo sha1
133 return
134 fi
135 fi
136 if [ $UNAME = "NetBSD" ]; then
137 if test -x "`which cksum 2>/dev/null`"; then
138 echo cksum -a `echo $1 | sed -e 's,sum,,'`
139 return
140 fi
141 fi
142 if [ $UNAME = "Darwin" ]; then
143 if test -x "`which openssl 2>/dev/null`"; then
144 echo openssl `echo $1 | sed -e 's,sum,,'`
145 return
146 fi
147 fi
148 fi
Patrick Georgiae5ab602015-04-29 23:30:15 +0200149 printf "${RED}ERROR:${red} Missing tool: Please install $1 (eg using your OS packaging system)${NC}\n" >&2
Patrick Georgib7062882015-02-24 10:52:14 +0100150 [ -z "$3" ] && exit 1
151 false
Stefan Reinauer074d9132009-09-26 16:43:17 +0000152}
153
Patrick Georgib7062882015-02-24 10:52:14 +0100154TAR=`searchtool tar` || exit $?
155PATCH=`searchtool patch` || exit $?
156MAKE=`searchtool make` || exit $?
Stefan Reinauer699ac272015-06-05 12:43:28 -0700157SHA1SUM=`searchtool sha1sum`
158SHA512SUM=`searchtool sha512sum`
159CHECKSUM=$SHA1SUM
Stefan Reinauer074d9132009-09-26 16:43:17 +0000160
Patrick Georgib7062882015-02-24 10:52:14 +0100161searchtool m4 > /dev/null
162searchtool bison > /dev/null
163searchtool flex flex > /dev/null
164searchtool g++ "Free Software Foundation" nofail > /dev/null || \
Patrick Georgi915c4fc2015-03-09 13:58:23 +0100165searchtool clang "clang version" > /dev/null
166searchtool wget > /dev/null
167searchtool bzip2 "bzip2," > /dev/null
Patrick Georgi5fb2b5c2012-05-12 23:25:23 +0200168
Stefan Reinauer88935482015-06-05 09:51:10 -0700169download() {
Stefan Reinauer699ac272015-06-05 12:43:28 -0700170 PACKAGE=$1
171 archive=$PACKAGE"_ARCHIVE"
172 archive="`eval echo '$'$archive`"
173
174 FILE=`basename $archive`
Stefan Reinauer88935482015-06-05 09:51:10 -0700175 printf " * $FILE "
176
177 test -f tarballs/$FILE && \
178 (test -z "$CHECKSUM" || \
179 test "`cat sum/$FILE.cksum 2>/dev/null | sed -e 's,.*\([0-9a-f]\{40\}\).*,\1,'`" = "`$CHECKSUM tarballs/$FILE 2>/dev/null | sed -e 's,.*\([0-9a-f]\{40\}\).*,\1,'`" ) && \
180 printf "(cached)" || (
181 printf "(downloading)"
182 rm -f tarballs/$FILE
183 cd tarballs
Stefan Reinauer699ac272015-06-05 12:43:28 -0700184 wget --no-check-certificate -q $archive
Stefan Reinauer88935482015-06-05 09:51:10 -0700185 cd ..
186 test ! -f sum/$FILE.cksum && test -f tarballs/$FILE && \
187 (test -z "$CHECKSUM" || $CHECKSUM tarballs/$FILE > sum/$FILE.cksum ) && \
188 printf "(checksum created. ${RED}Note. Please upload sum/$FILE.cksum if the corresponding archive is upgraded.${NC})"
189 )
190 test -f tarballs/$FILE || \
191 printf "\n${RED}Failed to download $FILE.${NC}\n"
192 test -f tarballs/$FILE || exit 1
193 printf "\n"
194}
195
196unpack_and_patch() {
197 PACKAGE=$1
198 archive=$PACKAGE"_ARCHIVE"
199 archive="`eval echo '$'$archive`"
200 dir=$PACKAGE"_DIR"
201 dir="`eval echo '$'${dir}`"
202 test -d ${dir} && test -f ${dir}/.unpack_success || (
203 printf " * `basename $archive`\n"
204 FLAGS=zxf
205 suffix=`echo $archive | sed 's,.*\.,,'`
206 test "$suffix" = "gz" && FLAGS=zxf
207 test "$suffix" = "bz2" && FLAGS=jxf
208 test "$suffix" = "xz" && FLAGS="--xz -xf"
209 test "$suffix" = "lzma" && FLAGS="--lzma -xf"
210 $TAR $FLAGS tarballs/`basename $archive`
211 for patch in patches/${dir}_*.patch; do
212 test -r $patch || continue
213 printf " o `basename $patch`\n"
214 $PATCH -s -N -p0 < `echo $patch` || \
215 printf "\n${RED}Failed $patch.${NC}\n"
216 done
217 touch ${dir}/.unpack_success
218 )
219}
220
Patrick Georgi74c06422015-03-25 18:40:13 +0100221wait_for_build() {
222 # $1: directory in which log file and failure marker are stored
223 cat > "$1/crossgcc-build.log"
224 test -r "$1/.failed" && printf "${RED}failed${NC}. Check $1/crossgcc-build.log.\n" || \
225 printf "${green}ok${NC}\n"
226 test -r "$1/.failed" && exit 1
227 true
228}
229
Stefan Reinauer074d9132009-09-26 16:43:17 +0000230cleanup()
231{
232 printf "Cleaning up temporary files... "
Stefan Reinauer699ac272015-06-05 12:43:28 -0700233 # GCC toolchain
234 rm -rf ${GMP_DIR} ${BUILDDIRPREFIX}-gmp
235 rm -rf ${MPFR_DIR} ${BUILDDIRPREFIX}-mpfr
236 rm -rf ${MPC_DIR} ${BUILDDIRPREFIX}-mpc
237 rm -rf ${LIBELF_DIR} ${BUILDDIRPREFIX}-libelf
238 rm -rf ${BINUTILS_DIR} ${BUILDDIRPREFIX}-binutils
239 rm -rf ${GCC_DIR} ${BUILDDIRPREFIX}-gcc
240
241 # Other tools
242 rm -rf ${GDB_DIR} ${BUILDDIRPREFIX}-gdb
243 rm -rf ${EXPAT_DIR} ${BUILDDIRPREFIX}-expat
244 rm -rf ${PYTHON_DIR} ${BUILDDIRPREFIX}-python
245 rm -rf ${IASL_DIR}
246
Stefan Reinauer074d9132009-09-26 16:43:17 +0000247 printf "${green}ok${NC}\n"
248}
249
250myhelp()
251{
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100252 printf "Usage: $0 [-V] [-c] [-p <platform>] [-d <target directory>] [-D <dest dir>] [-G] [-S]\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000253 printf " $0 [-V|--version]\n"
254 printf " $0 [-h|--help]\n\n"
255
256 printf "Options:\n"
257 printf " [-V|--version] print version number and exit\n"
258 printf " [-h|--help] print this help and exit\n"
259 printf " [-c|--clean] remove temporary files before build\n"
260 printf " [-t|--savetemps] don't remove temporary files after build\n"
Patrick Georgic1a75b12011-11-04 21:37:14 +0100261 printf " [-y|--ccache] Use ccache when building cross compiler\n"
Patrick Georgi73166c72010-04-14 20:42:42 +0000262 printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000263 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
264 printf " (defaults to $TARGETARCH)\n"
265 printf " [-d|--directory <target dir>] target directory to install cross compiler to\n"
266 printf " (defaults to $TARGETDIR)\n\n"
267 printf " [-D|--destdir <dest dir>] destination directory to install cross compiler to\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100268 printf " (for RPM builds, default unset)\n"
269 printf " [-G|--gdb] build GNU debugger\n"
270 printf " [-S|--scripting] build scripting support for GDB\n\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000271}
272
273myversion()
274{
275 # version tag is always printed, so just print the license here
276
277 cat << EOF
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000278Copyright (C) 2008-2010 by coresystems GmbH
Marc Jones2aac3f62011-08-08 16:07:50 -0600279Copyright (C) 2011 by Sage Electronic Engineering
Stefan Reinauer074d9132009-09-26 16:43:17 +0000280
281This program is free software; you can redistribute it and/or modify
282it under the terms of the GNU General Public License as published by
283the Free Software Foundation; version 2 of the License.
284
285This program is distributed in the hope that it will be useful,
286but WITHOUT ANY WARRANTY; without even the implied warranty of
287MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
288GNU General Public License for more details.
289
290EOF
291}
292
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700293printf "${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 +0000294
Patrick Georgi6bba29f2010-01-29 17:40:52 +0000295# Look if we have getopt. If not, build it.
296export PATH=$PATH:.
297getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c
298
Stefan Reinauer074d9132009-09-26 16:43:17 +0000299# parse parameters.. try to find out whether we're running GNU getopt
Peter Stuge09377b72011-08-21 06:24:55 +0200300getoptbrand="`getopt -V | sed -e '1!d' -e 's,^\(......\).*,\1,'`"
301if [ "${getoptbrand}" = "getopt" ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000302 # Detected GNU getopt that supports long options.
Patrick Georgic1a75b12011-11-04 21:37:14 +0100303 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 +0000304 eval set "$args"
305else
306 # Detected non-GNU getopt
Patrick Georgic1a75b12011-11-04 21:37:14 +0100307 args=`getopt Vhcd:p:j:D:tGy $*`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000308 set -- $args
309fi
310
311if [ $? != 0 ]; then
312 myhelp
313 exit 1
314fi
315
316while true ; do
317 case "$1" in
318 -V|--version) shift; myversion; exit 0;;
319 -h|--help) shift; myhelp; exit 0;;
Patrick Georgi44af57a2013-12-19 22:06:22 +0100320 -c|--clean) shift; clean=1;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000321 -t|--savetemps) shift; SAVETEMPS=1;;
322 -d|--directory) shift; TARGETDIR="$1"; shift;;
323 -p|--platform) shift; TARGETARCH="$1"; shift;;
324 -D|--destdir) shift; DESTDIR="$1"; shift;;
Patrick Georgi73166c72010-04-14 20:42:42 +0000325 -j|--jobs) shift; JOBS="-j $1"; shift;;
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100326 -G|--gdb) shift; SKIPGDB=0;;
327 -S|--scripting) shift; SKIPPYTHON=0;;
Patrick Georgic1a75b12011-11-04 21:37:14 +0100328 -y|--ccache) shift; USECCACHE=1;;
Patrick Georgid2e0dd52013-06-09 08:05:45 +0200329 --) shift; break;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000330 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
Patrick Georgid2e0dd52013-06-09 08:05:45 +0200331 *) break;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000332 esac
333done
334
Ronald G. Minnichb460a662013-05-26 05:33:35 -0700335case "$TARGETARCH" in
Stefan Reinauer24f9cb92015-03-13 22:50:22 +0100336 x86_64-elf) ;;
337 x86_64*) TARGETARCH=x86_64-elf;;
David Hubbard5b0420a2013-05-28 16:33:15 -0600338 i386-elf) ;;
339 i386-mingw32) ;;
Patrick Georgi9b7efa52015-03-08 09:20:36 +0100340 mipsel-elf) ;;
Patrick Georgif0bbc952015-03-07 10:57:25 +0100341 riscv-elf) ;;
Ronald G. Minnichb460a662013-05-26 05:33:35 -0700342 i386*) TARGETARCH=i386-elf;;
Patrick Georgic8883262013-09-19 10:57:58 +0200343 arm*) TARGETARCH=armv7-a-eabi;;
Stefan Reinauer0d2119d2013-07-10 14:27:56 -0700344 aarch64*) TARGETARCH=aarch64-elf;;
345 *) printf "${red}WARNING: Unsupported architecture $TARGETARCH.${NC}\n\n"; ;;
Ronald G. Minnichb460a662013-05-26 05:33:35 -0700346esac
347
348echo "Target arch is now $TARGETARCH"
Stefan Reinauer699ac272015-06-05 12:43:28 -0700349NAME="${TARGETARCH} cross"
350PACKAGES="GMP MPFR MPC LIBELF BINUTILS GCC IASL"
351
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200352BUILDDIRPREFIX=build-${TARGETARCH}
353
Patrick Georgi44af57a2013-12-19 22:06:22 +0100354if [ "$clean" = "1" ]; then
355 cleanup
356fi
357
Peter Stugeceacd772011-06-09 04:54:16 +0200358if [ $SKIPGDB -eq 1 ]; then
359 printf "Will skip GDB ... ${green}ok${NC}\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100360 if [ $SKIPPYTHON -eq 0 ]; then
361 printf "Python scripting needs GDB ... disabling ... ${green}ok${NC}\n"
362 SKIPPYTHON=1
363 fi
Stefan Reinauer699ac272015-06-05 12:43:28 -0700364else
365 PACKAGES="$PACKAGES GDB"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100366fi
Stefan Reinauer699ac272015-06-05 12:43:28 -0700367if [ $SKIPPYTHON -eq 0 ]; then
368 PACKAGES="$PACKAGES EXPAT PYTHON"
Peter Stugeceacd772011-06-09 04:54:16 +0200369fi
370
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700371# coreboot does not like the GOLD linker
372# USE_GOLD="--enable-gold"
373USE_GOLD=""
374GCC_OPTIONS="--enable-lto"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000375
Stefan Reinauer074d9132009-09-26 16:43:17 +0000376printf "Downloading tar balls ... \n"
377mkdir -p tarballs
Stefan Reinauer699ac272015-06-05 12:43:28 -0700378for P in $PACKAGES; do
379 download $P
Stefan Reinauer074d9132009-09-26 16:43:17 +0000380done
Stefan Reinauer699ac272015-06-05 12:43:28 -0700381printf "Downloaded tar balls ... ${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000382
383printf "Unpacking and patching ... \n"
Stefan Reinauer699ac272015-06-05 12:43:28 -0700384for P in $PACKAGES; do
385 unpack_and_patch $P
Stefan Reinauer074d9132009-09-26 16:43:17 +0000386done
Stefan Reinauer699ac272015-06-05 12:43:28 -0700387printf "Unpacked and patched ... ${green}ok${NC}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000388
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700389CC=cc
Stefan Reinauer0d2119d2013-07-10 14:27:56 -0700390if [ $UNAME = "Darwin" ]; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000391 #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix"
392
393 # generally the OS X compiler can create x64 binaries.
394 # Per default it generated i386 binaries in 10.5 and x64
395 # binaries in 10.6 (even if the kernel is 32bit)
396 # For some weird reason, 10.5 autodetects an ABI=64 though
397 # so we're setting the ABI explicitly here.
Zheng Bao04ceed62012-10-23 19:41:25 +0800398 if [ `sysctl -n hw.optional.x86_64 2>/dev/null` -eq 1 ] 2>/dev/null; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000399 OPTIONS="ABI=64"
400 else
401 OPTIONS="ABI=32"
402 fi
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700403
Stefan Reinauer4266b922012-12-05 16:18:32 -0800404 # In Xcode 4.5.2 the default compiler is clang.
405 # However, this compiler fails to compile gcc 4.7.x. As a
406 # workaround it's possible to compile gcc with llvm-gcc.
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700407 if $CC -v 2>&1 | grep -q LLVM; then
Stefan Reinauer4266b922012-12-05 16:18:32 -0800408 CC=llvm-gcc
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700409 fi
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000410fi
411
Patrick Georgic1a75b12011-11-04 21:37:14 +0100412if [ "$USECCACHE" = 1 ]; then
413 CC="ccache $CC"
414fi
415
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200416mkdir -p ${BUILDDIRPREFIX}-gmp ${BUILDDIRPREFIX}-mpfr ${BUILDDIRPREFIX}-mpc ${BUILDDIRPREFIX}-libelf ${BUILDDIRPREFIX}-binutils \
Stefan Reinauer699ac272015-06-05 12:43:28 -0700417 ${BUILDDIRPREFIX}-gcc ${BUILDDIRPREFIX}-python ${BUILDDIRPREFIX}-expat ${BUILDDIRPREFIX}-gdb
Stefan Reinauer16bd7892012-12-07 23:57:01 +0100418
419mkdir -p $DESTDIR$TARGETDIR/bin
420export PATH=$DESTDIR$TARGETDIR/bin:$PATH
421
Stefan Reinauer699ac272015-06-05 12:43:28 -0700422[[ "$PACKAGES" == *GMP* ]] && \
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200423if [ -f ${BUILDDIRPREFIX}-gmp/.success ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000424 printf "Skipping GMP as it is already built\n"
425else
Stefan Reinauer699ac272015-06-05 12:43:28 -0700426 printf "Building GMP ${GMP_VERSION} ... "
Stefan Reinauer074d9132009-09-26 16:43:17 +0000427(
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200428 cd ${BUILDDIRPREFIX}-gmp
Stefan Reinauer074d9132009-09-26 16:43:17 +0000429 rm -f .failed
Patrick Georgi31bf37e2015-06-04 00:09:12 +0200430 CC="$CC" CFLAGS="-Os" ../${GMP_DIR}/configure --disable-shared --enable-fat --prefix=$TARGETDIR $OPTIONS \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000431 || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000432 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000433 $MAKE install DESTDIR=$DESTDIR || touch .failed
Patrick Georgi198d23c2012-12-08 08:02:44 +0100434
435 normalize_dirs
436
Stefan Reinauer074d9132009-09-26 16:43:17 +0000437 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi74c06422015-03-25 18:40:13 +0100438) 2>&1 | wait_for_build "${BUILDDIRPREFIX}-gmp" || exit 1
Stefan Reinauer074d9132009-09-26 16:43:17 +0000439
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700440# Now set CFLAGS to match GMP CFLAGS but strip out -pedantic
441# as GCC 4.6.x fails if it's there.
442HOSTCFLAGS=`grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2 |\
443 sed s,-pedantic,,`
Stefan Reinauer699ac272015-06-05 12:43:28 -0700444fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000445
Stefan Reinauer699ac272015-06-05 12:43:28 -0700446[[ "$PACKAGES" == *MPFR* ]] && \
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200447if [ -f ${BUILDDIRPREFIX}-mpfr/.success ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000448 printf "Skipping MPFR as it is already built\n"
449else
Stefan Reinauer699ac272015-06-05 12:43:28 -0700450 printf "Building MPFR ${MPFR_VERSION} ... "
Stefan Reinauer074d9132009-09-26 16:43:17 +0000451(
Stefan Reinauer0d2119d2013-07-10 14:27:56 -0700452 test $UNAME = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200453 cd ${BUILDDIRPREFIX}-mpfr
Stefan Reinauer074d9132009-09-26 16:43:17 +0000454 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100455 CC="$CC" ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000456 --infodir=$TARGETDIR/info \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100457 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
458 touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000459 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000460 $MAKE install DESTDIR=$DESTDIR || touch .failed
461
Patrick Georgi198d23c2012-12-08 08:02:44 +0100462 normalize_dirs
463
Stefan Reinauer074d9132009-09-26 16:43:17 +0000464 # work around build problem of libgmp.la
465 if [ "$DESTDIR" != "" ]; then
466 perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la
467 fi
468
469 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi74c06422015-03-25 18:40:13 +0100470) 2>&1 | wait_for_build "${BUILDDIRPREFIX}-mpfr" || exit 1
Stefan Reinauer074d9132009-09-26 16:43:17 +0000471fi
472
Stefan Reinauer699ac272015-06-05 12:43:28 -0700473[[ "$PACKAGES" == *MPC* ]] && \
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200474if [ -f ${BUILDDIRPREFIX}-mpc/.success ]; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000475 printf "Skipping MPC as it is already built\n"
476else
Stefan Reinauer699ac272015-06-05 12:43:28 -0700477 printf "Building MPC ${MPC_VERSION} ... "
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000478(
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200479 cd ${BUILDDIRPREFIX}-mpc
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000480 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100481 CC="$CC" ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000482 --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100483 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
484 touch .failed
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000485 $MAKE $JOBS || touch .failed
486 $MAKE install DESTDIR=$DESTDIR || touch .failed
487
Patrick Georgi198d23c2012-12-08 08:02:44 +0100488 normalize_dirs
489
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000490 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi74c06422015-03-25 18:40:13 +0100491) 2>&1 | wait_for_build "${BUILDDIRPREFIX}-mpc" || exit 1
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000492fi
493
Stefan Reinauer699ac272015-06-05 12:43:28 -0700494[[ "$PACKAGES" == *LIBELF* ]] && \
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200495if [ -f ${BUILDDIRPREFIX}-libelf/.success ]; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000496 printf "Skipping libelf as it is already built\n"
497else
Stefan Reinauer699ac272015-06-05 12:43:28 -0700498 printf "Building libelf ${LIBELF_VERSION} ... "
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000499(
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200500 cd ${BUILDDIRPREFIX}-libelf
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000501 rm -f .failed
502 echo "$HOSTCFLAGS"
Patrick Georgi643c9e82011-11-04 21:30:49 +0100503 CC="$CC" CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100504 ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000505 --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed
506 $MAKE $JOBS || touch .failed
Scott Duplichan4270a972014-12-12 20:21:40 -0600507 $MAKE install prefix=$DESTDIR$TARGETDIR || touch .failed
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000508
Patrick Georgi198d23c2012-12-08 08:02:44 +0100509 normalize_dirs
510
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000511 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi74c06422015-03-25 18:40:13 +0100512) 2>&1 | wait_for_build "${BUILDDIRPREFIX}-libelf" || exit 1
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000513fi
514
Stefan Reinauer699ac272015-06-05 12:43:28 -0700515[[ "$PACKAGES" == *BINUTILS* ]] && \
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200516if [ -f ${BUILDDIRPREFIX}-binutils/.success ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000517 printf "Skipping binutils as it is already built\n"
518else
Stefan Reinauer699ac272015-06-05 12:43:28 -0700519 printf "Building binutils ${BINUTILS_VERSION} ... "
Stefan Reinauer074d9132009-09-26 16:43:17 +0000520(
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700521 # What a pain: binutils don't come with configure
522 # script anymore. Create it:
523 cd binutils-${BINUTILS_VERSION}/
524 autoconf
525 cd ..
526 # Now build binutils
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200527 cd ${BUILDDIRPREFIX}-binutils
Stefan Reinauer074d9132009-09-26 16:43:17 +0000528 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100529 CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100530 --target=${TARGETARCH} --disable-werror --disable-nls \
531 $USE_GOLD CFLAGS="$HOSTCFLAGS" || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000532 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000533 $MAKE install DESTDIR=$DESTDIR || touch .failed
534 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi74c06422015-03-25 18:40:13 +0100535) 2>&1 | wait_for_build "${BUILDDIRPREFIX}-binutils" || exit 1
Stefan Reinauer074d9132009-09-26 16:43:17 +0000536fi
537
Stefan Reinauer699ac272015-06-05 12:43:28 -0700538[[ "$PACKAGES" == *GCC* ]] && \
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200539if [ -f ${BUILDDIRPREFIX}-gcc/.success ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000540 printf "Skipping GCC as it is already built\n"
541else
Stefan Reinauer699ac272015-06-05 12:43:28 -0700542 printf "Building GCC ${GCC_VERSION} ... "
Stefan Reinauer074d9132009-09-26 16:43:17 +0000543(
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700544 # Even worse than binutils: GCC does not come with configure
545 # script anymore, but also enforces an obsolete autoconf version
546 # to create it. This is a poster child of how autotools help make
547 # software portable.
548 cd gcc-${GCC_VERSION}
549 sed '/dnl Ensure exactly this Autoconf version is used/d' \
550 config/override.m4 > config/override.m4.new
551 autoconf_version=`autoconf -V | grep "autoconf" | tr ' ' '\n' | tail -1`
552 sed "s/${GCC_AUTOCONF_VERSION}/${autoconf_version}/g" \
553 config/override.m4.new > config/override.m4
554 autoconf
555 cd ..
556 # Now, finally, we can build gcc:
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200557 cd ${BUILDDIRPREFIX}-gcc
Stefan Reinauer074d9132009-09-26 16:43:17 +0000558 rm -f .failed
559 # GCC does not honour HOSTCFLAGS at all. CFLAGS are used for
560 # both target and host object files. This is pretty misdesigned.
561 # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
562 # but it does not seem to work properly. At least the host library
563 # libiberty is not compiled with CFLAGS_FOR_BUILD.
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700564 CC="$CC" CFLAGS_FOR_TARGET="-O2" CFLAGS="$HOSTCFLAGS" \
565 CFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000566 --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000567 --target=${TARGETARCH} --disable-werror --disable-shared \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000568 --disable-libssp --disable-bootstrap --disable-nls \
Patrick Georgi969cd932012-12-07 13:13:53 +0100569 --disable-libquadmath --without-headers \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000570 $GCC_OPTIONS --enable-languages="c" $USE_GOLD \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000571 --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000572 --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \
573 --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000574 || touch .failed
Patrick Georgi969cd932012-12-07 13:13:53 +0100575 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-gcc || touch .failed
576 $MAKE install-gcc DESTDIR=$DESTDIR || touch .failed
577
578 if [ "`echo $TARGETARCH | grep -c -- -mingw32`" -eq 0 ]; then
579 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-target-libgcc || touch .failed
580 $MAKE install-target-libgcc DESTDIR=$DESTDIR || touch .failed
581 fi
582
Stefan Reinauer074d9132009-09-26 16:43:17 +0000583 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi74c06422015-03-25 18:40:13 +0100584) 2>&1 | wait_for_build "${BUILDDIRPREFIX}-gcc" || exit 1
Stefan Reinauer074d9132009-09-26 16:43:17 +0000585fi
586
Stefan Reinauer699ac272015-06-05 12:43:28 -0700587[[ "$PACKAGES" == *EXPAT* ]] && \
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200588if [ -f ${BUILDDIRPREFIX}-expat/.success ]; then
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100589 printf "Skipping Expat as it is already built\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100590else
Stefan Reinauer699ac272015-06-05 12:43:28 -0700591 printf "Building Expat ${EXPAT_VERSION} ... "
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100592(
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200593 cd ${BUILDDIRPREFIX}-expat
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100594 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100595 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${EXPAT_DIR}/configure --disable-shared \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100596 --prefix=$TARGETDIR --target=${TARGETARCH} || touch .failed
597 $MAKE || touch .failed
598 $MAKE install DESTDIR=$DESTDIR || touch .failed
Patrick Georgi198d23c2012-12-08 08:02:44 +0100599
600 normalize_dirs
601
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100602 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi74c06422015-03-25 18:40:13 +0100603) 2>&1 | wait_for_build "${BUILDDIRPREFIX}-expat" || exit 1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100604fi
605
Stefan Reinauer699ac272015-06-05 12:43:28 -0700606[[ "$PACKAGES" == *PYTHON* ]] && \
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200607if [ -f ${BUILDDIRPREFIX}-python/.success ]; then
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100608 printf "Skipping Python as it is already built\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100609else
Stefan Reinauer699ac272015-06-05 12:43:28 -0700610 printf "Building Python ${PYTHON_VERSION} ... "
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100611(
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200612 cd ${BUILDDIRPREFIX}-python
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100613 rm -f .failed
Patrick Georgi643c9e82011-11-04 21:30:49 +0100614 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$TARGETDIR \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100615 --target=${TARGETARCH} || touch .failed
616 $MAKE $JOBS || touch .failed
617 $MAKE install DESTDIR=$DESTDIR || touch .failed
Patrick Georgi198d23c2012-12-08 08:02:44 +0100618
619 normalize_dirs
620
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100621 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi74c06422015-03-25 18:40:13 +0100622) 2>&1 | wait_for_build "${BUILDDIRPREFIX}-python" || exit 1
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100623fi
624
Stefan Reinauer699ac272015-06-05 12:43:28 -0700625[[ "$PACKAGES" == *GDB* ]] && \
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200626if [ -f ${BUILDDIRPREFIX}-gdb/.success ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000627 printf "Skipping GDB as it is already built\n"
628else
Stefan Reinauer699ac272015-06-05 12:43:28 -0700629 printf "Building GDB ${GDB_VERSION} ... "
Stefan Reinauer074d9132009-09-26 16:43:17 +0000630(
Patrick Georgi3af0aa22013-09-17 20:59:52 +0200631 cd ${BUILDDIRPREFIX}-gdb
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100632 export PYTHONHOME=$DESTDIR$TARGETDIR
Stefan Reinauer074d9132009-09-26 16:43:17 +0000633 rm -f .failed
Idwer Vollering1b7c9592015-04-09 15:34:07 +0200634 if [ $(uname) != "FreeBSD" -a $(uname) != "NetBSD" ]; then
635 LIBDL="-ldl"
636 fi
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100637 LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \
Idwer Vollering1b7c9592015-04-09 15:34:07 +0200638 -lpthread $LIBDL -lutil" \
Patrick Georgi643c9e82011-11-04 21:30:49 +0100639 CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100640 ../gdb-${GDB_VERSION}/configure --prefix=$TARGETDIR \
641 --target=${TARGETARCH} --disable-werror --disable-nls
Patrick Georgi73166c72010-04-14 20:42:42 +0000642 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000643 $MAKE install DESTDIR=$DESTDIR || touch .failed
644 if [ ! -f .failed ]; then touch .success; fi
Patrick Georgi74c06422015-03-25 18:40:13 +0100645) 2>&1 | wait_for_build "${BUILDDIRPREFIX}-gdb" || exit 1
Stefan Reinauer074d9132009-09-26 16:43:17 +0000646fi
647
Stefan Reinauer699ac272015-06-05 12:43:28 -0700648[[ "$PACKAGES" == *IASL* ]] && \
Patrick Georgi6e61ad32012-05-12 23:19:30 +0200649if [ -f $IASL_DIR/source/compiler/.success ]; then
Marc Jones2aac3f62011-08-08 16:07:50 -0600650 printf "Skipping IASL as it is already built\n"
651else
Stefan Reinauer699ac272015-06-05 12:43:28 -0700652 printf "Building IASL ${IASL_VERSION} ... "
Marc Jones2aac3f62011-08-08 16:07:50 -0600653(
Patrick Georgi74c06422015-03-25 18:40:13 +0100654 RDIR=$IASL_DIR/source/compiler
Idwer Vollering6b11c8b2012-11-15 21:14:36 +0100655 cd $IASL_DIR/generate/unix
Patrick Georgi74c06422015-03-25 18:40:13 +0100656 rm -f $RDIR/.failed
Marc Jones2aac3f62011-08-08 16:07:50 -0600657 CFLAGS="$HOSTCFLAGS"
Stefan Reinauer0d2119d2013-07-10 14:27:56 -0700658 HOST="_LINUX"
659 test $UNAME = "Darwin" && HOST="_APPLE"
660 test $UNAME = "FreeBSD" && HOST="_FreeBSD"
661 test $UNAME = "Cygwin" && HOST="_CYGWIN"
Patrick Georgi74c06422015-03-25 18:40:13 +0100662 HOST="$HOST" OPT_CFLAGS="-O -D_FORTIFY_SOURCE=2" CFLAGS="$CFLAGS" $MAKE CC="$CC" iasl || touch $RDIR/.failed
663 rm -f $DESTDIR$TARGETDIR/bin/iasl || touch $RDIR/.failed
664 cp bin/iasl $DESTDIR$TARGETDIR/bin || touch $RDIR/.failed
665 if [ ! -f $RDIR/.failed ]; then touch $RDIR/.success; fi
666) 2>&1 | wait_for_build "$IASL_DIR/source/compiler" || exit 1
Marc Jones2aac3f62011-08-08 16:07:50 -0600667fi
668
Stefan Reinauer699ac272015-06-05 12:43:28 -0700669# Adding git information of current tree to target directory
670# for reproducibility
Patrick Georgi5602f2c2015-03-28 15:48:47 +0100671PROGNAME=`basename "$0"`
672rm -f "$DESTDIR$TARGETDIR/$PROGNAME".commit.*
673cp "$PROGNAME" $DESTDIR$TARGETDIR/"$PROGNAME.commit.`git describe`"
Zheng Bao30b895f2013-02-06 18:04:40 +0800674
Stefan Reinauer074d9132009-09-26 16:43:17 +0000675if [ $SAVETEMPS -eq 0 ]; then
Stefan Reinauer699ac272015-06-05 12:43:28 -0700676 cleanup
Stefan Reinauer074d9132009-09-26 16:43:17 +0000677else
678 printf "Leaving temporary files around... ${green}ok${NC}\n"
679fi
680
Stefan Reinauer699ac272015-06-05 12:43:28 -0700681printf "\n${green}You can now run your $NAME toolchain from $TARGETDIR.${NC}\n"