blob: e0ef98148c706ae2666c9e05652d2893f7da5c5e [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#
Stefan Reinauer074d9132009-09-26 16:43:17 +000018
Stefan Reinauerd7649122015-06-09 11:44:25 -070019cd $(dirname $0)
Patrick Georgi8135dba2015-03-17 21:05:20 +010020
Stefan Reinauerea1a5fe2016-01-29 17:33:56 -080021CROSSGCC_DATE="January 29th, 2016"
22CROSSGCC_VERSION="1.35"
Stefan Reinauer074d9132009-09-26 16:43:17 +000023
24# default settings
Stefan Reinauer85b07d62015-06-09 14:45:14 -070025PACKAGE=GCC
Stefan Reinauerd7649122015-06-09 11:44:25 -070026TARGETDIR=$(pwd)/xgcc
Stefan Reinauer074d9132009-09-26 16:43:17 +000027TARGETARCH=i386-elf
Nico Huber32c4a062016-01-25 18:30:57 +010028LANGUAGES=c
Stefan Reinauer074d9132009-09-26 16:43:17 +000029DESTDIR=
Stefan Reinauer85b07d62015-06-09 14:45:14 -070030SAVETEMPS=0
31SKIPPYTHON=1
Stefan Reinauer074d9132009-09-26 16:43:17 +000032
Stefan Reinauer699ac272015-06-05 12:43:28 -070033# GCC toolchain version numbers
Timothy Pearson96310162015-12-28 22:53:29 -060034GMP_VERSION=6.1.0
Timothy Pearson74432e12016-01-05 10:41:36 -060035MPFR_VERSION=3.1.3
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 Georgiaf473ed2015-07-17 23:35:54 +020038GCC_VERSION=5.2.0
Stefan Reinauer0d2119d2013-07-10 14:27:56 -070039GCC_AUTOCONF_VERSION=2.69
Patrick Georgi53c388f2015-03-07 09:55:18 +010040BINUTILS_VERSION=2.25
Stefan Reinauerbed95b22015-06-09 13:41:40 -070041GDB_VERSION=7.9.1
Stefan Reinaueradf61e22015-07-07 00:41:42 +020042IASL_VERSION=20150619
Patrick Georgi53c388f2015-03-07 09:55:18 +010043PYTHON_VERSION=3.4.3
Idwer Vollering296a0152012-10-26 01:48:04 +020044EXPAT_VERSION=2.1.0
Stefan Reinauer14ce2132015-06-05 13:01:13 -070045# CLANG version number
Stefan Reinauerea1a5fe2016-01-29 17:33:56 -080046CLANG_VERSION=3.7.1
Stefan Reinauera851bbb2016-01-29 18:03:26 -080047MAKE_VERSION=4.1
Stefan Reinauer074d9132009-09-26 16:43:17 +000048
Stefan Reinauer699ac272015-06-05 12:43:28 -070049# GCC toolchain archive locations
Timothy Pearson96310162015-12-28 22:53:29 -060050GMP_ARCHIVE="http://ftpmirror.gnu.org/gmp/gmp-${GMP_VERSION}.tar.bz2"
Patrick Georgi6e61ad32012-05-12 23:19:30 +020051MPFR_ARCHIVE="http://ftpmirror.gnu.org/mpfr/mpfr-${MPFR_VERSION}.tar.bz2"
Idwer Vollering7962fc72012-10-25 02:14:09 +020052MPC_ARCHIVE="http://ftpmirror.gnu.org/mpc/mpc-${MPC_VERSION}.tar.gz"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000053LIBELF_ARCHIVE="http://www.mr511.de/software/libelf-${LIBELF_VERSION}.tar.gz"
Idwer Vollering1cfee0b2012-10-25 02:03:53 +020054GCC_ARCHIVE="http://ftpmirror.gnu.org/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.bz2"
Stefan Reinauer0d2119d2013-07-10 14:27:56 -070055BINUTILS_ARCHIVE="http://ftpmirror.gnu.org/binutils/binutils-${BINUTILS_VERSION}.tar.bz2"
Patrick Georgi53c388f2015-03-07 09:55:18 +010056GDB_ARCHIVE="http://ftpmirror.gnu.org/gdb/gdb-${GDB_VERSION}.tar.xz"
Patrick Georgi85bb9462016-02-11 17:22:16 +010057IASL_ARCHIVE="https://acpica.org/sites/acpica/files/acpica-unix2-${IASL_VERSION}.tar.gz"
Patrick Georgi53c388f2015-03-07 09:55:18 +010058PYTHON_ARCHIVE="http://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010059EXPAT_ARCHIVE="http://downloads.sourceforge.net/sourceforge/expat/expat-${EXPAT_VERSION}.tar.gz"
Stefan Reinauer14ce2132015-06-05 13:01:13 -070060# CLANG toolchain archive locations
61LLVM_ARCHIVE="http://llvm.org/releases/${CLANG_VERSION}/llvm-${CLANG_VERSION}.src.tar.xz"
62CFE_ARCHIVE="http://llvm.org/releases/${CLANG_VERSION}/cfe-${CLANG_VERSION}.src.tar.xz"
63CRT_ARCHIVE="http://llvm.org/releases/${CLANG_VERSION}/compiler-rt-${CLANG_VERSION}.src.tar.xz"
64CTE_ARCHIVE="http://llvm.org/releases/${CLANG_VERSION}/clang-tools-extra-${CLANG_VERSION}.src.tar.xz"
Stefan Reinauera851bbb2016-01-29 18:03:26 -080065MAKE_ARCHIVE="http://ftpmirror.gnu.org/make/make-${MAKE_VERSION}.tar.bz2"
Stefan Reinauer074d9132009-09-26 16:43:17 +000066
Stefan Reinauer699ac272015-06-05 12:43:28 -070067# GCC toolchain directories
Stefan Reinauer074d9132009-09-26 16:43:17 +000068GMP_DIR="gmp-${GMP_VERSION}"
69MPFR_DIR="mpfr-${MPFR_VERSION}"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000070MPC_DIR="mpc-${MPC_VERSION}"
71LIBELF_DIR="libelf-${LIBELF_VERSION}"
Stefan Reinauer074d9132009-09-26 16:43:17 +000072GCC_DIR="gcc-${GCC_VERSION}"
73BINUTILS_DIR="binutils-${BINUTILS_VERSION}"
74GDB_DIR="gdb-${GDB_VERSION}"
Patrick Georgi85bb9462016-02-11 17:22:16 +010075IASL_DIR="acpica-unix2-${IASL_VERSION}"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010076PYTHON_DIR="Python-${PYTHON_VERSION}"
77EXPAT_DIR="expat-${EXPAT_VERSION}"
Stefan Reinauer14ce2132015-06-05 13:01:13 -070078# CLANG toolchain directories
79LLVM_DIR="llvm-${CLANG_VERSION}.src"
80CFE_DIR="cfe-${CLANG_VERSION}.src"
81CRT_DIR="compiler-rt-${CLANG_VERSION}.src"
82CTE_DIR="clang-tools-extra-${CLANG_VERSION}.src"
Stefan Reinauera851bbb2016-01-29 18:03:26 -080083MAKE_DIR="make-${MAKE_VERSION}"
Stefan Reinauer074d9132009-09-26 16:43:17 +000084
Patrick Georgi6321f522015-02-27 23:36:26 +010085unset MAKELEVEL MAKEFLAGS
86
Patrick Georgi1861ff72011-10-31 12:15:55 +010087red='\033[0;31m'
88RED='\033[1;31m'
89green='\033[0;32m'
90GREEN='\033[1;32m'
91blue='\033[0;34m'
92BLUE='\033[1;34m'
93cyan='\033[0;36m'
94CYAN='\033[1;36m'
95NC='\033[0m' # No Color
Stefan Reinauer074d9132009-09-26 16:43:17 +000096
zbaoe05c1ea2015-08-05 23:10:05 -040097UNAME=$(uname | grep -iq cygwin && echo Cygwin || uname)
Martin Roth88463822016-01-07 11:03:36 -070098HALT_FOR_TOOLS=0
Stefan Reinauer0d2119d2013-07-10 14:27:56 -070099
Patrick Georgi198d23c2012-12-08 08:02:44 +0100100normalize_dirs()
101{
102 mkdir -p $DESTDIR$TARGETDIR/lib
103 test -d $DESTDIR$TARGETDIR/lib32 && mv $DESTDIR$TARGETDIR/lib32/* $DESTDIR$TARGETDIR/lib
104 test -d $DESTDIR$TARGETDIR/lib64 && mv $DESTDIR$TARGETDIR/lib64/* $DESTDIR$TARGETDIR/lib
105 rmdir -p $DESTDIR$TARGETDIR/lib32 $DESTDIR$TARGETDIR/lib64
106
107 perl -pi -e "s,/lib32,/lib," $DESTDIR$TARGETDIR/lib/*.la
108 perl -pi -e "s,/lib64,/lib," $DESTDIR$TARGETDIR/lib/*.la
109}
110
Stefan Reinauer93a96302015-06-15 12:36:53 -0700111please_install()
112{
Martin Roth88463822016-01-07 11:03:36 -0700113 HALT_FOR_TOOLS=1
Patrick Georgi5da95dc2015-07-17 23:33:05 +0200114 test -r /etc/os-release && . /etc/os-release
Stefan Reinauer93a96302015-06-15 12:36:53 -0700115 case "$ID_LIKE" in
116 debian) solution="sudo apt-get install $1" ;;
117 suse) solution="sudo zypper install $1" ;;
118 *) solution="using your OS packaging system" ;;
119 esac
120
121 printf "${RED}ERROR:${red} Missing tool: Please install \'$1\' utility. (eg $solution)${NC}\n" >&2
Martin Rothe3963172016-01-06 13:54:32 -0700122 if [ -n "$2" ]; then
123 printf "${RED}ERROR:${red} or install \'$2\' utility. (eg $solution)${NC}\n" >&2
124 fi
Stefan Reinauer93a96302015-06-15 12:36:53 -0700125}
126
Patrick Georgib7062882015-02-24 10:52:14 +0100127searchtool()
Stefan Reinauer074d9132009-09-26 16:43:17 +0000128{
129 # $1 short name
Patrick Georgib7062882015-02-24 10:52:14 +0100130 # $2 search string
131 # $3 soft fail if set
Martin Rothe3963172016-01-06 13:54:32 -0700132 # $4 alternative package to install on failure
Patrick Georgib7062882015-02-24 10:52:14 +0100133 # result: file name of that tool on stdout
134 # or no output if nothing suitable was found
135 search=GNU
136 if [ -n "$2" ]; then
137 search="$2"
138 fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000139 for i in "$1" "g$1" "gnu$1"; do
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700140 if [ -x "$(which $i 2>/dev/null)" ]; then
141 if [ "$(cat /dev/null | $i --version 2>&1 | grep -c "$search")" \
142 -gt 0 ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000143 echo $i
144 return
145 fi
146 fi
147 done
Andrew Wub67e9a12014-04-28 18:13:44 +0800148 # A workaround for OSX 10.9 and some BSDs, whose nongnu
149 # patch and tar also work.
Patrick Georgi7cb26b42015-04-28 21:29:22 +0200150 if [ $UNAME = "Darwin" -o $UNAME = "FreeBSD" -o $UNAME = "NetBSD" -o $UNAME = "OpenBSD" ]; then
Patrick Georgib7062882015-02-24 10:52:14 +0100151 if [ "$1" = "patch" -o "$1" = "tar" ]; then
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700152 if [ -x "$(which $1 2>/dev/null)" ]; then
Zheng Bao36156ff2012-09-28 16:18:58 +0800153 echo $1
154 return
155 fi
156 fi
157 fi
Stefan Reinauerd7649122015-06-09 11:44:25 -0700158 if [ "$(echo $1 | cut -b -3)" = "sha" ]; then
zbao939dc842015-04-30 04:44:07 +0800159 if [ $UNAME = "FreeBSD" ]; then
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700160 if [ -x "$(which sha1 2>/dev/null)" ]; then
zbao939dc842015-04-30 04:44:07 +0800161 echo sha1
162 return
163 fi
164 fi
165 if [ $UNAME = "NetBSD" ]; then
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700166 if [ -x "$(which cksum 2>/dev/null)" ]; then
Stefan Reinauerd7649122015-06-09 11:44:25 -0700167 echo cksum -a $(echo $1 | sed -e 's,sum,,')
zbao939dc842015-04-30 04:44:07 +0800168 return
169 fi
170 fi
171 if [ $UNAME = "Darwin" ]; then
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700172 if [ -x "$(which openssl 2>/dev/null)" ]; then
Stefan Reinauerd7649122015-06-09 11:44:25 -0700173 echo openssl $(echo $1 | sed -e 's,sum,,')
zbao939dc842015-04-30 04:44:07 +0800174 return
175 fi
176 fi
177 fi
Martin Rothe3963172016-01-06 13:54:32 -0700178
Martin Roth88463822016-01-07 11:03:36 -0700179 [ -z "$3" ] && please_install $1 $4
Patrick Georgib7062882015-02-24 10:52:14 +0100180 false
Stefan Reinauer074d9132009-09-26 16:43:17 +0000181}
182
zbao06e85ac2015-08-24 22:08:36 -0400183check_sum() {
184 test -z "$CHECKSUM" || \
185 test "$(cat sum/$1.cksum 2>/dev/null | sed -e 's@.*\([0-9a-f]\{40,\}\).*@\1@')" = \
186 "$($CHECKSUM tarballs/$1 2>/dev/null | sed -e 's@.*\([0-9a-f]\{40,\}\).*@\1@')"
187}
188
189compute_sum() {
190 test ! -f sum/$1.cksum && test -f tarballs/$1 && \
191 (test -z "$CHECKSUM" || $CHECKSUM tarballs/$1 > sum/$1.cksum ) && \
192 printf "(checksum created. ${RED}Note. Please upload sum/$1.cksum if the corresponding archive is upgraded.)${NC}"
193}
194
zbao282dd952015-09-06 05:00:04 -0400195download_showing_percentage() {
196 url=$1
197 printf " ..${red} 0%%"
198 wget --no-check-certificate $url 2>&1 | while read line; do
199 printf "${red}"
200 echo $line | grep -o "[0-9]\+%" | awk '{printf("\b\b\b\b%4s", $1)}'
201 printf "${NC}"
202 done
203}
204
Stefan Reinauer88935482015-06-05 09:51:10 -0700205download() {
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700206 package=$1
207 archive="$(eval echo \$$package"_ARCHIVE")"
Stefan Reinauer699ac272015-06-05 12:43:28 -0700208
Stefan Reinauerd7649122015-06-09 11:44:25 -0700209 FILE=$(basename $archive)
Stefan Reinauer88935482015-06-05 09:51:10 -0700210 printf " * $FILE "
211
zbaod22b9ea2015-08-30 23:35:16 -0400212 if test -f tarballs/$FILE && check_sum $FILE ; then
213 printf "(cached)"
214 else
Paul Menzelb2ba3952015-06-12 11:58:14 +0200215 printf "(downloading from $archive)"
Stefan Reinauer88935482015-06-05 09:51:10 -0700216 rm -f tarballs/$FILE
217 cd tarballs
zbao282dd952015-09-06 05:00:04 -0400218 download_showing_percentage $archive
Stefan Reinauer88935482015-06-05 09:51:10 -0700219 cd ..
zbao06e85ac2015-08-24 22:08:36 -0400220 compute_sum $FILE
zbaod22b9ea2015-08-30 23:35:16 -0400221 fi
222
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700223 if [ ! -f tarballs/$FILE ]; then
zbao282dd952015-09-06 05:00:04 -0400224 printf "\n${RED}Failed to download $FILE.${NC}\n"
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700225 exit 1
226 fi
Stefan Reinauer88935482015-06-05 09:51:10 -0700227 printf "\n"
228}
229
230unpack_and_patch() {
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700231 package=$1
232 archive="$(eval echo \$$package"_ARCHIVE")"
233 dir="$(eval echo \$$package"_DIR")"
Stefan Reinauer88935482015-06-05 09:51:10 -0700234 test -d ${dir} && test -f ${dir}/.unpack_success || (
Stefan Reinauerd7649122015-06-09 11:44:25 -0700235 printf " * $(basename $archive)\n"
Stefan Reinauer88935482015-06-05 09:51:10 -0700236 FLAGS=zxf
Stefan Reinauerd7649122015-06-09 11:44:25 -0700237 suffix=$(echo $archive | sed 's,.*\.,,')
Stefan Reinauer88935482015-06-05 09:51:10 -0700238 test "$suffix" = "gz" && FLAGS=zxf
239 test "$suffix" = "bz2" && FLAGS=jxf
240 test "$suffix" = "xz" && FLAGS="--xz -xf"
241 test "$suffix" = "lzma" && FLAGS="--lzma -xf"
Stefan Reinauerd7649122015-06-09 11:44:25 -0700242 $TAR $FLAGS tarballs/$(basename $archive)
Stefan Reinauer88935482015-06-05 09:51:10 -0700243 for patch in patches/${dir}_*.patch; do
244 test -r $patch || continue
Stefan Reinauerd7649122015-06-09 11:44:25 -0700245 printf " o $(basename $patch)\n"
Stefan Reinauer916b8452015-06-09 11:54:49 -0700246 $PATCH -s -N -p0 < $(echo $patch) || {
Stefan Reinauer88935482015-06-05 09:51:10 -0700247 printf "\n${RED}Failed $patch.${NC}\n"
Stefan Reinauer916b8452015-06-09 11:54:49 -0700248 exit 1
249 }
Stefan Reinauer88935482015-06-05 09:51:10 -0700250 done
251 touch ${dir}/.unpack_success
252 )
253}
254
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700255fn_exists()
256{
Patrick Georgic8665912015-06-11 21:04:31 +0200257 type $1 >/dev/null 2>&1
Patrick Georgi74c06422015-03-25 18:40:13 +0100258}
259
Patrick Georgif2c15f52015-06-11 21:07:31 +0200260is_package_enabled()
261{
262 echo "$PACKAGES" |grep -q "\<$1\>"
263}
264
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700265build() {
266 package=$1
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700267
268 fn_exists build_$package || return
269
Stefan Reinauer05bbc9202015-06-09 12:21:42 -0700270 version="$(eval echo \$$package"_VERSION")"
271 BUILDDIR=build-${TARGETARCH}-$package
272
273 mkdir -p ${BUILDDIR}
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700274
Patrick Georgif2c15f52015-06-11 21:07:31 +0200275 is_package_enabled "$package" && \
Stefan Reinauer05bbc9202015-06-09 12:21:42 -0700276 if [ -f ${BUILDDIR}/.success ]; then
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700277 printf "Skipping $package as it is already built\n"
278 else
279 printf "Building $package $version ... "
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700280 DIR=$PWD
Stefan Reinauer05bbc9202015-06-09 12:21:42 -0700281 cd ${BUILDDIR}
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700282 rm -f .failed
283 build_${package} > build.log 2>&1
Stefan Reinauer05bbc9202015-06-09 12:21:42 -0700284 cd $DIR/${BUILDDIR}
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700285 if [ ! -f .failed ]; then touch .success; fi
286 cd ..
287
Stefan Reinauer05bbc9202015-06-09 12:21:42 -0700288 if [ -r "${BUILDDIR}/.failed" ]; then
289 printf "${RED}failed${NC}. Check ${BUILDDIR}/build.log.\n"
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700290 exit 1
291 fi
292 printf "${green}ok${NC}\n"
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700293 fi
294}
295
Stefan Reinauer074d9132009-09-26 16:43:17 +0000296cleanup()
297{
298 printf "Cleaning up temporary files... "
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700299 for package in $PACKAGES; do
Stefan Reinauer05bbc9202015-06-09 12:21:42 -0700300 rm -rf build-${TARGETARCH}-$package $(eval echo \$$package"_DIR")
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700301 done
zbaoff3f15c2015-08-26 22:00:31 -0400302 rm -f getopt
Stefan Reinauer074d9132009-09-26 16:43:17 +0000303 printf "${green}ok${NC}\n"
304}
305
306myhelp()
307{
Stefan Reinauer14ce2132015-06-05 13:01:13 -0700308 printf "Usage: $0 [-V] [-c] [-p <platform>] [-d <target directory>] [-D <dest dir>] [-C] [-G] [-S]\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000309 printf " $0 [-V|--version]\n"
310 printf " $0 [-h|--help]\n\n"
311
312 printf "Options:\n"
313 printf " [-V|--version] print version number and exit\n"
314 printf " [-h|--help] print this help and exit\n"
315 printf " [-c|--clean] remove temporary files before build\n"
316 printf " [-t|--savetemps] don't remove temporary files after build\n"
Patrick Georgic1a75b12011-11-04 21:37:14 +0100317 printf " [-y|--ccache] Use ccache when building cross compiler\n"
Martin Roth4a53db02016-03-01 15:21:07 -0700318 printf " [--nocolor] don't print color codes in output\n"
Patrick Georgi73166c72010-04-14 20:42:42 +0000319 printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n"
Martin Rothedf965a2015-11-25 16:58:33 -0700320 printf " [-s]--supported <tool> print supported version of a tool"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000321 printf " [-d|--directory <target dir>] target directory to install cross compiler to\n"
322 printf " (defaults to $TARGETDIR)\n\n"
323 printf " [-D|--destdir <dest dir>] destination directory to install cross compiler to\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100324 printf " (for RPM builds, default unset)\n"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700325 printf " [-P|--package <package>] Build a specific package: GCC, CLANG, IASL, GDB\n"
326 printf " (defaults to $PACKAGE)\n"
327 printf "GCC specific options:\n"
328 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
329 printf " (defaults to $TARGETARCH)\n"
Nico Huberbb313bf2015-09-08 12:30:27 +0200330 printf " [-l|--languages <languages>] comma separated list of target languages\n"
331 printf " (defaults to $LANGUAGES)\n"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700332 printf "GDB specific options:\n"
333 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
334 printf " (defaults to $TARGETARCH)\n"
335 printf " [-S|--scripting] build scripting support for GDB\n\n"
Martin Rothd1da74f2015-06-21 12:06:28 -0600336 printf "Platforms for GCC & GDB:\n"
337 printf " x86_64 i386-elf i386-mingw32 mipsel-elf riscv-elf arm aarch64\n\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000338}
339
Martin Rothedf965a2015-11-25 16:58:33 -0700340printversion() {
341 printf "${blue}Welcome to the ${red}coreboot${blue} cross toolchain builder v$CROSSGCC_VERSION ($CROSSGCC_DATE)${NC}\n\n"
342}
343
Stefan Reinauer074d9132009-09-26 16:43:17 +0000344myversion()
345{
Martin Rothedf965a2015-11-25 16:58:33 -0700346 printversion
Stefan Reinauer074d9132009-09-26 16:43:17 +0000347
348 cat << EOF
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000349Copyright (C) 2008-2010 by coresystems GmbH
Marc Jones2aac3f62011-08-08 16:07:50 -0600350Copyright (C) 2011 by Sage Electronic Engineering
Stefan Reinauer074d9132009-09-26 16:43:17 +0000351
352This program is free software; you can redistribute it and/or modify
353it under the terms of the GNU General Public License as published by
354the Free Software Foundation; version 2 of the License.
355
356This program is distributed in the hope that it will be useful,
357but WITHOUT ANY WARRANTY; without even the implied warranty of
358MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
359GNU General Public License for more details.
360
361EOF
362}
363
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700364build_GMP() {
365 CC="$CC" CFLAGS="-Os" ../${GMP_DIR}/configure --disable-shared --enable-fat --prefix=$TARGETDIR $OPTIONS \
366 || touch .failed
367 $MAKE $JOBS || touch .failed
368 $MAKE install DESTDIR=$DESTDIR || touch .failed
369
370 normalize_dirs
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700371
372 # Now set CFLAGS to match GMP CFLAGS but strip out -pedantic
373 # as GCC 4.6.x fails if it's there.
374 export HOSTCFLAGS=$(grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2 |\
375 sed s,-pedantic,,)
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700376}
377
378build_MPFR() {
379 test $UNAME = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
380 CC="$CC" ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
381 --infodir=$TARGETDIR/info \
382 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
383 touch .failed
384 $MAKE $JOBS || touch .failed
385 $MAKE install DESTDIR=$DESTDIR || touch .failed
386
387 normalize_dirs
388
389 # work around build problem of libgmp.la
390 if [ "$DESTDIR" != "" ]; then
391 perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la
392 fi
393}
394
395build_MPC() {
396 CC="$CC" ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \
397 --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \
398 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
399 touch .failed
400 $MAKE $JOBS || touch .failed
401 $MAKE install DESTDIR=$DESTDIR || touch .failed
402
403 normalize_dirs
404}
405
406build_LIBELF() {
407 CC="$CC" CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no \
408 ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \
409 --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed
410 $MAKE $JOBS || touch .failed
411 $MAKE install prefix=$DESTDIR$TARGETDIR || touch .failed
412
413 normalize_dirs
414}
415
416build_BINUTILS() {
Stefan Reinauer682a90c2015-06-09 14:59:58 -0700417 if [ $TARGETARCH == "x86_64-elf" ]; then
418 ADDITIONALTARGET=",i386-elf"
419 fi
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700420 CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \
Stefan Reinauer682a90c2015-06-09 14:59:58 -0700421 --target=${TARGETARCH} --enable-targets=${TARGETARCH}${ADDITIONALTARGET} \
422 --disable-werror --disable-nls --enable-lto --enable-gold \
423 --enable-plugins --enable-multilibs CFLAGS="$HOSTCFLAGS" || touch .failed
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700424 $MAKE $JOBS || touch .failed
425 $MAKE install DESTDIR=$DESTDIR || touch .failed
426}
427
428
429build_GCC() {
Stefan Reinauerd0f83722015-06-09 11:52:28 -0700430 # GCC does not honor HOSTCFLAGS at all. CFLAGS are used for
431 # both target and host object files.
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700432 # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
433 # but it does not seem to work properly. At least the host library
434 # libiberty is not compiled with CFLAGS_FOR_BUILD.
Patrick Georgi0a97d7e2016-01-25 09:51:22 +0100435 CC="$CC" CFLAGS_FOR_TARGET="-O2 -Dinhibit_libc" CFLAGS="$HOSTCFLAGS" \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700436 CFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \
437 --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \
438 --target=${TARGETARCH} --disable-werror --disable-shared \
Stefan Reinauer2f97ebc2015-06-09 12:24:54 -0700439 --enable-lto --enable-plugins --enable-gold --enable-ld=default \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700440 --disable-libssp --disable-bootstrap --disable-nls \
441 --disable-libquadmath --without-headers \
Patrick Georgi0a97d7e2016-01-25 09:51:22 +0100442 --disable-threads \
Patrick Georgi8e68aff2016-02-08 11:48:26 +0100443 --enable-interwork --enable-multilib \
Patrick Georgi0a97d7e2016-01-25 09:51:22 +0100444 --disable-libatomic --disable-libcc1 --disable-decimal-float \
Nico Huberbb313bf2015-09-08 12:30:27 +0200445 ${GCC_OPTIONS} --enable-languages="${LANGUAGES}" \
Ronald G. Minnich7ee16b72016-02-12 21:54:59 +0000446 --with-system-zlib \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700447 --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \
448 --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \
449 --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \
450 || touch .failed
451 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-gcc || touch .failed
452 $MAKE install-gcc DESTDIR=$DESTDIR || touch .failed
453
Stefan Reinauerd7649122015-06-09 11:44:25 -0700454 if [ "$(echo $TARGETARCH | grep -c -- -mingw32)" -eq 0 ]; then
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700455 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-target-libgcc || touch .failed
456 $MAKE install-target-libgcc DESTDIR=$DESTDIR || touch .failed
457 fi
458}
459
460build_EXPAT() {
461 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${EXPAT_DIR}/configure --disable-shared \
462 --prefix=$TARGETDIR --target=${TARGETARCH} || touch .failed
463 $MAKE || touch .failed
464 $MAKE install DESTDIR=$DESTDIR || touch .failed
465
466 normalize_dirs
467}
468
469build_PYTHON() {
470 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$TARGETDIR \
471 --target=${TARGETARCH} || touch .failed
472 $MAKE $JOBS || touch .failed
473 $MAKE install DESTDIR=$DESTDIR || touch .failed
474
475 normalize_dirs
476}
477
478build_GDB() {
479 export PYTHONHOME=$DESTDIR$TARGETDIR
480 if [ $(uname) != "FreeBSD" -a $(uname) != "NetBSD" ]; then
481 LIBDL="-ldl"
482 fi
483 LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \
484 -lpthread $LIBDL -lutil" \
485 CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \
Stefan Reinauer7b40e422015-06-09 11:56:32 -0700486 ../${GDB_DIR}/configure --prefix=$TARGETDIR \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700487 --target=${TARGETARCH} --disable-werror --disable-nls
488 $MAKE $JOBS || touch .failed
489 $MAKE install DESTDIR=$DESTDIR || touch .failed
490}
491
492build_IASL() {
493 RDIR=$PWD
494 cd ../$IASL_DIR/generate/unix
495 CFLAGS="$HOSTCFLAGS"
496 HOST="_LINUX"
497 test $UNAME = "Darwin" && HOST="_APPLE"
498 test $UNAME = "FreeBSD" && HOST="_FreeBSD"
499 test $UNAME = "Cygwin" && HOST="_CYGWIN"
Martin Roth6f656132015-12-08 11:14:10 -0700500 HOST="$HOST" OPT_CFLAGS="-O -D_FORTIFY_SOURCE=2 -D COREBOOT_TOOLCHAIN_VERSION='\"coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE\"' " CFLAGS="$CFLAGS" $MAKE CC="$CC" iasl || touch $RDIR/.failed
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700501 rm -f $DESTDIR$TARGETDIR/bin/iasl || touch $RDIR/.failed
502 cp bin/iasl $DESTDIR$TARGETDIR/bin || touch $RDIR/.failed
503}
504
505build_LLVM() {
506 cd ..
507 ln -sf $PWD/$CFE_DIR $LLVM_DIR/tools/clang
508 ln -sf $PWD/$CTE_DIR $LLVM_DIR/tools/clang/tools/extra
509 ln -sf $PWD/$CRT_DIR $LLVM_DIR/projects/compiler-rt
510 cd -
511
512 $CMAKE -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=$DESTDIR$TARGETDIR \
Martin Rothfb5647a2015-12-18 09:26:45 -0700513 -DCLANG_VENDOR="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE - " \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700514 -DCMAKE_BUILD_TYPE=Release ../$LLVM_DIR || touch .failed
515 $MAKE $JOBS || touch .failed
516 $MAKE install || touch .failed
517
518 cp -a ../$CFE_DIR/tools/scan-build/* $DESTDIR$TARGETDIR/bin
519 cp -a ../$CFE_DIR/tools/scan-view/* $DESTDIR$TARGETDIR/bin
Stefan Reinauere9e6e3d2015-07-07 00:20:42 +0200520
521 # create symlinks to work around broken --print-librt-file-name
522 # when used with -target.
523 cd $DESTDIR$TARGETDIR/lib/clang/${CLANG_VERSION}/lib
524 for i in */libclang_rt.builtins*.a; do
525 ln -s $i .
526 done
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700527}
528
Stefan Reinauera851bbb2016-01-29 18:03:26 -0800529build_MAKE() {
530 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${MAKE_DIR}/configure --prefix=$TARGETDIR \
531 --disable-nls || touch .failed
532 $MAKE $JOBS || touch .failed
533 $MAKE install DESTDIR=$DESTDIR || touch .failed
534
535 normalize_dirs
536}
537
Martin Rothedf965a2015-11-25 16:58:33 -0700538print_stable() {
539 case "$PRINTSTABLE" in
540 AUTOCONF|autoconf) printf "%s\n" "$GCC_AUTOCONF_VERSION";;
541 BINUTILS|binutils) printf "%s\n" "$BINUTILS_VERSION";;
542 CLANG|clang) printf "%s\n" "$CLANG_VERSION";;
543 EXPAT|expat) printf "%s\n" "$EXPAT_VERSION";;
544 GCC|gcc) printf "%s\n" "$GCC_VERSION";;
545 GDB|gdb) printf "%s\n" "$GDB_VERSION";;
546 GMP|gmp) printf "%s\n" "$GMP_VERSION";;
547 IASL|iasl) printf "%s\n" "$IASL_VERSION";;
548 LIBELF|libelf) printf "%s\n" "$LIBELF_VERSION";;
549 MPC|mpc) printf "%s\n" "$MPC_VERSION";;
550 MPFR|mpfr) printf "%s\n" "$MPFR_VERSION";;
551 PYTHON|python) printf "%s\n" "$PYTHON_VERSION";;
Stefan Reinauera851bbb2016-01-29 18:03:26 -0800552 MAKE|make) printf "%s\n" "$MAKE_VERSION";;
Martin Rothedf965a2015-11-25 16:58:33 -0700553 *) printf "Unknown tool %s\n" "$PRINTSTABLE";;
554 esac
555}
Stefan Reinauer074d9132009-09-26 16:43:17 +0000556
Patrick Georgi6bba29f2010-01-29 17:40:52 +0000557# Look if we have getopt. If not, build it.
558export PATH=$PATH:.
559getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c
560
Stefan Reinauer074d9132009-09-26 16:43:17 +0000561# parse parameters.. try to find out whether we're running GNU getopt
Stefan Reinauerd7649122015-06-09 11:44:25 -0700562getoptbrand="$(getopt -V | sed -e '1!d' -e 's,^\(......\).*,\1,')"
Peter Stuge09377b72011-08-21 06:24:55 +0200563if [ "${getoptbrand}" = "getopt" ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000564 # Detected GNU getopt that supports long options.
Martin Rothedf965a2015-11-25 16:58:33 -0700565 args=$(getopt -l version,help,clean,directory:,platform:,languages:,package:,jobs:,destdir:,savetemps,scripting,ccache,supported: Vhcd:p:l:P:j:D:tSys: -- "$@")
Stefan Reinauer074d9132009-09-26 16:43:17 +0000566 eval set "$args"
567else
568 # Detected non-GNU getopt
Martin Rothedf965a2015-11-25 16:58:33 -0700569 args=$(getopt Vhcd:p:l:P:j:D:tSys: $*)
Stefan Reinauer074d9132009-09-26 16:43:17 +0000570 set -- $args
571fi
572
573if [ $? != 0 ]; then
574 myhelp
575 exit 1
576fi
577
578while true ; do
579 case "$1" in
580 -V|--version) shift; myversion; exit 0;;
581 -h|--help) shift; myhelp; exit 0;;
Patrick Georgi44af57a2013-12-19 22:06:22 +0100582 -c|--clean) shift; clean=1;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000583 -t|--savetemps) shift; SAVETEMPS=1;;
584 -d|--directory) shift; TARGETDIR="$1"; shift;;
585 -p|--platform) shift; TARGETARCH="$1"; shift;;
Nico Huberbb313bf2015-09-08 12:30:27 +0200586 -l|--languages) shift; LANGUAGES="$1"; shift;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000587 -D|--destdir) shift; DESTDIR="$1"; shift;;
Patrick Georgi73166c72010-04-14 20:42:42 +0000588 -j|--jobs) shift; JOBS="-j $1"; shift;;
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700589 -P|--package) shift; PACKAGE="$1"; shift;;
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100590 -S|--scripting) shift; SKIPPYTHON=0;;
Patrick Georgic1a75b12011-11-04 21:37:14 +0100591 -y|--ccache) shift; USECCACHE=1;;
Martin Rothedf965a2015-11-25 16:58:33 -0700592 -s|--supported) shift; PRINTSTABLE="$1"; shift;;
Martin Roth4a53db02016-03-01 15:21:07 -0700593 --nocolor) shift; \
594 unset red RED green GREEN blue BLUE cyan CYAN NC;;
Patrick Georgid2e0dd52013-06-09 08:05:45 +0200595 --) shift; break;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000596 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
Patrick Georgid2e0dd52013-06-09 08:05:45 +0200597 *) break;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000598 esac
599done
600
Martin Rothedf965a2015-11-25 16:58:33 -0700601if [ -n "$PRINTSTABLE" ]; then
602 print_stable
603 exit 0
604fi
605
606#print toolchain builder version string as the header
607printversion
608
Ronald G. Minnichb460a662013-05-26 05:33:35 -0700609case "$TARGETARCH" in
Timothy Pearsona9f62352015-12-30 18:59:00 -0600610 x86_64-elf) ;;
611 x86_64*) TARGETARCH=x86_64-elf;;
612 i386-elf) ;;
613 i386-mingw32) ;;
614 mipsel-elf) ;;
615 riscv-elf) ;;
Patrick Georgi0a97d7e2016-01-25 09:51:22 +0100616 powerpc64*-linux*) ;;
Timothy Pearsona9f62352015-12-30 18:59:00 -0600617 i386*) TARGETARCH=i386-elf;;
Stefan Reinauer27522ad2016-01-29 17:31:34 -0800618 arm*) TARGETARCH=arm-eabi;;
Timothy Pearsona9f62352015-12-30 18:59:00 -0600619 aarch64*) TARGETARCH=aarch64-elf;;
620 *) printf "${red}WARNING: Unsupported architecture $TARGETARCH.${NC}\n\n"; ;;
Ronald G. Minnichb460a662013-05-26 05:33:35 -0700621esac
622
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700623# Figure out which packages to build
Stefan Reinauer699ac272015-06-05 12:43:28 -0700624
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700625case "$PACKAGE" in
626 GCC|gcc)
627 echo "Target architecture is now $TARGETARCH"
628 NAME="${TARGETARCH} cross GCC"
Stefan Reinauerbd8b2e32015-06-17 11:55:02 -0700629 PACKAGES="GMP MPFR MPC LIBELF BINUTILS GCC"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700630 ;;
631 GDB|gdb)
632 NAME="${TARGETARCH} cross GDB"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700633 if [ $SKIPPYTHON -eq 0 ]; then
Ronald G. Minnichfb944f42016-02-27 04:06:42 +0000634 PACKAGES="EXPAT PYTHON GDB"
635 else
636 PACKAGES="EXPAT GDB"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700637 fi
638 ;;
639 CLANG|clang)
640 NAME=clang
641 PACKAGES="LLVM CFE CRT CTE"
David Hendrickscd5cdd32015-06-15 17:03:22 -0700642 CMAKE=$(searchtool cmake "cmake") || exit $?
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700643 ;;
644 IASL|iasl)
645 NAME="IASL ACPI compiler"
646 PACKAGES=IASL
647 ;;
Stefan Reinauera851bbb2016-01-29 18:03:26 -0800648 MAKE|make)
649 NAME="GNU Make"
650 PACKAGES=MAKE
651 ;;
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700652 *)
Stefan Reinauera851bbb2016-01-29 18:03:26 -0800653 printf "${red}ERROR: Unsupported package $PACKAGE. (Supported packages are GCC, GDB, CLANG, IASL, MAKE)${NC}\n\n";
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700654 exit 1
655 ;;
656esac
Peter Stugeceacd772011-06-09 04:54:16 +0200657
Stefan Reinauer66e93352015-06-16 22:38:23 +0200658# Find all the required tools:
659
660TAR=$(searchtool tar) || exit $?
661PATCH=$(searchtool patch) || exit $?
662MAKE=$(searchtool make) || exit $?
663SHA1SUM=$(searchtool sha1sum)
664SHA512SUM=$(searchtool sha512sum)
665CHECKSUM=$SHA1SUM
666
667searchtool m4 > /dev/null
668searchtool bison > /dev/null
669searchtool flex flex > /dev/null
670searchtool g++ "Free Software Foundation" nofail > /dev/null || \
Marc Jones5ee69512015-06-17 15:38:17 -0600671searchtool clang "clang version" nofail > /dev/null || \
Martin Rothe3963172016-01-06 13:54:32 -0700672searchtool clang "LLVM" "" "g++" > /dev/null
Stefan Reinauer66e93352015-06-16 22:38:23 +0200673searchtool wget > /dev/null
674searchtool bzip2 "bzip2," > /dev/null
675
Martin Roth88463822016-01-07 11:03:36 -0700676if [ "$HALT_FOR_TOOLS" -ne 0 ]; then
677 exit 1
678fi
679
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700680# This initial cleanup is useful when updating the toolchain script.
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000681
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700682if [ "$clean" = "1" ]; then
683 cleanup
684fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000685
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700686# Set up host compiler and flags needed for various OSes
Stefan Reinauer074d9132009-09-26 16:43:17 +0000687
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700688CC=cc
Patrick Georgif2c15f52015-06-11 21:07:31 +0200689if is_package_enabled "GCC"; then
Stefan Reinauer0d2119d2013-07-10 14:27:56 -0700690if [ $UNAME = "Darwin" ]; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000691 #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix"
692
693 # generally the OS X compiler can create x64 binaries.
694 # Per default it generated i386 binaries in 10.5 and x64
695 # binaries in 10.6 (even if the kernel is 32bit)
696 # For some weird reason, 10.5 autodetects an ABI=64 though
697 # so we're setting the ABI explicitly here.
Stefan Reinauerd7649122015-06-09 11:44:25 -0700698 if [ $(sysctl -n hw.optional.x86_64 2>/dev/null) -eq 1 ] 2>/dev/null; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000699 OPTIONS="ABI=64"
700 else
701 OPTIONS="ABI=32"
702 fi
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700703
Stefan Reinauer4266b922012-12-05 16:18:32 -0800704 # In Xcode 4.5.2 the default compiler is clang.
705 # However, this compiler fails to compile gcc 4.7.x. As a
706 # workaround it's possible to compile gcc with llvm-gcc.
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700707 if $CC -v 2>&1 | grep -q LLVM; then
Stefan Reinauer4266b922012-12-05 16:18:32 -0800708 CC=llvm-gcc
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700709 fi
zbao11f1d312015-08-05 23:15:54 -0400710elif [ $UNAME = "Linux" -o $UNAME = "Cygwin" ]; then
Patrick Georgiddb8f802015-07-04 17:45:54 +0200711 # gmp is overeager with detecting 64bit CPUs even if they run
712 # a 32bit kernel and userland.
713 if [ "$(uname -m 2>/dev/null)" = "i686" ]; then
714 OPTIONS="ABI=32"
715 fi
Nico Huberde45c592016-01-20 23:22:33 +0100716elif [ $UNAME = "NetBSD" ]; then
717 # same for NetBSD but this one reports an i386
718 if [ "$(uname -m 2>/dev/null)" = "i386" ]; then
719 OPTIONS="ABI=32"
720 fi
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000721fi
Stefan Reinauer14ce2132015-06-05 13:01:13 -0700722fi # GCC
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000723
Patrick Georgic1a75b12011-11-04 21:37:14 +0100724if [ "$USECCACHE" = 1 ]; then
725 CC="ccache $CC"
726fi
727
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700728# Prepare target directory for building GCC
729# (dependencies must be in the PATH)
Stefan Reinauer16bd7892012-12-07 23:57:01 +0100730mkdir -p $DESTDIR$TARGETDIR/bin
731export PATH=$DESTDIR$TARGETDIR/bin:$PATH
732
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700733# Download, unpack, patch and build all packages
734
Martin Roth03625172016-02-17 14:44:14 -0700735printf "Downloading tarballs ... \n"
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700736mkdir -p tarballs
737for P in $PACKAGES; do
738 download $P
739done
Martin Roth03625172016-02-17 14:44:14 -0700740printf "Downloaded tarballs ... ${green}ok${NC}\n"
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700741
742printf "Unpacking and patching ... \n"
743for P in $PACKAGES; do
744 unpack_and_patch $P || exit 1
745done
746printf "Unpacked and patched ... ${green}ok${NC}\n"
747
748printf "Building packages ... \n"
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700749for package in $PACKAGES; do
750 build $package
751done
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700752printf "Packages built ... ${green}ok${NC}\n"
Stefan Reinauer14ce2132015-06-05 13:01:13 -0700753
Stefan Reinauer699ac272015-06-05 12:43:28 -0700754# Adding git information of current tree to target directory
755# for reproducibility
Stefan Reinauerd7649122015-06-09 11:44:25 -0700756PROGNAME=$(basename "$0")
Patrick Georgi5602f2c2015-03-28 15:48:47 +0100757rm -f "$DESTDIR$TARGETDIR/$PROGNAME".commit.*
Stefan Reinauerd7649122015-06-09 11:44:25 -0700758cp "$PROGNAME" $DESTDIR$TARGETDIR/"$PROGNAME.commit.$(git describe)"
Zheng Bao30b895f2013-02-06 18:04:40 +0800759
Stefan Reinauer074d9132009-09-26 16:43:17 +0000760if [ $SAVETEMPS -eq 0 ]; then
Stefan Reinauer699ac272015-06-05 12:43:28 -0700761 cleanup
Stefan Reinauer074d9132009-09-26 16:43:17 +0000762else
763 printf "Leaving temporary files around... ${green}ok${NC}\n"
764fi
765
Stefan Reinauer699ac272015-06-05 12:43:28 -0700766printf "\n${green}You can now run your $NAME toolchain from $TARGETDIR.${NC}\n"