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_BUILD}" )
73 core_opts+=( "complibs=${CT_COMPLIBS_DIR}" )
74 core_opts+=( "prefix=${CT_BUILDTOOLS_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 core_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
104 case "${CT_BARE_METAL},${CT_CANADIAN},${CT_THREADS}" in
107 core_opts+=( "host=${CT_BUILD}" )
108 core_opts+=( "mode=static" )
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_BUILD}" )
117 core_opts+=( "build_libgcc=yes" )
118 core_opts+=( "complibs=${CT_COMPLIBS_DIR}" )
119 core_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
123 core_opts+=( "mode=static" )
124 core_opts+=( "host=${CT_BUILD}" )
125 core_opts+=( "build_libgcc=yes" )
126 core_opts+=( "complibs=${CT_COMPLIBS_DIR}" )
127 core_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
131 core_opts+=( "mode=static" )
132 core_opts+=( "host=${CT_BUILD}" )
133 core_opts+=( "complibs=${CT_COMPLIBS_DIR}" )
134 core_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
135 if [ "${CT_CC_GCC_4_3_or_later}" = "y" ]; then
136 core_opts+=( "build_libgcc=yes" )
141 if [ "${do_core}" = "y" ]; then
142 CT_DoStep INFO "Installing pass-2 core C compiler"
143 CT_mkdir_pushd "${CT_BUILD_DIR}/build-cc-core-pass-2"
145 do_cc_core_backend "${core_opts[@]}"
152 #------------------------------------------------------------------------------
154 # This function is used to build the core C compiler.
155 # Usage: do_cc_core_backend param=value [...]
156 # Parameter : Definition : Type : Default
157 # mode : build a 'static', 'shared' or 'baremetal' : string : (none)
158 # host : the machine the core will run on : tuple : (none)
159 # prefix : dir prefix to install into : dir : (none)
160 # complibs : dir where complibs are isntalled : dir : (none)
161 # build_libgcc : build libgcc or not : bool : no
162 # build_libstdcxx : build libstdc++ or not : bool : no
163 # build_staticlinked : build statically linked or not : bool : no
164 # build_manuals : whether to build manuals or not : bool : no
165 # cflags : host CFLAGS to use : string : (empty)
166 # Usage: do_cc_core_backend mode=[static|shared|baremetal] build_libgcc=[yes|no] build_staticlinked=[yes|no]
167 do_cc_core_backend() {
169 local build_libgcc=no
170 local build_libstdcxx=no
171 local build_staticlinked=no
172 local build_manuals=no
179 local -a host_libstdcxx_flags
180 local -a extra_config
181 local -a core_LDFLAGS
182 local -a core_targets
189 CT_DoLog EXTRA "Configuring core C compiler"
194 extra_config+=("--with-newlib")
195 extra_config+=("--enable-threads=no")
196 extra_config+=("--disable-shared")
197 copy_headers=y # For baremetal, as there's no headers to copy,
198 # we copy an empty directory. So, who cares?
201 extra_config+=("--enable-shared")
205 extra_config+=("--with-newlib")
206 extra_config+=("--enable-threads=no")
207 extra_config+=("--disable-shared")
208 [ "${CT_CC_LANG_CXX}" = "y" ] && lang_opt="${lang_opt},c++"
212 CT_Abort "Internal Error: 'mode' must be one of: 'static', 'shared' or 'baremetal', not '${mode:-(empty)}'"
216 if [ "${CT_CC_GCC_HAS_PKGVERSION_BUGURL}" = "y" ]; then
217 # Bare metal delivers the core compiler as final compiler, so add version info and bugurl
218 extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
219 [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
222 if [ "${copy_headers}" = "y" ]; then
223 CT_DoLog DEBUG "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
224 CT_DoExecLog ALL cp -a "${CT_HEADERS_DIR}" "${prefix}/${CT_TARGET}/include"
227 for tmp in ARCH ABI CPU TUNE FPU FLOAT; do
228 eval tmp="\${CT_ARCH_WITH_${tmp}}"
229 if [ -n "${tmp}" ]; then
230 extra_config+=("${tmp}")
233 if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
234 extra_config+=("--enable-__cxa_atexit")
236 extra_config+=("--disable-__cxa_atexit")
240 # Keep this full if-else-if-elif-fi-fi block in sync
241 # with the same block in do_cc, below.
242 if [ "${build_staticlinked}" = "yes" ]; then
243 core_LDFLAGS+=("-static")
244 host_libstdcxx_flags+=("-static-libgcc")
245 host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++")
246 host_libstdcxx_flags+=("-lm")
247 # Companion libraries are build static (eg !shared), so
248 # the libstdc++ is not pulled automatically, although it
249 # is needed. Shoe-horn it in our LDFLAGS
250 # Ditto libm on some Fedora boxen
251 core_LDFLAGS+=("-lstdc++")
252 core_LDFLAGS+=("-lm")
254 if [ "${CT_CC_STATIC_LIBSTDCXX}" = "y" ]; then
255 # this is from CodeSourcery arm-2010q1-202-arm-none-linux-gnueabi.src.tar.bz2
257 # INFO: if the host gcc is gcc-4.5 then presumably we could use -static-libstdc++,
258 # see http://gcc.gnu.org/ml/gcc-patches/2009-06/msg01635.html
259 host_libstdcxx_flags+=("-static-libgcc")
260 host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++,-Bdynamic")
261 host_libstdcxx_flags+=("-lm")
262 elif [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
263 # When companion libraries are build static (eg !shared),
264 # the libstdc++ is not pulled automatically, although it
265 # is needed. Shoe-horn it in our LDFLAGS
266 # Ditto libm on some Fedora boxen
267 core_LDFLAGS+=("-lstdc++")
268 core_LDFLAGS+=("-lm")
272 if [ "${CT_CC_GCC_USE_GMP_MPFR}" = "y" ]; then
273 extra_config+=("--with-gmp=${complibs}")
274 extra_config+=("--with-mpfr=${complibs}")
276 if [ "${CT_CC_GCC_USE_MPC}" = "y" ]; then
277 extra_config+=("--with-mpc=${complibs}")
279 if [ "${CT_CC_GCC_USE_GRAPHITE}" = "y" ]; then
280 extra_config+=("--with-ppl=${complibs}")
281 # With PPL 0.11+, also pull libpwl if needed
282 if [ "${CT_PPL_NEEDS_LIBPWL}" = "y" ]; then
283 host_libstdcxx_flags+=("-L${complibs}/lib")
284 host_libstdcxx_flags+=("-lpwl")
286 extra_config+=("--with-cloog=${complibs}")
287 elif [ "${CT_CC_GCC_HAS_GRAPHITE}" = "y" ]; then
288 extra_config+=("--with-ppl=no")
289 extra_config+=("--with-cloog=no")
291 if [ "${CT_CC_GCC_USE_LTO}" = "y" ]; then
292 extra_config+=("--with-libelf=${complibs}")
293 extra_config+=("--enable-lto")
294 elif [ "${CT_CC_GCC_HAS_LTO}" = "y" ]; then
295 extra_config+=("--with-libelf=no")
296 extra_config+=("--disable-lto")
299 if [ ${#host_libstdcxx_flags[@]} -ne 0 ]; then
300 extra_config+=("--with-host-libstdcxx=${host_libstdcxx_flags[*]}")
303 if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then
304 extra_config+=("--enable-target-optspace")
307 case "${CT_CC_GCC_LDBL_128}" in
308 y) extra_config+=("--with-long-double-128");;
310 "") extra_config+=("--without-long-double-128");;
313 if [ "${CT_CC_GCC_BUILD_ID}" = "y" ]; then
314 extra_config+=( --enable-linker-build-id )
317 case "${CT_CC_GCC_LNK_HASH_STYLE}" in
319 *) extra_config+=( "--with-linker-hash-style=${CT_CC_GCC_LNK_HASH_STYLE}" );;
324 case "${CT_CC_GCC_mips_llsc}" in
325 y) extra_config+=( --with-llsc );;
327 *) extra_config+=( --without-llsc );;
329 case "${CT_CC_GCC_mips_synci}" in
330 y) extra_config+=( --with-synci );;
332 *) extra_config+=( --without-synci );;
334 if [ "${CT_CC_GCC_mips_plt}" ]; then
335 extra_config+=( --with-mips-plt )
340 extra_config+=(--disable-libgomp)
341 extra_config+=(--disable-libmudflap)
343 [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && extra_config+=("--disable-nls")
345 [ "${CT_CC_GCC_DISABLE_PCH}" = "y" ] && extra_config+=("--disable-libstdcxx-pch")
347 if [ "${CT_CC_GCC_SYSTEM_ZLIB}" = "y" ]; then
348 extra_config+=("--with-system-zlib")
351 if [ "${CT_MULTILIB}" = "y" ]; then
352 extra_config+=("--enable-multilib")
354 extra_config+=("--disable-multilib")
357 CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
359 # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
361 CC_FOR_BUILD="${CT_BUILD}-gcc" \
363 LDFLAGS="${core_LDFLAGS[*]}" \
364 "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/configure" \
365 --build=${CT_BUILD} \
367 --target=${CT_TARGET} \
368 --prefix="${prefix}" \
369 --with-local-prefix="${CT_SYSROOT_DIR}" \
370 --disable-libmudflap \
371 ${CC_CORE_SYSROOT_ARG} \
372 "${extra_config[@]}" \
373 --enable-languages="${lang_opt}" \
374 "${CT_CC_CORE_EXTRA_CONFIG_ARRAY[@]}"
376 if [ "${build_libgcc}" = "yes" ]; then
377 # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
378 # gcc/config/t-libunwind so -lc is removed from the link for
379 # libgcc_s.so, as we do not have a target -lc yet.
380 # This is not as ugly as it appears to be ;-) All symbols get resolved
381 # during the glibc build, and we provide a proper libgcc_s.so for the
382 # cross toolchain during the final gcc build.
384 # As we cannot modify the source tree, nor override SHLIB_LC itself
385 # during configure or make, we have to edit the resultant
386 # gcc/libgcc.mk itself to remove -lc from the link.
387 # This causes us to have to jump through some hoops...
389 # To produce libgcc.mk to edit we firstly require libiberty.a,
390 # so we configure then build it.
391 # Next we have to configure gcc, create libgcc.mk then edit it...
392 # So much easier if we just edit the source tree, but hey...
393 if [ ! -f "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" ]; then
394 CT_DoExecLog CFG make ${JOBSFLAGS} configure-libiberty
395 CT_DoExecLog ALL make ${JOBSFLAGS} -C libiberty libiberty.a
396 CT_DoExecLog CFG make ${JOBSFLAGS} configure-gcc configure-libcpp
397 CT_DoExecLog ALL make ${JOBSFLAGS} all-libcpp
399 CT_DoExecLog CFG make ${JOBSFLAGS} configure-gcc configure-libcpp configure-build-libiberty
400 CT_DoExecLog ALL make ${JOBSFLAGS} all-libcpp all-build-libiberty
402 # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
403 if [ -d "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/libdecnumber" ]; then
404 CT_DoExecLog CFG make ${JOBSFLAGS} configure-libdecnumber
405 CT_DoExecLog ALL make ${JOBSFLAGS} -C libdecnumber libdecnumber.a
408 # Starting with GCC 4.3, libgcc.mk is no longer built,
409 # and libgcc.mvars is used instead.
411 if [ "${CT_CC_GCC_4_3_or_later}" = "y" ]; then
412 libgcc_rule="libgcc.mvars"
413 core_targets=( gcc target-libgcc )
415 libgcc_rule="libgcc.mk"
419 # On bare metal and canadian build the host-compiler is used when
420 # actually the build-system compiler is required. Choose the correct
421 # compilers for canadian build and use the defaults on other
423 if [ "${CT_BARE_METAL},${CT_CANADIAN}" = "y,y" ]; then
424 repair_cc="CC_FOR_BUILD=${CT_BUILD}-gcc \
425 GCC_FOR_TARGET=${CT_TARGET}-gcc"
430 CT_DoExecLog ALL make ${JOBSFLAGS} -C gcc ${libgcc_rule} \
432 sed -r -i -e 's@-lc@@g' gcc/${libgcc_rule}
436 if [ "${build_libstdcxx}" = "yes" \
437 -a "${CT_CC_LANG_CXX}" = "y" \
439 core_targets+=( target-libstdc++-v3 )
442 CT_DoLog EXTRA "Building core C compiler"
443 CT_DoExecLog ALL make ${JOBSFLAGS} "${core_targets[@]/#/all-}"
445 CT_DoLog EXTRA "Installing core C compiler"
446 CT_DoExecLog ALL make ${JOBSFLAGS} "${core_targets[@]/#/install-}"
448 if [ "${build_manuals}" = "yes" ]; then
449 CT_DoLog EXTRA "Building the GCC manuals"
450 CT_DoExecLog ALL make pdf html
451 CT_DoLog EXTRA "Installing the GCC manuals"
452 CT_DoExecLog ALL make install-{pdf,html}-gcc
455 # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
456 # to call the C compiler with the same, somewhat canonical name.
457 # check whether compiler has an extension
458 file="$( ls -1 "${prefix}/bin/${CT_TARGET}-gcc."* 2>/dev/null || true )"
459 [ -z "${file}" ] || ext=".${file##*.}"
460 CT_DoExecLog ALL ln -sfv "${CT_TARGET}-gcc${ext}" "${prefix}/bin/${CT_TARGET}-cc${ext}"
462 if [ "${CT_MULTILIB}" = "y" ]; then
463 multilibs=( $( "${prefix}/bin/${CT_TARGET}-gcc" -print-multi-lib \
465 if [ ${#multilibs[@]} -ne 0 ]; then
466 CT_DoLog EXTRA "gcc configured with these multilibs (besides the default):"
467 for i in "${multilibs[@]}"; do
470 CT_DoLog EXTRA " ${flags//@/ -} --> ${dir}/"
473 CT_DoLog WARN "gcc configured for multilib, but none available"
478 #------------------------------------------------------------------------------
484 final_opts+=( "host=${CT_HOST}" )
485 final_opts+=( "prefix=${CT_PREFIX_DIR}" )
486 final_opts+=( "complibs=${CT_COMPLIBS_DIR}" )
487 final_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
488 if [ "${CT_BUILD_MANUALS}" = "y" ]; then
489 final_opts+=( "build_manuals=yes" )
491 if [ "${CT_BARE_METAL}" = "y" ]; then
492 final_opts+=( "mode=baremetal" )
493 final_opts+=( "build_libgcc=yes" )
494 final_opts+=( "build_libstdcxx=yes" )
495 if [ "${CT_STATIC_TOOLCHAIN}" = "y" ]; then
496 final_opts+=( "build_staticlinked=yes" )
498 final_backend=do_cc_core_backend
500 final_backend=do_cc_backend
503 CT_DoStep INFO "Installing final compiler"
504 CT_mkdir_pushd "${CT_BUILD_DIR}/build-cc-final"
506 "${final_backend}" "${final_opts[@]}"
512 #------------------------------------------------------------------------------
513 # Build the final gcc
514 # Usage: do_cc_backend param=value [...]
515 # Parameter : Definition : Type : Default
516 # host : the host we run onto : tuple : (none)
517 # prefix : the runtime prefix : dir : (none)
518 # complibs : the companion libraries prefix : dir : (none)
519 # cflags : the host CFLAGS : string : (empty)
520 # build_manuals : whether to build manuals or not : bool : no
527 local -a host_libstdcxx_flags
528 local -a extra_config
529 local -a final_LDFLAGS
537 CT_DoLog EXTRA "Configuring final compiler"
539 # Enable selected languages
541 [ "${CT_CC_LANG_CXX}" = "y" ] && lang_opt="${lang_opt},c++"
542 [ "${CT_CC_LANG_FORTRAN}" = "y" ] && lang_opt="${lang_opt},fortran"
543 [ "${CT_CC_LANG_ADA}" = "y" ] && lang_opt="${lang_opt},ada"
544 [ "${CT_CC_LANG_JAVA}" = "y" ] && lang_opt="${lang_opt},java"
545 [ "${CT_CC_LANG_OBJC}" = "y" ] && lang_opt="${lang_opt},objc"
546 [ "${CT_CC_LANG_OBJCXX}" = "y" ] && lang_opt="${lang_opt},obj-c++"
547 CT_Test "Building ADA language is not yet supported. Will try..." "${CT_CC_LANG_ADA}" = "y"
548 CT_Test "Building Objective-C language is not yet supported. Will try..." "${CT_CC_LANG_OBJC}" = "y"
549 CT_Test "Building Objective-C++ language is not yet supported. Will try..." "${CT_CC_LANG_OBJCXX}" = "y"
550 CT_Test "Building ${CT_CC_LANG_OTHERS//,/ } language(s) is not yet supported. Will try..." -n "${CT_CC_LANG_OTHERS}"
551 lang_opt=$(echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;')
553 extra_config+=("--enable-languages=${lang_opt}")
554 for tmp in ARCH ABI CPU TUNE FPU FLOAT; do
555 eval tmp="\${CT_ARCH_WITH_${tmp}}"
556 if [ -n "${tmp}" ]; then
557 extra_config+=("${tmp}")
561 [ "${CT_SHARED_LIBS}" = "y" ] || extra_config+=("--disable-shared")
562 if [ "${CT_CC_GCC_HAS_PKGVERSION_BUGURL}" = "y" ]; then
563 extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
564 [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
566 case "${CT_CC_GCC_SJLJ_EXCEPTIONS}" in
567 y) extra_config+=("--enable-sjlj-exceptions");;
569 "") extra_config+=("--disable-sjlj-exceptions");;
571 if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
572 extra_config+=("--enable-__cxa_atexit")
574 extra_config+=("--disable-__cxa_atexit")
576 if [ -n "${CT_CC_ENABLE_CXX_FLAGS}" ]; then
577 extra_config+=("--enable-cxx-flags=${CT_CC_ENABLE_CXX_FLAGS}")
579 if [ "${CT_CC_GCC_LIBMUDFLAP}" = "y" ]; then
580 extra_config+=(--enable-libmudflap)
582 extra_config+=(--disable-libmudflap)
584 if [ "${CT_CC_GCC_LIBGOMP}" = "y" ]; then
585 extra_config+=(--enable-libgomp)
587 extra_config+=(--disable-libgomp)
589 if [ "${CT_CC_GCC_LIBSSP}" = "y" ]; then
590 extra_config+=(--enable-libssp)
592 extra_config+=(--disable-libssp)
596 # Keep this full if-else-if-elif-fi-fi block in sync
597 # with the same block in do_cc_core, above.
598 if [ "${CT_STATIC_TOOLCHAIN}" = "y" ]; then
599 final_LDFLAGS+=("-static")
600 host_libstdcxx_flags+=("-static-libgcc")
601 host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++")
602 host_libstdcxx_flags+=("-lm")
603 # Companion libraries are build static (eg !shared), so
604 # the libstdc++ is not pulled automatically, although it
605 # is needed. Shoe-horn it in our LDFLAGS
606 # Ditto libm on some Fedora boxen
607 final_LDFLAGS+=("-lstdc++")
608 final_LDFLAGS+=("-lm")
610 if [ "${CT_CC_STATIC_LIBSTDCXX}" = "y" ]; then
611 # this is from CodeSourcery arm-2010q1-202-arm-none-linux-gnueabi.src.tar.bz2
613 # INFO: if the host gcc is gcc-4.5 then presumably we could use -static-libstdc++,
614 # see http://gcc.gnu.org/ml/gcc-patches/2009-06/msg01635.html
615 host_libstdcxx_flags+=("-static-libgcc")
616 host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++,-Bdynamic")
617 host_libstdcxx_flags+=("-lm")
618 elif [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
619 # When companion libraries are build static (eg !shared),
620 # the libstdc++ is not pulled automatically, although it
621 # is needed. Shoe-horn it in our LDFLAGS
622 # Ditto libm on some Fedora boxen
623 final_LDFLAGS+=("-lstdc++")
624 final_LDFLAGS+=("-lm")
628 if [ "${CT_CC_GCC_USE_GMP_MPFR}" = "y" ]; then
629 extra_config+=("--with-gmp=${complibs}")
630 extra_config+=("--with-mpfr=${complibs}")
632 if [ "${CT_CC_GCC_USE_MPC}" = "y" ]; then
633 extra_config+=("--with-mpc=${complibs}")
635 if [ "${CT_CC_GCC_USE_GRAPHITE}" = "y" ]; then
636 extra_config+=("--with-ppl=${complibs}")
637 # With PPL 0.11+, also pull libpwl if needed
638 if [ "${CT_PPL_NEEDS_LIBPWL}" = "y" ]; then
639 host_libstdcxx_flags+=("-L${complibs}/lib")
640 host_libstdcxx_flags+=("-lpwl")
642 extra_config+=("--with-cloog=${complibs}")
643 elif [ "${CT_CC_GCC_HAS_GRAPHITE}" = "y" ]; then
644 extra_config+=("--with-ppl=no")
645 extra_config+=("--with-cloog=no")
647 if [ "${CT_CC_GCC_USE_LTO}" = "y" ]; then
648 extra_config+=("--with-libelf=${complibs}")
649 elif [ "${CT_CC_GCC_HAS_LTO}" = "y" ]; then
650 extra_config+=("--with-libelf=no")
653 if [ ${#host_libstdcxx_flags[@]} -ne 0 ]; then
654 extra_config+=("--with-host-libstdcxx=${host_libstdcxx_flags[*]}")
657 if [ "${CT_THREADS}" = "none" ]; then
658 extra_config+=("--disable-threads")
659 if [ "${CT_CC_GCC_4_2_or_later}" = y ]; then
660 CT_Test "Disabling libgomp for no-thread gcc>=4.2" "${CT_CC_GCC_LIBGOMP}" = "Y"
661 extra_config+=("--disable-libgomp")
664 if [ "${CT_THREADS}" = "win32" ]; then
665 extra_config+=("--enable-threads=win32")
666 extra_config+=("--disable-win32-registry")
668 extra_config+=("--enable-threads=posix")
672 if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then
673 extra_config+=("--enable-target-optspace")
675 if [ "${CT_CC_GCC_DISABLE_PCH}" = "y" ]; then
676 extra_config+=("--disable-libstdcxx-pch")
679 case "${CT_CC_GCC_LDBL_128}" in
680 y) extra_config+=("--with-long-double-128");;
682 "") extra_config+=("--without-long-double-128");;
685 if [ "${CT_CC_GCC_BUILD_ID}" = "y" ]; then
686 extra_config+=( --enable-linker-build-id )
689 case "${CT_CC_GCC_LNK_HASH_STYLE}" in
691 *) extra_config+=( "--with-linker-hash-style=${CT_CC_GCC_LNK_HASH_STYLE}" );;
694 if [ "${CT_CC_GCC_ENABLE_PLUGINS}" = "y" ]; then
695 extra_config+=( --enable-plugin )
697 if [ "${CT_CC_GCC_GOLD}" = "y" ]; then
698 extra_config+=( --enable-gold )
703 case "${CT_CC_GCC_mips_llsc}" in
704 y) extra_config+=( --with-llsc );;
706 *) extra_config+=( --without-llsc );;
708 case "${CT_CC_GCC_mips_synci}" in
709 y) extra_config+=( --with-synci );;
711 *) extra_config+=( --without-synci );;
713 if [ "${CT_CC_GCC_mips_plt}" ]; then
714 extra_config+=( --with-mips-plt )
719 [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && extra_config+=("--disable-nls")
721 if [ "${CT_CC_GCC_SYSTEM_ZLIB}" = "y" ]; then
722 extra_config+=("--with-system-zlib")
725 if [ "${CT_MULTILIB}" = "y" ]; then
726 extra_config+=("--enable-multilib")
728 extra_config+=("--disable-multilib")
731 CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
734 CC_FOR_BUILD="${CT_BUILD}-gcc" \
736 LDFLAGS="${final_LDFLAGS[*]}" \
737 CFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}" \
738 CXXFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}" \
739 LDFLAGS_FOR_TARGET="${CT_TARGET_LDFLAGS}" \
740 "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/configure" \
741 --build=${CT_BUILD} \
743 --target=${CT_TARGET} \
744 --prefix="${prefix}" \
746 "${extra_config[@]}" \
747 --with-local-prefix="${CT_SYSROOT_DIR}" \
750 "${CT_CC_EXTRA_CONFIG_ARRAY[@]}"
752 if [ "${CT_CANADIAN}" = "y" ]; then
753 CT_DoLog EXTRA "Building libiberty"
754 CT_DoExecLog ALL make ${JOBSFLAGS} all-build-libiberty
757 CT_DoLog EXTRA "Building final compiler"
758 CT_DoExecLog ALL make ${JOBSFLAGS} all
760 CT_DoLog EXTRA "Installing final compiler"
761 CT_DoExecLog ALL make ${JOBSFLAGS} install
763 if [ "${build_manuals}" = "yes" ]; then
764 CT_DoLog EXTRA "Building the GCC manuals"
765 CT_DoExecLog ALL make ${JOBSFLAGS} pdf html
766 CT_DoLog EXTRA "Installing the GCC manuals"
767 CT_DoExecLog ALL make install-{pdf,html}-gcc
770 # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
771 # to call the C compiler with the same, somewhat canonical name.
772 # check whether compiler has an extension
773 file="$( ls -1 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-gcc."* 2>/dev/null || true )"
774 [ -z "${file}" ] || ext=".${file##*.}"
775 CT_DoExecLog ALL ln -sfv "${CT_TARGET}-gcc${ext}" "${CT_PREFIX_DIR}/bin/${CT_TARGET}-cc${ext}"
777 if [ "${CT_MULTILIB}" = "y" ]; then
778 multilibs=( $( "${CT_PREFIX_DIR}/bin/${CT_TARGET}-gcc" -print-multi-lib \
780 if [ ${#multilibs[@]} -ne 0 ]; then
781 CT_DoLog EXTRA "gcc configured with these multilibs (besides the default):"
782 for i in "${multilibs[@]}"; do
785 CT_DoLog EXTRA " ${flags//@/ -} --> ${dir}/"
788 CT_DoLog WARN "gcc configured for multilib, but none available"