scripts/build/cc/gcc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jan 01 17:49:44 2012 +0100 (2012-01-01)
changeset 2924 0eab838768b1
parent 2901 4fcedd2c14b2
child 2925 d99b1adc4402
permissions -rw-r--r--
cc/gcc: install the core compilers in the build-tools dir

There really is no good reason to install the core compilers in their
own places, one for each pass. We can install them with the other
build tools.

Also, this implies that:
- there are fewer directories to save/restore
- there are fewer symlinks to create for binutils
- the PATH is shorter

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
     1 # This file adds the function to build the gcc C compiler
     2 # Copyright 2007 Yann E. MORIN
     3 # Licensed under the GPL v2. See COPYING in the root of this package
     4 
     5 # Download gcc
     6 do_cc_get() {
     7     local linaro_version
     8     local linaro_series
     9     local linaro_base_url="http://launchpad.net/gcc-linaro"
    10 
    11 
    12     # Account for the Linaro versioning
    13     linaro_version="$( echo "${CT_CC_VERSION}"      \
    14                        |sed -r -e 's/^linaro-//;'   \
    15                      )"
    16     linaro_series="$( echo "${linaro_version}"      \
    17                       |sed -r -e 's/-.*//;'         \
    18                     )"
    19 
    20     # Ah! gcc folks are kind of 'different': they store the tarballs in
    21     # subdirectories of the same name! That's because gcc is such /crap/ that
    22     # it is such /big/ that it needs being splitted for distribution! Sad. :-(
    23     # Arrgghh! Some of those versions does not follow this convention:
    24     # gcc-3.3.3 lives in releases/gcc-3.3.3, while gcc-2.95.* isn't in a
    25     # subdirectory! You bastard!
    26     CT_GetFile "gcc-${CT_CC_VERSION}"                                                       \
    27                {ftp,http}://ftp.gnu.org/gnu/gcc{,{,/releases}/gcc-${CT_CC_VERSION}}         \
    28                ftp://ftp.irisa.fr/pub/mirrors/gcc.gnu.org/gcc/releases/gcc-${CT_CC_VERSION} \
    29                ftp://ftp.uvsq.fr/pub/gcc/snapshots/${CT_CC_VERSION}                         \
    30                "${linaro_base_url}/${linaro_series}/${linaro_version}/+download"
    31 
    32     # Starting with GCC 4.3, ecj is used for Java, and will only be
    33     # built if the configure script finds ecj.jar at the top of the
    34     # GCC source tree, which will not be there unless we get it and
    35     # put it there ourselves
    36     if [ "${CT_CC_LANG_JAVA_USE_ECJ}" = "y" ]; then
    37         CT_GetFile ecj-latest .jar ftp://gcc.gnu.org/pub/java   \
    38                                    ftp://sourceware.org/pub/java
    39     fi
    40 }
    41 
    42 # Extract gcc
    43 do_cc_extract() {
    44     CT_Extract "gcc-${CT_CC_VERSION}"
    45     CT_Patch "gcc" "${CT_CC_VERSION}"
    46 
    47     # Copy ecj-latest.jar to ecj.jar at the top of the GCC source tree
    48     if [ "${CT_CC_LANG_JAVA_USE_ECJ}" = "y"                     \
    49          -a ! -f "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/ecj.jar"   \
    50        ]; then
    51         CT_DoExecLog ALL cp -v "${CT_TARBALLS_DIR}/ecj-latest.jar" "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/ecj.jar"
    52     fi
    53 }
    54 
    55 #------------------------------------------------------------------------------
    56 # Core gcc pass 1
    57 do_cc_core_pass_1() {
    58     local -a core_opts
    59     local do_core
    60 
    61     # If we're building for bare metal, build the static core gcc,
    62     # with libgcc.
    63     # In case we're not bare metal and building a canadian compiler, do nothing
    64     # In case we're not bare metal, and we're NPTL, build the static core gcc.
    65     # In any other case, do nothing.
    66     case "${CT_BARE_METAL},${CT_CANADIAN},${CT_THREADS}" in
    67         ,y,*)
    68             ;;
    69         ,,nptl)
    70             do_core=y
    71             core_opts+=( "mode=static" )
    72             core_opts+=( "host=${CT_HOST}" )
    73             core_opts+=( "complibs=${CT_COMPLIBS_DIR}" )
    74             core_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
    75             core_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
    76             ;;
    77         *)
    78             ;;
    79     esac
    80 
    81     if [ "${do_core}" = "y" ]; then
    82         CT_DoStep INFO "Installing pass-1 core C compiler"
    83         CT_mkdir_pushd "${CT_BUILD_DIR}/build-cc-core-pass-1"
    84 
    85         do_cc_core_backend "${core_opts[@]}"
    86 
    87         CT_Popd
    88         CT_EndStep
    89     fi
    90 }
    91 
    92 # Core gcc pass 2
    93 do_cc_core_pass_2() {
    94     local -a core_opts
    95     local do_core
    96 
    97     # In case we're building for bare metal, do nothing, we already have
    98     # our compiler.
    99     # In case we're not bare metal and building a canadian compiler, do nothing
   100     # In case we're NPTL, build the shared core gcc and the target libgcc.
   101     # In any other case, build the static core gcc and, if using gcc-4.3+,
   102     # also build the target libgcc.
   103     core_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
   104     case "${CT_BARE_METAL},${CT_CANADIAN},${CT_THREADS}" in
   105         y,*,*)
   106             do_core=y
   107             core_opts+=( "host=${CT_HOST}" )
   108             core_opts+=( "mode=static" )
   109             core_opts+=( "complibs=${CT_COMPLIBS_DIR}" )
   110             core_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
   111             ;;
   112         ,y,*)   ;;
   113         ,,nptl)
   114             do_core=y
   115             core_opts+=( "mode=shared" )
   116             core_opts+=( "host=${CT_HOST}" )
   117             core_opts+=( "build_libgcc=yes" )
   118             core_opts+=( "complibs=${CT_COMPLIBS_DIR}" )
   119             core_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
   120             ;;
   121         ,,win32)
   122             do_core=y
   123             core_opts+=( "mode=static" )
   124             core_opts+=( "host=${CT_HOST}" )
   125             core_opts+=( "build_libgcc=yes" )
   126             core_opts+=( "complibs=${CT_COMPLIBS_DIR}" )
   127             core_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
   128             ;;
   129         *)
   130             do_core=y
   131             core_opts+=( "mode=static" )
   132             core_opts+=( "host=${CT_HOST}" )
   133             core_opts+=( "complibs=${CT_COMPLIBS_DIR}" )
   134             core_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
   135             if [ "${CT_CC_GCC_4_3_or_later}" = "y" ]; then
   136                 core_opts+=( "build_libgcc=yes" )
   137             fi
   138             ;;
   139     esac
   140 
   141     if [ "${do_core}" = "y" ]; then
   142         CT_DoStep INFO "Installing pass-2 core C compiler"
   143         CT_mkdir_pushd "${CT_BUILD_DIR}/build-cc-core-pass-2"
   144 
   145         do_cc_core_backend "${core_opts[@]}"
   146 
   147         CT_Popd
   148         CT_EndStep
   149     fi
   150 }
   151 
   152 #------------------------------------------------------------------------------
   153 # Build core gcc
   154 # This function is used to build the core C compiler.
   155 # Usage: do_cc_core_backend param=value [...]
   156 #   Parameter           : Definition                                : Type      : Default
   157 #   mode                : build a 'static', 'shared' or 'baremetal' : string    : (none)
   158 #   host                : the machine the core will run on          : tuple     : (none)
   159 #   prefix              : dir prefix to install into                : dir       : (none)
   160 #   complibs            : dir where complibs are isntalled          : dir       : (none)
   161 #   build_libgcc        : build libgcc or not                       : bool      : no
   162 #   build_libstdcxx     : build libstdc++ or not                    : bool      : no
   163 #   build_staticlinked  : build statically linked or not            : bool      : no
   164 #   build_manuals       : whether to build manuals or not           : bool      : no
   165 #   cflags              : host CFLAGS to use                        : string    : (empty)
   166 # Usage: do_cc_core_backend mode=[static|shared|baremetal] build_libgcc=[yes|no] build_staticlinked=[yes|no]
   167 do_cc_core_backend() {
   168     local mode
   169     local build_libgcc=no
   170     local build_libstdcxx=no
   171     local build_staticlinked=no
   172     local build_manuals=no
   173     local host
   174     local prefix
   175     local complibs
   176     local lang_opt
   177     local cflags
   178     local tmp
   179     local -a host_libstdcxx_flags
   180     local -a extra_config
   181     local -a core_LDFLAGS
   182     local -a core_targets
   183     local arg
   184 
   185     for arg in "$@"; do
   186         eval "${arg// /\\ }"
   187     done
   188 
   189     CT_DoLog EXTRA "Configuring core C compiler"
   190 
   191     lang_opt=c
   192     case "${mode}" in
   193         static)
   194             extra_config+=("--with-newlib")
   195             extra_config+=("--enable-threads=no")
   196             extra_config+=("--disable-shared")
   197             copy_headers=y  # For baremetal, as there's no headers to copy,
   198                             # we copy an empty directory. So, who cares?
   199             ;;
   200         shared)
   201             extra_config+=("--enable-shared")
   202             copy_headers=y
   203             ;;
   204         baremetal)
   205             extra_config+=("--with-newlib")
   206             extra_config+=("--enable-threads=no")
   207             extra_config+=("--disable-shared")
   208             [ "${CT_CC_LANG_CXX}" = "y" ] && lang_opt="${lang_opt},c++"
   209             copy_headers=n
   210             ;;
   211         *)
   212             CT_Abort "Internal Error: 'mode' must be one of: 'static', 'shared' or 'baremetal', not '${mode:-(empty)}'"
   213             ;;
   214     esac
   215 
   216     if [ "${CT_CC_GCC_HAS_PKGVERSION_BUGURL}" = "y" ]; then
   217         # Bare metal delivers the core compiler as final compiler, so add version info and bugurl
   218         extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
   219         [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
   220     fi
   221 
   222     if [ "${copy_headers}" = "y" ]; then
   223         CT_DoLog DEBUG "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
   224         CT_DoExecLog ALL cp -a "${CT_HEADERS_DIR}" "${prefix}/${CT_TARGET}/include"
   225     fi
   226 
   227     for tmp in ARCH ABI CPU TUNE FPU FLOAT; do
   228         eval tmp="\${CT_ARCH_WITH_${tmp}}"
   229         if [ -n "${tmp}" ]; then
   230             extra_config+=("${tmp}")
   231         fi
   232     done
   233     if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
   234         extra_config+=("--enable-__cxa_atexit")
   235     else
   236         extra_config+=("--disable-__cxa_atexit")
   237     fi
   238 
   239     # *** WARNING ! ***
   240     # Keep this full if-else-if-elif-fi-fi block in sync
   241     # with the same block in do_cc, below.
   242     if [ "${build_staticlinked}" = "yes" ]; then
   243         core_LDFLAGS+=("-static")
   244         host_libstdcxx_flags+=("-static-libgcc")
   245         host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++")
   246         host_libstdcxx_flags+=("-lm")
   247         # Companion libraries are build static (eg !shared), so
   248         # the libstdc++ is not pulled automatically, although it
   249         # is needed. Shoe-horn it in our LDFLAGS
   250         # Ditto libm on some Fedora boxen
   251         core_LDFLAGS+=("-lstdc++")
   252         core_LDFLAGS+=("-lm")
   253     else
   254         if [ "${CT_CC_STATIC_LIBSTDCXX}" = "y" ]; then
   255             # this is from CodeSourcery arm-2010q1-202-arm-none-linux-gnueabi.src.tar.bz2
   256             # build script
   257             # INFO: if the host gcc is gcc-4.5 then presumably we could use -static-libstdc++,
   258             #       see http://gcc.gnu.org/ml/gcc-patches/2009-06/msg01635.html
   259             host_libstdcxx_flags+=("-static-libgcc")
   260             host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++,-Bdynamic")
   261             host_libstdcxx_flags+=("-lm")
   262         elif [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
   263             # When companion libraries are build static (eg !shared),
   264             # the libstdc++ is not pulled automatically, although it
   265             # is needed. Shoe-horn it in our LDFLAGS
   266             # Ditto libm on some Fedora boxen
   267             core_LDFLAGS+=("-lstdc++")
   268             core_LDFLAGS+=("-lm")
   269         fi
   270     fi
   271 
   272     if [ "${CT_CC_GCC_USE_GMP_MPFR}" = "y" ]; then
   273         extra_config+=("--with-gmp=${complibs}")
   274         extra_config+=("--with-mpfr=${complibs}")
   275     fi
   276     if [ "${CT_CC_GCC_USE_MPC}" = "y" ]; then
   277         extra_config+=("--with-mpc=${complibs}")
   278     fi
   279     if [ "${CT_CC_GCC_USE_GRAPHITE}" = "y" ]; then
   280         extra_config+=("--with-ppl=${complibs}")
   281         # With PPL 0.11+, also pull libpwl if needed
   282         if [ "${CT_PPL_NEEDS_LIBPWL}" = "y" ]; then
   283             host_libstdcxx_flags+=("-L${complibs}/lib")
   284             host_libstdcxx_flags+=("-lpwl")
   285         fi
   286         extra_config+=("--with-cloog=${complibs}")
   287     elif [ "${CT_CC_GCC_HAS_GRAPHITE}" = "y" ]; then
   288         extra_config+=("--with-ppl=no")
   289         extra_config+=("--with-cloog=no")
   290     fi
   291     if [ "${CT_CC_GCC_USE_LTO}" = "y" ]; then
   292         extra_config+=("--with-libelf=${complibs}")
   293         extra_config+=("--enable-lto")
   294     elif [ "${CT_CC_GCC_HAS_LTO}" = "y" ]; then
   295         extra_config+=("--with-libelf=no")
   296         extra_config+=("--disable-lto")
   297     fi
   298 
   299     if [ ${#host_libstdcxx_flags[@]} -ne 0 ]; then
   300         extra_config+=("--with-host-libstdcxx=${host_libstdcxx_flags[*]}")
   301     fi
   302 
   303     if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then
   304         extra_config+=("--enable-target-optspace")
   305     fi
   306 
   307     case "${CT_CC_GCC_LDBL_128}" in
   308         y)  extra_config+=("--with-long-double-128");;
   309         m)  ;;
   310         "") extra_config+=("--without-long-double-128");;
   311     esac
   312 
   313     if [ "${CT_CC_GCC_BUILD_ID}" = "y" ]; then
   314         extra_config+=( --enable-linker-build-id )
   315     fi
   316 
   317     case "${CT_CC_GCC_LNK_HASH_STYLE}" in
   318         "") ;;
   319         *)  extra_config+=( "--with-linker-hash-style=${CT_CC_GCC_LNK_HASH_STYLE}" );;
   320     esac
   321 
   322     case "${CT_ARCH}" in
   323         mips)
   324             case "${CT_CC_GCC_mips_llsc}" in
   325                 y)  extra_config+=( --with-llsc );;
   326                 m)  ;;
   327                 *)  extra_config+=( --without-llsc );;
   328             esac
   329             case "${CT_CC_GCC_mips_synci}" in
   330                 y)  extra_config+=( --with-synci );;
   331                 m)  ;;
   332                 *)  extra_config+=( --without-synci );;
   333             esac
   334             if [ "${CT_CC_GCC_mips_plt}" ]; then
   335                 extra_config+=( --with-mips-plt )
   336             fi
   337             ;; # ARCH is mips
   338     esac
   339 
   340     extra_config+=(--disable-libgomp)
   341     extra_config+=(--disable-libmudflap)
   342 
   343     [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && extra_config+=("--disable-nls")
   344 
   345     [ "${CT_CC_GCC_DISABLE_PCH}" = "y" ] && extra_config+=("--disable-libstdcxx-pch")
   346 
   347     if [ "${CT_CC_GCC_SYSTEM_ZLIB}" = "y" ]; then
   348         extra_config+=("--with-system-zlib")
   349     fi
   350 
   351     if [ "${CT_MULTILIB}" = "y" ]; then
   352         extra_config+=("--enable-multilib")
   353     else
   354         extra_config+=("--disable-multilib")
   355     fi
   356 
   357     CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
   358 
   359     # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
   360     CT_DoExecLog CFG                                \
   361     CC_FOR_BUILD="${CT_BUILD}-gcc"                  \
   362     CFLAGS="${cflags}"                              \
   363     LDFLAGS="${core_LDFLAGS[*]}"                    \
   364     "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/configure"  \
   365         --build=${CT_BUILD}                         \
   366         --host=${host}                              \
   367         --target=${CT_TARGET}                       \
   368         --prefix="${prefix}"                        \
   369         --with-local-prefix="${CT_SYSROOT_DIR}"     \
   370         --disable-libmudflap                        \
   371         ${CC_CORE_SYSROOT_ARG}                      \
   372         "${extra_config[@]}"                        \
   373         --enable-languages="${lang_opt}"            \
   374         "${CT_CC_CORE_EXTRA_CONFIG_ARRAY[@]}"
   375 
   376     if [ "${build_libgcc}" = "yes" ]; then
   377         # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
   378         # gcc/config/t-libunwind so -lc is removed from the link for
   379         # libgcc_s.so, as we do not have a target -lc yet.
   380         # This is not as ugly as it appears to be ;-) All symbols get resolved
   381         # during the glibc build, and we provide a proper libgcc_s.so for the
   382         # cross toolchain during the final gcc build.
   383         #
   384         # As we cannot modify the source tree, nor override SHLIB_LC itself
   385         # during configure or make, we have to edit the resultant
   386         # gcc/libgcc.mk itself to remove -lc from the link.
   387         # This causes us to have to jump through some hoops...
   388         #
   389         # To produce libgcc.mk to edit we firstly require libiberty.a,
   390         # so we configure then build it.
   391         # Next we have to configure gcc, create libgcc.mk then edit it...
   392         # So much easier if we just edit the source tree, but hey...
   393         if [ ! -f "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" ]; then
   394             CT_DoExecLog CFG make ${JOBSFLAGS} configure-libiberty
   395             CT_DoExecLog ALL make ${JOBSFLAGS} -C libiberty libiberty.a
   396             CT_DoExecLog CFG make ${JOBSFLAGS} configure-gcc configure-libcpp
   397             CT_DoExecLog ALL make ${JOBSFLAGS} all-libcpp
   398         else
   399             CT_DoExecLog CFG make ${JOBSFLAGS} configure-gcc configure-libcpp configure-build-libiberty
   400             CT_DoExecLog ALL make ${JOBSFLAGS} all-libcpp all-build-libiberty
   401         fi
   402         # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
   403         if [ -d "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/libdecnumber" ]; then
   404             CT_DoExecLog CFG make ${JOBSFLAGS} configure-libdecnumber
   405             CT_DoExecLog ALL make ${JOBSFLAGS} -C libdecnumber libdecnumber.a
   406         fi
   407 
   408         # Starting with GCC 4.3, libgcc.mk is no longer built,
   409         # and libgcc.mvars is used instead.
   410 
   411         if [ "${CT_CC_GCC_4_3_or_later}" = "y" ]; then
   412             libgcc_rule="libgcc.mvars"
   413             core_targets=( gcc target-libgcc )
   414         else
   415             libgcc_rule="libgcc.mk"
   416             core_targets=( gcc )
   417         fi
   418 
   419         # On bare metal and canadian build the host-compiler is used when
   420         # actually the build-system compiler is required. Choose the correct
   421         # compilers for canadian build and use the defaults on other
   422         # configurations.
   423         if [ "${CT_BARE_METAL},${CT_CANADIAN}" = "y,y" ]; then
   424             repair_cc="CC_FOR_BUILD=${CT_BUILD}-gcc \
   425                        GCC_FOR_TARGET=${CT_TARGET}-gcc"
   426         else
   427             repair_cc=""
   428         fi
   429 
   430         CT_DoExecLog ALL make ${JOBSFLAGS} -C gcc ${libgcc_rule} \
   431                               ${repair_cc}
   432         sed -r -i -e 's@-lc@@g' gcc/${libgcc_rule}
   433     else # build_libgcc
   434         core_targets=( gcc )
   435     fi   # ! build libgcc
   436     if [    "${build_libstdcxx}" = "yes"    \
   437          -a "${CT_CC_LANG_CXX}"  = "y"      \
   438        ]; then
   439         core_targets+=( target-libstdc++-v3 )
   440     fi
   441 
   442     CT_DoLog EXTRA "Building core C compiler"
   443     CT_DoExecLog ALL make ${JOBSFLAGS} "${core_targets[@]/#/all-}"
   444 
   445     CT_DoLog EXTRA "Installing core C compiler"
   446     CT_DoExecLog ALL make ${JOBSFLAGS} "${core_targets[@]/#/install-}"
   447 
   448     if [ "${build_manuals}" = "yes" ]; then
   449         CT_DoLog EXTRA "Building the GCC manuals"
   450         CT_DoExecLog ALL make pdf html
   451         CT_DoLog EXTRA "Installing the GCC manuals"
   452         CT_DoExecLog ALL make install-{pdf,html}-gcc
   453     fi
   454 
   455     # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
   456     # to call the C compiler with the same, somewhat canonical name.
   457     # check whether compiler has an extension
   458     file="$( ls -1 "${prefix}/bin/${CT_TARGET}-gcc."* 2>/dev/null || true )"
   459     [ -z "${file}" ] || ext=".${file##*.}"
   460     CT_DoExecLog ALL ln -sfv "${CT_TARGET}-gcc${ext}" "${prefix}/bin/${CT_TARGET}-cc${ext}"
   461 
   462     if [ "${CT_MULTILIB}" = "y" ]; then
   463         multilibs=( $( "${prefix}/bin/${CT_TARGET}-gcc" -print-multi-lib   \
   464                        |tail -n +2 ) )
   465         if [ ${#multilibs[@]} -ne 0 ]; then
   466             CT_DoLog EXTRA "gcc configured with these multilibs (besides the default):"
   467             for i in "${multilibs[@]}"; do
   468                 dir="${i%%;*}"
   469                 flags="${i#*;}"
   470                 CT_DoLog EXTRA "   ${flags//@/ -}  -->  ${dir}/"
   471             done
   472         else
   473             CT_DoLog WARN "gcc configured for multilib, but none available"
   474         fi
   475     fi
   476 }
   477 
   478 #------------------------------------------------------------------------------
   479 # Build final gcc
   480 do_cc() {
   481     local -a final_opts
   482     local final_backend
   483 
   484     final_opts+=( "host=${CT_HOST}" )
   485     final_opts+=( "prefix=${CT_PREFIX_DIR}" )
   486     final_opts+=( "complibs=${CT_COMPLIBS_DIR}" )
   487     final_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
   488     if [ "${CT_BUILD_MANUALS}" = "y" ]; then
   489         final_opts+=( "build_manuals=yes" )
   490     fi
   491     if [ "${CT_BARE_METAL}" = "y" ]; then
   492         final_opts+=( "mode=baremetal" )
   493         final_opts+=( "build_libgcc=yes" )
   494         final_opts+=( "build_libstdcxx=yes" )
   495         if [ "${CT_STATIC_TOOLCHAIN}" = "y" ]; then
   496             final_opts+=( "build_staticlinked=yes" )
   497         fi
   498         final_backend=do_cc_core_backend
   499     else
   500         final_backend=do_cc_backend
   501     fi
   502 
   503     CT_DoStep INFO "Installing final compiler"
   504     CT_mkdir_pushd "${CT_BUILD_DIR}/build-cc-final"
   505 
   506     "${final_backend}" "${final_opts[@]}"
   507 
   508     CT_Popd
   509     CT_EndStep
   510 }
   511 
   512 #------------------------------------------------------------------------------
   513 # Build the final gcc
   514 # Usage: do_cc_backend param=value [...]
   515 #   Parameter     : Definition                          : Type      : Default
   516 #   host          : the host we run onto                : tuple     : (none)
   517 #   prefix        : the runtime prefix                  : dir       : (none)
   518 #   complibs      : the companion libraries prefix      : dir       : (none)
   519 #   cflags        : the host CFLAGS                     : string    : (empty)
   520 #   build_manuals : whether to build manuals or not     : bool      : no
   521 do_cc_backend() {
   522     local host
   523     local prefix
   524     local complibs
   525     local cflags
   526     local build_manuals
   527     local -a host_libstdcxx_flags
   528     local -a extra_config
   529     local -a final_LDFLAGS
   530     local tmp
   531     local arg
   532 
   533     for arg in "$@"; do
   534         eval "${arg// /\\ }"
   535     done
   536 
   537     CT_DoLog EXTRA "Configuring final compiler"
   538 
   539     # Enable selected languages
   540     lang_opt="c"
   541     [ "${CT_CC_LANG_CXX}" = "y"      ] && lang_opt="${lang_opt},c++"
   542     [ "${CT_CC_LANG_FORTRAN}" = "y"  ] && lang_opt="${lang_opt},fortran"
   543     [ "${CT_CC_LANG_ADA}" = "y"      ] && lang_opt="${lang_opt},ada"
   544     [ "${CT_CC_LANG_JAVA}" = "y"     ] && lang_opt="${lang_opt},java"
   545     [ "${CT_CC_LANG_OBJC}" = "y"     ] && lang_opt="${lang_opt},objc"
   546     [ "${CT_CC_LANG_OBJCXX}" = "y"   ] && lang_opt="${lang_opt},obj-c++"
   547     CT_Test "Building ADA language is not yet supported. Will try..." "${CT_CC_LANG_ADA}" = "y"
   548     CT_Test "Building Objective-C language is not yet supported. Will try..." "${CT_CC_LANG_OBJC}" = "y"
   549     CT_Test "Building Objective-C++ language is not yet supported. Will try..." "${CT_CC_LANG_OBJCXX}" = "y"
   550     CT_Test "Building ${CT_CC_LANG_OTHERS//,/ } language(s) is not yet supported. Will try..." -n "${CT_CC_LANG_OTHERS}"
   551     lang_opt=$(echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;')
   552 
   553     extra_config+=("--enable-languages=${lang_opt}")
   554     for tmp in ARCH ABI CPU TUNE FPU FLOAT; do
   555         eval tmp="\${CT_ARCH_WITH_${tmp}}"
   556         if [ -n "${tmp}" ]; then
   557             extra_config+=("${tmp}")
   558         fi
   559     done
   560 
   561     [ "${CT_SHARED_LIBS}" = "y" ] || extra_config+=("--disable-shared")
   562     if [ "${CT_CC_GCC_HAS_PKGVERSION_BUGURL}" = "y" ]; then
   563         extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
   564         [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
   565     fi
   566     case "${CT_CC_GCC_SJLJ_EXCEPTIONS}" in
   567         y)  extra_config+=("--enable-sjlj-exceptions");;
   568         m)  ;;
   569         "") extra_config+=("--disable-sjlj-exceptions");;
   570     esac
   571     if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
   572         extra_config+=("--enable-__cxa_atexit")
   573     else
   574         extra_config+=("--disable-__cxa_atexit")
   575     fi
   576     if [ -n "${CT_CC_ENABLE_CXX_FLAGS}" ]; then
   577         extra_config+=("--enable-cxx-flags=${CT_CC_ENABLE_CXX_FLAGS}")
   578     fi
   579     if [ "${CT_CC_GCC_LIBMUDFLAP}" = "y" ]; then
   580         extra_config+=(--enable-libmudflap)
   581     else
   582         extra_config+=(--disable-libmudflap)
   583     fi
   584     if [ "${CT_CC_GCC_LIBGOMP}" = "y" ]; then
   585         extra_config+=(--enable-libgomp)
   586     else
   587         extra_config+=(--disable-libgomp)
   588     fi
   589     if [ "${CT_CC_GCC_LIBSSP}" = "y" ]; then
   590         extra_config+=(--enable-libssp)
   591     else
   592         extra_config+=(--disable-libssp)
   593     fi
   594 
   595     # *** WARNING ! ***
   596     # Keep this full if-else-if-elif-fi-fi block in sync
   597     # with the same block in do_cc_core, above.
   598     if [ "${CT_STATIC_TOOLCHAIN}" = "y" ]; then
   599         final_LDFLAGS+=("-static")
   600         host_libstdcxx_flags+=("-static-libgcc")
   601         host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++")
   602         host_libstdcxx_flags+=("-lm")
   603         # Companion libraries are build static (eg !shared), so
   604         # the libstdc++ is not pulled automatically, although it
   605         # is needed. Shoe-horn it in our LDFLAGS
   606         # Ditto libm on some Fedora boxen
   607         final_LDFLAGS+=("-lstdc++")
   608         final_LDFLAGS+=("-lm")
   609     else
   610         if [ "${CT_CC_STATIC_LIBSTDCXX}" = "y" ]; then
   611             # this is from CodeSourcery arm-2010q1-202-arm-none-linux-gnueabi.src.tar.bz2
   612             # build script
   613             # INFO: if the host gcc is gcc-4.5 then presumably we could use -static-libstdc++,
   614             #       see http://gcc.gnu.org/ml/gcc-patches/2009-06/msg01635.html
   615             host_libstdcxx_flags+=("-static-libgcc")
   616             host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++,-Bdynamic")
   617             host_libstdcxx_flags+=("-lm")
   618         elif [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
   619             # When companion libraries are build static (eg !shared),
   620             # the libstdc++ is not pulled automatically, although it
   621             # is needed. Shoe-horn it in our LDFLAGS
   622             # Ditto libm on some Fedora boxen
   623             final_LDFLAGS+=("-lstdc++")
   624             final_LDFLAGS+=("-lm")
   625         fi
   626     fi
   627 
   628     if [ "${CT_CC_GCC_USE_GMP_MPFR}" = "y" ]; then
   629         extra_config+=("--with-gmp=${complibs}")
   630         extra_config+=("--with-mpfr=${complibs}")
   631     fi
   632     if [ "${CT_CC_GCC_USE_MPC}" = "y" ]; then
   633         extra_config+=("--with-mpc=${complibs}")
   634     fi
   635     if [ "${CT_CC_GCC_USE_GRAPHITE}" = "y" ]; then
   636         extra_config+=("--with-ppl=${complibs}")
   637         # With PPL 0.11+, also pull libpwl if needed
   638         if [ "${CT_PPL_NEEDS_LIBPWL}" = "y" ]; then
   639             host_libstdcxx_flags+=("-L${complibs}/lib")
   640             host_libstdcxx_flags+=("-lpwl")
   641         fi
   642         extra_config+=("--with-cloog=${complibs}")
   643     elif [ "${CT_CC_GCC_HAS_GRAPHITE}" = "y" ]; then
   644         extra_config+=("--with-ppl=no")
   645         extra_config+=("--with-cloog=no")
   646     fi
   647     if [ "${CT_CC_GCC_USE_LTO}" = "y" ]; then
   648         extra_config+=("--with-libelf=${complibs}")
   649     elif [ "${CT_CC_GCC_HAS_LTO}" = "y" ]; then
   650         extra_config+=("--with-libelf=no")
   651     fi
   652 
   653     if [ ${#host_libstdcxx_flags[@]} -ne 0 ]; then
   654         extra_config+=("--with-host-libstdcxx=${host_libstdcxx_flags[*]}")
   655     fi
   656 
   657     if [ "${CT_THREADS}" = "none" ]; then
   658         extra_config+=("--disable-threads")
   659         if [ "${CT_CC_GCC_4_2_or_later}" = y ]; then
   660             CT_Test "Disabling libgomp for no-thread gcc>=4.2" "${CT_CC_GCC_LIBGOMP}" = "Y"
   661             extra_config+=("--disable-libgomp")
   662         fi
   663     else
   664         if [ "${CT_THREADS}" = "win32" ]; then
   665             extra_config+=("--enable-threads=win32")
   666             extra_config+=("--disable-win32-registry")
   667         else
   668             extra_config+=("--enable-threads=posix")
   669         fi
   670     fi
   671 
   672     if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then
   673         extra_config+=("--enable-target-optspace")
   674     fi
   675     if [ "${CT_CC_GCC_DISABLE_PCH}" = "y" ]; then
   676         extra_config+=("--disable-libstdcxx-pch")
   677     fi
   678 
   679     case "${CT_CC_GCC_LDBL_128}" in
   680         y)  extra_config+=("--with-long-double-128");;
   681         m)  ;;
   682         "") extra_config+=("--without-long-double-128");;
   683     esac
   684 
   685     if [ "${CT_CC_GCC_BUILD_ID}" = "y" ]; then
   686         extra_config+=( --enable-linker-build-id )
   687     fi
   688 
   689     case "${CT_CC_GCC_LNK_HASH_STYLE}" in
   690         "") ;;
   691         *)  extra_config+=( "--with-linker-hash-style=${CT_CC_GCC_LNK_HASH_STYLE}" );;
   692     esac
   693 
   694     if [ "${CT_CC_GCC_ENABLE_PLUGINS}" = "y" ]; then
   695         extra_config+=( --enable-plugin )
   696     fi
   697     if [ "${CT_CC_GCC_GOLD}" = "y" ]; then
   698         extra_config+=( --enable-gold )
   699     fi
   700 
   701     case "${CT_ARCH}" in
   702         mips)
   703             case "${CT_CC_GCC_mips_llsc}" in
   704                 y)  extra_config+=( --with-llsc );;
   705                 m)  ;;
   706                 *)  extra_config+=( --without-llsc );;
   707             esac
   708             case "${CT_CC_GCC_mips_synci}" in
   709                 y)  extra_config+=( --with-synci );;
   710                 m)  ;;
   711                 *)  extra_config+=( --without-synci );;
   712             esac
   713             if [ "${CT_CC_GCC_mips_plt}" ]; then
   714                 extra_config+=( --with-mips-plt )
   715             fi
   716             ;; # ARCH is mips
   717     esac
   718 
   719     [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && extra_config+=("--disable-nls")
   720 
   721     if [ "${CT_CC_GCC_SYSTEM_ZLIB}" = "y" ]; then
   722         extra_config+=("--with-system-zlib")
   723     fi
   724 
   725     if [ "${CT_MULTILIB}" = "y" ]; then
   726         extra_config+=("--enable-multilib")
   727     else
   728         extra_config+=("--disable-multilib")
   729     fi
   730 
   731     CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
   732 
   733     CT_DoExecLog CFG                                \
   734     CC_FOR_BUILD="${CT_BUILD}-gcc"                  \
   735     CFLAGS="${cflags}"                              \
   736     LDFLAGS="${final_LDFLAGS[*]}"                   \
   737     CFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}"         \
   738     CXXFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}"       \
   739     LDFLAGS_FOR_TARGET="${CT_TARGET_LDFLAGS}"       \
   740     "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/configure"  \
   741         --build=${CT_BUILD}                         \
   742         --host=${host}                              \
   743         --target=${CT_TARGET}                       \
   744         --prefix="${prefix}"                        \
   745         ${CC_SYSROOT_ARG}                           \
   746         "${extra_config[@]}"                        \
   747         --with-local-prefix="${CT_SYSROOT_DIR}"     \
   748         --enable-c99                                \
   749         --enable-long-long                          \
   750         "${CT_CC_EXTRA_CONFIG_ARRAY[@]}"
   751 
   752     if [ "${CT_CANADIAN}" = "y" ]; then
   753         CT_DoLog EXTRA "Building libiberty"
   754         CT_DoExecLog ALL make ${JOBSFLAGS} all-build-libiberty
   755     fi
   756 
   757     CT_DoLog EXTRA "Building final compiler"
   758     CT_DoExecLog ALL make ${JOBSFLAGS} all
   759 
   760     CT_DoLog EXTRA "Installing final compiler"
   761     CT_DoExecLog ALL make ${JOBSFLAGS} install
   762 
   763     if [ "${build_manuals}" = "yes" ]; then
   764         CT_DoLog EXTRA "Building the GCC manuals"
   765         CT_DoExecLog ALL make ${JOBSFLAGS} pdf html
   766         CT_DoLog EXTRA "Installing the GCC manuals"
   767         CT_DoExecLog ALL make install-{pdf,html}-gcc
   768     fi
   769 
   770     # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
   771     # to call the C compiler with the same, somewhat canonical name.
   772     # check whether compiler has an extension
   773     file="$( ls -1 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-gcc."* 2>/dev/null || true )"
   774     [ -z "${file}" ] || ext=".${file##*.}"
   775     CT_DoExecLog ALL ln -sfv "${CT_TARGET}-gcc${ext}" "${CT_PREFIX_DIR}/bin/${CT_TARGET}-cc${ext}"
   776 
   777     if [ "${CT_MULTILIB}" = "y" ]; then
   778         multilibs=( $( "${CT_PREFIX_DIR}/bin/${CT_TARGET}-gcc" -print-multi-lib \
   779                        |tail -n +2 ) )
   780         if [ ${#multilibs[@]} -ne 0 ]; then
   781             CT_DoLog EXTRA "gcc configured with these multilibs (besides the default):"
   782             for i in "${multilibs[@]}"; do
   783                 dir="${i%%;*}"
   784                 flags="${i#*;}"
   785                 CT_DoLog EXTRA "   ${flags//@/ -}  -->  ${dir}/"
   786             done
   787         else
   788             CT_DoLog WARN "gcc configured for multilib, but none available"
   789         fi
   790     fi
   791 }