scripts/build/cc_core_gcc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun May 27 20:22:06 2007 +0000 (2007-05-27)
changeset 136 22b5ef41df97
parent 131 5d234d9a257c
child 161 be4484f10ac7
permissions -rw-r--r--
Merge the NPTL stuff.
That still leaves the linuxthreads stuff broken, but it was just before. I don't care anyway. Time to fix that later...
     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 # Download core gcc
     6 do_cc_core_get() {
     7     # Ah! gcc folks are kind of 'different': they store the tarballs in
     8     # subdirectories of the same name! That's because gcc is such /crap/ that
     9     # it is such /big/ that it needs being splitted for distribution! Sad. :-(
    10     # Arrgghh! Some of those versions does not follow this convention:
    11     # gcc-3.3.3 lives in releases/gcc-3.3.3, while gcc-2.95.* isn't in a
    12     # subdirectory! You bastard!
    13     CT_GetFile "${CT_CC_CORE_FILE}"                                    \
    14                ftp://ftp.gnu.org/gnu/gcc/${CT_CC_CORE_FILE}            \
    15                ftp://ftp.gnu.org/gnu/gcc/releases/${CT_CC_CORE_FILE}   \
    16                ftp://ftp.gnu.org/gnu/gcc
    17 }
    18 
    19 # Extract core gcc
    20 do_cc_core_extract() {
    21     CT_ExtractAndPatch "${CT_CC_CORE_FILE}"
    22 }
    23 
    24 # Core gcc pass 1
    25 do_cc_core_pass_1() {
    26     # In case we're NPTL, build the static core gcc;
    27     # in any other case, do nothing.
    28     case "${CT_THREADS}" in
    29         nptl)   do_cc_core_static;;
    30         *)      ;;
    31     esac
    32 }
    33 
    34 # Core gcc pass 2
    35 do_cc_core_pass_2() {
    36     # In case we're NPTL, build the shared core gcc,
    37     # in any other case, build the static core gcc.
    38     case "${CT_THREADS}" in
    39         nptl)   do_cc_core_shared;;
    40         *)      do_cc_core_static;;
    41     esac
    42 }
    43 
    44 # Build static core gcc
    45 do_cc_core_static() {
    46     mkdir -p "${CT_BUILD_DIR}/build-cc-core-static"
    47     cd "${CT_BUILD_DIR}/build-cc-core-static"
    48 
    49     CT_DoStep INFO "Installing static core C compiler"
    50 
    51     CT_DoLog EXTRA "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
    52     mkdir -p "${CT_CC_CORE_STATIC_PREFIX_DIR}/${CT_TARGET}/include"
    53     cp -r "${CT_HEADERS_DIR}"/* "${CT_CC_CORE_STATIC_PREFIX_DIR}/${CT_TARGET}/include" 2>&1 |CT_DoLog DEBUG
    54 
    55     CT_DoLog EXTRA "Configuring static core C compiler"
    56 
    57     extra_config=""
    58     [ "${CT_ARCH_FLOAT_SW}" = "y" ] && extra_config="${extra_config} --with-float=soft"
    59     [ -n "${CT_ARCH_ABI}" ]  && extra_config="${extra_config} --with-abi=${CT_ARCH_ABI}"
    60     [ -n "${CT_ARCH_ARCH}" ] && extra_config="${extra_config} --with-arch=${CT_ARCH_ARCH}"
    61     [ -n "${CT_ARCH_CPU}" ]  && extra_config="${extra_config} --with-cpu=${CT_ARCH_CPU}"
    62     [ -n "${CT_ARCH_TUNE}" ] && extra_config="${extra_config} --with-tune=${CT_ARCH_TUNE}"
    63     [ -n "${CT_ARCH_FPU}" ] && extra_config="${extra_config} --with-fpu=${CT_ARCH_FPU}"
    64     [ "${CT_CC_CXA_ATEXIT}" = "y" ] && extra_config="${extra_config} --enable-__cxa_atexit"
    65 
    66     CT_DoLog DEBUG "Extra config passed: \"${extra_config}\""
    67 
    68     # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
    69     CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
    70     "${CT_SRC_DIR}/${CT_CC_CORE_FILE}/configure"    \
    71         ${CT_CANADIAN_OPT}                          \
    72         --host=${CT_HOST}                           \
    73         --target=${CT_TARGET}                       \
    74         --prefix="${CT_CC_CORE_STATIC_PREFIX_DIR}"  \
    75         --with-local-prefix="${CT_SYSROOT_DIR}"     \
    76         --disable-multilib                          \
    77         --with-newlib                               \
    78         ${CC_CORE_SYSROOT_ARG}                      \
    79         ${extra_config}                             \
    80         --disable-nls                               \
    81         --enable-threads=no                         \
    82         --enable-symvers=gnu                        \
    83         --enable-languages=c                        \
    84         --disable-shared                            \
    85         ${CT_CC_CORE_EXTRA_CONFIG}                  2>&1 |CT_DoLog ALL
    86 
    87     if [ "${CT_CANADIAN}" = "y" ]; then
    88         CT_DoLog EXTRA "Building libiberty"
    89         make ${PARALLELMFLAGS} all-build-libiberty 2>&1 |CT_DoLog ALL
    90     fi
    91 
    92     CT_DoLog EXTRA "Building static core C compiler"
    93     make ${PARALLELMFLAGS} all-gcc 2>&1 |CT_DoLog ALL
    94 
    95     CT_DoLog EXTRA "Installing static core C compiler"
    96     make install-gcc 2>&1 |CT_DoLog ALL
    97 
    98     CT_EndStep
    99 }
   100 
   101 # Build shared core gcc
   102 do_cc_core_shared() {
   103     mkdir -p "${CT_BUILD_DIR}/build-cc-core-shared"
   104     cd "${CT_BUILD_DIR}/build-cc-core-shared"
   105 
   106     CT_DoStep INFO "Installing shared core C compiler"
   107 
   108     CT_DoLog EXTRA "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
   109     mkdir -p "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include"
   110     cp -r "${CT_HEADERS_DIR}"/* "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include" 2>&1 |CT_DoLog DEBUG
   111 
   112     CT_DoLog EXTRA "Configuring shared core C compiler"
   113 
   114     extra_config=""
   115     [ "${CT_ARCH_FLOAT_SW}" = "y" ] && extra_config="${extra_config} --with-float=soft"
   116     [ -n "${CT_ARCH_ABI}" ]  && extra_config="${extra_config} --with-abi=${CT_ARCH_ABI}"
   117     [ -n "${CT_ARCH_ARCH}" ] && extra_config="${extra_config} --with-arch=${CT_ARCH_ARCH}"
   118     [ -n "${CT_ARCH_CPU}" ]  && extra_config="${extra_config} --with-cpu=${CT_ARCH_CPU}"
   119     [ -n "${CT_ARCH_TUNE}" ] && extra_config="${extra_config} --with-tune=${CT_ARCH_TUNE}"
   120     [ -n "${CT_ARCH_FPU}" ] && extra_config="${extra_config} --with-fpu=${CT_ARCH_FPU}"
   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_CORE_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_CORE_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_CORE_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 }