scripts/build/libc/glibc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jan 04 22:17:53 2009 +0000 (2009-01-04)
changeset 1123 8c5881324a79
parent 1121 4b7ed9da5a21
child 1124 eec7a46a4c19
permissions -rw-r--r--
Get rid of CT_LIBC_FILE, remove useless CT_MakeAbsolutePath.

CT_LIBC_FILE:
- that one was not easy, as it had sneaked into CT_ExtractAndPatch
- which in turn made CT_ExtractAndPatch have references to C library addons
- which in turn relieved the C library _extract functions from doing their own job
- which in turn imposed some nasty tricks in CT_ExtractAndPatch
- which in turn made life easier for the DUMA _get and _extract functions
- which unveiled some bizare behavior for pushd and popd:
- if using smthg ike: 'pushd foo |bar':
- the directory is *neither* changed
- *nor* is it pushed onto the stack
- which made popd fail

CT_MakeAbsolutePath:
- used only to make CT_LOCAL_TARBALLS_DIR canonical
- which is ((almost) useless:
- hopefully, the user entered a full path already
- if it's not the case, too bad...

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