Update all samples to the latest set of options (because so much as changed since we dropped the core C compiler and many obsolete versions).
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 case "${CT_THREADS}" in
35 nptl) do_cc_core_static;;
42 # In case we're NPTL, build the shared core gcc,
43 # in any other case, build the static core gcc.
44 case "${CT_THREADS}" in
45 nptl) do_cc_core_shared;;
46 *) do_cc_core_static;;
50 #------------------------------------------------------------------------------
51 # Build static core gcc
53 mkdir -p "${CT_BUILD_DIR}/build-cc-core-static"
54 cd "${CT_BUILD_DIR}/build-cc-core-static"
56 CT_DoStep INFO "Installing static core C compiler"
58 CT_DoLog EXTRA "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
59 mkdir -p "${CT_CC_CORE_STATIC_PREFIX_DIR}/${CT_TARGET}/include"
60 cp -r "${CT_HEADERS_DIR}"/* "${CT_CC_CORE_STATIC_PREFIX_DIR}/${CT_TARGET}/include" 2>&1 |CT_DoLog DEBUG
62 CT_DoLog EXTRA "Configuring static core C compiler"
65 [ "${CT_ARCH_FLOAT_SW}" = "y" ] && extra_config="${extra_config} --with-float=soft"
66 [ -n "${CT_ARCH_ABI}" ] && extra_config="${extra_config} --with-abi=${CT_ARCH_ABI}"
67 [ -n "${CT_ARCH_ARCH}" ] && extra_config="${extra_config} --with-arch=${CT_ARCH_ARCH}"
68 [ -n "${CT_ARCH_CPU}" ] && extra_config="${extra_config} --with-cpu=${CT_ARCH_CPU}"
69 [ -n "${CT_ARCH_TUNE}" ] && extra_config="${extra_config} --with-tune=${CT_ARCH_TUNE}"
70 [ -n "${CT_ARCH_FPU}" ] && extra_config="${extra_config} --with-fpu=${CT_ARCH_FPU}"
71 [ "${CT_CC_CXA_ATEXIT}" = "y" ] && extra_config="${extra_config} --enable-__cxa_atexit"
73 CT_DoLog DEBUG "Extra config passed: \"${extra_config}\""
75 # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
76 CFLAGS="${CT_CFLAGS_FOR_HOST}" \
77 "${CT_SRC_DIR}/${CT_CC_FILE}/configure" \
80 --target=${CT_TARGET} \
81 --prefix="${CT_CC_CORE_STATIC_PREFIX_DIR}" \
82 --with-local-prefix="${CT_SYSROOT_DIR}" \
85 ${CC_CORE_SYSROOT_ARG} \
89 --enable-symvers=gnu \
90 --enable-languages=c \
92 ${CT_CC_CORE_EXTRA_CONFIG} 2>&1 |CT_DoLog ALL
94 if [ "${CT_CANADIAN}" = "y" ]; then
95 CT_DoLog EXTRA "Building libiberty"
96 make ${PARALLELMFLAGS} all-build-libiberty 2>&1 |CT_DoLog ALL
99 CT_DoLog EXTRA "Building static core C compiler"
100 make ${PARALLELMFLAGS} all-gcc 2>&1 |CT_DoLog ALL
102 CT_DoLog EXTRA "Installing static core C compiler"
103 make install-gcc 2>&1 |CT_DoLog ALL
108 #------------------------------------------------------------------------------
109 # Build shared core gcc
110 do_cc_core_shared() {
111 mkdir -p "${CT_BUILD_DIR}/build-cc-core-shared"
112 cd "${CT_BUILD_DIR}/build-cc-core-shared"
114 CT_DoStep INFO "Installing shared core C compiler"
116 CT_DoLog EXTRA "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
117 mkdir -p "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include"
118 cp -r "${CT_HEADERS_DIR}"/* "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include" 2>&1 |CT_DoLog DEBUG
120 CT_DoLog EXTRA "Configuring shared core C compiler"
123 [ "${CT_ARCH_FLOAT_SW}" = "y" ] && extra_config="${extra_config} --with-float=soft"
124 [ -n "${CT_ARCH_ABI}" ] && extra_config="${extra_config} --with-abi=${CT_ARCH_ABI}"
125 [ -n "${CT_ARCH_ARCH}" ] && extra_config="${extra_config} --with-arch=${CT_ARCH_ARCH}"
126 [ -n "${CT_ARCH_CPU}" ] && extra_config="${extra_config} --with-cpu=${CT_ARCH_CPU}"
127 [ -n "${CT_ARCH_TUNE}" ] && extra_config="${extra_config} --with-tune=${CT_ARCH_TUNE}"
128 [ -n "${CT_ARCH_FPU}" ] && extra_config="${extra_config} --with-fpu=${CT_ARCH_FPU}"
129 [ "${CT_CC_CXA_ATEXIT}" = "y" ] && extra_config="${extra_config} --enable-__cxa_atexit"
131 CT_DoLog DEBUG "Extra config passed: \"${extra_config}\""
133 CFLAGS="${CT_CFLAGS_FOR_HOST}" \
134 "${CT_SRC_DIR}/${CT_CC_FILE}/configure" \
136 --target=${CT_TARGET} \
138 --prefix="${CT_CC_CORE_SHARED_PREFIX_DIR}" \
139 --with-local-prefix="${CT_SYSROOT_DIR}" \
141 ${CC_CORE_SYSROOT_ARG} \
144 --enable-symvers=gnu \
145 --enable-languages=c \
147 ${CT_CC_CORE_EXTRA_CONFIG} 2>&1 |CT_DoLog ALL
149 # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
150 # gcc/config/t-libunwind so -lc is removed from the link for
151 # libgcc_s.so, as we do not have a target -lc yet.
152 # This is not as ugly as it appears to be ;-) All symbols get resolved
153 # during the glibc build, and we provide a proper libgcc_s.so for the
154 # cross toolchain during the final gcc build.
156 # As we cannot modify the source tree, nor override SHLIB_LC itself
157 # during configure or make, we have to edit the resultant
158 # gcc/libgcc.mk itself to remove -lc from the link.
159 # This causes us to have to jump through some hoops...
161 # To produce libgcc.mk to edit we firstly require libiberty.a,
162 # so we configure then build it.
163 # Next we have to configure gcc, create libgcc.mk then edit it...
164 # So much easier if we just edit the source tree, but hey...
165 if [ ! -f "${CT_SRC_DIR}/${CT_CC_FILE}/gcc/BASE-VER" ]; then
166 make configure-libiberty
167 make -C libiberty libiberty.a
169 make configure-libcpp
173 make configure-libcpp
174 make configure-build-libiberty
176 make all-build-libiberty
177 fi 2>&1 |CT_DoLog ALL
178 # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
179 if [ -d "${CT_SRC_DIR}/${CT_CC_FILE}/libdecnumber" ]; then
180 make configure-libdecnumber
181 make -C libdecnumber libdecnumber.a
182 fi 2>&1 |CT_DoLog ALL
183 make -C gcc libgcc.mk 2>&1 |CT_DoLog ALL
184 sed -r -i -e 's@-lc@@g' gcc/libgcc.mk
186 if [ "${CT_CANADIAN}" = "y" ]; then
187 CT_DoLog EXTRA "Building libiberty"
188 make ${PARALLELMFLAGS} all-build-libiberty 2>&1 |CT_DoLog ALL
191 CT_DoLog EXTRA "Building shared core C compiler"
192 make ${PARALLELMFLAGS} all-gcc 2>&1 |CT_DoLog ALL
194 CT_DoLog EXTRA "Installing shared core C compiler"
195 make install-gcc 2>&1 |CT_DoLog ALL
200 #------------------------------------------------------------------------------
203 CT_DoStep INFO "Installing final compiler"
205 mkdir -p "${CT_BUILD_DIR}/build-cc"
206 cd "${CT_BUILD_DIR}/build-cc"
208 CT_DoLog EXTRA "Configuring final compiler"
210 # Enable selected languages
212 [ "${CT_CC_LANG_CXX}" = "y" ] && lang_opt="${lang_opt},c++"
213 [ "${CT_CC_LANG_FORTRAN}" = "y" ] && lang_opt="${lang_opt},fortran"
214 [ "${CT_CC_LANG_ADA}" = "y" ] && lang_opt="${lang_opt},ada"
215 [ "${CT_CC_LANG_JAVA}" = "y" ] && lang_opt="${lang_opt},java"
216 [ "${CT_CC_LANG_OBJC}" = "y" ] && lang_opt="${lang_opt},objc"
217 [ "${CT_CC_LANG_OBJCXX}" = "y" ] && lang_opt="${lang_opt},obj-c++"
218 CT_Test "Building Fortran language is not yet supported. Will try..." "${CT_CC_LANG_FORTRAN}" = "y"
219 CT_Test "Building ADA language is not yet supported. Will try..." "${CT_CC_LANG_ADA}" = "y"
220 CT_Test "Building Java language is not yet supported. Will try..." "${CT_CC_LANG_JAVA}" = "y"
221 CT_Test "Building Objective-C language is not yet supported. Will try..." "${CT_CC_LANG_OBJC}" = "y"
222 CT_Test "Building Objective-C++ language is not yet supported. Will try..." "${CT_CC_LANG_OBJCXX}" = "y"
223 CT_Test "Building ${CT_CC_LANG_OTHERS} language(s) is not yet supported. Will try..." -n "${CT_CC_LANG_OTHERS}"
224 lang_opt=`echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;'`
226 extra_config="--enable-languages=${lang_opt}"
227 [ "${CT_ARCH_FLOAT_SW}" = "y" ] && extra_config="${extra_config} --with-float=soft"
228 [ "${CT_SHARED_LIBS}" = "y" ] || extra_config="${extra_config} --disable-shared"
229 [ -n "${CT_ARCH_ABI}" ] && extra_config="${extra_config} --with-abi=${CT_ARCH_ABI}"
230 [ -n "${CT_ARCH_CPU}" ] && extra_config="${extra_config} --with-cpu=${CT_ARCH_CPU}"
231 [ -n "${CT_ARCH_TUNE}" ] && extra_config="${extra_config} --with-tune=${CT_ARCH_TUNE}"
232 [ -n "${CT_ARCH_ARCH}" ] && extra_config="${extra_config} --with-arch=${CT_ARCH_ARCH}"
233 [ -n "${CT_ARCH_FPU}" ] && extra_config="${extra_config} --with-fpu=${CT_ARCH_FPU}"
234 if [ "${CT_TARGET_MULTILIB}" = "y" ]; then
235 extra_config="${extra_config} --enable-multilib"
237 extra_config="${extra_config} --disable-multilib"
239 [ "${CT_CC_CXA_ATEXIT}" == "y" ] && extra_config="${extra_config} --enable-__cxa_atexit"
241 CT_DoLog DEBUG "Extra config passed: \"${extra_config}\""
243 # --enable-symvers=gnu really only needed for sh4 to work around a
244 # detection problem only matters for gcc-3.2.x and later, I think.
245 # --disable-nls to work around crash bug on ppc405, but also because
246 # embedded systems don't really need message catalogs...
247 CFLAGS="${CT_CFLAGS_FOR_HOST}" \
248 "${CT_SRC_DIR}/${CT_CC_FILE}/configure" \
250 --target=${CT_TARGET} --host=${CT_HOST} \
251 --prefix="${CT_PREFIX_DIR}" \
254 --with-local-prefix="${CT_SYSROOT_DIR}" \
256 --enable-threads=posix \
257 --enable-symvers=gnu \
260 ${CT_CC_EXTRA_CONFIG} 2>&1 |CT_DoLog ALL
262 if [ "${CT_CANADIAN}" = "y" ]; then
263 CT_DoLog EXTRA "Building libiberty"
264 make ${PARALLELMFLAGS} all-build-libiberty 2>&1 |CT_DoLog ALL
268 # Idea from <cort.dougan at gmail.com>:
269 # Fix lib/lib64 confusion for GCC 3.3.3 on PowerPC64 and x86_64.
270 # GCC 3.4.0 and up don't suffer from this confusion, and don't need this
272 # FIXME: we should patch gcc's source rather than uglify crosstool.sh.
273 # FIXME: is this needed for gcc-3.3.[56]?
274 case "${CT_CC_FILE}" in
276 case "${CT_TARGET}" in
277 powerpc64-unknown-linux-gnu|x86_64-unknown-linux-gnu)
278 for d in `find "${CT_SYSROOT_DIR}" -name lib -type d -empty`; do
279 if [ -d `dirname "${d}"`/lib64 ] ; then
281 ln -s `dirname "${d}"`/lib64 "${d}"
288 CT_DoLog EXTRA "Building final compiler"
289 make ${PARALLELMFLAGS} all 2>&1 |CT_DoLog ALL
291 CT_DoLog EXTRA "Installing final compiler"
292 make install 2>&1 |CT_DoLog ALL
294 # FIXME: shouldn't people who want this just --disable-multilib in final gcc
295 # and be done with it?
296 # This code should probably be deleted, it was written long ago and hasn't
297 # been tested in ages.
298 # kludge: If the chip does not have a floating point unit
299 # (i.e. if GLIBC_EXTRA_CONFIG contains --without-fp),
300 # and there are shared libraries in /lib/nof, copy them to /lib
301 # so they get used by default.
302 # FIXME: only rs6000/powerpc seem to use nof. See MULTILIB_DIRNAMES
303 # in $GCC_DIR/gcc/config/$TARGET/* to see what your arch calls it.
304 #case "${CT_LIBC_EXTRA_CONFIG}" in
306 # if test -d "${CT_SYSROOT_DIR}/lib/nof"; then
307 # cp -af "${CT_SYSROOT_DIR}/lib/nof/"*.so* "${CT_SYSROOT_DIR}/lib" || true
312 # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
313 # to call the C compiler with the same, somewhat canonical name.
314 ln "${CT_PREFIX_DIR}/bin/${CT_TARGET}"-{g,}cc