blob: 423d7690474af569adeabec0ca19682f65c8f240 [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
Martin Roth64b35f32015-12-30 15:10:13 -070021CROSSGCC_DATE="March 21st, 2016"
22CROSSGCC_VERSION="1.37"
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
Martin Roth64b35f32015-12-30 15:10:13 -070042IASL_VERSION=20160318
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
Martin Roth1484c032016-03-08 09:37:14 -070050# These are sanitized by the jenkins toolchain test builder, so if
51# a completely new URL is added here, it probably needs to be added
52# to the jenkins build as well, or the builder won't download it.
Timothy Pearson96310162015-12-28 22:53:29 -060053GMP_ARCHIVE="http://ftpmirror.gnu.org/gmp/gmp-${GMP_VERSION}.tar.bz2"
Patrick Georgi6e61ad32012-05-12 23:19:30 +020054MPFR_ARCHIVE="http://ftpmirror.gnu.org/mpfr/mpfr-${MPFR_VERSION}.tar.bz2"
Idwer Vollering7962fc72012-10-25 02:14:09 +020055MPC_ARCHIVE="http://ftpmirror.gnu.org/mpc/mpc-${MPC_VERSION}.tar.gz"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000056LIBELF_ARCHIVE="http://www.mr511.de/software/libelf-${LIBELF_VERSION}.tar.gz"
Idwer Vollering1cfee0b2012-10-25 02:03:53 +020057GCC_ARCHIVE="http://ftpmirror.gnu.org/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.bz2"
Stefan Reinauer0d2119d2013-07-10 14:27:56 -070058BINUTILS_ARCHIVE="http://ftpmirror.gnu.org/binutils/binutils-${BINUTILS_VERSION}.tar.bz2"
Patrick Georgi53c388f2015-03-07 09:55:18 +010059GDB_ARCHIVE="http://ftpmirror.gnu.org/gdb/gdb-${GDB_VERSION}.tar.xz"
Patrick Georgi85bb9462016-02-11 17:22:16 +010060IASL_ARCHIVE="https://acpica.org/sites/acpica/files/acpica-unix2-${IASL_VERSION}.tar.gz"
Patrick Georgi53c388f2015-03-07 09:55:18 +010061PYTHON_ARCHIVE="http://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010062EXPAT_ARCHIVE="http://downloads.sourceforge.net/sourceforge/expat/expat-${EXPAT_VERSION}.tar.gz"
Stefan Reinauer14ce2132015-06-05 13:01:13 -070063# CLANG toolchain archive locations
64LLVM_ARCHIVE="http://llvm.org/releases/${CLANG_VERSION}/llvm-${CLANG_VERSION}.src.tar.xz"
65CFE_ARCHIVE="http://llvm.org/releases/${CLANG_VERSION}/cfe-${CLANG_VERSION}.src.tar.xz"
66CRT_ARCHIVE="http://llvm.org/releases/${CLANG_VERSION}/compiler-rt-${CLANG_VERSION}.src.tar.xz"
67CTE_ARCHIVE="http://llvm.org/releases/${CLANG_VERSION}/clang-tools-extra-${CLANG_VERSION}.src.tar.xz"
Stefan Reinauera851bbb2016-01-29 18:03:26 -080068MAKE_ARCHIVE="http://ftpmirror.gnu.org/make/make-${MAKE_VERSION}.tar.bz2"
Stefan Reinauer074d9132009-09-26 16:43:17 +000069
Martin Roth58c68d52016-03-01 15:22:42 -070070ALL_ARCHIVES="$GMP_ARCHIVE $MPFR_ARCHIVE $MPC_ARCHIVE $LIBELF_ARCHIVE \
71 $GCC_ARCHIVE $BINUTILS_ARCHIVE $GDB_ARCHIVE $IASL_ARCHIVE \
72 $PYTHON_ARCHIVE $EXPAT_ARCHIVE $LLVM_ARCHIVE $CFE_ARCHIVE \
73 $CRT_ARCHIVE $CTE_ARCHIVE $MAKE_ARCHIVE"
74
Stefan Reinauer699ac272015-06-05 12:43:28 -070075# GCC toolchain directories
Stefan Reinauer074d9132009-09-26 16:43:17 +000076GMP_DIR="gmp-${GMP_VERSION}"
77MPFR_DIR="mpfr-${MPFR_VERSION}"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000078MPC_DIR="mpc-${MPC_VERSION}"
79LIBELF_DIR="libelf-${LIBELF_VERSION}"
Stefan Reinauer074d9132009-09-26 16:43:17 +000080GCC_DIR="gcc-${GCC_VERSION}"
81BINUTILS_DIR="binutils-${BINUTILS_VERSION}"
82GDB_DIR="gdb-${GDB_VERSION}"
Patrick Georgi85bb9462016-02-11 17:22:16 +010083IASL_DIR="acpica-unix2-${IASL_VERSION}"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010084PYTHON_DIR="Python-${PYTHON_VERSION}"
85EXPAT_DIR="expat-${EXPAT_VERSION}"
Stefan Reinauer14ce2132015-06-05 13:01:13 -070086# CLANG toolchain directories
87LLVM_DIR="llvm-${CLANG_VERSION}.src"
88CFE_DIR="cfe-${CLANG_VERSION}.src"
89CRT_DIR="compiler-rt-${CLANG_VERSION}.src"
90CTE_DIR="clang-tools-extra-${CLANG_VERSION}.src"
Stefan Reinauera851bbb2016-01-29 18:03:26 -080091MAKE_DIR="make-${MAKE_VERSION}"
Stefan Reinauer074d9132009-09-26 16:43:17 +000092
Patrick Georgi6321f522015-02-27 23:36:26 +010093unset MAKELEVEL MAKEFLAGS
94
Patrick Georgi1861ff72011-10-31 12:15:55 +010095red='\033[0;31m'
96RED='\033[1;31m'
97green='\033[0;32m'
98GREEN='\033[1;32m'
99blue='\033[0;34m'
100BLUE='\033[1;34m'
101cyan='\033[0;36m'
102CYAN='\033[1;36m'
103NC='\033[0m' # No Color
Stefan Reinauer074d9132009-09-26 16:43:17 +0000104
zbaoe05c1ea2015-08-05 23:10:05 -0400105UNAME=$(uname | grep -iq cygwin && echo Cygwin || uname)
Martin Roth88463822016-01-07 11:03:36 -0700106HALT_FOR_TOOLS=0
Stefan Reinauer0d2119d2013-07-10 14:27:56 -0700107
Patrick Georgi198d23c2012-12-08 08:02:44 +0100108normalize_dirs()
109{
110 mkdir -p $DESTDIR$TARGETDIR/lib
111 test -d $DESTDIR$TARGETDIR/lib32 && mv $DESTDIR$TARGETDIR/lib32/* $DESTDIR$TARGETDIR/lib
112 test -d $DESTDIR$TARGETDIR/lib64 && mv $DESTDIR$TARGETDIR/lib64/* $DESTDIR$TARGETDIR/lib
113 rmdir -p $DESTDIR$TARGETDIR/lib32 $DESTDIR$TARGETDIR/lib64
114
115 perl -pi -e "s,/lib32,/lib," $DESTDIR$TARGETDIR/lib/*.la
116 perl -pi -e "s,/lib64,/lib," $DESTDIR$TARGETDIR/lib/*.la
117}
118
Stefan Reinauer93a96302015-06-15 12:36:53 -0700119please_install()
120{
Martin Roth88463822016-01-07 11:03:36 -0700121 HALT_FOR_TOOLS=1
Patrick Georgi5da95dc2015-07-17 23:33:05 +0200122 test -r /etc/os-release && . /etc/os-release
Stefan Reinauer93a96302015-06-15 12:36:53 -0700123 case "$ID_LIKE" in
124 debian) solution="sudo apt-get install $1" ;;
125 suse) solution="sudo zypper install $1" ;;
126 *) solution="using your OS packaging system" ;;
127 esac
128
129 printf "${RED}ERROR:${red} Missing tool: Please install \'$1\' utility. (eg $solution)${NC}\n" >&2
Martin Rothe3963172016-01-06 13:54:32 -0700130 if [ -n "$2" ]; then
131 printf "${RED}ERROR:${red} or install \'$2\' utility. (eg $solution)${NC}\n" >&2
132 fi
Stefan Reinauer93a96302015-06-15 12:36:53 -0700133}
134
Patrick Georgib7062882015-02-24 10:52:14 +0100135searchtool()
Stefan Reinauer074d9132009-09-26 16:43:17 +0000136{
137 # $1 short name
Patrick Georgib7062882015-02-24 10:52:14 +0100138 # $2 search string
139 # $3 soft fail if set
Martin Rothe3963172016-01-06 13:54:32 -0700140 # $4 alternative package to install on failure
Patrick Georgib7062882015-02-24 10:52:14 +0100141 # result: file name of that tool on stdout
142 # or no output if nothing suitable was found
143 search=GNU
144 if [ -n "$2" ]; then
145 search="$2"
146 fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000147 for i in "$1" "g$1" "gnu$1"; do
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700148 if [ -x "$(which $i 2>/dev/null)" ]; then
149 if [ "$(cat /dev/null | $i --version 2>&1 | grep -c "$search")" \
150 -gt 0 ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000151 echo $i
152 return
153 fi
154 fi
155 done
Andrew Wub67e9a12014-04-28 18:13:44 +0800156 # A workaround for OSX 10.9 and some BSDs, whose nongnu
157 # patch and tar also work.
Patrick Georgi7cb26b42015-04-28 21:29:22 +0200158 if [ $UNAME = "Darwin" -o $UNAME = "FreeBSD" -o $UNAME = "NetBSD" -o $UNAME = "OpenBSD" ]; then
Patrick Georgib7062882015-02-24 10:52:14 +0100159 if [ "$1" = "patch" -o "$1" = "tar" ]; then
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700160 if [ -x "$(which $1 2>/dev/null)" ]; then
Zheng Bao36156ff2012-09-28 16:18:58 +0800161 echo $1
162 return
163 fi
164 fi
165 fi
Stefan Reinauerd7649122015-06-09 11:44:25 -0700166 if [ "$(echo $1 | cut -b -3)" = "sha" ]; then
zbao939dc842015-04-30 04:44:07 +0800167 if [ $UNAME = "FreeBSD" ]; then
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700168 if [ -x "$(which sha1 2>/dev/null)" ]; then
zbao939dc842015-04-30 04:44:07 +0800169 echo sha1
170 return
171 fi
172 fi
173 if [ $UNAME = "NetBSD" ]; then
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700174 if [ -x "$(which cksum 2>/dev/null)" ]; then
Stefan Reinauerd7649122015-06-09 11:44:25 -0700175 echo cksum -a $(echo $1 | sed -e 's,sum,,')
zbao939dc842015-04-30 04:44:07 +0800176 return
177 fi
178 fi
179 if [ $UNAME = "Darwin" ]; then
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700180 if [ -x "$(which openssl 2>/dev/null)" ]; then
Stefan Reinauerd7649122015-06-09 11:44:25 -0700181 echo openssl $(echo $1 | sed -e 's,sum,,')
zbao939dc842015-04-30 04:44:07 +0800182 return
183 fi
184 fi
185 fi
Martin Rothe3963172016-01-06 13:54:32 -0700186
Martin Roth88463822016-01-07 11:03:36 -0700187 [ -z "$3" ] && please_install $1 $4
Patrick Georgib7062882015-02-24 10:52:14 +0100188 false
Stefan Reinauer074d9132009-09-26 16:43:17 +0000189}
190
zbao06e85ac2015-08-24 22:08:36 -0400191check_sum() {
192 test -z "$CHECKSUM" || \
193 test "$(cat sum/$1.cksum 2>/dev/null | sed -e 's@.*\([0-9a-f]\{40,\}\).*@\1@')" = \
194 "$($CHECKSUM tarballs/$1 2>/dev/null | sed -e 's@.*\([0-9a-f]\{40,\}\).*@\1@')"
195}
196
197compute_sum() {
198 test ! -f sum/$1.cksum && test -f tarballs/$1 && \
199 (test -z "$CHECKSUM" || $CHECKSUM tarballs/$1 > sum/$1.cksum ) && \
200 printf "(checksum created. ${RED}Note. Please upload sum/$1.cksum if the corresponding archive is upgraded.)${NC}"
201}
202
zbao282dd952015-09-06 05:00:04 -0400203download_showing_percentage() {
204 url=$1
205 printf " ..${red} 0%%"
206 wget --no-check-certificate $url 2>&1 | while read line; do
207 printf "${red}"
208 echo $line | grep -o "[0-9]\+%" | awk '{printf("\b\b\b\b%4s", $1)}'
209 printf "${NC}"
210 done
211}
212
Stefan Reinauer88935482015-06-05 09:51:10 -0700213download() {
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700214 package=$1
215 archive="$(eval echo \$$package"_ARCHIVE")"
Stefan Reinauer699ac272015-06-05 12:43:28 -0700216
Stefan Reinauerd7649122015-06-09 11:44:25 -0700217 FILE=$(basename $archive)
Stefan Reinauer88935482015-06-05 09:51:10 -0700218 printf " * $FILE "
219
zbaod22b9ea2015-08-30 23:35:16 -0400220 if test -f tarballs/$FILE && check_sum $FILE ; then
221 printf "(cached)"
222 else
Paul Menzelb2ba3952015-06-12 11:58:14 +0200223 printf "(downloading from $archive)"
Stefan Reinauer88935482015-06-05 09:51:10 -0700224 rm -f tarballs/$FILE
225 cd tarballs
zbao282dd952015-09-06 05:00:04 -0400226 download_showing_percentage $archive
Stefan Reinauer88935482015-06-05 09:51:10 -0700227 cd ..
zbao06e85ac2015-08-24 22:08:36 -0400228 compute_sum $FILE
zbaod22b9ea2015-08-30 23:35:16 -0400229 fi
230
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700231 if [ ! -f tarballs/$FILE ]; then
zbao282dd952015-09-06 05:00:04 -0400232 printf "\n${RED}Failed to download $FILE.${NC}\n"
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700233 exit 1
234 fi
Stefan Reinauer88935482015-06-05 09:51:10 -0700235 printf "\n"
236}
237
238unpack_and_patch() {
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700239 package=$1
240 archive="$(eval echo \$$package"_ARCHIVE")"
241 dir="$(eval echo \$$package"_DIR")"
Stefan Reinauer88935482015-06-05 09:51:10 -0700242 test -d ${dir} && test -f ${dir}/.unpack_success || (
Stefan Reinauerd7649122015-06-09 11:44:25 -0700243 printf " * $(basename $archive)\n"
Stefan Reinauer88935482015-06-05 09:51:10 -0700244 FLAGS=zxf
Stefan Reinauerd7649122015-06-09 11:44:25 -0700245 suffix=$(echo $archive | sed 's,.*\.,,')
Martin Roth95f7b222016-03-20 12:38:48 -0600246 if [ "$suffix" = "gz" ] && [ -n "$PIGZ" ]; then FLAGS="-I pigz -xf"
247 elif [ "$suffix" = "gz" ]; then FLAGS=zxf
248 elif [ "$suffix" = "bz2" ] && [ -n "$LBZIP2" ]; then FLAGS="-I lbzip2 -xf"
249 elif [ "$suffix" = "bz2" ]; then FLAGS=jxf
250 elif [ "$suffix" = "xz" ]; then FLAGS="--xz -xf"
251 elif [ "$suffix" = "lzma" ]; then FLAGS="--lzma -xf"
252 fi
Stefan Reinauerd7649122015-06-09 11:44:25 -0700253 $TAR $FLAGS tarballs/$(basename $archive)
Stefan Reinauer88935482015-06-05 09:51:10 -0700254 for patch in patches/${dir}_*.patch; do
255 test -r $patch || continue
Stefan Reinauerd7649122015-06-09 11:44:25 -0700256 printf " o $(basename $patch)\n"
Stefan Reinauer916b8452015-06-09 11:54:49 -0700257 $PATCH -s -N -p0 < $(echo $patch) || {
Stefan Reinauer88935482015-06-05 09:51:10 -0700258 printf "\n${RED}Failed $patch.${NC}\n"
Stefan Reinauer916b8452015-06-09 11:54:49 -0700259 exit 1
260 }
Stefan Reinauer88935482015-06-05 09:51:10 -0700261 done
262 touch ${dir}/.unpack_success
263 )
264}
265
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700266fn_exists()
267{
Patrick Georgic8665912015-06-11 21:04:31 +0200268 type $1 >/dev/null 2>&1
Patrick Georgi74c06422015-03-25 18:40:13 +0100269}
270
Patrick Georgif2c15f52015-06-11 21:07:31 +0200271is_package_enabled()
272{
273 echo "$PACKAGES" |grep -q "\<$1\>"
274}
275
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700276build() {
277 package=$1
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700278
279 fn_exists build_$package || return
280
Stefan Reinauer05bbc9202015-06-09 12:21:42 -0700281 version="$(eval echo \$$package"_VERSION")"
282 BUILDDIR=build-${TARGETARCH}-$package
283
284 mkdir -p ${BUILDDIR}
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700285
Patrick Georgif2c15f52015-06-11 21:07:31 +0200286 is_package_enabled "$package" && \
Stefan Reinauer05bbc9202015-06-09 12:21:42 -0700287 if [ -f ${BUILDDIR}/.success ]; then
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700288 printf "Skipping $package as it is already built\n"
289 else
290 printf "Building $package $version ... "
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700291 DIR=$PWD
Stefan Reinauer05bbc9202015-06-09 12:21:42 -0700292 cd ${BUILDDIR}
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700293 rm -f .failed
294 build_${package} > build.log 2>&1
Stefan Reinauer05bbc9202015-06-09 12:21:42 -0700295 cd $DIR/${BUILDDIR}
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700296 if [ ! -f .failed ]; then touch .success; fi
297 cd ..
298
Stefan Reinauer05bbc9202015-06-09 12:21:42 -0700299 if [ -r "${BUILDDIR}/.failed" ]; then
300 printf "${RED}failed${NC}. Check ${BUILDDIR}/build.log.\n"
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700301 exit 1
302 fi
303 printf "${green}ok${NC}\n"
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700304 fi
305}
306
Stefan Reinauer074d9132009-09-26 16:43:17 +0000307cleanup()
308{
309 printf "Cleaning up temporary files... "
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700310 for package in $PACKAGES; do
Stefan Reinauer05bbc9202015-06-09 12:21:42 -0700311 rm -rf build-${TARGETARCH}-$package $(eval echo \$$package"_DIR")
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700312 done
zbaoff3f15c2015-08-26 22:00:31 -0400313 rm -f getopt
Stefan Reinauer074d9132009-09-26 16:43:17 +0000314 printf "${green}ok${NC}\n"
315}
316
317myhelp()
318{
Stefan Reinauer14ce2132015-06-05 13:01:13 -0700319 printf "Usage: $0 [-V] [-c] [-p <platform>] [-d <target directory>] [-D <dest dir>] [-C] [-G] [-S]\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000320 printf " $0 [-V|--version]\n"
321 printf " $0 [-h|--help]\n\n"
322
323 printf "Options:\n"
324 printf " [-V|--version] print version number and exit\n"
325 printf " [-h|--help] print this help and exit\n"
326 printf " [-c|--clean] remove temporary files before build\n"
327 printf " [-t|--savetemps] don't remove temporary files after build\n"
Patrick Georgic1a75b12011-11-04 21:37:14 +0100328 printf " [-y|--ccache] Use ccache when building cross compiler\n"
Martin Roth4a53db02016-03-01 15:21:07 -0700329 printf " [--nocolor] don't print color codes in output\n"
Martin Roth58c68d52016-03-01 15:22:42 -0700330 printf " [--urls] print the urls for all packages\n"
Patrick Georgi73166c72010-04-14 20:42:42 +0000331 printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n"
Martin Roth588c79d2016-03-20 12:03:20 -0600332 printf " [-s]--supported <tool> print supported version of a tool\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000333 printf " [-d|--directory <target dir>] target directory to install cross compiler to\n"
Martin Roth588c79d2016-03-20 12:03:20 -0600334 printf " (defaults to $TARGETDIR)\n\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000335 printf " [-D|--destdir <dest dir>] destination directory to install cross compiler to\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100336 printf " (for RPM builds, default unset)\n"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700337 printf " [-P|--package <package>] Build a specific package: GCC, CLANG, IASL, GDB\n"
338 printf " (defaults to $PACKAGE)\n"
339 printf "GCC specific options:\n"
340 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
341 printf " (defaults to $TARGETARCH)\n"
Nico Huberbb313bf2015-09-08 12:30:27 +0200342 printf " [-l|--languages <languages>] comma separated list of target languages\n"
343 printf " (defaults to $LANGUAGES)\n"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700344 printf "GDB specific options:\n"
345 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
346 printf " (defaults to $TARGETARCH)\n"
347 printf " [-S|--scripting] build scripting support for GDB\n\n"
Martin Rothd1da74f2015-06-21 12:06:28 -0600348 printf "Platforms for GCC & GDB:\n"
Martin Roth3e0f74d2016-03-08 12:07:04 -0700349 printf " x86_64 i386-elf i386-mingw32 mipsel-elf riscv-elf arm aarch64\n"
Jonathan Neuschäferf14f6402016-03-11 20:22:23 +0100350 printf " powerpc64le-linux-gnu nds32le-elf\n\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000351}
352
Martin Rothedf965a2015-11-25 16:58:33 -0700353printversion() {
354 printf "${blue}Welcome to the ${red}coreboot${blue} cross toolchain builder v$CROSSGCC_VERSION ($CROSSGCC_DATE)${NC}\n\n"
355}
356
Stefan Reinauer074d9132009-09-26 16:43:17 +0000357myversion()
358{
Martin Rothedf965a2015-11-25 16:58:33 -0700359 printversion
Stefan Reinauer074d9132009-09-26 16:43:17 +0000360
361 cat << EOF
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000362Copyright (C) 2008-2010 by coresystems GmbH
Marc Jones2aac3f62011-08-08 16:07:50 -0600363Copyright (C) 2011 by Sage Electronic Engineering
Stefan Reinauer074d9132009-09-26 16:43:17 +0000364
365This program is free software; you can redistribute it and/or modify
366it under the terms of the GNU General Public License as published by
367the Free Software Foundation; version 2 of the License.
368
369This program is distributed in the hope that it will be useful,
370but WITHOUT ANY WARRANTY; without even the implied warranty of
371MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
372GNU General Public License for more details.
373
374EOF
375}
376
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700377build_GMP() {
378 CC="$CC" CFLAGS="-Os" ../${GMP_DIR}/configure --disable-shared --enable-fat --prefix=$TARGETDIR $OPTIONS \
379 || touch .failed
380 $MAKE $JOBS || touch .failed
381 $MAKE install DESTDIR=$DESTDIR || touch .failed
382
383 normalize_dirs
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700384
385 # Now set CFLAGS to match GMP CFLAGS but strip out -pedantic
386 # as GCC 4.6.x fails if it's there.
387 export HOSTCFLAGS=$(grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2 |\
388 sed s,-pedantic,,)
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700389}
390
391build_MPFR() {
392 test $UNAME = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
393 CC="$CC" ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
394 --infodir=$TARGETDIR/info \
395 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
396 touch .failed
397 $MAKE $JOBS || touch .failed
398 $MAKE install DESTDIR=$DESTDIR || touch .failed
399
400 normalize_dirs
401
402 # work around build problem of libgmp.la
403 if [ "$DESTDIR" != "" ]; then
404 perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la
405 fi
406}
407
408build_MPC() {
409 CC="$CC" ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \
410 --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \
411 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
412 touch .failed
413 $MAKE $JOBS || touch .failed
414 $MAKE install DESTDIR=$DESTDIR || touch .failed
415
416 normalize_dirs
417}
418
419build_LIBELF() {
420 CC="$CC" CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no \
421 ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \
422 --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed
423 $MAKE $JOBS || touch .failed
424 $MAKE install prefix=$DESTDIR$TARGETDIR || touch .failed
425
426 normalize_dirs
427}
428
429build_BINUTILS() {
Stefan Reinauer682a90c2015-06-09 14:59:58 -0700430 if [ $TARGETARCH == "x86_64-elf" ]; then
431 ADDITIONALTARGET=",i386-elf"
432 fi
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700433 CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \
Stefan Reinauer682a90c2015-06-09 14:59:58 -0700434 --target=${TARGETARCH} --enable-targets=${TARGETARCH}${ADDITIONALTARGET} \
435 --disable-werror --disable-nls --enable-lto --enable-gold \
436 --enable-plugins --enable-multilibs CFLAGS="$HOSTCFLAGS" || touch .failed
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700437 $MAKE $JOBS || touch .failed
438 $MAKE install DESTDIR=$DESTDIR || touch .failed
439}
440
441
442build_GCC() {
Stefan Reinauerd0f83722015-06-09 11:52:28 -0700443 # GCC does not honor HOSTCFLAGS at all. CFLAGS are used for
444 # both target and host object files.
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700445 # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
446 # but it does not seem to work properly. At least the host library
447 # libiberty is not compiled with CFLAGS_FOR_BUILD.
Patrick Georgi0a97d7e2016-01-25 09:51:22 +0100448 CC="$CC" CFLAGS_FOR_TARGET="-O2 -Dinhibit_libc" CFLAGS="$HOSTCFLAGS" \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700449 CFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \
450 --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \
451 --target=${TARGETARCH} --disable-werror --disable-shared \
Stefan Reinauer2f97ebc2015-06-09 12:24:54 -0700452 --enable-lto --enable-plugins --enable-gold --enable-ld=default \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700453 --disable-libssp --disable-bootstrap --disable-nls \
454 --disable-libquadmath --without-headers \
Patrick Georgi0a97d7e2016-01-25 09:51:22 +0100455 --disable-threads \
Patrick Georgi1fc02d12016-03-23 21:44:43 +0100456 --enable-interwork --enable-multilib --enable-targets=all \
Patrick Georgi0a97d7e2016-01-25 09:51:22 +0100457 --disable-libatomic --disable-libcc1 --disable-decimal-float \
Nico Huberbb313bf2015-09-08 12:30:27 +0200458 ${GCC_OPTIONS} --enable-languages="${LANGUAGES}" \
Ronald G. Minnich7ee16b72016-02-12 21:54:59 +0000459 --with-system-zlib \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700460 --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \
461 --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \
462 --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \
463 || touch .failed
464 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-gcc || touch .failed
465 $MAKE install-gcc DESTDIR=$DESTDIR || touch .failed
466
Stefan Reinauerd7649122015-06-09 11:44:25 -0700467 if [ "$(echo $TARGETARCH | grep -c -- -mingw32)" -eq 0 ]; then
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700468 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-target-libgcc || touch .failed
469 $MAKE install-target-libgcc DESTDIR=$DESTDIR || touch .failed
470 fi
471}
472
473build_EXPAT() {
474 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${EXPAT_DIR}/configure --disable-shared \
475 --prefix=$TARGETDIR --target=${TARGETARCH} || touch .failed
476 $MAKE || touch .failed
477 $MAKE install DESTDIR=$DESTDIR || touch .failed
478
479 normalize_dirs
480}
481
482build_PYTHON() {
483 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$TARGETDIR \
484 --target=${TARGETARCH} || touch .failed
485 $MAKE $JOBS || touch .failed
486 $MAKE install DESTDIR=$DESTDIR || touch .failed
487
488 normalize_dirs
489}
490
491build_GDB() {
492 export PYTHONHOME=$DESTDIR$TARGETDIR
493 if [ $(uname) != "FreeBSD" -a $(uname) != "NetBSD" ]; then
494 LIBDL="-ldl"
495 fi
496 LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \
497 -lpthread $LIBDL -lutil" \
498 CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \
Stefan Reinauer7b40e422015-06-09 11:56:32 -0700499 ../${GDB_DIR}/configure --prefix=$TARGETDIR \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700500 --target=${TARGETARCH} --disable-werror --disable-nls
501 $MAKE $JOBS || touch .failed
502 $MAKE install DESTDIR=$DESTDIR || touch .failed
503}
504
505build_IASL() {
506 RDIR=$PWD
507 cd ../$IASL_DIR/generate/unix
508 CFLAGS="$HOSTCFLAGS"
509 HOST="_LINUX"
510 test $UNAME = "Darwin" && HOST="_APPLE"
511 test $UNAME = "FreeBSD" && HOST="_FreeBSD"
512 test $UNAME = "Cygwin" && HOST="_CYGWIN"
Martin Roth6f656132015-12-08 11:14:10 -0700513 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 -0700514 rm -f $DESTDIR$TARGETDIR/bin/iasl || touch $RDIR/.failed
515 cp bin/iasl $DESTDIR$TARGETDIR/bin || touch $RDIR/.failed
516}
517
518build_LLVM() {
519 cd ..
520 ln -sf $PWD/$CFE_DIR $LLVM_DIR/tools/clang
521 ln -sf $PWD/$CTE_DIR $LLVM_DIR/tools/clang/tools/extra
522 ln -sf $PWD/$CRT_DIR $LLVM_DIR/projects/compiler-rt
523 cd -
524
525 $CMAKE -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=$DESTDIR$TARGETDIR \
Martin Rothfb5647a2015-12-18 09:26:45 -0700526 -DCLANG_VENDOR="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE - " \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700527 -DCMAKE_BUILD_TYPE=Release ../$LLVM_DIR || touch .failed
528 $MAKE $JOBS || touch .failed
529 $MAKE install || touch .failed
530
531 cp -a ../$CFE_DIR/tools/scan-build/* $DESTDIR$TARGETDIR/bin
532 cp -a ../$CFE_DIR/tools/scan-view/* $DESTDIR$TARGETDIR/bin
Stefan Reinauere9e6e3d2015-07-07 00:20:42 +0200533
534 # create symlinks to work around broken --print-librt-file-name
535 # when used with -target.
536 cd $DESTDIR$TARGETDIR/lib/clang/${CLANG_VERSION}/lib
537 for i in */libclang_rt.builtins*.a; do
538 ln -s $i .
539 done
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700540}
541
Stefan Reinauera851bbb2016-01-29 18:03:26 -0800542build_MAKE() {
543 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${MAKE_DIR}/configure --prefix=$TARGETDIR \
544 --disable-nls || touch .failed
545 $MAKE $JOBS || touch .failed
546 $MAKE install DESTDIR=$DESTDIR || touch .failed
547
548 normalize_dirs
549}
550
Martin Rothedf965a2015-11-25 16:58:33 -0700551print_stable() {
552 case "$PRINTSTABLE" in
553 AUTOCONF|autoconf) printf "%s\n" "$GCC_AUTOCONF_VERSION";;
554 BINUTILS|binutils) printf "%s\n" "$BINUTILS_VERSION";;
555 CLANG|clang) printf "%s\n" "$CLANG_VERSION";;
556 EXPAT|expat) printf "%s\n" "$EXPAT_VERSION";;
557 GCC|gcc) printf "%s\n" "$GCC_VERSION";;
558 GDB|gdb) printf "%s\n" "$GDB_VERSION";;
559 GMP|gmp) printf "%s\n" "$GMP_VERSION";;
560 IASL|iasl) printf "%s\n" "$IASL_VERSION";;
561 LIBELF|libelf) printf "%s\n" "$LIBELF_VERSION";;
562 MPC|mpc) printf "%s\n" "$MPC_VERSION";;
563 MPFR|mpfr) printf "%s\n" "$MPFR_VERSION";;
564 PYTHON|python) printf "%s\n" "$PYTHON_VERSION";;
Stefan Reinauera851bbb2016-01-29 18:03:26 -0800565 MAKE|make) printf "%s\n" "$MAKE_VERSION";;
Martin Rothedf965a2015-11-25 16:58:33 -0700566 *) printf "Unknown tool %s\n" "$PRINTSTABLE";;
567 esac
568}
Stefan Reinauer074d9132009-09-26 16:43:17 +0000569
Patrick Georgi6bba29f2010-01-29 17:40:52 +0000570# Look if we have getopt. If not, build it.
571export PATH=$PATH:.
572getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c
573
Stefan Reinauer074d9132009-09-26 16:43:17 +0000574# parse parameters.. try to find out whether we're running GNU getopt
Stefan Reinauerd7649122015-06-09 11:44:25 -0700575getoptbrand="$(getopt -V | sed -e '1!d' -e 's,^\(......\).*,\1,')"
Peter Stuge09377b72011-08-21 06:24:55 +0200576if [ "${getoptbrand}" = "getopt" ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000577 # Detected GNU getopt that supports long options.
Martin Rothedf965a2015-11-25 16:58:33 -0700578 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 +0000579 eval set "$args"
580else
581 # Detected non-GNU getopt
Martin Rothedf965a2015-11-25 16:58:33 -0700582 args=$(getopt Vhcd:p:l:P:j:D:tSys: $*)
Stefan Reinauer074d9132009-09-26 16:43:17 +0000583 set -- $args
584fi
585
586if [ $? != 0 ]; then
587 myhelp
588 exit 1
589fi
590
591while true ; do
592 case "$1" in
593 -V|--version) shift; myversion; exit 0;;
594 -h|--help) shift; myhelp; exit 0;;
Patrick Georgi44af57a2013-12-19 22:06:22 +0100595 -c|--clean) shift; clean=1;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000596 -t|--savetemps) shift; SAVETEMPS=1;;
597 -d|--directory) shift; TARGETDIR="$1"; shift;;
598 -p|--platform) shift; TARGETARCH="$1"; shift;;
Nico Huberbb313bf2015-09-08 12:30:27 +0200599 -l|--languages) shift; LANGUAGES="$1"; shift;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000600 -D|--destdir) shift; DESTDIR="$1"; shift;;
Patrick Georgi73166c72010-04-14 20:42:42 +0000601 -j|--jobs) shift; JOBS="-j $1"; shift;;
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700602 -P|--package) shift; PACKAGE="$1"; shift;;
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100603 -S|--scripting) shift; SKIPPYTHON=0;;
Patrick Georgic1a75b12011-11-04 21:37:14 +0100604 -y|--ccache) shift; USECCACHE=1;;
Martin Rothedf965a2015-11-25 16:58:33 -0700605 -s|--supported) shift; PRINTSTABLE="$1"; shift;;
Martin Roth58c68d52016-03-01 15:22:42 -0700606 --urls) shift; printf "%s\n" "$ALL_ARCHIVES"; exit 0;;
Martin Roth4a53db02016-03-01 15:21:07 -0700607 --nocolor) shift; \
608 unset red RED green GREEN blue BLUE cyan CYAN NC;;
Patrick Georgid2e0dd52013-06-09 08:05:45 +0200609 --) shift; break;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000610 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
Patrick Georgid2e0dd52013-06-09 08:05:45 +0200611 *) break;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000612 esac
613done
614
Martin Rothedf965a2015-11-25 16:58:33 -0700615if [ -n "$PRINTSTABLE" ]; then
616 print_stable
617 exit 0
618fi
619
620#print toolchain builder version string as the header
621printversion
622
Ronald G. Minnichb460a662013-05-26 05:33:35 -0700623case "$TARGETARCH" in
Timothy Pearsona9f62352015-12-30 18:59:00 -0600624 x86_64-elf) ;;
625 x86_64*) TARGETARCH=x86_64-elf;;
626 i386-elf) ;;
627 i386-mingw32) ;;
628 mipsel-elf) ;;
629 riscv-elf) ;;
Patrick Georgi0a97d7e2016-01-25 09:51:22 +0100630 powerpc64*-linux*) ;;
Timothy Pearsona9f62352015-12-30 18:59:00 -0600631 i386*) TARGETARCH=i386-elf;;
Stefan Reinauer27522ad2016-01-29 17:31:34 -0800632 arm*) TARGETARCH=arm-eabi;;
Timothy Pearsona9f62352015-12-30 18:59:00 -0600633 aarch64*) TARGETARCH=aarch64-elf;;
Martin Roth3e0f74d2016-03-08 12:07:04 -0700634 nds32le-elf) ;;
Timothy Pearsona9f62352015-12-30 18:59:00 -0600635 *) printf "${red}WARNING: Unsupported architecture $TARGETARCH.${NC}\n\n"; ;;
Ronald G. Minnichb460a662013-05-26 05:33:35 -0700636esac
637
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700638# Figure out which packages to build
Stefan Reinauer699ac272015-06-05 12:43:28 -0700639
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700640case "$PACKAGE" in
641 GCC|gcc)
642 echo "Target architecture is now $TARGETARCH"
643 NAME="${TARGETARCH} cross GCC"
Stefan Reinauerbd8b2e32015-06-17 11:55:02 -0700644 PACKAGES="GMP MPFR MPC LIBELF BINUTILS GCC"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700645 ;;
646 GDB|gdb)
647 NAME="${TARGETARCH} cross GDB"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700648 if [ $SKIPPYTHON -eq 0 ]; then
Ronald G. Minnichfb944f42016-02-27 04:06:42 +0000649 PACKAGES="EXPAT PYTHON GDB"
650 else
651 PACKAGES="EXPAT GDB"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700652 fi
653 ;;
654 CLANG|clang)
655 NAME=clang
656 PACKAGES="LLVM CFE CRT CTE"
David Hendrickscd5cdd32015-06-15 17:03:22 -0700657 CMAKE=$(searchtool cmake "cmake") || exit $?
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700658 ;;
659 IASL|iasl)
660 NAME="IASL ACPI compiler"
661 PACKAGES=IASL
662 ;;
Stefan Reinauera851bbb2016-01-29 18:03:26 -0800663 MAKE|make)
664 NAME="GNU Make"
665 PACKAGES=MAKE
666 ;;
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700667 *)
Stefan Reinauera851bbb2016-01-29 18:03:26 -0800668 printf "${red}ERROR: Unsupported package $PACKAGE. (Supported packages are GCC, GDB, CLANG, IASL, MAKE)${NC}\n\n";
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700669 exit 1
670 ;;
671esac
Peter Stugeceacd772011-06-09 04:54:16 +0200672
Stefan Reinauer66e93352015-06-16 22:38:23 +0200673# Find all the required tools:
674
675TAR=$(searchtool tar) || exit $?
676PATCH=$(searchtool patch) || exit $?
677MAKE=$(searchtool make) || exit $?
678SHA1SUM=$(searchtool sha1sum)
679SHA512SUM=$(searchtool sha512sum)
680CHECKSUM=$SHA1SUM
Martin Roth95f7b222016-03-20 12:38:48 -0600681LBZIP2=$(searchtool lbzip2 "" nofail)
682PIGZ=$(searchtool pigz "" nofail)
Stefan Reinauer66e93352015-06-16 22:38:23 +0200683
684searchtool m4 > /dev/null
685searchtool bison > /dev/null
686searchtool flex flex > /dev/null
687searchtool g++ "Free Software Foundation" nofail > /dev/null || \
Marc Jones5ee69512015-06-17 15:38:17 -0600688searchtool clang "clang version" nofail > /dev/null || \
Martin Rothe3963172016-01-06 13:54:32 -0700689searchtool clang "LLVM" "" "g++" > /dev/null
Stefan Reinauer66e93352015-06-16 22:38:23 +0200690searchtool wget > /dev/null
691searchtool bzip2 "bzip2," > /dev/null
692
Martin Roth88463822016-01-07 11:03:36 -0700693if [ "$HALT_FOR_TOOLS" -ne 0 ]; then
694 exit 1
695fi
696
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700697# This initial cleanup is useful when updating the toolchain script.
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000698
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700699if [ "$clean" = "1" ]; then
700 cleanup
701fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000702
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700703# Set up host compiler and flags needed for various OSes
Stefan Reinauer074d9132009-09-26 16:43:17 +0000704
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700705CC=cc
Patrick Georgif2c15f52015-06-11 21:07:31 +0200706if is_package_enabled "GCC"; then
Stefan Reinauer0d2119d2013-07-10 14:27:56 -0700707if [ $UNAME = "Darwin" ]; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000708 #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix"
709
710 # generally the OS X compiler can create x64 binaries.
711 # Per default it generated i386 binaries in 10.5 and x64
712 # binaries in 10.6 (even if the kernel is 32bit)
713 # For some weird reason, 10.5 autodetects an ABI=64 though
714 # so we're setting the ABI explicitly here.
Stefan Reinauerd7649122015-06-09 11:44:25 -0700715 if [ $(sysctl -n hw.optional.x86_64 2>/dev/null) -eq 1 ] 2>/dev/null; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000716 OPTIONS="ABI=64"
717 else
718 OPTIONS="ABI=32"
719 fi
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700720
Stefan Reinauer4266b922012-12-05 16:18:32 -0800721 # In Xcode 4.5.2 the default compiler is clang.
722 # However, this compiler fails to compile gcc 4.7.x. As a
723 # workaround it's possible to compile gcc with llvm-gcc.
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700724 if $CC -v 2>&1 | grep -q LLVM; then
Stefan Reinauer4266b922012-12-05 16:18:32 -0800725 CC=llvm-gcc
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700726 fi
zbao11f1d312015-08-05 23:15:54 -0400727elif [ $UNAME = "Linux" -o $UNAME = "Cygwin" ]; then
Patrick Georgiddb8f802015-07-04 17:45:54 +0200728 # gmp is overeager with detecting 64bit CPUs even if they run
729 # a 32bit kernel and userland.
730 if [ "$(uname -m 2>/dev/null)" = "i686" ]; then
731 OPTIONS="ABI=32"
732 fi
Nico Huberde45c592016-01-20 23:22:33 +0100733elif [ $UNAME = "NetBSD" ]; then
734 # same for NetBSD but this one reports an i386
735 if [ "$(uname -m 2>/dev/null)" = "i386" ]; then
736 OPTIONS="ABI=32"
737 fi
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000738fi
Stefan Reinauer14ce2132015-06-05 13:01:13 -0700739fi # GCC
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000740
Patrick Georgic1a75b12011-11-04 21:37:14 +0100741if [ "$USECCACHE" = 1 ]; then
742 CC="ccache $CC"
743fi
744
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700745# Prepare target directory for building GCC
746# (dependencies must be in the PATH)
Stefan Reinauer16bd7892012-12-07 23:57:01 +0100747mkdir -p $DESTDIR$TARGETDIR/bin
748export PATH=$DESTDIR$TARGETDIR/bin:$PATH
749
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700750# Download, unpack, patch and build all packages
751
Martin Roth03625172016-02-17 14:44:14 -0700752printf "Downloading tarballs ... \n"
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700753mkdir -p tarballs
754for P in $PACKAGES; do
755 download $P
756done
Martin Roth03625172016-02-17 14:44:14 -0700757printf "Downloaded tarballs ... ${green}ok${NC}\n"
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700758
759printf "Unpacking and patching ... \n"
760for P in $PACKAGES; do
761 unpack_and_patch $P || exit 1
762done
763printf "Unpacked and patched ... ${green}ok${NC}\n"
764
765printf "Building packages ... \n"
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700766for package in $PACKAGES; do
767 build $package
768done
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700769printf "Packages built ... ${green}ok${NC}\n"
Stefan Reinauer14ce2132015-06-05 13:01:13 -0700770
Stefan Reinauer699ac272015-06-05 12:43:28 -0700771# Adding git information of current tree to target directory
772# for reproducibility
Stefan Reinauerd7649122015-06-09 11:44:25 -0700773PROGNAME=$(basename "$0")
Patrick Georgi5602f2c2015-03-28 15:48:47 +0100774rm -f "$DESTDIR$TARGETDIR/$PROGNAME".commit.*
Stefan Reinauerd7649122015-06-09 11:44:25 -0700775cp "$PROGNAME" $DESTDIR$TARGETDIR/"$PROGNAME.commit.$(git describe)"
Zheng Bao30b895f2013-02-06 18:04:40 +0800776
Stefan Reinauer074d9132009-09-26 16:43:17 +0000777if [ $SAVETEMPS -eq 0 ]; then
Stefan Reinauer699ac272015-06-05 12:43:28 -0700778 cleanup
Stefan Reinauer074d9132009-09-26 16:43:17 +0000779else
780 printf "Leaving temporary files around... ${green}ok${NC}\n"
781fi
782
Stefan Reinauer699ac272015-06-05 12:43:28 -0700783printf "\n${green}You can now run your $NAME toolchain from $TARGETDIR.${NC}\n"