blob: 355b01afb4b7e8380f11c2eeb1c718301efa9337 [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 Reinauer5411e712010-12-17 02:32:42 +000021CROSSGCC_DATE="December 16th, 2010"
22CROSSGCC_VERSION="1.03"
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
Marc Jones36932662010-12-03 00:45:56 +000031MPFR_VERSION=3.0.0
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000032MPC_VERSION=0.8.2
33LIBELF_VERSION=0.8.13
Stefan Reinauer5411e712010-12-17 02:32:42 +000034GCC_VERSION=4.5.2
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000035BINUTILS_VERSION=2.20.1
Marc Jones36932662010-12-03 00:45:56 +000036GDB_VERSION=7.2
37W32API_VERSION=3.15
Patrick Georgi73166c72010-04-14 20:42:42 +000038MINGWRT_VERSION=3.18
Stefan Reinauer074d9132009-09-26 16:43:17 +000039
40# archive locations
41GMP_ARCHIVE="ftp://ftp.gmplib.org/pub/gmp-${GMP_VERSION}/gmp-${GMP_VERSION}.tar.bz2"
Peter Stuge85e68702009-12-13 13:39:01 +000042MPFR_ARCHIVE="http://www.mpfr.org/mpfr-${MPFR_VERSION}/mpfr-${MPFR_VERSION}.tar.bz2"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000043MPC_ARCHIVE="http://www.multiprecision.org/mpc/download/mpc-${MPC_VERSION}.tar.gz"
44LIBELF_ARCHIVE="http://www.mr511.de/software/libelf-${LIBELF_VERSION}.tar.gz"
Stefan Reinauer5411e712010-12-17 02:32:42 +000045GCC_ARCHIVE="ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-${GCC_VERSION}/gcc-core-${GCC_VERSION}.tar.bz2"
Stefan Reinauer074d9132009-09-26 16:43:17 +000046BINUTILS_ARCHIVE="http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.bz2"
47GDB_ARCHIVE="http://ftp.gnu.org/gnu/gdb/gdb-${GDB_VERSION}.tar.bz2"
Marc Jones36932662010-12-03 00:45:56 +000048W32API_ARCHIVE="http://downloads.sourceforge.net/project/mingw/MinGW/BaseSystem/RuntimeLibrary/Win32-API/w32api-${W32API_VERSION}/w32api-${W32API_VERSION}-mingw32-src.tar.gz"
49MINGWRT_ARCHIVE="http://downloads.sourceforge.net/project/mingw/MinGW/BaseSystem/RuntimeLibrary/MinGW-RT/mingwrt-${MINGWRT_VERSION}/mingwrt-${MINGWRT_VERSION}-mingw32-src.tar.gz"
Stefan Reinauer074d9132009-09-26 16:43:17 +000050
51GMP_DIR="gmp-${GMP_VERSION}"
52MPFR_DIR="mpfr-${MPFR_VERSION}"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000053MPC_DIR="mpc-${MPC_VERSION}"
54LIBELF_DIR="libelf-${LIBELF_VERSION}"
Stefan Reinauer074d9132009-09-26 16:43:17 +000055GCC_DIR="gcc-${GCC_VERSION}"
56BINUTILS_DIR="binutils-${BINUTILS_VERSION}"
57GDB_DIR="gdb-${GDB_VERSION}"
Stefan Reinauer6ade1612010-01-16 16:44:20 +000058W32API_DIR="w32api-${W32API_VERSION}-mingw32"
59MINGWRT_DIR="mingwrt-${MINGWRT_VERSION}-mingw32"
Stefan Reinauer074d9132009-09-26 16:43:17 +000060
61SAVETEMPS=0
Peter Stugeceacd772011-06-09 04:54:16 +020062SKIPGDB=0
Stefan Reinauer074d9132009-09-26 16:43:17 +000063
64red='\e[0;31m'
65RED='\e[1;31m'
66green='\e[0;32m'
67GREEN='\e[1;32m'
68blue='\e[0;34m'
69BLUE='\e[1;34m'
70cyan='\e[0;36m'
71CYAN='\e[1;36m'
72NC='\e[0m' # No Color
73
74searchgnu()
75{
76 # $1 short name
77 # result: GNU version of that tool on stdout
78 # or no output if no GNU version was found
79 for i in "$1" "g$1" "gnu$1"; do
80 if test -x "`which $i 2>/dev/null`"; then
81 if test `$i --version 2>/dev/null |grep -c GNU` -gt 0; then
82 echo $i
83 return
84 fi
85 fi
86 done
87 printf "${RED}ERROR:${red} Missing toolchain: $1${NC}\n" >&2
88 exit 1
89}
90
Patrick Georgi68df8042011-07-17 11:36:10 +020091TAR=`searchgnu tar` || exit $?
92PATCH=`searchgnu patch` || exit $?
93MAKE=`searchgnu make` || exit $?
Stefan Reinauer074d9132009-09-26 16:43:17 +000094
95cleanup()
96{
97 printf "Cleaning up temporary files... "
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000098 rm -rf build-* combined gcc-* gmp-* mpfr-* mpc-* libelf-* binutils-* gdb-* w32api-* mingwrt-*
Stefan Reinauer074d9132009-09-26 16:43:17 +000099 printf "${green}ok${NC}\n"
100}
101
102myhelp()
103{
Peter Stugeceacd772011-06-09 04:54:16 +0200104 printf "Usage: $0 [-V] [-c] [-p <platform>] [-d <target directory>] [-D <dest dir>] [-G]\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000105 printf " $0 [-V|--version]\n"
106 printf " $0 [-h|--help]\n\n"
107
108 printf "Options:\n"
109 printf " [-V|--version] print version number and exit\n"
110 printf " [-h|--help] print this help and exit\n"
111 printf " [-c|--clean] remove temporary files before build\n"
112 printf " [-t|--savetemps] don't remove temporary files after build\n"
Patrick Georgi73166c72010-04-14 20:42:42 +0000113 printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000114 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
115 printf " (defaults to $TARGETARCH)\n"
116 printf " [-d|--directory <target dir>] target directory to install cross compiler to\n"
117 printf " (defaults to $TARGETDIR)\n\n"
118 printf " [-D|--destdir <dest dir>] destination directory to install cross compiler to\n"
119 printf " (for RPM builds, default unset)\n\n"
Peter Stugeceacd772011-06-09 04:54:16 +0200120 printf " [-G|--skip-gdb] don't build GNU debugger\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000121}
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.
Peter Stugeceacd772011-06-09 04:54:16 +0200152 args=`getopt -l version,help,clean,directory:,platform:,jobs:,destdir:,savetemps,skip-gdb Vhcd:p:j:D:tG -- "$@"`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000153 eval set "$args"
154else
155 # Detected non-GNU getopt
Peter Stugeceacd772011-06-09 04:54:16 +0200156 args=`getopt Vhcd:p:j:D:tG $*`
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;;
Peter Stugeceacd772011-06-09 04:54:16 +0200175 -G|--skip-gdb) shift; SKIPGDB=1;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000176 --) shift; break;;
177 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
178 *) break;;
179 esac
180done
181
Peter Stugeceacd772011-06-09 04:54:16 +0200182GDB_PACKAGE="GDB"
183if [ $SKIPGDB -eq 1 ]; then
184 printf "Will skip GDB ... ${green}ok${NC}\n"
185 GDB_PACKAGE=""
186fi
187
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000188MINGW_ARCHIVES=""
189if [ "$TARGETARCH" = "i386-mingw32" ]; then
190 MINGW_ARCHIVES="$W32API_ARCHIVE $MINGWRT_ARCHIVE"
191fi
192
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000193if [ ${GCC_VERSION} == "4.5.0" -o ${GCC_VERSION} == "4.6.0" ]; then
194 # coreboot does not like the GOLD linker
195 # USE_GOLD="--enable-gold"
196 USE_GOLD=""
197 GCC_OPTIONS="--enable-lto"
198fi
199
200if [ ${GCC_VERSION} == "4.6.0" ]; then
201 if [ ! -r tarballs/gcc-core-${GCC_VERSION}.tar.bz2 ]; then
202 printf "Pre-Release GCC ${GCC_VERSION}, checking out subversion trunk\n"
203 mkdir -p tarballs/.tmp
204 cd tarballs/.tmp
205 rm -rf gcc-${GCC_VERSION}
206 svn export -q svn://gcc.gnu.org/svn/gcc/trunk gcc-${GCC_VERSION}
207 printf "done. Now creating tar ball...\n"
208 tar cjf ../gcc-core-${GCC_VERSION}.tar.bz2 gcc-${GCC_VERSION}
209 printf "done. Now cleaning up...\n"
210 cd ..
211 rm -rf .tmp
212 cd ..
213 printf "done.\n"
214 fi
215fi
216
Stefan Reinauer074d9132009-09-26 16:43:17 +0000217printf "Downloading tar balls ... \n"
218mkdir -p tarballs
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000219for 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 +0000220 FILE=`basename $ARCHIVE`
221 printf " * $FILE "
222 test -f tarballs/$FILE && printf "(cached)" || (
223 printf "(downloading)"
224 cd tarballs
225 wget -q $ARCHIVE
226 )
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000227 test -f tarballs/$FILE || printf "\n${RED}Failed to download $FILE.${red}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000228 test -f tarballs/$FILE || exit 1
229 printf "\n"
230done
231printf "Downloaded tar balls ... "
232printf "${green}ok${NC}\n"
233
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000234MINGW_PACKAGES=""
235if [ "$TARGETARCH" = "i386-mingw32" ]; then
236 MINGW_PACKAGES="W32API MINGWRT"
237fi
238
Stefan Reinauer074d9132009-09-26 16:43:17 +0000239printf "Unpacking and patching ... \n"
Peter Stugeceacd772011-06-09 04:54:16 +0200240for PACKAGE in GMP MPFR MPC LIBELF GCC BINUTILS $GDB_PACKAGE $MINGW_PACKAGES; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000241 archive=$PACKAGE"_ARCHIVE"
242 archive=${!archive}
243 dir=$PACKAGE"_DIR"
Stefan Reinauer14e22772010-04-27 06:56:47 +0000244 test -d ${!dir} || (
Stefan Reinauer074d9132009-09-26 16:43:17 +0000245 printf " * `basename $archive`\n"
246 FLAGS=zxf
247 test ${archive:${#archive}-2:2} = "gz" && FLAGS=zxf
248 test ${archive:${#archive}-3:3} = "bz2" && FLAGS=jxf
249 $TAR $FLAGS tarballs/`basename $archive`
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000250 for patch in patches/${!dir}_*.patch; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000251 test -r $patch || continue
252 printf " o `basename $patch`\n"
Patrick Georgi6bba29f2010-01-29 17:40:52 +0000253 $PATCH -s -N -p0 < `echo $patch`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000254 done
255 )
256done
257printf "Unpacked and patched ... "
258printf "${green}ok${NC}\n"
259
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000260if [ "$TARGETARCH" = "i386-mingw32" ]; then
261 mkdir -p $TARGETDIR/i386-mingw32/sys-include
262 mv $MINGWRT_DIR/include/* $W32API_DIR/include/* $TARGETDIR/i386-mingw32/sys-include
263fi
264
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000265if [ `uname` = "Darwin" ]; then
266 #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix"
267
268 # generally the OS X compiler can create x64 binaries.
269 # Per default it generated i386 binaries in 10.5 and x64
270 # binaries in 10.6 (even if the kernel is 32bit)
271 # For some weird reason, 10.5 autodetects an ABI=64 though
272 # so we're setting the ABI explicitly here.
273 if [ `sysctl -n hw.optional.x86_64` -eq 1 ]; then
274 OPTIONS="ABI=64"
275 else
276 OPTIONS="ABI=32"
277 fi
278 # old check:
279 #OPTIONS="ABI=32"
280 #touch .architecture_check.c
281 #gcc .architecture_check.c -c -o .architecture_check.o
282 #ARCH=`file .architecture_check.o |cut -f5 -d\ `
283 #test "$ARCH" = "x86_64" && OPTIONS="ABI=64"
284 #rm .architecture_check.c .architecture_check.o
285fi
286
Peter Stugeceacd772011-06-09 04:54:16 +0200287mkdir -p build-gmp build-mpfr build-mpc build-libelf build-binutils build-gcc
288if [ $SKIPGDB -eq 0 ]; then
289 mkdir -p build-gdb
290fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000291if [ -f build-gmp/.success ]; then
292 printf "Skipping GMP as it is already built\n"
293else
294printf "Building GMP ${GMP_VERSION} ... "
295(
296 cd build-gmp
297 rm -f .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000298 ../${GMP_DIR}/configure --disable-shared --prefix=$TARGETDIR $OPTIONS \
299 || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000300 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000301 $MAKE install DESTDIR=$DESTDIR || touch .failed
302 if [ ! -f .failed ]; then touch .success; fi
303) &> build-gmp/crossgcc-build.log
304test -r build-gmp/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
305test -r build-gmp/.failed && exit 1
306fi
307
308#if [ "$DESTDIR" != "" -a ! -x $TARGETDIR ]; then
309# # create compat link
310# ln -s $DESTDIR$TARGETDIR $TARGETDIR
311#fi
312
313# Now set CFLAGS to match GMP CFLAGS.
314HOSTCFLAGS=`grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2`
315
316if [ -f build-mpfr/.success ]; then
317 printf "Skipping MPFR as it is already built\n"
318else
319printf "Building MPFR ${MPFR_VERSION} ... "
320(
321 test `uname` = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
322 cd build-mpfr
323 rm -f .failed
324 ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
325 --infodir=$TARGETDIR/info \
326 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000327 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000328 $MAKE install DESTDIR=$DESTDIR || touch .failed
329
330 # work around build problem of libgmp.la
331 if [ "$DESTDIR" != "" ]; then
332 perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la
333 fi
334
335 if [ ! -f .failed ]; then touch .success; fi
336) &> build-mpfr/crossgcc-build.log
337test -r build-mpfr/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
338test -r build-mpfr/.failed && exit 1
339fi
340
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000341if [ -f build-mpc/.success ]; then
342 printf "Skipping MPC as it is already built\n"
343else
344printf "Building MPC ${MPC_VERSION} ... "
345(
346 #test `uname` = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
347 cd build-mpc
348 rm -f .failed
349 ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \
350 --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \
351 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || touch .failed
352 $MAKE $JOBS || touch .failed
353 $MAKE install DESTDIR=$DESTDIR || touch .failed
354
355 if [ ! -f .failed ]; then touch .success; fi
356) &> build-mpc/crossgcc-build.log
357test -r build-mpc/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
358test -r build-mpc/.failed && exit 1
359fi
360
361if [ -f build-libelf/.success ]; then
362 printf "Skipping libelf as it is already built\n"
363else
364printf "Building libelf ${LIBELF_VERSION} ... "
365(
366 cd build-libelf
367 rm -f .failed
368 echo "$HOSTCFLAGS"
Marc Jones36932662010-12-03 00:45:56 +0000369 CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000370 --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed
371 $MAKE $JOBS || touch .failed
372 $MAKE install DESTDIR=$DESTDIR || touch .failed
373
374 if [ ! -f .failed ]; then touch .success; fi
375) &> build-libelf/crossgcc-build.log
376test -r build-libelf/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
377test -r build-libelf/.failed && exit 1
378fi
379
Stefan Reinauer074d9132009-09-26 16:43:17 +0000380if [ -f build-binutils/.success ]; then
381 printf "Skipping binutils as it is already built\n"
382else
383printf "Building binutils ${BINUTILS_VERSION} ... "
384(
385 cd build-binutils
386 rm -f .failed
387 ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR --target=${TARGETARCH} \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000388 --disable-werror --disable-nls $USE_GOLD \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000389 CFLAGS="$HOSTCFLAGS" || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000390 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000391 $MAKE install DESTDIR=$DESTDIR || touch .failed
392 if [ ! -f .failed ]; then touch .success; fi
393) &> build-binutils/crossgcc-build.log
394test -r build-binutils/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
395test -r build-binutils/.failed && exit 1
396fi
397
398if [ -f build-gcc/.success ]; then
399 printf "Skipping GCC as it is already built\n"
400else
401printf "Building GCC ${GCC_VERSION} ... "
402(
403 cd build-gcc
Patrick Georgiba3b0eb2010-09-03 08:53:06 +0000404 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
Stefan Reinauer074d9132009-09-26 16:43:17 +0000405 rm -f .failed
406 # GCC does not honour HOSTCFLAGS at all. CFLAGS are used for
407 # both target and host object files. This is pretty misdesigned.
408 # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
409 # but it does not seem to work properly. At least the host library
410 # libiberty is not compiled with CFLAGS_FOR_BUILD.
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000411 CFLAGS_FOR_TARGET="-O2" CFLAGS="$HOSTCFLAGS" CFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000412 --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000413 --target=${TARGETARCH} --disable-werror --disable-shared \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000414 --disable-libssp --disable-bootstrap --disable-nls \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000415 $GCC_OPTIONS --enable-languages="c" $USE_GOLD \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000416 --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000417 --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \
418 --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000419 || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000420 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000421 $MAKE install DESTDIR=$DESTDIR || touch .failed
422 if [ ! -f .failed ]; then touch .success; fi
423) &> build-gcc/crossgcc-build.log
424test -r build-gcc/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
425test -r build-gcc/.failed && exit 1
426fi
427
428if [ -f build-gdb/.success ]; then
429 printf "Skipping GDB as it is already built\n"
Peter Stugeceacd772011-06-09 04:54:16 +0200430elif [ $SKIPGDB -eq 1 ]; then
431 printf "Skipping GDB as requested by command line\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000432else
433printf "Building GDB ${GDB_VERSION} ... "
434(
435 cd build-gdb
Patrick Georgiba3b0eb2010-09-03 08:53:06 +0000436 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
Stefan Reinauer074d9132009-09-26 16:43:17 +0000437 rm -f .failed
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000438 CFLAGS="$HOSTCFLAGS" ../gdb-${GDB_VERSION}/configure --prefix=$TARGETDIR --target=${TARGETARCH} \
439 --without-python --disable-werror --disable-nls
Patrick Georgi73166c72010-04-14 20:42:42 +0000440 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000441 $MAKE install DESTDIR=$DESTDIR || touch .failed
442 if [ ! -f .failed ]; then touch .success; fi
443) &> build-gdb/crossgcc-build.log
444test -r build-gdb/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
445test -r build-gdb/.failed && exit 1
446fi
447
448if [ $SAVETEMPS -eq 0 ]; then
449 printf "Cleaning up... "
450 rm -rf ${GMP_DIR} build-gmp
451 rm -rf ${MPFR_DIR} build-mpfr
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000452 rm -rf ${MPC_DIR} build-mpc
453 rm -rf ${LIBELF_DIR} build-libelf
Stefan Reinauer074d9132009-09-26 16:43:17 +0000454 rm -rf ${BINUTILS_DIR} build-binutils
455 rm -rf ${GCC_DIR} build-gcc
456 rm -rf ${GDB_DIR} build-gdb
457 printf "${green}ok${NC}\n"
458else
459 printf "Leaving temporary files around... ${green}ok${NC}\n"
460fi
461
462printf "\n${green}You can now run your $TARGETARCH cross toolchain from $TARGETDIR.${NC}\n"
463
464