scripts/build/cc_gcc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sat Sep 15 21:44:18 2007 +0000 (2007-09-15)
changeset 391 11172b754564
parent 354 cf673077c0c1
child 392 ee71450c5a6f
permissions -rw-r--r--
Further improve the architecture-specific framework.
Apply this framework into building of glibc and gcc.

(Whoo! 500th commit! Yeah!)
     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
     4 
     5 do_print_filename() {
     6     [ "${CT_CC}" = "gcc" ] || return 0
     7     echo "gcc-${CT_CC_VERSION}"
     8 }
     9 
    10 # Download final gcc
    11 do_cc_get() {
    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
    22 }
    23 
    24 # Extract final gcc
    25 do_cc_extract() {
    26     CT_ExtractAndPatch "${CT_CC_FILE}"
    27 }
    28 
    29 #------------------------------------------------------------------------------
    30 # Core gcc pass 1
    31 do_cc_core_pass_1() {
    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";;
    38     esac
    39     CT_EndStep
    40 }
    41 
    42 # Core gcc pass 2
    43 do_cc_core_pass_2() {
    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;;
    50     esac
    51     CT_EndStep
    52 }
    53 
    54 #------------------------------------------------------------------------------
    55 # Build static core gcc
    56 do_cc_core_static() {
    57     mkdir -p "${CT_BUILD_DIR}/build-cc-core-static"
    58     cd "${CT_BUILD_DIR}/build-cc-core-static"
    59 
    60     CT_DoStep INFO "Installing static core C compiler"
    61 
    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
    65 
    66     CT_DoLog EXTRA "Configuring static core C compiler"
    67 
    68     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}"
    69     [ "${CT_CC_CXA_ATEXIT}" = "y" ] && extra_config="${extra_config} --enable-__cxa_atexit"
    70 
    71     CT_DoLog DEBUG "Extra config passed: \"${extra_config}\""
    72 
    73     # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
    74     CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
    75     "${CT_SRC_DIR}/${CT_CC_FILE}/configure"         \
    76         ${CT_CANADIAN_OPT}                          \
    77         --host=${CT_HOST}                           \
    78         --target=${CT_TARGET}                       \
    79         --prefix="${CT_CC_CORE_STATIC_PREFIX_DIR}"  \
    80         --with-local-prefix="${CT_SYSROOT_DIR}"     \
    81         --disable-multilib                          \
    82         --with-newlib                               \
    83         ${CC_CORE_SYSROOT_ARG}                      \
    84         ${extra_config}                             \
    85         --disable-nls                               \
    86         --enable-threads=no                         \
    87         --enable-symvers=gnu                        \
    88         --enable-languages=c                        \
    89         --disable-shared                            \
    90         ${CT_CC_CORE_EXTRA_CONFIG}                  2>&1 |CT_DoLog ALL
    91 
    92     if [ "${CT_CANADIAN}" = "y" ]; then
    93         CT_DoLog EXTRA "Building libiberty"
    94         make ${PARALLELMFLAGS} all-build-libiberty 2>&1 |CT_DoLog ALL
    95     fi
    96 
    97     CT_DoLog EXTRA "Building static core C compiler"
    98     make ${PARALLELMFLAGS} all-gcc 2>&1 |CT_DoLog ALL
    99 
   100     CT_DoLog EXTRA "Installing static core C compiler"
   101     make install-gcc 2>&1 |CT_DoLog ALL
   102 
   103     CT_EndStep
   104 }
   105 
   106 #------------------------------------------------------------------------------
   107 # Build shared core gcc
   108 do_cc_core_shared() {
   109     mkdir -p "${CT_BUILD_DIR}/build-cc-core-shared"
   110     cd "${CT_BUILD_DIR}/build-cc-core-shared"
   111 
   112     CT_DoStep INFO "Installing shared core C compiler"
   113 
   114     CT_DoLog EXTRA "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
   115     mkdir -p "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include"
   116     cp -r "${CT_HEADERS_DIR}"/* "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include" 2>&1 |CT_DoLog DEBUG
   117 
   118     CT_DoLog EXTRA "Configuring shared core C compiler"
   119 
   120     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}"
   121     [ "${CT_CC_CXA_ATEXIT}" = "y" ] && extra_config="${extra_config} --enable-__cxa_atexit"
   122 
   123     CT_DoLog DEBUG "Extra config passed: \"${extra_config}\""
   124 
   125     CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
   126     "${CT_SRC_DIR}/${CT_CC_FILE}/configure"         \
   127         ${CT_CANADIAN_OPT}                          \
   128         --target=${CT_TARGET}                       \
   129         --host=${CT_HOST}                           \
   130         --prefix="${CT_CC_CORE_SHARED_PREFIX_DIR}"  \
   131         --with-local-prefix="${CT_SYSROOT_DIR}"     \
   132         --disable-multilib                          \
   133         ${CC_CORE_SYSROOT_ARG}                      \
   134         ${extra_config}                             \
   135         --disable-nls                               \
   136         --enable-symvers=gnu                        \
   137         --enable-languages=c                        \
   138         --enable-shared                             \
   139         ${CT_CC_CORE_EXTRA_CONFIG}                  2>&1 |CT_DoLog ALL
   140 
   141     # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
   142     # gcc/config/t-libunwind so -lc is removed from the link for
   143     # libgcc_s.so, as we do not have a target -lc yet.
   144     # This is not as ugly as it appears to be ;-) All symbols get resolved
   145     # during the glibc build, and we provide a proper libgcc_s.so for the
   146     # cross toolchain during the final gcc build.
   147     #
   148     # As we cannot modify the source tree, nor override SHLIB_LC itself
   149     # during configure or make, we have to edit the resultant
   150     # gcc/libgcc.mk itself to remove -lc from the link.
   151     # This causes us to have to jump through some hoops...
   152     #
   153     # To produce libgcc.mk to edit we firstly require libiberty.a,
   154     # so we configure then build it.
   155     # Next we have to configure gcc, create libgcc.mk then edit it...
   156     # So much easier if we just edit the source tree, but hey...
   157     if [ ! -f "${CT_SRC_DIR}/${CT_CC_FILE}/gcc/BASE-VER" ]; then
   158         make configure-libiberty
   159         make -C libiberty libiberty.a
   160         make configure-gcc
   161         make configure-libcpp
   162         make all-libcpp
   163     else
   164         make configure-gcc
   165         make configure-libcpp
   166         make configure-build-libiberty
   167         make all-libcpp
   168         make all-build-libiberty
   169     fi 2>&1 |CT_DoLog ALL
   170     # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
   171     if [ -d "${CT_SRC_DIR}/${CT_CC_FILE}/libdecnumber" ]; then
   172         make configure-libdecnumber
   173         make -C libdecnumber libdecnumber.a
   174     fi 2>&1 |CT_DoLog ALL
   175     make -C gcc libgcc.mk 2>&1 |CT_DoLog ALL
   176     sed -r -i -e 's@-lc@@g' gcc/libgcc.mk
   177 
   178     if [ "${CT_CANADIAN}" = "y" ]; then
   179         CT_DoLog EXTRA "Building libiberty"
   180         make ${PARALLELMFLAGS} all-build-libiberty 2>&1 |CT_DoLog ALL
   181     fi
   182 
   183     CT_DoLog EXTRA "Building shared core C compiler"
   184     make ${PARALLELMFLAGS} all-gcc 2>&1 |CT_DoLog ALL
   185 
   186     CT_DoLog EXTRA "Installing shared core C compiler"
   187     make install-gcc 2>&1 |CT_DoLog ALL
   188 
   189     CT_EndStep
   190 }
   191 
   192 #------------------------------------------------------------------------------
   193 # Build final gcc
   194 do_cc() {
   195     CT_DoStep INFO "Installing final compiler"
   196 
   197     mkdir -p "${CT_BUILD_DIR}/build-cc"
   198     cd "${CT_BUILD_DIR}/build-cc"
   199 
   200     CT_DoLog EXTRA "Configuring final compiler"
   201 
   202     # Enable selected languages
   203     lang_opt="c"
   204     [ "${CT_CC_LANG_CXX}" = "y"      ] && lang_opt="${lang_opt},c++"
   205     [ "${CT_CC_LANG_FORTRAN}" = "y"  ] && lang_opt="${lang_opt},fortran"
   206     [ "${CT_CC_LANG_ADA}" = "y"      ] && lang_opt="${lang_opt},ada"
   207     [ "${CT_CC_LANG_JAVA}" = "y"     ] && lang_opt="${lang_opt},java"
   208     [ "${CT_CC_LANG_OBJC}" = "y"     ] && lang_opt="${lang_opt},objc"
   209     [ "${CT_CC_LANG_OBJCXX}" = "y"   ] && lang_opt="${lang_opt},obj-c++"
   210     CT_Test "Building Fortran language is not yet supported. Will try..." "${CT_CC_LANG_FORTRAN}" = "y"
   211     CT_Test "Building ADA language is not yet supported. Will try..." "${CT_CC_LANG_ADA}" = "y"
   212     CT_Test "Building Java language is not yet supported. Will try..." "${CT_CC_LANG_JAVA}" = "y"
   213     CT_Test "Building Objective-C language is not yet supported. Will try..." "${CT_CC_LANG_OBJC}" = "y"
   214     CT_Test "Building Objective-C++ language is not yet supported. Will try..." "${CT_CC_LANG_OBJCXX}" = "y"
   215     CT_Test "Building ${CT_CC_LANG_OTHERS} language(s) is not yet supported. Will try..." -n "${CT_CC_LANG_OTHERS}"
   216     lang_opt=`echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;'`
   217 
   218     extra_config="--enable-languages=${lang_opt}"
   219     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}"
   220     [ "${CT_SHARED_LIBS}" = "y" ] || extra_config="${extra_config} --disable-shared"
   221     [ "${CT_CC_CXA_ATEXIT}" == "y" ] && extra_config="${extra_config} --enable-__cxa_atexit"
   222 
   223     CT_DoLog DEBUG "Extra config passed: \"${extra_config}\""
   224 
   225     # --enable-symvers=gnu really only needed for sh4 to work around a
   226     # detection problem only matters for gcc-3.2.x and later, I think.
   227     # --disable-nls to work around crash bug on ppc405, but also because
   228     # embedded systems don't really need message catalogs...
   229     CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
   230     "${CT_SRC_DIR}/${CT_CC_FILE}/configure"     \
   231         ${CT_CANADIAN_OPT}                      \
   232         --target=${CT_TARGET} --host=${CT_HOST} \
   233         --prefix="${CT_PREFIX_DIR}"             \
   234         ${CC_SYSROOT_ARG}                       \
   235         ${extra_config}                         \
   236         --with-local-prefix="${CT_SYSROOT_DIR}" \
   237         --disable-nls                           \
   238         --enable-threads=posix                  \
   239         --enable-symvers=gnu                    \
   240         --enable-c99                            \
   241         --enable-long-long                      \
   242         ${CT_CC_EXTRA_CONFIG}                   2>&1 |CT_DoLog ALL
   243 
   244     if [ "${CT_CANADIAN}" = "y" ]; then
   245         CT_DoLog EXTRA "Building libiberty"
   246         make ${PARALLELMFLAGS} all-build-libiberty 2>&1 |CT_DoLog ALL
   247     fi
   248 
   249     # Idea from <cort.dougan at gmail.com>:
   250     # Fix lib/lib64 confusion for GCC 3.3.3 on PowerPC64 and x86_64.
   251     # GCC 3.4.0 and up don't suffer from this confusion, and don't need this
   252     # kludge.
   253     # FIXME: we should patch gcc's source rather than uglify crosstool.sh.
   254     # FIXME: is this needed for gcc-3.3.[56]?
   255     case "${CT_CC_FILE}" in
   256       gcc-3.3.[34])
   257         case "${CT_TARGET}" in
   258           powerpc64-unknown-linux-gnu|x86_64-unknown-linux-gnu)
   259             for d in `find "${CT_SYSROOT_DIR}" -name lib -type d -empty`; do
   260               if [ -d `dirname "${d}"`/lib64 ] ; then
   261                 rm -rf "${d}"
   262                 ln -s `dirname "${d}"`/lib64 "${d}"
   263               fi
   264             done ;;
   265           *) ;;
   266         esac ;;
   267     esac
   268 
   269     CT_DoLog EXTRA "Building final compiler"
   270     make ${PARALLELMFLAGS} all 2>&1 |CT_DoLog ALL
   271 
   272     CT_DoLog EXTRA "Installing final compiler"
   273     make install 2>&1 |CT_DoLog ALL
   274 
   275     # FIXME: shouldn't people who want this just --disable-multilib in final gcc
   276     # and be done with it?
   277     # This code should probably be deleted, it was written long ago and hasn't
   278     # been tested in ages.
   279     # kludge: If the chip does not have a floating point unit
   280     # (i.e. if GLIBC_EXTRA_CONFIG contains --without-fp),
   281     # and there are shared libraries in /lib/nof, copy them to /lib
   282     # so they get used by default.
   283     # FIXME: only rs6000/powerpc seem to use nof.  See MULTILIB_DIRNAMES
   284     # in $GCC_DIR/gcc/config/$TARGET/* to see what your arch calls it.
   285     #case "${CT_LIBC_EXTRA_CONFIG}" in
   286     #    *--without-fp*)
   287     #        if test -d "${CT_SYSROOT_DIR}/lib/nof"; then
   288     #            cp -af "${CT_SYSROOT_DIR}/lib/nof/"*.so* "${CT_SYSROOT_DIR}/lib" || true
   289     #        fi
   290     #    ;;
   291     #esac
   292 
   293     # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
   294     # to call the C compiler with the same, somewhat canonical name.
   295     ln "${CT_PREFIX_DIR}/bin/${CT_TARGET}"-{g,}cc
   296 
   297     CT_EndStep
   298 }