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
9 local linaro_base_url="http://launchpad.net/gcc-linaro"
12 # Account for the Linaro versioning
13 linaro_version="$( echo "${CT_CC_VERSION}" \
14 |sed -r -e 's/^linaro-//;' \
16 linaro_series="$( echo "${linaro_version}" \
17 |sed -r -e 's/-.*//;' \
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"
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
44 CT_Extract "gcc-${CT_CC_VERSION}"
45 CT_Patch "gcc" "${CT_CC_VERSION}"
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" \
51 CT_DoExecLog ALL cp -v "${CT_TARBALLS_DIR}/ecj-latest.jar" "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/ecj.jar"
55 #------------------------------------------------------------------------------
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
69 core_opts+=( "mode=static" )
70 core_opts+=( "host=${CT_BUILD}" )
71 core_opts+=( "complibs=${CT_BUILDTOOLS_PREFIX_DIR}" )
72 core_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
73 core_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
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"
81 do_cc_core_backend "${core_opts[@]}"
94 core_opts+=( "host=${CT_BUILD}" )
95 core_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
96 core_opts+=( "complibs=${CT_BUILDTOOLS_PREFIX_DIR}" )
97 core_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
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
110 core_opts+=( "mode=shared" )
111 core_opts+=( "build_libgcc=yes" )
115 core_opts+=( "mode=static" )
116 core_opts+=( "build_libgcc=yes" )
120 core_opts+=( "mode=static" )
121 if [ "${CT_CC_GCC_4_3_or_later}" = "y" ]; then
122 core_opts+=( "build_libgcc=yes" )
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"
131 do_cc_core_backend "${core_opts[@]}"
138 #------------------------------------------------------------------------------
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() {
155 local build_libgcc=no
156 local build_libstdcxx=no
157 local build_staticlinked=no
158 local build_manuals=no
165 local -a host_libstdcxx_flags
166 local -a extra_config
167 local -a core_LDFLAGS
168 local -a core_targets
175 CT_DoLog EXTRA "Configuring core C compiler"
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?
187 extra_config+=("--enable-shared")
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++"
198 CT_Abort "Internal Error: 'mode' must be one of: 'static', 'shared' or 'baremetal', not '${mode:-(empty)}'"
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}")
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"
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}")
219 if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
220 extra_config+=("--enable-__cxa_atexit")
222 extra_config+=("--disable-__cxa_atexit")
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")
240 if [ "${CT_CC_STATIC_LIBSTDCXX}" = "y" ]; then
241 # this is from CodeSourcery arm-2010q1-202-arm-none-linux-gnueabi.src.tar.bz2
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")
258 if [ "${CT_CC_GCC_USE_GMP_MPFR}" = "y" ]; then
259 extra_config+=("--with-gmp=${complibs}")
260 extra_config+=("--with-mpfr=${complibs}")
262 if [ "${CT_CC_GCC_USE_MPC}" = "y" ]; then
263 extra_config+=("--with-mpc=${complibs}")
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")
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")
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")
285 if [ ${#host_libstdcxx_flags[@]} -ne 0 ]; then
286 extra_config+=("--with-host-libstdcxx=${host_libstdcxx_flags[*]}")
289 if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then
290 extra_config+=("--enable-target-optspace")
293 case "${CT_CC_GCC_LDBL_128}" in
294 y) extra_config+=("--with-long-double-128");;
296 "") extra_config+=("--without-long-double-128");;
299 if [ "${CT_CC_GCC_BUILD_ID}" = "y" ]; then
300 extra_config+=( --enable-linker-build-id )
303 case "${CT_CC_GCC_LNK_HASH_STYLE}" in
305 *) extra_config+=( "--with-linker-hash-style=${CT_CC_GCC_LNK_HASH_STYLE}" );;
310 case "${CT_CC_GCC_mips_llsc}" in
311 y) extra_config+=( --with-llsc );;
313 *) extra_config+=( --without-llsc );;
315 case "${CT_CC_GCC_mips_synci}" in
316 y) extra_config+=( --with-synci );;
318 *) extra_config+=( --without-synci );;
320 if [ "${CT_CC_GCC_mips_plt}" ]; then
321 extra_config+=( --with-mips-plt )
326 extra_config+=(--disable-libgomp)
327 extra_config+=(--disable-libmudflap)
329 [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && extra_config+=("--disable-nls")
331 [ "${CT_CC_GCC_DISABLE_PCH}" = "y" ] && extra_config+=("--disable-libstdcxx-pch")
333 if [ "${CT_CC_GCC_SYSTEM_ZLIB}" = "y" ]; then
334 extra_config+=("--with-system-zlib")
337 if [ "${CT_MULTILIB}" = "y" ]; then
338 extra_config+=("--enable-multilib")
340 extra_config+=("--disable-multilib")
343 CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
345 # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
347 CC_FOR_BUILD="${CT_BUILD}-gcc" \
349 LDFLAGS="${core_LDFLAGS[*]}" \
350 "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/configure" \
351 --build=${CT_BUILD} \
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[@]}"
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.
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...
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
385 CT_DoExecLog CFG make ${JOBSFLAGS} configure-gcc configure-libcpp configure-build-libiberty
386 CT_DoExecLog ALL make ${JOBSFLAGS} all-libcpp all-build-libiberty
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
394 # Starting with GCC 4.3, libgcc.mk is no longer built,
395 # and libgcc.mvars is used instead.
397 if [ "${CT_CC_GCC_4_3_or_later}" = "y" ]; then
398 libgcc_rule="libgcc.mvars"
399 core_targets=( gcc target-libgcc )
401 libgcc_rule="libgcc.mk"
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
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"
416 CT_DoExecLog ALL make ${JOBSFLAGS} -C gcc ${libgcc_rule} \
418 sed -r -i -e 's@-lc@@g' gcc/${libgcc_rule}
422 if [ "${build_libstdcxx}" = "yes" \
423 -a "${CT_CC_LANG_CXX}" = "y" \
425 core_targets+=( target-libstdc++-v3 )
428 CT_DoLog EXTRA "Building core C compiler"
429 CT_DoExecLog ALL make ${JOBSFLAGS} "${core_targets[@]/#/all-}"
431 CT_DoLog EXTRA "Installing core C compiler"
432 CT_DoExecLog ALL make ${JOBSFLAGS} "${core_targets[@]/#/install-}"
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
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}"
448 if [ "${CT_MULTILIB}" = "y" ]; then
449 multilibs=( $( "${prefix}/bin/${CT_TARGET}-gcc" -print-multi-lib \
451 if [ ${#multilibs[@]} -ne 0 ]; then
452 CT_DoLog EXTRA "gcc configured with these multilibs (besides the default):"
453 for i in "${multilibs[@]}"; do
456 CT_DoLog EXTRA " ${flags//@/ -} --> ${dir}/"
459 CT_DoLog WARN "gcc configured for multilib, but none available"
464 #------------------------------------------------------------------------------
470 final_opts+=( "host=${CT_HOST}" )
471 final_opts+=( "prefix=${CT_PREFIX_DIR}" )
472 final_opts+=( "complibs=${CT_HOST_COMPLIBS_DIR}" )
473 final_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
474 if [ "${CT_BUILD_MANUALS}" = "y" ]; then
475 final_opts+=( "build_manuals=yes" )
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" )
484 final_backend=do_cc_core_backend
486 final_backend=do_cc_backend
489 CT_DoStep INFO "Installing final compiler"
490 CT_mkdir_pushd "${CT_BUILD_DIR}/build-cc-final"
492 "${final_backend}" "${final_opts[@]}"
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
513 local -a host_libstdcxx_flags
514 local -a extra_config
515 local -a final_LDFLAGS
523 CT_DoLog EXTRA "Configuring final compiler"
525 # Enable selected languages
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/,*$//;')
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}")
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}")
552 case "${CT_CC_GCC_SJLJ_EXCEPTIONS}" in
553 y) extra_config+=("--enable-sjlj-exceptions");;
555 "") extra_config+=("--disable-sjlj-exceptions");;
557 if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
558 extra_config+=("--enable-__cxa_atexit")
560 extra_config+=("--disable-__cxa_atexit")
562 if [ -n "${CT_CC_ENABLE_CXX_FLAGS}" ]; then
563 extra_config+=("--enable-cxx-flags=${CT_CC_ENABLE_CXX_FLAGS}")
565 if [ "${CT_CC_GCC_LIBMUDFLAP}" = "y" ]; then
566 extra_config+=(--enable-libmudflap)
568 extra_config+=(--disable-libmudflap)
570 if [ "${CT_CC_GCC_LIBGOMP}" = "y" ]; then
571 extra_config+=(--enable-libgomp)
573 extra_config+=(--disable-libgomp)
575 if [ "${CT_CC_GCC_LIBSSP}" = "y" ]; then
576 extra_config+=(--enable-libssp)
578 extra_config+=(--disable-libssp)
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")
596 if [ "${CT_CC_STATIC_LIBSTDCXX}" = "y" ]; then
597 # this is from CodeSourcery arm-2010q1-202-arm-none-linux-gnueabi.src.tar.bz2
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")
614 if [ "${CT_CC_GCC_USE_GMP_MPFR}" = "y" ]; then
615 extra_config+=("--with-gmp=${complibs}")
616 extra_config+=("--with-mpfr=${complibs}")
618 if [ "${CT_CC_GCC_USE_MPC}" = "y" ]; then
619 extra_config+=("--with-mpc=${complibs}")
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")
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")
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")
639 if [ ${#host_libstdcxx_flags[@]} -ne 0 ]; then
640 extra_config+=("--with-host-libstdcxx=${host_libstdcxx_flags[*]}")
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")
650 if [ "${CT_THREADS}" = "win32" ]; then
651 extra_config+=("--enable-threads=win32")
652 extra_config+=("--disable-win32-registry")
654 extra_config+=("--enable-threads=posix")
658 if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then
659 extra_config+=("--enable-target-optspace")
661 if [ "${CT_CC_GCC_DISABLE_PCH}" = "y" ]; then
662 extra_config+=("--disable-libstdcxx-pch")
665 case "${CT_CC_GCC_LDBL_128}" in
666 y) extra_config+=("--with-long-double-128");;
668 "") extra_config+=("--without-long-double-128");;
671 if [ "${CT_CC_GCC_BUILD_ID}" = "y" ]; then
672 extra_config+=( --enable-linker-build-id )
675 case "${CT_CC_GCC_LNK_HASH_STYLE}" in
677 *) extra_config+=( "--with-linker-hash-style=${CT_CC_GCC_LNK_HASH_STYLE}" );;
680 if [ "${CT_CC_GCC_ENABLE_PLUGINS}" = "y" ]; then
681 extra_config+=( --enable-plugin )
683 if [ "${CT_CC_GCC_GOLD}" = "y" ]; then
684 extra_config+=( --enable-gold )
689 case "${CT_CC_GCC_mips_llsc}" in
690 y) extra_config+=( --with-llsc );;
692 *) extra_config+=( --without-llsc );;
694 case "${CT_CC_GCC_mips_synci}" in
695 y) extra_config+=( --with-synci );;
697 *) extra_config+=( --without-synci );;
699 if [ "${CT_CC_GCC_mips_plt}" ]; then
700 extra_config+=( --with-mips-plt )
705 [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && extra_config+=("--disable-nls")
707 if [ "${CT_CC_GCC_SYSTEM_ZLIB}" = "y" ]; then
708 extra_config+=("--with-system-zlib")
711 if [ "${CT_MULTILIB}" = "y" ]; then
712 extra_config+=("--enable-multilib")
714 extra_config+=("--disable-multilib")
717 CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
720 CC_FOR_BUILD="${CT_BUILD}-gcc" \
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} \
729 --target=${CT_TARGET} \
730 --prefix="${prefix}" \
732 "${extra_config[@]}" \
733 --with-local-prefix="${CT_SYSROOT_DIR}" \
736 "${CT_CC_EXTRA_CONFIG_ARRAY[@]}"
738 if [ "${CT_CANADIAN}" = "y" ]; then
739 CT_DoLog EXTRA "Building libiberty"
740 CT_DoExecLog ALL make ${JOBSFLAGS} all-build-libiberty
743 CT_DoLog EXTRA "Building final compiler"
744 CT_DoExecLog ALL make ${JOBSFLAGS} all
746 CT_DoLog EXTRA "Installing final compiler"
747 CT_DoExecLog ALL make ${JOBSFLAGS} install
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
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}"
763 if [ "${CT_MULTILIB}" = "y" ]; then
764 multilibs=( $( "${CT_PREFIX_DIR}/bin/${CT_TARGET}-gcc" -print-multi-lib \
766 if [ ${#multilibs[@]} -ne 0 ]; then
767 CT_DoLog EXTRA "gcc configured with these multilibs (besides the default):"
768 for i in "${multilibs[@]}"; do
771 CT_DoLog EXTRA " ${flags//@/ -} --> ${dir}/"
774 CT_DoLog WARN "gcc configured for multilib, but none available"