Merge from branches/ia64@476 : add ia64 preliminary support.
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://ftp.gnu.org/gnu/gcc/${CT_CC_FILE} \
20 ftp://ftp.gnu.org/gnu/gcc/releases/${CT_CC_FILE} \
21 ftp://ftp.gnu.org/gnu/gcc
26 CT_ExtractAndPatch "${CT_CC_FILE}"
29 #------------------------------------------------------------------------------
32 # In case we're NPTL, build the static core gcc;
33 # in any other case, do nothing.
34 CT_DoStep INFO "Core C compiler, pass 1"
35 case "${CT_THREADS}" in
36 nptl) do_cc_core_static;;
37 *) CT_DoLog INFO "Nothing to do";;
44 # In case we're NPTL, build the shared core gcc,
45 # in any other case, build the static core gcc.
46 CT_DoStep INFO "Core C compiler, pass 2"
47 case "${CT_THREADS}" in
48 nptl) do_cc_core_shared;;
49 *) do_cc_core_static;;
54 #------------------------------------------------------------------------------
55 # Build static core gcc
57 mkdir -p "${CT_BUILD_DIR}/build-cc-core-static"
58 cd "${CT_BUILD_DIR}/build-cc-core-static"
60 CT_DoStep INFO "Installing static core C compiler"
62 CT_DoLog EXTRA "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
63 mkdir -p "${CT_CC_CORE_STATIC_PREFIX_DIR}/${CT_TARGET}/include"
64 cp -r "${CT_HEADERS_DIR}"/* "${CT_CC_CORE_STATIC_PREFIX_DIR}/${CT_TARGET}/include" 2>&1 |CT_DoLog DEBUG
66 CT_DoLog EXTRA "Configuring static core C compiler"
69 [ "${CT_ARCH_FLOAT_SW}" = "y" ] && extra_config="${extra_config} --with-float=soft"
70 [ -n "${CT_ARCH_ABI}" ] && extra_config="${extra_config} --with-abi=${CT_ARCH_ABI}"
71 [ -n "${CT_ARCH_ARCH}" ] && extra_config="${extra_config} --with-arch=${CT_ARCH_ARCH}"
72 [ -n "${CT_ARCH_CPU}" ] && extra_config="${extra_config} --with-cpu=${CT_ARCH_CPU}"
73 [ -n "${CT_ARCH_TUNE}" ] && extra_config="${extra_config} --with-tune=${CT_ARCH_TUNE}"
74 [ -n "${CT_ARCH_FPU}" ] && extra_config="${extra_config} --with-fpu=${CT_ARCH_FPU}"
75 [ "${CT_CC_CXA_ATEXIT}" = "y" ] && extra_config="${extra_config} --enable-__cxa_atexit"
77 CT_DoLog DEBUG "Extra config passed: \"${extra_config}\""
79 # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
80 CFLAGS="${CT_CFLAGS_FOR_HOST}" \
81 "${CT_SRC_DIR}/${CT_CC_FILE}/configure" \
84 --target=${CT_TARGET} \
85 --prefix="${CT_CC_CORE_STATIC_PREFIX_DIR}" \
86 --with-local-prefix="${CT_SYSROOT_DIR}" \
89 ${CC_CORE_SYSROOT_ARG} \
93 --enable-symvers=gnu \
94 --enable-languages=c \
96 ${CT_CC_CORE_EXTRA_CONFIG} 2>&1 |CT_DoLog ALL
98 if [ "${CT_CANADIAN}" = "y" ]; then
99 CT_DoLog EXTRA "Building libiberty"
100 make ${PARALLELMFLAGS} all-build-libiberty 2>&1 |CT_DoLog ALL
103 CT_DoLog EXTRA "Building static core C compiler"
104 make ${PARALLELMFLAGS} all-gcc 2>&1 |CT_DoLog ALL
106 CT_DoLog EXTRA "Installing static core C compiler"
107 make install-gcc 2>&1 |CT_DoLog ALL
112 #------------------------------------------------------------------------------
113 # Build shared core gcc
114 do_cc_core_shared() {
115 mkdir -p "${CT_BUILD_DIR}/build-cc-core-shared"
116 cd "${CT_BUILD_DIR}/build-cc-core-shared"
118 CT_DoStep INFO "Installing shared core C compiler"
120 CT_DoLog EXTRA "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
121 mkdir -p "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include"
122 cp -r "${CT_HEADERS_DIR}"/* "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include" 2>&1 |CT_DoLog DEBUG
124 CT_DoLog EXTRA "Configuring shared core C compiler"
127 [ "${CT_ARCH_FLOAT_SW}" = "y" ] && extra_config="${extra_config} --with-float=soft"
128 [ -n "${CT_ARCH_ABI}" ] && extra_config="${extra_config} --with-abi=${CT_ARCH_ABI}"
129 [ -n "${CT_ARCH_ARCH}" ] && extra_config="${extra_config} --with-arch=${CT_ARCH_ARCH}"
130 [ -n "${CT_ARCH_CPU}" ] && extra_config="${extra_config} --with-cpu=${CT_ARCH_CPU}"
131 [ -n "${CT_ARCH_TUNE}" ] && extra_config="${extra_config} --with-tune=${CT_ARCH_TUNE}"
132 [ -n "${CT_ARCH_FPU}" ] && extra_config="${extra_config} --with-fpu=${CT_ARCH_FPU}"
133 [ "${CT_CC_CXA_ATEXIT}" = "y" ] && extra_config="${extra_config} --enable-__cxa_atexit"
135 CT_DoLog DEBUG "Extra config passed: \"${extra_config}\""
137 CFLAGS="${CT_CFLAGS_FOR_HOST}" \
138 "${CT_SRC_DIR}/${CT_CC_FILE}/configure" \
140 --target=${CT_TARGET} \
142 --prefix="${CT_CC_CORE_SHARED_PREFIX_DIR}" \
143 --with-local-prefix="${CT_SYSROOT_DIR}" \
145 ${CC_CORE_SYSROOT_ARG} \
148 --enable-symvers=gnu \
149 --enable-languages=c \
151 ${CT_CC_CORE_EXTRA_CONFIG} 2>&1 |CT_DoLog ALL
153 # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
154 # gcc/config/t-libunwind so -lc is removed from the link for
155 # libgcc_s.so, as we do not have a target -lc yet.
156 # This is not as ugly as it appears to be ;-) All symbols get resolved
157 # during the glibc build, and we provide a proper libgcc_s.so for the
158 # cross toolchain during the final gcc build.
160 # As we cannot modify the source tree, nor override SHLIB_LC itself
161 # during configure or make, we have to edit the resultant
162 # gcc/libgcc.mk itself to remove -lc from the link.
163 # This causes us to have to jump through some hoops...
165 # To produce libgcc.mk to edit we firstly require libiberty.a,
166 # so we configure then build it.
167 # Next we have to configure gcc, create libgcc.mk then edit it...
168 # So much easier if we just edit the source tree, but hey...
169 if [ ! -f "${CT_SRC_DIR}/${CT_CC_FILE}/gcc/BASE-VER" ]; then
170 make configure-libiberty
171 make -C libiberty libiberty.a
173 make configure-libcpp
177 make configure-libcpp
178 make configure-build-libiberty
180 make all-build-libiberty
181 fi 2>&1 |CT_DoLog ALL
182 # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
183 if [ -d "${CT_SRC_DIR}/${CT_CC_FILE}/libdecnumber" ]; then
184 make configure-libdecnumber
185 make -C libdecnumber libdecnumber.a
186 fi 2>&1 |CT_DoLog ALL
187 make -C gcc libgcc.mk 2>&1 |CT_DoLog ALL
188 sed -r -i -e 's@-lc@@g' gcc/libgcc.mk
190 if [ "${CT_CANADIAN}" = "y" ]; then
191 CT_DoLog EXTRA "Building libiberty"
192 make ${PARALLELMFLAGS} all-build-libiberty 2>&1 |CT_DoLog ALL
195 CT_DoLog EXTRA "Building shared core C compiler"
196 make ${PARALLELMFLAGS} all-gcc 2>&1 |CT_DoLog ALL
198 CT_DoLog EXTRA "Installing shared core C compiler"
199 make install-gcc 2>&1 |CT_DoLog ALL
204 #------------------------------------------------------------------------------
207 CT_DoStep INFO "Installing final compiler"
209 mkdir -p "${CT_BUILD_DIR}/build-cc"
210 cd "${CT_BUILD_DIR}/build-cc"
212 CT_DoLog EXTRA "Configuring final compiler"
214 # Enable selected languages
216 [ "${CT_CC_LANG_CXX}" = "y" ] && lang_opt="${lang_opt},c++"
217 [ "${CT_CC_LANG_FORTRAN}" = "y" ] && lang_opt="${lang_opt},fortran"
218 [ "${CT_CC_LANG_ADA}" = "y" ] && lang_opt="${lang_opt},ada"
219 [ "${CT_CC_LANG_JAVA}" = "y" ] && lang_opt="${lang_opt},java"
220 [ "${CT_CC_LANG_OBJC}" = "y" ] && lang_opt="${lang_opt},objc"
221 [ "${CT_CC_LANG_OBJCXX}" = "y" ] && lang_opt="${lang_opt},obj-c++"
222 CT_Test "Building Fortran language is not yet supported. Will try..." "${CT_CC_LANG_FORTRAN}" = "y"
223 CT_Test "Building ADA language is not yet supported. Will try..." "${CT_CC_LANG_ADA}" = "y"
224 CT_Test "Building Java language is not yet supported. Will try..." "${CT_CC_LANG_JAVA}" = "y"
225 CT_Test "Building Objective-C language is not yet supported. Will try..." "${CT_CC_LANG_OBJC}" = "y"
226 CT_Test "Building Objective-C++ language is not yet supported. Will try..." "${CT_CC_LANG_OBJCXX}" = "y"
227 CT_Test "Building ${CT_CC_LANG_OTHERS} language(s) is not yet supported. Will try..." -n "${CT_CC_LANG_OTHERS}"
228 lang_opt=`echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;'`
230 extra_config="--enable-languages=${lang_opt}"
231 [ "${CT_ARCH_FLOAT_SW}" = "y" ] && extra_config="${extra_config} --with-float=soft"
232 [ "${CT_SHARED_LIBS}" = "y" ] || extra_config="${extra_config} --disable-shared"
233 [ -n "${CT_ARCH_ABI}" ] && extra_config="${extra_config} --with-abi=${CT_ARCH_ABI}"
234 [ -n "${CT_ARCH_CPU}" ] && extra_config="${extra_config} --with-cpu=${CT_ARCH_CPU}"
235 [ -n "${CT_ARCH_TUNE}" ] && extra_config="${extra_config} --with-tune=${CT_ARCH_TUNE}"
236 [ -n "${CT_ARCH_ARCH}" ] && extra_config="${extra_config} --with-arch=${CT_ARCH_ARCH}"
237 [ -n "${CT_ARCH_FPU}" ] && extra_config="${extra_config} --with-fpu=${CT_ARCH_FPU}"
238 if [ "${CT_TARGET_MULTILIB}" = "y" ]; then
239 extra_config="${extra_config} --enable-multilib"
241 extra_config="${extra_config} --disable-multilib"
243 [ "${CT_CC_CXA_ATEXIT}" == "y" ] && extra_config="${extra_config} --enable-__cxa_atexit"
245 CT_DoLog DEBUG "Extra config passed: \"${extra_config}\""
247 # --enable-symvers=gnu really only needed for sh4 to work around a
248 # detection problem only matters for gcc-3.2.x and later, I think.
249 # --disable-nls to work around crash bug on ppc405, but also because
250 # embedded systems don't really need message catalogs...
251 CFLAGS="${CT_CFLAGS_FOR_HOST}" \
252 "${CT_SRC_DIR}/${CT_CC_FILE}/configure" \
254 --target=${CT_TARGET} --host=${CT_HOST} \
255 --prefix="${CT_PREFIX_DIR}" \
258 --with-local-prefix="${CT_SYSROOT_DIR}" \
260 --enable-threads=posix \
261 --enable-symvers=gnu \
264 ${CT_CC_EXTRA_CONFIG} 2>&1 |CT_DoLog ALL
266 if [ "${CT_CANADIAN}" = "y" ]; then
267 CT_DoLog EXTRA "Building libiberty"
268 make ${PARALLELMFLAGS} all-build-libiberty 2>&1 |CT_DoLog ALL
272 # Idea from <cort.dougan at gmail.com>:
273 # Fix lib/lib64 confusion for GCC 3.3.3 on PowerPC64 and x86_64.
274 # GCC 3.4.0 and up don't suffer from this confusion, and don't need this
276 # FIXME: we should patch gcc's source rather than uglify crosstool.sh.
277 # FIXME: is this needed for gcc-3.3.[56]?
278 case "${CT_CC_FILE}" in
280 case "${CT_TARGET}" in
281 powerpc64-unknown-linux-gnu|x86_64-unknown-linux-gnu)
282 for d in `find "${CT_SYSROOT_DIR}" -name lib -type d -empty`; do
283 if [ -d `dirname "${d}"`/lib64 ] ; then
285 ln -s `dirname "${d}"`/lib64 "${d}"
292 CT_DoLog EXTRA "Building final compiler"
293 make ${PARALLELMFLAGS} all 2>&1 |CT_DoLog ALL
295 CT_DoLog EXTRA "Installing final compiler"
296 make install 2>&1 |CT_DoLog ALL
298 # FIXME: shouldn't people who want this just --disable-multilib in final gcc
299 # and be done with it?
300 # This code should probably be deleted, it was written long ago and hasn't
301 # been tested in ages.
302 # kludge: If the chip does not have a floating point unit
303 # (i.e. if GLIBC_EXTRA_CONFIG contains --without-fp),
304 # and there are shared libraries in /lib/nof, copy them to /lib
305 # so they get used by default.
306 # FIXME: only rs6000/powerpc seem to use nof. See MULTILIB_DIRNAMES
307 # in $GCC_DIR/gcc/config/$TARGET/* to see what your arch calls it.
308 #case "${CT_LIBC_EXTRA_CONFIG}" in
310 # if test -d "${CT_SYSROOT_DIR}/lib/nof"; then
311 # cp -af "${CT_SYSROOT_DIR}/lib/nof/"*.so* "${CT_SYSROOT_DIR}/lib" || true
316 # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
317 # to call the C compiler with the same, somewhat canonical name.
318 ln "${CT_PREFIX_DIR}/bin/${CT_TARGET}"-{g,}cc