scripts/build/cc_core_gcc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sat Jun 16 21:44:45 2007 +0000 (2007-06-16)
changeset 164 e78c0b2bc057
parent 161 be4484f10ac7
permissions -rw-r--r--
Fix printing components' file names.
     1 # This file adds the function to build the core 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_CORE}" = "gcc" ] || return 0
     7     echo "gcc-${CT_CC_CORE_VERSION}"
     8 }
     9 
    10 # Download core gcc
    11 do_cc_core_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_CORE_FILE}"                                    \
    19                ftp://ftp.gnu.org/gnu/gcc/${CT_CC_CORE_FILE}            \
    20                ftp://ftp.gnu.org/gnu/gcc/releases/${CT_CC_CORE_FILE}   \
    21                ftp://ftp.gnu.org/gnu/gcc
    22 }
    23 
    24 # Extract core gcc
    25 do_cc_core_extract() {
    26     CT_ExtractAndPatch "${CT_CC_CORE_FILE}"
    27 }
    28 
    29 # Core gcc pass 1
    30 do_cc_core_pass_1() {
    31     # In case we're NPTL, build the static core gcc;
    32     # in any other case, do nothing.
    33     case "${CT_THREADS}" in
    34         nptl)   do_cc_core_static;;
    35         *)      ;;
    36     esac
    37 }
    38 
    39 # Core gcc pass 2
    40 do_cc_core_pass_2() {
    41     # In case we're NPTL, build the shared core gcc,
    42     # in any other case, build the static core gcc.
    43     case "${CT_THREADS}" in
    44         nptl)   do_cc_core_shared;;
    45         *)      do_cc_core_static;;
    46     esac
    47 }
    48 
    49 # Build static core gcc
    50 do_cc_core_static() {
    51     mkdir -p "${CT_BUILD_DIR}/build-cc-core-static"
    52     cd "${CT_BUILD_DIR}/build-cc-core-static"
    53 
    54     CT_DoStep INFO "Installing static core C compiler"
    55 
    56     CT_DoLog EXTRA "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
    57     mkdir -p "${CT_CC_CORE_STATIC_PREFIX_DIR}/${CT_TARGET}/include"
    58     cp -r "${CT_HEADERS_DIR}"/* "${CT_CC_CORE_STATIC_PREFIX_DIR}/${CT_TARGET}/include" 2>&1 |CT_DoLog DEBUG
    59 
    60     CT_DoLog EXTRA "Configuring static core C compiler"
    61 
    62     extra_config=""
    63     [ "${CT_ARCH_FLOAT_SW}" = "y" ] && extra_config="${extra_config} --with-float=soft"
    64     [ -n "${CT_ARCH_ABI}" ]  && extra_config="${extra_config} --with-abi=${CT_ARCH_ABI}"
    65     [ -n "${CT_ARCH_ARCH}" ] && extra_config="${extra_config} --with-arch=${CT_ARCH_ARCH}"
    66     [ -n "${CT_ARCH_CPU}" ]  && extra_config="${extra_config} --with-cpu=${CT_ARCH_CPU}"
    67     [ -n "${CT_ARCH_TUNE}" ] && extra_config="${extra_config} --with-tune=${CT_ARCH_TUNE}"
    68     [ -n "${CT_ARCH_FPU}" ] && extra_config="${extra_config} --with-fpu=${CT_ARCH_FPU}"
    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_CORE_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 # Build shared core gcc
   107 do_cc_core_shared() {
   108     mkdir -p "${CT_BUILD_DIR}/build-cc-core-shared"
   109     cd "${CT_BUILD_DIR}/build-cc-core-shared"
   110 
   111     CT_DoStep INFO "Installing shared core C compiler"
   112 
   113     CT_DoLog EXTRA "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
   114     mkdir -p "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include"
   115     cp -r "${CT_HEADERS_DIR}"/* "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include" 2>&1 |CT_DoLog DEBUG
   116 
   117     CT_DoLog EXTRA "Configuring shared core C compiler"
   118 
   119     extra_config=""
   120     [ "${CT_ARCH_FLOAT_SW}" = "y" ] && extra_config="${extra_config} --with-float=soft"
   121     [ -n "${CT_ARCH_ABI}" ]  && extra_config="${extra_config} --with-abi=${CT_ARCH_ABI}"
   122     [ -n "${CT_ARCH_ARCH}" ] && extra_config="${extra_config} --with-arch=${CT_ARCH_ARCH}"
   123     [ -n "${CT_ARCH_CPU}" ]  && extra_config="${extra_config} --with-cpu=${CT_ARCH_CPU}"
   124     [ -n "${CT_ARCH_TUNE}" ] && extra_config="${extra_config} --with-tune=${CT_ARCH_TUNE}"
   125     [ -n "${CT_ARCH_FPU}" ] && extra_config="${extra_config} --with-fpu=${CT_ARCH_FPU}"
   126     [ "${CT_CC_CXA_ATEXIT}" = "y" ] && extra_config="${extra_config} --enable-__cxa_atexit"
   127 
   128     CT_DoLog DEBUG "Extra config passed: \"${extra_config}\""
   129 
   130     CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
   131     "${CT_SRC_DIR}/${CT_CC_CORE_FILE}/configure"    \
   132         ${CT_CANADIAN_OPT}                          \
   133         --target=${CT_TARGET}                       \
   134         --host=${CT_HOST}                           \
   135         --prefix="${CT_CC_CORE_SHARED_PREFIX_DIR}"  \
   136         --with-local-prefix="${CT_SYSROOT_DIR}"     \
   137         --disable-multilib                          \
   138         ${CC_CORE_SYSROOT_ARG}                      \
   139         ${extra_config}                             \
   140         --disable-nls                               \
   141         --enable-symvers=gnu                        \
   142         --enable-languages=c                        \
   143         --enable-shared                             \
   144         ${CT_CC_CORE_EXTRA_CONFIG}                  2>&1 |CT_DoLog ALL
   145 
   146     # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
   147     # gcc/config/t-libunwind so -lc is removed from the link for
   148     # libgcc_s.so, as we do not have a target -lc yet.
   149     # This is not as ugly as it appears to be ;-) All symbols get resolved
   150     # during the glibc build, and we provide a proper libgcc_s.so for the
   151     # cross toolchain during the final gcc build.
   152     #
   153     # As we cannot modify the source tree, nor override SHLIB_LC itself
   154     # during configure or make, we have to edit the resultant
   155     # gcc/libgcc.mk itself to remove -lc from the link.
   156     # This causes us to have to jump through some hoops...
   157     #
   158     # To produce libgcc.mk to edit we firstly require libiberty.a,
   159     # so we configure then build it.
   160     # Next we have to configure gcc, create libgcc.mk then edit it...
   161     # So much easier if we just edit the source tree, but hey...
   162     if [ ! -f "${CT_SRC_DIR}/${CT_CC_CORE_FILE}/gcc/BASE-VER" ]; then
   163         make configure-libiberty
   164         make -C libiberty libiberty.a
   165         make configure-gcc
   166         make configure-libcpp
   167         make all-libcpp
   168     else
   169         make configure-gcc
   170         make configure-libcpp
   171         make configure-build-libiberty
   172         make all-libcpp
   173         make all-build-libiberty
   174     fi 2>&1 |CT_DoLog ALL
   175     # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
   176     if [ -d "${CT_SRC_DIR}/${CT_CC_CORE_FILE}/libdecnumber" ]; then
   177         make configure-libdecnumber
   178         make -C libdecnumber libdecnumber.a
   179     fi 2>&1 |CT_DoLog ALL
   180     make -C gcc libgcc.mk 2>&1 |CT_DoLog ALL
   181     sed -r -i -e 's@-lc@@g' gcc/libgcc.mk
   182 
   183     if [ "${CT_CANADIAN}" = "y" ]; then
   184         CT_DoLog EXTRA "Building libiberty"
   185         make ${PARALLELMFLAGS} all-build-libiberty 2>&1 |CT_DoLog ALL
   186     fi
   187 
   188     CT_DoLog EXTRA "Building shared core C compiler"
   189     make ${PARALLELMFLAGS} all-gcc 2>&1 |CT_DoLog ALL
   190 
   191     CT_DoLog EXTRA "Installing shared core C compiler"
   192     make install-gcc 2>&1 |CT_DoLog ALL
   193 
   194     CT_EndStep
   195 }