scripts/build/cc/gcc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Nov 20 18:08:00 2011 +0100 (2011-11-20)
changeset 2887 6ee3b25e1097
parent 2886 f1ad0445325c
child 2888 dd71df95903a
permissions -rw-r--r--
cc/gcc: rename the core backend function

Rename the core backend function to do_cc_core_backend, to
make it explicit it is a backend.

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