scripts/build/cc/gcc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jun 13 23:38:37 2010 +0200 (2010-06-13)
changeset 1983 198a5a6e5239
parent 1981 7130357d712b
child 1991 1974075aa641
permissions -rw-r--r--
cc/gcc: baremetal requires a two-pass process

Here, we implement a highly ugly hack. I'm not proud of that one...

To build the libstdc++ library, the compiler requires the C library. In
case we build for non-baremetal, this is normally handled by the final
step, later.

But in the case of bare-metal, we never go through the final step (because
it does not work, and it seems complex enough to make it work), so the
baremetal compilers are issued out of the core step.
yann@850
     1
# This file adds the function to build the gcc C compiler
yann@850
     2
# Copyright 2007 Yann E. MORIN
yann@850
     3
# Licensed under the GPL v2. See COPYING in the root of this package
yann@850
     4
yann@850
     5
# Download gcc
yann@850
     6
do_cc_get() {
yann@850
     7
    # Ah! gcc folks are kind of 'different': they store the tarballs in
yann@850
     8
    # subdirectories of the same name! That's because gcc is such /crap/ that
yann@850
     9
    # it is such /big/ that it needs being splitted for distribution! Sad. :-(
yann@850
    10
    # Arrgghh! Some of those versions does not follow this convention:
yann@850
    11
    # gcc-3.3.3 lives in releases/gcc-3.3.3, while gcc-2.95.* isn't in a
yann@850
    12
    # subdirectory! You bastard!
yann@1389
    13
    CT_GetFile "gcc-${CT_CC_VERSION}"                                                       \
yann@1389
    14
               {ftp,http}://ftp.gnu.org/gnu/gcc{,{,/releases}/gcc-${CT_CC_VERSION}}         \
yann@1389
    15
               ftp://ftp.irisa.fr/pub/mirrors/gcc.gnu.org/gcc/releases/gcc-${CT_CC_VERSION} \
yann@1389
    16
               ftp://ftp.uvsq.fr/pub/gcc/snapshots/${CT_CC_VERSION}
yann@1268
    17
yann@1129
    18
    # Starting with GCC 4.3, ecj is used for Java, and will only be
yann@1129
    19
    # built if the configure script finds ecj.jar at the top of the
yann@1129
    20
    # GCC source tree, which will not be there unless we get it and
yann@1129
    21
    # put it there ourselves
yann@1129
    22
    if [ "${CT_CC_LANG_JAVA_USE_ECJ}" = "y" ]; then
yann@1129
    23
        CT_GetFile ecj-latest .jar ftp://gcc.gnu.org/pub/java   \
yann@1129
    24
                                   ftp://sourceware.org/pub/java
yann@1129
    25
    fi
yann@850
    26
}
yann@850
    27
yann@850
    28
# Extract gcc
yann@850
    29
do_cc_extract() {
yann@1389
    30
    CT_Extract "gcc-${CT_CC_VERSION}"
yann@1901
    31
    CT_Patch "gcc" "${CT_CC_VERSION}"
yann@1268
    32
yann@1129
    33
    # Copy ecj-latest.jar to ecj.jar at the top of the GCC source tree
yann@1389
    34
    if [ "${CT_CC_LANG_JAVA_USE_ECJ}" = "y"                     \
yann@1389
    35
         -a ! -f "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/ecj.jar"   \
yann@1259
    36
       ]; then
yann@1389
    37
        CT_DoExecLog ALL cp -v "${CT_TARBALLS_DIR}/ecj-latest.jar" "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/ecj.jar"
yann@1129
    38
    fi
yann@850
    39
}
yann@850
    40
yann@850
    41
#------------------------------------------------------------------------------
yann@850
    42
# Core gcc pass 1
yann@850
    43
do_cc_core_pass_1() {
yann@850
    44
    # If we're building for bare metal, build the static core gcc,
yann@850
    45
    # with libgcc.
linux@1925
    46
    # In case we're not bare metal and building a canadian compiler, do nothing
yann@850
    47
    # In case we're not bare metal, and we're NPTL, build the static core gcc.
yann@850
    48
    # In any other case, do nothing.
linux@1925
    49
    case "${CT_BARE_METAL},${CT_CANADIAN},${CT_THREADS}" in
yann@1983
    50
        y,*,*)  do_cc_core mode=static;;
