blob: f25685121ce0f646b18cf006702c679e64efb0a3 [file] [log] [blame]
Stefan Reinauer074d9132009-09-26 16:43:17 +00001#!/bin/bash
2#
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#
Stefan Reinauer074d9132009-09-26 16:43:17 +00007# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; version 2 of the License.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19#
20
Stefan Reinauerace2dc32010-05-19 10:01:37 +000021CROSSGCC_DATE="May 18th, 2010"
22CROSSGCC_VERSION="1.01"
Stefan Reinauer074d9132009-09-26 16:43:17 +000023
24# default settings
25TARGETDIR=`pwd`/xgcc
26TARGETARCH=i386-elf
27DESTDIR=
28
29# version numbers
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000030GMP_VERSION=5.0.1
Stefan Reinauer6ade1612010-01-16 16:44:20 +000031MPFR_VERSION=2.4.2
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000032MPC_VERSION=0.8.2
33LIBELF_VERSION=0.8.13
Stefan Reinauerace2dc32010-05-19 10:01:37 +000034# GCC 4.5.0 is broken on some AMD boards:
35# GCC_VERSION=4.5.0 # enable for Link Time Optimization & Co
36GCC_VERSION=4.4.4
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000037BINUTILS_VERSION=2.20.1
38GDB_VERSION=7.1
Patrick Georgi73166c72010-04-14 20:42:42 +000039W32API_VERSION=3.14
40MINGWRT_VERSION=3.18
Stefan Reinauer074d9132009-09-26 16:43:17 +000041
42# archive locations
43GMP_ARCHIVE="ftp://ftp.gmplib.org/pub/gmp-${GMP_VERSION}/gmp-${GMP_VERSION}.tar.bz2"
Peter Stuge85e68702009-12-13 13:39:01 +000044MPFR_ARCHIVE="http://www.mpfr.org/mpfr-${MPFR_VERSION}/mpfr-${MPFR_VERSION}.tar.bz2"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000045MPC_ARCHIVE="http://www.multiprecision.org/mpc/download/mpc-${MPC_VERSION}.tar.gz"
46LIBELF_ARCHIVE="http://www.mr511.de/software/libelf-${LIBELF_VERSION}.tar.gz"
Stefan Reinauer074d9132009-09-26 16:43:17 +000047GCC_ARCHIVE="ftp://ftp.gwdg.de/pub/gnu/ftp/gnu/gcc/gcc-${GCC_VERSION}/gcc-core-${GCC_VERSION}.tar.bz2"
48BINUTILS_ARCHIVE="http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.bz2"
49GDB_ARCHIVE="http://ftp.gnu.org/gnu/gdb/gdb-${GDB_VERSION}.tar.bz2"
Patrick Georgi73166c72010-04-14 20:42:42 +000050W32API_ARCHIVE="http://downloads.sourceforge.net/project/mingw/MinGW%20API%20for%20MS-Windows/w32api-${W32API_VERSION}/w32api-${W32API_VERSION}-mingw32-src.tar.gz"
Stefan Reinauer6ade1612010-01-16 16:44:20 +000051MINGWRT_ARCHIVE="http://downloads.sourceforge.net/project/mingw/MinGW%20Runtime/mingwrt-${MINGWRT_VERSION}/mingwrt-${MINGWRT_VERSION}-mingw32-src.tar.gz"
Stefan Reinauer074d9132009-09-26 16:43:17 +000052
53GMP_DIR="gmp-${GMP_VERSION}"
54MPFR_DIR="mpfr-${MPFR_VERSION}"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000055MPC_DIR="mpc-${MPC_VERSION}"
56LIBELF_DIR="libelf-${LIBELF_VERSION}"
Stefan Reinauer074d9132009-09-26 16:43:17 +000057GCC_DIR="gcc-${GCC_VERSION}"
58BINUTILS_DIR="binutils-${BINUTILS_VERSION}"
59GDB_DIR="gdb-${GDB_VERSION}"
Stefan Reinauer6ade1612010-01-16 16:44:20 +000060W32API_DIR="w32api-${W32API_VERSION}-mingw32"
61MINGWRT_DIR="mingwrt-${MINGWRT_VERSION}-mingw32"
Stefan Reinauer074d9132009-09-26 16:43:17 +000062
63SAVETEMPS=0
64
65red='\e[0;31m'
66RED='\e[1;31m'
67green='\e[0;32m'
68GREEN='\e[1;32m'
69blue='\e[0;34m'
70BLUE='\e[1;34m'
71cyan='\e[0;36m'
72CYAN='\e[1;36m'
73NC='\e[0m' # No Color
74
75searchgnu()
76{
77 # $1 short name
78 # result: GNU version of that tool on stdout
79 # or no output if no GNU version was found
80 for i in "$1" "g$1" "gnu$1"; do
81 if test -x "`which $i 2>/dev/null`"; then
82 if test `$i --version 2>/dev/null |grep -c GNU` -gt 0; then
83 echo $i
84 return
85 fi
86 fi
87 done
88 printf "${RED}ERROR:${red} Missing toolchain: $1${NC}\n" >&2
89 exit 1
90}
91
92TAR=`searchgnu tar`
93PATCH=`searchgnu patch`
94MAKE=`searchgnu make`
95
96cleanup()
97{
98 printf "Cleaning up temporary files... "
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000099 rm -rf build-* combined gcc-* gmp-* mpfr-* mpc-* libelf-* binutils-* gdb-* w32api-* mingwrt-*
Stefan Reinauer074d9132009-09-26 16:43:17 +0000100 printf "${green}ok${NC}\n"
101}
102
103myhelp()
104{
105 printf "Usage: $0 [-V] [-c] [-p <platform>] [-d <target directory>] [-D <dest dir>]\n"
106 printf " $0 [-V|--version]\n"
107 printf " $0 [-h|--help]\n\n"
108
109 printf "Options:\n"
110 printf " [-V|--version] print version number and exit\n"
111 printf " [-h|--help] print this help and exit\n"
112 printf " [-c|--clean] remove temporary files before build\n"
113 printf " [-t|--savetemps] don't remove temporary files after build\n"
Patrick Georgi73166c72010-04-14 20:42:42 +0000114 printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000115 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
116 printf " (defaults to $TARGETARCH)\n"
117 printf " [-d|--directory <target dir>] target directory to install cross compiler to\n"
118 printf " (defaults to $TARGETDIR)\n\n"
119 printf " [-D|--destdir <dest dir>] destination directory to install cross compiler to\n"
120 printf " (for RPM builds, default unset)\n\n"
121}
122
123myversion()
124{
125 # version tag is always printed, so just print the license here
126
127 cat << EOF
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000128Copyright (C) 2008-2010 by coresystems GmbH
Stefan Reinauer074d9132009-09-26 16:43:17 +0000129
130This program is free software; you can redistribute it and/or modify
131it under the terms of the GNU General Public License as published by
132the Free Software Foundation; version 2 of the License.
133
134This program is distributed in the hope that it will be useful,
135but WITHOUT ANY WARRANTY; without even the implied warranty of
136MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
137GNU General Public License for more details.
138
139EOF
140}
141
142printf "${blue}Welcome to the ${red}coresystems${blue} cross toolchain builder v$CROSSGCC_VERSION ($CROSSGCC_DATE)${NC}\n\n"
143
Patrick Georgi6bba29f2010-01-29 17:40:52 +0000144# Look if we have getopt. If not, build it.
145export PATH=$PATH:.
146getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c
147
Stefan Reinauer074d9132009-09-26 16:43:17 +0000148# parse parameters.. try to find out whether we're running GNU getopt
149getoptbrand="`getopt -V`"
150if [ "${getoptbrand:0:6}" == "getopt" ]; then
151 # Detected GNU getopt that supports long options.
Patrick Georgi73166c72010-04-14 20:42:42 +0000152 args=`getopt -l version,help,clean,directory:,platform:,jobs:,destdir:,savetemps Vhcd:p:j:D:t -- "$@"`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000153 eval set "$args"
154else
155 # Detected non-GNU getopt
Patrick Georgi73166c72010-04-14 20:42:42 +0000156 args=`getopt Vhcd:p:j:D:t $*`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000157 set -- $args
158fi
159
160if [ $? != 0 ]; then
161 myhelp
162 exit 1
163fi
164
165while true ; do
166 case "$1" in
167 -V|--version) shift; myversion; exit 0;;
168 -h|--help) shift; myhelp; exit 0;;
169 -c|--clean) shift; cleanup;;
170 -t|--savetemps) shift; SAVETEMPS=1;;
171 -d|--directory) shift; TARGETDIR="$1"; shift;;
172 -p|--platform) shift; TARGETARCH="$1"; shift;;
173 -D|--destdir) shift; DESTDIR="$1"; shift;;
Patrick Georgi73166c72010-04-14 20:42:42 +0000174 -j|--jobs) shift; JOBS="-j $1"; shift;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000175 --) shift; break;;
176 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
177 *) break;;
178 esac
179done
180
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000181MINGW_ARCHIVES=""
182if [ "$TARGETARCH" = "i386-mingw32" ]; then
183 MINGW_ARCHIVES="$W32API_ARCHIVE $MINGWRT_ARCHIVE"
184fi
185
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000186if [ ${GCC_VERSION} == "4.5.0" -o ${GCC_VERSION} == "4.6.0" ]; then
187 # coreboot does not like the GOLD linker
188 # USE_GOLD="--enable-gold"
189 USE_GOLD=""
190 GCC_OPTIONS="--enable-lto"
191fi
192
193if [ ${GCC_VERSION} == "4.6.0" ]; then
194 if [ ! -r tarballs/gcc-core-${GCC_VERSION}.tar.bz2 ]; then
195 printf "Pre-Release GCC ${GCC_VERSION}, checking out subversion trunk\n"
196 mkdir -p tarballs/.tmp
197 cd tarballs/.tmp
198 rm -rf gcc-${GCC_VERSION}
199 svn export -q svn://gcc.gnu.org/svn/gcc/trunk gcc-${GCC_VERSION}
200 printf "done. Now creating tar ball...\n"
201 tar cjf ../gcc-core-${GCC_VERSION}.tar.bz2 gcc-${GCC_VERSION}
202 printf "done. Now cleaning up...\n"
203 cd ..
204 rm -rf .tmp
205 cd ..
206 printf "done.\n"
207 fi
208fi
209
Stefan Reinauer074d9132009-09-26 16:43:17 +0000210printf "Downloading tar balls ... \n"
211mkdir -p tarballs
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000212for ARCHIVE in $GMP_ARCHIVE $MPFR_ARCHIVE $MPC_ARCHIVE $LIBELF_ARCHIVE $GCC_ARCHIVE $BINUTILS_ARCHIVE $GDB_ARCHIVE $MINGW_ARCHIVES; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000213 FILE=`basename $ARCHIVE`
214 printf " * $FILE "
215 test -f tarballs/$FILE && printf "(cached)" || (
216 printf "(downloading)"
217 cd tarballs
218 wget -q $ARCHIVE
219 )
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000220 test -f tarballs/$FILE || printf "\n${RED}Failed to download $FILE.${red}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000221 test -f tarballs/$FILE || exit 1
222 printf "\n"
223done
224printf "Downloaded tar balls ... "
225printf "${green}ok${NC}\n"
226
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000227MINGW_PACKAGES=""
228if [ "$TARGETARCH" = "i386-mingw32" ]; then
229 MINGW_PACKAGES="W32API MINGWRT"
230fi
231
Stefan Reinauer074d9132009-09-26 16:43:17 +0000232printf "Unpacking and patching ... \n"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000233for PACKAGE in GMP MPFR MPC LIBELF GCC BINUTILS GDB $MINGW_PACKAGES; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000234 archive=$PACKAGE"_ARCHIVE"
235 archive=${!archive}
236 dir=$PACKAGE"_DIR"
Stefan Reinauer14e22772010-04-27 06:56:47 +0000237 test -d ${!dir} || (
Stefan Reinauer074d9132009-09-26 16:43:17 +0000238 printf " * `basename $archive`\n"
239 FLAGS=zxf
240 test ${archive:${#archive}-2:2} = "gz" && FLAGS=zxf
241 test ${archive:${#archive}-3:3} = "bz2" && FLAGS=jxf
242 $TAR $FLAGS tarballs/`basename $archive`
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000243 for patch in patches/${!dir}_*.patch; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000244 test -r $patch || continue
245 printf " o `basename $patch`\n"
Patrick Georgi6bba29f2010-01-29 17:40:52 +0000246 $PATCH -s -N -p0 < `echo $patch`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000247 done
248 )
249done
250printf "Unpacked and patched ... "
251printf "${green}ok${NC}\n"
252
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000253if [ "$TARGETARCH" = "i386-mingw32" ]; then
254 mkdir -p $TARGETDIR/i386-mingw32/sys-include
255 mv $MINGWRT_DIR/include/* $W32API_DIR/include/* $TARGETDIR/i386-mingw32/sys-include
256fi
257
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000258if [ `uname` = "Darwin" ]; then
259 #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix"
260
261 # generally the OS X compiler can create x64 binaries.
262 # Per default it generated i386 binaries in 10.5 and x64
263 # binaries in 10.6 (even if the kernel is 32bit)
264 # For some weird reason, 10.5 autodetects an ABI=64 though
265 # so we're setting the ABI explicitly here.
266 if [ `sysctl -n hw.optional.x86_64` -eq 1 ]; then
267 OPTIONS="ABI=64"
268 else
269 OPTIONS="ABI=32"
270 fi
271 # old check:
272 #OPTIONS="ABI=32"
273 #touch .architecture_check.c
274 #gcc .architecture_check.c -c -o .architecture_check.o
275 #ARCH=`file .architecture_check.o |cut -f5 -d\ `
276 #test "$ARCH" = "x86_64" && OPTIONS="ABI=64"
277 #rm .architecture_check.c .architecture_check.o
278fi
279
280mkdir -p build-gmp build-mpfr build-mpc build-libelf build-binutils build-gcc build-gdb
Stefan Reinauer074d9132009-09-26 16:43:17 +0000281if [ -f build-gmp/.success ]; then
282 printf "Skipping GMP as it is already built\n"
283else
284printf "Building GMP ${GMP_VERSION} ... "
285(
286 cd build-gmp
287 rm -f .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000288 ../${GMP_DIR}/configure --disable-shared --prefix=$TARGETDIR $OPTIONS \
289 || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000290 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000291 $MAKE install DESTDIR=$DESTDIR || touch .failed
292 if [ ! -f .failed ]; then touch .success; fi
293) &> build-gmp/crossgcc-build.log
294test -r build-gmp/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
295test -r build-gmp/.failed && exit 1
296fi
297
298#if [ "$DESTDIR" != "" -a ! -x $TARGETDIR ]; then
299# # create compat link
300# ln -s $DESTDIR$TARGETDIR $TARGETDIR
301#fi
302
303# Now set CFLAGS to match GMP CFLAGS.
304HOSTCFLAGS=`grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2`
305
306if [ -f build-mpfr/.success ]; then
307 printf "Skipping MPFR as it is already built\n"
308else
309printf "Building MPFR ${MPFR_VERSION} ... "
310(
311 test `uname` = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
312 cd build-mpfr
313 rm -f .failed
314 ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
315 --infodir=$TARGETDIR/info \
316 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000317 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000318 $MAKE install DESTDIR=$DESTDIR || touch .failed
319
320 # work around build problem of libgmp.la
321 if [ "$DESTDIR" != "" ]; then
322 perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la
323 fi
324
325 if [ ! -f .failed ]; then touch .success; fi
326) &> build-mpfr/crossgcc-build.log
327test -r build-mpfr/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
328test -r build-mpfr/.failed && exit 1
329fi
330
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000331if [ -f build-mpc/.success ]; then
332 printf "Skipping MPC as it is already built\n"
333else
334printf "Building MPC ${MPC_VERSION} ... "
335(
336 #test `uname` = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
337 cd build-mpc
338 rm -f .failed
339 ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \
340 --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \
341 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || touch .failed
342 $MAKE $JOBS || touch .failed
343 $MAKE install DESTDIR=$DESTDIR || touch .failed
344
345 if [ ! -f .failed ]; then touch .success; fi
346) &> build-mpc/crossgcc-build.log
347test -r build-mpc/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
348test -r build-mpc/.failed && exit 1
349fi
350
351if [ -f build-libelf/.success ]; then
352 printf "Skipping libelf as it is already built\n"
353else
354printf "Building libelf ${LIBELF_VERSION} ... "
355(
356 cd build-libelf
357 rm -f .failed
358 echo "$HOSTCFLAGS"
359 CFLAGS="$HOSTCFLAGS" ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \
360 --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed
361 $MAKE $JOBS || touch .failed
362 $MAKE install DESTDIR=$DESTDIR || touch .failed
363
364 if [ ! -f .failed ]; then touch .success; fi
365) &> build-libelf/crossgcc-build.log
366test -r build-libelf/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
367test -r build-libelf/.failed && exit 1
368fi
369
Stefan Reinauer074d9132009-09-26 16:43:17 +0000370if [ -f build-binutils/.success ]; then
371 printf "Skipping binutils as it is already built\n"
372else
373printf "Building binutils ${BINUTILS_VERSION} ... "
374(
375 cd build-binutils
376 rm -f .failed
377 ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR --target=${TARGETARCH} \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000378 --disable-werror --disable-nls $USE_GOLD \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000379 CFLAGS="$HOSTCFLAGS" || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000380 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000381 $MAKE install DESTDIR=$DESTDIR || touch .failed
382 if [ ! -f .failed ]; then touch .success; fi
383) &> build-binutils/crossgcc-build.log
384test -r build-binutils/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
385test -r build-binutils/.failed && exit 1
386fi
387
388if [ -f build-gcc/.success ]; then
389 printf "Skipping GCC as it is already built\n"
390else
391printf "Building GCC ${GCC_VERSION} ... "
392(
393 cd build-gcc
Patrick Georgiba3b0eb2010-09-03 08:53:06 +0000394 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
Stefan Reinauer074d9132009-09-26 16:43:17 +0000395 rm -f .failed
396 # GCC does not honour HOSTCFLAGS at all. CFLAGS are used for
397 # both target and host object files. This is pretty misdesigned.
398 # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
399 # but it does not seem to work properly. At least the host library
400 # libiberty is not compiled with CFLAGS_FOR_BUILD.
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000401 CFLAGS_FOR_TARGET="-O2" CFLAGS="$HOSTCFLAGS" CFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000402 --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000403 --target=${TARGETARCH} --disable-werror --disable-shared \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000404 --disable-libssp --disable-bootstrap --disable-nls \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000405 $GCC_OPTIONS --enable-languages="c" $USE_GOLD \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000406 --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000407 --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \
408 --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000409 || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000410 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000411 $MAKE install DESTDIR=$DESTDIR || touch .failed
412 if [ ! -f .failed ]; then touch .success; fi
413) &> build-gcc/crossgcc-build.log
414test -r build-gcc/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
415test -r build-gcc/.failed && exit 1
416fi
417
418if [ -f build-gdb/.success ]; then
419 printf "Skipping GDB as it is already built\n"
420else
421printf "Building GDB ${GDB_VERSION} ... "
422(
423 cd build-gdb
Patrick Georgiba3b0eb2010-09-03 08:53:06 +0000424 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
Stefan Reinauer074d9132009-09-26 16:43:17 +0000425 rm -f .failed
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000426 CFLAGS="$HOSTCFLAGS" ../gdb-${GDB_VERSION}/configure --prefix=$TARGETDIR --target=${TARGETARCH} \
427 --without-python --disable-werror --disable-nls
Patrick Georgi73166c72010-04-14 20:42:42 +0000428 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000429 $MAKE install DESTDIR=$DESTDIR || touch .failed
430 if [ ! -f .failed ]; then touch .success; fi
431) &> build-gdb/crossgcc-build.log
432test -r build-gdb/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
433test -r build-gdb/.failed && exit 1
434fi
435
436if [ $SAVETEMPS -eq 0 ]; then
437 printf "Cleaning up... "
438 rm -rf ${GMP_DIR} build-gmp
439 rm -rf ${MPFR_DIR} build-mpfr
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000440 rm -rf ${MPC_DIR} build-mpc
441 rm -rf ${LIBELF_DIR} build-libelf
Stefan Reinauer074d9132009-09-26 16:43:17 +0000442 rm -rf ${BINUTILS_DIR} build-binutils
443 rm -rf ${GCC_DIR} build-gcc
444 rm -rf ${GDB_DIR} build-gdb
445 printf "${green}ok${NC}\n"
446else
447 printf "Leaving temporary files around... ${green}ok${NC}\n"
448fi
449
450printf "\n${green}You can now run your $TARGETARCH cross toolchain from $TARGETDIR.${NC}\n"
451
452