scripts/build/cc/gcc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sat Oct 09 11:38:04 2010 +0200 (2010-10-09)
changeset 2146 3b812ba8d001
parent 2145 efea409ff8be
child 2153 ef0142a8ad4c
permissions -rw-r--r--
cc/gcc: add an option to enable/disable build of libssp

libssp is the run-time Stack-Smashing Protection library.
It can be usefull to have or miss, depends...

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
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
            ;;
bartvdrmeulen@2017
    71
        ,,win32) do_cc_core mode=static build_libgcc=yes
bartvdrmeulen@2017
    72
            ;;
yann@892
    73
        *)  if [ "${CT_CC_GCC_4_3_or_later}" = "y" ]; then
yann@892
    74
                do_cc_core mode=static build_libgcc=yes
yann@892
    75
            else
yann@1980
    76
                do_cc_core mode=static
yann@892
    77
            fi
yann@892
    78
            ;;
yann@850
    79
    esac
yann@850
    80
}
yann@850
    81
yann@850
    82
#------------------------------------------------------------------------------
yann@850
    83
# Build core gcc
yann@850
    84
# This function is used to build both the static and the shared core C conpiler,
yann@850
    85
# with or without the target libgcc. We need to know wether:
yann@850
    86
#  - we're building static, shared or bare metal: mode=[static|shared|baremetal]
yann@1980
    87
#  - we need to build libgcc or not             : build_libgcc=[yes|no]     (default: no)
yann@1983
    88
#  - we need to build libstdc++ or not          : build_libstdcxx=[yes|no]  (default: no)
yann@850
    89
# Usage: do_cc_core_static mode=[static|shared|baremetal] build_libgcc=[yes|no]
yann@850
    90
do_cc_core() {
yann@850
    91
    local mode
yann@1980
    92
    local build_libgcc=no
yann@1983
    93
    local build_libstdcxx=no
yann@850
    94
    local core_prefix_dir
yann@1107
    95
    local lang_opt
yann@1479
    96
    local tmp
yann@1479
    97
    local -a extra_config
yann@1892
    98
    local core_LDFLAGS
yann@1981
    99
    local -a core_targets
yann@850
   100
yann@1980
   101
    while [ $# -ne 0 ]; do
yann@1980
   102
        eval "${1}"
yann@1980
   103
        shift
yann@1980
   104
    done
yann@850
   105
yann@1107
   106
    lang_opt=c
yann@850
   107
    case "${mode}" in
yann@850
   108
        static)
yann@850
   109
            core_prefix_dir="${CT_CC_CORE_STATIC_PREFIX_DIR}"
yann@1479
   110
            extra_config+=("--with-newlib")
yann@1479
   111
            extra_config+=("--enable-threads=no")
yann@1479
   112
            extra_config+=("--disable-shared")
yann@1983
   113
            copy_headers=y  # For baremetal, as there's no headers to copy,
yann@1983
   114
                            # we copy an empty directory. So, who cares?
yann@850
   115
            ;;
yann@850
   116
        shared)
yann@850
   117
            core_prefix_dir="${CT_CC_CORE_SHARED_PREFIX_DIR}"
yann@1479
   118
            extra_config+=("--enable-shared")
yann@850
   119
            copy_headers=y
yann@850
   120
            ;;
yann@850
   121
        baremetal)
yann@850
   122
            core_prefix_dir="${CT_PREFIX_DIR}"
yann@1479
   123
            extra_config+=("--with-newlib")
yann@1479
   124
            extra_config+=("--enable-threads=no")
yann@1479
   125
            extra_config+=("--disable-shared")
yann@1107
   126
            [ "${CT_CC_LANG_CXX}" = "y" ] && lang_opt="${lang_opt},c++"
yann@850
   127
            copy_headers=n
yann@850
   128
            ;;
yann@1980
   129
        *)
yann@1980
   130
            CT_Abort "Internal Error: 'mode' must be one of: 'static', 'shared' or 'baremetal', not '${mode:-(empty)}'"
yann@1980
   131
            ;;
yann@850
   132
    esac
yann@850
   133
yann@1980
   134
    CT_DoStep INFO "Installing ${mode} core C compiler"
