scripts/build/cc_gcc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sat May 24 22:49:54 2008 +0000 (2008-05-24)
changeset 532 0faef1ae3f09
parent 528 38e382b3829e
child 533 81a582c81c13
permissions -rw-r--r--
Multilib is gone, so don't use it when building gcc.

/trunk/scripts/build/cc_gcc.sh | 6 1 5 0 +-----
1 file changed, 1 insertion(+), 5 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 EXTRA "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_CC_GCC_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_SRC_DIR}/${CT_CC_FILE}/configure"         \
    75         ${CT_CANADIAN_OPT}                          \
    76         --host=${CT_HOST}                           \
    77         --target=${CT_TARGET}                       \
    78         --prefix="${CT_CC_CORE_STATIC_PREFIX_DIR}"  \
    79         --with-local-prefix="${CT_SYSROOT_DIR}"     \
    80         --disable-multilib                          \
    81         --with-newlib                               \
    82         ${CC_CORE_SYSROOT_ARG}                      \
    83         ${extra_config}                             \
    84         --disable-nls                               \
    85         --enable-threads=no                         \
    86         --enable-symvers=gnu                        \
    87         --enable-languages=c                        \
    88         --disable-shared                            \
    89         --enable-target-optspace                    \
    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_GCC_GMP_MPFR}" = "y" ] && extra_config="${extra_config} --with-gmp=${CT_PREFIX_DIR} --with-mpfr=${CT_PREFIX_DIR}"
   122     if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
   123         extra_config="${extra_config} --enable-__cxa_atexit"
   124     else
   125         extra_config="${extra_config} --disable-__cxa_atexit"
   126     fi
   127 
   128     CT_DoLog DEBUG "Extra config passed: '${extra_config}'"
   129 
   130     CC_FOR_BUILD="${CT_CC_NATIVE}"                  \
   131     CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
   132     "${CT_SRC_DIR}/${CT_CC_FILE}/configure"         \
   133         ${CT_CANADIAN_OPT}                          \
   134         --target=${CT_TARGET}                       \
   135         --host=${CT_HOST}                           \
   136         --prefix="${CT_CC_CORE_SHARED_PREFIX_DIR}"  \
   137         --with-local-prefix="${CT_SYSROOT_DIR}"     \
   138         --disable-multilib                          \
   139         ${CC_CORE_SYSROOT_ARG}                      \
   140         ${extra_config}                             \
   141         --disable-nls                               \
   142         --enable-symvers=gnu                        \
   143         --enable-languages=c                        \
   144         --enable-shared                             \
   145         --enable-target-optspace                    \
   146         ${CT_CC_CORE_EXTRA_CONFIG}                  2>&1 |CT_DoLog ALL
   147 
   148     # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
   149     # gcc/config/t-libunwind so -lc is removed from the link for
   150     # libgcc_s.so, as we do not have a target -lc yet.
   151     # This is not as ugly as it appears to be ;-) All symbols get resolved
   152     # during the glibc build, and we provide a proper libgcc_s.so for the
   153     # cross toolchain during the final gcc build.
   154     #
   155     # As we cannot modify the source tree, nor override SHLIB_LC itself
   156     # during configure or make, we have to edit the resultant
   157     # gcc/libgcc.mk itself to remove -lc from the link.
   158     # This causes us to have to jump through some hoops...
   159     #
   160     # To produce libgcc.mk to edit we firstly require libiberty.a,
   161     # so we configure then build it.
   162     # Next we have to configure gcc, create libgcc.mk then edit it...
   163     # So much easier if we just edit the source tree, but hey...
   164     if [ ! -f "${CT_SRC_DIR}/${CT_CC_FILE}/gcc/BASE-VER" ]; then
   165         make configure-libiberty
   166         make -C libiberty libiberty.a
   167         make configure-gcc
   168         make configure-libcpp
   169         make all-libcpp
   170     else
   171         make configure-gcc
   172         make configure-libcpp
   173         make configure-build-libiberty
   174         make all-libcpp
   175         make all-build-libiberty
   176     fi 2>&1 |CT_DoLog ALL
   177     # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
   178     if [ -d "${CT_SRC_DIR}/${CT_CC_FILE}/libdecnumber" ]; then
   179         make configure-libdecnumber
   180         make -C libdecnumber libdecnumber.a
   181     fi 2>&1 |CT_DoLog ALL
   182     make -C gcc libgcc.mk 2>&1 |CT_DoLog ALL
   183     sed -r -i -e 's@-lc@@g' gcc/libgcc.mk
   184 
   185     if [ "${CT_CANADIAN}" = "y" ]; then
   186         CT_DoLog EXTRA "Building libiberty"
   187         make ${PARALLELMFLAGS} all-build-libiberty 2>&1 |CT_DoLog ALL
   188     fi
   189 
   190     CT_DoLog EXTRA "Building shared core C compiler"
   191     make ${PARALLELMFLAGS} all-gcc 2>&1 |CT_DoLog ALL
   192 
   193     CT_DoLog EXTRA "Installing shared core C compiler"
   194     make install-gcc 2>&1 |CT_DoLog ALL
   195 
   196     CT_EndStep
   197 }
   198 
   199 #------------------------------------------------------------------------------
   200 # Build final gcc
   201 do_cc() {
   202     CT_DoStep INFO "Installing final compiler"
   203 
   204     mkdir -p "${CT_BUILD_DIR}/build-cc"
   205     cd "${CT_BUILD_DIR}/build-cc"
   206 
   207     CT_DoLog EXTRA "Configuring final compiler"
   208 
   209     # Enable selected languages
   210     lang_opt="c"
   211     [ "${CT_CC_LANG_CXX}" = "y"      ] && lang_opt="${lang_opt},c++"
   212     [ "${CT_CC_LANG_FORTRAN}" = "y"  ] && lang_opt="${lang_opt},fortran"
   213     [ "${CT_CC_LANG_ADA}" = "y"      ] && lang_opt="${lang_opt},ada"
   214     [ "${CT_CC_LANG_JAVA}" = "y"     ] && lang_opt="${lang_opt},java"
   215     [ "${CT_CC_LANG_OBJC}" = "y"     ] && lang_opt="${lang_opt},objc"
   216     [ "${CT_CC_LANG_OBJCXX}" = "y"   ] && lang_opt="${lang_opt},obj-c++"
   217     CT_Test "Building ADA language is not yet supported. Will try..." "${CT_CC_LANG_ADA}" = "y"
   218     CT_Test "Building Objective-C language is not yet supported. Will try..." "${CT_CC_LANG_OBJC}" = "y"
   219     CT_Test "Building Objective-C++ language is not yet supported. Will try..." "${CT_CC_LANG_OBJCXX}" = "y"
   220     CT_Test "Building ${CT_CC_LANG_OTHERS//,/ } language(s) is not yet supported. Will try..." -n "${CT_CC_LANG_OTHERS}"
   221     lang_opt=$(echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;')
   222 
   223     extra_config="--enable-languages=${lang_opt}"
   224     extra_config="${extra_config} --disable-multilib"
   225     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}"
   226     [ "${CT_SHARED_LIBS}" = "y" ] || extra_config="${extra_config} --disable-shared"
   227     if [ "${CT_CC_CXA_ATEXIT}" = "y" ]; then
   228         extra_config="${extra_config} --enable-__cxa_atexit"
   229     else
   230         extra_config="${extra_config} --disable-__cxa_atexit"
   231     fi
   232     [ "${CT_CC_GCC_GMP_MPFR}" = "y" ] && extra_config="${extra_config} --with-gmp=${CT_PREFIX_DIR} --with-mpfr=${CT_PREFIX_DIR}"
   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     TARGET_CFLAGS="${CT_TARGET_CFLAGS}"         \
   243     "${CT_SRC_DIR}/${CT_CC_FILE}/configure"     \
   244         ${CT_CANADIAN_OPT}                      \
   245         --target=${CT_TARGET} --host=${CT_HOST} \
   246         --prefix="${CT_PREFIX_DIR}"             \
   247         ${CC_SYSROOT_ARG}                       \
   248         ${extra_config}                         \
   249         --with-local-prefix="${CT_SYSROOT_DIR}" \
   250         --disable-nls                           \
   251         --enable-threads=posix                  \
   252         --enable-symvers=gnu                    \
   253         --enable-c99                            \
   254         --enable-long-long                      \
   255         --enable-target-optspace                \
   256         ${CT_CC_EXTRA_CONFIG}                   2>&1 |CT_DoLog ALL
   257 
   258     if [ "${CT_CANADIAN}" = "y" ]; then
   259         CT_DoLog EXTRA "Building libiberty"
   260         make ${PARALLELMFLAGS} all-build-libiberty 2>&1 |CT_DoLog ALL
   261     fi
   262 
   263     # Idea from <cort.dougan at gmail.com>:
   264     # Fix lib/lib64 confusion for GCC 3.3.3 on PowerPC64 and x86_64.
   265     # GCC 3.4.0 and up don't suffer from this confusion, and don't need this
   266     # kludge.
   267     # FIXME: we should patch gcc's source rather than uglify crosstool.sh.
   268     # FIXME: is this needed for gcc-3.3.[56]?
   269     case "${CT_CC_FILE}" in
   270       gcc-3.3.[34])
   271         case "${CT_TARGET}" in
   272           powerpc64-unknown-linux-gnu|x86_64-unknown-linux-gnu)
   273             for d in $(find "${CT_SYSROOT_DIR}" -name lib -type d -empty); do
   274               if [ -d $(dirname "${d}")/lib64 ] ; then
   275                 rm -rf "${d}"
   276                 ln -s $(dirname "${d}")/lib64 "${d}"
   277               fi
   278             done ;;
   279           *) ;;
   280         esac ;;
   281     esac
   282 
   283     CT_DoLog EXTRA "Building final compiler"
   284     make ${PARALLELMFLAGS} all 2>&1 |CT_DoLog ALL
   285 
   286     CT_DoLog EXTRA "Installing final compiler"
   287     make install 2>&1 |CT_DoLog ALL
   288 
   289     # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
   290     # to call the C compiler with the same, somewhat canonical name.
   291     ln "${CT_PREFIX_DIR}/bin/${CT_TARGET}"-{g,}cc
   292 
   293     # gcc installs stuff in prefix/target/lib, when it would make better sense
   294     # to install that into sysroot/usr/lib
   295     CT_DoLog EXTRA "Moving improperly installed gcc libs to sysroot"
   296     ( cd "${CT_PREFIX_DIR}/${CT_TARGET}/lib"; tar cf - . ) | ( cd "${CT_SYSROOT_DIR}/usr/lib"; tar xfv - )
   297 
   298     CT_EndStep
   299 }