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
6 [ "${CT_CC}" = "gcc" ] || return 0
7 echo "gcc-${CT_CC_VERSION}"
12 # Ah! gcc folks are kind of 'different': they store the tarballs in
13 # subdirectories of the same name! That's because gcc is such /crap/ that
14 # it is such /big/ that it needs being splitted for distribution! Sad. :-(
15 # Arrgghh! Some of those versions does not follow this convention:
16 # gcc-3.3.3 lives in releases/gcc-3.3.3, while gcc-2.95.* isn't in a
17 # subdirectory! You bastard!
18 CT_GetFile "${CT_CC_FILE}" \
19 {ftp,http}://ftp.gnu.org/gnu/gcc{,{,/releases}/${CT_CC_FILE}}
24 CT_ExtractAndPatch "${CT_CC_FILE}"
27 #------------------------------------------------------------------------------
30 # In case we're NPTL, build the static core gcc;
31 # in any other case, do nothing.
32 case "${CT_THREADS}" in
33 nptl) do_cc_core_static build_libgcc=no;;
39 # In case we're NPTL, build the shared core gcc,
40 # in any other case, build the static core gcc and the target libgcc.
41 case "${CT_THREADS}" in
42 nptl) do_cc_core_shared;;
43 *) do_cc_core_static build_libgcc=yes;;
47 #------------------------------------------------------------------------------
48 # Build static core gcc
49 # We need to know wether to build the target libgcc!
50 # Usage: do_cc_core_static <build_libgcc=[yes|no]>
53 CT_TestOrAbort "Internal Error: '$0' does not know wether to build, or not to build, target libgcc" -n "${build_libgcc}"
55 mkdir -p "${CT_BUILD_DIR}/build-cc-core-static"
56 cd "${CT_BUILD_DIR}/build-cc-core-static"
58 CT_DoStep INFO "Installing static core C compiler"
60 CT_DoLog DEBUG "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
61 mkdir -p "${CT_CC_CORE_STATIC_PREFIX_DIR}/${CT_TARGET}/include"
62 cp -r "${CT_HEADERS_DIR}"/* "${CT_CC_CORE_STATIC_PREFIX_DIR}/${CT_TARGET}/include" 2>&1 |CT_DoLog DEBUG
64 CT_DoLog EXTRA "Configuring static core C compiler"
66 extra_config="${CT_ARCH_WITH_ARCH} ${CT_ARCH_WITH_ABI} ${CT_ARCH_WITH_CPU} ${CT_ARCH_WITH_TUNE} ${CT_ARCH_WITH_FPU} ${CT_ARCH_WITH_FLOAT}"
67 [ "${CT_GMP_MPFR}" = "y" ] && extra_config="${extra_config} --with-gmp=${CT_PREFIX_DIR} --with-mpfr=${CT_PREFIX_DIR}"
68 if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
69 extra_config="${extra_config} --enable-__cxa_atexit"
71 extra_config="${extra_config} --disable-__cxa_atexit"
74 CT_DoLog DEBUG "Extra config passed: '${extra_config}'"
76 # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
77 CC_FOR_BUILD="${CT_CC_NATIVE}" \
78 CFLAGS="${CT_CFLAGS_FOR_HOST}" \
80 "${CT_SRC_DIR}/${CT_CC_FILE}/configure" \
83 --target=${CT_TARGET} \
84 --prefix="${CT_CC_CORE_STATIC_PREFIX_DIR}" \
85 --with-local-prefix="${CT_SYSROOT_DIR}" \
88 ${CC_CORE_SYSROOT_ARG} \
92 --enable-symvers=gnu \
93 --enable-languages=c \
95 --enable-target-optspace \
96 ${CT_CC_CORE_EXTRA_CONFIG}
98 if [ "${build_libgcc}" = "yes" ]; then
99 if [ ! -f "${CT_SRC_DIR}/${CT_CC_FILE}/gcc/BASE-VER" ]; then
100 CT_DoExecLog ALL make configure-libiberty
101 CT_DoExecLog ALL make ${PARALLELMFLAGS} -C libiberty libiberty.a
102 CT_DoExecLog ALL make configure-gcc configure-libcpp
103 CT_DoExecLog ALL make ${PARALLELMFLAGS} all-libcpp
105 CT_DoExecLog ALL make configure-gcc configure-libcpp configure-build-libiberty
106 CT_DoExecLog ALL make ${PARALLELMFLAGS} all-libcpp all-build-libiberty
108 # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
109 if [ -d "${CT_SRC_DIR}/${CT_CC_FILE}/libdecnumber" ]; then
110 CT_DoExecLog ALL make configure-libdecnumber
111 CT_DoExecLog ALL make ${PARALLELMFLAGS} -C libdecnumber libdecnumber.a
114 # Starting with GCC 4.3, libgcc.mk is no longer built,
115 # and libgcc.mvars is used instead.
117 gcc_version_major=$(echo ${CT_CC_VERSION} |sed -r -e 's/^([^\.]+)\..*/\1/')
118 gcc_version_minor=$(echo ${CT_CC_VERSION} |sed -r -e 's/^[^\.]+\.([^.]+).*/\1/')
120 if [ ${gcc_version_major} -eq 4 -a ${gcc_version_minor} -ge 3 \
121 -o ${gcc_version_major} -gt 4 ]; then
122 libgcc_rule="libgcc.mvars"
123 build_rules="all-gcc all-target-libgcc"
124 install_rules="install-gcc install-target-libgcc"
126 libgcc_rule="libgcc.mk"
127 build_rules="all-gcc"
128 install_rules="install-gcc"
131 CT_DoExecLog ALL make ${PARALLELMFLAGS} -C gcc ${libgcc_rule}
132 sed -r -i -e 's@-lc@@g' gcc/${libgcc_rule}
134 build_rules="all-gcc"
135 install_rules="install-gcc"
138 if [ "${CT_CANADIAN}" = "y" ]; then
139 CT_DoLog EXTRA "Building libiberty"
140 CT_DoExecLog ALL make ${PARALLELMFLAGS} all-build-libiberty
143 CT_DoLog EXTRA "Building static core C compiler"
144 CT_DoExecLog ALL make ${PARALLELMFLAGS} ${build_rules}
146 CT_DoLog EXTRA "Installing static core C compiler"
147 CT_DoExecLog ALL make ${install_rules}
152 #------------------------------------------------------------------------------
153 # Build shared core gcc
154 do_cc_core_shared() {
155 mkdir -p "${CT_BUILD_DIR}/build-cc-core-shared"
156 cd "${CT_BUILD_DIR}/build-cc-core-shared"
158 CT_DoStep INFO "Installing shared core C compiler"
160 CT_DoLog DEBUG "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
161 mkdir -p "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include"
162 cp -r "${CT_HEADERS_DIR}"/* "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include" 2>&1 |CT_DoLog DEBUG
164 CT_DoLog EXTRA "Configuring shared core C compiler"
166 extra_config="${CT_ARCH_WITH_ARCH} ${CT_ARCH_WITH_ABI} ${CT_ARCH_WITH_CPU} ${CT_ARCH_WITH_TUNE} ${CT_ARCH_WITH_FPU} ${CT_ARCH_WITH_FLOAT}"
167 [ "${CT_GMP_MPFR}" = "y" ] && extra_config="${extra_config} --with-gmp=${CT_PREFIX_DIR} --with-mpfr=${CT_PREFIX_DIR}"
168 if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
169 extra_config="${extra_config} --enable-__cxa_atexit"
171 extra_config="${extra_config} --disable-__cxa_atexit"
174 CT_DoLog DEBUG "Extra config passed: '${extra_config}'"
176 CC_FOR_BUILD="${CT_CC_NATIVE}" \
177 CFLAGS="${CT_CFLAGS_FOR_HOST}" \
179 "${CT_SRC_DIR}/${CT_CC_FILE}/configure" \
181 --target=${CT_TARGET} \
183 --prefix="${CT_CC_CORE_SHARED_PREFIX_DIR}" \
184 --with-local-prefix="${CT_SYSROOT_DIR}" \
186 ${CC_CORE_SYSROOT_ARG} \
189 --enable-symvers=gnu \
190 --enable-languages=c \
192 --enable-target-optspace \
193 ${CT_CC_CORE_EXTRA_CONFIG}
195 # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
196 # gcc/config/t-libunwind so -lc is removed from the link for
197 # libgcc_s.so, as we do not have a target -lc yet.
198 # This is not as ugly as it appears to be ;-) All symbols get resolved
199 # during the glibc build, and we provide a proper libgcc_s.so for the
200 # cross toolchain during the final gcc build.
202 # As we cannot modify the source tree, nor override SHLIB_LC itself
203 # during configure or make, we have to edit the resultant
204 # gcc/libgcc.mk itself to remove -lc from the link.
205 # This causes us to have to jump through some hoops...
207 # To produce libgcc.mk to edit we firstly require libiberty.a,
208 # so we configure then build it.
209 # Next we have to configure gcc, create libgcc.mk then edit it...
210 # So much easier if we just edit the source tree, but hey...
211 if [ ! -f "${CT_SRC_DIR}/${CT_CC_FILE}/gcc/BASE-VER" ]; then
212 CT_DoExecLog ALL make configure-libiberty
213 CT_DoExecLog ALL make ${PARALLELMFLAGS} -C libiberty libiberty.a
214 CT_DoExecLog ALL make configure-gcc configure-libcpp
215 CT_DoExecLog ALL make ${PARALLELMFLAGS} all-libcpp
217 CT_DoExecLog ALL make configure-gcc configure-libcpp configure-build-libiberty
218 CT_DoExecLog ALL make ${PARALLELMFLAGS} all-libcpp all-build-libiberty
220 # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
221 if [ -d "${CT_SRC_DIR}/${CT_CC_FILE}/libdecnumber" ]; then
222 CT_DoExecLog ALL make configure-libdecnumber
223 CT_DoExecLog ALL make ${PARALLELMFLAGS} -C libdecnumber libdecnumber.a
226 # Starting with GCC 4.3, libgcc.mk is no longer built,
227 # and libgcc.mvars is used instead.
229 gcc_version_major=$(echo ${CT_CC_VERSION} |sed -r -e 's/^([^\.]+)\..*/\1/')
230 gcc_version_minor=$(echo ${CT_CC_VERSION} |sed -r -e 's/^[^\.]+\.([^.]+).*/\1/')
232 if [ ${gcc_version_major} -eq 4 -a ${gcc_version_minor} -ge 3 \
233 -o ${gcc_version_major} -gt 4 ]; then
234 libgcc_rule="libgcc.mvars"
235 build_rules="all-gcc all-target-libgcc"
236 install_rules="install-gcc install-target-libgcc"
238 libgcc_rule="libgcc.mk"
239 build_rules="all-gcc"
240 install_rules="install-gcc"
243 CT_DoExecLog ALL make ${PARALLELMFLAGS} -C gcc ${libgcc_rule}
244 sed -r -i -e 's@-lc@@g' gcc/${libgcc_rule}
246 if [ "${CT_CANADIAN}" = "y" ]; then
247 CT_DoLog EXTRA "Building libiberty"
248 CT_DoExecLog ALL make ${PARALLELMFLAGS} all-build-libiberty
251 CT_DoLog EXTRA "Building shared core C compiler"
252 CT_DoExecLog ALL make ${PARALLELMFLAGS} ${build_rules}
254 CT_DoLog EXTRA "Installing shared core C compiler"
255 CT_DoExecLog ALL make ${install_rules}
260 #------------------------------------------------------------------------------
263 CT_DoStep INFO "Installing final compiler"
265 mkdir -p "${CT_BUILD_DIR}/build-cc"
266 cd "${CT_BUILD_DIR}/build-cc"
268 CT_DoLog EXTRA "Configuring final compiler"
270 # Enable selected languages
272 [ "${CT_CC_LANG_CXX}" = "y" ] && lang_opt="${lang_opt},c++"
273 [ "${CT_CC_LANG_FORTRAN}" = "y" ] && lang_opt="${lang_opt},fortran"
274 [ "${CT_CC_LANG_ADA}" = "y" ] && lang_opt="${lang_opt},ada"
275 [ "${CT_CC_LANG_JAVA}" = "y" ] && lang_opt="${lang_opt},java"
276 [ "${CT_CC_LANG_OBJC}" = "y" ] && lang_opt="${lang_opt},objc"
277 [ "${CT_CC_LANG_OBJCXX}" = "y" ] && lang_opt="${lang_opt},obj-c++"
278 CT_Test "Building ADA language is not yet supported. Will try..." "${CT_CC_LANG_ADA}" = "y"
279 CT_Test "Building Objective-C language is not yet supported. Will try..." "${CT_CC_LANG_OBJC}" = "y"
280 CT_Test "Building Objective-C++ language is not yet supported. Will try..." "${CT_CC_LANG_OBJCXX}" = "y"
281 CT_Test "Building ${CT_CC_LANG_OTHERS//,/ } language(s) is not yet supported. Will try..." -n "${CT_CC_LANG_OTHERS}"
282 lang_opt=$(echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;')
284 extra_config="--enable-languages=${lang_opt}"
285 extra_config="${extra_config} --disable-multilib"
286 extra_config="${extra_config} ${CT_ARCH_WITH_ARCH} ${CT_ARCH_WITH_ABI} ${CT_ARCH_WITH_CPU} ${CT_ARCH_WITH_TUNE} ${CT_ARCH_WITH_FPU} ${CT_ARCH_WITH_FLOAT}"
287 [ "${CT_SHARED_LIBS}" = "y" ] || extra_config="${extra_config} --disable-shared"
288 [ "${CT_GMP_MPFR}" = "y" ] && extra_config="${extra_config} --with-gmp=${CT_PREFIX_DIR} --with-mpfr=${CT_PREFIX_DIR}"
289 [ -n "${CT_CC_PKGVERSION}" ] && extra_config="${extra_config} --with-pkgversion=${CT_CC_PKGVERSION}"
290 [ -n "${CT_CC_BUGURL}" ] && extra_config="${extra_config} --with-bugurl=${CT_CC_BUGURL}"
291 [ "${CT_CC_SJLJ_EXCEPTIONS_USE}" = "y" ] && extra_config="${extra_config} --enable-sjlj-exceptions"
292 [ "${CT_CC_SJLJ_EXCEPTIONS_DONT_USE}" = "y" ] && extra_config="${extra_config} --disable-sjlj-exceptions"
293 if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
294 extra_config="${extra_config} --enable-__cxa_atexit"
296 extra_config="${extra_config} --disable-__cxa_atexit"
299 CT_DoLog DEBUG "Extra config passed: '${extra_config}'"
301 # --enable-symvers=gnu really only needed for sh4 to work around a
302 # detection problem only matters for gcc-3.2.x and later, I think.
303 # --disable-nls to work around crash bug on ppc405, but also because
304 # embedded systems don't really need message catalogs...
305 CC_FOR_BUILD="${CT_CC_NATIVE}" \
306 CFLAGS="${CT_CFLAGS_FOR_HOST}" \
307 CFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}" \
308 CXXFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}" \
309 LDFLAGS_FOR_TARGET="${CT_TARGET_LDFLAGS}" \
311 "${CT_SRC_DIR}/${CT_CC_FILE}/configure" \
313 --target=${CT_TARGET} --host=${CT_HOST} \
314 --prefix="${CT_PREFIX_DIR}" \
317 --with-local-prefix="${CT_SYSROOT_DIR}" \
319 --enable-threads=posix \
320 --enable-symvers=gnu \
323 --enable-target-optspace \
324 ${CT_CC_EXTRA_CONFIG}
326 if [ "${CT_CANADIAN}" = "y" ]; then
327 CT_DoLog EXTRA "Building libiberty"
328 CT_DoExecLog ALL make ${PARALLELMFLAGS} all-build-libiberty
331 CT_DoLog EXTRA "Building final compiler"
332 CT_DoExecLog ALL make ${PARALLELMFLAGS} all
334 CT_DoLog EXTRA "Installing final compiler"
335 CT_DoExecLog ALL make install
337 # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
338 # to call the C compiler with the same, somewhat canonical name.
339 ln -sv "${CT_PREFIX_DIR}/bin/${CT_TARGET}"-{g,}cc 2>&1 |CT_DoLog ALL