yann@1980
   135
    mkdir -p "${CT_BUILD_DIR}/build-cc-core-${mode}"
yann@1980
   136
    cd "${CT_BUILD_DIR}/build-cc-core-${mode}"
yann@1980
   137
linux@1898
   138
    # Bare metal delivers the core compiler as final compiler, so add version info and bugurl
linux@1898
   139
    [ -n "${CT_CC_BUGURL}" ]     && extra_config+=("--with-bugurl=${CT_CC_BUGURL}")
linux@1898
   140
    [ -n "${CT_CC_PKGVERSION}" ] && extra_config+=("--with-pkgversion=${CT_CC_PKGVERSION}")
linux@1898
   141
yann@850
   142
    if [ "${copy_headers}" = "y" ]; then
yann@850
   143
        CT_DoLog DEBUG "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
yann@1979
   144
        CT_DoExecLog ALL cp -a "${CT_HEADERS_DIR}" "${core_prefix_dir}/${CT_TARGET}/include"
yann@850
   145
    fi
yann@850
   146
yann@850
   147
    CT_DoLog EXTRA "Configuring ${mode} core C compiler"
yann@850
   148
yann@1479
   149
    for tmp in ARCH ABI CPU TUNE FPU FLOAT; do
yann@1479
   150
        eval tmp="\${CT_ARCH_WITH_${tmp}}"
yann@1479
   151
        if [ -n "${tmp}" ]; then
yann@1479
   152
            extra_config+=("${tmp}")
yann@1479
   153
        fi
yann@1479
   154
    done
yann@850
   155
    if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
yann@1479
   156
        extra_config+=("--enable-__cxa_atexit")
yann@850
   157
    else
yann@1479
   158
        extra_config+=("--disable-__cxa_atexit")
yann@850
   159
    fi
yann@850
   160
yann@1892
   161
    # When companion libraries are build static (eg !shared),
yann@1892
   162
    # the libstdc++ is not pulled automatically, although it
yann@1892
   163
    # is needed. Shoe-horn it in our LDFLAGS
dwatkins@2070
   164
    # Ditto libm on some Fedora boxen
yann@1893
   165
    if [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
dwatkins@2070
   166
        core_LDFLAGS='-lstdc++ -lm'
yann@1892
   167
    fi
yann@1893
   168
    if [ "${CT_CC_GCC_USE_GMP_MPFR}" = "y" ]; then
yann@1893
   169
        extra_config+=("--with-gmp=${CT_COMPLIBS_DIR}")
yann@1893
   170
        extra_config+=("--with-mpfr=${CT_COMPLIBS_DIR}")
yann@1893
   171
    fi
yann@2122
   172
    if [ "${CT_CC_GCC_USE_MPC}" = "y" ]; then
yann@2122
   173
        extra_config+=("--with-mpc=${CT_COMPLIBS_DIR}")
yann@2122
   174
    fi
yann@2122
   175
    if [ "${CT_CC_GCC_USE_GRAPHITE}" = "y" ]; then
yann@1893
   176
        extra_config+=("--with-ppl=${CT_COMPLIBS_DIR}")
yann@1893
   177
        extra_config+=("--with-cloog=${CT_COMPLIBS_DIR}")
yann@2123
   178
    elif [ "${CT_CC_GCC_HAS_GRAPHITE}" = "y" ]; then
yann@2123
   179
        extra_config+=("--with-ppl=no")
yann@2123
   180
        extra_config+=("--with-cloog=no")
yann@2014
   181
    fi
yann@2122
   182
    if [ "${CT_CC_GCC_USE_LTO}" = "y" ]; then
yann@1920
   183
        extra_config+=("--with-libelf=${CT_COMPLIBS_DIR}")
yann@2142
   184
        extra_config+=("--enable-lto")
yann@2123
   185
    elif [ "${CT_CC_GCC_HAS_LTO}" = "y" ]; then
yann@2123
   186
        extra_config+=("--with-libelf=no")
yann@2142
   187
        extra_config+=("--disable-lto")
yann@1920
   188
    fi
yann@1893
   189
titus@1972
   190
    if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then
titus@1972
   191
        extra_config+=("--enable-target-optspace")
titus@1972
   192
    fi
titus@1972
   193
yann@2143
   194
    case "${CT_CC_GCC_LDBL_128}" in
yann@2143
   195
        Y)  extra_config+=("--with-long-double-128");;