linux@1925
    51
        ,y,*)   ;;
yann@1980
    52
        ,,nptl) do_cc_core mode=static;;
yann@850
    53
        *)      ;;
yann@850
    54
    esac
yann@850
    55
}
yann@850
    56
yann@850
    57
# Core gcc pass 2
yann@850
    58
do_cc_core_pass_2() {
yann@850
    59
    # In case we're building for bare metal, do nothing, we already have
yann@850
    60
    # our compiler.
linux@1925
    61
    # In case we're not bare metal and building a canadian compiler, do nothing
yann@892
    62
    # In case we're NPTL, build the shared core gcc and the target libgcc.
yann@892
    63
    # In any other case, build the static core gcc and, if using gcc-4.3+,
yann@892
    64
    # also build the target libgcc.
linux@1925
    65
    case "${CT_BARE_METAL},${CT_CANADIAN},${CT_THREADS}" in
yann@1983
    66
        y,*,*)  do_cc_core mode=baremetal build_libgcc=yes build_libstdcxx=yes;;
yann@1983
    67
        ,y,*)   ;;
linux@1925
    68
        ,,nptl)
yann@892
    69
            do_cc_core mode=shared build_libgcc=yes
yann@892
    70
            ;;
yann@892
    71
        *)  if [ "${CT_CC_GCC_4_3_or_later}" = "y" ]; then
yann@892
    72
                do_cc_core mode=static build_libgcc=yes
yann@892
    73
            else
yann@1980
    74
                do_cc_core mode=static
yann@892
    75
            fi
yann@892
    76
            ;;
yann@850
    77
    esac
yann@850
    78
}
yann@850
    79
yann@850
    80
#------------------------------------------------------------------------------
yann@850
    81
# Build core gcc
yann@850
    82
# This function is used to build both the static and the shared core C conpiler,
yann@850
    83
# with or without the target libgcc. We need to know wether:
yann@850
    84
#  - we're building static, shared or bare metal: mode=[static|shared|baremetal]
yann@1980
    85
#  - we need to build libgcc or not             : build_libgcc=[yes|no]     (default: no)
yann@1983
    86
#  - we need to build libstdc++ or not          : build_libstdcxx=[yes|no]  (default: no)
yann@850
    87
# Usage: do_cc_core_static mode=[static|shared|baremetal] build_libgcc=[yes|no]
yann@850
    88
do_cc_core() {
yann@850
    89
    local mode
yann@1980
    90
    local build_libgcc=no
yann@1983
    91
    local build_libstdcxx=no
yann@850
    92
    local core_prefix_dir
yann@1107
    93
    local lang_opt
yann@1479
    94
    local tmp
yann@1479
    95
    local -a extra_config
yann@1892
    96
    local core_LDFLAGS
yann@1981
    97
    local -a core_targets
yann@850
    98
yann@1980
    99
    while [ $# -ne 0 ]; do
yann@1980
   100
        eval "${1}"
yann@1980
   101
        shift
yann@1980
   102
    done
yann@850
   103
yann@1107
   104
    lang_opt=c
yann@850
   105
    case "${mode}" in
yann@850
   106
        static)
yann@850
   107
            core_prefix_dir="${CT_CC_CORE_STATIC_PREFIX_DIR}"
yann@1479
   108
            extra_config+=("--with-newlib")
yann@1479
   109
            extra_config+=("--enable-threads=no")
yann@1479
   110
            extra_config+=("--disable-shared")
yann@1983
   111
            copy_headers=y  # For baremetal, as there's no headers to copy,
yann@1983
   112
                            # we copy an empty directory. So, who cares?
yann@850
   113
            ;;
yann@850
   114
        shared)
yann@850
   115
            core_prefix_dir="${CT_CC_CORE_SHARED_PREFIX_DIR}"
yann@1479
   116
            extra_config+=("--enable-shared")
yann@850
   117
            copy_headers=y
yann@850
   118
            ;;
yann@850
   119
        baremetal)
yann@850
   120
            core_prefix_dir="${CT_PREFIX_DIR}"
