scripts/build/cc/gcc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Sep 14 16:21:07 2008 +0000 (2008-09-14)
changeset 850 ef8549b58b6f
child 887 0a8cc9d782de
permissions -rw-r--r--
Introduce a new EXPERIMENTAL feature: BARE_METAL.
This should ultimately llow to build bare-metal compilers, for targets that have no kernel and no C library.
Move the C library build script to their own sub-directory; introduce an empty build script for bare-metal.
Move the compiler build script to its own sub-directory.
Move the kernel build script to its own sub-directory; introduce an empty build script for bare-metal.
Update the ARM target tuples to enable bare-metal targets.
Add two ARM bare-metal samples.
Add latest Linux kernel versions.

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