yann@2143
   196
        M)  ;;
yann@2143
   197
        "") extra_config+=("--without-long-double-128");;
yann@2143
   198
    esac
yann@2143
   199
yann@1893
   200
    CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
yann@1892
   201
yann@850
   202
    # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
yann@1041
   203
    CC_FOR_BUILD="${CT_BUILD}-gcc"                  \
yann@850
   204
    CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
yann@1892
   205
    LDFLAGS="${core_LDFLAGS}"                       \
yann@850
   206
    CT_DoExecLog ALL                                \
yann@1389
   207
    "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/configure"  \
yann@1041
   208
        --build=${CT_BUILD}                         \
yann@850
   209
        --host=${CT_HOST}                           \
yann@850
   210
        --target=${CT_TARGET}                       \
yann@850
   211
        --prefix="${core_prefix_dir}"               \
yann@850
   212
        --with-local-prefix="${CT_SYSROOT_DIR}"     \
yann@850
   213
        --disable-multilib                          \
yann@2043
   214
        --disable-libmudflap                        \
yann@850
   215
        ${CC_CORE_SYSROOT_ARG}                      \
yann@1479
   216
        "${extra_config[@]}"                        \
yann@850
   217
        --disable-nls                               \
yann@850
   218
        --enable-symvers=gnu                        \
yann@1107
   219
        --enable-languages="${lang_opt}"            \
yann@850
   220
        ${CT_CC_CORE_EXTRA_CONFIG}
yann@850
   221
yann@850
   222
    if [ "${build_libgcc}" = "yes" ]; then
yann@850
   223
        # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
yann@850
   224
        # gcc/config/t-libunwind so -lc is removed from the link for
yann@850
   225
        # libgcc_s.so, as we do not have a target -lc yet.
yann@850
   226
        # This is not as ugly as it appears to be ;-) All symbols get resolved
yann@850
   227
        # during the glibc build, and we provide a proper libgcc_s.so for the
yann@850
   228
        # cross toolchain during the final gcc build.
yann@850
   229
        #
yann@850
   230
        # As we cannot modify the source tree, nor override SHLIB_LC itself
yann@850
   231
        # during configure or make, we have to edit the resultant
yann@850
   232
        # gcc/libgcc.mk itself to remove -lc from the link.
yann@850
   233
        # This causes us to have to jump through some hoops...
yann@850
   234
        #
yann@850
   235
        # To produce libgcc.mk to edit we firstly require libiberty.a,
yann@850
   236
        # so we configure then build it.
yann@850
   237
        # Next we have to configure gcc, create libgcc.mk then edit it...
yann@850
   238
        # So much easier if we just edit the source tree, but hey...
yann@1389
   239
        if [ ! -f "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" ]; then
yann@850
   240
            CT_DoExecLog ALL make configure-libiberty
yann@850
   241
            CT_DoExecLog ALL make ${PARALLELMFLAGS} -C libiberty libiberty.a
yann@850
   242
            CT_DoExecLog ALL make configure-gcc configure-libcpp
yann@850
   243
            CT_DoExecLog ALL make ${PARALLELMFLAGS} all-libcpp
yann@850
   244
        else
yann@850
   245
            CT_DoExecLog ALL make configure-gcc configure-libcpp configure-build-libiberty
yann@850
   246
            CT_DoExecLog ALL make ${PARALLELMFLAGS} all-libcpp all-build-libiberty
yann@850
   247
        fi
yann@850
   248
        # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
yann@1389
   249
        if [ -d "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/libdecnumber" ]; then
yann@850
   250
            CT_DoExecLog ALL make configure-libdecnumber
yann@850
   251
            CT_DoExecLog ALL make ${PARALLELMFLAGS} -C libdecnumber libdecnumber.a
yann@850
   252
        fi
yann@850
   253
yann@850
   254
        # Starting with GCC 4.3, libgcc.mk is no longer built,
yann@850
   255
        # and libgcc.mvars is used instead.
yann@850
   256
yann@892
   257
        if [ "${CT_CC_GCC_4_3_or_later}" = "y" ]; then
