scripts/build/cc_gcc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun May 04 10:46:32 2008 +0000 (2008-05-04)
changeset 491 85e0330f8715
parent 466 7f9bbf94b0bb
child 501 a7da743b324f
permissions -rw-r--r--
Bump up version to 1.1.0+svn.

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