scripts/build/cc_gcc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon Aug 04 12:38:06 2008 +0000 (2008-08-04)
changeset 757 90e887b06da3
parent 740 d26d8cc7c460
child 763 f078be5961ec
permissions -rw-r--r--
Make gcc-4.3.x able to compile uClibc (snapshot only).
Update the gcc patchset accordingly.

/trunk/scripts/build/cc_gcc.sh | 55 53 2 0 ++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 53 insertions(+), 2 deletions(-)
     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 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,http}://ftp.gnu.org/gnu/gcc{,{,/releases}/${CT_CC_FILE}}
    20 }
    21 
    22 # Extract gcc
    23 do_cc_extract() {
    24     CT_ExtractAndPatch "${CT_CC_FILE}"
    25 }
    26 
    27 #------------------------------------------------------------------------------
    28 # Core gcc pass 1
    29 do_cc_core_pass_1() {
    30     # In case we're NPTL, build the static core gcc;
    31     # in any other case, do nothing.
    32     case "${CT_THREADS}" in
    33         nptl)   do_cc_core_static;;
    34     esac
    35 }
    36 
    37 # Core gcc pass 2
    38 do_cc_core_pass_2() {
    39     # In case we're NPTL, build the shared core gcc,
    40     # in any other case, build the static core gcc.
    41     case "${CT_THREADS}" in
    42         nptl)   do_cc_core_shared;;
    43         *)      do_cc_core_static;;
    44     esac
    45 }
    46 
    47 #------------------------------------------------------------------------------
    48 # Build static core gcc
    49 do_cc_core_static() {
    50     mkdir -p "${CT_BUILD_DIR}/build-cc-core-static"
    51     cd "${CT_BUILD_DIR}/build-cc-core-static"
    52 
    53     CT_DoStep INFO "Installing static core C compiler"
    54 
    55     CT_DoLog DEBUG "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
    56     mkdir -p "${CT_CC_CORE_STATIC_PREFIX_DIR}/${CT_TARGET}/include"
    57     cp -r "${CT_HEADERS_DIR}"/* "${CT_CC_CORE_STATIC_PREFIX_DIR}/${CT_TARGET}/include" 2>&1 |CT_DoLog DEBUG
    58 
    59     CT_DoLog EXTRA "Configuring static core C compiler"
    60 
    61     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}"
    62     [ "${CT_GMP_MPFR}" = "y" ] && extra_config="${extra_config} --with-gmp=${CT_PREFIX_DIR} --with-mpfr=${CT_PREFIX_DIR}"
    63     if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
    64         extra_config="${extra_config} --enable-__cxa_atexit"
    65     else
    66         extra_config="${extra_config} --disable-__cxa_atexit"
    67     fi
    68 
    69     CT_DoLog DEBUG "Extra config passed: '${extra_config}'"
    70 
    71     # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
    72     CC_FOR_BUILD="${CT_CC_NATIVE}"                  \
    73     CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
    74     CT_DoExecLog ALL                                \
    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         --enable-target-optspace                    \
    91         ${CT_CC_CORE_EXTRA_CONFIG}
    92 
    93     # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
    94     # gcc/config/t-libunwind so -lc is removed from the link for
    95     # libgcc_s.so, as we do not have a target -lc yet.
    96     # This is not as ugly as it appears to be ;-) All symbols get resolved
    97     # during the glibc build, and we provide a proper libgcc_s.so for the
    98     # cross toolchain during the final gcc build.
    99     #
   100     # As we cannot modify the source tree, nor override SHLIB_LC itself
   101     # during configure or make, we have to edit the resultant
   102     # gcc/libgcc.mk itself to remove -lc from the link.
   103     # This causes us to have to jump through some hoops...
   104     #
   105     # To produce libgcc.mk to edit we firstly require libiberty.a,
   106     # so we configure then build it.
   107     # Next we have to configure gcc, create libgcc.mk then edit it...
   108     # So much easier if we just edit the source tree, but hey...
   109     if [ ! -f "${CT_SRC_DIR}/${CT_CC_FILE}/gcc/BASE-VER" ]; then
   110         CT_DoExecLog ALL make configure-libiberty
   111         CT_DoExecLog ALL make ${PARALLELMFLAGS} -C libiberty libiberty.a
   112         CT_DoExecLog ALL make configure-gcc configure-libcpp
   113         CT_DoExecLog ALL make ${PARALLELMFLAGS} all-libcpp
   114     else
   115         CT_DoExecLog ALL make configure-gcc configure-libcpp configure-build-libiberty
   116         CT_DoExecLog ALL make ${PARALLELMFLAGS} all-libcpp all-build-libiberty
   117     fi
   118     # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
   119     if [ -d "${CT_SRC_DIR}/${CT_CC_FILE}/libdecnumber" ]; then
   120         CT_DoExecLog ALL make configure-libdecnumber
   121         CT_DoExecLog ALL make ${PARALLELMFLAGS} -C libdecnumber libdecnumber.a
   122     fi
   123 
   124     # Starting with GCC 4.3, libgcc.mk is no longer built,
   125     # and libgcc.mvars is used instead.
   126 
   127     gcc_version_major=$(echo ${CT_CC_VERSION} |sed -r -e 's/^([^\.]+)\..*/\1/')
   128     gcc_version_minor=$(echo ${CT_CC_VERSION} |sed -r -e 's/^[^\.]+\.([^.]+).*/\1/')
   129 
   130     if [    ${gcc_version_major} -eq 4 -a ${gcc_version_minor} -ge 3    \
   131          -o ${gcc_version_major} -gt 4                                  ]; then
   132         libgcc_rule="libgcc.mvars"
   133         build_rules="all-gcc all-target-libgcc"
   134         install_rules="install-gcc install-target-libgcc"
   135     else
   136         libgcc_rule="libgcc.mk"
   137         build_rules="all-gcc"
   138         install_rules="install-gcc"
   139     fi
   140 
   141     CT_DoExecLog ALL make ${PARALLELMFLAGS} -C gcc ${libgcc_rule}
   142     sed -r -i -e 's@-lc@@g' gcc/${libgcc_rule}
   143 
   144     if [ "${CT_CANADIAN}" = "y" ]; then
   145         CT_DoLog EXTRA "Building libiberty"
   146         CT_DoExecLog ALL make ${PARALLELMFLAGS} all-build-libiberty
   147     fi
   148 
   149     CT_DoLog EXTRA "Building static core C compiler"
   150     CT_DoExecLog ALL make ${PARALLELMFLAGS} ${build_rules}
   151 
   152     CT_DoLog EXTRA "Installing static core C compiler"
   153     CT_DoExecLog ALL make ${install_rules}
   154 
   155     CT_EndStep
   156 }
   157 
   158 #------------------------------------------------------------------------------
   159 # Build shared core gcc
   160 do_cc_core_shared() {
   161     mkdir -p "${CT_BUILD_DIR}/build-cc-core-shared"
   162     cd "${CT_BUILD_DIR}/build-cc-core-shared"
   163 
   164     CT_DoStep INFO "Installing shared core C compiler"
   165 
   166     CT_DoLog DEBUG "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
   167     mkdir -p "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include"
   168     cp -r "${CT_HEADERS_DIR}"/* "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include" 2>&1 |CT_DoLog DEBUG
   169 
   170     CT_DoLog EXTRA "Configuring shared core C compiler"
   171 
   172     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}"
   173     [ "${CT_GMP_MPFR}" = "y" ] && extra_config="${extra_config} --with-gmp=${CT_PREFIX_DIR} --with-mpfr=${CT_PREFIX_DIR}"
   174     if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
   175         extra_config="${extra_config} --enable-__cxa_atexit"
   176     else
   177         extra_config="${extra_config} --disable-__cxa_atexit"
   178     fi
   179 
   180     CT_DoLog DEBUG "Extra config passed: '${extra_config}'"
   181 
   182     CC_FOR_BUILD="${CT_CC_NATIVE}"                  \
   183     CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
   184     CT_DoExecLog ALL                                \
   185     "${CT_SRC_DIR}/${CT_CC_FILE}/configure"         \
   186         ${CT_CANADIAN_OPT}                          \
   187         --target=${CT_TARGET}                       \
   188         --host=${CT_HOST}                           \
   189         --prefix="${CT_CC_CORE_SHARED_PREFIX_DIR}"  \
   190         --with-local-prefix="${CT_SYSROOT_DIR}"     \
   191         --disable-multilib                          \
   192         ${CC_CORE_SYSROOT_ARG}                      \
   193         ${extra_config}                             \
   194         --disable-nls                               \
   195         --enable-symvers=gnu                        \
   196         --enable-languages=c                        \
   197         --enable-shared                             \
   198         --enable-target-optspace                    \
   199         ${CT_CC_CORE_EXTRA_CONFIG}
   200 
   201     # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
   202     # gcc/config/t-libunwind so -lc is removed from the link for
   203     # libgcc_s.so, as we do not have a target -lc yet.
   204     # This is not as ugly as it appears to be ;-) All symbols get resolved
   205     # during the glibc build, and we provide a proper libgcc_s.so for the
   206     # cross toolchain during the final gcc build.
   207     #
   208     # As we cannot modify the source tree, nor override SHLIB_LC itself
   209     # during configure or make, we have to edit the resultant
   210     # gcc/libgcc.mk itself to remove -lc from the link.
   211     # This causes us to have to jump through some hoops...
   212     #
   213     # To produce libgcc.mk to edit we firstly require libiberty.a,
   214     # so we configure then build it.
   215     # Next we have to configure gcc, create libgcc.mk then edit it...
   216     # So much easier if we just edit the source tree, but hey...
   217     if [ ! -f "${CT_SRC_DIR}/${CT_CC_FILE}/gcc/BASE-VER" ]; then
   218         CT_DoExecLog ALL make configure-libiberty
   219         CT_DoExecLog ALL make ${PARALLELMFLAGS} -C libiberty libiberty.a
   220         CT_DoExecLog ALL make configure-gcc configure-libcpp
   221         CT_DoExecLog ALL make ${PARALLELMFLAGS} all-libcpp
   222     else
   223         CT_DoExecLog ALL make configure-gcc configure-libcpp configure-build-libiberty
   224         CT_DoExecLog ALL make ${PARALLELMFLAGS} all-libcpp all-build-libiberty
   225     fi
   226     # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
   227     if [ -d "${CT_SRC_DIR}/${CT_CC_FILE}/libdecnumber" ]; then
   228         CT_DoExecLog ALL make configure-libdecnumber
   229         CT_DoExecLog ALL make ${PARALLELMFLAGS} -C libdecnumber libdecnumber.a
   230     fi
   231 
   232     # Starting with GCC 4.3, libgcc.mk is no longer built,
   233     # and libgcc.mvars is used instead.
   234 
   235     gcc_version_major=$(echo ${CT_CC_VERSION} |sed -r -e 's/^([^\.]+)\..*/\1/')
   236     gcc_version_minor=$(echo ${CT_CC_VERSION} |sed -r -e 's/^[^\.]+\.([^.]+).*/\1/')
   237 
   238     if [    ${gcc_version_major} -eq 4 -a ${gcc_version_minor} -ge 3    \
   239          -o ${gcc_version_major} -gt 4                                  ]; then
   240         libgcc_rule="libgcc.mvars"
   241         build_rules="all-gcc all-target-libgcc"
   242         install_rules="install-gcc install-target-libgcc"
   243     else
   244         libgcc_rule="libgcc.mk"
   245         build_rules="all-gcc"
   246         install_rules="install-gcc"
   247     fi
   248 
   249     CT_DoExecLog ALL make ${PARALLELMFLAGS} -C gcc ${libgcc_rule}
   250     sed -r -i -e 's@-lc@@g' gcc/${libgcc_rule}
   251 
   252     if [ "${CT_CANADIAN}" = "y" ]; then
   253         CT_DoLog EXTRA "Building libiberty"
   254         CT_DoExecLog ALL make ${PARALLELMFLAGS} all-build-libiberty
   255     fi
   256 
   257     CT_DoLog EXTRA "Building shared core C compiler"
   258     CT_DoExecLog ALL make ${PARALLELMFLAGS} ${build_rules}
   259 
   260     CT_DoLog EXTRA "Installing shared core C compiler"
   261     CT_DoExecLog ALL make ${install_rules}
   262 
   263     CT_EndStep
   264 }
   265 
   266 #------------------------------------------------------------------------------
   267 # Build final gcc
   268 do_cc() {
   269     CT_DoStep INFO "Installing final compiler"
   270 
   271     mkdir -p "${CT_BUILD_DIR}/build-cc"
   272     cd "${CT_BUILD_DIR}/build-cc"
   273 
   274     CT_DoLog EXTRA "Configuring final compiler"
   275 
   276     # Enable selected languages
   277     lang_opt="c"
   278     [ "${CT_CC_LANG_CXX}" = "y"      ] && lang_opt="${lang_opt},c++"
   279     [ "${CT_CC_LANG_FORTRAN}" = "y"  ] && lang_opt="${lang_opt},fortran"
   280     [ "${CT_CC_LANG_ADA}" = "y"      ] && lang_opt="${lang_opt},ada"
   281     [ "${CT_CC_LANG_JAVA}" = "y"     ] && lang_opt="${lang_opt},java"
   282     [ "${CT_CC_LANG_OBJC}" = "y"     ] && lang_opt="${lang_opt},objc"
   283     [ "${CT_CC_LANG_OBJCXX}" = "y"   ] && lang_opt="${lang_opt},obj-c++"
   284     CT_Test "Building ADA language is not yet supported. Will try..." "${CT_CC_LANG_ADA}" = "y"
   285     CT_Test "Building Objective-C language is not yet supported. Will try..." "${CT_CC_LANG_OBJC}" = "y"
   286     CT_Test "Building Objective-C++ language is not yet supported. Will try..." "${CT_CC_LANG_OBJCXX}" = "y"
   287     CT_Test "Building ${CT_CC_LANG_OTHERS//,/ } language(s) is not yet supported. Will try..." -n "${CT_CC_LANG_OTHERS}"
   288     lang_opt=$(echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;')
   289 
   290     extra_config="--enable-languages=${lang_opt}"
   291     extra_config="${extra_config} --disable-multilib"
   292     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}"
   293     [ "${CT_SHARED_LIBS}" = "y" ]     || extra_config="${extra_config} --disable-shared"
   294     [ "${CT_GMP_MPFR}" = "y" ] && extra_config="${extra_config} --with-gmp=${CT_PREFIX_DIR} --with-mpfr=${CT_PREFIX_DIR}"
   295     [ -n "${CT_CC_PKGVERSION}" ]      && extra_config="${extra_config} --with-pkgversion=${CT_CC_PKGVERSION}"
   296     [ -n "${CT_CC_BUGURL}" ]          && extra_config="${extra_config} --with-bugurl=${CT_CC_BUGURL}"
   297     if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
   298         extra_config="${extra_config} --enable-__cxa_atexit"
   299     else
   300         extra_config="${extra_config} --disable-__cxa_atexit"
   301     fi
   302 
   303     CT_DoLog DEBUG "Extra config passed: '${extra_config}'"
   304 
   305     # --enable-symvers=gnu really only needed for sh4 to work around a
   306     # detection problem only matters for gcc-3.2.x and later, I think.
   307     # --disable-nls to work around crash bug on ppc405, but also because
   308     # embedded systems don't really need message catalogs...
   309     CC_FOR_BUILD="${CT_CC_NATIVE}"              \
   310     CFLAGS="${CT_CFLAGS_FOR_HOST}"              \
   311     CFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}"     \
   312     CXXFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}"   \
   313     LDFLAGS_FOR_TARGET="${CT_TARGET_LDFLAGS}"   \
   314     CT_DoExecLog ALL                            \
   315     "${CT_SRC_DIR}/${CT_CC_FILE}/configure"     \
   316         ${CT_CANADIAN_OPT}                      \
   317         --target=${CT_TARGET} --host=${CT_HOST} \
   318         --prefix="${CT_PREFIX_DIR}"             \
   319         ${CC_SYSROOT_ARG}                       \
   320         ${extra_config}                         \
   321         --with-local-prefix="${CT_SYSROOT_DIR}" \
   322         --disable-nls                           \
   323         --enable-threads=posix                  \
   324         --enable-symvers=gnu                    \
   325         --enable-c99                            \
   326         --enable-long-long                      \
   327         --enable-target-optspace                \
   328         ${CT_CC_EXTRA_CONFIG}
   329 
   330     if [ "${CT_CANADIAN}" = "y" ]; then
   331         CT_DoLog EXTRA "Building libiberty"
   332         CT_DoExecLog ALL make ${PARALLELMFLAGS} all-build-libiberty
   333     fi
   334 
   335     CT_DoLog EXTRA "Building final compiler"
   336     CT_DoExecLog ALL make ${PARALLELMFLAGS} all
   337 
   338     CT_DoLog EXTRA "Installing final compiler"
   339     CT_DoExecLog ALL make install
   340 
   341     # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
   342     # to call the C compiler with the same, somewhat canonical name.
   343     ln -sv "${CT_PREFIX_DIR}/bin/${CT_TARGET}"-{g,}cc 2>&1 |CT_DoLog ALL
   344 
   345     CT_EndStep
   346 }