yann@850
   258
            libgcc_rule="libgcc.mvars"
yann@1981
   259
            core_targets=( gcc target-libgcc )
yann@850
   260
        else
yann@850
   261
            libgcc_rule="libgcc.mk"
yann@1981
   262
            core_targets=( gcc )
yann@850
   263
        fi
yann@850
   264
linux@1926
   265
        # On bare metal and canadian build the host-compiler is used when
linux@1926
   266
        # actually the build-system compiler is required. Choose the correct
linux@1926
   267
        # compilers for canadian build and use the defaults on other
linux@1926
   268
        # configurations.
linux@1926
   269
        if [ "${CT_BARE_METAL},${CT_CANADIAN}" = "y,y" ]; then
linux@1926
   270
            repair_cc="CC_FOR_BUILD=${CT_BUILD}-gcc \
linux@1926
   271
                       GCC_FOR_TARGET=${CT_TARGET}-gcc"
linux@1926
   272
        else
linux@1926
   273
            repair_cc=""
linux@1926
   274
        fi
linux@1926
   275
linux@1926
   276
        CT_DoExecLog ALL make ${PARALLELMFLAGS} -C gcc ${libgcc_rule} \
linux@1926
   277
                              ${repair_cc}
yann@850
   278
        sed -r -i -e 's@-lc@@g' gcc/${libgcc_rule}
yann@850
   279
    else # build_libgcc
yann@1981
   280
        core_targets=( gcc )
yann@850
   281
    fi   # ! build libgcc
yann@1983
   282
    if [    "${build_libstdcxx}" = "yes"    \
yann@1983
   283
         -a "${CT_CC_LANG_CXX}"  = "y"      \
yann@1983
   284
       ]; then
yann@1983
   285
        core_targets+=( target-libstdc++-v3 )
yann@1983
   286
    fi
yann@850
   287
yann@850
   288
    CT_DoLog EXTRA "Building ${mode} core C compiler"
yann@1981
   289
    CT_DoExecLog ALL make ${PARALLELMFLAGS} "${core_targets[@]/#/all-}"
yann@850
   290
yann@850
   291
    CT_DoLog EXTRA "Installing ${mode} core C compiler"
yann@1981
   292
    CT_DoExecLog ALL make "${core_targets[@]/#/install-}"
yann@850
   293
yann@1269
   294
    # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
yann@1269
   295
    # to call the C compiler with the same, somewhat canonical name.
linux@1924
   296
    # check whether compiler has an extension
linux@1924
   297
    file="$( ls -1 "${core_prefix_dir}/bin/${CT_TARGET}-gcc."* 2>/dev/null || true )"
linux@1924
   298
    [ -z "${file}" ] || ext=".${file##*.}"
linux@1924
   299
    CT_DoExecLog ALL ln -sv "${CT_TARGET}-gcc${ext}" "${core_prefix_dir}/bin/${CT_TARGET}-cc${ext}"
yann@1269
   300
yann@850
   301
    CT_EndStep
yann@850
   302
}
yann@850
   303
yann@850
   304
#------------------------------------------------------------------------------
yann@850
   305
# Build final gcc
yann@850
   306
