blob: 5bfd383ee1e5586645677d8e88f7bfb0a148b12d [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 Roth589ef9d2016-08-11 18:35:06 -060021CROSSGCC_DATE="August 11th, 2016"
22CROSSGCC_VERSION="1.42"
Stefan Reinauer88352d72016-04-06 15:57:03 -070023CROSSGCC_COMMIT=$( git describe )
Stefan Reinauer074d9132009-09-26 16:43:17 +000024
25# default settings
Stefan Reinauer85b07d62015-06-09 14:45:14 -070026PACKAGE=GCC
Stefan Reinauerd7649122015-06-09 11:44:25 -070027TARGETDIR=$(pwd)/xgcc
Stefan Reinauer074d9132009-09-26 16:43:17 +000028TARGETARCH=i386-elf
Nico Huber32c4a062016-01-25 18:30:57 +010029LANGUAGES=c
Stefan Reinauer074d9132009-09-26 16:43:17 +000030DESTDIR=
Stefan Reinauer85b07d62015-06-09 14:45:14 -070031SAVETEMPS=0
32SKIPPYTHON=1
Nico Huber234d2462016-01-26 16:10:17 +010033BOOTSTRAP=0
Stefan Reinauer074d9132009-09-26 16:43:17 +000034
Stefan Reinauer699ac272015-06-05 12:43:28 -070035# GCC toolchain version numbers
Timothy Pearson96310162015-12-28 22:53:29 -060036GMP_VERSION=6.1.0
Iru Caiae8e3a02016-04-02 10:50:59 +080037MPFR_VERSION=3.1.4
Paul Menzele6619422015-02-23 10:33:59 +010038MPC_VERSION=1.0.3
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000039LIBELF_VERSION=0.8.13
Iru Caiae8e3a02016-04-02 10:50:59 +080040GCC_VERSION=5.3.0
Stefan Reinauer0d2119d2013-07-10 14:27:56 -070041GCC_AUTOCONF_VERSION=2.69
Martin Rothbcfa7cc2016-07-14 13:01:37 -060042BINUTILS_VERSION=2.26.1
Stefan Reinauer498f3d02016-04-21 18:10:15 -070043GDB_VERSION=7.11
Martin Roth64b35f32015-12-30 15:10:13 -070044IASL_VERSION=20160318
Stefan Reinauer3dc5d072016-04-21 19:29:03 -070045PYTHON_VERSION=3.5.1
Stefan Reinauer498f3d02016-04-21 18:10:15 -070046EXPAT_VERSION=2.1.1
Stefan Reinauer14ce2132015-06-05 13:01:13 -070047# CLANG version number
Iru Caiae8e3a02016-04-02 10:50:59 +080048CLANG_VERSION=3.8.0
Martin Roth589ef9d2016-08-11 18:35:06 -060049MAKE_VERSION=4.2.1
Stefan Reinauer074d9132009-09-26 16:43:17 +000050
Stefan Reinauer699ac272015-06-05 12:43:28 -070051# GCC toolchain archive locations
Martin Roth1484c032016-03-08 09:37:14 -070052# These are sanitized by the jenkins toolchain test builder, so if
53# a completely new URL is added here, it probably needs to be added
54# to the jenkins build as well, or the builder won't download it.
Stefan Reinauerd9d21022016-04-21 18:16:30 -070055GMP_ARCHIVE="http://ftpmirror.gnu.org/gmp/gmp-${GMP_VERSION}.tar.xz"
56MPFR_ARCHIVE="http://ftpmirror.gnu.org/mpfr/mpfr-${MPFR_VERSION}.tar.xz"
Idwer Vollering7962fc72012-10-25 02:14:09 +020057MPC_ARCHIVE="http://ftpmirror.gnu.org/mpc/mpc-${MPC_VERSION}.tar.gz"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000058LIBELF_ARCHIVE="http://www.mr511.de/software/libelf-${LIBELF_VERSION}.tar.gz"
Idwer Vollering1cfee0b2012-10-25 02:03:53 +020059GCC_ARCHIVE="http://ftpmirror.gnu.org/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.bz2"
Stefan Reinauer0d2119d2013-07-10 14:27:56 -070060BINUTILS_ARCHIVE="http://ftpmirror.gnu.org/binutils/binutils-${BINUTILS_VERSION}.tar.bz2"
Patrick Georgi53c388f2015-03-07 09:55:18 +010061GDB_ARCHIVE="http://ftpmirror.gnu.org/gdb/gdb-${GDB_VERSION}.tar.xz"
Patrick Georgi85bb9462016-02-11 17:22:16 +010062IASL_ARCHIVE="https://acpica.org/sites/acpica/files/acpica-unix2-${IASL_VERSION}.tar.gz"
Patrick Georgi53c388f2015-03-07 09:55:18 +010063PYTHON_ARCHIVE="http://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz"
Stefan Reinauer498f3d02016-04-21 18:10:15 -070064EXPAT_ARCHIVE="http://downloads.sourceforge.net/sourceforge/expat/expat-${EXPAT_VERSION}.tar.bz2"
Stefan Reinauer14ce2132015-06-05 13:01:13 -070065# CLANG toolchain archive locations
66LLVM_ARCHIVE="http://llvm.org/releases/${CLANG_VERSION}/llvm-${CLANG_VERSION}.src.tar.xz"
67CFE_ARCHIVE="http://llvm.org/releases/${CLANG_VERSION}/cfe-${CLANG_VERSION}.src.tar.xz"
68CRT_ARCHIVE="http://llvm.org/releases/${CLANG_VERSION}/compiler-rt-${CLANG_VERSION}.src.tar.xz"
69CTE_ARCHIVE="http://llvm.org/releases/${CLANG_VERSION}/clang-tools-extra-${CLANG_VERSION}.src.tar.xz"
Stefan Reinauera851bbb2016-01-29 18:03:26 -080070MAKE_ARCHIVE="http://ftpmirror.gnu.org/make/make-${MAKE_VERSION}.tar.bz2"
Stefan Reinauer074d9132009-09-26 16:43:17 +000071
Martin Roth58c68d52016-03-01 15:22:42 -070072ALL_ARCHIVES="$GMP_ARCHIVE $MPFR_ARCHIVE $MPC_ARCHIVE $LIBELF_ARCHIVE \
73 $GCC_ARCHIVE $BINUTILS_ARCHIVE $GDB_ARCHIVE $IASL_ARCHIVE \
74 $PYTHON_ARCHIVE $EXPAT_ARCHIVE $LLVM_ARCHIVE $CFE_ARCHIVE \
75 $CRT_ARCHIVE $CTE_ARCHIVE $MAKE_ARCHIVE"
76
Stefan Reinauer699ac272015-06-05 12:43:28 -070077# GCC toolchain directories
Stefan Reinauer074d9132009-09-26 16:43:17 +000078GMP_DIR="gmp-${GMP_VERSION}"
79MPFR_DIR="mpfr-${MPFR_VERSION}"
Stefan Reinauer5f1ad892010-05-17 11:02:25 +000080MPC_DIR="mpc-${MPC_VERSION}"
81LIBELF_DIR="libelf-${LIBELF_VERSION}"
Stefan Reinauer074d9132009-09-26 16:43:17 +000082GCC_DIR="gcc-${GCC_VERSION}"
83BINUTILS_DIR="binutils-${BINUTILS_VERSION}"
84GDB_DIR="gdb-${GDB_VERSION}"
Patrick Georgi85bb9462016-02-11 17:22:16 +010085IASL_DIR="acpica-unix2-${IASL_VERSION}"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +010086PYTHON_DIR="Python-${PYTHON_VERSION}"
87EXPAT_DIR="expat-${EXPAT_VERSION}"
Stefan Reinauer14ce2132015-06-05 13:01:13 -070088# CLANG toolchain directories
89LLVM_DIR="llvm-${CLANG_VERSION}.src"
90CFE_DIR="cfe-${CLANG_VERSION}.src"
91CRT_DIR="compiler-rt-${CLANG_VERSION}.src"
92CTE_DIR="clang-tools-extra-${CLANG_VERSION}.src"
Stefan Reinauera851bbb2016-01-29 18:03:26 -080093MAKE_DIR="make-${MAKE_VERSION}"
Stefan Reinauer074d9132009-09-26 16:43:17 +000094
Patrick Georgi6321f522015-02-27 23:36:26 +010095unset MAKELEVEL MAKEFLAGS
96
Patrick Georgi1861ff72011-10-31 12:15:55 +010097red='\033[0;31m'
98RED='\033[1;31m'
99green='\033[0;32m'
100GREEN='\033[1;32m'
101blue='\033[0;34m'
102BLUE='\033[1;34m'
103cyan='\033[0;36m'
104CYAN='\033[1;36m'
105NC='\033[0m' # No Color
Stefan Reinauer074d9132009-09-26 16:43:17 +0000106
zbaoe05c1ea2015-08-05 23:10:05 -0400107UNAME=$(uname | grep -iq cygwin && echo Cygwin || uname)
Martin Roth88463822016-01-07 11:03:36 -0700108HALT_FOR_TOOLS=0
Stefan Reinauer0d2119d2013-07-10 14:27:56 -0700109
Patrick Georgi198d23c2012-12-08 08:02:44 +0100110normalize_dirs()
111{
112 mkdir -p $DESTDIR$TARGETDIR/lib
113 test -d $DESTDIR$TARGETDIR/lib32 && mv $DESTDIR$TARGETDIR/lib32/* $DESTDIR$TARGETDIR/lib
114 test -d $DESTDIR$TARGETDIR/lib64 && mv $DESTDIR$TARGETDIR/lib64/* $DESTDIR$TARGETDIR/lib
115 rmdir -p $DESTDIR$TARGETDIR/lib32 $DESTDIR$TARGETDIR/lib64
116
117 perl -pi -e "s,/lib32,/lib," $DESTDIR$TARGETDIR/lib/*.la
118 perl -pi -e "s,/lib64,/lib," $DESTDIR$TARGETDIR/lib/*.la
119}
120
Stefan Reinauer93a96302015-06-15 12:36:53 -0700121please_install()
122{
Martin Roth88463822016-01-07 11:03:36 -0700123 HALT_FOR_TOOLS=1
Patrick Georgi5da95dc2015-07-17 23:33:05 +0200124 test -r /etc/os-release && . /etc/os-release
Stefan Reinauer93a96302015-06-15 12:36:53 -0700125 case "$ID_LIKE" in
126 debian) solution="sudo apt-get install $1" ;;
127 suse) solution="sudo zypper install $1" ;;
128 *) solution="using your OS packaging system" ;;
129 esac
130
Martin Roth591790f2016-03-20 20:39:04 -0600131 printf "${RED}ERROR:${red} Missing tool: Please install \'$1\'. (eg $solution)${NC}\n" >&2
Martin Rothe3963172016-01-06 13:54:32 -0700132 if [ -n "$2" ]; then
Martin Roth591790f2016-03-20 20:39:04 -0600133 printf "${RED}ERROR:${red} or install \'$2\'.${NC}\n" >&2
Martin Rothe3963172016-01-06 13:54:32 -0700134 fi
Stefan Reinauer93a96302015-06-15 12:36:53 -0700135}
136
Patrick Georgib7062882015-02-24 10:52:14 +0100137searchtool()
Stefan Reinauer074d9132009-09-26 16:43:17 +0000138{
139 # $1 short name
Patrick Georgib7062882015-02-24 10:52:14 +0100140 # $2 search string
141 # $3 soft fail if set
Martin Rothe3963172016-01-06 13:54:32 -0700142 # $4 alternative package to install on failure
Patrick Georgib7062882015-02-24 10:52:14 +0100143 # result: file name of that tool on stdout
144 # or no output if nothing suitable was found
145 search=GNU
146 if [ -n "$2" ]; then
147 search="$2"
148 fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000149 for i in "$1" "g$1" "gnu$1"; do
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700150 if [ -x "$(which $i 2>/dev/null)" ]; then
151 if [ "$(cat /dev/null | $i --version 2>&1 | grep -c "$search")" \
152 -gt 0 ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000153 echo $i
154 return
155 fi
156 fi
157 done
Andrew Wub67e9a12014-04-28 18:13:44 +0800158 # A workaround for OSX 10.9 and some BSDs, whose nongnu
159 # patch and tar also work.
Patrick Georgi7cb26b42015-04-28 21:29:22 +0200160 if [ $UNAME = "Darwin" -o $UNAME = "FreeBSD" -o $UNAME = "NetBSD" -o $UNAME = "OpenBSD" ]; then
Patrick Georgib7062882015-02-24 10:52:14 +0100161 if [ "$1" = "patch" -o "$1" = "tar" ]; then
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700162 if [ -x "$(which $1 2>/dev/null)" ]; then
Zheng Bao36156ff2012-09-28 16:18:58 +0800163 echo $1
164 return
165 fi
166 fi
167 fi
Stefan Reinauerd7649122015-06-09 11:44:25 -0700168 if [ "$(echo $1 | cut -b -3)" = "sha" ]; then
zbao939dc842015-04-30 04:44:07 +0800169 if [ $UNAME = "FreeBSD" ]; then
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700170 if [ -x "$(which sha1 2>/dev/null)" ]; then
zbao939dc842015-04-30 04:44:07 +0800171 echo sha1
172 return
173 fi
174 fi
175 if [ $UNAME = "NetBSD" ]; then
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700176 if [ -x "$(which cksum 2>/dev/null)" ]; then
Stefan Reinauerd7649122015-06-09 11:44:25 -0700177 echo cksum -a $(echo $1 | sed -e 's,sum,,')
zbao939dc842015-04-30 04:44:07 +0800178 return
179 fi
180 fi
181 if [ $UNAME = "Darwin" ]; then
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700182 if [ -x "$(which openssl 2>/dev/null)" ]; then
Stefan Reinauerd7649122015-06-09 11:44:25 -0700183 echo openssl $(echo $1 | sed -e 's,sum,,')
zbao939dc842015-04-30 04:44:07 +0800184 return
185 fi
186 fi
187 fi
Martin Rothe3963172016-01-06 13:54:32 -0700188
Martin Roth88463822016-01-07 11:03:36 -0700189 [ -z "$3" ] && please_install $1 $4
Patrick Georgib7062882015-02-24 10:52:14 +0100190 false
Stefan Reinauer074d9132009-09-26 16:43:17 +0000191}
192
Martin Roth591790f2016-03-20 20:39:04 -0600193# Run a compile check of the specified library option to see if it's installed
194check_for_library() {
195 local LIBRARY_FLAGS=$1
Aaron Durbin0ac4e5a2016-04-07 16:56:25 -0500196 local LIBRARY_PACKAGES="$2"
Martin Roth591790f2016-03-20 20:39:04 -0600197 local LIBTEST_FILE=.libtest
198
199 echo "int main(int argc, char **argv) { (void) argc; (void) argv; return 0; }" > "${LIBTEST_FILE}.c"
200
201 cc $CFLAGS $LIBRARY_FLAGS "${LIBTEST_FILE}.c" -o "${LIBTEST_FILE}" >/dev/null 2>&1 || \
202 please_install "$LIBRARY_PACKAGES"
203 rm -rf "${LIBTEST_FILE}.c" "${LIBTEST_FILE}"
204}
205
zbao06e85ac2015-08-24 22:08:36 -0400206check_sum() {
207 test -z "$CHECKSUM" || \
208 test "$(cat sum/$1.cksum 2>/dev/null | sed -e 's@.*\([0-9a-f]\{40,\}\).*@\1@')" = \
209 "$($CHECKSUM tarballs/$1 2>/dev/null | sed -e 's@.*\([0-9a-f]\{40,\}\).*@\1@')"
210}
211
212compute_sum() {
213 test ! -f sum/$1.cksum && test -f tarballs/$1 && \
214 (test -z "$CHECKSUM" || $CHECKSUM tarballs/$1 > sum/$1.cksum ) && \
215 printf "(checksum created. ${RED}Note. Please upload sum/$1.cksum if the corresponding archive is upgraded.)${NC}"
216}
217
zbao282dd952015-09-06 05:00:04 -0400218download_showing_percentage() {
219 url=$1
220 printf " ..${red} 0%%"
221 wget --no-check-certificate $url 2>&1 | while read line; do
zbao282dd952015-09-06 05:00:04 -0400222 echo $line | grep -o "[0-9]\+%" | awk '{printf("\b\b\b\b%4s", $1)}'
zbao282dd952015-09-06 05:00:04 -0400223 done
Zheng Baobb003c82016-08-05 13:41:51 +0800224 printf "${NC}"
zbao282dd952015-09-06 05:00:04 -0400225}
226
Stefan Reinauer88935482015-06-05 09:51:10 -0700227download() {
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700228 package=$1
229 archive="$(eval echo \$$package"_ARCHIVE")"
Stefan Reinauer699ac272015-06-05 12:43:28 -0700230
Stefan Reinauerd7649122015-06-09 11:44:25 -0700231 FILE=$(basename $archive)
Stefan Reinauer88935482015-06-05 09:51:10 -0700232 printf " * $FILE "
233
zbaod22b9ea2015-08-30 23:35:16 -0400234 if test -f tarballs/$FILE && check_sum $FILE ; then
235 printf "(cached)"
236 else
Paul Menzelb2ba3952015-06-12 11:58:14 +0200237 printf "(downloading from $archive)"
Stefan Reinauer88935482015-06-05 09:51:10 -0700238 rm -f tarballs/$FILE
239 cd tarballs
zbao282dd952015-09-06 05:00:04 -0400240 download_showing_percentage $archive
Stefan Reinauer88935482015-06-05 09:51:10 -0700241 cd ..
zbao06e85ac2015-08-24 22:08:36 -0400242 compute_sum $FILE
zbaod22b9ea2015-08-30 23:35:16 -0400243 fi
244
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700245 if [ ! -f tarballs/$FILE ]; then
zbao282dd952015-09-06 05:00:04 -0400246 printf "\n${RED}Failed to download $FILE.${NC}\n"
Stefan Reinauerdbc00872015-06-09 11:50:05 -0700247 exit 1
248 fi
Stefan Reinauer88935482015-06-05 09:51:10 -0700249 printf "\n"
250}
251
252unpack_and_patch() {
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700253 package=$1
254 archive="$(eval echo \$$package"_ARCHIVE")"
255 dir="$(eval echo \$$package"_DIR")"
Stefan Reinauer88935482015-06-05 09:51:10 -0700256 test -d ${dir} && test -f ${dir}/.unpack_success || (
Stefan Reinauerd7649122015-06-09 11:44:25 -0700257 printf " * $(basename $archive)\n"
Stefan Reinauer88935482015-06-05 09:51:10 -0700258 FLAGS=zxf
Stefan Reinauerd7649122015-06-09 11:44:25 -0700259 suffix=$(echo $archive | sed 's,.*\.,,')
Martin Roth95f7b222016-03-20 12:38:48 -0600260 if [ "$suffix" = "gz" ] && [ -n "$PIGZ" ]; then FLAGS="-I pigz -xf"
261 elif [ "$suffix" = "gz" ]; then FLAGS=zxf
262 elif [ "$suffix" = "bz2" ] && [ -n "$LBZIP2" ]; then FLAGS="-I lbzip2 -xf"
263 elif [ "$suffix" = "bz2" ]; then FLAGS=jxf
264 elif [ "$suffix" = "xz" ]; then FLAGS="--xz -xf"
265 elif [ "$suffix" = "lzma" ]; then FLAGS="--lzma -xf"
266 fi
Stefan Reinauerd7649122015-06-09 11:44:25 -0700267 $TAR $FLAGS tarballs/$(basename $archive)
Stefan Reinauer88935482015-06-05 09:51:10 -0700268 for patch in patches/${dir}_*.patch; do
269 test -r $patch || continue
Stefan Reinauerd7649122015-06-09 11:44:25 -0700270 printf " o $(basename $patch)\n"
Nico Huber4b48ed82016-07-27 00:28:03 +0200271 (cd ${dir} && $PATCH -s -N -p1 <../${patch}) || {
Stefan Reinauer88935482015-06-05 09:51:10 -0700272 printf "\n${RED}Failed $patch.${NC}\n"
Stefan Reinauer916b8452015-06-09 11:54:49 -0700273 exit 1
274 }
Stefan Reinauer88935482015-06-05 09:51:10 -0700275 done
276 touch ${dir}/.unpack_success
277 )
278}
279
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700280fn_exists()
281{
Patrick Georgic8665912015-06-11 21:04:31 +0200282 type $1 >/dev/null 2>&1
Patrick Georgi74c06422015-03-25 18:40:13 +0100283}
284
Patrick Georgif2c15f52015-06-11 21:07:31 +0200285is_package_enabled()
286{
287 echo "$PACKAGES" |grep -q "\<$1\>"
288}
289
Martin Roth444ece22016-04-01 18:46:29 -0600290package_uses_targetarch()
291{
Stefan Reinauera344b682016-04-21 19:29:51 -0700292 if [ "$1" = "GCC" ] || [ "$1" = "GDB" ] || [ "$1" = "BINUTILS" ]; then
Martin Roth444ece22016-04-01 18:46:29 -0600293 true
294 else
295 false
296 fi
297}
298
Nico Huber11ea2b32016-01-26 16:09:31 +0100299generic_build()
300{
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700301 package=$1
Nico Huber11ea2b32016-01-26 16:09:31 +0100302 host_target=$2
303 builddir=$3
304 success=$4
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700305
306 fn_exists build_$package || return
307
Stefan Reinauer05bbc9202015-06-09 12:21:42 -0700308 version="$(eval echo \$$package"_VERSION")"
Stefan Reinauer05bbc9202015-06-09 12:21:42 -0700309
Nico Huber11ea2b32016-01-26 16:09:31 +0100310 mkdir -p "$builddir"
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700311
Nico Huber11ea2b32016-01-26 16:09:31 +0100312 if [ -f "$success" ]; then
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700313 printf "Skipping $package as it is already built\n"
314 else
315 printf "Building $package $version ... "
Nico Huber11ea2b32016-01-26 16:09:31 +0100316 DIR="$PWD"
317 cd "$builddir"
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700318 rm -f .failed
Nico Huber11ea2b32016-01-26 16:09:31 +0100319 build_${package} $host_target > build.log 2>&1
320 cd "$DIR"
321 if [ ! -f "$builddir/.failed" ]; then
322 touch "$success";
323 else
324 printf "${RED}failed${NC}. Check $builddir/build.log.\n"
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700325 exit 1
326 fi
327 printf "${green}ok${NC}\n"
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700328 fi
329}
330
Nico Huber11ea2b32016-01-26 16:09:31 +0100331build_for_host()
332{
333 generic_build $1 host build-$1 "${TARGETDIR}/.$1.success"
334}
335
336build_for_target()
337{
338 generic_build $1 target build-${TARGETARCH}-$1 "${TARGETDIR}/.${TARGETARCH}-$1.success"
339}
340
341build()
342{
343 if package_uses_targetarch $1; then
Nico Huber234d2462016-01-26 16:10:17 +0100344 if [ $BOOTSTRAP -eq 1 -a ! -f "${TARGETDIR}/.GCC.success" ]; then
345 build_for_host GCC
346 fi
Nico Huber11ea2b32016-01-26 16:09:31 +0100347 build_for_target $1
348 else
349 build_for_host $1
350 fi
351}
352
Zheng Baobb003c82016-08-05 13:41:51 +0800353quit()
354{
355 printf "${NC}Stop\n"
356 exit 1
357}
358
Stefan Reinauer074d9132009-09-26 16:43:17 +0000359cleanup()
360{
Stefan Reinauer88e83e52016-04-06 15:39:48 -0700361 if [ $SAVETEMPS -ne 0 ]; then
362 printf "Leaving temporary files around... ${green}ok${NC}\n"
363 return
364 fi
365
Stefan Reinauer074d9132009-09-26 16:43:17 +0000366 printf "Cleaning up temporary files... "
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700367 for package in $PACKAGES; do
Martin Roth444ece22016-04-01 18:46:29 -0600368 rm -rf build-${TARGETARCH}-$package build-$package $(eval echo \$$package"_DIR")
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700369 done
zbaoff3f15c2015-08-26 22:00:31 -0400370 rm -f getopt
Stefan Reinauer074d9132009-09-26 16:43:17 +0000371 printf "${green}ok${NC}\n"
372}
373
374myhelp()
375{
Stefan Reinauer14ce2132015-06-05 13:01:13 -0700376 printf "Usage: $0 [-V] [-c] [-p <platform>] [-d <target directory>] [-D <dest dir>] [-C] [-G] [-S]\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000377 printf " $0 [-V|--version]\n"
378 printf " $0 [-h|--help]\n\n"
379
380 printf "Options:\n"
381 printf " [-V|--version] print version number and exit\n"
382 printf " [-h|--help] print this help and exit\n"
383 printf " [-c|--clean] remove temporary files before build\n"
384 printf " [-t|--savetemps] don't remove temporary files after build\n"
Patrick Georgic1a75b12011-11-04 21:37:14 +0100385 printf " [-y|--ccache] Use ccache when building cross compiler\n"
Martin Roth4a53db02016-03-01 15:21:07 -0700386 printf " [--nocolor] don't print color codes in output\n"
Martin Roth58c68d52016-03-01 15:22:42 -0700387 printf " [--urls] print the urls for all packages\n"
Patrick Georgi73166c72010-04-14 20:42:42 +0000388 printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n"
Martin Roth588c79d2016-03-20 12:03:20 -0600389 printf " [-s]--supported <tool> print supported version of a tool\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000390 printf " [-d|--directory <target dir>] target directory to install cross compiler to\n"
Martin Roth588c79d2016-03-20 12:03:20 -0600391 printf " (defaults to $TARGETDIR)\n\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000392 printf " [-D|--destdir <dest dir>] destination directory to install cross compiler to\n"
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100393 printf " (for RPM builds, default unset)\n"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700394 printf " [-P|--package <package>] Build a specific package: GCC, CLANG, IASL, GDB\n"
395 printf " (defaults to $PACKAGE)\n"
396 printf "GCC specific options:\n"
Nico Huber234d2462016-01-26 16:10:17 +0100397 printf " [-b|--bootstrap] bootstrap the host compiler before building\n"
398 printf " the cross compiler\n"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700399 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
400 printf " (defaults to $TARGETARCH)\n"
Nico Huberbb313bf2015-09-08 12:30:27 +0200401 printf " [-l|--languages <languages>] comma separated list of target languages\n"
402 printf " (defaults to $LANGUAGES)\n"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700403 printf "GDB specific options:\n"
404 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
405 printf " (defaults to $TARGETARCH)\n"
406 printf " [-S|--scripting] build scripting support for GDB\n\n"
Martin Rothd1da74f2015-06-21 12:06:28 -0600407 printf "Platforms for GCC & GDB:\n"
Martin Roth3e0f74d2016-03-08 12:07:04 -0700408 printf " x86_64 i386-elf i386-mingw32 mipsel-elf riscv-elf arm aarch64\n"
Jonathan Neuschäferf14f6402016-03-11 20:22:23 +0100409 printf " powerpc64le-linux-gnu nds32le-elf\n\n"
Stefan Reinauer074d9132009-09-26 16:43:17 +0000410}
411
Martin Rothedf965a2015-11-25 16:58:33 -0700412printversion() {
413 printf "${blue}Welcome to the ${red}coreboot${blue} cross toolchain builder v$CROSSGCC_VERSION ($CROSSGCC_DATE)${NC}\n\n"
414}
415
Stefan Reinauer074d9132009-09-26 16:43:17 +0000416myversion()
417{
Martin Rothedf965a2015-11-25 16:58:33 -0700418 printversion
Stefan Reinauer074d9132009-09-26 16:43:17 +0000419
420 cat << EOF
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000421Copyright (C) 2008-2010 by coresystems GmbH
Marc Jones2aac3f62011-08-08 16:07:50 -0600422Copyright (C) 2011 by Sage Electronic Engineering
Stefan Reinauer074d9132009-09-26 16:43:17 +0000423
424This program is free software; you can redistribute it and/or modify
425it under the terms of the GNU General Public License as published by
426the Free Software Foundation; version 2 of the License.
427
428This program is distributed in the hope that it will be useful,
429but WITHOUT ANY WARRANTY; without even the implied warranty of
430MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
431GNU General Public License for more details.
432
433EOF
434}
435
Nico Huber5f72f962016-01-31 23:05:19 +0100436have_hostcflags_from_gmp() {
437 grep -q __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h >/dev/null 2>&1
438}
439
440set_hostcflags_from_gmp() {
441 # Now set CFLAGS to match GMP CFLAGS but strip out -pedantic
442 # as GCC 4.6.x fails if it's there.
443 export HOSTCFLAGS=$(grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2 |\
444 sed s,-pedantic,,)
445}
446
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700447build_GMP() {
Paul Kocialkowski7899db22016-06-17 21:41:00 -0700448 CC="$CC" ../${GMP_DIR}/configure --disable-shared --enable-fat \
Nico Huber5f72f962016-01-31 23:05:19 +0100449 --prefix=$TARGETDIR $OPTIONS \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700450 || touch .failed
451 $MAKE $JOBS || touch .failed
452 $MAKE install DESTDIR=$DESTDIR || touch .failed
453
454 normalize_dirs
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700455
Nico Huber5f72f962016-01-31 23:05:19 +0100456 set_hostcflags_from_gmp
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700457}
458
459build_MPFR() {
460 test $UNAME = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
461 CC="$CC" ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
462 --infodir=$TARGETDIR/info \
463 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
464 touch .failed
465 $MAKE $JOBS || touch .failed
466 $MAKE install DESTDIR=$DESTDIR || touch .failed
467
468 normalize_dirs
469
470 # work around build problem of libgmp.la
471 if [ "$DESTDIR" != "" ]; then
472 perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la
473 fi
474}
475
476build_MPC() {
477 CC="$CC" ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \
478 --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \
479 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
480 touch .failed
481 $MAKE $JOBS || touch .failed
482 $MAKE install DESTDIR=$DESTDIR || touch .failed
483
484 normalize_dirs
485}
486
487build_LIBELF() {
488 CC="$CC" CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no \
489 ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \
490 --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed
491 $MAKE $JOBS || touch .failed
492 $MAKE install prefix=$DESTDIR$TARGETDIR || touch .failed
493
494 normalize_dirs
495}
496
497build_BINUTILS() {
Stefan Reinauer682a90c2015-06-09 14:59:58 -0700498 if [ $TARGETARCH == "x86_64-elf" ]; then
499 ADDITIONALTARGET=",i386-elf"
500 fi
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700501 CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \
Stefan Reinauer682a90c2015-06-09 14:59:58 -0700502 --target=${TARGETARCH} --enable-targets=${TARGETARCH}${ADDITIONALTARGET} \
503 --disable-werror --disable-nls --enable-lto --enable-gold \
Stefan Reinauer2fe2d3d2016-04-05 02:14:48 -0700504 --enable-interwork --enable-multilib \
Stefan Reinauer682a90c2015-06-09 14:59:58 -0700505 --enable-plugins --enable-multilibs CFLAGS="$HOSTCFLAGS" || touch .failed
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700506 $MAKE $JOBS || touch .failed
507 $MAKE install DESTDIR=$DESTDIR || touch .failed
508}
509
Nico Huber234d2462016-01-26 16:10:17 +0100510bootstrap_GCC() {
511 CC="$CC" \
512 CFLAGS="$HOSTCFLAGS" \
513 CFLAGS_FOR_BUILD="$HOSTCFLAGS" \
514 CFLAGS_FOR_TARGET="$HOSTCFLAGS -fPIC" \
515 CXXFLAGS="$HOSTCFLAGS" \
516 CXXFLAGS_FOR_BUILD="$HOSTCFLAGS" \
517 CXXFLAGS_FOR_TARGET="$HOSTCFLAGS -fPIC" \
518 ../gcc-${GCC_VERSION}/configure \
519 --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \
520 --enable-bootstrap \
521 --disable-werror --disable-nls \
522 --disable-shared --disable-multilib \
523 --disable-libssp --disable-libquadmath --disable-libcc1 \
524 ${GCC_OPTIONS} --enable-languages="${LANGUAGES}" \
525 --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \
526 --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \
527 --with-pkgversion="coreboot bootstrap v$CROSSGCC_VERSION $CROSSGCC_DATE" \
528 && \
529 $MAKE $JOBS BOOT_CFLAGS="$HOSTCFLAGS" BUILD_CONFIG="" bootstrap && \
530 $MAKE install-gcc \
531 install-target-libgcc \
532 maybe-install-target-libada \
533 maybe-install-target-libstdc++-v3 \
534 DESTDIR=$DESTDIR && \
535 ln -s gcc $DESTDIR$TARGETDIR/bin/cc || touch .failed
536}
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700537
Nico Huber234d2462016-01-26 16:10:17 +0100538build_cross_GCC() {
Stefan Reinauer45f77b82016-04-03 20:52:01 -0700539 # Work around crazy code generator in GCC that confuses CLANG.
Aaron Durbinb2229dc2016-04-07 16:58:10 -0500540 $CC --version | grep clang >/dev/null 2>&1 && \
Stefan Reinauer45f77b82016-04-03 20:52:01 -0700541 HOSTCFLAGS="$HOSTCFLAGS -fbracket-depth=1024"
542
Stefan Reinauerd0f83722015-06-09 11:52:28 -0700543 # GCC does not honor HOSTCFLAGS at all. CFLAGS are used for
544 # both target and host object files.
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700545 # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
546 # but it does not seem to work properly. At least the host library
547 # libiberty is not compiled with CFLAGS_FOR_BUILD.
Stefan Reinauer45f77b82016-04-03 20:52:01 -0700548 # Also set the CXX version of the flags because GCC is now compiled
549 # using C++.
Patrick Georgi0a97d7e2016-01-25 09:51:22 +0100550 CC="$CC" CFLAGS_FOR_TARGET="-O2 -Dinhibit_libc" CFLAGS="$HOSTCFLAGS" \
Stefan Reinauer45f77b82016-04-03 20:52:01 -0700551 CFLAGS_FOR_BUILD="$HOSTCFLAGS" CXXFLAGS="$HOSTCFLAGS" \
552 CXXFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700553 --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \
554 --target=${TARGETARCH} --disable-werror --disable-shared \
Stefan Reinauer2f97ebc2015-06-09 12:24:54 -0700555 --enable-lto --enable-plugins --enable-gold --enable-ld=default \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700556 --disable-libssp --disable-bootstrap --disable-nls \
557 --disable-libquadmath --without-headers \
Patrick Georgi0a97d7e2016-01-25 09:51:22 +0100558 --disable-threads \
Patrick Georgi1fc02d12016-03-23 21:44:43 +0100559 --enable-interwork --enable-multilib --enable-targets=all \
Patrick Georgi0a97d7e2016-01-25 09:51:22 +0100560 --disable-libatomic --disable-libcc1 --disable-decimal-float \
Nico Huberbb313bf2015-09-08 12:30:27 +0200561 ${GCC_OPTIONS} --enable-languages="${LANGUAGES}" \
Ronald G. Minnich7ee16b72016-02-12 21:54:59 +0000562 --with-system-zlib \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700563 --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \
564 --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \
565 --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \
566 || touch .failed
567 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-gcc || touch .failed
568 $MAKE install-gcc DESTDIR=$DESTDIR || touch .failed
569
Stefan Reinauerd7649122015-06-09 11:44:25 -0700570 if [ "$(echo $TARGETARCH | grep -c -- -mingw32)" -eq 0 ]; then
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700571 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-target-libgcc || touch .failed
572 $MAKE install-target-libgcc DESTDIR=$DESTDIR || touch .failed
573 fi
574}
575
Nico Huber234d2462016-01-26 16:10:17 +0100576build_GCC() {
577 if [ "$1" = host ]; then
578 bootstrap_GCC
579 else
580 build_cross_GCC
581 fi
582}
583
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700584build_EXPAT() {
585 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${EXPAT_DIR}/configure --disable-shared \
Stefan Reinauera344b682016-04-21 19:29:51 -0700586 --prefix=$TARGETDIR || touch .failed
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700587 $MAKE || touch .failed
588 $MAKE install DESTDIR=$DESTDIR || touch .failed
589
590 normalize_dirs
591}
592
593build_PYTHON() {
594 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$TARGETDIR \
Stefan Reinauera344b682016-04-21 19:29:51 -0700595 || touch .failed
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700596 $MAKE $JOBS || touch .failed
597 $MAKE install DESTDIR=$DESTDIR || touch .failed
598
599 normalize_dirs
600}
601
602build_GDB() {
603 export PYTHONHOME=$DESTDIR$TARGETDIR
604 if [ $(uname) != "FreeBSD" -a $(uname) != "NetBSD" ]; then
605 LIBDL="-ldl"
606 fi
607 LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \
608 -lpthread $LIBDL -lutil" \
609 CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \
Stefan Reinauer7b40e422015-06-09 11:56:32 -0700610 ../${GDB_DIR}/configure --prefix=$TARGETDIR \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700611 --target=${TARGETARCH} --disable-werror --disable-nls
612 $MAKE $JOBS || touch .failed
613 $MAKE install DESTDIR=$DESTDIR || touch .failed
614}
615
616build_IASL() {
617 RDIR=$PWD
618 cd ../$IASL_DIR/generate/unix
619 CFLAGS="$HOSTCFLAGS"
620 HOST="_LINUX"
621 test $UNAME = "Darwin" && HOST="_APPLE"
622 test $UNAME = "FreeBSD" && HOST="_FreeBSD"
623 test $UNAME = "Cygwin" && HOST="_CYGWIN"
Martin Roth6f656132015-12-08 11:14:10 -0700624 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 -0700625 rm -f $DESTDIR$TARGETDIR/bin/iasl || touch $RDIR/.failed
626 cp bin/iasl $DESTDIR$TARGETDIR/bin || touch $RDIR/.failed
627}
628
629build_LLVM() {
630 cd ..
631 ln -sf $PWD/$CFE_DIR $LLVM_DIR/tools/clang
632 ln -sf $PWD/$CTE_DIR $LLVM_DIR/tools/clang/tools/extra
633 ln -sf $PWD/$CRT_DIR $LLVM_DIR/projects/compiler-rt
634 cd -
635
636 $CMAKE -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=$DESTDIR$TARGETDIR \
Martin Rothfb5647a2015-12-18 09:26:45 -0700637 -DCLANG_VENDOR="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE - " \
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700638 -DCMAKE_BUILD_TYPE=Release ../$LLVM_DIR || touch .failed
639 $MAKE $JOBS || touch .failed
640 $MAKE install || touch .failed
641
642 cp -a ../$CFE_DIR/tools/scan-build/* $DESTDIR$TARGETDIR/bin
643 cp -a ../$CFE_DIR/tools/scan-view/* $DESTDIR$TARGETDIR/bin
Stefan Reinauere9e6e3d2015-07-07 00:20:42 +0200644
645 # create symlinks to work around broken --print-librt-file-name
646 # when used with -target.
647 cd $DESTDIR$TARGETDIR/lib/clang/${CLANG_VERSION}/lib
648 for i in */libclang_rt.builtins*.a; do
649 ln -s $i .
650 done
Stefan Reinauere7757bd2015-06-05 13:59:44 -0700651}
652
Stefan Reinauera851bbb2016-01-29 18:03:26 -0800653build_MAKE() {
654 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${MAKE_DIR}/configure --prefix=$TARGETDIR \
655 --disable-nls || touch .failed
656 $MAKE $JOBS || touch .failed
657 $MAKE install DESTDIR=$DESTDIR || touch .failed
658
659 normalize_dirs
660}
661
Martin Rothedf965a2015-11-25 16:58:33 -0700662print_stable() {
663 case "$PRINTSTABLE" in
664 AUTOCONF|autoconf) printf "%s\n" "$GCC_AUTOCONF_VERSION";;
665 BINUTILS|binutils) printf "%s\n" "$BINUTILS_VERSION";;
666 CLANG|clang) printf "%s\n" "$CLANG_VERSION";;
667 EXPAT|expat) printf "%s\n" "$EXPAT_VERSION";;
668 GCC|gcc) printf "%s\n" "$GCC_VERSION";;
669 GDB|gdb) printf "%s\n" "$GDB_VERSION";;
670 GMP|gmp) printf "%s\n" "$GMP_VERSION";;
671 IASL|iasl) printf "%s\n" "$IASL_VERSION";;
672 LIBELF|libelf) printf "%s\n" "$LIBELF_VERSION";;
673 MPC|mpc) printf "%s\n" "$MPC_VERSION";;
674 MPFR|mpfr) printf "%s\n" "$MPFR_VERSION";;
675 PYTHON|python) printf "%s\n" "$PYTHON_VERSION";;
Stefan Reinauera851bbb2016-01-29 18:03:26 -0800676 MAKE|make) printf "%s\n" "$MAKE_VERSION";;
Martin Rothedf965a2015-11-25 16:58:33 -0700677 *) printf "Unknown tool %s\n" "$PRINTSTABLE";;
678 esac
679}
Stefan Reinauer074d9132009-09-26 16:43:17 +0000680
Zheng Baobb003c82016-08-05 13:41:51 +0800681trap quit 1 2 3 15
682
Patrick Georgi6bba29f2010-01-29 17:40:52 +0000683# Look if we have getopt. If not, build it.
684export PATH=$PATH:.
685getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c
686
Stefan Reinauer074d9132009-09-26 16:43:17 +0000687# parse parameters.. try to find out whether we're running GNU getopt
Stefan Reinauerd7649122015-06-09 11:44:25 -0700688getoptbrand="$(getopt -V | sed -e '1!d' -e 's,^\(......\).*,\1,')"
Peter Stuge09377b72011-08-21 06:24:55 +0200689if [ "${getoptbrand}" = "getopt" ]; then
Stefan Reinauer074d9132009-09-26 16:43:17 +0000690 # Detected GNU getopt that supports long options.
Nico Huber234d2462016-01-26 16:10:17 +0100691 args=$(getopt -l version,help,clean,directory:,bootstrap,platform:,languages:,package:,jobs:,destdir:,savetemps,scripting,ccache,supported: Vhcd:bp:l:P:j:D:tSys: -- "$@")
Stefan Reinauer074d9132009-09-26 16:43:17 +0000692 eval set "$args"
693else
694 # Detected non-GNU getopt
Nico Huber234d2462016-01-26 16:10:17 +0100695 args=$(getopt Vhcd:bp:l:P:j:D:tSys: $*)
Stefan Reinauer074d9132009-09-26 16:43:17 +0000696 set -- $args
697fi
698
699if [ $? != 0 ]; then
700 myhelp
701 exit 1
702fi
703
704while true ; do
705 case "$1" in
706 -V|--version) shift; myversion; exit 0;;
707 -h|--help) shift; myhelp; exit 0;;
Patrick Georgi44af57a2013-12-19 22:06:22 +0100708 -c|--clean) shift; clean=1;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000709 -t|--savetemps) shift; SAVETEMPS=1;;
710 -d|--directory) shift; TARGETDIR="$1"; shift;;
Nico Huber234d2462016-01-26 16:10:17 +0100711 -b|--bootstrap) shift; BOOTSTRAP=1;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000712 -p|--platform) shift; TARGETARCH="$1"; shift;;
Nico Huberbb313bf2015-09-08 12:30:27 +0200713 -l|--languages) shift; LANGUAGES="$1"; shift;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000714 -D|--destdir) shift; DESTDIR="$1"; shift;;
Patrick Georgi73166c72010-04-14 20:42:42 +0000715 -j|--jobs) shift; JOBS="-j $1"; shift;;
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700716 -P|--package) shift; PACKAGE="$1"; shift;;
Stefan Reinauer2c3cd122011-11-01 21:43:50 +0100717 -S|--scripting) shift; SKIPPYTHON=0;;
Patrick Georgic1a75b12011-11-04 21:37:14 +0100718 -y|--ccache) shift; USECCACHE=1;;
Martin Rothedf965a2015-11-25 16:58:33 -0700719 -s|--supported) shift; PRINTSTABLE="$1"; shift;;
Martin Roth58c68d52016-03-01 15:22:42 -0700720 --urls) shift; printf "%s\n" "$ALL_ARCHIVES"; exit 0;;
Martin Roth4a53db02016-03-01 15:21:07 -0700721 --nocolor) shift; \
722 unset red RED green GREEN blue BLUE cyan CYAN NC;;
Patrick Georgid2e0dd52013-06-09 08:05:45 +0200723 --) shift; break;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000724 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
Patrick Georgid2e0dd52013-06-09 08:05:45 +0200725 *) break;;
Stefan Reinauer074d9132009-09-26 16:43:17 +0000726 esac
727done
728
Martin Rothedf965a2015-11-25 16:58:33 -0700729if [ -n "$PRINTSTABLE" ]; then
730 print_stable
731 exit 0
732fi
733
734#print toolchain builder version string as the header
735printversion
736
Ronald G. Minnichb460a662013-05-26 05:33:35 -0700737case "$TARGETARCH" in
Timothy Pearsona9f62352015-12-30 18:59:00 -0600738 x86_64-elf) ;;
739 x86_64*) TARGETARCH=x86_64-elf;;
740 i386-elf) ;;
741 i386-mingw32) ;;
742 mipsel-elf) ;;
Iru Caiae8e3a02016-04-02 10:50:59 +0800743 riscv-elf) TARGETARCH=riscv64-elf;;
Patrick Georgi0a97d7e2016-01-25 09:51:22 +0100744 powerpc64*-linux*) ;;
Timothy Pearsona9f62352015-12-30 18:59:00 -0600745 i386*) TARGETARCH=i386-elf;;
Stefan Reinauer27522ad2016-01-29 17:31:34 -0800746 arm*) TARGETARCH=arm-eabi;;
Timothy Pearsona9f62352015-12-30 18:59:00 -0600747 aarch64*) TARGETARCH=aarch64-elf;;
Martin Roth3e0f74d2016-03-08 12:07:04 -0700748 nds32le-elf) ;;
Timothy Pearsona9f62352015-12-30 18:59:00 -0600749 *) printf "${red}WARNING: Unsupported architecture $TARGETARCH.${NC}\n\n"; ;;
Ronald G. Minnichb460a662013-05-26 05:33:35 -0700750esac
751
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700752# Figure out which packages to build
Stefan Reinauer699ac272015-06-05 12:43:28 -0700753
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700754case "$PACKAGE" in
755 GCC|gcc)
756 echo "Target architecture is now $TARGETARCH"
757 NAME="${TARGETARCH} cross GCC"
Stefan Reinauerbd8b2e32015-06-17 11:55:02 -0700758 PACKAGES="GMP MPFR MPC LIBELF BINUTILS GCC"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700759 ;;
760 GDB|gdb)
761 NAME="${TARGETARCH} cross GDB"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700762 if [ $SKIPPYTHON -eq 0 ]; then
Ronald G. Minnichfb944f42016-02-27 04:06:42 +0000763 PACKAGES="EXPAT PYTHON GDB"
764 else
765 PACKAGES="EXPAT GDB"
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700766 fi
767 ;;
768 CLANG|clang)
769 NAME=clang
770 PACKAGES="LLVM CFE CRT CTE"
David Hendrickscd5cdd32015-06-15 17:03:22 -0700771 CMAKE=$(searchtool cmake "cmake") || exit $?
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700772 ;;
773 IASL|iasl)
774 NAME="IASL ACPI compiler"
775 PACKAGES=IASL
776 ;;
Stefan Reinauera851bbb2016-01-29 18:03:26 -0800777 MAKE|make)
778 NAME="GNU Make"
779 PACKAGES=MAKE
780 ;;
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700781 *)
Stefan Reinauera851bbb2016-01-29 18:03:26 -0800782 printf "${red}ERROR: Unsupported package $PACKAGE. (Supported packages are GCC, GDB, CLANG, IASL, MAKE)${NC}\n\n";
Stefan Reinauer85b07d62015-06-09 14:45:14 -0700783 exit 1
784 ;;
785esac
Peter Stugeceacd772011-06-09 04:54:16 +0200786
Stefan Reinauer66e93352015-06-16 22:38:23 +0200787# Find all the required tools:
788
789TAR=$(searchtool tar) || exit $?
790PATCH=$(searchtool patch) || exit $?
791MAKE=$(searchtool make) || exit $?
792SHA1SUM=$(searchtool sha1sum)
793SHA512SUM=$(searchtool sha512sum)
794CHECKSUM=$SHA1SUM
Martin Roth95f7b222016-03-20 12:38:48 -0600795LBZIP2=$(searchtool lbzip2 "" nofail)
796PIGZ=$(searchtool pigz "" nofail)
Stefan Reinauer66e93352015-06-16 22:38:23 +0200797
798searchtool m4 > /dev/null
799searchtool bison > /dev/null
800searchtool flex flex > /dev/null
801searchtool g++ "Free Software Foundation" nofail > /dev/null || \
Marc Jones5ee69512015-06-17 15:38:17 -0600802searchtool clang "clang version" nofail > /dev/null || \
Martin Rothe3963172016-01-06 13:54:32 -0700803searchtool clang "LLVM" "" "g++" > /dev/null
Stefan Reinauer66e93352015-06-16 22:38:23 +0200804searchtool wget > /dev/null
805searchtool bzip2 "bzip2," > /dev/null
806
Martin Roth591790f2016-03-20 20:39:04 -0600807check_for_library "-lz" "zlib (zlib1g-dev or zlib-devel)"
808
Martin Roth88463822016-01-07 11:03:36 -0700809if [ "$HALT_FOR_TOOLS" -ne 0 ]; then
810 exit 1
811fi
812
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700813# This initial cleanup is useful when updating the toolchain script.
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000814
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700815if [ "$clean" = "1" ]; then
816 cleanup
817fi
Stefan Reinauer074d9132009-09-26 16:43:17 +0000818
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700819# Set up host compiler and flags needed for various OSes
Stefan Reinauer074d9132009-09-26 16:43:17 +0000820
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700821CC=cc
Patrick Georgif2c15f52015-06-11 21:07:31 +0200822if is_package_enabled "GCC"; then
Stefan Reinauer0d2119d2013-07-10 14:27:56 -0700823if [ $UNAME = "Darwin" ]; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000824 #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix"
825
826 # generally the OS X compiler can create x64 binaries.
827 # Per default it generated i386 binaries in 10.5 and x64
828 # binaries in 10.6 (even if the kernel is 32bit)
829 # For some weird reason, 10.5 autodetects an ABI=64 though
830 # so we're setting the ABI explicitly here.
Stefan Reinauerd7649122015-06-09 11:44:25 -0700831 if [ $(sysctl -n hw.optional.x86_64 2>/dev/null) -eq 1 ] 2>/dev/null; then
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000832 OPTIONS="ABI=64"
833 else
834 OPTIONS="ABI=32"
835 fi
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700836
Stefan Reinauer4266b922012-12-05 16:18:32 -0800837 # In Xcode 4.5.2 the default compiler is clang.
838 # However, this compiler fails to compile gcc 4.7.x. As a
839 # workaround it's possible to compile gcc with llvm-gcc.
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700840 if $CC -v 2>&1 | grep -q LLVM; then
Stefan Reinauer4266b922012-12-05 16:18:32 -0800841 CC=llvm-gcc
Stefan Reinauer9491b4d2011-10-11 22:37:59 -0700842 fi
zbao11f1d312015-08-05 23:15:54 -0400843elif [ $UNAME = "Linux" -o $UNAME = "Cygwin" ]; then
Patrick Georgiddb8f802015-07-04 17:45:54 +0200844 # gmp is overeager with detecting 64bit CPUs even if they run
845 # a 32bit kernel and userland.
846 if [ "$(uname -m 2>/dev/null)" = "i686" ]; then
847 OPTIONS="ABI=32"
848 fi
Nico Huberde45c592016-01-20 23:22:33 +0100849elif [ $UNAME = "NetBSD" ]; then
850 # same for NetBSD but this one reports an i386
851 if [ "$(uname -m 2>/dev/null)" = "i386" ]; then
852 OPTIONS="ABI=32"
853 fi
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000854fi
Stefan Reinauer14ce2132015-06-05 13:01:13 -0700855fi # GCC
Stefan Reinauer5f1ad892010-05-17 11:02:25 +0000856
Nico Huber5f72f962016-01-31 23:05:19 +0100857export HOSTCFLAGS="-Os"
858if have_hostcflags_from_gmp; then
859 set_hostcflags_from_gmp
860fi
861
Patrick Georgic1a75b12011-11-04 21:37:14 +0100862if [ "$USECCACHE" = 1 ]; then
863 CC="ccache $CC"
864fi
865
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700866# Prepare target directory for building GCC
867# (dependencies must be in the PATH)
Stefan Reinauer16bd7892012-12-07 23:57:01 +0100868mkdir -p $DESTDIR$TARGETDIR/bin
Stefan Reinauer88352d72016-04-06 15:57:03 -0700869mkdir -p $DESTDIR$TARGETDIR/share
Stefan Reinauer16bd7892012-12-07 23:57:01 +0100870export PATH=$DESTDIR$TARGETDIR/bin:$PATH
871
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700872# Download, unpack, patch and build all packages
873
Martin Roth03625172016-02-17 14:44:14 -0700874printf "Downloading tarballs ... \n"
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700875mkdir -p tarballs
876for P in $PACKAGES; do
877 download $P
878done
Martin Roth03625172016-02-17 14:44:14 -0700879printf "Downloaded tarballs ... ${green}ok${NC}\n"
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700880
881printf "Unpacking and patching ... \n"
882for P in $PACKAGES; do
883 unpack_and_patch $P || exit 1
884done
885printf "Unpacked and patched ... ${green}ok${NC}\n"
886
887printf "Building packages ... \n"
Stefan Reinauer1c70e052015-06-09 11:47:28 -0700888for package in $PACKAGES; do
889 build $package
890done
Stefan Reinauer5dd26352015-06-09 14:52:22 -0700891printf "Packages built ... ${green}ok${NC}\n"
Stefan Reinauer14ce2132015-06-05 13:01:13 -0700892
Stefan Reinauer699ac272015-06-05 12:43:28 -0700893# Adding git information of current tree to target directory
894# for reproducibility
Stefan Reinauerd7649122015-06-09 11:44:25 -0700895PROGNAME=$(basename "$0")
Stefan Reinauer88352d72016-04-06 15:57:03 -0700896rm -f "$DESTDIR$TARGETDIR/share/$PROGNAME-*"
897cp "$PROGNAME" "$DESTDIR$TARGETDIR/share/$PROGNAME-$CROSSGCC_VERSION-$CROSGCC_COMMIT"
Zheng Bao30b895f2013-02-06 18:04:40 +0800898
Stefan Reinauer88e83e52016-04-06 15:39:48 -0700899cleanup
Stefan Reinauer074d9132009-09-26 16:43:17 +0000900
Stefan Reinauer699ac272015-06-05 12:43:28 -0700901printf "\n${green}You can now run your $NAME toolchain from $TARGETDIR.${NC}\n"