scripts/build/cc/gcc.sh
author Zhenqiang Chen <zhenqiang.chen@linaro.org>
Mon Feb 27 15:24:18 2012 +0800 (2012-02-27)
changeset 2901 4fcedd2c14b2
parent 2900 369e2fbe9010
child 2924 0eab838768b1
permissions -rw-r--r--
cc/gcc: Update core_prefix_dir to prefix.

core_prefix_dir is not defined. It should be prefix.

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