do_cc() {
yann@1479
   307
    local -a extra_config
yann@1479
   308
    local tmp
yann@1892
   309
    local final_LDFLAGS
yann@1479
   310
yann@850
   311
    # If building for bare metal, nothing to be done here, the static core conpiler is enough!
yann@850
   312
    [ "${CT_BARE_METAL}" = "y" ] && return 0
yann@850
   313
yann@850
   314
    CT_DoStep INFO "Installing final compiler"
yann@850
   315
yann@850
   316
    mkdir -p "${CT_BUILD_DIR}/build-cc"
yann@850
   317
    cd "${CT_BUILD_DIR}/build-cc"
yann@850
   318
yann@850
   319
    CT_DoLog EXTRA "Configuring final compiler"
yann@850
   320
yann@850
   321
    # Enable selected languages
yann@850
   322
    lang_opt="c"
yann@850
   323
    [ "${CT_CC_LANG_CXX}" = "y"      ] && lang_opt="${lang_opt},c++"
yann@850
   324
    [ "${CT_CC_LANG_FORTRAN}" = "y"  ] && lang_opt="${lang_opt},fortran"
yann@850
   325
    [ "${CT_CC_LANG_ADA}" = "y"      ] && lang_opt="${lang_opt},ada"
yann@850
   326
    [ "${CT_CC_LANG_JAVA}" = "y"     ] && lang_opt="${lang_opt},java"
yann@850
   327
    [ "${CT_CC_LANG_OBJC}" = "y"     ] && lang_opt="${lang_opt},objc"
yann@850
   328
    [ "${CT_CC_LANG_OBJCXX}" = "y"   ] && lang_opt="${lang_opt},obj-c++"
yann@850
   329
    CT_Test "Building ADA language is not yet supported. Will try..." "${CT_CC_LANG_ADA}" = "y"
yann@850
   330
    CT_Test "Building Objective-C language is not yet supported. Will try..." "${CT_CC_LANG_OBJC}" = "y"
yann@850
   331
    CT_Test "Building Objective-C++ language is not yet supported. Will try..." "${CT_CC_LANG_OBJCXX}" = "y"
yann@850
   332
    CT_Test "Building ${CT_CC_LANG_OTHERS//,/ } language(s) is not yet supported. Will try..." -n "${CT_CC_LANG_OTHERS}"
yann@850
   333
    lang_opt=$(echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;')
yann@850
   334
yann@2141
   335
    # In case we build the C++ compiler, we have to tell gcc where to put the
yann@2141
   336
    # C++ headers, or else it will try to put it in prefix/tuple/include,
yann@2141
   337
    # which we make a symlink to sysroot/usr/include during the build, and
yann@2141
   338
    # that we delete (the symlink!) after the build, but gcc will not look
yann@2141
   339
    # in sysroot/usr/inlcude for C++ headers by default
yann@2141
   340
    if [ "${CT_CC_LANG_CXX}" = "y"   ]; then
yann@2141
   341
        extra_config+=("--with-gxx-include-dir=${CT_SYSROOT_DIR}/usr/include")
yann@2141
   342
    fi
yann@2141
   343
yann@1479
   344
    extra_config+=("--enable-languages=${lang_opt}")
yann@1479
   345
    extra_config+=("--disable-multilib")
yann@1479
   346
    for tmp in ARCH ABI CPU TUNE FPU FLOAT; do
yann@1479
   347
        eval tmp="\${CT_ARCH_WITH_${tmp}}"
yann@1479
   348
        if [ -n "${tmp}" ]; then
yann@1479
   349
            extra_config+=("${tmp}")
yann@1479
   350
        fi
yann@1479
   351
    done
yann@1479
   352
yann@1479
   353
    [ "${CT_SHARED_LIBS}" = "y" ]                   || extra_config+=("--disable-shared")
yann@1479
   354
    [ -n "${CT_CC_PKGVERSION}" ]                    && extra_config+=("--with-pkgversion=${CT_CC_PKGVERSION}")
yann@1479
   355
    [ -n "${CT_CC_BUGURL}" ]                        && extra_config+=("--with-bugurl=${CT_CC_BUGURL}")
yann@2042
   356
    case "${CT_CC_GCC_SJLJ_EXCEPTIONS}" in
yann@2042
   357
        y)  extra_config+=("--enable-sjlj-exceptions");;
yann@2042
   358
        m)  ;;
yann@2042
   359
        "") extra_config+=("--disable-sjlj-exceptions");;
yann@2042
   360
    esac
yann@850
   361
    if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
yann@1479
   362
        extra_config+=("--enable-__cxa_atexit")
yann@850
   363
    else
yann@1479
   364
        extra_config+=("--disable-__cxa_atexit")
yann@850
   365
    fi
yann@1484
   366
    if [ -n "${CC_ENABLE_CXX_FLAGS}" ]; then
yann@1484
   367
        extra_config+=("--enable-cxx-flags=${CC_ENABLE_CXX_FLAGS}")
yann@1484
   368
    fi
yann@2043
   369
    if [ "${CT_CC_GCC_LIBMUDFLAP}" = "y" ]; then
yann@2043
   370
        extra_config+=(--enable-libmudflap)
