scripts/build/cc/gcc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Thu Mar 26 18:58:13 2009 +0000 (2009-03-26)
changeset 1269 17e37102a037
parent 1268 5594b05bc2d8
child 1389 fbaee258bfea
permissions -rw-r--r--
Merge r1432:1437 from /branches/newlib into /trunk :
- under bare-metal, the user is responsible for providing a gdbserver stub (r1433)
- install a CT_TARGET-cc -> CT_TARGET-gcc symlink for the core gcc (r1434)
- allow broader dependency in generated config files (r1435, r1436)
- prepare C library menuconfig for using a C library under bare-metal (r1437)

/trunk/scripts/build/cc/gcc.sh | 4 4 0 0 ++++
/trunk/config/debug/gdb.in | 5 5 0 0 +++++
/trunk/config/libc/glibc.in | 1 1 0 0 +
/trunk/config/libc/uClibc.in | 1 1 0 0 +
/trunk/config/libc/eglibc.in | 2 1 1 0 +-
/trunk/config/config.mk | 20 8 12 0 ++++++++------------
/trunk/config/arch/sh.in | 2 1 1 0 +-
/trunk/config/arch/ia64.in | 2 1 1 0 +-
/trunk/config/arch/powerpc64.in | 2 1 1 0 +-
/trunk/config/libc.in | 4 0 4 0 ----
10 files changed, 23 insertions(+), 20 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 # Download gcc
     6 do_cc_get() {
     7     local version="${CT_CC_VERSION}${CT_CC_GCC_4_4_snapshot_date}"
     8 
     9     # Ah! gcc folks are kind of 'different': they store the tarballs in
    10     # subdirectories of the same name! That's because gcc is such /crap/ that
    11     # it is such /big/ that it needs being splitted for distribution! Sad. :-(
    12     # Arrgghh! Some of those versions does not follow this convention:
    13     # gcc-3.3.3 lives in releases/gcc-3.3.3, while gcc-2.95.* isn't in a
    14     # subdirectory! You bastard!
    15     CT_GetFile "gcc-${version}"                                                         \
    16                {ftp,http}://ftp.gnu.org/gnu/gcc{,{,/releases}/gcc-${version}}           \
    17                ftp://ftp.irisa.fr/pub/mirrors/gcc.gnu.org/gcc/releases/gcc-${version}   \
    18                ftp://ftp.uvsq.fr/pub/gcc/snapshots/${version}
    19 
    20     # Starting with GCC 4.3, ecj is used for Java, and will only be
    21     # built if the configure script finds ecj.jar at the top of the
    22     # GCC source tree, which will not be there unless we get it and
    23     # put it there ourselves
    24     if [ "${CT_CC_LANG_JAVA_USE_ECJ}" = "y" ]; then
    25         CT_GetFile ecj-latest .jar ftp://gcc.gnu.org/pub/java   \
    26                                    ftp://sourceware.org/pub/java
    27     fi
    28 }
    29 
    30 # Extract gcc
    31 do_cc_extract() {
    32     local version="${CT_CC_VERSION}${CT_CC_GCC_4_4_snapshot_date}"
    33 
    34     CT_Extract "gcc-${version}"
    35     CT_Patch "gcc-${version}"
    36 
    37     # Copy ecj-latest.jar to ecj.jar at the top of the GCC source tree
    38     if [ "${CT_CC_LANG_JAVA_USE_ECJ}" = "y"             \
    39          -a ! -f "${CT_SRC_DIR}/gcc-${version}/ecj.jar" \
    40        ]; then
    41         CT_DoExecLog ALL cp -v "${CT_TARBALLS_DIR}/ecj-latest.jar" "${CT_SRC_DIR}/gcc-${version}/ecj.jar"
    42     fi
    43 }
    44 
    45 #------------------------------------------------------------------------------
    46 # Core gcc pass 1
    47 do_cc_core_pass_1() {
    48     # If we're building for bare metal, build the static core gcc,
    49     # with libgcc.
    50     # In case we're not bare metal, and we're NPTL, build the static core gcc.
    51     # In any other case, do nothing.
    52     case "${CT_BARE_METAL},${CT_THREADS}" in
    53         y,*)    do_cc_core mode=baremetal build_libgcc=yes;;
    54         ,nptl)  do_cc_core mode=static build_libgcc=no;;
    55         *)      ;;
    56     esac
    57 }
    58 
    59 # Core gcc pass 2
    60 do_cc_core_pass_2() {
    61     # In case we're building for bare metal, do nothing, we already have
    62     # our compiler.
    63     # In case we're NPTL, build the shared core gcc and the target libgcc.
    64     # In any other case, build the static core gcc and, if using gcc-4.3+,
    65     # also build the target libgcc.
    66     case "${CT_BARE_METAL},${CT_THREADS}" in
    67         y,*)    ;;
    68         ,nptl)
    69             do_cc_core mode=shared build_libgcc=yes
    70             ;;
    71         *)  if [ "${CT_CC_GCC_4_3_or_later}" = "y" ]; then
    72                 do_cc_core mode=static build_libgcc=yes
    73             else
    74                 do_cc_core mode=static build_libgcc=no
    75             fi
    76             ;;
    77     esac
    78 }
    79 
    80 #------------------------------------------------------------------------------
    81 # Build core gcc
    82 # This function is used to build both the static and the shared core C conpiler,
    83 # with or without the target libgcc. We need to know wether:
    84 #  - we're building static, shared or bare metal: mode=[static|shared|baremetal]
    85 #  - we need to build libgcc or not             : build_libgcc=[yes|no]
    86 # Usage: do_cc_core_static mode=[static|shared|baremetal] build_libgcc=[yes|no]
    87 do_cc_core() {
    88     local mode
    89     local build_libgcc
    90     local core_prefix_dir
    91     local extra_config
    92     local lang_opt
    93     local version="${CT_CC_VERSION}${CT_CC_GCC_4_4_snapshot_date}"
    94 
    95     eval $1
    96     eval $2
    97     CT_TestOrAbort "Internal Error: 'mode' must either 'static', 'shared' or 'baremetal', not '${mode:-(empty)}'" "${mode}" = "static" -o "${mode}" = "shared" -o "${mode}" = "baremetal"
    98     CT_TestOrAbort "Internal Error: 'build_libgcc' must be either 'yes' or 'no', not '${build_libgcc:-(empty)}'" "${build_libgcc}" = "yes" -o "${build_libgcc}" = "no"
    99     # In normal conditions, ( "${mode}" = "shared" ) implies
   100     # ( "${build_libgcc}" = "yes" ), but I won't check for that
   101 
   102     CT_DoStep INFO "Installing ${mode} core C compiler"
   103     mkdir -p "${CT_BUILD_DIR}/build-cc-core-${mode}"
   104     cd "${CT_BUILD_DIR}/build-cc-core-${mode}"
   105 
   106     lang_opt=c
   107     case "${mode}" in
   108         static)
   109             core_prefix_dir="${CT_CC_CORE_STATIC_PREFIX_DIR}"
   110             extra_config="${extra_config} --with-newlib --enable-threads=no --disable-shared"
   111             copy_headers=y
   112             ;;
   113         shared)
   114             core_prefix_dir="${CT_CC_CORE_SHARED_PREFIX_DIR}"
   115             extra_config="${extra_config} --enable-shared"
   116             copy_headers=y
   117             ;;
   118         baremetal)
   119             core_prefix_dir="${CT_PREFIX_DIR}"
   120             extra_config="${extra_config} --with-newlib --enable-threads=no --disable-shared"
   121             [ "${CT_CC_LANG_CXX}" = "y" ] && lang_opt="${lang_opt},c++"
   122             copy_headers=n
   123             ;;
   124     esac
   125 
   126     if [ "${copy_headers}" = "y" ]; then
   127         CT_DoLog DEBUG "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
   128         CT_DoExecLog ALL mkdir -p "${core_prefix_dir}/${CT_TARGET}/include"
   129         CT_DoExecLog ALL cp -r "${CT_HEADERS_DIR}"/* "${core_prefix_dir}/${CT_TARGET}/include"
   130     fi
   131 
   132     CT_DoLog EXTRA "Configuring ${mode} core C compiler"
   133 
   134     extra_config="${extra_config} ${CT_ARCH_WITH_ARCH}"
   135     extra_config="${extra_config} ${CT_ARCH_WITH_ABI}"
   136     extra_config="${extra_config} ${CT_ARCH_WITH_CPU}"
   137     extra_config="${extra_config} ${CT_ARCH_WITH_TUNE}"
   138     extra_config="${extra_config} ${CT_ARCH_WITH_FPU}"
   139     extra_config="${extra_config} ${CT_ARCH_WITH_FLOAT}"
   140     [ "${CT_GMP_MPFR}" = "y" ] && extra_config="${extra_config} --with-gmp=${CT_PREFIX_DIR} --with-mpfr=${CT_PREFIX_DIR}"
   141     if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
   142         extra_config="${extra_config} --enable-__cxa_atexit"
   143     else
   144         extra_config="${extra_config} --disable-__cxa_atexit"
   145     fi
   146 
   147     CT_DoLog DEBUG "Extra config passed: '${extra_config}'"
   148 
   149     # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
   150     CC_FOR_BUILD="${CT_BUILD}-gcc"                  \
   151     CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
   152     CT_DoExecLog ALL                                \
   153     "${CT_SRC_DIR}/gcc-${version}/configure"        \
   154         --build=${CT_BUILD}                         \
   155         --host=${CT_HOST}                           \
   156         --target=${CT_TARGET}                       \
   157         --prefix="${core_prefix_dir}"               \
   158         --with-local-prefix="${CT_SYSROOT_DIR}"     \
   159         --disable-multilib                          \
   160         ${CC_CORE_SYSROOT_ARG}                      \
   161         ${extra_config}                             \
   162         --disable-nls                               \
   163         --enable-symvers=gnu                        \
   164         --enable-languages="${lang_opt}"            \
   165         --enable-target-optspace                    \
   166         ${CT_CC_CORE_EXTRA_CONFIG}
   167 
   168     if [ "${build_libgcc}" = "yes" ]; then
   169         # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
   170         # gcc/config/t-libunwind so -lc is removed from the link for
   171         # libgcc_s.so, as we do not have a target -lc yet.
   172         # This is not as ugly as it appears to be ;-) All symbols get resolved
   173         # during the glibc build, and we provide a proper libgcc_s.so for the
   174         # cross toolchain during the final gcc build.
   175         #
   176         # As we cannot modify the source tree, nor override SHLIB_LC itself
   177         # during configure or make, we have to edit the resultant
   178         # gcc/libgcc.mk itself to remove -lc from the link.
   179         # This causes us to have to jump through some hoops...
   180         #
   181         # To produce libgcc.mk to edit we firstly require libiberty.a,
   182         # so we configure then build it.
   183         # Next we have to configure gcc, create libgcc.mk then edit it...
   184         # So much easier if we just edit the source tree, but hey...
   185         if [ ! -f "${CT_SRC_DIR}/gcc-${version}/gcc/BASE-VER" ]; then
   186             CT_DoExecLog ALL make configure-libiberty
   187             CT_DoExecLog ALL make ${PARALLELMFLAGS} -C libiberty libiberty.a
   188             CT_DoExecLog ALL make configure-gcc configure-libcpp
   189             CT_DoExecLog ALL make ${PARALLELMFLAGS} all-libcpp
   190         else
   191             CT_DoExecLog ALL make configure-gcc configure-libcpp configure-build-libiberty
   192             CT_DoExecLog ALL make ${PARALLELMFLAGS} all-libcpp all-build-libiberty
   193         fi
   194         # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
   195         if [ -d "${CT_SRC_DIR}/gcc-${version}/libdecnumber" ]; then
   196             CT_DoExecLog ALL make configure-libdecnumber
   197             CT_DoExecLog ALL make ${PARALLELMFLAGS} -C libdecnumber libdecnumber.a
   198         fi
   199 
   200         # Starting with GCC 4.3, libgcc.mk is no longer built,
   201         # and libgcc.mvars is used instead.
   202 
   203         if [ "${CT_CC_GCC_4_3_or_later}" = "y" ]; then
   204             libgcc_rule="libgcc.mvars"
   205             build_rules="all-gcc all-target-libgcc"
   206             install_rules="install-gcc install-target-libgcc"
   207         else
   208             libgcc_rule="libgcc.mk"
   209             build_rules="all-gcc"
   210             install_rules="install-gcc"
   211         fi
   212 
   213         CT_DoExecLog ALL make ${PARALLELMFLAGS} -C gcc ${libgcc_rule}
   214         sed -r -i -e 's@-lc@@g' gcc/${libgcc_rule}
   215     else # build_libgcc
   216             build_rules="all-gcc"
   217             install_rules="install-gcc"
   218     fi   # ! build libgcc
   219 
   220     if [ "${CT_CANADIAN}" = "y" ]; then
   221         CT_DoLog EXTRA "Building libiberty"
   222         CT_DoExecLog ALL make ${PARALLELMFLAGS} all-build-libiberty
   223     fi
   224 
   225     CT_DoLog EXTRA "Building ${mode} core C compiler"
   226     CT_DoExecLog ALL make ${PARALLELMFLAGS} ${build_rules}
   227 
   228     CT_DoLog EXTRA "Installing ${mode} core C compiler"
   229     CT_DoExecLog ALL make ${install_rules}
   230 
   231     # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
   232     # to call the C compiler with the same, somewhat canonical name.
   233     CT_DoExecLog ALL ln -sv "${CT_TARGET}"-gcc "${core_prefix_dir}/bin/${CT_TARGET}"-cc
   234 
   235     CT_EndStep
   236 }
   237 
   238 #------------------------------------------------------------------------------
   239 # Build final gcc
   240 do_cc() {
   241     local version="${CT_CC_VERSION}${CT_CC_GCC_4_4_snapshot_date}"
   242 
   243     # If building for bare metal, nothing to be done here, the static core conpiler is enough!
   244     [ "${CT_BARE_METAL}" = "y" ] && return 0
   245 
   246     CT_DoStep INFO "Installing final compiler"
   247 
   248     mkdir -p "${CT_BUILD_DIR}/build-cc"
   249     cd "${CT_BUILD_DIR}/build-cc"
   250 
   251     CT_DoLog EXTRA "Configuring final compiler"
   252 
   253     # Enable selected languages
   254     lang_opt="c"
   255     [ "${CT_CC_LANG_CXX}" = "y"      ] && lang_opt="${lang_opt},c++"
   256     [ "${CT_CC_LANG_FORTRAN}" = "y"  ] && lang_opt="${lang_opt},fortran"
   257     [ "${CT_CC_LANG_ADA}" = "y"      ] && lang_opt="${lang_opt},ada"
   258     [ "${CT_CC_LANG_JAVA}" = "y"     ] && lang_opt="${lang_opt},java"
   259     [ "${CT_CC_LANG_OBJC}" = "y"     ] && lang_opt="${lang_opt},objc"
   260     [ "${CT_CC_LANG_OBJCXX}" = "y"   ] && lang_opt="${lang_opt},obj-c++"
   261     CT_Test "Building ADA language is not yet supported. Will try..." "${CT_CC_LANG_ADA}" = "y"
   262     CT_Test "Building Objective-C language is not yet supported. Will try..." "${CT_CC_LANG_OBJC}" = "y"
   263     CT_Test "Building Objective-C++ language is not yet supported. Will try..." "${CT_CC_LANG_OBJCXX}" = "y"
   264     CT_Test "Building ${CT_CC_LANG_OTHERS//,/ } language(s) is not yet supported. Will try..." -n "${CT_CC_LANG_OTHERS}"
   265     lang_opt=$(echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;')
   266 
   267     extra_config="--enable-languages=${lang_opt}"
   268     extra_config="${extra_config} --disable-multilib"
   269     extra_config="${extra_config} ${CT_ARCH_WITH_ARCH}"
   270     extra_config="${extra_config} ${CT_ARCH_WITH_ABI}"
   271     extra_config="${extra_config} ${CT_ARCH_WITH_CPU}"
   272     extra_config="${extra_config} ${CT_ARCH_WITH_TUNE}"
   273     extra_config="${extra_config} ${CT_ARCH_WITH_FPU}"
   274     extra_config="${extra_config} ${CT_ARCH_WITH_FLOAT}"
   275     [ "${CT_SHARED_LIBS}" = "y" ]                   || extra_config="${extra_config} --disable-shared"
   276     [ "${CT_GMP_MPFR}" = "y" ]                      && extra_config="${extra_config} --with-gmp=${CT_PREFIX_DIR} --with-mpfr=${CT_PREFIX_DIR}"
   277     [ -n "${CT_CC_PKGVERSION}" ]                    && extra_config="${extra_config} --with-pkgversion=${CT_CC_PKGVERSION}"
   278     [ -n "${CT_CC_BUGURL}" ]                        && extra_config="${extra_config} --with-bugurl=${CT_CC_BUGURL}"
   279     [ "${CT_CC_SJLJ_EXCEPTIONS_USE}" = "y" ]        && extra_config="${extra_config} --enable-sjlj-exceptions"
   280     [ "${CT_CC_SJLJ_EXCEPTIONS_DONT_USE}" = "y" ]   && extra_config="${extra_config} --disable-sjlj-exceptions"
   281     if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
   282         extra_config="${extra_config} --enable-__cxa_atexit"
   283     else
   284         extra_config="${extra_config} --disable-__cxa_atexit"
   285     fi
   286 
   287     CT_DoLog DEBUG "Extra config passed: '${extra_config}'"
   288 
   289     # --enable-symvers=gnu really only needed for sh4 to work around a
   290     # detection problem only matters for gcc-3.2.x and later, I think.
   291     # --disable-nls to work around crash bug on ppc405, but also because
   292     # embedded systems don't really need message catalogs...
   293     CC_FOR_BUILD="${CT_BUILD}-gcc"                  \
   294     CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
   295     CFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}"         \
   296     CXXFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}"       \
   297     LDFLAGS_FOR_TARGET="${CT_TARGET_LDFLAGS}"       \
   298     CT_DoExecLog ALL                                \
   299     "${CT_SRC_DIR}/gcc-${version}/configure"        \
   300         --build=${CT_BUILD}                         \
   301         --host=${CT_HOST}                           \
   302         --target=${CT_TARGET}                       \
   303         --prefix="${CT_PREFIX_DIR}"                 \
   304         ${CC_SYSROOT_ARG}                           \
   305         ${extra_config}                             \
   306         --with-local-prefix="${CT_SYSROOT_DIR}"     \
   307         --disable-nls                               \
   308         --enable-threads=posix                      \
   309         --enable-symvers=gnu                        \
   310         --enable-c99                                \
   311         --enable-long-long                          \
   312         --enable-target-optspace                    \
   313         ${CT_CC_EXTRA_CONFIG}
   314 
   315     if [ "${CT_CANADIAN}" = "y" ]; then
   316         CT_DoLog EXTRA "Building libiberty"
   317         CT_DoExecLog ALL make ${PARALLELMFLAGS} all-build-libiberty
   318     fi
   319 
   320     CT_DoLog EXTRA "Building final compiler"
   321     CT_DoExecLog ALL make ${PARALLELMFLAGS} all
   322 
   323     CT_DoLog EXTRA "Installing final compiler"
   324     CT_DoExecLog ALL make install
   325 
   326     # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
   327     # to call the C compiler with the same, somewhat canonical name.
   328     CT_DoExecLog ALL ln -sv "${CT_TARGET}"-gcc "${CT_PREFIX_DIR}/bin/${CT_TARGET}"-cc
   329 
   330     CT_EndStep
   331 }