yann@1479
   121
            extra_config+=("--with-newlib")
yann@1479
   122
            extra_config+=("--enable-threads=no")
yann@1479
   123
            extra_config+=("--disable-shared")
yann@1107
   124
            [ "${CT_CC_LANG_CXX}" = "y" ] && lang_opt="${lang_opt},c++"
yann@850
   125
            copy_headers=n
yann@850
   126
            ;;
yann@1980
   127
        *)
yann@1980
   128
            CT_Abort "Internal Error: 'mode' must be one of: 'static', 'shared' or 'baremetal', not '${mode:-(empty)}'"
yann@1980
   129
            ;;
yann@850
   130
    esac
yann@850
   131
yann@1980
   132
    CT_DoStep INFO "Installing ${mode} core C compiler"
yann@1980
   133
    mkdir -p "${CT_BUILD_DIR}/build-cc-core-${mode}"
yann@1980
   134
    cd "${CT_BUILD_DIR}/build-cc-core-${mode}"
yann@1980
   135
linux@1898
   136
    # Bare metal delivers the core compiler as final compiler, so add version info and bugurl
linux@1898
   137
    [ -n "${CT_CC_BUGURL}" ]     && extra_config+=("--with-bugurl=${CT_CC_BUGURL}")
linux@1898
   138
    [ -n "${CT_CC_PKGVERSION}" ] && extra_config+=("--with-pkgversion=${CT_CC_PKGVERSION}")
linux@1898
   139
yann@850
   140
    if [ "${copy_headers}" = "y" ]; then
yann@850
   141
        CT_DoLog DEBUG "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
yann@1979
   142
        CT_DoExecLog ALL cp -a "${CT_HEADERS_DIR}" "${core_prefix_dir}/${CT_TARGET}/include"
yann@850
   143
    fi
yann@850
   144
yann@850
   145
    CT_DoLog EXTRA "Configuring ${mode} core C compiler"
yann@850
   146
yann@1479
   147
    for tmp in ARCH ABI CPU TUNE FPU FLOAT; do
yann@1479
   148
        eval tmp="\${CT_ARCH_WITH_${tmp}}"
yann@1479
   149
        if [ -n "${tmp}" ]; then
yann@1479
   150
            extra_config+=("${tmp}")
yann@1479
   151
        fi
yann@1479
   152
    done
yann@850
   153
    if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
yann@1479
   154
        extra_config+=("--enable-__cxa_atexit")
yann@850
   155
    else
yann@1479
   156
        extra_config+=("--disable-__cxa_atexit")
yann@850
   157
    fi
yann@850
   158
yann@1892
   159
    # When companion libraries are build static (eg !shared),
yann@1892
   160
    # the libstdc++ is not pulled automatically, although it
yann@1892
   161
    # is needed. Shoe-horn it in our LDFLAGS
