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
69 core_opts+=( "mode=static" )
75 core_opts+=( "mode=static" )
81 if [ "${do_core}" = "y" ]; then
82 do_cc_core_backend "${core_opts[@]}"
91 # In case we're building for bare metal, do nothing, we already have
93 # In case we're not bare metal and building a canadian compiler, do nothing
94 # In case we're NPTL, build the shared core gcc and the target libgcc.
95 # In any other case, build the static core gcc and, if using gcc-4.3+,
96 # also build the target libgcc.
97 case "${CT_BARE_METAL},${CT_CANADIAN},${CT_THREADS}" in
100 core_opts+=( "mode=baremetal" )
101 core_opts+=( "build_libgcc=yes" )
102 core_opts+=( "build_libstdcxx=yes" )
103 if [ "${CT_STATIC_TOOLCHAIN}" = "y" ]; then
104 core_opts+=( "build_staticlinked=yes" )
106 core_opts+=( "build_manuals=yes" )
111 core_opts+=( "mode=shared" )
112 core_opts+=( "build_libgcc=yes" )
116 core_opts+=( "mode=static" )
117 core_opts+=( "build_libgcc=yes" )
121 core_opts+=( "mode=static" )
122 if [ "${CT_CC_GCC_4_3_or_later}" = "y" ]; then
123 core_opts+=( "build_libgcc=yes" )
128 if [ "${do_core}" = "y" ]; then
129 do_cc_core_backend "${core_opts[@]}"
133 #------------------------------------------------------------------------------
135 # This function is used to build both the static and the shared core C compiler,
136 # with or without the target libgcc. We need to know wether:
137 # - we're building static, shared or bare metal: mode=[static|shared|baremetal]
138 # - we need to build libgcc or not : build_libgcc=[yes|no] (default: no)
139 # - we need to build libstdc++ or not : build_libstdcxx=[yes|no] (default: no)
140 # - we need to build statically linked or not : build_staticlinked=[yes|no] (default: no)
141 # Usage: do_cc_core_backend mode=[static|shared|baremetal] build_libgcc=[yes|no] build_staticlinked=[yes|no]
142 do_cc_core_backend() {
144 local build_libgcc=no
145 local build_libstdcxx=no
146 local build_staticlinked=no
147 local build_manuals=no
148 local core_prefix_dir
151 local -a host_libstdcxx_flags
152 local -a extra_config
153 local -a core_LDFLAGS
154 local -a core_targets
164 core_prefix_dir="${CT_CC_CORE_STATIC_PREFIX_DIR}"
165 extra_config+=("--with-newlib")
166 extra_config+=("--enable-threads=no")
167 extra_config+=("--disable-shared")
168 copy_headers=y # For baremetal, as there's no headers to copy,
169 # we copy an empty directory. So, who cares?
172 core_prefix_dir="${CT_CC_CORE_SHARED_PREFIX_DIR}"
173 extra_config+=("--enable-shared")
177 core_prefix_dir="${CT_PREFIX_DIR}"
178 extra_config+=("--with-newlib")
179 extra_config+=("--enable-threads=no")
180 extra_config+=("--disable-shared")
181 [ "${CT_CC_LANG_CXX}" = "y" ] && lang_opt="${lang_opt},c++"
185 CT_Abort "Internal Error: 'mode' must be one of: 'static', 'shared' or 'baremetal', not '${mode:-(empty)}'"
189 CT_DoStep INFO "Installing ${mode} core C compiler"
190 mkdir -p "${CT_BUILD_DIR}/build-cc-core-${mode}"
191 cd "${CT_BUILD_DIR}/build-cc-core-${mode}"
193 if [ "${CT_CC_GCC_HAS_PKGVERSION_BUGURL}" = "y" ]; then
194 # Bare metal delivers the core compiler as final compiler, so add version info and bugurl
195 extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
196 [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
199 if [ "${copy_headers}" = "y" ]; then
200 CT_DoLog DEBUG "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
201 CT_DoExecLog ALL cp -a "${CT_HEADERS_DIR}" "${core_prefix_dir}/${CT_TARGET}/include"
204 CT_DoLog EXTRA "Configuring ${mode} core C compiler"
206 for tmp in ARCH ABI CPU TUNE FPU FLOAT; do
207 eval tmp="\${CT_ARCH_WITH_${tmp}}"
208 if [ -n "${tmp}" ]; then
209 extra_config+=("${tmp}")
212 if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
213 extra_config+=("--enable-__cxa_atexit")
215 extra_config+=("--disable-__cxa_atexit")
219 # Keep this full if-else-if-elif-fi-fi block in sync
220 # with the same block in do_cc, below.
221 if [ "${build_staticlinked}" = "yes" ]; then
222 core_LDFLAGS+=("-static")
223 host_libstdcxx_flags+=("-static-libgcc")
224 host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++")
225 host_libstdcxx_flags+=("-lm")
226 # Companion libraries are build static (eg !shared), so
227 # the libstdc++ is not pulled automatically, although it
228 # is needed. Shoe-horn it in our LDFLAGS
229 # Ditto libm on some Fedora boxen
230 core_LDFLAGS+=("-lstdc++")
231 core_LDFLAGS+=("-lm")
233 if [ "${CT_CC_STATIC_LIBSTDCXX}" = "y" ]; then
234 # this is from CodeSourcery arm-2010q1-202-arm-none-linux-gnueabi.src.tar.bz2
236 # INFO: if the host gcc is gcc-4.5 then presumably we could use -static-libstdc++,
237 # see http://gcc.gnu.org/ml/gcc-patches/2009-06/msg01635.html
238 host_libstdcxx_flags+=("-static-libgcc")
239 host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++,-Bdynamic")
240 host_libstdcxx_flags+=("-lm")
241 elif [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
242 # When companion libraries are build static (eg !shared),
243 # the libstdc++ is not pulled automatically, although it
244 # is needed. Shoe-horn it in our LDFLAGS
245 # Ditto libm on some Fedora boxen
246 core_LDFLAGS+=("-lstdc++")
247 core_LDFLAGS+=("-lm")
251 if [ "${CT_CC_GCC_USE_GMP_MPFR}" = "y" ]; then
252 extra_config+=("--with-gmp=${CT_COMPLIBS_DIR}")
253 extra_config+=("--with-mpfr=${CT_COMPLIBS_DIR}")
255 if [ "${CT_CC_GCC_USE_MPC}" = "y" ]; then
256 extra_config+=("--with-mpc=${CT_COMPLIBS_DIR}")
258 if [ "${CT_CC_GCC_USE_GRAPHITE}" = "y" ]; then
259 extra_config+=("--with-ppl=${CT_COMPLIBS_DIR}")
260 # With PPL 0.11+, also pull libpwl if needed
261 if [ "${CT_PPL_NEEDS_LIBPWL}" = "y" ]; then
262 host_libstdcxx_flags+=("-L${CT_COMPLIBS_DIR}/lib")
263 host_libstdcxx_flags+=("-lpwl")
265 extra_config+=("--with-cloog=${CT_COMPLIBS_DIR}")
266 elif [ "${CT_CC_GCC_HAS_GRAPHITE}" = "y" ]; then
267 extra_config+=("--with-ppl=no")
268 extra_config+=("--with-cloog=no")
270 if [ "${CT_CC_GCC_USE_LTO}" = "y" ]; then
271 extra_config+=("--with-libelf=${CT_COMPLIBS_DIR}")
272 extra_config+=("--enable-lto")
273 elif [ "${CT_CC_GCC_HAS_LTO}" = "y" ]; then
274 extra_config+=("--with-libelf=no")
275 extra_config+=("--disable-lto")
278 if [ ${#host_libstdcxx_flags[@]} -ne 0 ]; then
279 extra_config+=("--with-host-libstdcxx=${host_libstdcxx_flags[*]}")
282 if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then
283 extra_config+=("--enable-target-optspace")
286 case "${CT_CC_GCC_LDBL_128}" in
287 y) extra_config+=("--with-long-double-128");;
289 "") extra_config+=("--without-long-double-128");;
292 if [ "${CT_CC_GCC_BUILD_ID}" = "y" ]; then
293 extra_config+=( --enable-linker-build-id )
296 case "${CT_CC_GCC_LNK_HASH_STYLE}" in
298 *) extra_config+=( "--with-linker-hash-style=${CT_CC_GCC_LNK_HASH_STYLE}" );;
303 case "${CT_CC_GCC_mips_llsc}" in
304 y) extra_config+=( --with-llsc );;
306 *) extra_config+=( --without-llsc );;
308 case "${CT_CC_GCC_mips_synci}" in
309 y) extra_config+=( --with-synci );;
311 *) extra_config+=( --without-synci );;
313 if [ "${CT_CC_GCC_mips_plt}" ]; then
314 extra_config+=( --with-mips-plt )
319 extra_config+=(--disable-libgomp)
320 extra_config+=(--disable-libmudflap)
322 [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && extra_config+=("--disable-nls")
324 [ "${CT_CC_GCC_DISABLE_PCH}" = "y" ] && extra_config+=("--disable-libstdcxx-pch")
326 if [ "${CT_CC_GCC_SYSTEM_ZLIB}" = "y" ]; then
327 extra_config+=("--with-system-zlib")
330 if [ "${CT_MULTILIB}" = "y" ]; then
331 extra_config+=("--enable-multilib")
333 extra_config+=("--disable-multilib")
336 CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
338 # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
340 CC_FOR_BUILD="${CT_BUILD}-gcc" \
341 CFLAGS="${CT_CFLAGS_FOR_HOST}" \
342 LDFLAGS="${core_LDFLAGS[*]}" \
343 "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/configure" \
344 --build=${CT_BUILD} \
346 --target=${CT_TARGET} \
347 --prefix="${core_prefix_dir}" \
348 --with-local-prefix="${CT_SYSROOT_DIR}" \
349 --disable-libmudflap \
350 ${CC_CORE_SYSROOT_ARG} \
351 "${extra_config[@]}" \
352 --enable-languages="${lang_opt}" \
353 "${CT_CC_CORE_EXTRA_CONFIG_ARRAY[@]}"
355 if [ "${build_libgcc}" = "yes" ]; then
356 # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
357 # gcc/config/t-libunwind so -lc is removed from the link for
358 # libgcc_s.so, as we do not have a target -lc yet.
359 # This is not as ugly as it appears to be ;-) All symbols get resolved
360 # during the glibc build, and we provide a proper libgcc_s.so for the
361 # cross toolchain during the final gcc build.
363 # As we cannot modify the source tree, nor override SHLIB_LC itself
364 # during configure or make, we have to edit the resultant
365 # gcc/libgcc.mk itself to remove -lc from the link.
366 # This causes us to have to jump through some hoops...
368 # To produce libgcc.mk to edit we firstly require libiberty.a,
369 # so we configure then build it.
370 # Next we have to configure gcc, create libgcc.mk then edit it...
371 # So much easier if we just edit the source tree, but hey...
372 if [ ! -f "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" ]; then
373 CT_DoExecLog CFG make ${JOBSFLAGS} configure-libiberty
374 CT_DoExecLog ALL make ${JOBSFLAGS} -C libiberty libiberty.a
375 CT_DoExecLog CFG make ${JOBSFLAGS} configure-gcc configure-libcpp
376 CT_DoExecLog ALL make ${JOBSFLAGS} all-libcpp
378 CT_DoExecLog CFG make ${JOBSFLAGS} configure-gcc configure-libcpp configure-build-libiberty
379 CT_DoExecLog ALL make ${JOBSFLAGS} all-libcpp all-build-libiberty
381 # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
382 if [ -d "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/libdecnumber" ]; then
383 CT_DoExecLog CFG make ${JOBSFLAGS} configure-libdecnumber
384 CT_DoExecLog ALL make ${JOBSFLAGS} -C libdecnumber libdecnumber.a
387 # Starting with GCC 4.3, libgcc.mk is no longer built,
388 # and libgcc.mvars is used instead.
390 if [ "${CT_CC_GCC_4_3_or_later}" = "y" ]; then
391 libgcc_rule="libgcc.mvars"
392 core_targets=( gcc target-libgcc )
394 libgcc_rule="libgcc.mk"
398 # On bare metal and canadian build the host-compiler is used when
399 # actually the build-system compiler is required. Choose the correct
400 # compilers for canadian build and use the defaults on other
402 if [ "${CT_BARE_METAL},${CT_CANADIAN}" = "y,y" ]; then
403 repair_cc="CC_FOR_BUILD=${CT_BUILD}-gcc \
404 GCC_FOR_TARGET=${CT_TARGET}-gcc"
409 CT_DoExecLog ALL make ${JOBSFLAGS} -C gcc ${libgcc_rule} \
411 sed -r -i -e 's@-lc@@g' gcc/${libgcc_rule}
415 if [ "${build_libstdcxx}" = "yes" \
416 -a "${CT_CC_LANG_CXX}" = "y" \
418 core_targets+=( target-libstdc++-v3 )
421 CT_DoLog EXTRA "Building ${mode} core C compiler"
422 CT_DoExecLog ALL make ${JOBSFLAGS} "${core_targets[@]/#/all-}"
424 CT_DoLog EXTRA "Installing ${mode} core C compiler"
425 CT_DoExecLog ALL make ${JOBSFLAGS} "${core_targets[@]/#/install-}"
427 if [ "${CT_BUILD_MANUALS}" = "y" -a "${build_manuals}" = "yes" ]; then
428 CT_DoLog EXTRA "Building the GCC manuals"
429 CT_DoExecLog ALL make pdf html
430 CT_DoLog EXTRA "Installing the GCC manuals"
431 CT_DoExecLog ALL make install-{pdf,html}-gcc
434 # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
435 # to call the C compiler with the same, somewhat canonical name.
436 # check whether compiler has an extension
437 file="$( ls -1 "${core_prefix_dir}/bin/${CT_TARGET}-gcc."* 2>/dev/null || true )"
438 [ -z "${file}" ] || ext=".${file##*.}"
439 CT_DoExecLog ALL ln -sfv "${CT_TARGET}-gcc${ext}" "${core_prefix_dir}/bin/${CT_TARGET}-cc${ext}"
441 if [ "${CT_MULTILIB}" = "y" ]; then
442 multilibs=( $( "${core_prefix_dir}/bin/${CT_TARGET}-gcc" -print-multi-lib \
444 if [ ${#multilibs[@]} -ne 0 ]; then
445 CT_DoLog EXTRA "gcc configured with these multilibs (besides the default):"
446 for i in "${multilibs[@]}"; do
449 CT_DoLog EXTRA " ${flags//@/ -} --> ${dir}/"
452 CT_DoLog WARN "gcc configured for multilib, but none available"
459 #------------------------------------------------------------------------------
462 local -a host_libstdcxx_flags
463 local -a extra_config
464 local -a final_LDFLAGS
467 # If building for bare metal, nothing to be done here, the static core conpiler is enough!
468 [ "${CT_BARE_METAL}" = "y" ] && return 0
470 CT_DoStep INFO "Installing final compiler"
472 mkdir -p "${CT_BUILD_DIR}/build-cc"
473 cd "${CT_BUILD_DIR}/build-cc"
475 CT_DoLog EXTRA "Configuring final compiler"
477 # Enable selected languages
479 [ "${CT_CC_LANG_CXX}" = "y" ] && lang_opt="${lang_opt},c++"
480 [ "${CT_CC_LANG_FORTRAN}" = "y" ] && lang_opt="${lang_opt},fortran"
481 [ "${CT_CC_LANG_ADA}" = "y" ] && lang_opt="${lang_opt},ada"
482 [ "${CT_CC_LANG_JAVA}" = "y" ] && lang_opt="${lang_opt},java"
483 [ "${CT_CC_LANG_OBJC}" = "y" ] && lang_opt="${lang_opt},objc"
484 [ "${CT_CC_LANG_OBJCXX}" = "y" ] && lang_opt="${lang_opt},obj-c++"
485 CT_Test "Building ADA language is not yet supported. Will try..." "${CT_CC_LANG_ADA}" = "y"
486 CT_Test "Building Objective-C language is not yet supported. Will try..." "${CT_CC_LANG_OBJC}" = "y"
487 CT_Test "Building Objective-C++ language is not yet supported. Will try..." "${CT_CC_LANG_OBJCXX}" = "y"
488 CT_Test "Building ${CT_CC_LANG_OTHERS//,/ } language(s) is not yet supported. Will try..." -n "${CT_CC_LANG_OTHERS}"
489 lang_opt=$(echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;')
491 extra_config+=("--enable-languages=${lang_opt}")
492 for tmp in ARCH ABI CPU TUNE FPU FLOAT; do
493 eval tmp="\${CT_ARCH_WITH_${tmp}}"
494 if [ -n "${tmp}" ]; then
495 extra_config+=("${tmp}")
499 [ "${CT_SHARED_LIBS}" = "y" ] || extra_config+=("--disable-shared")
500 if [ "${CT_CC_GCC_HAS_PKGVERSION_BUGURL}" = "y" ]; then
501 extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
502 [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
504 case "${CT_CC_GCC_SJLJ_EXCEPTIONS}" in
505 y) extra_config+=("--enable-sjlj-exceptions");;
507 "") extra_config+=("--disable-sjlj-exceptions");;
509 if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
510 extra_config+=("--enable-__cxa_atexit")
512 extra_config+=("--disable-__cxa_atexit")
514 if [ -n "${CT_CC_ENABLE_CXX_FLAGS}" ]; then
515 extra_config+=("--enable-cxx-flags=${CT_CC_ENABLE_CXX_FLAGS}")
517 if [ "${CT_CC_GCC_LIBMUDFLAP}" = "y" ]; then
518 extra_config+=(--enable-libmudflap)
520 extra_config+=(--disable-libmudflap)
522 if [ "${CT_CC_GCC_LIBGOMP}" = "y" ]; then
523 extra_config+=(--enable-libgomp)
525 extra_config+=(--disable-libgomp)
527 if [ "${CT_CC_GCC_LIBSSP}" = "y" ]; then
528 extra_config+=(--enable-libssp)
530 extra_config+=(--disable-libssp)
534 # Keep this full if-else-if-elif-fi-fi block in sync
535 # with the same block in do_cc_core, above.
536 if [ "${CT_STATIC_TOOLCHAIN}" = "y" ]; then
537 final_LDFLAGS+=("-static")
538 host_libstdcxx_flags+=("-static-libgcc")
539 host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++")
540 host_libstdcxx_flags+=("-lm")
541 # Companion libraries are build static (eg !shared), so
542 # the libstdc++ is not pulled automatically, although it
543 # is needed. Shoe-horn it in our LDFLAGS
544 # Ditto libm on some Fedora boxen
545 final_LDFLAGS+=("-lstdc++")
546 final_LDFLAGS+=("-lm")
548 if [ "${CT_CC_STATIC_LIBSTDCXX}" = "y" ]; then
549 # this is from CodeSourcery arm-2010q1-202-arm-none-linux-gnueabi.src.tar.bz2
551 # INFO: if the host gcc is gcc-4.5 then presumably we could use -static-libstdc++,
552 # see http://gcc.gnu.org/ml/gcc-patches/2009-06/msg01635.html
553 host_libstdcxx_flags+=("-static-libgcc")
554 host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++,-Bdynamic")
555 host_libstdcxx_flags+=("-lm")
556 elif [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
557 # When companion libraries are build static (eg !shared),
558 # the libstdc++ is not pulled automatically, although it
559 # is needed. Shoe-horn it in our LDFLAGS
560 # Ditto libm on some Fedora boxen
561 final_LDFLAGS+=("-lstdc++")
562 final_LDFLAGS+=("-lm")
566 if [ "${CT_CC_GCC_USE_GMP_MPFR}" = "y" ]; then
567 extra_config+=("--with-gmp=${CT_COMPLIBS_DIR}")
568 extra_config+=("--with-mpfr=${CT_COMPLIBS_DIR}")
570 if [ "${CT_CC_GCC_USE_MPC}" = "y" ]; then
571 extra_config+=("--with-mpc=${CT_COMPLIBS_DIR}")
573 if [ "${CT_CC_GCC_USE_GRAPHITE}" = "y" ]; then
574 extra_config+=("--with-ppl=${CT_COMPLIBS_DIR}")
575 # With PPL 0.11+, also pull libpwl if needed
576 if [ "${CT_PPL_NEEDS_LIBPWL}" = "y" ]; then
577 host_libstdcxx_flags+=("-L${CT_COMPLIBS_DIR}/lib")
578 host_libstdcxx_flags+=("-lpwl")
580 extra_config+=("--with-cloog=${CT_COMPLIBS_DIR}")
581 elif [ "${CT_CC_GCC_HAS_GRAPHITE}" = "y" ]; then
582 extra_config+=("--with-ppl=no")
583 extra_config+=("--with-cloog=no")
585 if [ "${CT_CC_GCC_USE_LTO}" = "y" ]; then
586 extra_config+=("--with-libelf=${CT_COMPLIBS_DIR}")
587 elif [ "${CT_CC_GCC_HAS_LTO}" = "y" ]; then
588 extra_config+=("--with-libelf=no")
591 if [ ${#host_libstdcxx_flags[@]} -ne 0 ]; then
592 extra_config+=("--with-host-libstdcxx=${host_libstdcxx_flags[*]}")
595 if [ "${CT_THREADS}" = "none" ]; then
596 extra_config+=("--disable-threads")
597 if [ "${CT_CC_GCC_4_2_or_later}" = y ]; then
598 CT_Test "Disabling libgomp for no-thread gcc>=4.2" "${CT_CC_GCC_LIBGOMP}" = "Y"
599 extra_config+=("--disable-libgomp")
602 if [ "${CT_THREADS}" = "win32" ]; then
603 extra_config+=("--enable-threads=win32")
604 extra_config+=("--disable-win32-registry")
606 extra_config+=("--enable-threads=posix")
610 if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then
611 extra_config+=("--enable-target-optspace")
613 if [ "${CT_CC_GCC_DISABLE_PCH}" = "y" ]; then
614 extra_config+=("--disable-libstdcxx-pch")
617 case "${CT_CC_GCC_LDBL_128}" in
618 y) extra_config+=("--with-long-double-128");;
620 "") extra_config+=("--without-long-double-128");;
623 if [ "${CT_CC_GCC_BUILD_ID}" = "y" ]; then
624 extra_config+=( --enable-linker-build-id )
627 case "${CT_CC_GCC_LNK_HASH_STYLE}" in
629 *) extra_config+=( "--with-linker-hash-style=${CT_CC_GCC_LNK_HASH_STYLE}" );;
632 if [ "${CT_CC_GCC_ENABLE_PLUGINS}" = "y" ]; then
633 extra_config+=( --enable-plugin )
635 if [ "${CT_CC_GCC_GOLD}" = "y" ]; then
636 extra_config+=( --enable-gold )
641 case "${CT_CC_GCC_mips_llsc}" in
642 y) extra_config+=( --with-llsc );;
644 *) extra_config+=( --without-llsc );;
646 case "${CT_CC_GCC_mips_synci}" in
647 y) extra_config+=( --with-synci );;
649 *) extra_config+=( --without-synci );;
651 if [ "${CT_CC_GCC_mips_plt}" ]; then
652 extra_config+=( --with-mips-plt )
657 [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && extra_config+=("--disable-nls")
659 if [ "${CT_CC_GCC_SYSTEM_ZLIB}" = "y" ]; then
660 extra_config+=("--with-system-zlib")
663 if [ "${CT_MULTILIB}" = "y" ]; then
664 extra_config+=("--enable-multilib")
666 extra_config+=("--disable-multilib")
669 CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
672 CC_FOR_BUILD="${CT_BUILD}-gcc" \
673 CFLAGS="${CT_CFLAGS_FOR_HOST}" \
674 LDFLAGS="${final_LDFLAGS[*]}" \
675 CFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}" \
676 CXXFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}" \
677 LDFLAGS_FOR_TARGET="${CT_TARGET_LDFLAGS}" \
678 "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/configure" \
679 --build=${CT_BUILD} \
681 --target=${CT_TARGET} \
682 --prefix="${CT_PREFIX_DIR}" \
684 "${extra_config[@]}" \
685 --with-local-prefix="${CT_SYSROOT_DIR}" \
688 "${CT_CC_EXTRA_CONFIG_ARRAY[@]}"
690 if [ "${CT_CANADIAN}" = "y" ]; then
691 CT_DoLog EXTRA "Building libiberty"
692 CT_DoExecLog ALL make ${JOBSFLAGS} all-build-libiberty
695 CT_DoLog EXTRA "Building final compiler"
696 CT_DoExecLog ALL make ${JOBSFLAGS} all
698 CT_DoLog EXTRA "Installing final compiler"
699 CT_DoExecLog ALL make ${JOBSFLAGS} install
701 if [ "${CT_BUILD_MANUALS}" = "y" ]; then
702 CT_DoLog EXTRA "Building the GCC manuals"
703 CT_DoExecLog ALL make ${JOBSFLAGS} pdf html
704 CT_DoLog EXTRA "Installing the GCC manuals"
705 CT_DoExecLog ALL make install-{pdf,html}-gcc
708 # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
709 # to call the C compiler with the same, somewhat canonical name.
710 # check whether compiler has an extension
711 file="$( ls -1 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-gcc."* 2>/dev/null || true )"
712 [ -z "${file}" ] || ext=".${file##*.}"
713 CT_DoExecLog ALL ln -sfv "${CT_TARGET}-gcc${ext}" "${CT_PREFIX_DIR}/bin/${CT_TARGET}-cc${ext}"
715 if [ "${CT_MULTILIB}" = "y" ]; then
716 multilibs=( $( "${CT_PREFIX_DIR}/bin/${CT_TARGET}-gcc" -print-multi-lib \
718 if [ ${#multilibs[@]} -ne 0 ]; then
719 CT_DoLog EXTRA "gcc configured with these multilibs (besides the default):"
720 for i in "${multilibs[@]}"; do
723 CT_DoLog EXTRA " ${flags//@/ -} --> ${dir}/"
726 CT_DoLog WARN "gcc configured for multilib, but none available"