scripts/build/cc_gcc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed Apr 30 10:43:41 2008 +0000 (2008-04-30)
changeset 466 7f9bbf94b0bb
parent 462 b959799c9a36
child 486 92f6149c4275
permissions -rw-r--r--
Merge the fortran stuff to trunk now it works!
Fortran is not supported for all targets, though. ARM at least does not work.

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