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