scripts/build/cc/gcc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon Jul 25 19:04:00 2011 +0200 (2011-07-25)
changeset 2930 79201a2826fd
parent 2925 d99b1adc4402
child 2931 8a72662f0815
permissions -rw-r--r--
cc/gcc: cleanup the frontends

A few noop fix-ups:
- fix the comments in core pass-1
- commonalise settings that can be

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