yann@2043
   371
    else
yann@2043
   372
        extra_config+=(--disable-libmudflap)
yann@2043
   373
    fi
yann@2145
   374
    if [ "${CT_CC_GCC_LIBGOMP}" = "y" ]; then
yann@2145
   375
        extra_config+=(--enable-libgomp)
yann@2145
   376
    else
yann@2145
   377
        extra_config+=(--disable-libgomp)
yann@2145
   378
    fi
yann@2146
   379
    if [ "${CT_CC_GCC_LIBSSP}" = "y" ]; then
yann@2146
   380
        extra_config+=(--enable-libssp)
yann@2146
   381
    else
yann@2146
   382
        extra_config+=(--disable-libssp)
yann@2146
   383
    fi
yann@1893
   384
js@2045
   385
    if [ "${CT_CC_STATIC_LIBSTDCXX}" = "y" ]; then
js@2045
   386
        # this is from CodeSourcery arm-2010q1-202-arm-none-linux-gnueabi.src.tar.bz2
js@2045
   387
        # build script
js@2045
   388
        # FIXME: if the host gcc is gcc-4.5 then presumably we could use -static-libstdc++,
js@2045
   389
        # see http://gcc.gnu.org/ml/gcc-patches/2009-06/msg01635.html
js@2045
   390
        extra_config+=("--with-host-libstdcxx=-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm")
js@2045
   391
    elif [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
js@2045
   392
        # When companion libraries are build static (eg !shared),
js@2045
   393
        # the libstdc++ is not pulled automatically, although it
js@2045
   394
        # is needed. Shoe-horn it in our LDFLAGS
dwatkins@2070
   395
        # Ditto libm on some Fedora boxen
dwatkins@2070
   396
        final_LDFLAGS='-lstdc++ -lm'
yann@1893
   397
    fi
lacombar@1880
   398
    if [ "${CT_CC_GCC_USE_GMP_MPFR}" = "y" ]; then
yann@1893
   399
        extra_config+=("--with-gmp=${CT_COMPLIBS_DIR}")
yann@1893
   400
        extra_config+=("--with-mpfr=${CT_COMPLIBS_DIR}")
yann@1848
   401
    fi
yann@2122
   402
    if [ "${CT_CC_GCC_USE_MPC}" = "y" ]; then
yann@2122
   403
        extra_config+=("--with-mpc=${CT_COMPLIBS_DIR}")
yann@2122
   404
    fi
yann@2122
   405
    if [ "${CT_CC_GCC_USE_GRAPHITE}" = "y" ]; then
yann@1893
   406
        extra_config+=("--with-ppl=${CT_COMPLIBS_DIR}")
yann@1893
   407
        extra_config+=("--with-cloog=${CT_COMPLIBS_DIR}")
yann@2123
   408
    elif [ "${CT_CC_GCC_HAS_GRAPHITE}" = "y" ]; then
yann@2123
   409
        extra_config+=("--with-ppl=no")
yann@2123
   410
        extra_config+=("--with-cloog=no")
yann@2014
   411
    fi
yann@2122
   412
    if [ "${CT_CC_GCC_USE_LTO}" = "y" ]; then
yann@1920
   413
        extra_config+=("--with-libelf=${CT_COMPLIBS_DIR}")
yann@2123
   414
    elif [ "${CT_CC_GCC_HAS_LTO}" = "y" ]; then
yann@2123
   415
        extra_config+=("--with-libelf=no")
yann@1920
   416
    fi
yann@850
   417
lacombar@1881
   418
    if [ "${CT_THREADS}" = "none" ]; then
lacombar@1881
   419
        extra_config+=("--disable-threads")
lacombar@1881
   420
        if [ "${CT_CC_GCC_4_2_or_later}" = y ]; then
yann@2145
   421
            CT_Test "Disabling libgomp for no-thread gcc>=4.2" "${CT_CC_GCC_LIBGOMP}" = "Y"
lacombar@1881
   422
            extra_config+=("--disable-libgomp")
lacombar@1881
   423
        fi
lacombar@1881
   424
    else
bartvdrmeulen@2017
   425
        if [ "${CT_THREADS}" = "win32" ]; then
bartvdrmeulen@2017
   426
            extra_config+=("--enable-threads=win32")
bartvdrmeulen@2017
   427
            extra_config+=("--disable-win32-registry")
bartvdrmeulen@2017
   428
        else
bartvdrmeulen@2017
   429
            extra_config+=("--enable-threads=posix")
bartvdrmeulen@2017
   430
        fi
lacombar@1881
   431
    fi
lacombar@1881
   432
titus@1972
   433
    if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then
titus@1972
   434
        extra_config+=("--enable-target-optspace")
titus@1972
   435
    fi
yann@1991
   436
    if [ "${CT_CC_GCC_DISABLE_PCH}" = "y" ]; then
yann@1991
   437
        extra_config+=("--disable-libstdcxx-pch")
yann@1991
   438
    fi
titus@1972
   439
yann@2143
   440
    case "${CT_CC_GCC_LDBL_128}" in
yann@2143
   441
        Y)  extra_config+=("--with-long-double-128");;
