scripts/build/cc_gcc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed Aug 15 10:14:43 2007 +0000 (2007-08-15)
changeset 331 0c05f9ea3254
parent 235 faadf2d49d5d
child 354 cf673077c0c1
permissions -rw-r--r--
Get rid of the core cc selection. It is now the same as the final compiler.
     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 final 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://ftp.gnu.org/gnu/gcc/${CT_CC_FILE}          \
    20                ftp://ftp.gnu.org/gnu/gcc/releases/${CT_CC_FILE} \
    21                ftp://ftp.gnu.org/gnu/gcc
    22 }
    23 
    24 # Extract final gcc
    25 do_cc_extract() {
    26     CT_ExtractAndPatch "${CT_CC_FILE}"
    27 }
    28 
    29 #------------------------------------------------------------------------------
    30 # Core gcc pass 1
    31 do_cc_core_pass_1() {
    32     # In case we're NPTL, build the static core gcc;
    33     # in any other case, do nothing.
    34     case "${CT_THREADS}" in
    35         nptl)   do_cc_core_static;;
    36         *)      ;;
    37     esac
    38 }
    39 
    40 # Core gcc pass 2
    41 do_cc_core_pass_2() {
    42     # In case we're NPTL, build the shared core gcc,
    43     # in any other case, build the static core gcc.
    44     case "${CT_THREADS}" in
    45         nptl)   do_cc_core_shared;;
    46         *)      do_cc_core_static;;
    47     esac
    48 }
    49 
    50 #------------------------------------------------------------------------------
    51 # Build static core gcc
    52 do_cc_core_static() {
    53     mkdir -p "${CT_BUILD_DIR}/build-cc-core-static"
    54     cd "${CT_BUILD_DIR}/build-cc-core-static"
    55 
    56     CT_DoStep INFO "Installing static core C compiler"
    57 
    58     CT_DoLog EXTRA "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
    59     mkdir -p "${CT_CC_CORE_STATIC_PREFIX_DIR}/${CT_TARGET}/include"
    60     cp -r "${CT_HEADERS_DIR}"/* "${CT_CC_CORE_STATIC_PREFIX_DIR}/${CT_TARGET}/include" 2>&1 |CT_DoLog DEBUG
    61 
    62     CT_DoLog EXTRA "Configuring static core C compiler"
    63 
    64     extra_config=""
    65     [ "${CT_ARCH_FLOAT_SW}" = "y" ] && extra_config="${extra_config} --with-float=soft"
    66     [ -n "${CT_ARCH_ABI}" ]  && extra_config="${extra_config} --with-abi=${CT_ARCH_ABI}"
    67     [ -n "${CT_ARCH_ARCH}" ] && extra_config="${extra_config} --with-arch=${CT_ARCH_ARCH}"
    68     [ -n "${CT_ARCH_CPU}" ]  && extra_config="${extra_config} --with-cpu=${CT_ARCH_CPU}"
    69     [ -n "${CT_ARCH_TUNE}" ] && extra_config="${extra_config} --with-tune=${CT_ARCH_TUNE}"
    70     [ -n "${CT_ARCH_FPU}" ] && extra_config="${extra_config} --with-fpu=${CT_ARCH_FPU}"
    71     [ "${CT_CC_CXA_ATEXIT}" = "y" ] && extra_config="${extra_config} --enable-__cxa_atexit"
    72 
    73     CT_DoLog DEBUG "Extra config passed: \"${extra_config}\""
    74 
    75     # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
    76     CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
    77     "${CT_SRC_DIR}/${CT_CC_FILE}/configure"         \
    78         ${CT_CANADIAN_OPT}                          \
    79         --host=${CT_HOST}                           \
    80         --target=${CT_TARGET}                       \
    81         --prefix="${CT_CC_CORE_STATIC_PREFIX_DIR}"  \
    82         --with-local-prefix="${CT_SYSROOT_DIR}"     \
    83         --disable-multilib                          \
    84         --with-newlib                               \
    85         ${CC_CORE_SYSROOT_ARG}                      \
    86         ${extra_config}                             \
    87         --disable-nls                               \
    88         --enable-threads=no                         \
    89         --enable-symvers=gnu                        \
    90         --enable-languages=c                        \
    91         --disable-shared                            \
    92         ${CT_CC_CORE_EXTRA_CONFIG}                  2>&1 |CT_DoLog ALL
    93 
    94     if [ "${CT_CANADIAN}" = "y" ]; then
    95         CT_DoLog EXTRA "Building libiberty"
    96         make ${PARALLELMFLAGS} all-build-libiberty 2>&1 |CT_DoLog ALL
    97     fi
    98 
    99     CT_DoLog EXTRA "Building static core C compiler"
   100     make ${PARALLELMFLAGS} all-gcc 2>&1 |CT_DoLog ALL
   101 
   102     CT_DoLog EXTRA "Installing static core C compiler"
   103     make install-gcc 2>&1 |CT_DoLog ALL
   104 
   105     CT_EndStep
   106 }
   107 
   108 #------------------------------------------------------------------------------
   109 # Build shared core gcc
   110 do_cc_core_shared() {
   111     mkdir -p "${CT_BUILD_DIR}/build-cc-core-shared"
   112     cd "${CT_BUILD_DIR}/build-cc-core-shared"
   113 
   114     CT_DoStep INFO "Installing shared core C compiler"
   115 
   116     CT_DoLog EXTRA "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
   117     mkdir -p "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include"
   118     cp -r "${CT_HEADERS_DIR}"/* "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include" 2>&1 |CT_DoLog DEBUG
   119 
   120     CT_DoLog EXTRA "Configuring shared core C compiler"
   121 
   122     extra_config=""
   123     [ "${CT_ARCH_FLOAT_SW}" = "y" ] && extra_config="${extra_config} --with-float=soft"
   124     [ -n "${CT_ARCH_ABI}" ]  && extra_config="${extra_config} --with-abi=${CT_ARCH_ABI}"
   125     [ -n "${CT_ARCH_ARCH}" ] && extra_config="${extra_config} --with-arch=${CT_ARCH_ARCH}"
   126     [ -n "${CT_ARCH_CPU}" ]  && extra_config="${extra_config} --with-cpu=${CT_ARCH_CPU}"
   127     [ -n "${CT_ARCH_TUNE}" ] && extra_config="${extra_config} --with-tune=${CT_ARCH_TUNE}"
   128     [ -n "${CT_ARCH_FPU}" ] && extra_config="${extra_config} --with-fpu=${CT_ARCH_FPU}"
   129     [ "${CT_CC_CXA_ATEXIT}" = "y" ] && extra_config="${extra_config} --enable-__cxa_atexit"
   130 
   131     CT_DoLog DEBUG "Extra config passed: \"${extra_config}\""
   132 
   133     CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
   134     "${CT_SRC_DIR}/${CT_CC_FILE}/configure"         \
   135         ${CT_CANADIAN_OPT}                          \
   136         --target=${CT_TARGET}                       \
   137         --host=${CT_HOST}                           \
   138         --prefix="${CT_CC_CORE_SHARED_PREFIX_DIR}"  \
   139         --with-local-prefix="${CT_SYSROOT_DIR}"     \
   140         --disable-multilib                          \
   141         ${CC_CORE_SYSROOT_ARG}                      \
   142         ${extra_config}                             \
   143         --disable-nls                               \
   144         --enable-symvers=gnu                        \
   145         --enable-languages=c                        \
   146         --enable-shared                             \
   147         ${CT_CC_CORE_EXTRA_CONFIG}                  2>&1 |CT_DoLog ALL
   148 
   149     # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
   150     # gcc/config/t-libunwind so -lc is removed from the link for
   151     # libgcc_s.so, as we do not have a target -lc yet.
   152     # This is not as ugly as it appears to be ;-) All symbols get resolved
   153     # during the glibc build, and we provide a proper libgcc_s.so for the
   154     # cross toolchain during the final gcc build.
   155     #
   156     # As we cannot modify the source tree, nor override SHLIB_LC itself
   157     # during configure or make, we have to edit the resultant
   158     # gcc/libgcc.mk itself to remove -lc from the link.
   159     # This causes us to have to jump through some hoops...
   160     #
   161     # To produce libgcc.mk to edit we firstly require libiberty.a,
   162     # so we configure then build it.
   163     # Next we have to configure gcc, create libgcc.mk then edit it...
   164     # So much easier if we just edit the source tree, but hey...
   165     if [ ! -f "${CT_SRC_DIR}/${CT_CC_FILE}/gcc/BASE-VER" ]; then
   166         make configure-libiberty
   167         make -C libiberty libiberty.a
   168         make configure-gcc
   169         make configure-libcpp
   170         make all-libcpp
   171     else
   172         make configure-gcc
   173         make configure-libcpp
   174         make configure-build-libiberty
   175         make all-libcpp
   176         make all-build-libiberty
   177     fi 2>&1 |CT_DoLog ALL
   178     # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
   179     if [ -d "${CT_SRC_DIR}/${CT_CC_FILE}/libdecnumber" ]; then
   180         make configure-libdecnumber
   181         make -C libdecnumber libdecnumber.a
   182     fi 2>&1 |CT_DoLog ALL
   183     make -C gcc libgcc.mk 2>&1 |CT_DoLog ALL
   184     sed -r -i -e 's@-lc@@g' gcc/libgcc.mk
   185 
   186     if [ "${CT_CANADIAN}" = "y" ]; then
   187         CT_DoLog EXTRA "Building libiberty"
   188         make ${PARALLELMFLAGS} all-build-libiberty 2>&1 |CT_DoLog ALL
   189     fi
   190 
   191     CT_DoLog EXTRA "Building shared core C compiler"
   192     make ${PARALLELMFLAGS} all-gcc 2>&1 |CT_DoLog ALL
   193 
   194     CT_DoLog EXTRA "Installing shared core C compiler"
   195     make install-gcc 2>&1 |CT_DoLog ALL
   196 
   197     CT_EndStep
   198 }
   199 
   200 #------------------------------------------------------------------------------
   201 # Build final gcc
   202 do_cc() {
   203     CT_DoStep INFO "Installing final compiler"
   204 
   205     mkdir -p "${CT_BUILD_DIR}/build-cc"
   206     cd "${CT_BUILD_DIR}/build-cc"
   207 
   208     CT_DoLog EXTRA "Configuring final compiler"
   209 
   210     # Enable selected languages
   211     lang_opt="c"
   212     [ "${CT_CC_LANG_CXX}" = "y"      ] && lang_opt="${lang_opt},c++"
   213     [ "${CT_CC_LANG_FORTRAN}" = "y"  ] && lang_opt="${lang_opt},fortran"
   214     [ "${CT_CC_LANG_ADA}" = "y"      ] && lang_opt="${lang_opt},ada"
   215     [ "${CT_CC_LANG_JAVA}" = "y"     ] && lang_opt="${lang_opt},java"
   216     [ "${CT_CC_LANG_OBJC}" = "y"     ] && lang_opt="${lang_opt},objc"
   217     [ "${CT_CC_LANG_OBJCXX}" = "y"   ] && lang_opt="${lang_opt},obj-c++"
   218     CT_Test "Building Fortran language is not yet supported. Will try..." "${CT_CC_LANG_FORTRAN}" = "y"
   219     CT_Test "Building ADA language is not yet supported. Will try..." "${CT_CC_LANG_ADA}" = "y"
   220     CT_Test "Building Java language is not yet supported. Will try..." "${CT_CC_LANG_JAVA}" = "y"
   221     CT_Test "Building Objective-C language is not yet supported. Will try..." "${CT_CC_LANG_OBJC}" = "y"
   222     CT_Test "Building Objective-C++ language is not yet supported. Will try..." "${CT_CC_LANG_OBJCXX}" = "y"
   223     CT_Test "Building ${CT_CC_LANG_OTHERS} language(s) is not yet supported. Will try..." -n "${CT_CC_LANG_OTHERS}"
   224     lang_opt=`echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;'`
   225 
   226     extra_config="--enable-languages=${lang_opt}"
   227     [ "${CT_ARCH_FLOAT_SW}" = "y" ] && extra_config="${extra_config} --with-float=soft"
   228     [ "${CT_SHARED_LIBS}" = "y" ] || extra_config="${extra_config} --disable-shared"
   229     [ -n "${CT_ARCH_ABI}" ]  && extra_config="${extra_config} --with-abi=${CT_ARCH_ABI}"
   230     [ -n "${CT_ARCH_CPU}" ]  && extra_config="${extra_config} --with-cpu=${CT_ARCH_CPU}"
   231     [ -n "${CT_ARCH_TUNE}" ] && extra_config="${extra_config} --with-tune=${CT_ARCH_TUNE}"
   232     [ -n "${CT_ARCH_ARCH}" ] && extra_config="${extra_config} --with-arch=${CT_ARCH_ARCH}"
   233     [ -n "${CT_ARCH_FPU}" ] && extra_config="${extra_config} --with-fpu=${CT_ARCH_FPU}"
   234     if [ "${CT_TARGET_MULTILIB}" = "y" ]; then
   235        extra_config="${extra_config} --enable-multilib"
   236     else
   237        extra_config="${extra_config} --disable-multilib"
   238     fi
   239     [ "${CT_CC_CXA_ATEXIT}" == "y" ] && extra_config="${extra_config} --enable-__cxa_atexit"
   240 
   241     CT_DoLog DEBUG "Extra config passed: \"${extra_config}\""
   242 
   243     # --enable-symvers=gnu really only needed for sh4 to work around a
   244     # detection problem only matters for gcc-3.2.x and later, I think.
   245     # --disable-nls to work around crash bug on ppc405, but also because
   246     # embedded systems don't really need message catalogs...
   247     CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
   248     "${CT_SRC_DIR}/${CT_CC_FILE}/configure"     \
   249         ${CT_CANADIAN_OPT}                      \
   250         --target=${CT_TARGET} --host=${CT_HOST} \
   251         --prefix="${CT_PREFIX_DIR}"             \
   252         ${CC_SYSROOT_ARG}                       \
   253         ${extra_config}                         \
   254         --with-local-prefix="${CT_SYSROOT_DIR}" \
   255         --disable-nls                           \
   256         --enable-threads=posix                  \
   257         --enable-symvers=gnu                    \
   258         --enable-c99                            \
   259         --enable-long-long                      \
   260         ${CT_CC_EXTRA_CONFIG}                   2>&1 |CT_DoLog ALL
   261 
   262     if [ "${CT_CANADIAN}" = "y" ]; then
   263         CT_DoLog EXTRA "Building libiberty"
   264         make ${PARALLELMFLAGS} all-build-libiberty 2>&1 |CT_DoLog ALL
   265     fi
   266 
   267 
   268     # Idea from <cort.dougan at gmail.com>:
   269     # Fix lib/lib64 confusion for GCC 3.3.3 on PowerPC64 and x86_64.
   270     # GCC 3.4.0 and up don't suffer from this confusion, and don't need this
   271     # kludge.
   272     # FIXME: we should patch gcc's source rather than uglify crosstool.sh.
   273     # FIXME: is this needed for gcc-3.3.[56]?
   274     case "${CT_CC_FILE}" in
   275       gcc-3.3.[34])
   276         case "${CT_TARGET}" in
   277           powerpc64-unknown-linux-gnu|x86_64-unknown-linux-gnu)
   278             for d in `find "${CT_SYSROOT_DIR}" -name lib -type d -empty`; do
   279               if [ -d `dirname "${d}"`/lib64 ] ; then
   280                 rm -rf "${d}"
   281                 ln -s `dirname "${d}"`/lib64 "${d}"
   282               fi
   283             done ;;
   284           *) ;;
   285         esac ;;
   286     esac
   287 
   288     CT_DoLog EXTRA "Building final compiler"
   289     make ${PARALLELMFLAGS} all 2>&1 |CT_DoLog ALL
   290 
   291     CT_DoLog EXTRA "Installing final compiler"
   292     make install 2>&1 |CT_DoLog ALL
   293 
   294     # FIXME: shouldn't people who want this just --disable-multilib in final gcc
   295     # and be done with it?
   296     # This code should probably be deleted, it was written long ago and hasn't
   297     # been tested in ages.
   298     # kludge: If the chip does not have a floating point unit
   299     # (i.e. if GLIBC_EXTRA_CONFIG contains --without-fp),
   300     # and there are shared libraries in /lib/nof, copy them to /lib
   301     # so they get used by default.
   302     # FIXME: only rs6000/powerpc seem to use nof.  See MULTILIB_DIRNAMES
   303     # in $GCC_DIR/gcc/config/$TARGET/* to see what your arch calls it.
   304     #case "${CT_LIBC_EXTRA_CONFIG}" in
   305     #    *--without-fp*)
   306     #        if test -d "${CT_SYSROOT_DIR}/lib/nof"; then
   307     #            cp -af "${CT_SYSROOT_DIR}/lib/nof/"*.so* "${CT_SYSROOT_DIR}/lib" || true
   308     #        fi
   309     #    ;;
   310     #esac
   311 
   312     # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
   313     # to call the C compiler with the same, somewhat canonical name.
   314     ln "${CT_PREFIX_DIR}/bin/${CT_TARGET}"-{g,}cc
   315 
   316     CT_EndStep
   317 }