yann@1893
   162
    if [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
yann@1892
   163
        core_LDFLAGS='-lstdc++'
yann@1892
   164
    fi
yann@1893
   165
    if [ "${CT_CC_GCC_USE_GMP_MPFR}" = "y" ]; then
yann@1893
   166
        extra_config+=("--with-gmp=${CT_COMPLIBS_DIR}")
yann@1893
   167
        extra_config+=("--with-mpfr=${CT_COMPLIBS_DIR}")
yann@1893
   168
    fi
yann@1893
   169
    if [ "${CT_CC_GCC_USE_PPL_CLOOG_MPC}" = "y" ]; then
yann@1893
   170
        extra_config+=("--with-ppl=${CT_COMPLIBS_DIR}")
yann@1893
   171
        extra_config+=("--with-cloog=${CT_COMPLIBS_DIR}")
yann@1893
   172
        extra_config+=("--with-mpc=${CT_COMPLIBS_DIR}")
yann@1893
   173
    fi
yann@1920
   174
    if [ "${CT_CC_GCC_USE_LIBELF}" = "y" ]; then
yann@1920
   175
        extra_config+=("--with-libelf=${CT_COMPLIBS_DIR}")
yann@1920
   176
    fi
yann@1893
   177
titus@1972
   178
    if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then
titus@1972
   179
        extra_config+=("--enable-target-optspace")
titus@1972
   180
    fi
titus@1972
   181
yann@1893
   182
    CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
yann@1892
   183
yann@850
   184
    # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
yann@1041
   185
    CC_FOR_BUILD="${CT_BUILD}-gcc"                  \
yann@850
   186
    CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
yann@1892
   187
    LDFLAGS="${core_LDFLAGS}"                       \
yann@850
   188
    CT_DoExecLog ALL                                \
yann@1389
   189
    "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/configure"  \
yann@1041
   190
        --build=${CT_BUILD}                         \
yann@850
   191
        --host=${CT_HOST}                           \
yann@850
   192
        --target=${CT_TARGET}                       \
yann@850
   193
        --prefix="${core_prefix_dir}"               \
yann@850
   194
        --with-local-prefix="${CT_SYSROOT_DIR}"     \
yann@850
   195
        --disable-multilib                          \
yann@850
   196
        ${CC_CORE_SYSROOT_ARG}                      \
yann@1479
   197
        "${extra_config[@]}"                        \
yann@850
   198
        --disable-nls                               \
yann@850
   199
        --enable-symvers=gnu                        \
yann@1107
   200
        --enable-languages="${lang_opt}"            \
yann@850
   201
        ${CT_CC_CORE_EXTRA_CONFIG}
yann@850
   202
yann@850
   203
    if [ "${build_libgcc}" = "yes" ]; then
yann@850
   204
        # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
yann@850
   205
        # gcc/config/t-libunwind so -lc is removed from the link for
yann@850
   206
        # libgcc_s.so, as we do not have a target -lc yet.
yann@850
   207
        # This is not as ugly as it appears to be ;-) All symbols get resolved
yann@850
   208
        # during the glibc build, and we provide a proper libgcc_s.so for the
yann@850
   209
        # cross toolchain during the final gcc build.
yann@850
   210
        #
yann@850
   211
        # As we cannot modify the source tree, nor override SHLIB_LC itself
yann@850
   212
        # during configure or make, we have to edit the resultant
yann@850
   213
        # gcc/libgcc.mk itself to remove -lc from the link.
yann@850
   214
        # This causes us to have to jump through some hoops...
yann@850
   215
        #
yann@850
   216
        # To produce libgcc.mk to edit we firstly require libiberty.a,
yann@850
   217
        # so we configure then build it.
yann@850
   218
        # Next we have to configure gcc, create libgcc.mk then edit it...
yann@850
   219
        # So much easier if we just edit the source tree, but hey...
yann@1389
   220
        if [ ! -f "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" ]; then
yann@850
   221
            CT_DoExecLog ALL make configure-libiberty
yann@850
   222
            CT_DoExecLog ALL make ${PARALLELMFLAGS} -C libiberty libiberty.a
yann@850
   223
            CT_DoExecLog ALL make configure-gcc configure-libcpp
yann@850
   224
            CT_DoExecLog ALL make ${PARALLELMFLAGS} all-libcpp
yann@850
   225
        else
yann@850
   226
            CT_DoExecLog ALL make configure-gcc configure-libcpp configure-build-libiberty
yann@850
   227
            CT_DoExecLog ALL make ${PARALLELMFLAGS} all-libcpp all-build-libiberty
yann@850
   228
        fi
yann@850
   229
        # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
yann@1389
   230
        if [ -d "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/libdecnumber" ]; then
yann@850
   231
            CT_DoExecLog ALL make configure-libdecnumber
yann@850
   232
            CT_DoExecLog ALL make ${PARALLELMFLAGS} -C libdecnumber libdecnumber.a
yann@850
   233
        fi
yann@850
   234
yann@850
   235
        # Starting with GCC 4.3, libgcc.mk is no longer built,
yann@850
   236
        # and libgcc.mvars is used instead.
yann@850
   237
yann@892
   238
        if [ "${CT_CC_GCC_4_3_or_later}" = "y" ]; then
yann@850
   239
            libgcc_rule="libgcc.mvars"
yann@1981
   240
            core_targets=( gcc target-libgcc )
yann@850
   241
        else
yann@850
   242
            libgcc_rule="libgcc.mk"
yann@1981
   243
            core_targets=( gcc )
yann@850
   244
        fi
yann@850
   245
linux@1926
   246
        # On bare metal and canadian build the host-compiler is used when
linux@1926
   247
        # actually the build-system compiler is required. Choose the correct
linux@1926
   248
        # compilers for canadian build and use the defaults on other
linux@1926
   249
        # configurations.
linux@1926
   250
        if [ "${CT_BARE_METAL},${CT_CANADIAN}" = "y,y" ]; then
linux@1926
   251
            repair_cc="CC_FOR_BUILD=${CT_BUILD}-gcc \
linux@1926
   252
                       GCC_FOR_TARGET=${CT_TARGET}-gcc"
linux@1926
   253
        else
linux@1926
   254
            repair_cc=""
linux@1926
   255
        fi
linux@1926
   256
linux@1926
   257
        CT_DoExecLog ALL make ${PARALLELMFLAGS} -C gcc ${libgcc_rule} \
linux@1926
   258
                              ${repair_cc}
yann@850
   259
        sed -r -i -e 's@-lc@@g' gcc/${libgcc_rule}
yann@850
   260
    else # build_libgcc
yann@1981
   261
        core_targets=( gcc )
yann@850
   262
    fi   # ! build libgcc
yann@1983
   263
    if [    "${build_libstdcxx}" = "yes"    \
yann@1983
   264
         -a "${CT_CC_LANG_CXX}"  = "y"      \
yann@1983
   265
       ]; then
yann@1983
   266
        core_targets+=( target-libstdc++-v3 )
yann@1983
   267
    fi
yann@850
   268
yann@850
   269
    CT_DoLog EXTRA "Building ${mode} core C compiler"
yann@1981
   270
    CT_DoExecLog ALL make ${PARALLELMFLAGS} "${core_targets[@]/#/all-}"
yann@850
   271
yann@850
   272
    CT_DoLog EXTRA "Installing ${mode} core C compiler"
yann@1981
   273
    CT_DoExecLog ALL make "${core_targets[@]/#/install-}"
yann@850
   274
yann@1269
   275
    # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
yann@1269
   276
    # to call the C compiler with the same, somewhat canonical name.
linux@1924
   277
    # check whether compiler has an extension
linux@1924
   278
    file="$( ls -1 "${core_prefix_dir}/bin/${CT_TARGET}-gcc."* 2>/dev/null || true )"
linux@1924
   279
    [ -z "${file}" ] || ext=".${file##*.}"
linux@1924
   280
    CT_DoExecLog ALL ln -sv "${CT_TARGET}-gcc${ext}" "${core_prefix_dir}/bin/${CT_TARGET}-cc${ext}"
yann@1269
   281
yann@850
   282
    CT_EndStep
yann@850
   283
}
yann@850
   284
