binutils/binutils: Add CUSTOM version and CUSTOM_LOCATION config options and GetCustom
CUSTOM_LOCATION config options only presented in menuconfig if component
CUSTOM version selected.
Signed-off-by: "David Holsgrove" <david.holsgrove@xilinx.com>
[yann.morin.1998@free.fr: fix indentation, don't patch custom dir location]
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Message-Id: <7a604b5df9c84a1e20c3.1349931195@localhost.localdomain>
PatchWork-Id: 190788
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
7 if [ "${CT_CC_CUSTOM}" = "y" ]; then
8 CT_GetCustom "gcc" "${CT_CC_VERSION}" "${CT_CC_CUSTOM_LOCATION}"
9 elif [ -n "${CT_CC_V_SVN}" ]; then
13 if [ "${CT_GCC_HTTP}" = "y" ]; then
14 svn_base="http://gcc.gnu.org/svn/gcc"
16 svn_base="svn://gcc.gnu.org/svn/gcc"
19 svn_base+="/${CT_GCC_BRANCH:-trunk}"
21 CT_CC_VERSION="${CT_GCC_BRANCH//\//_}"
23 CT_GetSVN "gcc-${CT_CC_VERSION}" \
25 "${CT_GCC_REVISION:-HEAD}"
29 local linaro_base_url="http://launchpad.net/gcc-linaro"
32 # Account for the Linaro versioning
33 linaro_version="$( echo "${CT_CC_VERSION}" \
34 |sed -r -e 's/^linaro-//;' \
36 linaro_series="$( echo "${linaro_version}" \
37 |sed -r -e 's/-.*//;' \
40 # Ah! gcc folks are kind of 'different': they store the tarballs in
41 # subdirectories of the same name!
42 # Arrgghh! Some of those versions does not follow this convention:
43 # gcc-3.3.3 lives in releases/gcc-3.3.3, while gcc-2.95.* isn't in a
45 CT_GetFile "gcc-${CT_CC_VERSION}" \
46 {ftp,http}://ftp.gnu.org/gnu/gcc{,{,/releases}/gcc-${CT_CC_VERSION}} \
47 ftp://ftp.irisa.fr/pub/mirrors/gcc.gnu.org/gcc/releases/gcc-${CT_CC_VERSION} \
48 ftp://ftp.uvsq.fr/pub/gcc/snapshots/${CT_CC_VERSION} \
49 "${linaro_base_url}/${linaro_series}/${linaro_version}/+download"
51 fi # -n ${CT_CC_V_SVN}
52 # Starting with GCC 4.3, ecj is used for Java, and will only be
53 # built if the configure script finds ecj.jar at the top of the
54 # GCC source tree, which will not be there unless we get it and
55 # put it there ourselves
56 if [ "${CT_CC_LANG_JAVA_USE_ECJ}" = "y" ]; then
57 CT_GetFile ecj-latest .jar ftp://gcc.gnu.org/pub/java \
58 ftp://sourceware.org/pub/java
64 # If using custom directory location, nothing to do
65 if [ "${CT_CC_CUSTOM}" = "y" \
66 -a -d "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}" ]; then
70 CT_Extract "gcc-${CT_CC_VERSION}"
71 CT_Patch "gcc" "${CT_CC_VERSION}"
73 # Copy ecj-latest.jar to ecj.jar at the top of the GCC source tree
74 if [ "${CT_CC_LANG_JAVA_USE_ECJ}" = "y" \
75 -a ! -f "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/ecj.jar" \
77 CT_DoExecLog ALL cp -v "${CT_TARBALLS_DIR}/ecj-latest.jar" "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/ecj.jar"
81 #------------------------------------------------------------------------------
82 # This function builds up the set of languages to enable
83 # No argument expected, returns the comma-separated language list on stdout
88 [ "${CT_CC_LANG_CXX}" = "y" ] && lang_list+=",c++"
89 [ "${CT_CC_LANG_FORTRAN}" = "y" ] && lang_list+=",fortran"
90 [ "${CT_CC_LANG_ADA}" = "y" ] && lang_list+=",ada"
91 [ "${CT_CC_LANG_JAVA}" = "y" ] && lang_list+=",java"
92 [ "${CT_CC_LANG_OBJC}" = "y" ] && lang_list+=",objc"
93 [ "${CT_CC_LANG_OBJCXX}" = "y" ] && lang_list+=",obj-c++"
94 lang_list+="${CT_CC_LANG_OTHERS:+,${CT_CC_LANG_OTHERS}}"
96 printf "%s" "${lang_list}"
99 #------------------------------------------------------------------------------
101 do_cc_core_pass_1() {
104 core_opts+=( "mode=static" )
105 core_opts+=( "host=${CT_BUILD}" )
106 core_opts+=( "complibs=${CT_BUILDTOOLS_PREFIX_DIR}" )
107 core_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
108 core_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
109 core_opts+=( "lang_list=c" )
111 CT_DoStep INFO "Installing pass-1 core C compiler"
112 CT_mkdir_pushd "${CT_BUILD_DIR}/build-cc-core-pass-1"
114 do_cc_core_backend "${core_opts[@]}"
121 do_cc_core_pass_2() {
125 core_opts+=( "host=${CT_BUILD}" )
126 core_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
127 core_opts+=( "complibs=${CT_BUILDTOOLS_PREFIX_DIR}" )
128 core_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
129 core_opts+=( "lang_list=c" )
131 # Different conditions are at stake here:
132 # - In case the threading model is NPTL, we need a shared-capable core
133 # gcc; in all other cases, we need a static-only core gcc.
134 # - In case the threading model is NPTL or win32, or gcc is 4.3 or
135 # later, we need to build libgcc
136 case "${CT_THREADS}" in
138 core_opts+=( "mode=shared" )
139 core_opts+=( "build_libgcc=yes" )
142 core_opts+=( "mode=static" )
143 core_opts+=( "build_libgcc=yes" )
146 core_opts+=( "mode=static" )
147 if [ "${CT_CC_GCC_4_3_or_later}" = "y" ]; then
148 core_opts+=( "build_libgcc=yes" )
153 CT_DoStep INFO "Installing pass-2 core C compiler"
154 CT_mkdir_pushd "${CT_BUILD_DIR}/build-cc-core-pass-2"
156 do_cc_core_backend "${core_opts[@]}"
162 #------------------------------------------------------------------------------
164 # This function is used to build the core C compiler.
165 # Usage: do_cc_core_backend param=value [...]
166 # Parameter : Definition : Type : Default
167 # mode : build a 'static', 'shared' or 'baremetal' : string : (none)
168 # host : the machine the core will run on : tuple : (none)
169 # prefix : dir prefix to install into : dir : (none)
170 # complibs : dir where complibs are isntalled : dir : (none)
171 # lang_list : the list of languages to build : string : (empty)
172 # build_libgcc : build libgcc or not : bool : no
173 # build_libstdcxx : build libstdc++ or not : bool : no
174 # build_staticlinked : build statically linked or not : bool : no
175 # build_manuals : whether to build manuals or not : bool : no
176 # cflags : host CFLAGS to use : string : (empty)
177 # Usage: do_cc_core_backend mode=[static|shared|baremetal] build_libgcc=[yes|no] build_staticlinked=[yes|no]
178 do_cc_core_backend() {
180 local build_libgcc=no
181 local build_libstdcxx=no
182 local build_staticlinked=no
183 local build_manuals=no
190 local -a host_libstdcxx_flags
191 local -a extra_config
192 local -a core_LDFLAGS
193 local -a core_targets
200 CT_DoLog EXTRA "Configuring core C compiler"
204 extra_config+=("--with-newlib")
205 extra_config+=("--enable-threads=no")
206 extra_config+=("--disable-shared")
207 copy_headers=y # For baremetal, as there's no headers to copy,
208 # we copy an empty directory. So, who cares?
211 extra_config+=("--enable-shared")
215 extra_config+=("--with-newlib")
216 extra_config+=("--enable-threads=no")
217 extra_config+=("--disable-shared")
221 CT_Abort "Internal Error: 'mode' must be one of: 'static', 'shared' or 'baremetal', not '${mode:-(empty)}'"
225 if [ "${CT_CC_GCC_HAS_PKGVERSION_BUGURL}" = "y" ]; then
226 # Bare metal delivers the core compiler as final compiler, so add version info and bugurl
227 extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
228 [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
231 if [ "${copy_headers}" = "y" ]; then
232 CT_DoLog DEBUG "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
233 CT_DoExecLog ALL cp -a "${CT_HEADERS_DIR}" "${prefix}/${CT_TARGET}/include"
236 for tmp in ARCH ABI CPU TUNE FPU FLOAT; do
237 eval tmp="\${CT_ARCH_WITH_${tmp}}"
238 if [ -n "${tmp}" ]; then
239 extra_config+=("${tmp}")
242 if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
243 extra_config+=("--enable-__cxa_atexit")
245 extra_config+=("--disable-__cxa_atexit")
249 # Keep this full if-else-if-elif-fi-fi block in sync
250 # with the same block in do_cc, below.
251 if [ "${build_staticlinked}" = "yes" ]; then
252 core_LDFLAGS+=("-static")
253 host_libstdcxx_flags+=("-static-libgcc")
254 host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++")
255 host_libstdcxx_flags+=("-lm")
256 # Companion libraries are build static (eg !shared), so
257 # the libstdc++ is not pulled automatically, although it
258 # is needed. Shoe-horn it in our LDFLAGS
259 # Ditto libm on some Fedora boxen
260 core_LDFLAGS+=("-lstdc++")
261 core_LDFLAGS+=("-lm")
263 if [ "${CT_CC_STATIC_LIBSTDCXX}" = "y" ]; then
264 # this is from CodeSourcery arm-2010q1-202-arm-none-linux-gnueabi.src.tar.bz2
266 # INFO: if the host gcc is gcc-4.5 then presumably we could use -static-libstdc++,
267 # see http://gcc.gnu.org/ml/gcc-patches/2009-06/msg01635.html
268 host_libstdcxx_flags+=("-static-libgcc")
269 host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++,-Bdynamic")
270 host_libstdcxx_flags+=("-lm")
271 elif [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
272 # When companion libraries are build static (eg !shared),
273 # the libstdc++ is not pulled automatically, although it
274 # is needed. Shoe-horn it in our LDFLAGS
275 # Ditto libm on some Fedora boxen
276 core_LDFLAGS+=("-lstdc++")
277 core_LDFLAGS+=("-lm")
281 if [ "${CT_CC_GCC_USE_GMP_MPFR}" = "y" ]; then
282 extra_config+=("--with-gmp=${complibs}")
283 extra_config+=("--with-mpfr=${complibs}")
285 if [ "${CT_CC_GCC_USE_MPC}" = "y" ]; then
286 extra_config+=("--with-mpc=${complibs}")
288 if [ "${CT_CC_GCC_USE_GRAPHITE}" = "y" ]; then
289 extra_config+=("--with-ppl=${complibs}")
290 # With PPL 0.11+, also pull libpwl if needed
291 if [ "${CT_PPL_NEEDS_LIBPWL}" = "y" ]; then
292 host_libstdcxx_flags+=("-L${complibs}/lib")
293 host_libstdcxx_flags+=("-lpwl")
295 extra_config+=("--with-cloog=${complibs}")
296 elif [ "${CT_CC_GCC_HAS_GRAPHITE}" = "y" ]; then
297 extra_config+=("--with-ppl=no")
298 extra_config+=("--with-cloog=no")
300 if [ "${CT_CC_GCC_USE_LTO}" = "y" ]; then
301 extra_config+=("--with-libelf=${complibs}")
302 extra_config+=("--enable-lto")
303 elif [ "${CT_CC_GCC_HAS_LTO}" = "y" ]; then
304 extra_config+=("--with-libelf=no")
305 extra_config+=("--disable-lto")
308 if [ ${#host_libstdcxx_flags[@]} -ne 0 ]; then
309 extra_config+=("--with-host-libstdcxx=${host_libstdcxx_flags[*]}")
312 if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then
313 extra_config+=("--enable-target-optspace")
316 case "${CT_CC_GCC_LDBL_128}" in
317 y) extra_config+=("--with-long-double-128");;
319 "") extra_config+=("--without-long-double-128");;
322 if [ "${CT_CC_GCC_BUILD_ID}" = "y" ]; then
323 extra_config+=( --enable-linker-build-id )
326 case "${CT_CC_GCC_LNK_HASH_STYLE}" in
328 *) extra_config+=( "--with-linker-hash-style=${CT_CC_GCC_LNK_HASH_STYLE}" );;
333 case "${CT_CC_GCC_mips_llsc}" in
334 y) extra_config+=( --with-llsc );;
336 *) extra_config+=( --without-llsc );;
338 case "${CT_CC_GCC_mips_synci}" in
339 y) extra_config+=( --with-synci );;
341 *) extra_config+=( --without-synci );;
343 if [ "${CT_CC_GCC_mips_plt}" ]; then
344 extra_config+=( --with-mips-plt )
349 extra_config+=(--disable-libgomp)
350 extra_config+=(--disable-libmudflap)
352 [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && extra_config+=("--disable-nls")
354 [ "${CT_CC_GCC_DISABLE_PCH}" = "y" ] && extra_config+=("--disable-libstdcxx-pch")
356 if [ "${CT_CC_GCC_SYSTEM_ZLIB}" = "y" ]; then
357 extra_config+=("--with-system-zlib")
360 if [ "${CT_MULTILIB}" = "y" ]; then
361 extra_config+=("--enable-multilib")
363 extra_config+=("--disable-multilib")
366 CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
368 # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
370 CC_FOR_BUILD="${CT_BUILD}-gcc" \
372 LDFLAGS="${core_LDFLAGS[*]}" \
373 "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/configure" \
374 --build=${CT_BUILD} \
376 --target=${CT_TARGET} \
377 --prefix="${prefix}" \
378 --with-local-prefix="${CT_SYSROOT_DIR}" \
379 --disable-libmudflap \
380 ${CC_CORE_SYSROOT_ARG} \
381 "${extra_config[@]}" \
382 --enable-languages="${lang_list}" \
383 "${CT_CC_CORE_EXTRA_CONFIG_ARRAY[@]}"
385 if [ "${build_libgcc}" = "yes" ]; then
386 # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
387 # gcc/config/t-libunwind so -lc is removed from the link for
388 # libgcc_s.so, as we do not have a target -lc yet.
389 # This is not as ugly as it appears to be ;-) All symbols get resolved
390 # during the glibc build, and we provide a proper libgcc_s.so for the
391 # cross toolchain during the final gcc build.
393 # As we cannot modify the source tree, nor override SHLIB_LC itself
394 # during configure or make, we have to edit the resultant
395 # gcc/libgcc.mk itself to remove -lc from the link.
396 # This causes us to have to jump through some hoops...
398 # To produce libgcc.mk to edit we firstly require libiberty.a,
399 # so we configure then build it.
400 # Next we have to configure gcc, create libgcc.mk then edit it...
401 # So much easier if we just edit the source tree, but hey...
402 if [ ! -f "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" ]; then
403 CT_DoExecLog CFG make ${JOBSFLAGS} configure-libiberty
404 CT_DoExecLog ALL make ${JOBSFLAGS} -C libiberty libiberty.a
405 CT_DoExecLog CFG make ${JOBSFLAGS} configure-gcc configure-libcpp
406 CT_DoExecLog ALL make ${JOBSFLAGS} all-libcpp
408 CT_DoExecLog CFG make ${JOBSFLAGS} configure-gcc configure-libcpp configure-build-libiberty
409 CT_DoExecLog ALL make ${JOBSFLAGS} all-libcpp all-build-libiberty
411 # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
412 if [ -d "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/libdecnumber" ]; then
413 CT_DoExecLog CFG make ${JOBSFLAGS} configure-libdecnumber
414 CT_DoExecLog ALL make ${JOBSFLAGS} -C libdecnumber libdecnumber.a
417 # Starting with GCC 4.3, libgcc.mk is no longer built,
418 # and libgcc.mvars is used instead.
420 if [ "${CT_CC_GCC_4_3_or_later}" = "y" ]; then
421 libgcc_rule="libgcc.mvars"
422 core_targets=( gcc target-libgcc )
424 libgcc_rule="libgcc.mk"
428 # On bare metal and canadian build the host-compiler is used when
429 # actually the build-system compiler is required. Choose the correct
430 # compilers for canadian build and use the defaults on other
432 if [ "${CT_BARE_METAL},${CT_CANADIAN}" = "y,y" ]; then
433 repair_cc="CC_FOR_BUILD=${CT_BUILD}-gcc \
434 GCC_FOR_TARGET=${CT_TARGET}-gcc"
439 CT_DoExecLog ALL make ${JOBSFLAGS} -C gcc ${libgcc_rule} \
441 sed -r -i -e 's@-lc@@g' gcc/${libgcc_rule}
445 if [ "${build_libstdcxx}" = "yes" \
446 -a "${CT_CC_LANG_CXX}" = "y" \
448 core_targets+=( target-libstdc++-v3 )
451 CT_DoLog EXTRA "Building core C compiler"
452 CT_DoExecLog ALL make ${JOBSFLAGS} "${core_targets[@]/#/all-}"
454 CT_DoLog EXTRA "Installing core C compiler"
455 CT_DoExecLog ALL make ${JOBSFLAGS} "${core_targets[@]/#/install-}"
457 if [ "${build_manuals}" = "yes" ]; then
458 CT_DoLog EXTRA "Building the GCC manuals"
459 CT_DoExecLog ALL make pdf html
460 CT_DoLog EXTRA "Installing the GCC manuals"
461 CT_DoExecLog ALL make install-{pdf,html}-gcc
464 # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
465 # to call the C compiler with the same, somewhat canonical name.
466 # check whether compiler has an extension
467 file="$( ls -1 "${prefix}/bin/${CT_TARGET}-gcc."* 2>/dev/null || true )"
468 [ -z "${file}" ] || ext=".${file##*.}"
469 CT_DoExecLog ALL ln -sfv "${CT_TARGET}-gcc${ext}" "${prefix}/bin/${CT_TARGET}-cc${ext}"
471 if [ "${CT_MULTILIB}" = "y" ]; then
472 if [ "${CT_CANADIAN}" = "y" -a "${mode}" = "baremetal" \
473 -a "${host}" = "${CT_HOST}" ]; then
474 CT_DoLog WARN "Canadian Cross unable to confirm multilibs configured correctly"
476 multilibs=( $( "${prefix}/bin/${CT_TARGET}-gcc" -print-multi-lib \
478 if [ ${#multilibs[@]} -ne 0 ]; then
479 CT_DoLog EXTRA "gcc configured with these multilibs (besides the default):"
480 for i in "${multilibs[@]}"; do
483 CT_DoLog EXTRA " ${flags//@/ -} --> ${dir}/"
486 CT_DoLog WARN "gcc configured for multilib, but none available"
492 #------------------------------------------------------------------------------
493 # Build complete gcc to run on build
495 local -a build_final_opts
496 local build_final_backend
498 # In case we're canadian or cross-native, it seems that a
499 # real, complete compiler is needed?!? WTF? Sigh...
500 # Otherwise, there is nothing to do.
501 case "${CT_TOOLCHAIN_TYPE}" in
502 native|cross) return 0;;
505 build_final_opts+=( "host=${CT_BUILD}" )
506 build_final_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
507 build_final_opts+=( "complibs=${CT_BUILDTOOLS_PREFIX_DIR}" )
508 build_final_opts+=( "lang_list=$( cc_gcc_lang_list )" )
509 if [ "${CT_BARE_METAL}" = "y" ]; then
510 # In the tests I've done, bare-metal was not impacted by the
511 # lack of such a compiler, but better safe than sorry...
512 build_final_opts+=( "mode=baremetal" )
513 build_final_opts+=( "build_libgcc=yes" )
514 build_final_opts+=( "build_libstdcxx=yes" )
515 if [ "${CT_STATIC_TOOLCHAIN}" = "y" ]; then
516 build_final_opts+=( "build_staticlinked=yes" )
518 build_final_backend=do_cc_core_backend
520 build_final_backend=do_cc_backend
523 CT_DoStep INFO "Installing final compiler for build"
524 CT_mkdir_pushd "${CT_BUILD_DIR}/build-cc-final-build-${CT_BUILD}"
526 "${build_final_backend}" "${build_final_opts[@]}"
532 #------------------------------------------------------------------------------
533 # Build final gcc to run on host
538 final_opts+=( "host=${CT_HOST}" )
539 final_opts+=( "prefix=${CT_PREFIX_DIR}" )
540 final_opts+=( "complibs=${CT_HOST_COMPLIBS_DIR}" )
541 final_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
542 final_opts+=( "lang_list=$( cc_gcc_lang_list )" )
543 if [ "${CT_BUILD_MANUALS}" = "y" ]; then
544 final_opts+=( "build_manuals=yes" )
546 if [ "${CT_BARE_METAL}" = "y" ]; then
547 final_opts+=( "mode=baremetal" )
548 final_opts+=( "build_libgcc=yes" )
549 final_opts+=( "build_libstdcxx=yes" )
550 if [ "${CT_STATIC_TOOLCHAIN}" = "y" ]; then
551 final_opts+=( "build_staticlinked=yes" )
553 final_backend=do_cc_core_backend
555 final_backend=do_cc_backend
558 CT_DoStep INFO "Installing final compiler"
559 CT_mkdir_pushd "${CT_BUILD_DIR}/build-cc-final"
561 "${final_backend}" "${final_opts[@]}"
567 #------------------------------------------------------------------------------
568 # Build the final gcc
569 # Usage: do_cc_backend param=value [...]
570 # Parameter : Definition : Type : Default
571 # host : the host we run onto : tuple : (none)
572 # prefix : the runtime prefix : dir : (none)
573 # complibs : the companion libraries prefix : dir : (none)
574 # cflags : the host CFLAGS : string : (empty)
575 # lang_list : the list of languages to build : string : (empty)
576 # build_manuals : whether to build manuals or not : bool : no
584 local -a host_libstdcxx_flags
585 local -a extra_config
586 local -a final_LDFLAGS
594 CT_DoLog EXTRA "Configuring final compiler"
596 # Enable selected languages
597 extra_config+=("--enable-languages=${lang_list}")
599 for tmp in ARCH ABI CPU TUNE FPU FLOAT; do
600 eval tmp="\${CT_ARCH_WITH_${tmp}}"
601 if [ -n "${tmp}" ]; then
602 extra_config+=("${tmp}")
606 [ "${CT_SHARED_LIBS}" = "y" ] || extra_config+=("--disable-shared")
607 if [ "${CT_CC_GCC_HAS_PKGVERSION_BUGURL}" = "y" ]; then
608 extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
609 [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
611 case "${CT_CC_GCC_SJLJ_EXCEPTIONS}" in
612 y) extra_config+=("--enable-sjlj-exceptions");;
614 "") extra_config+=("--disable-sjlj-exceptions");;
616 if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
617 extra_config+=("--enable-__cxa_atexit")
619 extra_config+=("--disable-__cxa_atexit")
621 if [ -n "${CT_CC_ENABLE_CXX_FLAGS}" ]; then
622 extra_config+=("--enable-cxx-flags=${CT_CC_ENABLE_CXX_FLAGS}")
624 if [ "${CT_CC_GCC_LIBMUDFLAP}" = "y" ]; then
625 extra_config+=(--enable-libmudflap)
627 extra_config+=(--disable-libmudflap)
629 if [ "${CT_CC_GCC_LIBGOMP}" = "y" ]; then
630 extra_config+=(--enable-libgomp)
632 extra_config+=(--disable-libgomp)
634 if [ "${CT_CC_GCC_LIBSSP}" = "y" ]; then
635 extra_config+=(--enable-libssp)
637 extra_config+=(--disable-libssp)
639 if [ "${CT_CC_GCC_HAS_LIBQUADMATH}" = "y" ]; then
640 if [ "${CT_CC_GCC_LIBQUADMATH}" = "y" ]; then
641 extra_config+=(--enable-libquadmath)
642 extra_config+=(--enable-libquadmath-support)
644 extra_config+=(--disable-libquadmath)
645 extra_config+=(--disable-libquadmath-support)
650 # Keep this full if-else-if-elif-fi-fi block in sync
651 # with the same block in do_cc_core, above.
652 if [ "${CT_STATIC_TOOLCHAIN}" = "y" ]; then
653 final_LDFLAGS+=("-static")
654 host_libstdcxx_flags+=("-static-libgcc")
655 host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++")
656 host_libstdcxx_flags+=("-lm")
657 # Companion libraries are build static (eg !shared), so
658 # the libstdc++ is not pulled automatically, although it
659 # is needed. Shoe-horn it in our LDFLAGS
660 # Ditto libm on some Fedora boxen
661 final_LDFLAGS+=("-lstdc++")
662 final_LDFLAGS+=("-lm")
664 if [ "${CT_CC_STATIC_LIBSTDCXX}" = "y" ]; then
665 # this is from CodeSourcery arm-2010q1-202-arm-none-linux-gnueabi.src.tar.bz2
667 # INFO: if the host gcc is gcc-4.5 then presumably we could use -static-libstdc++,
668 # see http://gcc.gnu.org/ml/gcc-patches/2009-06/msg01635.html
669 host_libstdcxx_flags+=("-static-libgcc")
670 host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++,-Bdynamic")
671 host_libstdcxx_flags+=("-lm")
672 elif [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
673 # When companion libraries are build static (eg !shared),
674 # the libstdc++ is not pulled automatically, although it
675 # is needed. Shoe-horn it in our LDFLAGS
676 # Ditto libm on some Fedora boxen
677 final_LDFLAGS+=("-lstdc++")
678 final_LDFLAGS+=("-lm")
682 if [ "${CT_CC_GCC_USE_GMP_MPFR}" = "y" ]; then
683 extra_config+=("--with-gmp=${complibs}")
684 extra_config+=("--with-mpfr=${complibs}")
686 if [ "${CT_CC_GCC_USE_MPC}" = "y" ]; then
687 extra_config+=("--with-mpc=${complibs}")
689 if [ "${CT_CC_GCC_USE_GRAPHITE}" = "y" ]; then
690 extra_config+=("--with-ppl=${complibs}")
691 # With PPL 0.11+, also pull libpwl if needed
692 if [ "${CT_PPL_NEEDS_LIBPWL}" = "y" ]; then
693 host_libstdcxx_flags+=("-L${complibs}/lib")
694 host_libstdcxx_flags+=("-lpwl")
696 extra_config+=("--with-cloog=${complibs}")
697 elif [ "${CT_CC_GCC_HAS_GRAPHITE}" = "y" ]; then
698 extra_config+=("--with-ppl=no")
699 extra_config+=("--with-cloog=no")
701 if [ "${CT_CC_GCC_USE_LTO}" = "y" ]; then
702 extra_config+=("--with-libelf=${complibs}")
703 elif [ "${CT_CC_GCC_HAS_LTO}" = "y" ]; then
704 extra_config+=("--with-libelf=no")
707 if [ ${#host_libstdcxx_flags[@]} -ne 0 ]; then
708 extra_config+=("--with-host-libstdcxx=${host_libstdcxx_flags[*]}")
711 if [ "${CT_THREADS}" = "none" ]; then
712 extra_config+=("--disable-threads")
713 if [ "${CT_CC_GCC_4_2_or_later}" = y ]; then
714 CT_Test "Disabling libgomp for no-thread gcc>=4.2" "${CT_CC_GCC_LIBGOMP}" = "Y"
715 extra_config+=("--disable-libgomp")
718 if [ "${CT_THREADS}" = "win32" ]; then
719 extra_config+=("--enable-threads=win32")
720 extra_config+=("--disable-win32-registry")
722 extra_config+=("--enable-threads=posix")
726 if [ "${CT_CC_GCC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then
727 extra_config+=("--enable-target-optspace")
729 if [ "${CT_CC_GCC_DISABLE_PCH}" = "y" ]; then
730 extra_config+=("--disable-libstdcxx-pch")
733 case "${CT_CC_GCC_LDBL_128}" in
734 y) extra_config+=("--with-long-double-128");;
736 "") extra_config+=("--without-long-double-128");;
739 if [ "${CT_CC_GCC_BUILD_ID}" = "y" ]; then
740 extra_config+=( --enable-linker-build-id )
743 case "${CT_CC_GCC_LNK_HASH_STYLE}" in
745 *) extra_config+=( "--with-linker-hash-style=${CT_CC_GCC_LNK_HASH_STYLE}" );;
748 if [ "${CT_CC_GCC_ENABLE_PLUGINS}" = "y" ]; then
749 extra_config+=( --enable-plugin )
751 if [ "${CT_CC_GCC_GOLD}" = "y" ]; then
752 extra_config+=( --enable-gold )
757 case "${CT_CC_GCC_mips_llsc}" in
758 y) extra_config+=( --with-llsc );;
760 *) extra_config+=( --without-llsc );;
762 case "${CT_CC_GCC_mips_synci}" in
763 y) extra_config+=( --with-synci );;
765 *) extra_config+=( --without-synci );;
767 if [ "${CT_CC_GCC_mips_plt}" ]; then
768 extra_config+=( --with-mips-plt )
773 [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && extra_config+=("--disable-nls")
775 if [ "${CT_CC_GCC_SYSTEM_ZLIB}" = "y" ]; then
776 extra_config+=("--with-system-zlib")
779 if [ "${CT_MULTILIB}" = "y" ]; then
780 extra_config+=("--enable-multilib")
782 extra_config+=("--disable-multilib")
785 CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
788 CC_FOR_BUILD="${CT_BUILD}-gcc" \
790 LDFLAGS="${final_LDFLAGS[*]}" \
791 CFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}" \
792 CXXFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}" \
793 LDFLAGS_FOR_TARGET="${CT_TARGET_LDFLAGS}" \
794 "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/configure" \
795 --build=${CT_BUILD} \
797 --target=${CT_TARGET} \
798 --prefix="${prefix}" \
800 "${extra_config[@]}" \
801 --with-local-prefix="${CT_SYSROOT_DIR}" \
804 "${CT_CC_EXTRA_CONFIG_ARRAY[@]}"
806 if [ "${CT_CANADIAN}" = "y" ]; then
807 CT_DoLog EXTRA "Building libiberty"
808 CT_DoExecLog ALL make ${JOBSFLAGS} all-build-libiberty
811 CT_DoLog EXTRA "Building final compiler"
812 CT_DoExecLog ALL make ${JOBSFLAGS} all
814 CT_DoLog EXTRA "Installing final compiler"
815 CT_DoExecLog ALL make ${JOBSFLAGS} install
817 if [ "${build_manuals}" = "yes" ]; then
818 CT_DoLog EXTRA "Building the GCC manuals"
819 CT_DoExecLog ALL make pdf html
820 CT_DoLog EXTRA "Installing the GCC manuals"
821 CT_DoExecLog ALL make install-{pdf,html}-gcc
824 # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
825 # to call the C compiler with the same, somewhat canonical name.
826 # check whether compiler has an extension
827 file="$( ls -1 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-gcc."* 2>/dev/null || true )"
828 [ -z "${file}" ] || ext=".${file##*.}"
829 CT_DoExecLog ALL ln -sfv "${CT_TARGET}-gcc${ext}" "${CT_PREFIX_DIR}/bin/${CT_TARGET}-cc${ext}"
831 if [ "${CT_MULTILIB}" = "y" ]; then
832 if [ "${CT_CANADIAN}" = "y" ]; then
833 CT_DoLog WARN "Canadian Cross unable to confirm multilibs configured correctly"
835 multilibs=( $( "${prefix}/bin/${CT_TARGET}-gcc" -print-multi-lib \
837 if [ ${#multilibs[@]} -ne 0 ]; then
838 CT_DoLog EXTRA "gcc configured with these multilibs (besides the default):"
839 for i in "${multilibs[@]}"; do
842 CT_DoLog EXTRA " ${flags//@/ -} --> ${dir}/"
845 CT_DoLog WARN "gcc configured for multilib, but none available"