scripts/build/cc_gcc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jul 27 14:28:36 2008 +0000 (2008-07-27)
branch1.2
changeset 739 8ebf5ea601d8
parent 645 8e58024f8e37
child 715 75a451191a0a
child 742 0aabeb36e6ae
permissions -rw-r--r--
Backport #876 from trunk:
Re-enable the restart functionality by removing some variables from the saved environment.

/branches/1.2/scripts/functions | 16 10 6 0 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
     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 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,http}://ftp.gnu.org/gnu/gcc{,{,/releases}/${CT_CC_FILE}}
    20 }
    21 
    22 # Extract gcc
    23 do_cc_extract() {
    24     CT_ExtractAndPatch "${CT_CC_FILE}"
    25 }
    26 
    27 #------------------------------------------------------------------------------
    28 # Core gcc pass 1
    29 do_cc_core_pass_1() {
    30     # In case we're NPTL, build the static core gcc;
    31     # in any other case, do nothing.
    32     case "${CT_THREADS}" in
    33         nptl)   do_cc_core_static;;
    34     esac
    35 }
    36 
    37 # Core gcc pass 2
    38 do_cc_core_pass_2() {
    39     # In case we're NPTL, build the shared core gcc,
    40     # in any other case, build the static core gcc.
    41     case "${CT_THREADS}" in
    42         nptl)   do_cc_core_shared;;
    43         *)      do_cc_core_static;;
    44     esac
    45 }
    46 
    47 #------------------------------------------------------------------------------
    48 # Build static core gcc
    49 do_cc_core_static() {
    50     mkdir -p "${CT_BUILD_DIR}/build-cc-core-static"
    51     cd "${CT_BUILD_DIR}/build-cc-core-static"
    52 
    53     CT_DoStep INFO "Installing static core C compiler"
    54 
    55     CT_DoLog DEBUG "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
    56     mkdir -p "${CT_CC_CORE_STATIC_PREFIX_DIR}/${CT_TARGET}/include"
    57     cp -r "${CT_HEADERS_DIR}"/* "${CT_CC_CORE_STATIC_PREFIX_DIR}/${CT_TARGET}/include" 2>&1 |CT_DoLog DEBUG
    58 
    59     CT_DoLog EXTRA "Configuring static core C compiler"
    60 
    61     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}"
    62     [ "${CT_GMP_MPFR}" = "y" ] && extra_config="${extra_config} --with-gmp=${CT_PREFIX_DIR} --with-mpfr=${CT_PREFIX_DIR}"
    63     if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
    64         extra_config="${extra_config} --enable-__cxa_atexit"
    65     else
    66         extra_config="${extra_config} --disable-__cxa_atexit"
    67     fi
    68 
    69     CT_DoLog DEBUG "Extra config passed: '${extra_config}'"
    70 
    71     # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
    72     CC_FOR_BUILD="${CT_CC_NATIVE}"                  \
    73     CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
    74     CT_DoExecLog ALL                                \
    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         --enable-target-optspace                    \
    91         ${CT_CC_CORE_EXTRA_CONFIG}
    92 
    93     if [ "${CT_CANADIAN}" = "y" ]; then
    94         CT_DoLog EXTRA "Building libiberty"
    95         CT_DoExecLog ALL make ${PARALLELMFLAGS} all-build-libiberty
    96     fi
    97 
    98     CT_DoLog EXTRA "Building static core C compiler"
    99     CT_DoExecLog ALL make ${PARALLELMFLAGS} all-gcc
   100 
   101     CT_DoLog EXTRA "Installing static core C compiler"
   102     CT_DoExecLog ALL make install-gcc
   103 
   104     CT_EndStep
   105 }
   106 
   107 #------------------------------------------------------------------------------
   108 # Build shared core gcc
   109 do_cc_core_shared() {
   110     mkdir -p "${CT_BUILD_DIR}/build-cc-core-shared"
   111     cd "${CT_BUILD_DIR}/build-cc-core-shared"
   112 
   113     CT_DoStep INFO "Installing shared core C compiler"
   114 
   115     CT_DoLog DEBUG "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
   116     mkdir -p "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include"
   117     cp -r "${CT_HEADERS_DIR}"/* "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include" 2>&1 |CT_DoLog DEBUG
   118 
   119     CT_DoLog EXTRA "Configuring shared core C compiler"
   120 
   121     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}"
   122     [ "${CT_GMP_MPFR}" = "y" ] && extra_config="${extra_config} --with-gmp=${CT_PREFIX_DIR} --with-mpfr=${CT_PREFIX_DIR}"
   123     if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
   124         extra_config="${extra_config} --enable-__cxa_atexit"
   125     else
   126         extra_config="${extra_config} --disable-__cxa_atexit"
   127     fi
   128 
   129     CT_DoLog DEBUG "Extra config passed: '${extra_config}'"
   130 
   131     CC_FOR_BUILD="${CT_CC_NATIVE}"                  \
   132     CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
   133     CT_DoExecLog ALL                                \
   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         --enable-target-optspace                    \
   148         ${CT_CC_CORE_EXTRA_CONFIG}
   149 
   150     # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
   151     # gcc/config/t-libunwind so -lc is removed from the link for
   152     # libgcc_s.so, as we do not have a target -lc yet.
   153     # This is not as ugly as it appears to be ;-) All symbols get resolved
   154     # during the glibc build, and we provide a proper libgcc_s.so for the
   155     # cross toolchain during the final gcc build.
   156     #
   157     # As we cannot modify the source tree, nor override SHLIB_LC itself
   158     # during configure or make, we have to edit the resultant
   159     # gcc/libgcc.mk itself to remove -lc from the link.
   160     # This causes us to have to jump through some hoops...
   161     #
   162     # To produce libgcc.mk to edit we firstly require libiberty.a,
   163     # so we configure then build it.
   164     # Next we have to configure gcc, create libgcc.mk then edit it...
   165     # So much easier if we just edit the source tree, but hey...
   166     if [ ! -f "${CT_SRC_DIR}/${CT_CC_FILE}/gcc/BASE-VER" ]; then
   167         CT_DoExecLog ALL make configure-libiberty
   168         CT_DoExecLog ALL make ${PARALLELMFLAGS} -C libiberty libiberty.a
   169         CT_DoExecLog ALL make configure-gcc configure-libcpp
   170         CT_DoExecLog ALL make ${PARALLELMFLAGS} all-libcpp
   171     else
   172         CT_DoExecLog ALL make configure-gcc configure-libcpp configure-build-libiberty
   173         CT_DoExecLog ALL make ${PARALLELMFLAGS} all-libcpp all-build-libiberty
   174     fi
   175     # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
   176     if [ -d "${CT_SRC_DIR}/${CT_CC_FILE}/libdecnumber" ]; then
   177         CT_DoExecLog ALL make configure-libdecnumber
   178         CT_DoExecLog ALL make ${PARALLELMFLAGS} -C libdecnumber libdecnumber.a
   179     fi
   180     CT_DoExecLog ALL make -C gcc libgcc.mk
   181     sed -r -i -e 's@-lc@@g' gcc/libgcc.mk
   182 
   183     if [ "${CT_CANADIAN}" = "y" ]; then
   184         CT_DoLog EXTRA "Building libiberty"
   185         CT_DoExecLog ALL make ${PARALLELMFLAGS} all-build-libiberty
   186     fi
   187 
   188     CT_DoLog EXTRA "Building shared core C compiler"
   189     CT_DoExecLog ALL make ${PARALLELMFLAGS} all-gcc
   190 
   191     CT_DoLog EXTRA "Installing shared core C compiler"
   192     CT_DoExecLog ALL make install-gcc
   193 
   194     CT_EndStep
   195 }
   196 
   197 #------------------------------------------------------------------------------
   198 # Build final gcc
   199 do_cc() {
   200     CT_DoStep INFO "Installing final compiler"
   201 
   202     mkdir -p "${CT_BUILD_DIR}/build-cc"
   203     cd "${CT_BUILD_DIR}/build-cc"
   204 
   205     CT_DoLog EXTRA "Configuring final compiler"
   206 
   207     # Enable selected languages
   208     lang_opt="c"
   209     [ "${CT_CC_LANG_CXX}" = "y"      ] && lang_opt="${lang_opt},c++"
   210     [ "${CT_CC_LANG_FORTRAN}" = "y"  ] && lang_opt="${lang_opt},fortran"
   211     [ "${CT_CC_LANG_ADA}" = "y"      ] && lang_opt="${lang_opt},ada"
   212     [ "${CT_CC_LANG_JAVA}" = "y"     ] && lang_opt="${lang_opt},java"
   213     [ "${CT_CC_LANG_OBJC}" = "y"     ] && lang_opt="${lang_opt},objc"
   214     [ "${CT_CC_LANG_OBJCXX}" = "y"   ] && lang_opt="${lang_opt},obj-c++"
   215     CT_Test "Building ADA language is not yet supported. Will try..." "${CT_CC_LANG_ADA}" = "y"
   216     CT_Test "Building Objective-C language is not yet supported. Will try..." "${CT_CC_LANG_OBJC}" = "y"
   217     CT_Test "Building Objective-C++ language is not yet supported. Will try..." "${CT_CC_LANG_OBJCXX}" = "y"
   218     CT_Test "Building ${CT_CC_LANG_OTHERS//,/ } language(s) is not yet supported. Will try..." -n "${CT_CC_LANG_OTHERS}"
   219     lang_opt=$(echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;')
   220 
   221     extra_config="--enable-languages=${lang_opt}"
   222     extra_config="${extra_config} --disable-multilib"
   223     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}"
   224     [ "${CT_SHARED_LIBS}" = "y" ]     || extra_config="${extra_config} --disable-shared"
   225     [ "${CT_GMP_MPFR}" = "y" ] && extra_config="${extra_config} --with-gmp=${CT_PREFIX_DIR} --with-mpfr=${CT_PREFIX_DIR}"
   226     [ -n "${CT_CC_PKGVERSION}" ]      && extra_config="${extra_config} --with-pkgversion=${CT_CC_PKGVERSION}"
   227     [ -n "${CT_CC_BUGURL}" ]          && extra_config="${extra_config} --with-bugurl=${CT_CC_BUGURL}"
   228     if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
   229         extra_config="${extra_config} --enable-__cxa_atexit"
   230     else
   231         extra_config="${extra_config} --disable-__cxa_atexit"
   232     fi
   233 
   234     CT_DoLog DEBUG "Extra config passed: '${extra_config}'"
   235 
   236     # --enable-symvers=gnu really only needed for sh4 to work around a
   237     # detection problem only matters for gcc-3.2.x and later, I think.
   238     # --disable-nls to work around crash bug on ppc405, but also because
   239     # embedded systems don't really need message catalogs...
   240     CC_FOR_BUILD="${CT_CC_NATIVE}"              \
   241     CFLAGS="${CT_CFLAGS_FOR_HOST}"              \
   242     CFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}"     \
   243     CXXFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}"   \
   244     LDFLAGS_FOR_TARGET="${CT_TARGET_LDFLAGS}"   \
   245     CT_DoExecLog ALL                            \
   246     "${CT_SRC_DIR}/${CT_CC_FILE}/configure"     \
   247         ${CT_CANADIAN_OPT}                      \
   248         --target=${CT_TARGET} --host=${CT_HOST} \
   249         --prefix="${CT_PREFIX_DIR}"             \
   250         ${CC_SYSROOT_ARG}                       \
   251         ${extra_config}                         \
   252         --with-local-prefix="${CT_SYSROOT_DIR}" \
   253         --disable-nls                           \
   254         --enable-threads=posix                  \
   255         --enable-symvers=gnu                    \
   256         --enable-c99                            \
   257         --enable-long-long                      \
   258         --enable-target-optspace                \
   259         ${CT_CC_EXTRA_CONFIG}
   260 
   261     if [ "${CT_CANADIAN}" = "y" ]; then
   262         CT_DoLog EXTRA "Building libiberty"
   263         CT_DoExecLog ALL make ${PARALLELMFLAGS} all-build-libiberty
   264     fi
   265 
   266     # Idea from <cort.dougan at gmail.com>:
   267     # Fix lib/lib64 confusion for GCC 3.3.3 on PowerPC64 and x86_64.
   268     # GCC 3.4.0 and up don't suffer from this confusion, and don't need this
   269     # kludge.
   270     # FIXME: we should patch gcc's source rather than uglify crosstool.sh.
   271     # FIXME: is this needed for gcc-3.3.[56]?
   272     case "${CT_CC_FILE}" in
   273       gcc-3.3.[34])
   274         case "${CT_TARGET}" in
   275           powerpc64-unknown-linux-gnu|x86_64-unknown-linux-gnu)
   276             for d in $(find "${CT_SYSROOT_DIR}" -name lib -type d -empty); do
   277               if [ -d $(dirname "${d}")/lib64 ] ; then
   278                 rm -rf "${d}"
   279                 ln -s $(dirname "${d}")/lib64 "${d}"
   280               fi
   281             done ;;
   282           *) ;;
   283         esac ;;
   284     esac
   285 
   286     CT_DoLog EXTRA "Building final compiler"
   287     CT_DoExecLog ALL make ${PARALLELMFLAGS} all
   288 
   289     CT_DoLog EXTRA "Installing final compiler"
   290     CT_DoExecLog ALL make install
   291 
   292     # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
   293     # to call the C compiler with the same, somewhat canonical name.
   294     ln -sv "${CT_PREFIX_DIR}/bin/${CT_TARGET}"-{g,}cc 2>&1 |CT_DoLog ALL
   295 
   296     # gcc installs stuff in prefix/target/lib, when it would make better sense
   297     # to install that into sysroot/usr/lib
   298     CT_DoLog EXTRA "Moving improperly installed gcc libs to sysroot"
   299     ( cd "${CT_PREFIX_DIR}/${CT_TARGET}/lib"; tar cf - . ) | ( cd "${CT_SYSROOT_DIR}/usr/lib"; tar xfv - ) |CT_DoLog ALL
   300     rm -rf "${CT_PREFIX_DIR}/${CT_TARGET}/lib"
   301 
   302     CT_EndStep
   303 }