scripts/build/cc/gcc.sh
changeset 850 ef8549b58b6f
child 887 0a8cc9d782de
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/scripts/build/cc/gcc.sh	Sun Sep 14 16:21:07 2008 +0000
     1.3 @@ -0,0 +1,299 @@
     1.4 +# This file adds the function to build the gcc C compiler
     1.5 +        ${extra_config}                         \
     1.6 +# Copyright 2007 Yann E. MORIN
     1.7 +# Licensed under the GPL v2. See COPYING in the root of this package
     1.8 +
     1.9 +do_print_filename() {
    1.10 +    [ "${CT_CC}" = "gcc" ] || return 0
    1.11 +    echo "gcc-${CT_CC_VERSION}"
    1.12 +}
    1.13 +
    1.14 +# Download gcc
    1.15 +do_cc_get() {
    1.16 +    # Ah! gcc folks are kind of 'different': they store the tarballs in
    1.17 +    # subdirectories of the same name! That's because gcc is such /crap/ that
    1.18 +    # it is such /big/ that it needs being splitted for distribution! Sad. :-(
    1.19 +    # Arrgghh! Some of those versions does not follow this convention:
    1.20 +    # gcc-3.3.3 lives in releases/gcc-3.3.3, while gcc-2.95.* isn't in a
    1.21 +    # subdirectory! You bastard!
    1.22 +    CT_GetFile "${CT_CC_FILE}"  \
    1.23 +               {ftp,http}://ftp.gnu.org/gnu/gcc{,{,/releases}/${CT_CC_FILE}}
    1.24 +}
    1.25 +
    1.26 +# Extract gcc
    1.27 +do_cc_extract() {
    1.28 +    CT_ExtractAndPatch "${CT_CC_FILE}"
    1.29 +}
    1.30 +
    1.31 +#------------------------------------------------------------------------------
    1.32 +# Core gcc pass 1
    1.33 +do_cc_core_pass_1() {
    1.34 +    # If we're building for bare metal, build the static core gcc,
    1.35 +    # with libgcc.
    1.36 +    # In case we're not bare metal, and we're NPTL, build the static core gcc.
    1.37 +    # In any other case, do nothing.
    1.38 +    case "${CT_BARE_METAL},${CT_THREADS}" in
    1.39 +        y,*)    do_cc_core mode=baremetal build_libgcc=yes;;
    1.40 +        ,nptl)  do_cc_core mode=static build_libgcc=no;;
    1.41 +        *)      ;;
    1.42 +    esac
    1.43 +}
    1.44 +
    1.45 +# Core gcc pass 2
    1.46 +do_cc_core_pass_2() {
    1.47 +    # In case we're building for bare metal, do nothing, we already have
    1.48 +    # our compiler.
    1.49 +    # In case we're NPTL, build the shared core gcc.
    1.50 +    # In any other case, build the static core gcc and the target libgcc.
    1.51 +    case "${CT_BARE_METAL},${CT_THREADS}" in
    1.52 +        y,*)    ;;
    1.53 +        ,nptl)  do_cc_core mode=shared build_libgcc=yes;;
    1.54 +        *)      do_cc_core mode=static build_libgcc=yes;;
    1.55 +    esac
    1.56 +}
    1.57 +
    1.58 +#------------------------------------------------------------------------------
    1.59 +# Build core gcc
    1.60 +# This function is used to build both the static and the shared core C conpiler,
    1.61 +# with or without the target libgcc. We need to know wether:
    1.62 +#  - we're building static, shared or bare metal: mode=[static|shared|baremetal]
    1.63 +#  - we need to build libgcc or not             : build_libgcc=[yes|no]
    1.64 +# Usage: do_cc_core_static mode=[static|shared|baremetal] build_libgcc=[yes|no]
    1.65 +do_cc_core() {
    1.66 +    local mode
    1.67 +    local build_libgcc
    1.68 +    local core_prefix_dir
    1.69 +    local extra_config
    1.70 +
    1.71 +    eval $1
    1.72 +    eval $2
    1.73 +    CT_TestOrAbort "Internal Error: 'mode' must either 'static', 'shared' or 'baremetal', not '${mode:-(empty)}'" "${mode}" = "static" -o "${mode}" = "shared" -o "${mode}" = "baremetal"
    1.74 +    CT_TestOrAbort "Internal Error: 'build_libgcc' must be either 'yes' or 'no', not '${build_libgcc:-(empty)}'" "${build_libgcc}" = "yes" -o "${build_libgcc}" = "no"
    1.75 +    # In normal conditions, ( "${mode}" = "shared" ) implies
    1.76 +    # ( "${build_libgcc}" = "yes" ), but I won't check for that
    1.77 +
    1.78 +    mkdir -p "${CT_BUILD_DIR}/build-cc-core-${mode}"
    1.79 +    cd "${CT_BUILD_DIR}/build-cc-core-${mode}"
    1.80 +
    1.81 +    CT_DoStep INFO "Installing ${mode} core C compiler"
    1.82 +    case "${mode}" in
    1.83 +        static)
    1.84 +            core_prefix_dir="${CT_CC_CORE_STATIC_PREFIX_DIR}"
    1.85 +            extra_config="${extra_config} --with-newlib --enable-threads=no --disable-shared"
    1.86 +            copy_headers=y
    1.87 +            ;;
    1.88 +        shared)
    1.89 +            core_prefix_dir="${CT_CC_CORE_SHARED_PREFIX_DIR}"
    1.90 +            extra_config="${extra_config} --enable-shared"
    1.91 +            copy_headers=y
    1.92 +            ;;
    1.93 +        baremetal)
    1.94 +            core_prefix_dir="${CT_PREFIX_DIR}"
    1.95 +            extra_config="${extra_config} --with-newlib --enable-threads=no --disable-shared"
    1.96 +            copy_headers=n
    1.97 +            ;;
    1.98 +    esac
    1.99 +
   1.100 +    if [ "${copy_headers}" = "y" ]; then
   1.101 +        CT_DoLog DEBUG "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
   1.102 +        CT_DoExecLog ALL mkdir -p "${core_prefix_dir}/${CT_TARGET}/include"
   1.103 +        CT_DoExecLog ALL cp -r "${CT_HEADERS_DIR}"/* "${core_prefix_dir}/${CT_TARGET}/include"
   1.104 +    fi
   1.105 +
   1.106 +    CT_DoLog EXTRA "Configuring ${mode} core C compiler"
   1.107 +
   1.108 +    extra_config="${extra_config} ${CT_ARCH_WITH_ARCH}"
   1.109 +    extra_config="${extra_config} ${CT_ARCH_WITH_ABI}"
   1.110 +    extra_config="${extra_config} ${CT_ARCH_WITH_CPU}"
   1.111 +    extra_config="${extra_config} ${CT_ARCH_WITH_TUNE}"
   1.112 +    extra_config="${extra_config} ${CT_ARCH_WITH_FPU}"
   1.113 +    extra_config="${extra_config} ${CT_ARCH_WITH_FLOAT}"
   1.114 +    [ "${CT_GMP_MPFR}" = "y" ] && extra_config="${extra_config} --with-gmp=${CT_PREFIX_DIR} --with-mpfr=${CT_PREFIX_DIR}"
   1.115 +    if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
   1.116 +        extra_config="${extra_config} --enable-__cxa_atexit"
   1.117 +    else
   1.118 +        extra_config="${extra_config} --disable-__cxa_atexit"
   1.119 +    fi
   1.120 +
   1.121 +    CT_DoLog DEBUG "Extra config passed: '${extra_config}'"
   1.122 +
   1.123 +    # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
   1.124 +    CC_FOR_BUILD="${CT_CC_NATIVE}"                  \
   1.125 +    CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
   1.126 +    CT_DoExecLog ALL                                \
   1.127 +    "${CT_SRC_DIR}/${CT_CC_FILE}/configure"         \
   1.128 +        ${CT_CANADIAN_OPT}                          \
   1.129 +        --host=${CT_HOST}                           \
   1.130 +        --target=${CT_TARGET}                       \
   1.131 +        --prefix="${core_prefix_dir}"               \
   1.132 +        --with-local-prefix="${CT_SYSROOT_DIR}"     \
   1.133 +        --disable-multilib                          \
   1.134 +        ${CC_CORE_SYSROOT_ARG}                      \
   1.135 +        ${extra_config}                             \
   1.136 +        --disable-nls                               \
   1.137 +        --enable-symvers=gnu                        \
   1.138 +        --enable-languages=c                        \
   1.139 +        --enable-target-optspace                    \
   1.140 +        ${CT_CC_CORE_EXTRA_CONFIG}
   1.141 +
   1.142 +    if [ "${build_libgcc}" = "yes" ]; then
   1.143 +        # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
   1.144 +        # gcc/config/t-libunwind so -lc is removed from the link for
   1.145 +        # libgcc_s.so, as we do not have a target -lc yet.
   1.146 +        # This is not as ugly as it appears to be ;-) All symbols get resolved
   1.147 +        # during the glibc build, and we provide a proper libgcc_s.so for the
   1.148 +        # cross toolchain during the final gcc build.
   1.149 +        #
   1.150 +        # As we cannot modify the source tree, nor override SHLIB_LC itself
   1.151 +        # during configure or make, we have to edit the resultant
   1.152 +        # gcc/libgcc.mk itself to remove -lc from the link.
   1.153 +        # This causes us to have to jump through some hoops...
   1.154 +        #
   1.155 +        # To produce libgcc.mk to edit we firstly require libiberty.a,
   1.156 +        # so we configure then build it.
   1.157 +        # Next we have to configure gcc, create libgcc.mk then edit it...
   1.158 +        # So much easier if we just edit the source tree, but hey...
   1.159 +        if [ ! -f "${CT_SRC_DIR}/${CT_CC_FILE}/gcc/BASE-VER" ]; then
   1.160 +            CT_DoExecLog ALL make configure-libiberty
   1.161 +            CT_DoExecLog ALL make ${PARALLELMFLAGS} -C libiberty libiberty.a
   1.162 +            CT_DoExecLog ALL make configure-gcc configure-libcpp
   1.163 +            CT_DoExecLog ALL make ${PARALLELMFLAGS} all-libcpp
   1.164 +        else
   1.165 +            CT_DoExecLog ALL make configure-gcc configure-libcpp configure-build-libiberty
   1.166 +            CT_DoExecLog ALL make ${PARALLELMFLAGS} all-libcpp all-build-libiberty
   1.167 +        fi
   1.168 +        # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
   1.169 +        if [ -d "${CT_SRC_DIR}/${CT_CC_FILE}/libdecnumber" ]; then
   1.170 +            CT_DoExecLog ALL make configure-libdecnumber
   1.171 +            CT_DoExecLog ALL make ${PARALLELMFLAGS} -C libdecnumber libdecnumber.a
   1.172 +        fi
   1.173 +
   1.174 +        # Starting with GCC 4.3, libgcc.mk is no longer built,
   1.175 +        # and libgcc.mvars is used instead.
   1.176 +
   1.177 +        gcc_version_major=$(echo ${CT_CC_VERSION} |sed -r -e 's/^([^\.]+)\..*/\1/')
   1.178 +        gcc_version_minor=$(echo ${CT_CC_VERSION} |sed -r -e 's/^[^\.]+\.([^.]+).*/\1/')
   1.179 +
   1.180 +        if [    ${gcc_version_major} -eq 4 -a ${gcc_version_minor} -ge 3    \
   1.181 +             -o ${gcc_version_major} -gt 4                                  ]; then
   1.182 +            libgcc_rule="libgcc.mvars"
   1.183 +            build_rules="all-gcc all-target-libgcc"
   1.184 +            install_rules="install-gcc install-target-libgcc"
   1.185 +        else
   1.186 +            libgcc_rule="libgcc.mk"
   1.187 +            build_rules="all-gcc"
   1.188 +            install_rules="install-gcc"
   1.189 +        fi
   1.190 +
   1.191 +        CT_DoExecLog ALL make ${PARALLELMFLAGS} -C gcc ${libgcc_rule}
   1.192 +        sed -r -i -e 's@-lc@@g' gcc/${libgcc_rule}
   1.193 +    else # build_libgcc
   1.194 +            build_rules="all-gcc"
   1.195 +            install_rules="install-gcc"
   1.196 +    fi   # ! build libgcc
   1.197 +
   1.198 +    if [ "${CT_CANADIAN}" = "y" ]; then
   1.199 +        CT_DoLog EXTRA "Building libiberty"
   1.200 +        CT_DoExecLog ALL make ${PARALLELMFLAGS} all-build-libiberty
   1.201 +    fi
   1.202 +
   1.203 +    CT_DoLog EXTRA "Building ${mode} core C compiler"
   1.204 +    CT_DoExecLog ALL make ${PARALLELMFLAGS} ${build_rules}
   1.205 +
   1.206 +    CT_DoLog EXTRA "Installing ${mode} core C compiler"
   1.207 +    CT_DoExecLog ALL make ${install_rules}
   1.208 +
   1.209 +    CT_EndStep
   1.210 +}
   1.211 +
   1.212 +#------------------------------------------------------------------------------
   1.213 +# Build final gcc
   1.214 +do_cc() {
   1.215 +    # If building for bare metal, nothing to be done here, the static core conpiler is enough!
   1.216 +    [ "${CT_BARE_METAL}" = "y" ] && return 0
   1.217 +
   1.218 +    CT_DoStep INFO "Installing final compiler"
   1.219 +
   1.220 +    mkdir -p "${CT_BUILD_DIR}/build-cc"
   1.221 +    cd "${CT_BUILD_DIR}/build-cc"
   1.222 +
   1.223 +    CT_DoLog EXTRA "Configuring final compiler"
   1.224 +
   1.225 +    # Enable selected languages
   1.226 +    lang_opt="c"
   1.227 +    [ "${CT_CC_LANG_CXX}" = "y"      ] && lang_opt="${lang_opt},c++"
   1.228 +    [ "${CT_CC_LANG_FORTRAN}" = "y"  ] && lang_opt="${lang_opt},fortran"
   1.229 +    [ "${CT_CC_LANG_ADA}" = "y"      ] && lang_opt="${lang_opt},ada"
   1.230 +    [ "${CT_CC_LANG_JAVA}" = "y"     ] && lang_opt="${lang_opt},java"
   1.231 +    [ "${CT_CC_LANG_OBJC}" = "y"     ] && lang_opt="${lang_opt},objc"
   1.232 +    [ "${CT_CC_LANG_OBJCXX}" = "y"   ] && lang_opt="${lang_opt},obj-c++"
   1.233 +    CT_Test "Building ADA language is not yet supported. Will try..." "${CT_CC_LANG_ADA}" = "y"
   1.234 +    CT_Test "Building Objective-C language is not yet supported. Will try..." "${CT_CC_LANG_OBJC}" = "y"
   1.235 +    CT_Test "Building Objective-C++ language is not yet supported. Will try..." "${CT_CC_LANG_OBJCXX}" = "y"
   1.236 +    CT_Test "Building ${CT_CC_LANG_OTHERS//,/ } language(s) is not yet supported. Will try..." -n "${CT_CC_LANG_OTHERS}"
   1.237 +    lang_opt=$(echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;')
   1.238 +
   1.239 +    extra_config="--enable-languages=${lang_opt}"
   1.240 +    extra_config="${extra_config} --disable-multilib"
   1.241 +    extra_config="${extra_config} ${CT_ARCH_WITH_ARCH}"
   1.242 +    extra_config="${extra_config} ${CT_ARCH_WITH_ABI}"
   1.243 +    extra_config="${extra_config} ${CT_ARCH_WITH_CPU}"
   1.244 +    extra_config="${extra_config} ${CT_ARCH_WITH_TUNE}"
   1.245 +    extra_config="${extra_config} ${CT_ARCH_WITH_FPU}"
   1.246 +    extra_config="${extra_config} ${CT_ARCH_WITH_FLOAT}"
   1.247 +    [ "${CT_SHARED_LIBS}" = "y" ]                   || extra_config="${extra_config} --disable-shared"
   1.248 +    [ "${CT_GMP_MPFR}" = "y" ]                      && extra_config="${extra_config} --with-gmp=${CT_PREFIX_DIR} --with-mpfr=${CT_PREFIX_DIR}"
   1.249 +    [ -n "${CT_CC_PKGVERSION}" ]                    && extra_config="${extra_config} --with-pkgversion=${CT_CC_PKGVERSION}"
   1.250 +    [ -n "${CT_CC_BUGURL}" ]                        && extra_config="${extra_config} --with-bugurl=${CT_CC_BUGURL}"
   1.251 +    [ "${CT_CC_SJLJ_EXCEPTIONS_USE}" = "y" ]        && extra_config="${extra_config} --enable-sjlj-exceptions"
   1.252 +    [ "${CT_CC_SJLJ_EXCEPTIONS_DONT_USE}" = "y" ]   && extra_config="${extra_config} --disable-sjlj-exceptions"
   1.253 +    if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
   1.254 +        extra_config="${extra_config} --enable-__cxa_atexit"
   1.255 +    else
   1.256 +        extra_config="${extra_config} --disable-__cxa_atexit"
   1.257 +    fi
   1.258 +
   1.259 +    CT_DoLog DEBUG "Extra config passed: '${extra_config}'"
   1.260 +
   1.261 +    # --enable-symvers=gnu really only needed for sh4 to work around a
   1.262 +    # detection problem only matters for gcc-3.2.x and later, I think.
   1.263 +    # --disable-nls to work around crash bug on ppc405, but also because
   1.264 +    # embedded systems don't really need message catalogs...
   1.265 +    CC_FOR_BUILD="${CT_CC_NATIVE}"              \
   1.266 +    CFLAGS="${CT_CFLAGS_FOR_HOST}"              \
   1.267 +    CFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}"     \
   1.268 +    CXXFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}"   \
   1.269 +    LDFLAGS_FOR_TARGET="${CT_TARGET_LDFLAGS}"   \
   1.270 +    CT_DoExecLog ALL                            \
   1.271 +    "${CT_SRC_DIR}/${CT_CC_FILE}/configure"     \
   1.272 +        ${CT_CANADIAN_OPT}                      \
   1.273 +        --target=${CT_TARGET} --host=${CT_HOST} \
   1.274 +        --prefix="${CT_PREFIX_DIR}"             \
   1.275 +        ${CC_SYSROOT_ARG}                       \
   1.276 +        ${extra_config}                         \
   1.277 +        --with-local-prefix="${CT_SYSROOT_DIR}" \
   1.278 +        --disable-nls                           \
   1.279 +        --enable-threads=posix                  \
   1.280 +        --enable-symvers=gnu                    \
   1.281 +        --enable-c99                            \
   1.282 +        --enable-long-long                      \
   1.283 +        --enable-target-optspace                \
   1.284 +        ${CT_CC_EXTRA_CONFIG}
   1.285 +
   1.286 +    if [ "${CT_CANADIAN}" = "y" ]; then
   1.287 +        CT_DoLog EXTRA "Building libiberty"
   1.288 +        CT_DoExecLog ALL make ${PARALLELMFLAGS} all-build-libiberty
   1.289 +    fi
   1.290 +
   1.291 +    CT_DoLog EXTRA "Building final compiler"
   1.292 +    CT_DoExecLog ALL make ${PARALLELMFLAGS} all
   1.293 +
   1.294 +    CT_DoLog EXTRA "Installing final compiler"
   1.295 +    CT_DoExecLog ALL make install
   1.296 +
   1.297 +    # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
   1.298 +    # to call the C compiler with the same, somewhat canonical name.
   1.299 +    ln -sv "${CT_PREFIX_DIR}/bin/${CT_TARGET}"-{g,}cc 2>&1 |CT_DoLog ALL
   1.300 +
   1.301 +    CT_EndStep
   1.302 +}