scripts/build/cc_gcc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed May 14 17:56:33 2008 +0000 (2008-05-14)
changeset 501 a7da743b324f
parent 486 92f6149c4275
child 523 010f6f4e4dd6
child 529 a62cf50e2d86
permissions -rw-r--r--
Sanitise and use CT_CC_NATIVE.
Comment inclusion of scripts/functions.

/trunk/scripts/build/cc_gcc.sh | 6 6 0 0 ++++++
/trunk/scripts/crosstool.sh | 7 6 1 0 ++++++-
2 files changed, 12 insertions(+), 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     CC_FOR_BUILD="${CT_CC_NATIVE}"                  \
    69     CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
    70     "${CT_SRC_DIR}/${CT_CC_FILE}/configure"         \
    71         ${CT_CANADIAN_OPT}                          \
    72         --host=${CT_HOST}                           \
    73         --target=${CT_TARGET}                       \
    74         --prefix="${CT_CC_CORE_STATIC_PREFIX_DIR}"  \
    75         --with-local-prefix="${CT_SYSROOT_DIR}"     \
    76         --disable-multilib                          \
    77         --with-newlib                               \
    78         ${CC_CORE_SYSROOT_ARG}                      \
    79         ${extra_config}                             \
    80         --disable-nls                               \
    81         --enable-threads=no                         \
    82         --enable-symvers=gnu                        \
    83         --enable-languages=c                        \
    84         --disable-shared                            \
    85         --enable-target-optspace                    \
    86         ${CT_CC_CORE_EXTRA_CONFIG}                  2>&1 |CT_DoLog ALL
    87 
    88     if [ "${CT_CANADIAN}" = "y" ]; then
    89         CT_DoLog EXTRA "Building libiberty"
    90         make ${PARALLELMFLAGS} all-build-libiberty 2>&1 |CT_DoLog ALL
    91     fi
    92 
    93     CT_DoLog EXTRA "Building static core C compiler"
    94     make ${PARALLELMFLAGS} all-gcc 2>&1 |CT_DoLog ALL
    95 
    96     CT_DoLog EXTRA "Installing static core C compiler"
    97     make install-gcc 2>&1 |CT_DoLog ALL
    98 
    99     CT_EndStep
   100 }
   101 
   102 #------------------------------------------------------------------------------
   103 # Build shared core gcc
   104 do_cc_core_shared() {
   105     mkdir -p "${CT_BUILD_DIR}/build-cc-core-shared"
   106     cd "${CT_BUILD_DIR}/build-cc-core-shared"
   107 
   108     CT_DoStep INFO "Installing shared core C compiler"
   109 
   110     CT_DoLog EXTRA "Copying headers to install area of bootstrap gcc, so it can build libgcc2"
   111     mkdir -p "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include"
   112     cp -r "${CT_HEADERS_DIR}"/* "${CT_CC_CORE_SHARED_PREFIX_DIR}/${CT_TARGET}/include" 2>&1 |CT_DoLog DEBUG
   113 
   114     CT_DoLog EXTRA "Configuring shared core C compiler"
   115 
   116     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}"
   117     [ "${CT_CC_CXA_ATEXIT}" = "y" ] && extra_config="${extra_config} --enable-__cxa_atexit"
   118     [ "${CT_CC_GCC_GMP_MPFR}" = "y" ] && extra_config="${extra_config} --with-gmp=${CT_PREFIX_DIR} --with-mpfr=${CT_PREFIX_DIR}"
   119 
   120     CT_DoLog DEBUG "Extra config passed: \"${extra_config}\""
   121 
   122     CC_FOR_BUILD="${CT_CC_NATIVE}"                  \
   123     CFLAGS="${CT_CFLAGS_FOR_HOST}"                  \
   124     "${CT_SRC_DIR}/${CT_CC_FILE}/configure"         \
   125         ${CT_CANADIAN_OPT}                          \
   126         --target=${CT_TARGET}                       \
   127         --host=${CT_HOST}                           \
   128         --prefix="${CT_CC_CORE_SHARED_PREFIX_DIR}"  \
   129         --with-local-prefix="${CT_SYSROOT_DIR}"     \
   130         --disable-multilib                          \
   131         ${CC_CORE_SYSROOT_ARG}                      \
   132         ${extra_config}                             \
   133         --disable-nls                               \
   134         --enable-symvers=gnu                        \
   135         --enable-languages=c                        \
   136         --enable-shared                             \
   137         --enable-target-optspace                    \
   138         ${CT_CC_CORE_EXTRA_CONFIG}                  2>&1 |CT_DoLog ALL
   139 
   140     # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
   141     # gcc/config/t-libunwind so -lc is removed from the link for
   142     # libgcc_s.so, as we do not have a target -lc yet.
   143     # This is not as ugly as it appears to be ;-) All symbols get resolved
   144     # during the glibc build, and we provide a proper libgcc_s.so for the
   145     # cross toolchain during the final gcc build.
   146     #
   147     # As we cannot modify the source tree, nor override SHLIB_LC itself
   148     # during configure or make, we have to edit the resultant
   149     # gcc/libgcc.mk itself to remove -lc from the link.
   150     # This causes us to have to jump through some hoops...
   151     #
   152     # To produce libgcc.mk to edit we firstly require libiberty.a,
   153     # so we configure then build it.
   154     # Next we have to configure gcc, create libgcc.mk then edit it...
   155     # So much easier if we just edit the source tree, but hey...
   156     if [ ! -f "${CT_SRC_DIR}/${CT_CC_FILE}/gcc/BASE-VER" ]; then
   157         make configure-libiberty
   158         make -C libiberty libiberty.a
   159         make configure-gcc
   160         make configure-libcpp
   161         make all-libcpp
   162     else
   163         make configure-gcc
   164         make configure-libcpp
   165         make configure-build-libiberty
   166         make all-libcpp
   167         make all-build-libiberty
   168     fi 2>&1 |CT_DoLog ALL
   169     # HACK: gcc-4.2 uses libdecnumber to build libgcc.mk, so build it here.
   170     if [ -d "${CT_SRC_DIR}/${CT_CC_FILE}/libdecnumber" ]; then
   171         make configure-libdecnumber
   172         make -C libdecnumber libdecnumber.a
   173     fi 2>&1 |CT_DoLog ALL
   174     make -C gcc libgcc.mk 2>&1 |CT_DoLog ALL
   175     sed -r -i -e 's@-lc@@g' gcc/libgcc.mk
   176 
   177     if [ "${CT_CANADIAN}" = "y" ]; then
   178         CT_DoLog EXTRA "Building libiberty"
   179         make ${PARALLELMFLAGS} all-build-libiberty 2>&1 |CT_DoLog ALL
   180     fi
   181 
   182     CT_DoLog EXTRA "Building shared core C compiler"
   183     make ${PARALLELMFLAGS} all-gcc 2>&1 |CT_DoLog ALL
   184 
   185     CT_DoLog EXTRA "Installing shared core C compiler"
   186     make install-gcc 2>&1 |CT_DoLog ALL
   187 
   188     CT_EndStep
   189 }
   190 
   191 #------------------------------------------------------------------------------
   192 # Build final gcc
   193 do_cc() {
   194     CT_DoStep INFO "Installing final compiler"
   195 
   196     mkdir -p "${CT_BUILD_DIR}/build-cc"
   197     cd "${CT_BUILD_DIR}/build-cc"
   198 
   199     CT_DoLog EXTRA "Configuring final compiler"
   200 
   201     # Enable selected languages
   202     lang_opt="c"
   203     [ "${CT_CC_LANG_CXX}" = "y"      ] && lang_opt="${lang_opt},c++"
   204     [ "${CT_CC_LANG_FORTRAN}" = "y"  ] && lang_opt="${lang_opt},fortran"
   205     [ "${CT_CC_LANG_ADA}" = "y"      ] && lang_opt="${lang_opt},ada"
   206     [ "${CT_CC_LANG_JAVA}" = "y"     ] && lang_opt="${lang_opt},java"
   207     [ "${CT_CC_LANG_OBJC}" = "y"     ] && lang_opt="${lang_opt},objc"
   208     [ "${CT_CC_LANG_OBJCXX}" = "y"   ] && lang_opt="${lang_opt},obj-c++"
   209     CT_Test "Building ADA language is not yet supported. Will try..." "${CT_CC_LANG_ADA}" = "y"
   210     CT_Test "Building Objective-C language is not yet supported. Will try..." "${CT_CC_LANG_OBJC}" = "y"
   211     CT_Test "Building Objective-C++ language is not yet supported. Will try..." "${CT_CC_LANG_OBJCXX}" = "y"
   212     CT_Test "Building ${CT_CC_LANG_OTHERS//,/ } language(s) is not yet supported. Will try..." -n "${CT_CC_LANG_OTHERS}"
   213     lang_opt=`echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;'`
   214 
   215     extra_config="--enable-languages=${lang_opt}"
   216     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}"
   217     [ "${CT_SHARED_LIBS}" = "y" ] || extra_config="${extra_config} --disable-shared"
   218     [ "${CT_CC_CXA_ATEXIT}" == "y" ] && extra_config="${extra_config} --enable-__cxa_atexit"
   219     if [ "${CT_TARGET_MULTILIB}" = "y" ]; then
   220         extra_config="${extra_config} --enable-multilib"
   221     else
   222         extra_config="${extra_config} --disable-multilib"
   223     fi
   224     [ "${CT_CC_GCC_GMP_MPFR}" = "y" ] && extra_config="${extra_config} --with-gmp=${CT_PREFIX_DIR} --with-mpfr=${CT_PREFIX_DIR}"
   225 
   226     CT_DoLog DEBUG "Extra config passed: \"${extra_config}\""
   227 
   228     # --enable-symvers=gnu really only needed for sh4 to work around a
   229     # detection problem only matters for gcc-3.2.x and later, I think.
   230     # --disable-nls to work around crash bug on ppc405, but also because
   231     # embedded systems don't really need message catalogs...
   232     CC_FOR_BUILD="${CT_CC_NATIVE}"              \
   233     CFLAGS="${CT_CFLAGS_FOR_HOST}"              \
   234     TARGET_CFLAGS="${CT_TARGET_CFLAGS}"         \
   235     "${CT_SRC_DIR}/${CT_CC_FILE}/configure"     \
   236         ${CT_CANADIAN_OPT}                      \
   237         --target=${CT_TARGET} --host=${CT_HOST} \
   238         --prefix="${CT_PREFIX_DIR}"             \
   239         ${CC_SYSROOT_ARG}                       \
   240         ${extra_config}                         \
   241         --with-local-prefix="${CT_SYSROOT_DIR}" \
   242         --disable-nls                           \
   243         --enable-threads=posix                  \
   244         --enable-symvers=gnu                    \
   245         --enable-c99                            \
   246         --enable-long-long                      \
   247         --enable-target-optspace                \
   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 }