scripts/build/libc/glibc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed Jan 13 20:46:01 2010 +0100 (2010-01-13)
changeset 1732 6b2ae7804c6f
parent 1641 fce0c507c9e5
child 1747 8e8b72bdcea0
permissions -rw-r--r--
debug/gdb: staticaly link to ncurses for the native gdb

Staticaly link the native gdb (the one that runs on the target,
not the cross one that runs on the host) to ncurses.
     1 # This file adds functions to build glibc
     2 # Copyright 2007 Yann E. MORIN
     3 # Licensed under the GPL v2. See COPYING in the root of this package
     4 
     5 # Download glibc
     6 do_libc_get() {
     7     local date
     8     local version
     9     local -a addons_list
    10 
    11     addons_list=($(do_libc_add_ons_list " "))
    12 
    13     if [ "${CT_LIBC_GLIBC_TARBALL}" = "y" ]; then
    14         # Use release tarballs
    15         CT_GetFile "glibc-${CT_LIBC_VERSION}"               \
    16                    {ftp,http}://ftp.gnu.org/gnu/glibc       \
    17                    ftp://gcc.gnu.org/pub/glibc/releases     \
    18                    ftp://gcc.gnu.org/pub/glibc/snapshots
    19 
    20         # C library addons
    21         for addon in "${addons_list[@]}"; do
    22             # NPTL addon is not to be downloaded, in any case
    23             [ "${addon}" = "nptl" ] && continue || true
    24             CT_GetFile "glibc-${addon}-${CT_LIBC_VERSION}"      \
    25                        {ftp,http}://ftp.gnu.org/gnu/glibc       \
    26                        ftp://gcc.gnu.org/pub/glibc/releases     \
    27                        ftp://gcc.gnu.org/pub/glibc/snapshots
    28         done
    29     elif [ "${CT_LIBC_GLIBC_CVS}" = "y" ]; then
    30         # Use CVS checkout
    31         version="${CT_LIBC_VERSION//./_}"
    32         date="${CT_LIBC_GLIBC_CVS_date}"
    33 
    34         CT_GetCVS "glibc-cvs-${CT_LIBC_VERSION}"                    \
    35                   ":pserver:anoncvs@sources.redhat.com:/cvs/glibc"  \
    36                   "libc"                                            \
    37                   "glibc-${version}-branch${date:+:}${date}"        \
    38                   "glibc-cvs-${CT_LIBC_VERSION}"
    39 
    40         # C library addons
    41         for addon in "${addons_list[@]}"; do
    42             # NPTL addon is not to be downloaded, in any case
    43             [ "${addon}" = "nptl" ] && continue || true
    44             CT_GetCVS "glibc-${addon}-cvs-${CT_LIBC_VERSION}"           \
    45                       ":pserver:anoncvs@sources.redhat.com:/cvs/glibc"  \
    46                       "${addon}"                                        \
    47                       "glibc-${version}-branch${date:+:}${date}"        \
    48                       "glibc-${addon}-cvs-${CT_LIBC_VERSION}"
    49         done
    50     fi
    51 
    52     return 0
    53 }
    54 
    55 # Extract glibc
    56 do_libc_extract() {
    57     local cvs
    58     local -a addons_list
    59 
    60     addons_list=($(do_libc_add_ons_list " "))
    61 
    62     [ "${CT_LIBC_GLIBC_CVS}" = "y" ] && cvs="cvs-"
    63 
    64     CT_Extract "glibc-${cvs}${CT_LIBC_VERSION}"
    65 
    66     CT_Pushd "${CT_SRC_DIR}/glibc-${cvs}${CT_LIBC_VERSION}"
    67     CT_Patch "glibc-${CT_LIBC_VERSION}" nochdir
    68 
    69     # C library addons
    70     for addon in "${addons_list[@]}"; do
    71         # NPTL addon is not to be extracted, in any case
    72         [ "${addon}" = "nptl" ] && continue || true
    73         CT_Extract "glibc-${addon}-${cvs}${CT_LIBC_VERSION}" nochdir
    74 
    75         # Some addons have the 'long' name, while others have the
    76         # 'short' name, but patches are non-uniformly built with
    77         # either the 'long' or 'short' name, whatever the addons name
    78         # so we have to make symlinks from the existing to the missing
    79         # Fortunately for us, [ -d foo ], when foo is a symlink to a
    80         # directory, returns true!
    81         [ -d "${addon}" ] || CT_DoExecLog ALL ln -s "glibc-${addon}-${cvs}${CT_LIBC_VERSION}" "${addon}"
    82         [ -d "glibc-${addon}-${cvs}${CT_LIBC_VERSION}" ] || CT_DoExecLog ALL ln -s "${addon}" "glibc-${addon}-${cvs}${CT_LIBC_VERSION}"
    83         CT_Patch "glibc-${addon}-${CT_LIBC_VERSION}" nochdir
    84     done
    85 
    86     # The configure files may be older than the configure.in files
    87     # if using a snapshot (or even some tarballs). Fake them being
    88     # up to date.
    89     sleep 2
    90     find . -type f -name configure -exec touch {} \; 2>&1 |CT_DoLog ALL
    91 
    92     CT_Popd
    93 
    94     return 0
    95 }
    96 
    97 # There is nothing to do for glibc check config
    98 do_libc_check_config() {
    99     :
   100 }
   101 
   102 # This function installs the glibc headers needed to build the core compiler
   103 do_libc_headers() {
   104     local cvs
   105     local -a extra_config
   106     local arch4hdrs
   107 
   108     CT_DoStep INFO "Installing C library headers"
   109 
   110     [ "${CT_LIBC_GLIBC_CVS}" = "y" ] && cvs="cvs-"
   111 
   112     mkdir -p "${CT_BUILD_DIR}/build-libc-headers"
   113     cd "${CT_BUILD_DIR}/build-libc-headers"
   114 
   115     CT_DoLog EXTRA "Configuring C library"
   116 
   117     # The x86 arch needs special care... Bizarelly enough... :-(
   118     case "${CT_KERNEL_ARCH}:${CT_ARCH_BITNESS}" in
   119         x86:32) arch4hdrs="i386";;
   120         x86:64) arch4hdrs="x86_64";;
   121         *)      arch4hdrs="${CT_KERNEL_ARCH}";;
   122     esac
   123 
   124     # The following three things have to be done to build glibc-2.3.x, but they don't hurt older versions.
   125     # 1. override CC to keep glibc's configure from using $TARGET-gcc. 
   126     # 2. disable linuxthreads, which needs a real cross-compiler to generate tcb-offsets.h properly
   127     # 3. build with gcc 3.2 or later
   128     # Compare these options with the ones used when building glibc for real below - they're different.
   129     # As of glibc-2.3.2, to get this step to work for hppa-linux, you need --enable-hacker-mode
   130     # so when configure checks to make sure gcc has access to the assembler you just built...
   131     # Alternately, we could put ${PREFIX}/${TARGET}/bin on the path.
   132     # Set --build so maybe we don't have to specify "cross-compiling=yes" below (haven't tried yet)
   133     # Note: the warning
   134     # "*** WARNING: Are you sure you do not want to use the `linuxthreads'"
   135     # *** add-on?"
   136     # is ok here, since all we want are the basic headers at this point.
   137     # Override libc_cv_ppc_machine so glibc-cvs doesn't complain
   138     # 'a version of binutils that supports .machine "altivec" is needed'.
   139 
   140     # We need to remove any threading addon when installing headers
   141     addons_list="$(do_libc_add_ons_list " "                     \
   142                    |sed -r -e 's/\<(nptl|linuxthreads)\>/ /g;'  \
   143                            -e 's/ +/,/g; s/^,+//; s/,+$//;'     \
   144                   )"
   145 
   146     extra_config+=("--enable-add-ons=${addons_list}")
   147 
   148     extra_config+=("${addons_config}")
   149     extra_config+=("$(do_libc_min_kernel_config)")
   150 
   151     # Pre-seed the configparms file with values from the config option
   152     printf "${CT_LIBC_GLIBC_CONFIGPARMS}\n" > configparms
   153 
   154     cross_cc=$(CT_Which "${CT_TARGET}-gcc")
   155     CT_DoLog DEBUG "Using gcc for target: '${cross_cc}'"
   156     CT_DoLog DEBUG "Extra config passed : '${extra_config[*]}'"
   157 
   158     libc_cv_ppc_machine=yes                                     \
   159     libc_cv_mlong_double_128=yes                                \
   160     libc_cv_mlong_double_128ibm=yes                             \
   161     CC=${cross_cc}                                              \
   162     CT_DoExecLog ALL                                            \
   163     "${CT_SRC_DIR}/glibc-${cvs}${CT_LIBC_VERSION}/configure"    \
   164         --build="${CT_BUILD}"                                   \
   165         --host="${CT_TARGET}"                                   \
   166         --prefix=/usr                                           \
   167         --with-headers="${CT_HEADERS_DIR}"                      \
   168         --without-cvs                                           \
   169         --disable-sanity-checks                                 \
   170         --enable-hacker-mode                                    \
   171         "${extra_config[@]}"                                    \
   172         --without-nptl
   173 
   174     CT_DoLog EXTRA "Installing C library headers"
   175 
   176     if grep -q GLIBC_2.3 "${CT_SRC_DIR}/glibc-${cvs}${CT_LIBC_VERSION}/ChangeLog"; then
   177         # glibc-2.3.x passes cross options to $(CC) when generating errlist-compat.c,
   178         # which fails without a real cross-compiler.
   179         # Fortunately, we don't need errlist-compat.c, since we just need .h
   180         # files, so work around this by creating a fake errlist-compat.c and
   181         # satisfying its dependencies.
   182         # Another workaround might be to tell configure to not use any cross
   183         # options to $(CC).
   184         # The real fix would be to get install-headers to not generate
   185         # errlist-compat.c.
   186         # Note: BOOTSTRAP_GCC is used by:
   187         # patches/glibc-2.3.5/glibc-mips-bootstrap-gcc-header-install.patch
   188 
   189         libc_cv_ppc_machine=yes                         \
   190         CT_DoExecLog ALL                                \
   191         make CFLAGS="-O2 -DBOOTSTRAP_GCC"               \
   192              OBJDUMP_FOR_HOST="${CT_TARGET}-objdump"    \
   193              PARALLELMFLAGS="${PARALLELMFLAGS}"         \
   194              sysdeps/gnu/errlist.c
   195         mkdir -p stdio-common
   196 
   197         # sleep for 2 seconds for benefit of filesystems with lousy time
   198         # resolution, like FAT, so make knows for sure errlist-compat.c doesn't
   199         # need generating
   200         sleep 2
   201         CT_DoExecLog ALL touch stdio-common/errlist-compat.c
   202     fi
   203     # Note: BOOTSTRAP_GCC (see above)
   204     libc_cv_ppc_machine=yes                         \
   205     CT_DoExecLog ALL                                \
   206     make cross-compiling=yes                        \
   207          install_root=${CT_SYSROOT_DIR}             \
   208          CFLAGS="-O2 -DBOOTSTRAP_GCC"               \
   209          ${LIBC_SYSROOT_ARG}                        \
   210          OBJDUMP_FOR_HOST="${CT_TARGET}-objdump"    \
   211          PARALLELMFLAGS="${PARALLELMFLAGS}"         \
   212          install-headers
   213 
   214     # Two headers -- stubs.h and features.h -- aren't installed by install-headers,
   215     # so do them by hand.  We can tolerate an empty stubs.h for the moment.
   216     # See e.g. http://gcc.gnu.org/ml/gcc/2002-01/msg00900.html
   217     mkdir -p "${CT_HEADERS_DIR}/gnu"
   218     CT_DoExecLog ALL touch "${CT_HEADERS_DIR}/gnu/stubs.h"
   219     CT_DoExecLog ALL cp -v "${CT_SRC_DIR}/glibc-${cvs}${CT_LIBC_VERSION}/include/features.h"  \
   220                            "${CT_HEADERS_DIR}/features.h"
   221 
   222     # Building the bootstrap gcc requires either setting inhibit_libc, or
   223     # having a copy of stdio_lim.h... see
   224     # http://sources.redhat.com/ml/libc-alpha/2003-11/msg00045.html
   225     CT_DoExecLog ALL cp -v bits/stdio_lim.h "${CT_HEADERS_DIR}/bits/stdio_lim.h"
   226 
   227     # Following error building gcc-4.0.0's gcj:
   228     #  error: bits/syscall.h: No such file or directory
   229     # solved by following copy; see http://sourceware.org/ml/crossgcc/2005-05/msg00168.html
   230     # but it breaks arm, see http://sourceware.org/ml/crossgcc/2006-01/msg00091.html
   231     [ "${CT_ARCH}" != "arm" ] && CT_DoExecLog ALL cp -v misc/syscall-list.h "${CT_HEADERS_DIR}/bits/syscall.h" || true
   232 
   233     # Those headers are to be manually copied so gcc can build properly
   234     pthread_h="${CT_SRC_DIR}/glibc-${cvs}${CT_LIBC_VERSION}/${CT_THREADS}/sysdeps/pthread/pthread.h"
   235     pthreadtypes_h=
   236     case "${CT_THREADS}" in
   237         nptl)
   238             # NOTE: for some archs, the pathes are different, but they are not
   239             # supported by crosstool-NG right now. See original crosstool when they are.
   240             pthread_h="${CT_SRC_DIR}/glibc-${cvs}${CT_LIBC_VERSION}/${CT_THREADS}/sysdeps/pthread/pthread.h"
   241             pthreadtypes_h="${CT_SRC_DIR}/glibc-${cvs}${CT_LIBC_VERSION}/nptl/sysdeps/unix/sysv/linux/${arch4hdrs}/bits/pthreadtypes.h"
   242             if [ ! -f "${pthreadtypes_h}" ]; then
   243                 pthreadtypes_h="${CT_SRC_DIR}/glibc-${cvs}${CT_LIBC_VERSION}/ports/sysdeps/unix/sysv/linux/${arch4hdrs}/nptl/bits/pthreadtypes.h"
   244             fi
   245             ;;
   246         linuxthreads)
   247             pthreadtypes_h="${CT_SRC_DIR}/glibc-${cvs}${CT_LIBC_VERSION}/linuxthreads/sysdeps/pthread/bits/pthreadtypes.h"
   248             ;;
   249         *)
   250             pthread_h=
   251             pthreadtypes_h=
   252             ;;
   253     esac
   254     if [ -n "${pthread_h}" ]; then
   255         CT_DoExecLog ALL cp -v "${pthread_h}" "${CT_HEADERS_DIR}/pthread.h"
   256     fi
   257     if [ -n "${pthreadtypes_h}" ]; then
   258         CT_DoExecLog ALL cp -v "${pthreadtypes_h}" "${CT_HEADERS_DIR}/bits/pthreadtypes.h"
   259     fi
   260 
   261     CT_EndStep
   262 }
   263 
   264 # Build and install start files
   265 do_libc_start_files() {
   266     local cvs
   267     local -a extra_config
   268 
   269     # Needed only in the NPTL case. Otherwise, return.
   270     [ "${CT_THREADS}" = "nptl" ] || return 0
   271 
   272     CT_DoStep INFO "Installing C library start files"
   273 
   274     [ "${CT_LIBC_GLIBC_CVS}" = "y" ] && cvs="cvs-"
   275 
   276     mkdir -p "${CT_BUILD_DIR}/build-libc-startfiles"
   277     cd "${CT_BUILD_DIR}/build-libc-startfiles"
   278 
   279     CT_DoLog EXTRA "Configuring C library"
   280 
   281     # Add some default glibc config options if not given by user.
   282     case "${CT_LIBC_GLIBC_EXTRA_CONFIG}" in
   283         *-tls*) ;;
   284         *) extra_config+=("--with-tls")
   285     esac
   286     case "${CT_SHARED_LIBS}" in
   287         y) extra_config+=("--enable-shared");;
   288         *) extra_config+=("--disable-shared");;
   289     esac
   290     case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
   291         y,) extra_config+=("--with-fp");;
   292         ,y) extra_config+=("--without-fp");;
   293     esac
   294     # Obviously, we want threads, as we come here only for NPTL
   295     extra_config+=("--with-__thread")
   296 
   297     addons_config="--enable-add-ons=$(do_libc_add_ons_list ,)"
   298     extra_config+=("${addons_config}")
   299 
   300     extra_config+=("$(do_libc_min_kernel_config)")
   301 
   302     # Add some default CC args
   303     glibc_version_major=$(echo ${CT_LIBC_VERSION} |sed -r -e 's/^([[:digit:]]+).*/\1/')
   304     glibc_version_minor=$(echo ${CT_LIBC_VERSION} |sed -r -e 's/^[[:digit:]]+[\.-_]([[:digit:]]+).*/\1/')
   305     if [    ${glibc_version_major} -eq 2 -a ${glibc_version_minor} -ge 6    \
   306          -o ${glibc_version_major} -gt 2                                    ]; then
   307         # Don't use -pipe: configure chokes on it for glibc >= 2.6.
   308         CT_Test 'Removing "-pipe" for use with glibc>=2.6' "${CT_USE_PIPES}" = "y"
   309         extra_cc_args="${CT_CFLAGS_FOR_HOST/-pipe}"
   310     else
   311         extra_cc_args="${CT_CFLAGS_FOR_HOST}"
   312     fi
   313     extra_cc_args="${extra_cc_args} ${CT_ARCH_ENDIAN_OPT}"
   314 
   315     cross_cc=$(CT_Which "${CT_TARGET}-gcc")
   316     CT_DoLog DEBUG "Using gcc for target    : '${cross_cc}'"
   317     CT_DoLog DEBUG "Configuring with addons : '$(do_libc_add_ons_list ,)'"
   318     CT_DoLog DEBUG "Extra config args passed: '${extra_config[*]}'"
   319     CT_DoLog DEBUG "Extra CC args passed    : '${extra_cc_args}'"
   320 
   321     # Pre-seed the configparms file with values from the config option
   322     printf "${CT_LIBC_GLIBC_CONFIGPARMS}\n" > configparms
   323 
   324     echo "libc_cv_forced_unwind=yes" > config.cache
   325     echo "libc_cv_c_cleanup=yes" >> config.cache
   326 
   327     # Please see the comment for the configure step in do_libc().
   328 
   329     BUILD_CC="${CT_BUILD}-gcc"                                      \
   330     CFLAGS="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} -O2"  \
   331     CC="${cross_cc} ${CT_LIBC_EXTRA_CC_ARGS} ${extra_cc_args}"      \
   332     AR=${CT_TARGET}-ar                                              \
   333     RANLIB=${CT_TARGET}-ranlib                                      \
   334     CT_DoExecLog ALL                                                \
   335     "${CT_SRC_DIR}/glibc-${cvs}${CT_LIBC_VERSION}/configure"        \
   336         --prefix=/usr                                               \
   337         --build="${CT_BUILD}"                                       \
   338         --host=${CT_TARGET}                                         \
   339         --without-cvs                                               \
   340         --disable-profile                                           \
   341         --disable-debug                                             \
   342         --without-gd                                                \
   343         --with-headers="${CT_HEADERS_DIR}"                          \
   344         --cache-file=config.cache                                   \
   345         "${extra_config[@]}"                                        \
   346         ${CT_LIBC_GLIBC_EXTRA_CONFIG}
   347 
   348     #TODO: should check whether slibdir has been set in configparms to */lib64
   349     #      and copy the startfiles into the appropriate libdir.
   350     CT_DoLog EXTRA "Building C library start files"
   351     CT_DoExecLog ALL make OBJDUMP_FOR_HOST="${CT_TARGET}-objdump"   \
   352                           PARALLELMFLAGS="${PARALLELMFLAGS}"        \
   353                           csu/subdir_lib
   354 
   355     CT_DoLog EXTRA "Installing C library start files"
   356     if [ "${CT_USE_SYSROOT}" = "y" ]; then
   357         CT_DoExecLog ALL cp -fpv csu/crt[1in].o "${CT_SYSROOT_DIR}/usr/lib/"
   358     else
   359         CT_DoExecLog ALL cp -fpv csu/crt[1in].o "${CT_SYSROOT_DIR}/lib/"
   360     fi
   361 
   362     CT_EndStep
   363 }
   364 
   365 # This function builds and install the full glibc
   366 do_libc() {
   367     local cvs
   368     local -a extra_config
   369 
   370     CT_DoStep INFO "Installing C library"
   371 
   372     [ "${CT_LIBC_GLIBC_CVS}" = "y" ] && cvs="cvs-"
   373 
   374     mkdir -p "${CT_BUILD_DIR}/build-libc"
   375     cd "${CT_BUILD_DIR}/build-libc"
   376 
   377     CT_DoLog EXTRA "Configuring C library"
   378 
   379     # Add some default glibc config options if not given by user.
   380     # We don't need to be conditional on wether the user did set different
   381     # values, as they CT_LIBC_GLIBC_EXTRA_CONFIG is passed after extra_config
   382 
   383     case "${CT_THREADS}" in
   384         nptl)           extra_config+=("--with-__thread" "--with-tls");;
   385         linuxthreads)   extra_config+=("--with-__thread" "--without-tls" "--without-nptl");;
   386         none)           extra_config+=("--without-__thread" "--without-nptl")
   387                         case "${CT_LIBC_GLIBC_EXTRA_CONFIG}" in
   388                             *-tls*) ;;
   389                             *) extra_config+=("--without-tls");;
   390                         esac
   391                         ;;
   392     esac
   393 
   394     case "${CT_SHARED_LIBS}" in
   395         y) extra_config+=("--enable-shared");;
   396         *) extra_config+=("--disable-shared");;
   397     esac
   398 
   399     case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
   400         y,) extra_config+=("--with-fp");;
   401         ,y) extra_config+=("--without-fp");;
   402     esac
   403 
   404     case "$(do_libc_add_ons_list ,)" in
   405         "") ;;
   406         *)  extra_config+=("--enable-add-ons=$(do_libc_add_ons_list ,)");;
   407     esac
   408 
   409     extra_config+=("$(do_libc_min_kernel_config)")
   410 
   411     # Add some default CC args
   412     glibc_version_major=$(echo ${CT_LIBC_VERSION} |sed -r -e 's/^([[:digit:]]+).*/\1/')
   413     glibc_version_minor=$(echo ${CT_LIBC_VERSION} |sed -r -e 's/^[[:digit:]]+[\.-_]([[:digit:]]+).*/\1/')
   414     if [    ${glibc_version_major} -eq 2 -a ${glibc_version_minor} -ge 6    \
   415          -o ${glibc_version_major} -gt 2                                    ]; then
   416         # Don't use -pipe: configure chokes on it for glibc >= 2.6.
   417         CT_Test 'Removing "-pipe" for use with glibc>=2.6' "${CT_USE_PIPES}" = "y"
   418         extra_cc_args="${CT_CFLAGS_FOR_HOST/-pipe}"
   419     else
   420         extra_cc_args="${CT_CFLAGS_FOR_HOST}"
   421     fi
   422     extra_cc_args="${extra_cc_args} ${CT_ARCH_ENDIAN_OPT}"
   423 
   424     cross_cc=$(CT_Which "${CT_TARGET}-gcc")
   425     CT_DoLog DEBUG "Using gcc for target    : '${cross_cc}'"
   426     CT_DoLog DEBUG "Configuring with addons : '$(do_libc_add_ons_list ,)'"
   427     CT_DoLog DEBUG "Extra config args passed: '${extra_config}'"
   428     CT_DoLog DEBUG "Extra CC args passed    : '${extra_cc_args}'"
   429 
   430     # Pre-seed the configparms file with values from the config option
   431     printf "${CT_LIBC_GLIBC_CONFIGPARMS}\n" > configparms
   432 
   433     # For glibc 2.3.4 and later we need to set some autoconf cache
   434     # variables, because nptl/sysdeps/pthread/configure.in does not
   435     # work when cross-compiling.
   436     if [ "${CT_THREADS}" = "nptl" ]; then
   437         echo libc_cv_forced_unwind=yes
   438         echo libc_cv_c_cleanup=yes
   439     fi >config.cache
   440 
   441     # Configure with --prefix the way we want it on the target...
   442     # There are a whole lot of settings here.  You'll probably want
   443     # to read up on what they all mean, and customize a bit, possibly by setting GLIBC_EXTRA_CONFIG
   444     # Compare these options with the ones used when installing the glibc headers above - they're different.
   445     # Adding "--without-gd" option to avoid error "memusagestat.c:36:16: gd.h: No such file or directory" 
   446     # See also http://sources.redhat.com/ml/libc-alpha/2000-07/msg00024.html. 
   447     # Set BUILD_CC, or you won't be able to build datafiles
   448     # Set --build, else glibc-2.3.2 will think you're not cross-compiling, and try to run the test programs
   449 
   450     # OK. I'm fed up with those folks telling me what I should do.
   451     # I don't configure nptl? Well, maybe that's purposedly because
   452     # I don't want nptl! --disable-sanity-checks will shut up those
   453     # silly messages. GNU folks again, he?
   454 
   455     BUILD_CC="${CT_BUILD}-gcc"                                      \
   456     CFLAGS="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} -O2"  \
   457     CC="${CT_TARGET}-gcc ${CT_LIBC_EXTRA_CC_ARGS} ${extra_cc_args}" \
   458     AR=${CT_TARGET}-ar                                              \
   459     RANLIB=${CT_TARGET}-ranlib                                      \
   460     CT_DoExecLog ALL                                                \
   461     "${CT_SRC_DIR}/glibc-${cvs}${CT_LIBC_VERSION}/configure"        \
   462         --prefix=/usr                                               \
   463         --build=${CT_BUILD}                                         \
   464         --host=${CT_TARGET}                                         \
   465         --without-cvs                                               \
   466         --disable-profile                                           \
   467         --disable-debug                                             \
   468         --without-gd                                                \
   469         --disable-sanity-checks                                     \
   470         --cache-file=config.cache                                   \
   471         --with-headers="${CT_HEADERS_DIR}"                          \
   472         "${extra_config[@]}"                                        \
   473         ${CT_LIBC_GLIBC_EXTRA_CONFIG}
   474 
   475     if grep -l '^install-lib-all:' "${CT_SRC_DIR}/glibc-${cvs}${CT_LIBC_VERSION}/Makerules" > /dev/null; then
   476         # nptl-era glibc.
   477         # If the install-lib-all target (which is added by our make-install-lib-all.patch)
   478         # is present, it means we're building glibc-2.3.3 or later, and we can't
   479         # build programs yet, as they require libeh, which won't be installed
   480         # until full build of gcc
   481         # YEM-FIXME: This comment is misleading: latest glibc-s do not have the
   482         #            make-install-lib-all.patch applied, so do not pass through this
   483         #            part of the if statement; nonetheless, they do build, and
   484         #            the result is useable (maybe the dual-pass core gcc is
   485         #            responsible for this).
   486         GLIBC_INITIAL_BUILD_RULE=lib
   487         GLIBC_INITIAL_INSTALL_RULE="install-lib-all install-headers"
   488         GLIBC_INSTALL_APPS_LATER=yes
   489     else
   490         # classic glibc.  
   491         # We can build and install everything with the bootstrap compiler.
   492         # YEM-FIXME: See the above FIXME as well.
   493         GLIBC_INITIAL_BUILD_RULE=all
   494         GLIBC_INITIAL_INSTALL_RULE=install
   495         GLIBC_INSTALL_APPS_LATER=no
   496     fi
   497 
   498     # glibc initial build hacks
   499     # http://sourceware.org/ml/crossgcc/2008-10/msg00068.html
   500     case "${CT_ARCH},${CT_ARCH_CPU}" in
   501 	powerpc,8??)
   502 	    CT_DoLog DEBUG "Activating support for memset on broken ppc-8xx (CPU15 erratum)"
   503 	    GLIBC_INITIAL_BUILD_ASFLAGS="-DBROKEN_PPC_8xx_CPU15";;
   504     esac
   505 
   506     # If this fails with an error like this:
   507     # ...  linux/autoconf.h: No such file or directory 
   508     # then you need to set the KERNELCONFIG variable to point to a .config file for this arch.
   509     # The following architectures are known to need kernel .config: alpha, arm, ia64, s390, sh, sparc
   510     # Note: LD and RANLIB needed by glibc-2.1.3's c_stub directory, at least on macosx
   511     CT_DoLog EXTRA "Building C library"
   512     CT_DoExecLog ALL make LD=${CT_TARGET}-ld                        \
   513                           RANLIB=${CT_TARGET}-ranlib                \
   514                           OBJDUMP_FOR_HOST="${CT_TARGET}-objdump"   \
   515                           ASFLAGS="${GLIBC_INITIAL_BUILD_ASFLAGS}"  \
   516                           PARALLELMFLAGS="${PARALLELMFLAGS}"        \
   517                           ${GLIBC_INITIAL_BUILD_RULE}
   518 
   519     CT_DoLog EXTRA "Installing C library"
   520     CT_DoExecLog ALL make install_root="${CT_SYSROOT_DIR}"          \
   521                           ${LIBC_SYSROOT_ARG}                       \
   522                           OBJDUMP_FOR_HOST="${CT_TARGET}-objdump"   \
   523                           PARALLELMFLAGS="${PARALLELMFLAGS}"        \
   524                           ${GLIBC_INITIAL_INSTALL_RULE}
   525 
   526     # This doesn't seem to work when building a crosscompiler,
   527     # as it tries to execute localedef using the just-built ld.so!?
   528     #CT_DoLog EXTRA "Installing locales"
   529     #make localedata/install-locales install_root=${SYSROOT} 2>&1 |CT_DoLog ALL
   530 
   531     # Fix problems in linker scripts.
   532     #
   533     # Remove lines containing BUG per http://sources.redhat.com/ml/bug-glibc/2003-05/msg00055.html,
   534     # needed to fix gcc-3.2.3/glibc-2.3.2 targeting arm
   535     # No need to look into the lib64/ dirs here and there, they point to the
   536     # corresponding lib/ directories.
   537     #
   538     # To make "strip *.so.*" not fail (ptxdist does this), rename to .so_orig rather than .so.orig
   539     CT_DoLog EXTRA "Fixing C library linker scripts"
   540     for file in libc.so libpthread.so libgcc_s.so; do
   541         for dir in lib usr/lib; do
   542             if [ -f "${CT_SYSROOT_DIR}/${dir}/${file}" -a ! -L ${CT_SYSROOT_DIR}/$lib/$file ]; then
   543                 CT_DoExecLog ALL cp -v "${CT_SYSROOT_DIR}/${dir}/${file}" "${CT_SYSROOT_DIR}/${dir}/${file}_orig"
   544                 CT_DoLog DEBUG "Fixing '${CT_SYS_ROOT_DIR}/${dir}/${file}'"
   545                 CT_DoExecLog ALL sed -i -r -e '/BUG in libc.scripts.output-format.sed/d' "${CT_SYSROOT_DIR}/${dir}/${file}"
   546             fi
   547         done
   548     done
   549 
   550     CT_EndStep
   551 }
   552 
   553 # This function finishes the glibc install
   554 do_libc_finish() {
   555     # Finally, build and install glibc programs, now that libeh (if any) is installed
   556     # Don't do this unless needed, 'cause it causes glibc-2.{1.3,2.2} to fail here with
   557     # .../gcc-3.4.1-glibc-2.1.3/build-glibc/libc.so.6: undefined reference to `__deregister_frame_info'
   558     # .../gcc-3.4.1-glibc-2.1.3/build-glibc/libc.so.6: undefined reference to `__register_frame_info'
   559     [ "${GLIBC_INSTALL_APPS_LATER}" = "yes" ] || return 0
   560 
   561     CT_DoStep INFO "Finishing C library"
   562 
   563     cd "${CT_BUILD_DIR}/build-libc"
   564 
   565     CT_DoLog EXTRA "Re-building C library"
   566     CT_DoExecLog ALL make LD=${CT_TARGET}-ld                        \
   567                           RANLIB=${CT_TARGET}-ranlib                \
   568                           OBJDUMP_FOR_HOST="${CT_TARGET}-objdump"   \
   569                           ASFLAGS="${GLIBC_INITIAL_BUILD_ASFLAGS}"  \
   570                           PARALLELMFLAGS="${PARALLELMFLAGS}"
   571 
   572     CT_DoLog EXTRA "Installing missing C library components"
   573     # note: should do full install and then fix linker scripts, but this is faster
   574     for t in bin rootsbin sbin data others; do
   575         CT_DoExecLog ALL make install_root="${CT_SYSROOT_DIR}"          \
   576                               ${LIBC_SYSROOT_ARG}                       \
   577                               OBJDUMP_FOR_HOST="${CT_TARGET}-objdump"   \
   578                               PARALLELMFLAGS="${PARALLELMFLAGS}"        \
   579                               install-${t}
   580     done
   581 
   582     CT_EndStep
   583 }
   584 
   585 # Build up the addons list, separated with $1
   586 do_libc_add_ons_list() {
   587     local sep="$1"
   588     local addons_list=$(echo "${CT_LIBC_ADDONS_LIST}" |sed -r -e "s/[ ,]/${sep}/g;")
   589     case "${CT_THREADS}" in
   590         none)   ;;
   591         *)      addons_list="${addons_list}${sep}${CT_THREADS}";;
   592     esac
   593     [ "${CT_LIBC_GLIBC_USE_PORTS}" = "y" ] && addons_list="${addons_list}${sep}ports"
   594     # Remove duplicate, leading and trailing separators
   595     echo "${addons_list}" |sed -r -e "s/${sep}+/${sep}/g; s/^${sep}//; s/${sep}\$//;"
   596 }
   597 
   598 # Builds up the minimum supported Linux kernel version
   599 do_libc_min_kernel_config() {
   600     local min_kernel_config=
   601     case "${CT_LIBC_GLIBC_EXTRA_CONFIG}" in
   602         *enable-kernel*) ;;
   603         *)  if [ "${CT_LIBC_GLIBC_KERNEL_VERSION_AS_HEADERS}" = "y" ]; then
   604                 # We can't rely on the kernel version from the configuration,
   605                 # because it might not be available if the user uses pre-installed
   606                 # headers. On the other hand, both method will have the kernel
   607                 # version installed in "usr/include/linux/version.h" in the sys-root.
   608                 # Parse that instead of having two code-paths.
   609                 version_code_file="${CT_SYSROOT_DIR}/usr/include/linux/version.h"
   610                 CT_TestOrAbort "Linux version is unavailable in installed headers files" -f "${version_code_file}" -a -r "${version_code_file}"
   611                 version_code=$(grep -E LINUX_VERSION_CODE "${version_code_file}" |cut -d ' ' -f 3)
   612                 version=$(((version_code>>16)&0xFF))
   613                 patchlevel=$(((version_code>>8)&0xFF))
   614                 sublevel=$((version_code&0xFF))
   615                 min_kernel_config="--enable-kernel=${version}.${patchlevel}.${sublevel}"
   616             elif [ "${CT_LIBC_GLIBC_KERNEL_VERSION_CHOSEN}" = "y" ]; then
   617                 # Trim the fourth part of the linux version, keeping only the first three numbers
   618                 min_kernel_config="--enable-kernel=$(echo ${CT_LIBC_GLIBC_MIN_KERNEL_VERSION} |sed -r -e 's/^([^.]+\.[^.]+\.[^.]+)(|\.[^.]+)$/\1/;')"
   619             fi
   620             ;;
   621     esac
   622     echo "${min_kernel_config}"
   623 }