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 # If we're building for bare metal, build the static core gcc,
63 # In case we're not bare metal and building a canadian compiler, do nothing
64 # In case we're not bare metal, and we're NPTL, build the static core gcc.
65 # In any other case, do nothing.
66 case "${CT_BARE_METAL},${CT_CANADIAN},${CT_THREADS}" in
71 core_opts+=( "mode=static" )
72 core_opts+=( "host=${CT_HOST}" )
73 core_opts+=( "complibs=${CT_COMPLIBS_DIR}" )
74 core_opts+=( "prefix=${CT_CC_CORE_STATIC_PREFIX_DIR}" )
75 core_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
81 if [ "${do_core}" = "y" ]; then
82 CT_DoStep INFO "Installing pass-1 core C compiler"
83 CT_mkdir_pushd "${CT_BUILD_DIR}/build-cc-core-pass-1"
85 do_cc_core_backend "${core_opts[@]}"
97 # In case we're building for bare metal, do nothing, we already have
99 # In case we're not bare metal and building a canadian compiler, do nothing
100 # In case we're NPTL, build the shared core gcc and the target libgcc.
101 # In any other case, build the static core gcc and, if using gcc-4.3+,
102 # also build the target libgcc.
103 case "${CT_BARE_METAL},${CT_CANADIAN},${CT_THREADS}" in
106 core_opts+=( "host=${CT_HOST}" )
107 core_opts+=( "mode=static" )
108 core_opts+=( "prefix=${CT_CC_CORE_STATIC_PREFIX_DIR}" )
109 core_opts+=( "complibs=${CT_COMPLIBS_DIR}" )
110 core_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
115 core_opts+=( "mode=shared" )
116 core_opts+=( "host=${CT_HOST}" )
117 core_opts+=( "build_libgcc=yes" )
118 core_opts+=( "complibs=${CT_COMPLIBS_DIR}" )
119 core_opts+=( "prefix=${CT_CC_CORE_SHARED_PREFIX_DIR}" )
120 core_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
124 core_opts+=( "mode=static" )
125 core_opts+=( "host=${CT_HOST}" )
126 core_opts+=( "build_libgcc=yes" )
127 core_opts+=( "complibs=${CT_COMPLIBS_DIR}" )
128 core_opts+=( "prefix=${CT_CC_CORE_STATIC_PREFIX_DIR}" )
129 core_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
133 core_opts+=( "mode=static" )
134 core_opts+=( "host=${CT_HOST}" )
135 core_opts+=( "complibs=${CT_COMPLIBS_DIR}" )
136 core_opts+=( "prefix=${CT_CC_CORE_STATIC_PREFIX_DIR}" )
137 core_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
138 if [ "${CT_CC_GCC_4_3_or_later}" = "y" ]; then
139 core_opts+=( "build_libgcc=yes" )
144 if [ "${do_core}" = "y" ]; then
145 CT_DoStep INFO "Installing pass-2 core C compiler"
146 CT_mkdir_pushd "${CT_BUILD_DIR}/build-cc-core-pass-2"
148 do_cc_core_backend "${core_opts[@]}"
155 #------------------------------------------------------------------------------
157 # This function is used to build the core C compiler.
158 # Usage: do_cc_core_backend param=value [...]
159 # Parameter : Definition : Type : Default
160 # mode : build a 'static', 'shared' or 'baremetal' : string : (none)
161 # host : the machine the core will run on : tuple : (none)
162 # prefix : dir prefix to install into : dir : (none)
163 # complibs : dir where complibs are isntalled : dir : (none)
164 # build_libgcc : build libgcc or not : bool : no
165 # build_libstdcxx : build libstdc++ or not : bool : no
166 # build_staticlinked : build statically linked or not : bool : no
167 # build_manuals : whether to build manuals or not : bool : no
168 # cflags : host CFLAGS to use : string : (empty)
169 # Usage: do_cc_core_backend mode=[static|shared|baremetal] build_libgcc=[yes|no] build_staticlinked=[yes|no]
170 do_cc_core_backend() {
172 local build_libgcc=no
173 local build_libstdcxx=no
174 local build_staticlinked=no
175 local build_manuals=no
182 local -a host_libstdcxx_flags
183 local -a extra_config
184 local -a core_LDFLAGS
185 local -a core_targets
192 CT_DoLog EXTRA "Configuring core C compiler"
197 extra_config+=("--with-newlib")
198 extra_config+=("--enable-threads=no")
199 extra_config+=("--disable-shared")
200 copy_headers=y # For baremetal, as there's no headers to copy,
201 # we copy an empty directory. So, who cares?
204 extra_config+=("--enable-shared")
208 extra_config+=("--with-newlib")
209 extra_config+=("--enable-threads=no")
210 extra_config+=("--disable-shared")
211 [ "${CT_CC_LANG_CXX}" = "y" ] && lang_opt="${lang_opt},c++"
215 CT_Abort "Internal Error: 'mode' must be one of: 'static', 'shared' or 'baremetal', not '${mode:-(empty)}'"
219 if [ "${CT_CC_GCC_HAS_PKGVERSION_BUGURL}" = "y" ]; then
220 # Bare metal delivers the core compiler as final compiler, so add version info and bugurl
221 extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
222 [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
225 if [ "${copy_headers}" = "y" ]; then
226 CT_DoLog DEBUG "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
227 CT_DoExecLog ALL cp -a "${CT_HEADERS_DIR}" "${prefix}/${CT_TARGET}/include"
230 for tmp in ARCH ABI CPU TUNE FPU FLOAT; do
231 eval tmp="\${CT_ARCH_WITH_${tmp}}"
232 if [ -n "${tmp}" ]; then
233 extra_config+=("${tmp}")
236 if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
237 extra_config+=("--enable-__cxa_atexit")
239 extra_config+=("--disable-__cxa_atexit")
243 # Keep this full if-else-if-elif-fi-fi block in sync
244 # with the same block in do_cc, below.
245 if [ "${build_staticlinked}" = "yes" ]; then
246 core_LDFLAGS+=("-static")
247 host_libstdcxx_flags+=("-static-libgcc")
248 host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++")
249 host_libstdcxx_flags+=("-lm")
250 # Companion libraries are build static (eg !shared), so
251 # the libstdc++ is not pulled automatically, although it
252 # is needed. Shoe-horn it in our LDFLAGS
253 # Ditto libm on some Fedora boxen
254 core_LDFLAGS+=("-lstdc++")
255 core_LDFLAGS+=("-lm")
257 if [ "${CT_CC_STATIC_LIBSTDCXX}" = "y" ]; then
258 # this is from CodeSourcery arm-2010q1-202-arm-none-linux-gnueabi.src.tar.bz2
260 # INFO: if the host gcc is gcc-4.5 then presumably we could use -static-libstdc++,
261 # see http://gcc.gnu.org/ml/gcc-patches/2009-06/msg01635.html
262 host_libstdcxx_flags+=("-static-libgcc")
263 host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++,-Bdynamic")
264 host_libstdcxx_flags+=("-lm")
265 elif [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
266 # When companion libraries are build static (eg !shared),
267 # the libstdc++ is not pulled automatically, although it
268 # is needed. Shoe-horn it in our LDFLAGS
269 # Ditto libm on some Fedora boxen
270 core_LDFLAGS+=("-lstdc++")
271 core_LDFLAGS+=("-lm")
275 if [ "${CT_CC_GCC_USE_GMP_MPFR}" = "y" ]; then
276 extra_config+=("--with-gmp=${complibs}")
277 extra_config+=("--with-mpfr=${complibs}")
279 if [ "${CT_CC_GCC_USE_MPC}" = "y" ]; then
280 extra_config+=("--with-mpc=${complibs}")
282 if [ "${CT_CC_GCC_USE_GRAPHITE}" = "y" ]; then
283 extra_config+=("--with-ppl=${complibs}")
284 # With PPL 0.11+, also pull libpwl if needed
285 if [ "${CT_PPL_NEEDS_LIBPWL}" = "y" ]; then
286 host_libstdcxx_flags+=("-L${complibs}/lib")
287 host_libstdcxx_flags+=("-lpwl")
289 extra_config+=("--with-cloog=${complibs}")
290 elif [ "${CT_CC_GCC_HAS_GRAPHITE}" = "y" ]; then
291 extra_config+=("--with-ppl=no")
292 extra_config+=("--with-cloog=no")
294 if [ "${CT_CC_GCC_USE_LTO}" = "y" ]; then
295 extra_config+=("--with-libelf=${complibs}")
296 extra_config+=("--enable-lto")
297 elif [ "${CT_CC_GCC_HAS_LTO}" = "y" ]; then
298 extra_config+=("--with-libelf=no")
299 extra_config+=("--disable-lto")
302 if [ ${#host_libstdcxx_flags[@]} -ne 0 ]; then
303 extra_config+=("--with-host-libstdcxx=${host_libstdcxx_flags[*]}")
306 if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then
307 extra_config+=("--enable-target-optspace")
310 case "${CT_CC_GCC_LDBL_128}" in
311 y) extra_config+=("--with-long-double-128");;
313 "") extra_config+=("--without-long-double-128");;
316 if [ "${CT_CC_GCC_BUILD_ID}" = "y" ]; then
317 extra_config+=( --enable-linker-build-id )
320 case "${CT_CC_GCC_LNK_HASH_STYLE}" in
322 *) extra_config+=( "--with-linker-hash-style=${CT_CC_GCC_LNK_HASH_STYLE}" );;
327 case "${CT_CC_GCC_mips_llsc}" in
328 y) extra_config+=( --with-llsc );;
330 *) extra_config+=( --without-llsc );;
332 case "${CT_CC_GCC_mips_synci}" in
333 y) extra_config+=( --with-synci );;
335 *) extra_config+=( --without-synci );;
337 if [ "${CT_CC_GCC_mips_plt}" ]; then
338 extra_config+=( --with-mips-plt )
343 extra_config+=(--disable-libgomp)
344 extra_config+=(--disable-libmudflap)
346 [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && extra_config+=("--disable-nls")
348 [ "${CT_CC_GCC_DISABLE_PCH}" = "y" ] && extra_config+=("--disable-libstdcxx-pch")
350 if [ "${CT_CC_GCC_SYSTEM_ZLIB}" = "y" ]; then
351 extra_config+=("--with-system-zlib")
354 if [ "${CT_MULTILIB}" = "y" ]; then
355 extra_config+=("--enable-multilib")
357 extra_config+=("--disable-multilib")
360 CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
362 # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
364 CC_FOR_BUILD="${CT_BUILD}-gcc" \
366 LDFLAGS="${core_LDFLAGS[*]}" \
367 "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/configure" \
368 --build=${CT_BUILD} \
370 --target=${CT_TARGET} \
371 --prefix="${prefix}" \
372 --with-local-prefix="${CT_SYSROOT_DIR}" \
373 --disable-libmudflap \
374 ${CC_CORE_SYSROOT_ARG} \
375 "${extra_config[@]}" \
376 --enable-languages="${lang_opt}" \
377 "${CT_CC_CORE_EXTRA_CONFIG_ARRAY[@]}"
379 if [ "${build_libgcc}" = "yes" ]; then
380 # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
381 # gcc/config/t-libunwind so -lc is removed from the link for
382 # libgcc_s.so, as we do not have a target -lc yet.
383 # This is not as ugly as it appears to be ;-) All symbols get resolved
384 # during the glibc build, and we provide a proper libgcc_s.so for the
385 # cross toolchain during the final gcc build.
387 # As we cannot modify the source tree, nor override SHLIB_LC itself
388 # during configure or make, we have to edit the resultant
389 # gcc/libgcc.mk itself to remove -lc from the link.
390 # This causes us to have to jump through some hoops...
392 # To produce libgcc.mk to edit we firstly require libiberty.a,
393 # so we configure then build it.
394 # Next we have to configure gcc, create libgcc.mk then edit it...
395 # So much easier if we just edit the source tree, but hey...
396 if [ ! -f "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" ]; then
397 CT_DoExecLog CFG make ${JOBSFLAGS} configure-libiberty
398 CT_DoExecLog ALL make ${JOBSFLAGS} -C libiberty libiberty.a
399 CT_DoExecLog CFG make ${JOBSFLAGS} configure-gcc configure-libcpp
400 CT_DoExecLog ALL make ${JOBSFLAGS} all-libcpp
402 CT_DoExecLog CFG make ${JOBSFLAGS} configure-gcc configure-libcpp configure-build-libiberty
403 CT_DoExecLog ALL make ${JOBSFLAGS} all-libcpp all-build-libiberty
405 # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
406 if [ -d "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/libdecnumber" ]; then
407 CT_DoExecLog CFG make ${JOBSFLAGS} configure-libdecnumber
408 CT_DoExecLog ALL make ${JOBSFLAGS} -C libdecnumber libdecnumber.a
411 # Starting with GCC 4.3, libgcc.mk is no longer built,
412 # and libgcc.mvars is used instead.
414 if [ "${CT_CC_GCC_4_3_or_later}" = "y" ]; then
415 libgcc_rule="libgcc.mvars"
416 core_targets=( gcc target-libgcc )
418 libgcc_rule="libgcc.mk"
422 # On bare metal and canadian build the host-compiler is used when
423 # actually the build-system compiler is required. Choose the correct
424 # compilers for canadian build and use the defaults on other
426 if [ "${CT_BARE_METAL},${CT_CANADIAN}" = "y,y" ]; then
427 repair_cc="CC_FOR_BUILD=${CT_BUILD}-gcc \
428 GCC_FOR_TARGET=${CT_TARGET}-gcc"
433 CT_DoExecLog ALL make ${JOBSFLAGS} -C gcc ${libgcc_rule} \
435 sed -r -i -e 's@-lc@@g' gcc/${libgcc_rule}
439 if [ "${build_libstdcxx}" = "yes" \
440 -a "${CT_CC_LANG_CXX}" = "y" \
442 core_targets+=( target-libstdc++-v3 )
445 CT_DoLog EXTRA "Building core C compiler"
446 CT_DoExecLog ALL make ${JOBSFLAGS} "${core_targets[@]/#/all-}"
448 CT_DoLog EXTRA "Installing core C compiler"
449 CT_DoExecLog ALL make ${JOBSFLAGS} "${core_targets[@]/#/install-}"
451 if [ "${build_manuals}" = "yes" ]; then
452 CT_DoLog EXTRA "Building the GCC manuals"
453 CT_DoExecLog ALL make pdf html
454 CT_DoLog EXTRA "Installing the GCC manuals"
455 CT_DoExecLog ALL make install-{pdf,html}-gcc
458 # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
459 # to call the C compiler with the same, somewhat canonical name.
460 # check whether compiler has an extension
461 file="$( ls -1 "${prefix}/bin/${CT_TARGET}-gcc."* 2>/dev/null || true )"
462 [ -z "${file}" ] || ext=".${file##*.}"
463 CT_DoExecLog ALL ln -sfv "${CT_TARGET}-gcc${ext}" "${prefix}/bin/${CT_TARGET}-cc${ext}"
465 if [ "${CT_MULTILIB}" = "y" ]; then
466 multilibs=( $( "${prefix}/bin/${CT_TARGET}-gcc" -print-multi-lib \
468 if [ ${#multilibs[@]} -ne 0 ]; then
469 CT_DoLog EXTRA "gcc configured with these multilibs (besides the default):"
470 for i in "${multilibs[@]}"; do
473 CT_DoLog EXTRA " ${flags//@/ -} --> ${dir}/"
476 CT_DoLog WARN "gcc configured for multilib, but none available"
481 #------------------------------------------------------------------------------
487 final_opts+=( "host=${CT_HOST}" )
488 final_opts+=( "prefix=${CT_PREFIX_DIR}" )
489 final_opts+=( "complibs=${CT_COMPLIBS_DIR}" )
490 final_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
491 if [ "${CT_BUILD_MANUALS}" = "y" ]; then
492 final_opts+=( "build_manuals=yes" )
494 if [ "${CT_BARE_METAL}" = "y" ]; then
495 final_opts+=( "mode=baremetal" )
496 final_opts+=( "build_libgcc=yes" )
497 final_opts+=( "build_libstdcxx=yes" )
498 if [ "${CT_STATIC_TOOLCHAIN}" = "y" ]; then
499 final_opts+=( "build_staticlinked=yes" )
501 final_backend=do_cc_core_backend
503 final_backend=do_cc_backend
506 CT_DoStep INFO "Installing final compiler"
507 CT_mkdir_pushd "${CT_BUILD_DIR}/build-cc-final"
509 "${final_backend}" "${final_opts[@]}"
515 #------------------------------------------------------------------------------
516 # Build the final gcc
517 # Usage: do_cc_backend param=value [...]
518 # Parameter : Definition : Type : Default
519 # host : the host we run onto : tuple : (none)
520 # prefix : the runtime prefix : dir : (none)
521 # complibs : the companion libraries prefix : dir : (none)
522 # cflags : the host CFLAGS : string : (empty)
523 # build_manuals : whether to build manuals or not : bool : no
530 local -a host_libstdcxx_flags
531 local -a extra_config
532 local -a final_LDFLAGS
540 CT_DoLog EXTRA "Configuring final compiler"
542 # Enable selected languages
544 [ "${CT_CC_LANG_CXX}" = "y" ] && lang_opt="${lang_opt},c++"
545 [ "${CT_CC_LANG_FORTRAN}" = "y" ] && lang_opt="${lang_opt},fortran"
546 [ "${CT_CC_LANG_ADA}" = "y" ] && lang_opt="${lang_opt},ada"
547 [ "${CT_CC_LANG_JAVA}" = "y" ] && lang_opt="${lang_opt},java"
548 [ "${CT_CC_LANG_OBJC}" = "y" ] && lang_opt="${lang_opt},objc"
549 [ "${CT_CC_LANG_OBJCXX}" = "y" ] && lang_opt="${lang_opt},obj-c++"
550 CT_Test "Building ADA language is not yet supported. Will try..." "${CT_CC_LANG_ADA}" = "y"
551 CT_Test "Building Objective-C language is not yet supported. Will try..." "${CT_CC_LANG_OBJC}" = "y"
552 CT_Test "Building Objective-C++ language is not yet supported. Will try..." "${CT_CC_LANG_OBJCXX}" = "y"
553 CT_Test "Building ${CT_CC_LANG_OTHERS//,/ } language(s) is not yet supported. Will try..." -n "${CT_CC_LANG_OTHERS}"
554 lang_opt=$(echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;')
556 extra_config+=("--enable-languages=${lang_opt}")
557 for tmp in ARCH ABI CPU TUNE FPU FLOAT; do
558 eval tmp="\${CT_ARCH_WITH_${tmp}}"
559 if [ -n "${tmp}" ]; then
560 extra_config+=("${tmp}")
564 [ "${CT_SHARED_LIBS}" = "y" ] || extra_config+=("--disable-shared")
565 if [ "${CT_CC_GCC_HAS_PKGVERSION_BUGURL}" = "y" ]; then
566 extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
567 [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
569 case "${CT_CC_GCC_SJLJ_EXCEPTIONS}" in
570 y) extra_config+=("--enable-sjlj-exceptions");;
572 "") extra_config+=("--disable-sjlj-exceptions");;
574 if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
575 extra_config+=("--enable-__cxa_atexit")
577 extra_config+=("--disable-__cxa_atexit")
579 if [ -n "${CT_CC_ENABLE_CXX_FLAGS}" ]; then
580 extra_config+=("--enable-cxx-flags=${CT_CC_ENABLE_CXX_FLAGS}")
582 if [ "${CT_CC_GCC_LIBMUDFLAP}" = "y" ]; then
583 extra_config+=(--enable-libmudflap)
585 extra_config+=(--disable-libmudflap)
587 if [ "${CT_CC_GCC_LIBGOMP}" = "y" ]; then
588 extra_config+=(--enable-libgomp)
590 extra_config+=(--disable-libgomp)
592 if [ "${CT_CC_GCC_LIBSSP}" = "y" ]; then
593 extra_config+=(--enable-libssp)
595 extra_config+=(--disable-libssp)
599 # Keep this full if-else-if-elif-fi-fi block in sync
600 # with the same block in do_cc_core, above.
601 if [ "${CT_STATIC_TOOLCHAIN}" = "y" ]; then
602 final_LDFLAGS+=("-static")
603 host_libstdcxx_flags+=("-static-libgcc")
604 host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++")
605 host_libstdcxx_flags+=("-lm")
606 # Companion libraries are build static (eg !shared), so
607 # the libstdc++ is not pulled automatically, although it
608 # is needed. Shoe-horn it in our LDFLAGS
609 # Ditto libm on some Fedora boxen
610 final_LDFLAGS+=("-lstdc++")
611 final_LDFLAGS+=("-lm")
613 if [ "${CT_CC_STATIC_LIBSTDCXX}" = "y" ]; then
614 # this is from CodeSourcery arm-2010q1-202-arm-none-linux-gnueabi.src.tar.bz2
616 # INFO: if the host gcc is gcc-4.5 then presumably we could use -static-libstdc++,
617 # see http://gcc.gnu.org/ml/gcc-patches/2009-06/msg01635.html
618 host_libstdcxx_flags+=("-static-libgcc")
619 host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++,-Bdynamic")
620 host_libstdcxx_flags+=("-lm")
621 elif [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
622 # When companion libraries are build static (eg !shared),
623 # the libstdc++ is not pulled automatically, although it
624 # is needed. Shoe-horn it in our LDFLAGS
625 # Ditto libm on some Fedora boxen
626 final_LDFLAGS+=("-lstdc++")
627 final_LDFLAGS+=("-lm")
631 if [ "${CT_CC_GCC_USE_GMP_MPFR}" = "y" ]; then
632 extra_config+=("--with-gmp=${complibs}")
633 extra_config+=("--with-mpfr=${complibs}")
635 if [ "${CT_CC_GCC_USE_MPC}" = "y" ]; then
636 extra_config+=("--with-mpc=${complibs}")
638 if [ "${CT_CC_GCC_USE_GRAPHITE}" = "y" ]; then
639 extra_config+=("--with-ppl=${complibs}")
640 # With PPL 0.11+, also pull libpwl if needed
641 if [ "${CT_PPL_NEEDS_LIBPWL}" = "y" ]; then
642 host_libstdcxx_flags+=("-L${complibs}/lib")
643 host_libstdcxx_flags+=("-lpwl")
645 extra_config+=("--with-cloog=${complibs}")
646 elif [ "${CT_CC_GCC_HAS_GRAPHITE}" = "y" ]; then
647 extra_config+=("--with-ppl=no")
648 extra_config+=("--with-cloog=no")
650 if [ "${CT_CC_GCC_USE_LTO}" = "y" ]; then
651 extra_config+=("--with-libelf=${complibs}")
652 elif [ "${CT_CC_GCC_HAS_LTO}" = "y" ]; then
653 extra_config+=("--with-libelf=no")
656 if [ ${#host_libstdcxx_flags[@]} -ne 0 ]; then
657 extra_config+=("--with-host-libstdcxx=${host_libstdcxx_flags[*]}")
660 if [ "${CT_THREADS}" = "none" ]; then
661 extra_config+=("--disable-threads")
662 if [ "${CT_CC_GCC_4_2_or_later}" = y ]; then
663 CT_Test "Disabling libgomp for no-thread gcc>=4.2" "${CT_CC_GCC_LIBGOMP}" = "Y"
664 extra_config+=("--disable-libgomp")
667 if [ "${CT_THREADS}" = "win32" ]; then
668 extra_config+=("--enable-threads=win32")
669 extra_config+=("--disable-win32-registry")
671 extra_config+=("--enable-threads=posix")
675 if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then
676 extra_config+=("--enable-target-optspace")
678 if [ "${CT_CC_GCC_DISABLE_PCH}" = "y" ]; then
679 extra_config+=("--disable-libstdcxx-pch")
682 case "${CT_CC_GCC_LDBL_128}" in
683 y) extra_config+=("--with-long-double-128");;
685 "") extra_config+=("--without-long-double-128");;
688 if [ "${CT_CC_GCC_BUILD_ID}" = "y" ]; then
689 extra_config+=( --enable-linker-build-id )
692 case "${CT_CC_GCC_LNK_HASH_STYLE}" in
694 *) extra_config+=( "--with-linker-hash-style=${CT_CC_GCC_LNK_HASH_STYLE}" );;
697 if [ "${CT_CC_GCC_ENABLE_PLUGINS}" = "y" ]; then
698 extra_config+=( --enable-plugin )
700 if [ "${CT_CC_GCC_GOLD}" = "y" ]; then
701 extra_config+=( --enable-gold )
706 case "${CT_CC_GCC_mips_llsc}" in
707 y) extra_config+=( --with-llsc );;
709 *) extra_config+=( --without-llsc );;
711 case "${CT_CC_GCC_mips_synci}" in
712 y) extra_config+=( --with-synci );;
714 *) extra_config+=( --without-synci );;
716 if [ "${CT_CC_GCC_mips_plt}" ]; then
717 extra_config+=( --with-mips-plt )
722 [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && extra_config+=("--disable-nls")
724 if [ "${CT_CC_GCC_SYSTEM_ZLIB}" = "y" ]; then
725 extra_config+=("--with-system-zlib")
728 if [ "${CT_MULTILIB}" = "y" ]; then
729 extra_config+=("--enable-multilib")
731 extra_config+=("--disable-multilib")
734 CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
737 CC_FOR_BUILD="${CT_BUILD}-gcc" \
739 LDFLAGS="${final_LDFLAGS[*]}" \
740 CFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}" \
741 CXXFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}" \
742 LDFLAGS_FOR_TARGET="${CT_TARGET_LDFLAGS}" \
743 "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/configure" \
744 --build=${CT_BUILD} \
746 --target=${CT_TARGET} \
747 --prefix="${prefix}" \
749 "${extra_config[@]}" \
750 --with-local-prefix="${CT_SYSROOT_DIR}" \
753 "${CT_CC_EXTRA_CONFIG_ARRAY[@]}"
755 if [ "${CT_CANADIAN}" = "y" ]; then
756 CT_DoLog EXTRA "Building libiberty"
757 CT_DoExecLog ALL make ${JOBSFLAGS} all-build-libiberty
760 CT_DoLog EXTRA "Building final compiler"
761 CT_DoExecLog ALL make ${JOBSFLAGS} all
763 CT_DoLog EXTRA "Installing final compiler"
764 CT_DoExecLog ALL make ${JOBSFLAGS} install
766 if [ "${build_manuals}" = "yes" ]; then
767 CT_DoLog EXTRA "Building the GCC manuals"
768 CT_DoExecLog ALL make ${JOBSFLAGS} pdf html
769 CT_DoLog EXTRA "Installing the GCC manuals"
770 CT_DoExecLog ALL make install-{pdf,html}-gcc
773 # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
774 # to call the C compiler with the same, somewhat canonical name.
775 # check whether compiler has an extension
776 file="$( ls -1 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-gcc."* 2>/dev/null || true )"
777 [ -z "${file}" ] || ext=".${file##*.}"
778 CT_DoExecLog ALL ln -sfv "${CT_TARGET}-gcc${ext}" "${CT_PREFIX_DIR}/bin/${CT_TARGET}-cc${ext}"
780 if [ "${CT_MULTILIB}" = "y" ]; then
781 multilibs=( $( "${CT_PREFIX_DIR}/bin/${CT_TARGET}-gcc" -print-multi-lib \
783 if [ ${#multilibs[@]} -ne 0 ]; then
784 CT_DoLog EXTRA "gcc configured with these multilibs (besides the default):"
785 for i in "${multilibs[@]}"; do
788 CT_DoLog EXTRA " ${flags//@/ -} --> ${dir}/"
791 CT_DoLog WARN "gcc configured for multilib, but none available"