Changeset 89c57b6 in mainline for tools/toolchain.sh


Ignore:
Timestamp:
2011-04-13T14:45:41Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
88634420
Parents:
cefb126 (diff), 17279ead (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/toolchain.sh

    rcefb126 r89c57b6  
    1 #!/bin/bash
     1#! /bin/bash
    22
    33#
     
    2929#
    3030
     31GMP_MAIN=<<EOF
     32#define GCC_GMP_VERSION_NUM(a, b, c) \
     33        (((a) << 16L) | ((b) << 8) | (c))
     34
     35#define GCC_GMP_VERSION \
     36        GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
     37
     38#if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,2)
     39        choke me
     40#endif
     41EOF
     42
     43MPFR_MAIN=<<EOF
     44#if MPFR_VERSION < MPFR_VERSION_NUM(2, 4, 2)
     45choke me
     46        #endif
     47EOF
     48
     49MPC_MAIN=<<EOF
     50#if MPC_VERSION < MPC_VERSION_NUM(0, 8, 1)
     51        choke me
     52#endif
     53EOF
     54
     55BINUTILS_VERSION="2.21"
     56GCC_VERSION="4.6.0"
     57
     58BASEDIR="`pwd`"
     59BINUTILS="binutils-${BINUTILS_VERSION}.tar.bz2"
     60GCC_CORE="gcc-core-${GCC_VERSION}.tar.bz2"
     61GCC_OBJC="gcc-objc-${GCC_VERSION}.tar.bz2"
     62GCC_CPP="gcc-g++-${GCC_VERSION}.tar.bz2"
     63
     64#
     65# Check if the library described in the argument
     66# exists and has acceptable version.
     67#
     68check_dependency() {
     69        DEPENDENCY="$1"
     70        HEADER="$2"
     71        BODY="$3"
     72       
     73        FNAME="/tmp/conftest-$$"
     74       
     75        echo "#include ${HEADER}" > "${FNAME}.c"
     76        echo >> "${FNAME}.c"
     77        echo "int main()" >> "${FNAME}.c"
     78        echo "{" >> "${FNAME}.c"
     79        echo "${BODY}" >> "${FNAME}.c"
     80        echo "  return 0;" >> "${FNAME}.c"
     81        echo "}" >> "${FNAME}.c"
     82       
     83        cc -c -o "${FNAME}.o" "${FNAME}.c" 2> "${FNAME}.log"
     84        RC="$?"
     85       
     86        if [ "$RC" -ne "0" ] ; then
     87                echo " ${DEPENDENCY} not found, too old or compiler error."
     88                echo " Please recheck manually the source file \"${FNAME}.c\"."
     89                echo " The compilation of the toolchain is probably going to fail,"
     90                echo " you have been warned."
     91                echo
     92                echo " ===== Compiler output ====="
     93                cat "${FNAME}.log"
     94                echo " ==========================="
     95                echo
     96        else
     97                echo " ${DEPENDENCY} found"
     98                rm -f "${FNAME}.log" "${FNAME}.o" "${FNAME}.c"
     99        fi
     100}
     101
     102check_dependecies() {
     103        echo ">>> Basic dependency check"
     104        check_dependency "GMP" "<gmp.h>" "${GMP_MAIN}"
     105        check_dependency "MPFR" "<mpfr.h>" "${MPFR_MAIN}"
     106        check_dependency "MPC" "<mpc.h>" "${MPC_MAIN}"
     107        echo
     108}
     109
    31110check_error() {
    32111        if [ "$1" -ne "0" ]; then
    33112                echo
    34113                echo "Script failed: $2"
     114               
    35115                exit 1
    36116        fi
     
    45125                echo
    46126                echo "Checksum of ${FILE} does not match."
     127               
    47128                exit 2
    48129        fi
     
    60141        echo " ia32       IA-32 (x86, i386)"
    61142        echo " ia64       IA-64 (Itanium)"
    62         echo " mips32     MIPS little-endian"
    63         echo " mips32eb   MIPS big-endian"
     143        echo " mips32     MIPS little-endian 32b"
     144        echo " mips32eb   MIPS big-endian 32b"
     145        echo " mips64     MIPS little-endian 64b"
    64146        echo " ppc32      32-bit PowerPC"
    65147        echo " ppc64      64-bit PowerPC"
    66148        echo " sparc64    SPARC V9"
    67149        echo " all        build all targets"
     150        echo " parallel   same as 'all', but in parallel"
     151        echo
     152        echo "The toolchain will be installed to the directory specified by"
     153        echo "the CROSS_PREFIX environment variable. If the variable is not"
     154        echo "defined, /usr/local/cross will be used by default."
    68155        echo
    69156       
     
    71158}
    72159
    73 download_check() {
     160change_title() {
     161        echo -en "\e]0;$1\a"
     162}
     163
     164show_countdown() {
     165        TM="$1"
     166       
     167        if [ "${TM}" -eq 0 ] ; then
     168                echo
     169                return 0
     170        fi
     171       
     172        echo -n "${TM} "
     173        change_title "${TM}"
     174        sleep 1
     175       
     176        TM="`expr "${TM}" - 1`"
     177        show_countdown "${TM}"
     178}
     179
     180show_dependencies() {
     181        echo "IMPORTANT NOTICE:"
     182        echo
     183        echo "For a successful compilation and use of the cross-compiler"
     184        echo "toolchain you need at least the following dependencies."
     185        echo
     186        echo "Please make sure that the dependencies are present in your"
     187        echo "system. Otherwise the compilation process might fail after"
     188        echo "a few seconds or minutes."
     189        echo
     190        echo " - SED, AWK, Flex, Bison, gzip, bzip2, Bourne Shell"
     191        echo " - gettext, zlib, Texinfo, libelf, libgomp"
     192        echo " - GNU Multiple Precision Library (GMP)"
     193        echo " - GNU Make"
     194        echo " - GNU tar"
     195        echo " - GNU Coreutils"
     196        echo " - GNU Sharutils"
     197        echo " - MPFR"
     198        echo " - MPC"
     199        echo " - Parma Polyhedra Library (PPL)"
     200        echo " - ClooG-PPL"
     201        echo " - native C compiler, assembler and linker"
     202        echo " - native C library with headers"
     203        echo
     204}
     205
     206download_fetch() {
    74207        SOURCE="$1"
    75208        FILE="$2"
     
    77210       
    78211        if [ ! -f "${FILE}" ]; then
     212                change_title "Downloading ${FILE}"
    79213                wget -c "${SOURCE}${FILE}"
    80214                check_error $? "Error downloading ${FILE}."
     
    84218}
    85219
     220source_check() {
     221        FILE="$1"
     222       
     223        if [ ! -f "${FILE}" ]; then
     224                echo
     225                echo "File ${FILE} not found."
     226               
     227                exit 4
     228        fi
     229}
     230
    86231cleanup_dir() {
    87232        DIR="$1"
    88233       
    89234        if [ -d "${DIR}" ]; then
     235                change_title "Removing ${DIR}"
    90236                echo " >>> Removing ${DIR}"
    91237                rm -fr "${DIR}"
     
    97243        DESC="$2"
    98244       
     245        change_title "Creating ${DESC}"
    99246        echo ">>> Creating ${DESC}"
    100247       
     
    108255        DESC="$2"
    109256       
    110         echo " >>> ${DESC}"
     257        change_title "Unpacking ${DESC}"
     258        echo " >>> Unpacking ${DESC}"
    111259       
    112260        tar -xjf "${FILE}"
     
    114262}
    115263
    116 patch_binutils() {
    117         PLATFORM="$1"
    118        
    119         if [ "${PLATFORM}" == "arm32" ] ; then
    120                 patch -p1 <<EOF
    121 diff -Naur binutils-2.20.orig/gas/config/tc-arm.c binutils-2.20/gas/config/tc-arm.c
    122 --- binutils-2.20.orig/gas/config/tc-arm.c      2009-08-30 00:10:59.000000000 +0200
    123 +++ binutils-2.20/gas/config/tc-arm.c   2009-11-02 14:25:11.000000000 +0100
    124 @@ -2485,8 +2485,9 @@
    125        know (frag->tc_frag_data.first_map == NULL);
    126        frag->tc_frag_data.first_map = symbolP;
    127      }
    128 -  if (frag->tc_frag_data.last_map != NULL)
    129 +  if (frag->tc_frag_data.last_map != NULL) {
    130      know (S_GET_VALUE (frag->tc_frag_data.last_map) < S_GET_VALUE (symbolP));
    131 +  }
    132    frag->tc_frag_data.last_map = symbolP;
    133  }
    134 EOF
    135                 check_error $? "Error patching binutils"
    136         fi
     264prepare() {
     265        show_dependencies
     266        check_dependecies
     267        show_countdown 10
     268       
     269        BINUTILS_SOURCE="ftp://ftp.gnu.org/gnu/binutils/"
     270        GCC_SOURCE="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"
     271       
     272        download_fetch "${BINUTILS_SOURCE}" "${BINUTILS}" "c84c5acc9d266f1a7044b51c85a823f5"
     273        download_fetch "${GCC_SOURCE}" "${GCC_CORE}" "b1957f3209080b2f55bc3756d3a62b7c"
     274        download_fetch "${GCC_SOURCE}" "${GCC_OBJC}" "120d4675366ee82ea52f9ed65b57da04"
     275        download_fetch "${GCC_SOURCE}" "${GCC_CPP}" "a30090fa655d0db4c970740d353c81f1"
    137276}
    138277
     
    141280        TARGET="$2"
    142281       
    143         BINUTILS_VERSION="2.20"
    144         GCC_VERSION="4.5.0"
    145        
    146         BINUTILS="binutils-${BINUTILS_VERSION}.tar.bz2"
    147         GCC_CORE="gcc-core-${GCC_VERSION}.tar.bz2"
    148         GCC_OBJC="gcc-objc-${GCC_VERSION}.tar.bz2"
    149         GCC_CPP="gcc-g++-${GCC_VERSION}.tar.bz2"
    150        
    151         BINUTILS_SOURCE="ftp://ftp.gnu.org/gnu/binutils/"
    152         GCC_SOURCE="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"
    153        
    154         WORKDIR="`pwd`"
     282        WORKDIR="${BASEDIR}/${PLATFORM}"
    155283        BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}"
    156284        GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
     
    158286       
    159287        if [ -z "${CROSS_PREFIX}" ] ; then
    160                 CROSS_PREFIX="/usr/local"
     288                CROSS_PREFIX="/usr/local/cross"
    161289        fi
    162290       
     
    164292       
    165293        echo ">>> Downloading tarballs"
    166         download_check "${BINUTILS_SOURCE}" "${BINUTILS}" "ee2d3e996e9a2d669808713360fa96f8"
    167         download_check "${GCC_SOURCE}" "${GCC_CORE}" "58eda33c3184303628f91c42a7ab15b5"
    168         download_check "${GCC_SOURCE}" "${GCC_OBJC}" "8d8c01b6631b020cc6c167860fde2398"
    169         download_check "${GCC_SOURCE}" "${GCC_CPP}" "5ab93605af40def4844eda09ca769c2d"
     294        source_check "${BASEDIR}/${BINUTILS}"
     295        source_check "${BASEDIR}/${GCC_CORE}"
     296        source_check "${BASEDIR}/${GCC_OBJC}"
     297        source_check "${BASEDIR}/${GCC_CPP}"
    170298       
    171299        echo ">>> Removing previous content"
    172300        cleanup_dir "${PREFIX}"
    173         cleanup_dir "${OBJDIR}"
    174         cleanup_dir "${BINUTILSDIR}"
    175         cleanup_dir "${GCCDIR}"
     301        cleanup_dir "${WORKDIR}"
    176302       
    177303        create_dir "${PREFIX}" "destination directory"
     
    179305       
    180306        echo ">>> Unpacking tarballs"
    181         unpack_tarball "${BINUTILS}" "binutils"
    182         unpack_tarball "${GCC_CORE}" "GCC Core"
    183         unpack_tarball "${GCC_OBJC}" "Objective C"
    184         unpack_tarball "${GCC_CPP}" "C++"
    185        
    186         echo ">>> Compiling and installing binutils"
     307        cd "${WORKDIR}"
     308        check_error $? "Change directory failed."
     309       
     310        unpack_tarball "${BASEDIR}/${BINUTILS}" "binutils"
     311        unpack_tarball "${BASEDIR}/${GCC_CORE}" "GCC Core"
     312        unpack_tarball "${BASEDIR}/${GCC_OBJC}" "Objective C"
     313        unpack_tarball "${BASEDIR}/${GCC_CPP}" "C++"
     314       
     315        echo ">>> Processing binutils (${PLATFORM})"
    187316        cd "${BINUTILSDIR}"
    188317        check_error $? "Change directory failed."
    189         patch_binutils "${PLATFORM}"
    190         ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" "--disable-nls"
     318       
     319        change_title "binutils: configure (${PLATFORM})"
     320        ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" --disable-nls
    191321        check_error $? "Error configuring binutils."
     322       
     323        change_title "binutils: make (${PLATFORM})"
    192324        make all install
    193325        check_error $? "Error compiling/installing binutils."
    194326       
    195         echo ">>> Compiling and installing GCC"
     327        echo ">>> Processing GCC (${PLATFORM})"
    196328        cd "${OBJDIR}"
    197329        check_error $? "Change directory failed."
     330       
     331        change_title "GCC: configure (${PLATFORM})"
    198332        "${GCCDIR}/configure" "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" --with-gnu-as --with-gnu-ld --disable-nls --disable-threads --enable-languages=c,objc,c++,obj-c++ --disable-multilib --disable-libgcj --without-headers --disable-shared --enable-lto
    199333        check_error $? "Error configuring GCC."
     334       
     335        change_title "GCC: make (${PLATFORM})"
    200336        PATH="${PATH}:${PREFIX}/bin" make all-gcc install-gcc
    201337        check_error $? "Error compiling/installing GCC."
    202338       
    203         cd "${WORKDIR}"
     339        cd "${BASEDIR}"
    204340        check_error $? "Change directory failed."
    205341       
    206342        echo ">>> Cleaning up"
    207         cleanup_dir "${OBJDIR}"
    208         cleanup_dir "${BINUTILSDIR}"
    209         cleanup_dir "${GCCDIR}"
     343        cleanup_dir "${WORKDIR}"
    210344       
    211345        echo
     
    219353case "$1" in
    220354        "amd64")
     355                prepare
    221356                build_target "amd64" "amd64-linux-gnu"
    222357                ;;
    223358        "arm32")
     359                prepare
    224360                build_target "arm32" "arm-linux-gnu"
    225361                ;;
    226362        "ia32")
     363                prepare
    227364                build_target "ia32" "i686-pc-linux-gnu"
    228365                ;;
    229366        "ia64")
     367                prepare
    230368                build_target "ia64" "ia64-pc-linux-gnu"
    231369                ;;
    232         "ia64")
    233                 build_target "ia64" "ia64-pc-linux-gnu"
    234                 ;;
    235370        "mips32")
     371                prepare
    236372                build_target "mips32" "mipsel-linux-gnu"
    237373                ;;
    238374        "mips32eb")
     375                prepare
    239376                build_target "mips32eb" "mips-linux-gnu"
    240377                ;;
     378        "mips64")
     379                prepare
     380                build_target "mips64" "mips64el-linux-gnu"
     381                ;;
    241382        "ppc32")
     383                prepare
    242384                build_target "ppc32" "ppc-linux-gnu"
    243385                ;;
    244386        "ppc64")
     387                prepare
    245388                build_target "ppc64" "ppc64-linux-gnu"
    246389                ;;
    247390        "sparc64")
     391                prepare
    248392                build_target "sparc64" "sparc64-linux-gnu"
    249393                ;;
    250394        "all")
     395                prepare
    251396                build_target "amd64" "amd64-linux-gnu"
    252397                build_target "arm32" "arm-linux-gnu"
    253398                build_target "ia32" "i686-pc-linux-gnu"
    254399                build_target "ia64" "ia64-pc-linux-gnu"
    255                 build_target "ia64" "ia64-pc-linux-gnu"
    256400                build_target "mips32" "mipsel-linux-gnu"
    257401                build_target "mips32eb" "mips-linux-gnu"
     402                build_target "mips64" "mips64el-linux-gnu"
    258403                build_target "ppc32" "ppc-linux-gnu"
    259404                build_target "ppc64" "ppc64-linux-gnu"
    260405                build_target "sparc64" "sparc64-linux-gnu"
    261406                ;;
     407        "parallel")
     408                prepare
     409                build_target "amd64" "amd64-linux-gnu" &
     410                build_target "arm32" "arm-linux-gnu" &
     411                build_target "ia32" "i686-pc-linux-gnu" &
     412                build_target "ia64" "ia64-pc-linux-gnu" &
     413                build_target "mips32" "mipsel-linux-gnu" &
     414                build_target "mips32eb" "mips-linux-gnu" &
     415                build_target "mips64" "mips64el-linux-gnu" &
     416                build_target "ppc32" "ppc-linux-gnu" &
     417                build_target "ppc64" "ppc64-linux-gnu" &
     418                build_target "sparc64" "sparc64-linux-gnu" &
     419                wait
     420                ;;
    262421        *)
    263422                show_usage
Note: See TracChangeset for help on using the changeset viewer.