scripts/build/cc_gcc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Feb 17 22:08:06 2008 +0000 (2008-02-17)
changeset 431 8bde4c6ea47a
parent 397 046dfd46798c
child 462 b959799c9a36
permissions -rw-r--r--
Robert P. J. DAY says:

apparently, the patchset for gcc 4.2.1 applies properly to the
source for gcc 4.2.2 and gcc 4.2.3. so, if you want, you can simply
add support for those last two just by augmenting menuconfig and
adding a couple symlinks for those two directories. seems like a
cheap way to add a couple new versions.
     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="${CT_ARCH_WITH_ARCH} ${CT_ARCH_WITH_ABI} ${CT_ARCH_WITH_CPU} ${CT_ARCH_WITH_TUNE} ${CT_ARCH_WITH_FPU} ${CT_ARCH_WITH_FLOAT}"
    69     [ "${CT_CC_CXA_ATEXIT}" = "y" ] && extra_config="${extra_config} --enable-__cxa_atexit"
    70 
    71     CT_DoLog DEBUG "Extra config passed: \"${extra_config}\""
    72 
    73     # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
    74     CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
    75     "${CT_SRC_DIR}/${CT_CC_FILE}/configure"         \
    76         ${CT_CANADIAN_OPT}                          \
    77         --host=${CT_HOST}                           \
    78         --target=${CT_TARGET}                       \
    79         --prefix="${CT_CC_CORE_STATIC_PREFIX_DIR}"  \
    80         --with-local-prefix="${CT_SYSROOT_DIR}"     \
    81         --disable-multilib                          \
    82         --with-newlib                               \
    83         ${CC_CORE_SYSROOT_ARG}                      \
    84         ${extra_config}                             \
    85         --disable-nls                               \
    86         --enable-threads=no                         \
    87         --enable-symvers=gnu                        \
    88         --enable-languages=c                        \
    89         --disable-shared                            \
    90         ${CT_CC_CORE_EXTRA_CONFIG}                  2>&1 |CT_DoLog ALL
    91 
    92     if [ "${CT_CANADIAN}" = "y" ]; then
    93         CT_DoLog EXTRA "Building libiberty"
    94         make ${PARALLELMFLAGS} all-build-libiberty 2>&1 |CT_DoLog ALL
    95     fi
    96 
    97     CT_DoLog EXTRA "Building static core C compiler"
    98     make ${PARALLELMFLAGS} all-gcc 2>&1 |CT_DoLog ALL
    99 
   100     CT_DoLog EXTRA "Installing static core C compiler"
   101     make install-gcc 2>&1 |CT_DoLog ALL
   102 
   103     CT_EndStep
   104 }
   105 
   106 #------------------------------------------------------------------------------
   107 # Build shared core gcc
   108 do_cc_core_shared() {
   109     mkdir -p "${CT_BUILD_DIR}/build-cc-core-shared"
   110     cd "${CT_BUILD_DIR}/build-cc-core-shared"
   111 
   112     CT_DoStep INFO "Installing shared core C compiler"
   113 
   114     CT_DoLog EXTRA "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
   115     mkdir -p "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include"
   116     cp -r "${CT_HEADERS_DIR}"/* "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include" 2>&1 |CT_DoLog DEBUG
   117 
   118     CT_DoLog EXTRA "Configuring shared core C compiler"
   119 
   120     extra_config="${CT_ARCH_WITH_ARCH} ${CT_ARCH_WITH_ABI} ${CT_ARCH_WITH_CPU} ${CT_ARCH_WITH_TUNE} ${CT_ARCH_WITH_FPU} ${CT_ARCH_WITH_FLOAT}"
   121     [ "${CT_CC_CXA_ATEXIT}" = "y" ] && extra_config="${extra_config} --enable-__cxa_atexit"
   122 
   123     CT_DoLog DEBUG "Extra config passed: \"${extra_config}\""
   124 
   125     CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
   126     "${CT_SRC_DIR}/${CT_CC_FILE}/configure"         \
   127         ${CT_CANADIAN_OPT}                          \
   128         --target=${CT_TARGET}                       \
   129         --host=${CT_HOST}                           \
   130         --prefix="${CT_CC_CORE_SHARED_PREFIX_DIR}"  \
   131         --with-local-prefix="${CT_SYSROOT_DIR}"     \
   132         --disable-multilib                          \
   133         ${CC_CORE_SYSROOT_ARG}                      \
   134         ${extra_config}                             \
   135         --disable-nls                               \
   136         --enable-symvers=gnu                        \
   137         --enable-languages=c                        \
   138         --enable-shared                             \
   139         ${CT_CC_CORE_EXTRA_CONFIG}                  2>&1 |CT_DoLog ALL
   140 
   141     # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
   142     # gcc/config/t-libunwind so -lc is removed from the link for
   143     # libgcc_s.so, as we do not have a target -lc yet.
   144     # This is not as ugly as it appears to be ;-) All symbols get resolved
   145     # during the glibc build, and we provide a proper libgcc_s.so for the
   146     # cross toolchain during the final gcc build.
   147     #
   148     # As we cannot modify the source tree, nor override SHLIB_LC itself
   149     # during configure or make, we have to edit the resultant
   150     # gcc/libgcc.mk itself to remove -lc from the link.
   151     # This causes us to have to jump through some hoops...
   152     #
   153     # To produce libgcc.mk to edit we firstly require libiberty.a,
   154     # so we configure then build it.
   155     # Next we have to configure gcc, create libgcc.mk then edit it...
   156     # So much easier if we just edit the source tree, but hey...
   157     if [ ! -f "${CT_SRC_DIR}/${CT_CC_FILE}/gcc/BASE-VER" ]; then
   158         make configure-libiberty
   159         make -C libiberty libiberty.a
   160         make configure-gcc
   161         make configure-libcpp
   162         make all-libcpp
   163     else
   164         make configure-gcc
   165         make configure-libcpp
   166         make configure-build-libiberty
   167         make all-libcpp
   168         make all-build-libiberty
   169     fi 2>&1 |CT_DoLog ALL
   170     # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
   171     if [ -d "${CT_SRC_DIR}/${CT_CC_FILE}/libdecnumber" ]; then
   172         make configure-libdecnumber
   173         make -C libdecnumber libdecnumber.a
   174     fi 2>&1 |CT_DoLog ALL
   175     make -C gcc libgcc.mk 2>&1 |CT_DoLog ALL
   176     sed -r -i -e 's@-lc@@g' gcc/libgcc.mk
   177 
   178     if [ "${CT_CANADIAN}" = "y" ]; then
   179         CT_DoLog EXTRA "Building libiberty"
   180         make ${PARALLELMFLAGS} all-build-libiberty 2>&1 |CT_DoLog ALL
   181     fi
   182 
   183     CT_DoLog EXTRA "Building shared core C compiler"
   184     make ${PARALLELMFLAGS} all-gcc 2>&1 |CT_DoLog ALL
   185 
   186     CT_DoLog EXTRA "Installing shared core C compiler"
   187     make install-gcc 2>&1 |CT_DoLog ALL
   188 
   189     CT_EndStep
   190 }
   191 
   192 #------------------------------------------------------------------------------
   193 # Build final gcc
   194 do_cc() {
   195     CT_DoStep INFO "Installing final compiler"
   196 
   197     mkdir -p "${CT_BUILD_DIR}/build-cc"
   198     cd "${CT_BUILD_DIR}/build-cc"
   199 
   200     CT_DoLog EXTRA "Configuring final compiler"
   201 
   202     # Enable selected languages
   203     lang_opt="c"
   204     [ "${CT_CC_LANG_CXX}" = "y"      ] && lang_opt="${lang_opt},c++"
   205     [ "${CT_CC_LANG_FORTRAN}" = "y"  ] && lang_opt="${lang_opt},fortran"
   206     [ "${CT_CC_LANG_ADA}" = "y"      ] && lang_opt="${lang_opt},ada"
   207     [ "${CT_CC_LANG_JAVA}" = "y"     ] && lang_opt="${lang_opt},java"
   208     [ "${CT_CC_LANG_OBJC}" = "y"     ] && lang_opt="${lang_opt},objc"
   209     [ "${CT_CC_LANG_OBJCXX}" = "y"   ] && lang_opt="${lang_opt},obj-c++"
   210     CT_Test "Building Fortran language is not yet supported. Will try..." "${CT_CC_LANG_FORTRAN}" = "y"
   211     CT_Test "Building ADA language is not yet supported. Will try..." "${CT_CC_LANG_ADA}" = "y"
   212     CT_Test "Building Java language is not yet supported. Will try..." "${CT_CC_LANG_JAVA}" = "y"
   213     CT_Test "Building Objective-C language is not yet supported. Will try..." "${CT_CC_LANG_OBJC}" = "y"
   214     CT_Test "Building Objective-C++ language is not yet supported. Will try..." "${CT_CC_LANG_OBJCXX}" = "y"
   215     CT_Test "Building ${CT_CC_LANG_OTHERS} language(s) is not yet supported. Will try..." -n "${CT_CC_LANG_OTHERS}"
   216     lang_opt=`echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;'`
   217 
   218     extra_config="--enable-languages=${lang_opt}"
   219     extra_config="${extra_config} ${CT_ARCH_WITH_ARCH} ${CT_ARCH_WITH_ABI} ${CT_ARCH_WITH_CPU} ${CT_ARCH_WITH_TUNE} ${CT_ARCH_WITH_FPU} ${CT_ARCH_WITH_FLOAT}"
   220     [ "${CT_SHARED_LIBS}" = "y" ] || extra_config="${extra_config} --disable-shared"
   221     [ "${CT_CC_CXA_ATEXIT}" == "y" ] && extra_config="${extra_config} --enable-__cxa_atexit"
   222     if [ "${CT_TARGET_MULTILIB}" = "y" ]; then
   223         extra_config="${extra_config} --enable-multilib"
   224     else
   225         extra_config="${extra_config} --disable-multilib"
   226     fi
   227 
   228     CT_DoLog DEBUG "Extra config passed: \"${extra_config}\""
   229 
   230     # --enable-symvers=gnu really only needed for sh4 to work around a
   231     # detection problem only matters for gcc-3.2.x and later, I think.
   232     # --disable-nls to work around crash bug on ppc405, but also because
   233     # embedded systems don't really need message catalogs...
   234     CFLAGS="${CT_CFLAGS_FOR_HOST}"              \
   235     TARGET_CFLAGS="${CT_TARGET_CFLAGS}"         \
   236     "${CT_SRC_DIR}/${CT_CC_FILE}/configure"     \
   237         ${CT_CANADIAN_OPT}                      \
   238         --target=${CT_TARGET} --host=${CT_HOST} \
   239         --prefix="${CT_PREFIX_DIR}"             \
   240         ${CC_SYSROOT_ARG}                       \
   241         ${extra_config}                         \
   242         --with-local-prefix="${CT_SYSROOT_DIR}" \
   243         --disable-nls                           \
   244         --enable-threads=posix                  \
   245         --enable-symvers=gnu                    \
   246         --enable-c99                            \
   247         --enable-long-long                      \
   248         ${CT_CC_EXTRA_CONFIG}                   2>&1 |CT_DoLog ALL
   249 
   250     if [ "${CT_CANADIAN}" = "y" ]; then
   251         CT_DoLog EXTRA "Building libiberty"
   252         make ${PARALLELMFLAGS} all-build-libiberty 2>&1 |CT_DoLog ALL
   253     fi
   254 
   255     # Idea from <cort.dougan at gmail.com>:
   256     # Fix lib/lib64 confusion for GCC 3.3.3 on PowerPC64 and x86_64.
   257     # GCC 3.4.0 and up don't suffer from this confusion, and don't need this
   258     # kludge.
   259     # FIXME: we should patch gcc's source rather than uglify crosstool.sh.
   260     # FIXME: is this needed for gcc-3.3.[56]?
   261     case "${CT_CC_FILE}" in
   262       gcc-3.3.[34])
   263         case "${CT_TARGET}" in
   264           powerpc64-unknown-linux-gnu|x86_64-unknown-linux-gnu)
   265             for d in `find "${CT_SYSROOT_DIR}" -name lib -type d -empty`; do
   266               if [ -d `dirname "${d}"`/lib64 ] ; then
   267                 rm -rf "${d}"
   268                 ln -s `dirname "${d}"`/lib64 "${d}"
   269               fi
   270             done ;;
   271           *) ;;
   272         esac ;;
   273     esac
   274 
   275     CT_DoLog EXTRA "Building final compiler"
   276     make ${PARALLELMFLAGS} all 2>&1 |CT_DoLog ALL
   277 
   278     CT_DoLog EXTRA "Installing final compiler"
   279     make install 2>&1 |CT_DoLog ALL
   280 
   281     # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
   282     # to call the C compiler with the same, somewhat canonical name.
   283     ln "${CT_PREFIX_DIR}/bin/${CT_TARGET}"-{g,}cc
   284 
   285     # gcc installs stuff in prefix/target/lib, when it would make better sense
   286     # to install that into sysroot/usr/lib
   287     CT_DoLog EXTRA "Moving improperly installed gcc libs to sysroot"
   288     ( cd "${CT_PREFIX_DIR}/${CT_TARGET}/lib"; tar cf - . ) | ( cd "${CT_SYSROOT_DIR}/usr/lib"; tar xfv - )
   289 
   290     CT_EndStep
   291 }