yann@2143
   442
        M)  ;;
yann@2143
   443
        "") extra_config+=("--without-long-double-128");;
yann@2143
   444
    esac
yann@2143
   445
yann@1479
   446
    CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
yann@850
   447
yann@850
   448
    # --enable-symvers=gnu really only needed for sh4 to work around a
yann@850
   449
    # detection problem only matters for gcc-3.2.x and later, I think.
yann@850
   450
    # --disable-nls to work around crash bug on ppc405, but also because
yann@850
   451
    # embedded systems don't really need message catalogs...
yann@1122
   452
    CC_FOR_BUILD="${CT_BUILD}-gcc"                  \
yann@1122
   453
    CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
yann@1892
   454
    LDFLAGS="${final_LDFLAGS}"                      \
yann@1122
   455
    CFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}"         \
yann@1122
   456
    CXXFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}"       \
yann@1122
   457
    LDFLAGS_FOR_TARGET="${CT_TARGET_LDFLAGS}"       \
yann@1122
   458
    CT_DoExecLog ALL                                \
yann@1389
   459
    "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/configure"  \
yann@1122
   460
        --build=${CT_BUILD}                         \
yann@1122
   461
        --host=${CT_HOST}                           \
yann@1122
   462
        --target=${CT_TARGET}                       \
yann@1122
   463
        --prefix="${CT_PREFIX_DIR}"                 \
yann@1122
   464
        ${CC_SYSROOT_ARG}                           \
yann@1479
   465
        "${extra_config[@]}"                        \
yann@1122
   466
        --with-local-prefix="${CT_SYSROOT_DIR}"     \
yann@1122
   467
        --disable-nls                               \
yann@1122
   468
        --enable-symvers=gnu                        \
yann@1122
   469
        --enable-c99                                \
yann@1122
   470
        --enable-long-long                          \
yann@850
   471
        ${CT_CC_EXTRA_CONFIG}
yann@850
   472
yann@850
   473
    if [ "${CT_CANADIAN}" = "y" ]; then
yann@850
   474
        CT_DoLog EXTRA "Building libiberty"
yann@850
   475
        CT_DoExecLog ALL make ${PARALLELMFLAGS} all-build-libiberty
yann@850
   476
    fi
yann@850
   477
yann@850
   478
    CT_DoLog EXTRA "Building final compiler"
yann@850
   479
    CT_DoExecLog ALL make ${PARALLELMFLAGS} all
yann@850
   480
yann@850
   481
    CT_DoLog EXTRA "Installing final compiler"
yann@850
   482
    CT_DoExecLog ALL make install
yann@850
   483
yann@850
   484
    # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
yann@850
   485
    # to call the C compiler with the same, somewhat canonical name.
linux@1924
   486
    # check whether compiler has an extension
bartvdrmeulen@2031
   487
    file="$( ls -1 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-gcc."* 2>/dev/null || true )"
linux@1924
   488
    [ -z "${file}" ] || ext=".${file##*.}"
linux@1924
   489
    CT_DoExecLog ALL ln -sv "${CT_TARGET}-gcc${ext}" "${CT_PREFIX_DIR}/bin/${CT_TARGET}-cc${ext}"
yann@850
   490
yann@850
   491
    CT_EndStep
yann@850
   492
}