blob: e58b23ed455ac804e9201279fad82391bd4053af [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#
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
20# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21#
22
Marc Jones2aac3f62011-08-08 16:07:50 -060023CROSSGCC_DATE="August 8th, 2011"
24CROSSGCC_VERSION="1.04"
Stefan Reinauer074d9132009-09-26 16:43:17 +000025
26# default settings
27TARGETDIR=`pwd`/xgcc
28TARGETARCH=i386-elf
29DESTDIR=
30
31# version numbers
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000032GMP_VERSION=5.0.1
Marc Jones36932662010-12-03 00:45:56 +000033MPFR_VERSION=3.0.0
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000034MPC_VERSION=0.8.2
35LIBELF_VERSION=0.8.13
Stefan Reinauer5411e712010-12-17 02:32:42 +000036GCC_VERSION=4.5.2
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000037BINUTILS_VERSION=2.20.1
Marc Jones36932662010-12-03 00:45:56 +000038GDB_VERSION=7.2
Patrick Georgice377652011-07-23 23:29:44 +020039W32API_VERSION=3.17-2
40W32API_VERSION_SHORT=3.17
Patrick Georgi73166c72010-04-14 20:42:42 +000041MINGWRT_VERSION=3.18
Marc Jones2aac3f62011-08-08 16:07:50 -060042IASL_VERSION=20110623
Stefan Reinauer074d9132009-09-26 16:43:17 +000043
44# archive locations
45GMP_ARCHIVE="ftp://ftp.gmplib.org/pub/gmp-${GMP_VERSION}/gmp-${GMP_VERSION}.tar.bz2"
Peter Stuge85e68702009-12-13 13:39:01 +000046MPFR_ARCHIVE="http://www.mpfr.org/mpfr-${MPFR_VERSION}/mpfr-${MPFR_VERSION}.tar.bz2"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000047MPC_ARCHIVE="http://www.multiprecision.org/mpc/download/mpc-${MPC_VERSION}.tar.gz"
48LIBELF_ARCHIVE="http://www.mr511.de/software/libelf-${LIBELF_VERSION}.tar.gz"
Stefan Reinauer5411e712010-12-17 02:32:42 +000049GCC_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 +000050BINUTILS_ARCHIVE="http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.bz2"
51GDB_ARCHIVE="http://ftp.gnu.org/gnu/gdb/gdb-${GDB_VERSION}.tar.bz2"
Patrick Georgice377652011-07-23 23:29:44 +020052W32API_ARCHIVE="http://downloads.sourceforge.net/project/mingw/MinGW/BaseSystem/RuntimeLibrary/Win32-API/w32api-${W32API_VERSION_SHORT}/w32api-${W32API_VERSION}-mingw32-src.tar.lzma"
Marc Jones36932662010-12-03 00:45:56 +000053MINGWRT_ARCHIVE="http://downloads.sourceforge.net/project/mingw/MinGW/BaseSystem/RuntimeLibrary/MinGW-RT/mingwrt-${MINGWRT_VERSION}/mingwrt-${MINGWRT_VERSION}-mingw32-src.tar.gz"
Marc Jones2aac3f62011-08-08 16:07:50 -060054IASL_ARCHIVE="http://www.acpica.org/download/acpica-unix-${IASL_VERSION}.tar.gz"
Stefan Reinauer074d9132009-09-26 16:43:17 +000055
56GMP_DIR="gmp-${GMP_VERSION}"
57MPFR_DIR="mpfr-${MPFR_VERSION}"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000058MPC_DIR="mpc-${MPC_VERSION}"
59LIBELF_DIR="libelf-${LIBELF_VERSION}"
Stefan Reinauer074d9132009-09-26 16:43:17 +000060GCC_DIR="gcc-${GCC_VERSION}"
61BINUTILS_DIR="binutils-${BINUTILS_VERSION}"
62GDB_DIR="gdb-${GDB_VERSION}"
Stefan Reinauer6ade1612010-01-16 16:44:20 +000063W32API_DIR="w32api-${W32API_VERSION}-mingw32"
64MINGWRT_DIR="mingwrt-${MINGWRT_VERSION}-mingw32"
Marc Jones2aac3f62011-08-08 16:07:50 -060065IASL_DIR="acpica-unix-${IASL_VERSION}"
Stefan Reinauer074d9132009-09-26 16:43:17 +000066
67SAVETEMPS=0
Peter Stugeceacd772011-06-09 04:54:16 +020068SKIPGDB=0
Stefan Reinauer074d9132009-09-26 16:43:17 +000069
70red='\e[0;31m'
71RED='\e[1;31m'
72green='\e[0;32m'
73GREEN='\e[1;32m'
74blue='\e[0;34m'
75BLUE='\e[1;34m'
76cyan='\e[0;36m'
77CYAN='\e[1;36m'
78NC='\e[0m' # No Color
79
80searchgnu()
81{
82 # $1 short name
83 # result: GNU version of that tool on stdout
84 # or no output if no GNU version was found
85 for i in "$1" "g$1" "gnu$1"; do
86 if test -x "`which $i 2>/dev/null`"; then
87 if test `$i --version 2>/dev/null |grep -c GNU` -gt 0; then
88 echo $i
89 return
90 fi
91 fi
92 done
93 printf "${RED}ERROR:${red} Missing toolchain: $1${NC}\n" >&2
94 exit 1
95}
96
Patrick Georgi68df8042011-07-17 11:36:10 +020097TAR=`searchgnu tar` || exit $?
98PATCH=`searchgnu patch` || exit $?
99MAKE=`searchgnu make` || exit $?
Stefan Reinauer074d9132009-09-26 16:43:17 +0000100
101cleanup()
102{
103 printf "Cleaning up temporary files... "
Marc Jones2aac3f62011-08-08 16:07:50 -0600104 rm -rf build-* combined gcc-* gmp-* mpfr-* mpc-* libelf-* binutils-* gdb-* w32api-* mingwrt-* acpica-*
Stefan Reinauer074d9132009-09-26 16:43:17 +0000105 printf "${green}ok${NC}\n"
106}
107
108myhelp()
109{
Peter Stugeceacd772011-06-09 04:54:16 +0200110 printf "Usage: $0 [-V] [-c] [-p <platform>] [-d <target directory>] [-D <dest dir>] [-G]\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000111 printf " $0 [-V|--version]\n"
112 printf " $0 [-h|--help]\n\n"
113
114 printf "Options:\n"
115 printf " [-V|--version] print version number and exit\n"
116 printf " [-h|--help] print this help and exit\n"
117 printf " [-c|--clean] remove temporary files before build\n"
118 printf " [-t|--savetemps] don't remove temporary files after build\n"
Patrick Georgi73166c72010-04-14 20:42:42 +0000119 printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000120 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
121 printf " (defaults to $TARGETARCH)\n"
122 printf " [-d|--directory <target dir>] target directory to install cross compiler to\n"
123 printf " (defaults to $TARGETDIR)\n\n"
124 printf " [-D|--destdir <dest dir>] destination directory to install cross compiler to\n"
125 printf " (for RPM builds, default unset)\n\n"
Peter Stugeceacd772011-06-09 04:54:16 +0200126 printf " [-G|--skip-gdb] don't build GNU debugger\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000127}
128
129myversion()
130{
131 # version tag is always printed, so just print the license here
132
133 cat << EOF
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000134Copyright (C) 2008-2010 by coresystems GmbH
Marc Jones2aac3f62011-08-08 16:07:50 -0600135Copyright (C) 2011 by Sage Electronic Engineering
Stefan Reinauer074d9132009-09-26 16:43:17 +0000136
137This program is free software; you can redistribute it and/or modify
138it under the terms of the GNU General Public License as published by
139the Free Software Foundation; version 2 of the License.
140
141This program is distributed in the hope that it will be useful,
142but WITHOUT ANY WARRANTY; without even the implied warranty of
143MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
144GNU General Public License for more details.
145
146EOF
147}
148
149printf "${blue}Welcome to the ${red}coresystems${blue} cross toolchain builder v$CROSSGCC_VERSION ($CROSSGCC_DATE)${NC}\n\n"
150
Patrick Georgi6bba29f2010-01-29 17:40:52 +0000151# Look if we have getopt. If not, build it.
152export PATH=$PATH:.
153getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c
154
Stefan Reinauer074d9132009-09-26 16:43:17 +0000155# parse parameters.. try to find out whether we're running GNU getopt
156getoptbrand="`getopt -V`"
157if [ "${getoptbrand:0:6}" == "getopt" ]; then
158 # Detected GNU getopt that supports long options.
Peter Stugeceacd772011-06-09 04:54:16 +0200159 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 +0000160 eval set "$args"
161else
162 # Detected non-GNU getopt
Peter Stugeceacd772011-06-09 04:54:16 +0200163 args=`getopt Vhcd:p:j:D:tG $*`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000164 set -- $args
165fi
166
167if [ $? != 0 ]; then
168 myhelp
169 exit 1
170fi
171
172while true ; do
173 case "$1" in
174 -V|--version) shift; myversion; exit 0;;
175 -h|--help) shift; myhelp; exit 0;;
176 -c|--clean) shift; cleanup;;
177 -t|--savetemps) shift; SAVETEMPS=1;;
178 -d|--directory) shift; TARGETDIR="$1"; shift;;
179 -p|--platform) shift; TARGETARCH="$1"; shift;;
180 -D|--destdir) shift; DESTDIR="$1"; shift;;
Patrick Georgi73166c72010-04-14 20:42:42 +0000181 -j|--jobs) shift; JOBS="-j $1"; shift;;
Peter Stugeceacd772011-06-09 04:54:16 +0200182 -G|--skip-gdb) shift; SKIPGDB=1;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000183 --) shift; break;;
184 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
185 *) break;;
186 esac
187done
188
Peter Stugeceacd772011-06-09 04:54:16 +0200189GDB_PACKAGE="GDB"
190if [ $SKIPGDB -eq 1 ]; then
191 printf "Will skip GDB ... ${green}ok${NC}\n"
192 GDB_PACKAGE=""
193fi
194
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000195MINGW_ARCHIVES=""
196if [ "$TARGETARCH" = "i386-mingw32" ]; then
197 MINGW_ARCHIVES="$W32API_ARCHIVE $MINGWRT_ARCHIVE"
198fi
199
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000200if [ ${GCC_VERSION} == "4.5.0" -o ${GCC_VERSION} == "4.6.0" ]; then
201 # coreboot does not like the GOLD linker
202 # USE_GOLD="--enable-gold"
203 USE_GOLD=""
204 GCC_OPTIONS="--enable-lto"
205fi
206
207if [ ${GCC_VERSION} == "4.6.0" ]; then
208 if [ ! -r tarballs/gcc-core-${GCC_VERSION}.tar.bz2 ]; then
209 printf "Pre-Release GCC ${GCC_VERSION}, checking out subversion trunk\n"
210 mkdir -p tarballs/.tmp
211 cd tarballs/.tmp
212 rm -rf gcc-${GCC_VERSION}
213 svn export -q svn://gcc.gnu.org/svn/gcc/trunk gcc-${GCC_VERSION}
214 printf "done. Now creating tar ball...\n"
215 tar cjf ../gcc-core-${GCC_VERSION}.tar.bz2 gcc-${GCC_VERSION}
216 printf "done. Now cleaning up...\n"
217 cd ..
218 rm -rf .tmp
219 cd ..
220 printf "done.\n"
221 fi
222fi
223
Stefan Reinauer074d9132009-09-26 16:43:17 +0000224printf "Downloading tar balls ... \n"
225mkdir -p tarballs
Marc Jones2aac3f62011-08-08 16:07:50 -0600226for ARCHIVE in $GMP_ARCHIVE $MPFR_ARCHIVE $MPC_ARCHIVE $LIBELF_ARCHIVE $GCC_ARCHIVE $BINUTILS_ARCHIVE $GDB_ARCHIVE $MINGW_ARCHIVES $IASL_ARCHIVE; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000227 FILE=`basename $ARCHIVE`
228 printf " * $FILE "
229 test -f tarballs/$FILE && printf "(cached)" || (
230 printf "(downloading)"
231 cd tarballs
232 wget -q $ARCHIVE
233 )
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000234 test -f tarballs/$FILE || printf "\n${RED}Failed to download $FILE.${red}\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000235 test -f tarballs/$FILE || exit 1
236 printf "\n"
237done
238printf "Downloaded tar balls ... "
239printf "${green}ok${NC}\n"
240
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000241MINGW_PACKAGES=""
242if [ "$TARGETARCH" = "i386-mingw32" ]; then
243 MINGW_PACKAGES="W32API MINGWRT"
244fi
245
Stefan Reinauer074d9132009-09-26 16:43:17 +0000246printf "Unpacking and patching ... \n"
Marc Jones2aac3f62011-08-08 16:07:50 -0600247for PACKAGE in GMP MPFR MPC LIBELF GCC BINUTILS $GDB_PACKAGE $MINGW_PACKAGES IASL; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000248 archive=$PACKAGE"_ARCHIVE"
249 archive=${!archive}
250 dir=$PACKAGE"_DIR"
Stefan Reinauer14e22772010-04-27 06:56:47 +0000251 test -d ${!dir} || (
Stefan Reinauer074d9132009-09-26 16:43:17 +0000252 printf " * `basename $archive`\n"
253 FLAGS=zxf
254 test ${archive:${#archive}-2:2} = "gz" && FLAGS=zxf
255 test ${archive:${#archive}-3:3} = "bz2" && FLAGS=jxf
Patrick Georgice377652011-07-23 23:29:44 +0200256 test ${archive:${#archive}-4:4} = "lzma" && FLAGS="--lzma -xf"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000257 $TAR $FLAGS tarballs/`basename $archive`
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000258 for patch in patches/${!dir}_*.patch; do
Stefan Reinauer074d9132009-09-26 16:43:17 +0000259 test -r $patch || continue
260 printf " o `basename $patch`\n"
Patrick Georgi6bba29f2010-01-29 17:40:52 +0000261 $PATCH -s -N -p0 < `echo $patch`
Stefan Reinauer074d9132009-09-26 16:43:17 +0000262 done
263 )
264done
265printf "Unpacked and patched ... "
266printf "${green}ok${NC}\n"
267
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000268if [ "$TARGETARCH" = "i386-mingw32" ]; then
269 mkdir -p $TARGETDIR/i386-mingw32/sys-include
270 mv $MINGWRT_DIR/include/* $W32API_DIR/include/* $TARGETDIR/i386-mingw32/sys-include
271fi
272
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000273if [ `uname` = "Darwin" ]; then
274 #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix"
275
276 # generally the OS X compiler can create x64 binaries.
277 # Per default it generated i386 binaries in 10.5 and x64
278 # binaries in 10.6 (even if the kernel is 32bit)
279 # For some weird reason, 10.5 autodetects an ABI=64 though
280 # so we're setting the ABI explicitly here.
281 if [ `sysctl -n hw.optional.x86_64` -eq 1 ]; then
282 OPTIONS="ABI=64"
283 else
284 OPTIONS="ABI=32"
285 fi
286 # old check:
287 #OPTIONS="ABI=32"
288 #touch .architecture_check.c
289 #gcc .architecture_check.c -c -o .architecture_check.o
290 #ARCH=`file .architecture_check.o |cut -f5 -d\ `
291 #test "$ARCH" = "x86_64" && OPTIONS="ABI=64"
292 #rm .architecture_check.c .architecture_check.o
293fi
294
Peter Stugeceacd772011-06-09 04:54:16 +0200295mkdir -p build-gmp build-mpfr build-mpc build-libelf build-binutils build-gcc
296if [ $SKIPGDB -eq 0 ]; then
297 mkdir -p build-gdb
298fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000299if [ -f build-gmp/.success ]; then
300 printf "Skipping GMP as it is already built\n"
301else
302printf "Building GMP ${GMP_VERSION} ... "
303(
304 cd build-gmp
305 rm -f .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000306 ../${GMP_DIR}/configure --disable-shared --prefix=$TARGETDIR $OPTIONS \
307 || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000308 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000309 $MAKE install DESTDIR=$DESTDIR || touch .failed
310 if [ ! -f .failed ]; then touch .success; fi
311) &> build-gmp/crossgcc-build.log
312test -r build-gmp/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
313test -r build-gmp/.failed && exit 1
314fi
315
316#if [ "$DESTDIR" != "" -a ! -x $TARGETDIR ]; then
317# # create compat link
318# ln -s $DESTDIR$TARGETDIR $TARGETDIR
319#fi
320
321# Now set CFLAGS to match GMP CFLAGS.
322HOSTCFLAGS=`grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2`
323
324if [ -f build-mpfr/.success ]; then
325 printf "Skipping MPFR as it is already built\n"
326else
327printf "Building MPFR ${MPFR_VERSION} ... "
328(
329 test `uname` = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
330 cd build-mpfr
331 rm -f .failed
332 ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
333 --infodir=$TARGETDIR/info \
334 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000335 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000336 $MAKE install DESTDIR=$DESTDIR || touch .failed
337
338 # work around build problem of libgmp.la
339 if [ "$DESTDIR" != "" ]; then
340 perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la
341 fi
342
343 if [ ! -f .failed ]; then touch .success; fi
344) &> build-mpfr/crossgcc-build.log
345test -r build-mpfr/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
346test -r build-mpfr/.failed && exit 1
347fi
348
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000349if [ -f build-mpc/.success ]; then
350 printf "Skipping MPC as it is already built\n"
351else
352printf "Building MPC ${MPC_VERSION} ... "
353(
354 #test `uname` = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
355 cd build-mpc
356 rm -f .failed
357 ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \
358 --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \
359 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || touch .failed
360 $MAKE $JOBS || touch .failed
361 $MAKE install DESTDIR=$DESTDIR || touch .failed
362
363 if [ ! -f .failed ]; then touch .success; fi
364) &> build-mpc/crossgcc-build.log
365test -r build-mpc/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
366test -r build-mpc/.failed && exit 1
367fi
368
369if [ -f build-libelf/.success ]; then
370 printf "Skipping libelf as it is already built\n"
371else
372printf "Building libelf ${LIBELF_VERSION} ... "
373(
374 cd build-libelf
375 rm -f .failed
376 echo "$HOSTCFLAGS"
Marc Jones36932662010-12-03 00:45:56 +0000377 CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000378 --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed
379 $MAKE $JOBS || touch .failed
380 $MAKE install DESTDIR=$DESTDIR || touch .failed
381
382 if [ ! -f .failed ]; then touch .success; fi
383) &> build-libelf/crossgcc-build.log
384test -r build-libelf/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
385test -r build-libelf/.failed && exit 1
386fi
387
Stefan Reinauer074d9132009-09-26 16:43:17 +0000388if [ -f build-binutils/.success ]; then
389 printf "Skipping binutils as it is already built\n"
390else
391printf "Building binutils ${BINUTILS_VERSION} ... "
392(
393 cd build-binutils
394 rm -f .failed
395 ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR --target=${TARGETARCH} \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000396 --disable-werror --disable-nls $USE_GOLD \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000397 CFLAGS="$HOSTCFLAGS" || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000398 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000399 $MAKE install DESTDIR=$DESTDIR || touch .failed
400 if [ ! -f .failed ]; then touch .success; fi
401) &> build-binutils/crossgcc-build.log
402test -r build-binutils/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
403test -r build-binutils/.failed && exit 1
404fi
405
406if [ -f build-gcc/.success ]; then
407 printf "Skipping GCC as it is already built\n"
408else
409printf "Building GCC ${GCC_VERSION} ... "
410(
411 cd build-gcc
Patrick Georgiba3b0eb2010-09-03 08:53:06 +0000412 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
Stefan Reinauer074d9132009-09-26 16:43:17 +0000413 rm -f .failed
414 # GCC does not honour HOSTCFLAGS at all. CFLAGS are used for
415 # both target and host object files. This is pretty misdesigned.
416 # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
417 # but it does not seem to work properly. At least the host library
418 # libiberty is not compiled with CFLAGS_FOR_BUILD.
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000419 CFLAGS_FOR_TARGET="-O2" CFLAGS="$HOSTCFLAGS" CFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000420 --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \
Stefan Reinauer6ade1612010-01-16 16:44:20 +0000421 --target=${TARGETARCH} --disable-werror --disable-shared \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000422 --disable-libssp --disable-bootstrap --disable-nls \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000423 $GCC_OPTIONS --enable-languages="c" $USE_GOLD \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000424 --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000425 --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \
426 --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \
Stefan Reinauer074d9132009-09-26 16:43:17 +0000427 || touch .failed
Patrick Georgi73166c72010-04-14 20:42:42 +0000428 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" || 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-gcc/crossgcc-build.log
432test -r build-gcc/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
433test -r build-gcc/.failed && exit 1
434fi
435
436if [ -f build-gdb/.success ]; then
437 printf "Skipping GDB as it is already built\n"
Peter Stugeceacd772011-06-09 04:54:16 +0200438elif [ $SKIPGDB -eq 1 ]; then
439 printf "Skipping GDB as requested by command line\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000440else
441printf "Building GDB ${GDB_VERSION} ... "
442(
443 cd build-gdb
Patrick Georgiba3b0eb2010-09-03 08:53:06 +0000444 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
Stefan Reinauer074d9132009-09-26 16:43:17 +0000445 rm -f .failed
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000446 CFLAGS="$HOSTCFLAGS" ../gdb-${GDB_VERSION}/configure --prefix=$TARGETDIR --target=${TARGETARCH} \
447 --without-python --disable-werror --disable-nls
Patrick Georgi73166c72010-04-14 20:42:42 +0000448 $MAKE $JOBS || touch .failed
Stefan Reinauer074d9132009-09-26 16:43:17 +0000449 $MAKE install DESTDIR=$DESTDIR || touch .failed
450 if [ ! -f .failed ]; then touch .success; fi
451) &> build-gdb/crossgcc-build.log
452test -r build-gdb/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
453test -r build-gdb/.failed && exit 1
454fi
455
Marc Jones2aac3f62011-08-08 16:07:50 -0600456if [ -f $IASL_DIR/compiler/.success ]; then
457 printf "Skipping IASL as it is already built\n"
458else
459printf "Building IASL ${IASL_VERSION} ... "
460(
461 cd $IASL_DIR/compiler
462 export PATH=$PATH:$DESTDIR$TARGETDIR/bin
463 rm -f .failed
464 CFLAGS="$HOSTCFLAGS"
465 $MAKE || touch .failed
Jonathan A. Kollaschf44bb4f2011-08-11 14:44:55 -0500466 rm -f $DESTDIR$TARGETDIR/bin/iasl || touch .failed
467 cp iasl $DESTDIR$TARGETDIR/bin || touch .failed
Marc Jones2aac3f62011-08-08 16:07:50 -0600468 if [ ! -f .failed ]; then touch .success; fi
469) &> $IASL_DIR/compiler/crossgcc-build.log
470test -r $IASL_DIR/compiler/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
471test -r $IASL_DIR/compiler.failed && exit 1
472fi
473
Stefan Reinauer074d9132009-09-26 16:43:17 +0000474if [ $SAVETEMPS -eq 0 ]; then
475 printf "Cleaning up... "
476 rm -rf ${GMP_DIR} build-gmp
477 rm -rf ${MPFR_DIR} build-mpfr
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000478 rm -rf ${MPC_DIR} build-mpc
479 rm -rf ${LIBELF_DIR} build-libelf
Stefan Reinauer074d9132009-09-26 16:43:17 +0000480 rm -rf ${BINUTILS_DIR} build-binutils
481 rm -rf ${GCC_DIR} build-gcc
482 rm -rf ${GDB_DIR} build-gdb
Marc Jones2aac3f62011-08-08 16:07:50 -0600483 rm -rf ${IASL_DIR}
Stefan Reinauer074d9132009-09-26 16:43:17 +0000484 printf "${green}ok${NC}\n"
485else
486 printf "Leaving temporary files around... ${green}ok${NC}\n"
487fi
488
489printf "\n${green}You can now run your $TARGETARCH cross toolchain from $TARGETDIR.${NC}\n"
490
491