blob: 525b574b3b143e40325022f15584739ae379f6f3 [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
Martin Roth591790f2016-03-20 20:39:04 -0600129 printf "${RED}ERROR:${red} Missing tool: Please install \'$1\'. (eg $solution)${NC}\n" >&2
Martin Rothe3963172016-01-06 13:54:32 -0700130 if [ -n "$2" ]; then
Martin Roth591790f2016-03-20 20:39:04 -0600131 printf "${RED}ERROR:${red} or install \'$2\'.${NC}\n" >&2
Martin Rothe3963172016-01-06 13:54:32 -0700132 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
Martin Roth591790f2016-03-20 20:39:04 -0600191# Run a compile check of the specified library option to see if it's installed
192check_for_library() {
193 local LIBRARY_FLAGS=$1
194 local LIBRARY_PACKAGES=$2
195 local LIBTEST_FILE=.libtest
196
197 echo "int main(int argc, char **argv) { (void) argc; (void) argv; return 0; }" > "${LIBTEST_FILE}.c"
198
199 cc $CFLAGS $LIBRARY_FLAGS "${LIBTEST_FILE}.c" -o "${LIBTEST_FILE}" >/dev/null 2>&1 || \
200 please_install "$LIBRARY_PACKAGES"
201 rm -rf "${LIBTEST_FILE}.c" "${LIBTEST_FILE}"
202}
203
zbao06e85ac2015-08-24 22:08:36 -0400204check_sum() {
205 test -z "$CHECKSUM" || \
206 test "$(cat sum/$1.cksum 2>/dev/null | sed -e 's@.*\([0-9a-f]\{40,\}\).*@\1@')" = \
207 "$($CHECKSUM tarballs/$1 2>/dev/null | sed -e 's@.*\([0-9a-f]\{40,\}\).*@\1@')"
208}
209
210compute_sum() {
211 test ! -f sum/$1.cksum && test -f tarballs/$1 && \
212 (test -z "$CHECKSUM" || $CHECKSUM tarballs/$1 > sum/$1.cksum ) && \
213 printf "(checksum created. ${RED}Note. Please upload sum/$1.cksum if the corresponding archive is upgraded.)${NC}"
214}
215
zbao282dd952015-09-06 05:00:04 -0400216download_showing_percentage() {
217 url=$1
218 printf " ..${red} 0%%"
219 wget --no-check-certificate $url 2>&1 | while read line; do
220 printf "${red}"
221 echo $line | grep -o "[0-9]\+%" | awk '{printf("\b\b\b\b%4s", $1)}'
222 printf "${NC}"
223 done
224}
225
Stefan Reinauer88935482015-06-05 09:51:10 -0700226download() {
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700227 package=$1
228 archive="$(eval echo \$$package"_ARCHIVE")"
Stefan Reinauer699ac272015-06-05 12:43:28 -0700229
Stefan Reinauerd7649122015-06-09 11:44:25 -0700230 FILE=$(basename $archive)
Stefan Reinauer88935482015-06-05 09:51:10 -0700231 printf " * $FILE "
232
zbaod22b9ea2015-08-30 23:35:16 -0400233 if test -f tarballs/$FILE && check_sum $FILE ; then
234 printf "(cached)"
235 else
Paul Menzelb2ba3952015-06-12 11:58:14 +0200236 printf "(downloading from $archive)"
Stefan Reinauer88935482015-06-05 09:51:10 -0700237 rm -f tarballs/$FILE
238 cd tarballs
zbao282dd952015-09-06 05:00:04 -0400239 download_showing_percentage $archive
Stefan Reinauer88935482015-06-05 09:51:10 -0700240 cd ..
zbao06e85ac2015-08-24 22:08:36 -0400241 compute_sum $FILE
zbaod22b9ea2015-08-30 23:35:16 -0400242 fi
243
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700244 if [ ! -f tarballs/$FILE ]; then
zbao282dd952015-09-06 05:00:04 -0400245 printf "\n${RED}Failed to download $FILE.${NC}\n"
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700246 exit 1
247 fi
Stefan Reinauer88935482015-06-05 09:51:10 -0700248 printf "\n"
249}
250
251unpack_and_patch() {
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700252 package=$1
253 archive="$(eval echo \$$package"_ARCHIVE")"
254 dir="$(eval echo \$$package"_DIR")"
Stefan Reinauer88935482015-06-05 09:51:10 -0700255 test -d ${dir} && test -f ${dir}/.unpack_success || (
Stefan Reinauerd7649122015-06-09 11:44:25 -0700256 printf " * $(basename $archive)\n"
Stefan Reinauer88935482015-06-05 09:51:10 -0700257 FLAGS=zxf
Stefan Reinauerd7649122015-06-09 11:44:25 -0700258 suffix=$(echo $archive | sed 's,.*\.,,')
Martin Roth95f7b222016-03-20 12:38:48 -0600259 if [ "$suffix" = "gz" ] && [ -n "$PIGZ" ]; then FLAGS="-I pigz -xf"
260 elif [ "$suffix" = "gz" ]; then FLAGS=zxf
261 elif [ "$suffix" = "bz2" ] && [ -n "$LBZIP2" ]; then FLAGS="-I lbzip2 -xf"
262 elif [ "$suffix" = "bz2" ]; then FLAGS=jxf
263 elif [ "$suffix" = "xz" ]; then FLAGS="--xz -xf"
264 elif [ "$suffix" = "lzma" ]; then FLAGS="--lzma -xf"
265 fi
Stefan Reinauerd7649122015-06-09 11:44:25 -0700266 $TAR $FLAGS tarballs/$(basename $archive)
Stefan Reinauer88935482015-06-05 09:51:10 -0700267 for patch in patches/${dir}_*.patch; do
268 test -r $patch || continue
Stefan Reinauerd7649122015-06-09 11:44:25 -0700269 printf " o $(basename $patch)\n"
Stefan Reinauer916b8452015-06-09 11:54:49 -0700270 $PATCH -s -N -p0 < $(echo $patch) || {
Stefan Reinauer88935482015-06-05 09:51:10 -0700271 printf "\n${RED}Failed $patch.${NC}\n"
Stefan Reinauer916b8452015-06-09 11:54:49 -0700272 exit 1
273 }
Stefan Reinauer88935482015-06-05 09:51:10 -0700274 done
275 touch ${dir}/.unpack_success
276 )
277}
278
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700279fn_exists()
280{
Patrick Georgic8665912015-06-11 21:04:31 +0200281 type $1 >/dev/null 2>&1
Patrick Georgi74c06422015-03-25 18:40:13 +0100282}
283
Patrick Georgif2c15f52015-06-11 21:07:31 +0200284is_package_enabled()
285{
286 echo "$PACKAGES" |grep -q "\<$1\>"
287}
288
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700289build() {
290 package=$1
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700291
292 fn_exists build_$package || return
293
Stefan Reinauer05bbc9202015-06-09 12:21:42 -0700294 version="$(eval echo \$$package"_VERSION")"
295 BUILDDIR=build-${TARGETARCH}-$package
296
297 mkdir -p ${BUILDDIR}
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700298
Patrick Georgif2c15f52015-06-11 21:07:31 +0200299 is_package_enabled "$package" && \
Stefan Reinauer05bbc9202015-06-09 12:21:42 -0700300 if [ -f ${BUILDDIR}/.success ]; then
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700301 printf "Skipping $package as it is already built\n"
302 else
303 printf "Building $package $version ... "
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700304 DIR=$PWD
Stefan Reinauer05bbc9202015-06-09 12:21:42 -0700305 cd ${BUILDDIR}
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700306 rm -f .failed
307 build_${package} > build.log 2>&1
Stefan Reinauer05bbc9202015-06-09 12:21:42 -0700308 cd $DIR/${BUILDDIR}
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700309 if [ ! -f .failed ]; then touch .success; fi
310 cd ..
311
Stefan Reinauer05bbc9202015-06-09 12:21:42 -0700312 if [ -r "${BUILDDIR}/.failed" ]; then
313 printf "${RED}failed${NC}. Check ${BUILDDIR}/build.log.\n"
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700314 exit 1
315 fi
316 printf "${green}ok${NC}\n"
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700317 fi
318}
319
Stefan Reinauer074d9132009-09-26 16:43:17 +0000320cleanup()
321{
322 printf "Cleaning up temporary files... "
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700323 for package in $PACKAGES; do
Stefan Reinauer05bbc9202015-06-09 12:21:42 -0700324 rm -rf build-${TARGETARCH}-$package $(eval echo \$$package"_DIR")
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700325 done
zbaoff3f15c2015-08-26 22:00:31 -0400326 rm -f getopt
Stefan Reinauer074d9132009-09-26 16:43:17 +0000327 printf "${green}ok${NC}\n"
328}
329
330myhelp()
331{
Stefan Reinauer14ce2132015-06-05 13:01:13 -0700332 printf "Usage: $0 [-V] [-c] [-p <platform>] [-d <target directory>] [-D <dest dir>] [-C] [-G] [-S]\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000333 printf " $0 [-V|--version]\n"
334 printf " $0 [-h|--help]\n\n"
335
336 printf "Options:\n"
337 printf " [-V|--version] print version number and exit\n"
338 printf " [-h|--help] print this help and exit\n"
339 printf " [-c|--clean] remove temporary files before build\n"
340 printf " [-t|--savetemps] don't remove temporary files after build\n"
Patrick Georgic1a75b12011-11-04 21:37:14 +0100341 printf " [-y|--ccache] Use ccache when building cross compiler\n"
Martin Roth4a53db02016-03-01 15:21:07 -0700342 printf " [--nocolor] don't print color codes in output\n"
Martin Roth58c68d52016-03-01 15:22:42 -0700343 printf " [--urls] print the urls for all packages\n"
Patrick Georgi73166c72010-04-14 20:42:42 +0000344 printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n"
Martin Roth588c79d2016-03-20 12:03:20 -0600345 printf " [-s]--supported <tool> print supported version of a tool\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000346 printf " [-d|--directory <target dir>] target directory to install cross compiler to\n"
Martin Roth588c79d2016-03-20 12:03:20 -0600347 printf " (defaults to $TARGETDIR)\n\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000348 printf " [-D|--destdir <dest dir>] destination directory to install cross compiler to\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100349 printf " (for RPM builds, default unset)\n"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700350 printf " [-P|--package <package>] Build a specific package: GCC, CLANG, IASL, GDB\n"
351 printf " (defaults to $PACKAGE)\n"
352 printf "GCC specific options:\n"
353 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
354 printf " (defaults to $TARGETARCH)\n"
Nico Huberbb313bf2015-09-08 12:30:27 +0200355 printf " [-l|--languages <languages>] comma separated list of target languages\n"
356 printf " (defaults to $LANGUAGES)\n"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700357 printf "GDB specific options:\n"
358 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
359 printf " (defaults to $TARGETARCH)\n"
360 printf " [-S|--scripting] build scripting support for GDB\n\n"
Martin Rothd1da74f2015-06-21 12:06:28 -0600361 printf "Platforms for GCC & GDB:\n"
Martin Roth3e0f74d2016-03-08 12:07:04 -0700362 printf " x86_64 i386-elf i386-mingw32 mipsel-elf riscv-elf arm aarch64\n"
Jonathan Neuschäferf14f6402016-03-11 20:22:23 +0100363 printf " powerpc64le-linux-gnu nds32le-elf\n\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000364}
365
Martin Rothedf965a2015-11-25 16:58:33 -0700366printversion() {
367 printf "${blue}Welcome to the ${red}coreboot${blue} cross toolchain builder v$CROSSGCC_VERSION ($CROSSGCC_DATE)${NC}\n\n"
368}
369
Stefan Reinauer074d9132009-09-26 16:43:17 +0000370myversion()
371{
Martin Rothedf965a2015-11-25 16:58:33 -0700372 printversion
Stefan Reinauer074d9132009-09-26 16:43:17 +0000373
374 cat << EOF
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000375Copyright (C) 2008-2010 by coresystems GmbH
Marc Jones2aac3f62011-08-08 16:07:50 -0600376Copyright (C) 2011 by Sage Electronic Engineering
Stefan Reinauer074d9132009-09-26 16:43:17 +0000377
378This program is free software; you can redistribute it and/or modify
379it under the terms of the GNU General Public License as published by
380the Free Software Foundation; version 2 of the License.
381
382This program is distributed in the hope that it will be useful,
383but WITHOUT ANY WARRANTY; without even the implied warranty of
384MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
385GNU General Public License for more details.
386
387EOF
388}
389
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700390build_GMP() {
391 CC="$CC" CFLAGS="-Os" ../${GMP_DIR}/configure --disable-shared --enable-fat --prefix=$TARGETDIR $OPTIONS \
392 || touch .failed
393 $MAKE $JOBS || touch .failed
394 $MAKE install DESTDIR=$DESTDIR || touch .failed
395
396 normalize_dirs
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700397
398 # Now set CFLAGS to match GMP CFLAGS but strip out -pedantic
399 # as GCC 4.6.x fails if it's there.
400 export HOSTCFLAGS=$(grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2 |\
401 sed s,-pedantic,,)
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700402}
403
404build_MPFR() {
405 test $UNAME = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
406 CC="$CC" ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
407 --infodir=$TARGETDIR/info \
408 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
409 touch .failed
410 $MAKE $JOBS || touch .failed
411 $MAKE install DESTDIR=$DESTDIR || touch .failed
412
413 normalize_dirs
414
415 # work around build problem of libgmp.la
416 if [ "$DESTDIR" != "" ]; then
417 perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la
418 fi
419}
420
421build_MPC() {
422 CC="$CC" ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \
423 --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \
424 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
425 touch .failed
426 $MAKE $JOBS || touch .failed
427 $MAKE install DESTDIR=$DESTDIR || touch .failed
428
429 normalize_dirs
430}
431
432build_LIBELF() {
433 CC="$CC" CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no \
434 ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \
435 --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed
436 $MAKE $JOBS || touch .failed
437 $MAKE install prefix=$DESTDIR$TARGETDIR || touch .failed
438
439 normalize_dirs
440}
441
442build_BINUTILS() {
Stefan Reinauer682a90c2015-06-09 14:59:58 -0700443 if [ $TARGETARCH == "x86_64-elf" ]; then
444 ADDITIONALTARGET=",i386-elf"
445 fi
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700446 CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \
Stefan Reinauer682a90c2015-06-09 14:59:58 -0700447 --target=${TARGETARCH} --enable-targets=${TARGETARCH}${ADDITIONALTARGET} \
448 --disable-werror --disable-nls --enable-lto --enable-gold \
449 --enable-plugins --enable-multilibs CFLAGS="$HOSTCFLAGS" || touch .failed
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700450 $MAKE $JOBS || touch .failed
451 $MAKE install DESTDIR=$DESTDIR || touch .failed
452}
453
454
455build_GCC() {
Stefan Reinauerd0f83722015-06-09 11:52:28 -0700456 # GCC does not honor HOSTCFLAGS at all. CFLAGS are used for
457 # both target and host object files.
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700458 # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
459 # but it does not seem to work properly. At least the host library
460 # libiberty is not compiled with CFLAGS_FOR_BUILD.
Patrick Georgi0a97d7e2016-01-25 09:51:22 +0100461 CC="$CC" CFLAGS_FOR_TARGET="-O2 -Dinhibit_libc" CFLAGS="$HOSTCFLAGS" \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700462 CFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \
463 --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \
464 --target=${TARGETARCH} --disable-werror --disable-shared \
Stefan Reinauer2f97ebc2015-06-09 12:24:54 -0700465 --enable-lto --enable-plugins --enable-gold --enable-ld=default \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700466 --disable-libssp --disable-bootstrap --disable-nls \
467 --disable-libquadmath --without-headers \
Patrick Georgi0a97d7e2016-01-25 09:51:22 +0100468 --disable-threads \
Patrick Georgi1fc02d12016-03-23 21:44:43 +0100469 --enable-interwork --enable-multilib --enable-targets=all \
Patrick Georgi0a97d7e2016-01-25 09:51:22 +0100470 --disable-libatomic --disable-libcc1 --disable-decimal-float \
Nico Huberbb313bf2015-09-08 12:30:27 +0200471 ${GCC_OPTIONS} --enable-languages="${LANGUAGES}" \
Ronald G. Minnich7ee16b72016-02-12 21:54:59 +0000472 --with-system-zlib \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700473 --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \
474 --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \
475 --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \
476 || touch .failed
477 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-gcc || touch .failed
478 $MAKE install-gcc DESTDIR=$DESTDIR || touch .failed
479
Stefan Reinauerd7649122015-06-09 11:44:25 -0700480 if [ "$(echo $TARGETARCH | grep -c -- -mingw32)" -eq 0 ]; then
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700481 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-target-libgcc || touch .failed
482 $MAKE install-target-libgcc DESTDIR=$DESTDIR || touch .failed
483 fi
484}
485
486build_EXPAT() {
487 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${EXPAT_DIR}/configure --disable-shared \
488 --prefix=$TARGETDIR --target=${TARGETARCH} || touch .failed
489 $MAKE || touch .failed
490 $MAKE install DESTDIR=$DESTDIR || touch .failed
491
492 normalize_dirs
493}
494
495build_PYTHON() {
496 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$TARGETDIR \
497 --target=${TARGETARCH} || touch .failed
498 $MAKE $JOBS || touch .failed
499 $MAKE install DESTDIR=$DESTDIR || touch .failed
500
501 normalize_dirs
502}
503
504build_GDB() {
505 export PYTHONHOME=$DESTDIR$TARGETDIR
506 if [ $(uname) != "FreeBSD" -a $(uname) != "NetBSD" ]; then
507 LIBDL="-ldl"
508 fi
509 LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \
510 -lpthread $LIBDL -lutil" \
511 CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \
Stefan Reinauer7b40e422015-06-09 11:56:32 -0700512 ../${GDB_DIR}/configure --prefix=$TARGETDIR \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700513 --target=${TARGETARCH} --disable-werror --disable-nls
514 $MAKE $JOBS || touch .failed
515 $MAKE install DESTDIR=$DESTDIR || touch .failed
516}
517
518build_IASL() {
519 RDIR=$PWD
520 cd ../$IASL_DIR/generate/unix
521 CFLAGS="$HOSTCFLAGS"
522 HOST="_LINUX"
523 test $UNAME = "Darwin" && HOST="_APPLE"
524 test $UNAME = "FreeBSD" && HOST="_FreeBSD"
525 test $UNAME = "Cygwin" && HOST="_CYGWIN"
Martin Roth6f656132015-12-08 11:14:10 -0700526 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 -0700527 rm -f $DESTDIR$TARGETDIR/bin/iasl || touch $RDIR/.failed
528 cp bin/iasl $DESTDIR$TARGETDIR/bin || touch $RDIR/.failed
529}
530
531build_LLVM() {
532 cd ..
533 ln -sf $PWD/$CFE_DIR $LLVM_DIR/tools/clang
534 ln -sf $PWD/$CTE_DIR $LLVM_DIR/tools/clang/tools/extra
535 ln -sf $PWD/$CRT_DIR $LLVM_DIR/projects/compiler-rt
536 cd -
537
538 $CMAKE -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=$DESTDIR$TARGETDIR \
Martin Rothfb5647a2015-12-18 09:26:45 -0700539 -DCLANG_VENDOR="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE - " \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700540 -DCMAKE_BUILD_TYPE=Release ../$LLVM_DIR || touch .failed
541 $MAKE $JOBS || touch .failed
542 $MAKE install || touch .failed
543
544 cp -a ../$CFE_DIR/tools/scan-build/* $DESTDIR$TARGETDIR/bin
545 cp -a ../$CFE_DIR/tools/scan-view/* $DESTDIR$TARGETDIR/bin
Stefan Reinauere9e6e3d2015-07-07 00:20:42 +0200546
547 # create symlinks to work around broken --print-librt-file-name
548 # when used with -target.
549 cd $DESTDIR$TARGETDIR/lib/clang/${CLANG_VERSION}/lib
550 for i in */libclang_rt.builtins*.a; do
551 ln -s $i .
552 done
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700553}
554
Stefan Reinauera851bbb2016-01-29 18:03:26 -0800555build_MAKE() {
556 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${MAKE_DIR}/configure --prefix=$TARGETDIR \
557 --disable-nls || touch .failed
558 $MAKE $JOBS || touch .failed
559 $MAKE install DESTDIR=$DESTDIR || touch .failed
560
561 normalize_dirs
562}
563
Martin Rothedf965a2015-11-25 16:58:33 -0700564print_stable() {
565 case "$PRINTSTABLE" in
566 AUTOCONF|autoconf) printf "%s\n" "$GCC_AUTOCONF_VERSION";;
567 BINUTILS|binutils) printf "%s\n" "$BINUTILS_VERSION";;
568 CLANG|clang) printf "%s\n" "$CLANG_VERSION";;
569 EXPAT|expat) printf "%s\n" "$EXPAT_VERSION";;
570 GCC|gcc) printf "%s\n" "$GCC_VERSION";;
571 GDB|gdb) printf "%s\n" "$GDB_VERSION";;
572 GMP|gmp) printf "%s\n" "$GMP_VERSION";;
573 IASL|iasl) printf "%s\n" "$IASL_VERSION";;
574 LIBELF|libelf) printf "%s\n" "$LIBELF_VERSION";;
575 MPC|mpc) printf "%s\n" "$MPC_VERSION";;
576 MPFR|mpfr) printf "%s\n" "$MPFR_VERSION";;
577 PYTHON|python) printf "%s\n" "$PYTHON_VERSION";;
Stefan Reinauera851bbb2016-01-29 18:03:26 -0800578 MAKE|make) printf "%s\n" "$MAKE_VERSION";;
Martin Rothedf965a2015-11-25 16:58:33 -0700579 *) printf "Unknown tool %s\n" "$PRINTSTABLE";;
580 esac
581}
Stefan Reinauer074d9132009-09-26 16:43:17 +0000582
Patrick Georgi6bba29f2010-01-29 17:40:52 +0000583# Look if we have getopt. If not, build it.
584export PATH=$PATH:.
585getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c
586
Stefan Reinauer074d9132009-09-26 16:43:17 +0000587# parse parameters.. try to find out whether we're running GNU getopt
Stefan Reinauerd7649122015-06-09 11:44:25 -0700588getoptbrand="$(getopt -V | sed -e '1!d' -e 's,^\(......\).*,\1,')"
Peter Stuge09377b72011-08-21 06:24:55 +0200589if [ "${getoptbrand}" = "getopt" ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000590 # Detected GNU getopt that supports long options.
Martin Rothedf965a2015-11-25 16:58:33 -0700591 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 +0000592 eval set "$args"
593else
594 # Detected non-GNU getopt
Martin Rothedf965a2015-11-25 16:58:33 -0700595 args=$(getopt Vhcd:p:l:P:j:D:tSys: $*)
Stefan Reinauer074d9132009-09-26 16:43:17 +0000596 set -- $args
597fi
598
599if [ $? != 0 ]; then
600 myhelp
601 exit 1
602fi
603
604while true ; do
605 case "$1" in
606 -V|--version) shift; myversion; exit 0;;
607 -h|--help) shift; myhelp; exit 0;;
Patrick Georgi44af57a2013-12-19 22:06:22 +0100608 -c|--clean) shift; clean=1;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000609 -t|--savetemps) shift; SAVETEMPS=1;;
610 -d|--directory) shift; TARGETDIR="$1"; shift;;
611 -p|--platform) shift; TARGETARCH="$1"; shift;;
Nico Huberbb313bf2015-09-08 12:30:27 +0200612 -l|--languages) shift; LANGUAGES="$1"; shift;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000613 -D|--destdir) shift; DESTDIR="$1"; shift;;
Patrick Georgi73166c72010-04-14 20:42:42 +0000614 -j|--jobs) shift; JOBS="-j $1"; shift;;
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700615 -P|--package) shift; PACKAGE="$1"; shift;;
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100616 -S|--scripting) shift; SKIPPYTHON=0;;
Patrick Georgic1a75b12011-11-04 21:37:14 +0100617 -y|--ccache) shift; USECCACHE=1;;
Martin Rothedf965a2015-11-25 16:58:33 -0700618 -s|--supported) shift; PRINTSTABLE="$1"; shift;;
Martin Roth58c68d52016-03-01 15:22:42 -0700619 --urls) shift; printf "%s\n" "$ALL_ARCHIVES"; exit 0;;
Martin Roth4a53db02016-03-01 15:21:07 -0700620 --nocolor) shift; \
621 unset red RED green GREEN blue BLUE cyan CYAN NC;;
Patrick Georgid2e0dd52013-06-09 08:05:45 +0200622 --) shift; break;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000623 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
Patrick Georgid2e0dd52013-06-09 08:05:45 +0200624 *) break;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000625 esac
626done
627
Martin Rothedf965a2015-11-25 16:58:33 -0700628if [ -n "$PRINTSTABLE" ]; then
629 print_stable
630 exit 0
631fi
632
633#print toolchain builder version string as the header
634printversion
635
Ronald G. Minnichb460a662013-05-26 05:33:35 -0700636case "$TARGETARCH" in
Timothy Pearsona9f62352015-12-30 18:59:00 -0600637 x86_64-elf) ;;
638 x86_64*) TARGETARCH=x86_64-elf;;
639 i386-elf) ;;
640 i386-mingw32) ;;
641 mipsel-elf) ;;
642 riscv-elf) ;;
Patrick Georgi0a97d7e2016-01-25 09:51:22 +0100643 powerpc64*-linux*) ;;
Timothy Pearsona9f62352015-12-30 18:59:00 -0600644 i386*) TARGETARCH=i386-elf;;
Stefan Reinauer27522ad2016-01-29 17:31:34 -0800645 arm*) TARGETARCH=arm-eabi;;
Timothy Pearsona9f62352015-12-30 18:59:00 -0600646 aarch64*) TARGETARCH=aarch64-elf;;
Martin Roth3e0f74d2016-03-08 12:07:04 -0700647 nds32le-elf) ;;
Timothy Pearsona9f62352015-12-30 18:59:00 -0600648 *) printf "${red}WARNING: Unsupported architecture $TARGETARCH.${NC}\n\n"; ;;
Ronald G. Minnichb460a662013-05-26 05:33:35 -0700649esac
650
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700651# Figure out which packages to build
Stefan Reinauer699ac272015-06-05 12:43:28 -0700652
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700653case "$PACKAGE" in
654 GCC|gcc)
655 echo "Target architecture is now $TARGETARCH"
656 NAME="${TARGETARCH} cross GCC"
Stefan Reinauerbd8b2e32015-06-17 11:55:02 -0700657 PACKAGES="GMP MPFR MPC LIBELF BINUTILS GCC"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700658 ;;
659 GDB|gdb)
660 NAME="${TARGETARCH} cross GDB"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700661 if [ $SKIPPYTHON -eq 0 ]; then
Ronald G. Minnichfb944f42016-02-27 04:06:42 +0000662 PACKAGES="EXPAT PYTHON GDB"
663 else
664 PACKAGES="EXPAT GDB"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700665 fi
666 ;;
667 CLANG|clang)
668 NAME=clang
669 PACKAGES="LLVM CFE CRT CTE"
David Hendrickscd5cdd32015-06-15 17:03:22 -0700670 CMAKE=$(searchtool cmake "cmake") || exit $?
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700671 ;;
672 IASL|iasl)
673 NAME="IASL ACPI compiler"
674 PACKAGES=IASL
675 ;;
Stefan Reinauera851bbb2016-01-29 18:03:26 -0800676 MAKE|make)
677 NAME="GNU Make"
678 PACKAGES=MAKE
679 ;;
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700680 *)
Stefan Reinauera851bbb2016-01-29 18:03:26 -0800681 printf "${red}ERROR: Unsupported package $PACKAGE. (Supported packages are GCC, GDB, CLANG, IASL, MAKE)${NC}\n\n";
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700682 exit 1
683 ;;
684esac
Peter Stugeceacd772011-06-09 04:54:16 +0200685
Stefan Reinauer66e93352015-06-16 22:38:23 +0200686# Find all the required tools:
687
688TAR=$(searchtool tar) || exit $?
689PATCH=$(searchtool patch) || exit $?
690MAKE=$(searchtool make) || exit $?
691SHA1SUM=$(searchtool sha1sum)
692SHA512SUM=$(searchtool sha512sum)
693CHECKSUM=$SHA1SUM
Martin Roth95f7b222016-03-20 12:38:48 -0600694LBZIP2=$(searchtool lbzip2 "" nofail)
695PIGZ=$(searchtool pigz "" nofail)
Stefan Reinauer66e93352015-06-16 22:38:23 +0200696
697searchtool m4 > /dev/null
698searchtool bison > /dev/null
699searchtool flex flex > /dev/null
700searchtool g++ "Free Software Foundation" nofail > /dev/null || \
Marc Jones5ee69512015-06-17 15:38:17 -0600701searchtool clang "clang version" nofail > /dev/null || \
Martin Rothe3963172016-01-06 13:54:32 -0700702searchtool clang "LLVM" "" "g++" > /dev/null
Stefan Reinauer66e93352015-06-16 22:38:23 +0200703searchtool wget > /dev/null
704searchtool bzip2 "bzip2," > /dev/null
705
Martin Roth591790f2016-03-20 20:39:04 -0600706check_for_library "-lz" "zlib (zlib1g-dev or zlib-devel)"
707
Martin Roth88463822016-01-07 11:03:36 -0700708if [ "$HALT_FOR_TOOLS" -ne 0 ]; then
709 exit 1
710fi
711
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700712# This initial cleanup is useful when updating the toolchain script.
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000713
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700714if [ "$clean" = "1" ]; then
715 cleanup
716fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000717
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700718# Set up host compiler and flags needed for various OSes
Stefan Reinauer074d9132009-09-26 16:43:17 +0000719
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700720CC=cc
Patrick Georgif2c15f52015-06-11 21:07:31 +0200721if is_package_enabled "GCC"; then
Stefan Reinauer0d2119d2013-07-10 14:27:56 -0700722if [ $UNAME = "Darwin" ]; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000723 #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix"
724
725 # generally the OS X compiler can create x64 binaries.
726 # Per default it generated i386 binaries in 10.5 and x64
727 # binaries in 10.6 (even if the kernel is 32bit)
728 # For some weird reason, 10.5 autodetects an ABI=64 though
729 # so we're setting the ABI explicitly here.
Stefan Reinauerd7649122015-06-09 11:44:25 -0700730 if [ $(sysctl -n hw.optional.x86_64 2>/dev/null) -eq 1 ] 2>/dev/null; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000731 OPTIONS="ABI=64"
732 else
733 OPTIONS="ABI=32"
734 fi
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700735
Stefan Reinauer4266b922012-12-05 16:18:32 -0800736 # In Xcode 4.5.2 the default compiler is clang.
737 # However, this compiler fails to compile gcc 4.7.x. As a
738 # workaround it's possible to compile gcc with llvm-gcc.
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700739 if $CC -v 2>&1 | grep -q LLVM; then
Stefan Reinauer4266b922012-12-05 16:18:32 -0800740 CC=llvm-gcc
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700741 fi
zbao11f1d312015-08-05 23:15:54 -0400742elif [ $UNAME = "Linux" -o $UNAME = "Cygwin" ]; then
Patrick Georgiddb8f802015-07-04 17:45:54 +0200743 # gmp is overeager with detecting 64bit CPUs even if they run
744 # a 32bit kernel and userland.
745 if [ "$(uname -m 2>/dev/null)" = "i686" ]; then
746 OPTIONS="ABI=32"
747 fi
Nico Huberde45c592016-01-20 23:22:33 +0100748elif [ $UNAME = "NetBSD" ]; then
749 # same for NetBSD but this one reports an i386
750 if [ "$(uname -m 2>/dev/null)" = "i386" ]; then
751 OPTIONS="ABI=32"
752 fi
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000753fi
Stefan Reinauer14ce2132015-06-05 13:01:13 -0700754fi # GCC
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000755
Patrick Georgic1a75b12011-11-04 21:37:14 +0100756if [ "$USECCACHE" = 1 ]; then
757 CC="ccache $CC"
758fi
759
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700760# Prepare target directory for building GCC
761# (dependencies must be in the PATH)
Stefan Reinauer16bd7892012-12-07 23:57:01 +0100762mkdir -p $DESTDIR$TARGETDIR/bin
763export PATH=$DESTDIR$TARGETDIR/bin:$PATH
764
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700765# Download, unpack, patch and build all packages
766
Martin Roth03625172016-02-17 14:44:14 -0700767printf "Downloading tarballs ... \n"
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700768mkdir -p tarballs
769for P in $PACKAGES; do
770 download $P
771done
Martin Roth03625172016-02-17 14:44:14 -0700772printf "Downloaded tarballs ... ${green}ok${NC}\n"
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700773
774printf "Unpacking and patching ... \n"
775for P in $PACKAGES; do
776 unpack_and_patch $P || exit 1
777done
778printf "Unpacked and patched ... ${green}ok${NC}\n"
779
780printf "Building packages ... \n"
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700781for package in $PACKAGES; do
782 build $package
783done
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700784printf "Packages built ... ${green}ok${NC}\n"
Stefan Reinauer14ce2132015-06-05 13:01:13 -0700785
Stefan Reinauer699ac272015-06-05 12:43:28 -0700786# Adding git information of current tree to target directory
787# for reproducibility
Stefan Reinauerd7649122015-06-09 11:44:25 -0700788PROGNAME=$(basename "$0")
Patrick Georgi5602f2c2015-03-28 15:48:47 +0100789rm -f "$DESTDIR$TARGETDIR/$PROGNAME".commit.*
Stefan Reinauerd7649122015-06-09 11:44:25 -0700790cp "$PROGNAME" $DESTDIR$TARGETDIR/"$PROGNAME.commit.$(git describe)"
Zheng Bao30b895f2013-02-06 18:04:40 +0800791
Stefan Reinauer074d9132009-09-26 16:43:17 +0000792if [ $SAVETEMPS -eq 0 ]; then
Stefan Reinauer699ac272015-06-05 12:43:28 -0700793 cleanup
Stefan Reinauer074d9132009-09-26 16:43:17 +0000794else
795 printf "Leaving temporary files around... ${green}ok${NC}\n"
796fi
797
Stefan Reinauer699ac272015-06-05 12:43:28 -0700798printf "\n${green}You can now run your $NAME toolchain from $TARGETDIR.${NC}\n"