blob: e4a6d473eef34a6eb6ac57a6d7479267c085eeeb [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"
Patrick Georgi73166c72010-04-14 20:42:42 +0000318 printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n"
Martin Rothedf965a2015-11-25 16:58:33 -0700319 printf " [-s]--supported <tool> print supported version of a tool"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000320 printf " [-d|--directory <target dir>] target directory to install cross compiler to\n"
321 printf " (defaults to $TARGETDIR)\n\n"
322 printf " [-D|--destdir <dest dir>] destination directory to install cross compiler to\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100323 printf " (for RPM builds, default unset)\n"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700324 printf " [-P|--package <package>] Build a specific package: GCC, CLANG, IASL, GDB\n"
325 printf " (defaults to $PACKAGE)\n"
326 printf "GCC specific options:\n"
327 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
328 printf " (defaults to $TARGETARCH)\n"
Nico Huberbb313bf2015-09-08 12:30:27 +0200329 printf " [-l|--languages <languages>] comma separated list of target languages\n"
330 printf " (defaults to $LANGUAGES)\n"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700331 printf "GDB specific options:\n"
332 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
333 printf " (defaults to $TARGETARCH)\n"
334 printf " [-S|--scripting] build scripting support for GDB\n\n"
Martin Rothd1da74f2015-06-21 12:06:28 -0600335 printf "Platforms for GCC & GDB:\n"
336 printf " x86_64 i386-elf i386-mingw32 mipsel-elf riscv-elf arm aarch64\n\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000337}
338
Martin Rothedf965a2015-11-25 16:58:33 -0700339printversion() {
340 printf "${blue}Welcome to the ${red}coreboot${blue} cross toolchain builder v$CROSSGCC_VERSION ($CROSSGCC_DATE)${NC}\n\n"
341}
342
Stefan Reinauer074d9132009-09-26 16:43:17 +0000343myversion()
344{
Martin Rothedf965a2015-11-25 16:58:33 -0700345 printversion
Stefan Reinauer074d9132009-09-26 16:43:17 +0000346
347 cat << EOF
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000348Copyright (C) 2008-2010 by coresystems GmbH
Marc Jones2aac3f62011-08-08 16:07:50 -0600349Copyright (C) 2011 by Sage Electronic Engineering
Stefan Reinauer074d9132009-09-26 16:43:17 +0000350
351This program is free software; you can redistribute it and/or modify
352it under the terms of the GNU General Public License as published by
353the Free Software Foundation; version 2 of the License.
354
355This program is distributed in the hope that it will be useful,
356but WITHOUT ANY WARRANTY; without even the implied warranty of
357MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
358GNU General Public License for more details.
359
360EOF
361}
362
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700363build_GMP() {
364 CC="$CC" CFLAGS="-Os" ../${GMP_DIR}/configure --disable-shared --enable-fat --prefix=$TARGETDIR $OPTIONS \
365 || touch .failed
366 $MAKE $JOBS || touch .failed
367 $MAKE install DESTDIR=$DESTDIR || touch .failed
368
369 normalize_dirs
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700370
371 # Now set CFLAGS to match GMP CFLAGS but strip out -pedantic
372 # as GCC 4.6.x fails if it's there.
373 export HOSTCFLAGS=$(grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2 |\
374 sed s,-pedantic,,)
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700375}
376
377build_MPFR() {
378 test $UNAME = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
379 CC="$CC" ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
380 --infodir=$TARGETDIR/info \
381 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
382 touch .failed
383 $MAKE $JOBS || touch .failed
384 $MAKE install DESTDIR=$DESTDIR || touch .failed
385
386 normalize_dirs
387
388 # work around build problem of libgmp.la
389 if [ "$DESTDIR" != "" ]; then
390 perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la
391 fi
392}
393
394build_MPC() {
395 CC="$CC" ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \
396 --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \
397 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
398 touch .failed
399 $MAKE $JOBS || touch .failed
400 $MAKE install DESTDIR=$DESTDIR || touch .failed
401
402 normalize_dirs
403}
404
405build_LIBELF() {
406 CC="$CC" CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no \
407 ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \
408 --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed
409 $MAKE $JOBS || touch .failed
410 $MAKE install prefix=$DESTDIR$TARGETDIR || touch .failed
411
412 normalize_dirs
413}
414
415build_BINUTILS() {
Stefan Reinauer682a90c2015-06-09 14:59:58 -0700416 if [ $TARGETARCH == "x86_64-elf" ]; then
417 ADDITIONALTARGET=",i386-elf"
418 fi
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700419 CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \
Stefan Reinauer682a90c2015-06-09 14:59:58 -0700420 --target=${TARGETARCH} --enable-targets=${TARGETARCH}${ADDITIONALTARGET} \
421 --disable-werror --disable-nls --enable-lto --enable-gold \
422 --enable-plugins --enable-multilibs CFLAGS="$HOSTCFLAGS" || touch .failed
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700423 $MAKE $JOBS || touch .failed
424 $MAKE install DESTDIR=$DESTDIR || touch .failed
425}
426
427
428build_GCC() {
Stefan Reinauerd0f83722015-06-09 11:52:28 -0700429 # GCC does not honor HOSTCFLAGS at all. CFLAGS are used for
430 # both target and host object files.
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700431 # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
432 # but it does not seem to work properly. At least the host library
433 # libiberty is not compiled with CFLAGS_FOR_BUILD.
Patrick Georgi0a97d7e2016-01-25 09:51:22 +0100434 CC="$CC" CFLAGS_FOR_TARGET="-O2 -Dinhibit_libc" CFLAGS="$HOSTCFLAGS" \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700435 CFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \
436 --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \
437 --target=${TARGETARCH} --disable-werror --disable-shared \
Stefan Reinauer2f97ebc2015-06-09 12:24:54 -0700438 --enable-lto --enable-plugins --enable-gold --enable-ld=default \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700439 --disable-libssp --disable-bootstrap --disable-nls \
440 --disable-libquadmath --without-headers \
Patrick Georgi0a97d7e2016-01-25 09:51:22 +0100441 --disable-threads \
Patrick Georgi8e68aff2016-02-08 11:48:26 +0100442 --enable-interwork --enable-multilib \
Patrick Georgi0a97d7e2016-01-25 09:51:22 +0100443 --disable-libatomic --disable-libcc1 --disable-decimal-float \
Nico Huberbb313bf2015-09-08 12:30:27 +0200444 ${GCC_OPTIONS} --enable-languages="${LANGUAGES}" \
Ronald G. Minnich7ee16b72016-02-12 21:54:59 +0000445 --with-system-zlib \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700446 --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \
447 --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \
448 --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \
449 || touch .failed
450 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-gcc || touch .failed
451 $MAKE install-gcc DESTDIR=$DESTDIR || touch .failed
452
Stefan Reinauerd7649122015-06-09 11:44:25 -0700453 if [ "$(echo $TARGETARCH | grep -c -- -mingw32)" -eq 0 ]; then
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700454 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-target-libgcc || touch .failed
455 $MAKE install-target-libgcc DESTDIR=$DESTDIR || touch .failed
456 fi
457}
458
459build_EXPAT() {
460 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${EXPAT_DIR}/configure --disable-shared \
461 --prefix=$TARGETDIR --target=${TARGETARCH} || touch .failed
462 $MAKE || touch .failed
463 $MAKE install DESTDIR=$DESTDIR || touch .failed
464
465 normalize_dirs
466}
467
468build_PYTHON() {
469 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$TARGETDIR \
470 --target=${TARGETARCH} || touch .failed
471 $MAKE $JOBS || touch .failed
472 $MAKE install DESTDIR=$DESTDIR || touch .failed
473
474 normalize_dirs
475}
476
477build_GDB() {
478 export PYTHONHOME=$DESTDIR$TARGETDIR
479 if [ $(uname) != "FreeBSD" -a $(uname) != "NetBSD" ]; then
480 LIBDL="-ldl"
481 fi
482 LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \
483 -lpthread $LIBDL -lutil" \
484 CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \
Stefan Reinauer7b40e422015-06-09 11:56:32 -0700485 ../${GDB_DIR}/configure --prefix=$TARGETDIR \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700486 --target=${TARGETARCH} --disable-werror --disable-nls
487 $MAKE $JOBS || touch .failed
488 $MAKE install DESTDIR=$DESTDIR || touch .failed
489}
490
491build_IASL() {
492 RDIR=$PWD
493 cd ../$IASL_DIR/generate/unix
494 CFLAGS="$HOSTCFLAGS"
495 HOST="_LINUX"
496 test $UNAME = "Darwin" && HOST="_APPLE"
497 test $UNAME = "FreeBSD" && HOST="_FreeBSD"
498 test $UNAME = "Cygwin" && HOST="_CYGWIN"
Martin Roth6f656132015-12-08 11:14:10 -0700499 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 -0700500 rm -f $DESTDIR$TARGETDIR/bin/iasl || touch $RDIR/.failed
501 cp bin/iasl $DESTDIR$TARGETDIR/bin || touch $RDIR/.failed
502}
503
504build_LLVM() {
505 cd ..
506 ln -sf $PWD/$CFE_DIR $LLVM_DIR/tools/clang
507 ln -sf $PWD/$CTE_DIR $LLVM_DIR/tools/clang/tools/extra
508 ln -sf $PWD/$CRT_DIR $LLVM_DIR/projects/compiler-rt
509 cd -
510
511 $CMAKE -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=$DESTDIR$TARGETDIR \
Martin Rothfb5647a2015-12-18 09:26:45 -0700512 -DCLANG_VENDOR="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE - " \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700513 -DCMAKE_BUILD_TYPE=Release ../$LLVM_DIR || touch .failed
514 $MAKE $JOBS || touch .failed
515 $MAKE install || touch .failed
516
517 cp -a ../$CFE_DIR/tools/scan-build/* $DESTDIR$TARGETDIR/bin
518 cp -a ../$CFE_DIR/tools/scan-view/* $DESTDIR$TARGETDIR/bin
Stefan Reinauere9e6e3d2015-07-07 00:20:42 +0200519
520 # create symlinks to work around broken --print-librt-file-name
521 # when used with -target.
522 cd $DESTDIR$TARGETDIR/lib/clang/${CLANG_VERSION}/lib
523 for i in */libclang_rt.builtins*.a; do
524 ln -s $i .
525 done
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700526}
527
Stefan Reinauera851bbb2016-01-29 18:03:26 -0800528build_MAKE() {
529 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${MAKE_DIR}/configure --prefix=$TARGETDIR \
530 --disable-nls || touch .failed
531 $MAKE $JOBS || touch .failed
532 $MAKE install DESTDIR=$DESTDIR || touch .failed
533
534 normalize_dirs
535}
536
Martin Rothedf965a2015-11-25 16:58:33 -0700537print_stable() {
538 case "$PRINTSTABLE" in
539 AUTOCONF|autoconf) printf "%s\n" "$GCC_AUTOCONF_VERSION";;
540 BINUTILS|binutils) printf "%s\n" "$BINUTILS_VERSION";;
541 CLANG|clang) printf "%s\n" "$CLANG_VERSION";;
542 EXPAT|expat) printf "%s\n" "$EXPAT_VERSION";;
543 GCC|gcc) printf "%s\n" "$GCC_VERSION";;
544 GDB|gdb) printf "%s\n" "$GDB_VERSION";;
545 GMP|gmp) printf "%s\n" "$GMP_VERSION";;
546 IASL|iasl) printf "%s\n" "$IASL_VERSION";;
547 LIBELF|libelf) printf "%s\n" "$LIBELF_VERSION";;
548 MPC|mpc) printf "%s\n" "$MPC_VERSION";;
549 MPFR|mpfr) printf "%s\n" "$MPFR_VERSION";;
550 PYTHON|python) printf "%s\n" "$PYTHON_VERSION";;
Stefan Reinauera851bbb2016-01-29 18:03:26 -0800551 MAKE|make) printf "%s\n" "$MAKE_VERSION";;
Martin Rothedf965a2015-11-25 16:58:33 -0700552 *) printf "Unknown tool %s\n" "$PRINTSTABLE";;
553 esac
554}
Stefan Reinauer074d9132009-09-26 16:43:17 +0000555
Patrick Georgi6bba29f2010-01-29 17:40:52 +0000556# Look if we have getopt. If not, build it.
557export PATH=$PATH:.
558getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c
559
Stefan Reinauer074d9132009-09-26 16:43:17 +0000560# parse parameters.. try to find out whether we're running GNU getopt
Stefan Reinauerd7649122015-06-09 11:44:25 -0700561getoptbrand="$(getopt -V | sed -e '1!d' -e 's,^\(......\).*,\1,')"
Peter Stuge09377b72011-08-21 06:24:55 +0200562if [ "${getoptbrand}" = "getopt" ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000563 # Detected GNU getopt that supports long options.
Martin Rothedf965a2015-11-25 16:58:33 -0700564 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 +0000565 eval set "$args"
566else
567 # Detected non-GNU getopt
Martin Rothedf965a2015-11-25 16:58:33 -0700568 args=$(getopt Vhcd:p:l:P:j:D:tSys: $*)
Stefan Reinauer074d9132009-09-26 16:43:17 +0000569 set -- $args
570fi
571
572if [ $? != 0 ]; then
573 myhelp
574 exit 1
575fi
576
577while true ; do
578 case "$1" in
579 -V|--version) shift; myversion; exit 0;;
580 -h|--help) shift; myhelp; exit 0;;
Patrick Georgi44af57a2013-12-19 22:06:22 +0100581 -c|--clean) shift; clean=1;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000582 -t|--savetemps) shift; SAVETEMPS=1;;
583 -d|--directory) shift; TARGETDIR="$1"; shift;;
584 -p|--platform) shift; TARGETARCH="$1"; shift;;
Nico Huberbb313bf2015-09-08 12:30:27 +0200585 -l|--languages) shift; LANGUAGES="$1"; shift;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000586 -D|--destdir) shift; DESTDIR="$1"; shift;;
Patrick Georgi73166c72010-04-14 20:42:42 +0000587 -j|--jobs) shift; JOBS="-j $1"; shift;;
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700588 -P|--package) shift; PACKAGE="$1"; shift;;
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100589 -S|--scripting) shift; SKIPPYTHON=0;;
Patrick Georgic1a75b12011-11-04 21:37:14 +0100590 -y|--ccache) shift; USECCACHE=1;;
Martin Rothedf965a2015-11-25 16:58:33 -0700591 -s|--supported) shift; PRINTSTABLE="$1"; shift;;
Patrick Georgid2e0dd52013-06-09 08:05:45 +0200592 --) shift; break;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000593 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
Patrick Georgid2e0dd52013-06-09 08:05:45 +0200594 *) break;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000595 esac
596done
597
Martin Rothedf965a2015-11-25 16:58:33 -0700598if [ -n "$PRINTSTABLE" ]; then
599 print_stable
600 exit 0
601fi
602
603#print toolchain builder version string as the header
604printversion
605
Ronald G. Minnichb460a662013-05-26 05:33:35 -0700606case "$TARGETARCH" in
Timothy Pearsona9f62352015-12-30 18:59:00 -0600607 x86_64-elf) ;;
608 x86_64*) TARGETARCH=x86_64-elf;;
609 i386-elf) ;;
610 i386-mingw32) ;;
611 mipsel-elf) ;;
612 riscv-elf) ;;
Patrick Georgi0a97d7e2016-01-25 09:51:22 +0100613 powerpc64*-linux*) ;;
Timothy Pearsona9f62352015-12-30 18:59:00 -0600614 i386*) TARGETARCH=i386-elf;;
Stefan Reinauer27522ad2016-01-29 17:31:34 -0800615 arm*) TARGETARCH=arm-eabi;;
Timothy Pearsona9f62352015-12-30 18:59:00 -0600616 aarch64*) TARGETARCH=aarch64-elf;;
617 *) printf "${red}WARNING: Unsupported architecture $TARGETARCH.${NC}\n\n"; ;;
Ronald G. Minnichb460a662013-05-26 05:33:35 -0700618esac
619
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700620# Figure out which packages to build
Stefan Reinauer699ac272015-06-05 12:43:28 -0700621
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700622case "$PACKAGE" in
623 GCC|gcc)
624 echo "Target architecture is now $TARGETARCH"
625 NAME="${TARGETARCH} cross GCC"
Stefan Reinauerbd8b2e32015-06-17 11:55:02 -0700626 PACKAGES="GMP MPFR MPC LIBELF BINUTILS GCC"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700627 ;;
628 GDB|gdb)
629 NAME="${TARGETARCH} cross GDB"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700630 if [ $SKIPPYTHON -eq 0 ]; then
Ronald G. Minnichfb944f42016-02-27 04:06:42 +0000631 PACKAGES="EXPAT PYTHON GDB"
632 else
633 PACKAGES="EXPAT GDB"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700634 fi
635 ;;
636 CLANG|clang)
637 NAME=clang
638 PACKAGES="LLVM CFE CRT CTE"
David Hendrickscd5cdd32015-06-15 17:03:22 -0700639 CMAKE=$(searchtool cmake "cmake") || exit $?
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700640 ;;
641 IASL|iasl)
642 NAME="IASL ACPI compiler"
643 PACKAGES=IASL
644 ;;
Stefan Reinauera851bbb2016-01-29 18:03:26 -0800645 MAKE|make)
646 NAME="GNU Make"
647 PACKAGES=MAKE
648 ;;
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700649 *)
Stefan Reinauera851bbb2016-01-29 18:03:26 -0800650 printf "${red}ERROR: Unsupported package $PACKAGE. (Supported packages are GCC, GDB, CLANG, IASL, MAKE)${NC}\n\n";
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700651 exit 1
652 ;;
653esac
Peter Stugeceacd772011-06-09 04:54:16 +0200654
Stefan Reinauer66e93352015-06-16 22:38:23 +0200655# Find all the required tools:
656
657TAR=$(searchtool tar) || exit $?
658PATCH=$(searchtool patch) || exit $?
659MAKE=$(searchtool make) || exit $?
660SHA1SUM=$(searchtool sha1sum)
661SHA512SUM=$(searchtool sha512sum)
662CHECKSUM=$SHA1SUM
663
664searchtool m4 > /dev/null
665searchtool bison > /dev/null
666searchtool flex flex > /dev/null
667searchtool g++ "Free Software Foundation" nofail > /dev/null || \
Marc Jones5ee69512015-06-17 15:38:17 -0600668searchtool clang "clang version" nofail > /dev/null || \
Martin Rothe3963172016-01-06 13:54:32 -0700669searchtool clang "LLVM" "" "g++" > /dev/null
Stefan Reinauer66e93352015-06-16 22:38:23 +0200670searchtool wget > /dev/null
671searchtool bzip2 "bzip2," > /dev/null
672
Martin Roth88463822016-01-07 11:03:36 -0700673if [ "$HALT_FOR_TOOLS" -ne 0 ]; then
674 exit 1
675fi
676
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700677# This initial cleanup is useful when updating the toolchain script.
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000678
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700679if [ "$clean" = "1" ]; then
680 cleanup
681fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000682
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700683# Set up host compiler and flags needed for various OSes
Stefan Reinauer074d9132009-09-26 16:43:17 +0000684
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700685CC=cc
Patrick Georgif2c15f52015-06-11 21:07:31 +0200686if is_package_enabled "GCC"; then
Stefan Reinauer0d2119d2013-07-10 14:27:56 -0700687if [ $UNAME = "Darwin" ]; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000688 #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix"
689
690 # generally the OS X compiler can create x64 binaries.
691 # Per default it generated i386 binaries in 10.5 and x64
692 # binaries in 10.6 (even if the kernel is 32bit)
693 # For some weird reason, 10.5 autodetects an ABI=64 though
694 # so we're setting the ABI explicitly here.
Stefan Reinauerd7649122015-06-09 11:44:25 -0700695 if [ $(sysctl -n hw.optional.x86_64 2>/dev/null) -eq 1 ] 2>/dev/null; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000696 OPTIONS="ABI=64"
697 else
698 OPTIONS="ABI=32"
699 fi
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700700
Stefan Reinauer4266b922012-12-05 16:18:32 -0800701 # In Xcode 4.5.2 the default compiler is clang.
702 # However, this compiler fails to compile gcc 4.7.x. As a
703 # workaround it's possible to compile gcc with llvm-gcc.
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700704 if $CC -v 2>&1 | grep -q LLVM; then
Stefan Reinauer4266b922012-12-05 16:18:32 -0800705 CC=llvm-gcc
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700706 fi
zbao11f1d312015-08-05 23:15:54 -0400707elif [ $UNAME = "Linux" -o $UNAME = "Cygwin" ]; then
Patrick Georgiddb8f802015-07-04 17:45:54 +0200708 # gmp is overeager with detecting 64bit CPUs even if they run
709 # a 32bit kernel and userland.
710 if [ "$(uname -m 2>/dev/null)" = "i686" ]; then
711 OPTIONS="ABI=32"
712 fi
Nico Huberde45c592016-01-20 23:22:33 +0100713elif [ $UNAME = "NetBSD" ]; then
714 # same for NetBSD but this one reports an i386
715 if [ "$(uname -m 2>/dev/null)" = "i386" ]; then
716 OPTIONS="ABI=32"
717 fi
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000718fi
Stefan Reinauer14ce2132015-06-05 13:01:13 -0700719fi # GCC
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000720
Patrick Georgic1a75b12011-11-04 21:37:14 +0100721if [ "$USECCACHE" = 1 ]; then
722 CC="ccache $CC"
723fi
724
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700725# Prepare target directory for building GCC
726# (dependencies must be in the PATH)
Stefan Reinauer16bd7892012-12-07 23:57:01 +0100727mkdir -p $DESTDIR$TARGETDIR/bin
728export PATH=$DESTDIR$TARGETDIR/bin:$PATH
729
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700730# Download, unpack, patch and build all packages
731
Martin Roth03625172016-02-17 14:44:14 -0700732printf "Downloading tarballs ... \n"
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700733mkdir -p tarballs
734for P in $PACKAGES; do
735 download $P
736done
Martin Roth03625172016-02-17 14:44:14 -0700737printf "Downloaded tarballs ... ${green}ok${NC}\n"
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700738
739printf "Unpacking and patching ... \n"
740for P in $PACKAGES; do
741 unpack_and_patch $P || exit 1
742done
743printf "Unpacked and patched ... ${green}ok${NC}\n"
744
745printf "Building packages ... \n"
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700746for package in $PACKAGES; do
747 build $package
748done
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700749printf "Packages built ... ${green}ok${NC}\n"
Stefan Reinauer14ce2132015-06-05 13:01:13 -0700750
Stefan Reinauer699ac272015-06-05 12:43:28 -0700751# Adding git information of current tree to target directory
752# for reproducibility
Stefan Reinauerd7649122015-06-09 11:44:25 -0700753PROGNAME=$(basename "$0")
Patrick Georgi5602f2c2015-03-28 15:48:47 +0100754rm -f "$DESTDIR$TARGETDIR/$PROGNAME".commit.*
Stefan Reinauerd7649122015-06-09 11:44:25 -0700755cp "$PROGNAME" $DESTDIR$TARGETDIR/"$PROGNAME.commit.$(git describe)"
Zheng Bao30b895f2013-02-06 18:04:40 +0800756
Stefan Reinauer074d9132009-09-26 16:43:17 +0000757if [ $SAVETEMPS -eq 0 ]; then
Stefan Reinauer699ac272015-06-05 12:43:28 -0700758 cleanup
Stefan Reinauer074d9132009-09-26 16:43:17 +0000759else
760 printf "Leaving temporary files around... ${green}ok${NC}\n"
761fi
762
Stefan Reinauer699ac272015-06-05 12:43:28 -0700763printf "\n${green}You can now run your $NAME toolchain from $TARGETDIR.${NC}\n"