scripts/build/cc/gcc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon Aug 15 21:42:28 2011 +0200 (2011-08-15)
changeset 2932 c1f65d6a9a13
parent 2931 8a72662f0815
child 2933 be5d4773a894
permissions -rw-r--r--
cc/gcc: add language helper function

Add a function that prepares the language configure option.
It is needed in at least two places, some commonalisation is needed. ;-)

Unfortunately, it is no longer possible to print warnings about experimental
languages any more. Anyway, the experimental status is clearly indicated
in the menuconfig. so it should not be a surprise if the build breaks. :-/

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