Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 3 | # Copyright (C) 2008-2010 by coresystems GmbH |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 4 | # written by Patrick Georgi <patrick.georgi@coresystems.de> and |
| 5 | # Stefan Reinauer <stefan.reinauer@coresystems.de> |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 6 | # |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 7 | # This program is free software; you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by |
| 9 | # the Free Software Foundation; version 2 of the License. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU General Public License |
| 17 | # along with this program; if not, write to the Free Software |
| 18 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
| 19 | # |
| 20 | |
Stefan Reinauer | 5411e71 | 2010-12-17 02:32:42 +0000 | [diff] [blame] | 21 | CROSSGCC_DATE="December 16th, 2010" |
| 22 | CROSSGCC_VERSION="1.03" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 23 | |
| 24 | # default settings |
| 25 | TARGETDIR=`pwd`/xgcc |
| 26 | TARGETARCH=i386-elf |
| 27 | DESTDIR= |
| 28 | |
| 29 | # version numbers |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 30 | GMP_VERSION=5.0.1 |
Marc Jones | 3693266 | 2010-12-03 00:45:56 +0000 | [diff] [blame] | 31 | MPFR_VERSION=3.0.0 |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 32 | MPC_VERSION=0.8.2 |
| 33 | LIBELF_VERSION=0.8.13 |
Stefan Reinauer | 5411e71 | 2010-12-17 02:32:42 +0000 | [diff] [blame] | 34 | GCC_VERSION=4.5.2 |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 35 | BINUTILS_VERSION=2.20.1 |
Marc Jones | 3693266 | 2010-12-03 00:45:56 +0000 | [diff] [blame] | 36 | GDB_VERSION=7.2 |
| 37 | W32API_VERSION=3.15 |
Patrick Georgi | 73166c7 | 2010-04-14 20:42:42 +0000 | [diff] [blame] | 38 | MINGWRT_VERSION=3.18 |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 39 | |
| 40 | # archive locations |
| 41 | GMP_ARCHIVE="ftp://ftp.gmplib.org/pub/gmp-${GMP_VERSION}/gmp-${GMP_VERSION}.tar.bz2" |
Peter Stuge | 85e6870 | 2009-12-13 13:39:01 +0000 | [diff] [blame] | 42 | MPFR_ARCHIVE="http://www.mpfr.org/mpfr-${MPFR_VERSION}/mpfr-${MPFR_VERSION}.tar.bz2" |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 43 | MPC_ARCHIVE="http://www.multiprecision.org/mpc/download/mpc-${MPC_VERSION}.tar.gz" |
| 44 | LIBELF_ARCHIVE="http://www.mr511.de/software/libelf-${LIBELF_VERSION}.tar.gz" |
Stefan Reinauer | 5411e71 | 2010-12-17 02:32:42 +0000 | [diff] [blame] | 45 | GCC_ARCHIVE="ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-${GCC_VERSION}/gcc-core-${GCC_VERSION}.tar.bz2" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 46 | BINUTILS_ARCHIVE="http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.bz2" |
| 47 | GDB_ARCHIVE="http://ftp.gnu.org/gnu/gdb/gdb-${GDB_VERSION}.tar.bz2" |
Marc Jones | 3693266 | 2010-12-03 00:45:56 +0000 | [diff] [blame] | 48 | W32API_ARCHIVE="http://downloads.sourceforge.net/project/mingw/MinGW/BaseSystem/RuntimeLibrary/Win32-API/w32api-${W32API_VERSION}/w32api-${W32API_VERSION}-mingw32-src.tar.gz" |
| 49 | MINGWRT_ARCHIVE="http://downloads.sourceforge.net/project/mingw/MinGW/BaseSystem/RuntimeLibrary/MinGW-RT/mingwrt-${MINGWRT_VERSION}/mingwrt-${MINGWRT_VERSION}-mingw32-src.tar.gz" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 50 | |
| 51 | GMP_DIR="gmp-${GMP_VERSION}" |
| 52 | MPFR_DIR="mpfr-${MPFR_VERSION}" |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 53 | MPC_DIR="mpc-${MPC_VERSION}" |
| 54 | LIBELF_DIR="libelf-${LIBELF_VERSION}" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 55 | GCC_DIR="gcc-${GCC_VERSION}" |
| 56 | BINUTILS_DIR="binutils-${BINUTILS_VERSION}" |
| 57 | GDB_DIR="gdb-${GDB_VERSION}" |
Stefan Reinauer | 6ade161 | 2010-01-16 16:44:20 +0000 | [diff] [blame] | 58 | W32API_DIR="w32api-${W32API_VERSION}-mingw32" |
| 59 | MINGWRT_DIR="mingwrt-${MINGWRT_VERSION}-mingw32" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 60 | |
| 61 | SAVETEMPS=0 |
Peter Stuge | ceacd77 | 2011-06-09 04:54:16 +0200 | [diff] [blame] | 62 | SKIPGDB=0 |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 63 | |
| 64 | red='\e[0;31m' |
| 65 | RED='\e[1;31m' |
| 66 | green='\e[0;32m' |
| 67 | GREEN='\e[1;32m' |
| 68 | blue='\e[0;34m' |
| 69 | BLUE='\e[1;34m' |
| 70 | cyan='\e[0;36m' |
| 71 | CYAN='\e[1;36m' |
| 72 | NC='\e[0m' # No Color |
| 73 | |
| 74 | searchgnu() |
| 75 | { |
| 76 | # $1 short name |
| 77 | # result: GNU version of that tool on stdout |
| 78 | # or no output if no GNU version was found |
| 79 | for i in "$1" "g$1" "gnu$1"; do |
| 80 | if test -x "`which $i 2>/dev/null`"; then |
| 81 | if test `$i --version 2>/dev/null |grep -c GNU` -gt 0; then |
| 82 | echo $i |
| 83 | return |
| 84 | fi |
| 85 | fi |
| 86 | done |
| 87 | printf "${RED}ERROR:${red} Missing toolchain: $1${NC}\n" >&2 |
| 88 | exit 1 |
| 89 | } |
| 90 | |
Patrick Georgi | 68df804 | 2011-07-17 11:36:10 +0200 | [diff] [blame^] | 91 | TAR=`searchgnu tar` || exit $? |
| 92 | PATCH=`searchgnu patch` || exit $? |
| 93 | MAKE=`searchgnu make` || exit $? |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 94 | |
| 95 | cleanup() |
| 96 | { |
| 97 | printf "Cleaning up temporary files... " |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 98 | rm -rf build-* combined gcc-* gmp-* mpfr-* mpc-* libelf-* binutils-* gdb-* w32api-* mingwrt-* |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 99 | printf "${green}ok${NC}\n" |
| 100 | } |
| 101 | |
| 102 | myhelp() |
| 103 | { |
Peter Stuge | ceacd77 | 2011-06-09 04:54:16 +0200 | [diff] [blame] | 104 | printf "Usage: $0 [-V] [-c] [-p <platform>] [-d <target directory>] [-D <dest dir>] [-G]\n" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 105 | printf " $0 [-V|--version]\n" |
| 106 | printf " $0 [-h|--help]\n\n" |
| 107 | |
| 108 | printf "Options:\n" |
| 109 | printf " [-V|--version] print version number and exit\n" |
| 110 | printf " [-h|--help] print this help and exit\n" |
| 111 | printf " [-c|--clean] remove temporary files before build\n" |
| 112 | printf " [-t|--savetemps] don't remove temporary files after build\n" |
Patrick Georgi | 73166c7 | 2010-04-14 20:42:42 +0000 | [diff] [blame] | 113 | printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 114 | printf " [-p|--platform <platform>] target platform to build cross compiler for\n" |
| 115 | printf " (defaults to $TARGETARCH)\n" |
| 116 | printf " [-d|--directory <target dir>] target directory to install cross compiler to\n" |
| 117 | printf " (defaults to $TARGETDIR)\n\n" |
| 118 | printf " [-D|--destdir <dest dir>] destination directory to install cross compiler to\n" |
| 119 | printf " (for RPM builds, default unset)\n\n" |
Peter Stuge | ceacd77 | 2011-06-09 04:54:16 +0200 | [diff] [blame] | 120 | printf " [-G|--skip-gdb] don't build GNU debugger\n" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | myversion() |
| 124 | { |
| 125 | # version tag is always printed, so just print the license here |
| 126 | |
| 127 | cat << EOF |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 128 | Copyright (C) 2008-2010 by coresystems GmbH |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 129 | |
| 130 | This program is free software; you can redistribute it and/or modify |
| 131 | it under the terms of the GNU General Public License as published by |
| 132 | the Free Software Foundation; version 2 of the License. |
| 133 | |
| 134 | This program is distributed in the hope that it will be useful, |
| 135 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 136 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 137 | GNU General Public License for more details. |
| 138 | |
| 139 | EOF |
| 140 | } |
| 141 | |
| 142 | printf "${blue}Welcome to the ${red}coresystems${blue} cross toolchain builder v$CROSSGCC_VERSION ($CROSSGCC_DATE)${NC}\n\n" |
| 143 | |
Patrick Georgi | 6bba29f | 2010-01-29 17:40:52 +0000 | [diff] [blame] | 144 | # Look if we have getopt. If not, build it. |
| 145 | export PATH=$PATH:. |
| 146 | getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c |
| 147 | |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 148 | # parse parameters.. try to find out whether we're running GNU getopt |
| 149 | getoptbrand="`getopt -V`" |
| 150 | if [ "${getoptbrand:0:6}" == "getopt" ]; then |
| 151 | # Detected GNU getopt that supports long options. |
Peter Stuge | ceacd77 | 2011-06-09 04:54:16 +0200 | [diff] [blame] | 152 | args=`getopt -l version,help,clean,directory:,platform:,jobs:,destdir:,savetemps,skip-gdb Vhcd:p:j:D:tG -- "$@"` |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 153 | eval set "$args" |
| 154 | else |
| 155 | # Detected non-GNU getopt |
Peter Stuge | ceacd77 | 2011-06-09 04:54:16 +0200 | [diff] [blame] | 156 | args=`getopt Vhcd:p:j:D:tG $*` |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 157 | set -- $args |
| 158 | fi |
| 159 | |
| 160 | if [ $? != 0 ]; then |
| 161 | myhelp |
| 162 | exit 1 |
| 163 | fi |
| 164 | |
| 165 | while true ; do |
| 166 | case "$1" in |
| 167 | -V|--version) shift; myversion; exit 0;; |
| 168 | -h|--help) shift; myhelp; exit 0;; |
| 169 | -c|--clean) shift; cleanup;; |
| 170 | -t|--savetemps) shift; SAVETEMPS=1;; |
| 171 | -d|--directory) shift; TARGETDIR="$1"; shift;; |
| 172 | -p|--platform) shift; TARGETARCH="$1"; shift;; |
| 173 | -D|--destdir) shift; DESTDIR="$1"; shift;; |
Patrick Georgi | 73166c7 | 2010-04-14 20:42:42 +0000 | [diff] [blame] | 174 | -j|--jobs) shift; JOBS="-j $1"; shift;; |
Peter Stuge | ceacd77 | 2011-06-09 04:54:16 +0200 | [diff] [blame] | 175 | -G|--skip-gdb) shift; SKIPGDB=1;; |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 176 | --) shift; break;; |
| 177 | -*) printf "Invalid option\n\n"; myhelp; exit 1;; |
| 178 | *) break;; |
| 179 | esac |
| 180 | done |
| 181 | |
Peter Stuge | ceacd77 | 2011-06-09 04:54:16 +0200 | [diff] [blame] | 182 | GDB_PACKAGE="GDB" |
| 183 | if [ $SKIPGDB -eq 1 ]; then |
| 184 | printf "Will skip GDB ... ${green}ok${NC}\n" |
| 185 | GDB_PACKAGE="" |
| 186 | fi |
| 187 | |
Stefan Reinauer | 6ade161 | 2010-01-16 16:44:20 +0000 | [diff] [blame] | 188 | MINGW_ARCHIVES="" |
| 189 | if [ "$TARGETARCH" = "i386-mingw32" ]; then |
| 190 | MINGW_ARCHIVES="$W32API_ARCHIVE $MINGWRT_ARCHIVE" |
| 191 | fi |
| 192 | |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 193 | if [ ${GCC_VERSION} == "4.5.0" -o ${GCC_VERSION} == "4.6.0" ]; then |
| 194 | # coreboot does not like the GOLD linker |
| 195 | # USE_GOLD="--enable-gold" |
| 196 | USE_GOLD="" |
| 197 | GCC_OPTIONS="--enable-lto" |
| 198 | fi |
| 199 | |
| 200 | if [ ${GCC_VERSION} == "4.6.0" ]; then |
| 201 | if [ ! -r tarballs/gcc-core-${GCC_VERSION}.tar.bz2 ]; then |
| 202 | printf "Pre-Release GCC ${GCC_VERSION}, checking out subversion trunk\n" |
| 203 | mkdir -p tarballs/.tmp |
| 204 | cd tarballs/.tmp |
| 205 | rm -rf gcc-${GCC_VERSION} |
| 206 | svn export -q svn://gcc.gnu.org/svn/gcc/trunk gcc-${GCC_VERSION} |
| 207 | printf "done. Now creating tar ball...\n" |
| 208 | tar cjf ../gcc-core-${GCC_VERSION}.tar.bz2 gcc-${GCC_VERSION} |
| 209 | printf "done. Now cleaning up...\n" |
| 210 | cd .. |
| 211 | rm -rf .tmp |
| 212 | cd .. |
| 213 | printf "done.\n" |
| 214 | fi |
| 215 | fi |
| 216 | |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 217 | printf "Downloading tar balls ... \n" |
| 218 | mkdir -p tarballs |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 219 | for ARCHIVE in $GMP_ARCHIVE $MPFR_ARCHIVE $MPC_ARCHIVE $LIBELF_ARCHIVE $GCC_ARCHIVE $BINUTILS_ARCHIVE $GDB_ARCHIVE $MINGW_ARCHIVES; do |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 220 | FILE=`basename $ARCHIVE` |
| 221 | printf " * $FILE " |
| 222 | test -f tarballs/$FILE && printf "(cached)" || ( |
| 223 | printf "(downloading)" |
| 224 | cd tarballs |
| 225 | wget -q $ARCHIVE |
| 226 | ) |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 227 | test -f tarballs/$FILE || printf "\n${RED}Failed to download $FILE.${red}\n" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 228 | test -f tarballs/$FILE || exit 1 |
| 229 | printf "\n" |
| 230 | done |
| 231 | printf "Downloaded tar balls ... " |
| 232 | printf "${green}ok${NC}\n" |
| 233 | |
Stefan Reinauer | 6ade161 | 2010-01-16 16:44:20 +0000 | [diff] [blame] | 234 | MINGW_PACKAGES="" |
| 235 | if [ "$TARGETARCH" = "i386-mingw32" ]; then |
| 236 | MINGW_PACKAGES="W32API MINGWRT" |
| 237 | fi |
| 238 | |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 239 | printf "Unpacking and patching ... \n" |
Peter Stuge | ceacd77 | 2011-06-09 04:54:16 +0200 | [diff] [blame] | 240 | for PACKAGE in GMP MPFR MPC LIBELF GCC BINUTILS $GDB_PACKAGE $MINGW_PACKAGES; do |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 241 | archive=$PACKAGE"_ARCHIVE" |
| 242 | archive=${!archive} |
| 243 | dir=$PACKAGE"_DIR" |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 244 | test -d ${!dir} || ( |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 245 | printf " * `basename $archive`\n" |
| 246 | FLAGS=zxf |
| 247 | test ${archive:${#archive}-2:2} = "gz" && FLAGS=zxf |
| 248 | test ${archive:${#archive}-3:3} = "bz2" && FLAGS=jxf |
| 249 | $TAR $FLAGS tarballs/`basename $archive` |
Stefan Reinauer | 6ade161 | 2010-01-16 16:44:20 +0000 | [diff] [blame] | 250 | for patch in patches/${!dir}_*.patch; do |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 251 | test -r $patch || continue |
| 252 | printf " o `basename $patch`\n" |
Patrick Georgi | 6bba29f | 2010-01-29 17:40:52 +0000 | [diff] [blame] | 253 | $PATCH -s -N -p0 < `echo $patch` |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 254 | done |
| 255 | ) |
| 256 | done |
| 257 | printf "Unpacked and patched ... " |
| 258 | printf "${green}ok${NC}\n" |
| 259 | |
Stefan Reinauer | 6ade161 | 2010-01-16 16:44:20 +0000 | [diff] [blame] | 260 | if [ "$TARGETARCH" = "i386-mingw32" ]; then |
| 261 | mkdir -p $TARGETDIR/i386-mingw32/sys-include |
| 262 | mv $MINGWRT_DIR/include/* $W32API_DIR/include/* $TARGETDIR/i386-mingw32/sys-include |
| 263 | fi |
| 264 | |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 265 | if [ `uname` = "Darwin" ]; then |
| 266 | #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix" |
| 267 | |
| 268 | # generally the OS X compiler can create x64 binaries. |
| 269 | # Per default it generated i386 binaries in 10.5 and x64 |
| 270 | # binaries in 10.6 (even if the kernel is 32bit) |
| 271 | # For some weird reason, 10.5 autodetects an ABI=64 though |
| 272 | # so we're setting the ABI explicitly here. |
| 273 | if [ `sysctl -n hw.optional.x86_64` -eq 1 ]; then |
| 274 | OPTIONS="ABI=64" |
| 275 | else |
| 276 | OPTIONS="ABI=32" |
| 277 | fi |
| 278 | # old check: |
| 279 | #OPTIONS="ABI=32" |
| 280 | #touch .architecture_check.c |
| 281 | #gcc .architecture_check.c -c -o .architecture_check.o |
| 282 | #ARCH=`file .architecture_check.o |cut -f5 -d\ ` |
| 283 | #test "$ARCH" = "x86_64" && OPTIONS="ABI=64" |
| 284 | #rm .architecture_check.c .architecture_check.o |
| 285 | fi |
| 286 | |
Peter Stuge | ceacd77 | 2011-06-09 04:54:16 +0200 | [diff] [blame] | 287 | mkdir -p build-gmp build-mpfr build-mpc build-libelf build-binutils build-gcc |
| 288 | if [ $SKIPGDB -eq 0 ]; then |
| 289 | mkdir -p build-gdb |
| 290 | fi |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 291 | if [ -f build-gmp/.success ]; then |
| 292 | printf "Skipping GMP as it is already built\n" |
| 293 | else |
| 294 | printf "Building GMP ${GMP_VERSION} ... " |
| 295 | ( |
| 296 | cd build-gmp |
| 297 | rm -f .failed |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 298 | ../${GMP_DIR}/configure --disable-shared --prefix=$TARGETDIR $OPTIONS \ |
| 299 | || touch .failed |
Patrick Georgi | 73166c7 | 2010-04-14 20:42:42 +0000 | [diff] [blame] | 300 | $MAKE $JOBS || touch .failed |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 301 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 302 | if [ ! -f .failed ]; then touch .success; fi |
| 303 | ) &> build-gmp/crossgcc-build.log |
| 304 | test -r build-gmp/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n" |
| 305 | test -r build-gmp/.failed && exit 1 |
| 306 | fi |
| 307 | |
| 308 | #if [ "$DESTDIR" != "" -a ! -x $TARGETDIR ]; then |
| 309 | # # create compat link |
| 310 | # ln -s $DESTDIR$TARGETDIR $TARGETDIR |
| 311 | #fi |
| 312 | |
| 313 | # Now set CFLAGS to match GMP CFLAGS. |
| 314 | HOSTCFLAGS=`grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2` |
| 315 | |
| 316 | if [ -f build-mpfr/.success ]; then |
| 317 | printf "Skipping MPFR as it is already built\n" |
| 318 | else |
| 319 | printf "Building MPFR ${MPFR_VERSION} ... " |
| 320 | ( |
| 321 | test `uname` = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL" |
| 322 | cd build-mpfr |
| 323 | rm -f .failed |
| 324 | ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \ |
| 325 | --infodir=$TARGETDIR/info \ |
| 326 | --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || touch .failed |
Patrick Georgi | 73166c7 | 2010-04-14 20:42:42 +0000 | [diff] [blame] | 327 | $MAKE $JOBS || touch .failed |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 328 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 329 | |
| 330 | # work around build problem of libgmp.la |
| 331 | if [ "$DESTDIR" != "" ]; then |
| 332 | perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la |
| 333 | fi |
| 334 | |
| 335 | if [ ! -f .failed ]; then touch .success; fi |
| 336 | ) &> build-mpfr/crossgcc-build.log |
| 337 | test -r build-mpfr/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n" |
| 338 | test -r build-mpfr/.failed && exit 1 |
| 339 | fi |
| 340 | |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 341 | if [ -f build-mpc/.success ]; then |
| 342 | printf "Skipping MPC as it is already built\n" |
| 343 | else |
| 344 | printf "Building MPC ${MPC_VERSION} ... " |
| 345 | ( |
| 346 | #test `uname` = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL" |
| 347 | cd build-mpc |
| 348 | rm -f .failed |
| 349 | ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \ |
| 350 | --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \ |
| 351 | --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || touch .failed |
| 352 | $MAKE $JOBS || touch .failed |
| 353 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 354 | |
| 355 | if [ ! -f .failed ]; then touch .success; fi |
| 356 | ) &> build-mpc/crossgcc-build.log |
| 357 | test -r build-mpc/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n" |
| 358 | test -r build-mpc/.failed && exit 1 |
| 359 | fi |
| 360 | |
| 361 | if [ -f build-libelf/.success ]; then |
| 362 | printf "Skipping libelf as it is already built\n" |
| 363 | else |
| 364 | printf "Building libelf ${LIBELF_VERSION} ... " |
| 365 | ( |
| 366 | cd build-libelf |
| 367 | rm -f .failed |
| 368 | echo "$HOSTCFLAGS" |
Marc Jones | 3693266 | 2010-12-03 00:45:56 +0000 | [diff] [blame] | 369 | CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \ |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 370 | --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed |
| 371 | $MAKE $JOBS || touch .failed |
| 372 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 373 | |
| 374 | if [ ! -f .failed ]; then touch .success; fi |
| 375 | ) &> build-libelf/crossgcc-build.log |
| 376 | test -r build-libelf/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n" |
| 377 | test -r build-libelf/.failed && exit 1 |
| 378 | fi |
| 379 | |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 380 | if [ -f build-binutils/.success ]; then |
| 381 | printf "Skipping binutils as it is already built\n" |
| 382 | else |
| 383 | printf "Building binutils ${BINUTILS_VERSION} ... " |
| 384 | ( |
| 385 | cd build-binutils |
| 386 | rm -f .failed |
| 387 | ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR --target=${TARGETARCH} \ |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 388 | --disable-werror --disable-nls $USE_GOLD \ |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 389 | CFLAGS="$HOSTCFLAGS" || touch .failed |
Patrick Georgi | 73166c7 | 2010-04-14 20:42:42 +0000 | [diff] [blame] | 390 | $MAKE $JOBS || touch .failed |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 391 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 392 | if [ ! -f .failed ]; then touch .success; fi |
| 393 | ) &> build-binutils/crossgcc-build.log |
| 394 | test -r build-binutils/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n" |
| 395 | test -r build-binutils/.failed && exit 1 |
| 396 | fi |
| 397 | |
| 398 | if [ -f build-gcc/.success ]; then |
| 399 | printf "Skipping GCC as it is already built\n" |
| 400 | else |
| 401 | printf "Building GCC ${GCC_VERSION} ... " |
| 402 | ( |
| 403 | cd build-gcc |
Patrick Georgi | ba3b0eb | 2010-09-03 08:53:06 +0000 | [diff] [blame] | 404 | export PATH=$PATH:$DESTDIR$TARGETDIR/bin |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 405 | rm -f .failed |
| 406 | # GCC does not honour HOSTCFLAGS at all. CFLAGS are used for |
| 407 | # both target and host object files. This is pretty misdesigned. |
| 408 | # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET |
| 409 | # but it does not seem to work properly. At least the host library |
| 410 | # libiberty is not compiled with CFLAGS_FOR_BUILD. |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 411 | CFLAGS_FOR_TARGET="-O2" CFLAGS="$HOSTCFLAGS" CFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \ |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 412 | --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \ |
Stefan Reinauer | 6ade161 | 2010-01-16 16:44:20 +0000 | [diff] [blame] | 413 | --target=${TARGETARCH} --disable-werror --disable-shared \ |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 414 | --disable-libssp --disable-bootstrap --disable-nls \ |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 415 | $GCC_OPTIONS --enable-languages="c" $USE_GOLD \ |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 416 | --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \ |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 417 | --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \ |
| 418 | --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \ |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 419 | || touch .failed |
Patrick Georgi | 73166c7 | 2010-04-14 20:42:42 +0000 | [diff] [blame] | 420 | $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" || touch .failed |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 421 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 422 | if [ ! -f .failed ]; then touch .success; fi |
| 423 | ) &> build-gcc/crossgcc-build.log |
| 424 | test -r build-gcc/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n" |
| 425 | test -r build-gcc/.failed && exit 1 |
| 426 | fi |
| 427 | |
| 428 | if [ -f build-gdb/.success ]; then |
| 429 | printf "Skipping GDB as it is already built\n" |
Peter Stuge | ceacd77 | 2011-06-09 04:54:16 +0200 | [diff] [blame] | 430 | elif [ $SKIPGDB -eq 1 ]; then |
| 431 | printf "Skipping GDB as requested by command line\n" |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 432 | else |
| 433 | printf "Building GDB ${GDB_VERSION} ... " |
| 434 | ( |
| 435 | cd build-gdb |
Patrick Georgi | ba3b0eb | 2010-09-03 08:53:06 +0000 | [diff] [blame] | 436 | export PATH=$PATH:$DESTDIR$TARGETDIR/bin |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 437 | rm -f .failed |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 438 | CFLAGS="$HOSTCFLAGS" ../gdb-${GDB_VERSION}/configure --prefix=$TARGETDIR --target=${TARGETARCH} \ |
| 439 | --without-python --disable-werror --disable-nls |
Patrick Georgi | 73166c7 | 2010-04-14 20:42:42 +0000 | [diff] [blame] | 440 | $MAKE $JOBS || touch .failed |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 441 | $MAKE install DESTDIR=$DESTDIR || touch .failed |
| 442 | if [ ! -f .failed ]; then touch .success; fi |
| 443 | ) &> build-gdb/crossgcc-build.log |
| 444 | test -r build-gdb/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n" |
| 445 | test -r build-gdb/.failed && exit 1 |
| 446 | fi |
| 447 | |
| 448 | if [ $SAVETEMPS -eq 0 ]; then |
| 449 | printf "Cleaning up... " |
| 450 | rm -rf ${GMP_DIR} build-gmp |
| 451 | rm -rf ${MPFR_DIR} build-mpfr |
Stefan Reinauer | 5f1ad89 | 2010-05-17 11:02:25 +0000 | [diff] [blame] | 452 | rm -rf ${MPC_DIR} build-mpc |
| 453 | rm -rf ${LIBELF_DIR} build-libelf |
Stefan Reinauer | 074d913 | 2009-09-26 16:43:17 +0000 | [diff] [blame] | 454 | rm -rf ${BINUTILS_DIR} build-binutils |
| 455 | rm -rf ${GCC_DIR} build-gcc |
| 456 | rm -rf ${GDB_DIR} build-gdb |
| 457 | printf "${green}ok${NC}\n" |
| 458 | else |
| 459 | printf "Leaving temporary files around... ${green}ok${NC}\n" |
| 460 | fi |
| 461 | |
| 462 | printf "\n${green}You can now run your $TARGETARCH cross toolchain from $TARGETDIR.${NC}\n" |
| 463 | |
| 464 | |