yann@850
   285
#------------------------------------------------------------------------------
yann@850
   286
# Build final gcc
yann@850
   287
do_cc() {
yann@1479
   288
    local -a extra_config
yann@1479
   289
    local tmp
yann@1892
   290
    local final_LDFLAGS
yann@1479
   291
yann@850
   292
    # If building for bare metal, nothing to be done here, the static core conpiler is enough!
yann@850
   293
    [ "${CT_BARE_METAL}" = "y" ] && return 0
yann@850
   294
yann@850
   295
    CT_DoStep INFO "Installing final compiler"
yann@850
   296
yann@850
   297
    mkdir -p "${CT_BUILD_DIR}/build-cc"
yann@850
   298
    cd "${CT_BUILD_DIR}/build-cc"
yann@850
   299
yann@850
   300
    CT_DoLog EXTRA "Configuring final compiler"
yann@850
   301
yann@850
   302
    # Enable selected languages
yann@850
   303
    lang_opt="c"
yann@850
   304
    [ "${CT_CC_LANG_CXX}" = "y"      ] && lang_opt="${lang_opt},c++"
yann@850
   305
    [ "${CT_CC_LANG_FORTRAN}" = "y"  ] && lang_opt="${lang_opt},fortran"
yann@850
   306
    [ "${CT_CC_LANG_ADA}" = "y"      ] && lang_opt="${lang_opt},ada"
yann@850
   307
    [ "${CT_CC_LANG_JAVA}" = "y"     ] && lang_opt="${lang_opt},java"
yann@850
   308
    [ "${CT_CC_LANG_OBJC}" = "y"     ] && lang_opt="${lang_opt},objc"
yann@850
   309
    [ "${CT_CC_LANG_OBJCXX}" = "y"   ] && lang_opt="${lang_opt},obj-c++"
yann@850
   310
    CT_Test "Building ADA language is not yet supported. Will try..." "${CT_CC_LANG_ADA}" = "y"
yann@850
   311
    CT_Test "Building Objective-C language is not yet supported. Will try..." "${CT_CC_LANG_OBJC}" = "y"
yann@850
   312
    CT_Test "Building Objective-C++ language is not yet supported. Will try..." "${CT_CC_LANG_OBJCXX}" = "y"
yann@850
   313
    CT_Test "Building ${CT_CC_LANG_OTHERS//,/ } language(s) is not yet supported. Will try..." -n "${CT_CC_LANG_OTHERS}"
yann@850
   314
    lang_opt=$(echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;')
yann@850
   315
yann@1479
   316
    extra_config+=("--enable-languages=${lang_opt}")
yann@1479
   317
    extra_config+=("--disable-multilib")
yann@1479
   318
    for tmp in ARCH ABI CPU TUNE FPU FLOAT; do
yann@1479
   319
        eval tmp="\${CT_ARCH_WITH_${tmp}}"
yann@1479
   320
        if [ -n "${tmp}" ]; then
yann@1479
   321
            extra_config+=("${tmp}")
yann@1479
   322
        fi
yann@1479
   323
    done
yann@1479
   324
yann@1479
   325
    [ "${CT_SHARED_LIBS}" = "y" ]                   || extra_config+=("--disable-shared")
yann@1479
   326
    [ -n "${CT_CC_PKGVERSION}" ]                    && extra_config+=("--with-pkgversion=${CT_CC_PKGVERSION}")
yann@1479
   327
    [ -n "${CT_CC_BUGURL}" ]                        && extra_config+=("--with-bugurl=${CT_CC_BUGURL}")
yann@1479
   328
    [ "${CT_CC_SJLJ_EXCEPTIONS_USE}" = "y" ]        && extra_config+=("--enable-sjlj-exceptions")
yann@1479
   329
    [ "${CT_CC_SJLJ_EXCEPTIONS_DONT_USE}" = "y" ]   && extra_config+=("--disable-sjlj-exceptions")
yann@850
   330
    if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
yann@1479
   331
        extra_config+=("--enable-__cxa_atexit")
yann@850
   332
    else
yann@1479
   333
        extra_config+=("--disable-__cxa_atexit")
yann@850
   334
    fi
yann@1484
   335
    if [ -n "${CC_ENABLE_CXX_FLAGS}" ]; then
yann@1484
   336
        extra_config+=("--enable-cxx-flags=${CC_ENABLE_CXX_FLAGS}")
yann@1484
   337
    fi
yann@1893
   338
yann@1893
   339
    # When companion libraries are build static (eg !shared),
yann@1893
   340
    # the libstdc++ is not pulled automatically, although it
yann@1893
   341
    # is needed. Shoe-horn it in our LDFLAGS
yann@1893
   342
    if [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
yann@1893
   343
        final_LDFLAGS='-lstdc++'
yann@1893
   344
    fi
lacombar@1880
   345
    if [ "${CT_CC_GCC_USE_GMP_MPFR}" = "y" ]; then
yann@1893
   346
        extra_config+=("--with-gmp=${CT_COMPLIBS_DIR}")
yann@1893
   347
        extra_config+=("--with-mpfr=${CT_COMPLIBS_DIR}")
yann@1848
   348
    fi
lacombar@1880
   349
    if [ "${CT_CC_GCC_USE_PPL_CLOOG_MPC}" = "y" ]; then
yann@1893
   350
        extra_config+=("--with-ppl=${CT_COMPLIBS_DIR}")
yann@1893
   351
        extra_config+=("--with-cloog=${CT_COMPLIBS_DIR}")
yann@1893
   352
        extra_config+=("--with-mpc=${CT_COMPLIBS_DIR}")
yann@1848
   353
    fi
yann@1920
   354
    if [ "${CT_CC_GCC_USE_LIBELF}" = "y" ]; then
yann@1920
   355
        extra_config+=("--with-libelf=${CT_COMPLIBS_DIR}")
yann@1920
   356
    fi
yann@850
   357
lacombar@1881
   358
    if [ "${CT_THREADS}" = "none" ]; then
lacombar@1881
   359
        extra_config+=("--disable-threads")
lacombar@1881
   360
        if [ "${CT_CC_GCC_4_2_or_later}" = y ]; then
lacombar@1881
   361
            extra_config+=("--disable-libgomp")
lacombar@1881
   362
        fi
lacombar@1881
   363
    else
lacombar@1881
   364
        extra_config+=("--enable-threads=posix")
lacombar@1881
   365
    fi
lacombar@1881
   366
titus@1972
   367
    if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then
titus@1972
   368
        extra_config+=("--enable-target-optspace")
titus@1972
   369
    fi
titus@1972
   370
yann@1479
   371
    CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
yann@850
   372
yann@850
   373
    # --enable-symvers=gnu really only needed for sh4 to work around a
yann@850
   374
    # detection problem only matters for gcc-3.2.x and later, I think.
yann@850
   375
    # --disable-nls to work around crash bug on ppc405, but also because
yann@850
   376
    # embedded systems don't really need message catalogs...
yann@1122
   377
    CC_FOR_BUILD="${CT_BUILD}-gcc"                  \
yann@1122
   378
    CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
yann@1892
   379
    LDFLAGS="${final_LDFLAGS}"                      \
yann@1122
   380
    CFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}"         \
yann@1122
   381
    CXXFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}"       \
yann@1122
   382
    LDFLAGS_FOR_TARGET="${CT_TARGET_LDFLAGS}"       \
yann@1122
   383
    CT_DoExecLog ALL                                \
yann@1389
   384
    "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/configure"  \
yann@1122
   385
        --build=${CT_BUILD}                         \
yann@1122
   386
        --host=${CT_HOST}                           \
yann@1122
   387
        --target=${CT_TARGET}                       \
yann@1122
   388
        --prefix="${CT_PREFIX_DIR}"                 \
yann@1122
   389
        ${CC_SYSROOT_ARG}                           \
yann@1479
   390
        "${extra_config[@]}"                        \
yann@1122
   391
        --with-local-prefix="${CT_SYSROOT_DIR}"     \
yann@1122
   392
        --disable-nls                               \
yann@1122
   393
        --enable-symvers=gnu                        \
yann@1122
   394
        --enable-c99                                \
yann@1122
   395
        --enable-long-long                          \
yann@850
   396
        ${CT_CC_EXTRA_CONFIG}
yann@850
   397
yann@850
   398
    if [ "${CT_CANADIAN}" = "y" ]; then
yann@850
   399
        CT_DoLog EXTRA "Building libiberty"
yann@850
   400
        CT_DoExecLog ALL make ${PARALLELMFLAGS} all-build-libiberty
yann@850
   401
    fi
yann@850
   402
yann@850
   403
    CT_DoLog EXTRA "Building final compiler"
yann@850
   404
    CT_DoExecLog ALL make ${PARALLELMFLAGS} all
yann@850
   405
yann@850
   406
    CT_DoLog EXTRA "Installing final compiler"
yann@850
   407
    CT_DoExecLog ALL make install
yann@850
   408
yann@850
   409
    # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
yann@850
   410
    # to call the C compiler with the same, somewhat canonical name.
linux@1924
   411
    # check whether compiler has an extension
linux@1924
   412
    file="$( ls -1 "${CT_TARGET}/bin/${CT_TARGET}-gcc."* 2>/dev/null || true )"
linux@1924
   413
    [ -z "${file}" ] || ext=".${file##*.}"
linux@1924
   414
    CT_DoExecLog ALL ln -sv "${CT_TARGET}-gcc${ext}" "${CT_PREFIX_DIR}/bin/${CT_TARGET}-cc${ext}"
yann@850
   415
yann@850
   416
    CT_EndStep
yann@850
   417
}