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 #------------------------------------------------------------------------------
56 # This function builds up the set of languages to enable
57 # No argument expected, returns the comma-separated language list on stdout
62 [ "${CT_CC_LANG_CXX}" = "y" ] && lang_list+=",c++"
63 [ "${CT_CC_LANG_FORTRAN}" = "y" ] && lang_list+=",fortran"
64 [ "${CT_CC_LANG_ADA}" = "y" ] && lang_list+=",ada"
65 [ "${CT_CC_LANG_JAVA}" = "y" ] && lang_list+=",java"
66 [ "${CT_CC_LANG_OBJC}" = "y" ] && lang_list+=",objc"
67 [ "${CT_CC_LANG_OBJCXX}" = "y" ] && lang_list+=",obj-c++"
68 lang_list+="${CT_CC_LANG_OTHERS:+,${CT_CC_LANG_OTHERS}}"
70 printf "%s" "${lang_list}"
73 #------------------------------------------------------------------------------
79 # Do nothing for canadian-crosses, we already have a target compiler.
80 # We only need a pass-1 core gcc if the threading model is NPTL.
81 # For all other cases, it is not used.
82 case "${CT_CANADIAN},${CT_THREADS}" in
87 core_opts+=( "mode=static" )
88 core_opts+=( "host=${CT_BUILD}" )
89 core_opts+=( "complibs=${CT_BUILDTOOLS_PREFIX_DIR}" )
90 core_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
91 core_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
95 if [ "${do_core}" = "y" ]; then
96 CT_DoStep INFO "Installing pass-1 core C compiler"
97 CT_mkdir_pushd "${CT_BUILD_DIR}/build-cc-core-pass-1"
99 do_cc_core_backend "${core_opts[@]}"
107 do_cc_core_pass_2() {
112 core_opts+=( "host=${CT_BUILD}" )
113 core_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
114 core_opts+=( "complibs=${CT_BUILDTOOLS_PREFIX_DIR}" )
115 core_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
117 # Do nothing for canadian-crosses, we already have a target compiler.
118 # Different conditions are at stake here:
119 # - In case the threading model is NPTL, we need a shared-capable core
120 # gcc; in all other cases, we need a static-only core gcc.
121 # - In case the threading model is NPTL or win32, or gcc is 4.3 or
122 # later, we need to build libgcc
123 case "${CT_CANADIAN},${CT_THREADS}" in
128 core_opts+=( "mode=shared" )
129 core_opts+=( "build_libgcc=yes" )
133 core_opts+=( "mode=static" )
134 core_opts+=( "build_libgcc=yes" )
138 core_opts+=( "mode=static" )
139 if [ "${CT_CC_GCC_4_3_or_later}" = "y" ]; then
140 core_opts+=( "build_libgcc=yes" )
145 if [ "${do_core}" = "y" ]; then
146 CT_DoStep INFO "Installing pass-2 core C compiler"
147 CT_mkdir_pushd "${CT_BUILD_DIR}/build-cc-core-pass-2"
149 do_cc_core_backend "${core_opts[@]}"
156 #------------------------------------------------------------------------------
158 # This function is used to build the core C compiler.
159 # Usage: do_cc_core_backend param=value [...]
160 # Parameter : Definition : Type : Default
161 # mode : build a 'static', 'shared' or 'baremetal' : string : (none)
162 # host : the machine the core will run on : tuple : (none)
163 # prefix : dir prefix to install into : dir : (none)
164 # complibs : dir where complibs are isntalled : dir : (none)
165 # build_libgcc : build libgcc or not : bool : no
166 # build_libstdcxx : build libstdc++ or not : bool : no
167 # build_staticlinked : build statically linked or not : bool : no
168 # build_manuals : whether to build manuals or not : bool : no
169 # cflags : host CFLAGS to use : string : (empty)
170 # Usage: do_cc_core_backend mode=[static|shared|baremetal] build_libgcc=[yes|no] build_staticlinked=[yes|no]
171 do_cc_core_backend() {
173 local build_libgcc=no
174 local build_libstdcxx=no
175 local build_staticlinked=no
176 local build_manuals=no
183 local -a host_libstdcxx_flags
184 local -a extra_config
185 local -a core_LDFLAGS
186 local -a core_targets
193 CT_DoLog EXTRA "Configuring core C compiler"
198 extra_config+=("--with-newlib")
199 extra_config+=("--enable-threads=no")
200 extra_config+=("--disable-shared")
201 copy_headers=y # For baremetal, as there's no headers to copy,
202 # we copy an empty directory. So, who cares?
205 extra_config+=("--enable-shared")
209 extra_config+=("--with-newlib")
210 extra_config+=("--enable-threads=no")
211 extra_config+=("--disable-shared")
212 [ "${CT_CC_LANG_CXX}" = "y" ] && lang_opt="${lang_opt},c++"
216 CT_Abort "Internal Error: 'mode' must be one of: 'static', 'shared' or 'baremetal', not '${mode:-(empty)}'"
220 if [ "${CT_CC_GCC_HAS_PKGVERSION_BUGURL}" = "y" ]; then
221 # Bare metal delivers the core compiler as final compiler, so add version info and bugurl
222 extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
223 [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
226 if [ "${copy_headers}" = "y" ]; then
227 CT_DoLog DEBUG "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
228 CT_DoExecLog ALL cp -a "${CT_HEADERS_DIR}" "${prefix}/${CT_TARGET}/include"
231 for tmp in ARCH ABI CPU TUNE FPU FLOAT; do
232 eval tmp="\${CT_ARCH_WITH_${tmp}}"
233 if [ -n "${tmp}" ]; then
234 extra_config+=("${tmp}")
237 if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
238 extra_config+=("--enable-__cxa_atexit")
240 extra_config+=("--disable-__cxa_atexit")
244 # Keep this full if-else-if-elif-fi-fi block in sync
245 # with the same block in do_cc, below.
246 if [ "${build_staticlinked}" = "yes" ]; then
247 core_LDFLAGS+=("-static")
248 host_libstdcxx_flags+=("-static-libgcc")
249 host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++")
250 host_libstdcxx_flags+=("-lm")
251 # Companion libraries are build static (eg !shared), so
252 # the libstdc++ is not pulled automatically, although it
253 # is needed. Shoe-horn it in our LDFLAGS
254 # Ditto libm on some Fedora boxen
255 core_LDFLAGS+=("-lstdc++")
256 core_LDFLAGS+=("-lm")
258 if [ "${CT_CC_STATIC_LIBSTDCXX}" = "y" ]; then
259 # this is from CodeSourcery arm-2010q1-202-arm-none-linux-gnueabi.src.tar.bz2
261 # INFO: if the host gcc is gcc-4.5 then presumably we could use -static-libstdc++,
262 # see http://gcc.gnu.org/ml/gcc-patches/2009-06/msg01635.html
263 host_libstdcxx_flags+=("-static-libgcc")
264 host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++,-Bdynamic")
265 host_libstdcxx_flags+=("-lm")
266 elif [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
267 # When companion libraries are build static (eg !shared),
268 # the libstdc++ is not pulled automatically, although it
269 # is needed. Shoe-horn it in our LDFLAGS
270 # Ditto libm on some Fedora boxen
271 core_LDFLAGS+=("-lstdc++")
272 core_LDFLAGS+=("-lm")
276 if [ "${CT_CC_GCC_USE_GMP_MPFR}" = "y" ]; then
277 extra_config+=("--with-gmp=${complibs}")
278 extra_config+=("--with-mpfr=${complibs}")
280 if [ "${CT_CC_GCC_USE_MPC}" = "y" ]; then
281 extra_config+=("--with-mpc=${complibs}")
283 if [ "${CT_CC_GCC_USE_GRAPHITE}" = "y" ]; then
284 extra_config+=("--with-ppl=${complibs}")
285 # With PPL 0.11+, also pull libpwl if needed
286 if [ "${CT_PPL_NEEDS_LIBPWL}" = "y" ]; then
287 host_libstdcxx_flags+=("-L${complibs}/lib")
288 host_libstdcxx_flags+=("-lpwl")
290 extra_config+=("--with-cloog=${complibs}")
291 elif [ "${CT_CC_GCC_HAS_GRAPHITE}" = "y" ]; then
292 extra_config+=("--with-ppl=no")
293 extra_config+=("--with-cloog=no")
295 if [ "${CT_CC_GCC_USE_LTO}" = "y" ]; then
296 extra_config+=("--with-libelf=${complibs}")
297 extra_config+=("--enable-lto")
298 elif [ "${CT_CC_GCC_HAS_LTO}" = "y" ]; then
299 extra_config+=("--with-libelf=no")
300 extra_config+=("--disable-lto")
303 if [ ${#host_libstdcxx_flags[@]} -ne 0 ]; then
304 extra_config+=("--with-host-libstdcxx=${host_libstdcxx_flags[*]}")
307 if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then
308 extra_config+=("--enable-target-optspace")
311 case "${CT_CC_GCC_LDBL_128}" in
312 y) extra_config+=("--with-long-double-128");;
314 "") extra_config+=("--without-long-double-128");;
317 if [ "${CT_CC_GCC_BUILD_ID}" = "y" ]; then
318 extra_config+=( --enable-linker-build-id )
321 case "${CT_CC_GCC_LNK_HASH_STYLE}" in
323 *) extra_config+=( "--with-linker-hash-style=${CT_CC_GCC_LNK_HASH_STYLE}" );;
328 case "${CT_CC_GCC_mips_llsc}" in
329 y) extra_config+=( --with-llsc );;
331 *) extra_config+=( --without-llsc );;
333 case "${CT_CC_GCC_mips_synci}" in
334 y) extra_config+=( --with-synci );;
336 *) extra_config+=( --without-synci );;
338 if [ "${CT_CC_GCC_mips_plt}" ]; then
339 extra_config+=( --with-mips-plt )
344 extra_config+=(--disable-libgomp)
345 extra_config+=(--disable-libmudflap)
347 [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && extra_config+=("--disable-nls")
349 [ "${CT_CC_GCC_DISABLE_PCH}" = "y" ] && extra_config+=("--disable-libstdcxx-pch")
351 if [ "${CT_CC_GCC_SYSTEM_ZLIB}" = "y" ]; then
352 extra_config+=("--with-system-zlib")
355 if [ "${CT_MULTILIB}" = "y" ]; then
356 extra_config+=("--enable-multilib")
358 extra_config+=("--disable-multilib")
361 CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
363 # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
365 CC_FOR_BUILD="${CT_BUILD}-gcc" \
367 LDFLAGS="${core_LDFLAGS[*]}" \
368 "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/configure" \
369 --build=${CT_BUILD} \
371 --target=${CT_TARGET} \
372 --prefix="${prefix}" \
373 --with-local-prefix="${CT_SYSROOT_DIR}" \
374 --disable-libmudflap \
375 ${CC_CORE_SYSROOT_ARG} \
376 "${extra_config[@]}" \
377 --enable-languages="${lang_opt}" \
378 "${CT_CC_CORE_EXTRA_CONFIG_ARRAY[@]}"
380 if [ "${build_libgcc}" = "yes" ]; then
381 # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
382 # gcc/config/t-libunwind so -lc is removed from the link for
383 # libgcc_s.so, as we do not have a target -lc yet.
384 # This is not as ugly as it appears to be ;-) All symbols get resolved
385 # during the glibc build, and we provide a proper libgcc_s.so for the
386 # cross toolchain during the final gcc build.
388 # As we cannot modify the source tree, nor override SHLIB_LC itself
389 # during configure or make, we have to edit the resultant
390 # gcc/libgcc.mk itself to remove -lc from the link.
391 # This causes us to have to jump through some hoops...
393 # To produce libgcc.mk to edit we firstly require libiberty.a,
394 # so we configure then build it.
395 # Next we have to configure gcc, create libgcc.mk then edit it...
396 # So much easier if we just edit the source tree, but hey...
397 if [ ! -f "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" ]; then
398 CT_DoExecLog CFG make ${JOBSFLAGS} configure-libiberty
399 CT_DoExecLog ALL make ${JOBSFLAGS} -C libiberty libiberty.a
400 CT_DoExecLog CFG make ${JOBSFLAGS} configure-gcc configure-libcpp
401 CT_DoExecLog ALL make ${JOBSFLAGS} all-libcpp
403 CT_DoExecLog CFG make ${JOBSFLAGS} configure-gcc configure-libcpp configure-build-libiberty
404 CT_DoExecLog ALL make ${JOBSFLAGS} all-libcpp all-build-libiberty
406 # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
407 if [ -d "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/libdecnumber" ]; then
408 CT_DoExecLog CFG make ${JOBSFLAGS} configure-libdecnumber
409 CT_DoExecLog ALL make ${JOBSFLAGS} -C libdecnumber libdecnumber.a
412 # Starting with GCC 4.3, libgcc.mk is no longer built,
413 # and libgcc.mvars is used instead.
415 if [ "${CT_CC_GCC_4_3_or_later}" = "y" ]; then
416 libgcc_rule="libgcc.mvars"
417 core_targets=( gcc target-libgcc )
419 libgcc_rule="libgcc.mk"
423 # On bare metal and canadian build the host-compiler is used when
424 # actually the build-system compiler is required. Choose the correct
425 # compilers for canadian build and use the defaults on other
427 if [ "${CT_BARE_METAL},${CT_CANADIAN}" = "y,y" ]; then
428 repair_cc="CC_FOR_BUILD=${CT_BUILD}-gcc \
429 GCC_FOR_TARGET=${CT_TARGET}-gcc"
434 CT_DoExecLog ALL make ${JOBSFLAGS} -C gcc ${libgcc_rule} \
436 sed -r -i -e 's@-lc@@g' gcc/${libgcc_rule}
440 if [ "${build_libstdcxx}" = "yes" \
441 -a "${CT_CC_LANG_CXX}" = "y" \
443 core_targets+=( target-libstdc++-v3 )
446 CT_DoLog EXTRA "Building core C compiler"
447 CT_DoExecLog ALL make ${JOBSFLAGS} "${core_targets[@]/#/all-}"
449 CT_DoLog EXTRA "Installing core C compiler"
450 CT_DoExecLog ALL make ${JOBSFLAGS} "${core_targets[@]/#/install-}"
452 if [ "${build_manuals}" = "yes" ]; then
453 CT_DoLog EXTRA "Building the GCC manuals"
454 CT_DoExecLog ALL make pdf html
455 CT_DoLog EXTRA "Installing the GCC manuals"
456 CT_DoExecLog ALL make install-{pdf,html}-gcc
459 # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
460 # to call the C compiler with the same, somewhat canonical name.
461 # check whether compiler has an extension
462 file="$( ls -1 "${prefix}/bin/${CT_TARGET}-gcc."* 2>/dev/null || true )"
463 [ -z "${file}" ] || ext=".${file##*.}"
464 CT_DoExecLog ALL ln -sfv "${CT_TARGET}-gcc${ext}" "${prefix}/bin/${CT_TARGET}-cc${ext}"
466 if [ "${CT_MULTILIB}" = "y" ]; then
467 multilibs=( $( "${prefix}/bin/${CT_TARGET}-gcc" -print-multi-lib \
469 if [ ${#multilibs[@]} -ne 0 ]; then
470 CT_DoLog EXTRA "gcc configured with these multilibs (besides the default):"
471 for i in "${multilibs[@]}"; do
474 CT_DoLog EXTRA " ${flags//@/ -} --> ${dir}/"
477 CT_DoLog WARN "gcc configured for multilib, but none available"
482 #------------------------------------------------------------------------------
488 final_opts+=( "host=${CT_HOST}" )
489 final_opts+=( "prefix=${CT_PREFIX_DIR}" )
490 final_opts+=( "complibs=${CT_HOST_COMPLIBS_DIR}" )
491 final_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
492 if [ "${CT_BUILD_MANUALS}" = "y" ]; then
493 final_opts+=( "build_manuals=yes" )
495 if [ "${CT_BARE_METAL}" = "y" ]; then
496 final_opts+=( "mode=baremetal" )
497 final_opts+=( "build_libgcc=yes" )
498 final_opts+=( "build_libstdcxx=yes" )
499 if [ "${CT_STATIC_TOOLCHAIN}" = "y" ]; then
500 final_opts+=( "build_staticlinked=yes" )
502 final_backend=do_cc_core_backend
504 final_backend=do_cc_backend
507 CT_DoStep INFO "Installing final compiler"
508 CT_mkdir_pushd "${CT_BUILD_DIR}/build-cc-final"
510 "${final_backend}" "${final_opts[@]}"
516 #------------------------------------------------------------------------------
517 # Build the final gcc
518 # Usage: do_cc_backend param=value [...]
519 # Parameter : Definition : Type : Default
520 # host : the host we run onto : tuple : (none)
521 # prefix : the runtime prefix : dir : (none)
522 # complibs : the companion libraries prefix : dir : (none)
523 # cflags : the host CFLAGS : string : (empty)
524 # build_manuals : whether to build manuals or not : bool : no
531 local -a host_libstdcxx_flags
532 local -a extra_config
533 local -a final_LDFLAGS
541 CT_DoLog EXTRA "Configuring final compiler"
543 # Enable selected languages
544 extra_config+=("--enable-languages=$( cc_gcc_lang_list )")
546 for tmp in ARCH ABI CPU TUNE FPU FLOAT; do
547 eval tmp="\${CT_ARCH_WITH_${tmp}}"
548 if [ -n "${tmp}" ]; then
549 extra_config+=("${tmp}")
553 [ "${CT_SHARED_LIBS}" = "y" ] || extra_config+=("--disable-shared")
554 if [ "${CT_CC_GCC_HAS_PKGVERSION_BUGURL}" = "y" ]; then
555 extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
556 [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
558 case "${CT_CC_GCC_SJLJ_EXCEPTIONS}" in
559 y) extra_config+=("--enable-sjlj-exceptions");;
561 "") extra_config+=("--disable-sjlj-exceptions");;
563 if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
564 extra_config+=("--enable-__cxa_atexit")
566 extra_config+=("--disable-__cxa_atexit")
568 if [ -n "${CT_CC_ENABLE_CXX_FLAGS}" ]; then
569 extra_config+=("--enable-cxx-flags=${CT_CC_ENABLE_CXX_FLAGS}")
571 if [ "${CT_CC_GCC_LIBMUDFLAP}" = "y" ]; then
572 extra_config+=(--enable-libmudflap)
574 extra_config+=(--disable-libmudflap)
576 if [ "${CT_CC_GCC_LIBGOMP}" = "y" ]; then
577 extra_config+=(--enable-libgomp)
579 extra_config+=(--disable-libgomp)
581 if [ "${CT_CC_GCC_LIBSSP}" = "y" ]; then
582 extra_config+=(--enable-libssp)
584 extra_config+=(--disable-libssp)
588 # Keep this full if-else-if-elif-fi-fi block in sync
589 # with the same block in do_cc_core, above.
590 if [ "${CT_STATIC_TOOLCHAIN}" = "y" ]; then
591 final_LDFLAGS+=("-static")
592 host_libstdcxx_flags+=("-static-libgcc")
593 host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++")
594 host_libstdcxx_flags+=("-lm")
595 # Companion libraries are build static (eg !shared), so
596 # the libstdc++ is not pulled automatically, although it
597 # is needed. Shoe-horn it in our LDFLAGS
598 # Ditto libm on some Fedora boxen
599 final_LDFLAGS+=("-lstdc++")
600 final_LDFLAGS+=("-lm")
602 if [ "${CT_CC_STATIC_LIBSTDCXX}" = "y" ]; then
603 # this is from CodeSourcery arm-2010q1-202-arm-none-linux-gnueabi.src.tar.bz2
605 # INFO: if the host gcc is gcc-4.5 then presumably we could use -static-libstdc++,
606 # see http://gcc.gnu.org/ml/gcc-patches/2009-06/msg01635.html
607 host_libstdcxx_flags+=("-static-libgcc")
608 host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++,-Bdynamic")
609 host_libstdcxx_flags+=("-lm")
610 elif [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
611 # When companion libraries are build static (eg !shared),
612 # the libstdc++ is not pulled automatically, although it
613 # is needed. Shoe-horn it in our LDFLAGS
614 # Ditto libm on some Fedora boxen
615 final_LDFLAGS+=("-lstdc++")
616 final_LDFLAGS+=("-lm")
620 if [ "${CT_CC_GCC_USE_GMP_MPFR}" = "y" ]; then
621 extra_config+=("--with-gmp=${complibs}")
622 extra_config+=("--with-mpfr=${complibs}")
624 if [ "${CT_CC_GCC_USE_MPC}" = "y" ]; then
625 extra_config+=("--with-mpc=${complibs}")
627 if [ "${CT_CC_GCC_USE_GRAPHITE}" = "y" ]; then
628 extra_config+=("--with-ppl=${complibs}")
629 # With PPL 0.11+, also pull libpwl if needed
630 if [ "${CT_PPL_NEEDS_LIBPWL}" = "y" ]; then
631 host_libstdcxx_flags+=("-L${complibs}/lib")
632 host_libstdcxx_flags+=("-lpwl")
634 extra_config+=("--with-cloog=${complibs}")
635 elif [ "${CT_CC_GCC_HAS_GRAPHITE}" = "y" ]; then
636 extra_config+=("--with-ppl=no")
637 extra_config+=("--with-cloog=no")
639 if [ "${CT_CC_GCC_USE_LTO}" = "y" ]; then
640 extra_config+=("--with-libelf=${complibs}")
641 elif [ "${CT_CC_GCC_HAS_LTO}" = "y" ]; then
642 extra_config+=("--with-libelf=no")
645 if [ ${#host_libstdcxx_flags[@]} -ne 0 ]; then
646 extra_config+=("--with-host-libstdcxx=${host_libstdcxx_flags[*]}")
649 if [ "${CT_THREADS}" = "none" ]; then
650 extra_config+=("--disable-threads")
651 if [ "${CT_CC_GCC_4_2_or_later}" = y ]; then
652 CT_Test "Disabling libgomp for no-thread gcc>=4.2" "${CT_CC_GCC_LIBGOMP}" = "Y"
653 extra_config+=("--disable-libgomp")
656 if [ "${CT_THREADS}" = "win32" ]; then
657 extra_config+=("--enable-threads=win32")
658 extra_config+=("--disable-win32-registry")
660 extra_config+=("--enable-threads=posix")
664 if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then
665 extra_config+=("--enable-target-optspace")
667 if [ "${CT_CC_GCC_DISABLE_PCH}" = "y" ]; then
668 extra_config+=("--disable-libstdcxx-pch")
671 case "${CT_CC_GCC_LDBL_128}" in
672 y) extra_config+=("--with-long-double-128");;
674 "") extra_config+=("--without-long-double-128");;
677 if [ "${CT_CC_GCC_BUILD_ID}" = "y" ]; then
678 extra_config+=( --enable-linker-build-id )
681 case "${CT_CC_GCC_LNK_HASH_STYLE}" in
683 *) extra_config+=( "--with-linker-hash-style=${CT_CC_GCC_LNK_HASH_STYLE}" );;
686 if [ "${CT_CC_GCC_ENABLE_PLUGINS}" = "y" ]; then
687 extra_config+=( --enable-plugin )
689 if [ "${CT_CC_GCC_GOLD}" = "y" ]; then
690 extra_config+=( --enable-gold )
695 case "${CT_CC_GCC_mips_llsc}" in
696 y) extra_config+=( --with-llsc );;
698 *) extra_config+=( --without-llsc );;
700 case "${CT_CC_GCC_mips_synci}" in
701 y) extra_config+=( --with-synci );;
703 *) extra_config+=( --without-synci );;
705 if [ "${CT_CC_GCC_mips_plt}" ]; then
706 extra_config+=( --with-mips-plt )
711 [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && extra_config+=("--disable-nls")
713 if [ "${CT_CC_GCC_SYSTEM_ZLIB}" = "y" ]; then
714 extra_config+=("--with-system-zlib")
717 if [ "${CT_MULTILIB}" = "y" ]; then
718 extra_config+=("--enable-multilib")
720 extra_config+=("--disable-multilib")
723 CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
726 CC_FOR_BUILD="${CT_BUILD}-gcc" \
728 LDFLAGS="${final_LDFLAGS[*]}" \
729 CFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}" \
730 CXXFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}" \
731 LDFLAGS_FOR_TARGET="${CT_TARGET_LDFLAGS}" \
732 "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/configure" \
733 --build=${CT_BUILD} \
735 --target=${CT_TARGET} \
736 --prefix="${prefix}" \
738 "${extra_config[@]}" \
739 --with-local-prefix="${CT_SYSROOT_DIR}" \
742 "${CT_CC_EXTRA_CONFIG_ARRAY[@]}"
744 if [ "${CT_CANADIAN}" = "y" ]; then
745 CT_DoLog EXTRA "Building libiberty"
746 CT_DoExecLog ALL make ${JOBSFLAGS} all-build-libiberty
749 CT_DoLog EXTRA "Building final compiler"
750 CT_DoExecLog ALL make ${JOBSFLAGS} all
752 CT_DoLog EXTRA "Installing final compiler"
753 CT_DoExecLog ALL make ${JOBSFLAGS} install
755 if [ "${build_manuals}" = "yes" ]; then
756 CT_DoLog EXTRA "Building the GCC manuals"
757 CT_DoExecLog ALL make ${JOBSFLAGS} pdf html
758 CT_DoLog EXTRA "Installing the GCC manuals"
759 CT_DoExecLog ALL make install-{pdf,html}-gcc
762 # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
763 # to call the C compiler with the same, somewhat canonical name.
764 # check whether compiler has an extension
765 file="$( ls -1 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-gcc."* 2>/dev/null || true )"
766 [ -z "${file}" ] || ext=".${file##*.}"
767 CT_DoExecLog ALL ln -sfv "${CT_TARGET}-gcc${ext}" "${CT_PREFIX_DIR}/bin/${CT_TARGET}-cc${ext}"
769 if [ "${CT_MULTILIB}" = "y" ]; then
770 multilibs=( $( "${CT_PREFIX_DIR}/bin/${CT_TARGET}-gcc" -print-multi-lib \
772 if [ ${#multilibs[@]} -ne 0 ]; then
773 CT_DoLog EXTRA "gcc configured with these multilibs (besides the default):"
774 for i in "${multilibs[@]}"; do
777 CT_DoLog EXTRA " ${flags//@/ -} --> ${dir}/"
780 CT_DoLog WARN "gcc configured for multilib, but none available"