scripts/build/libc/glibc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Mar 15 20:50:40 2009 +0000 (2009-03-15)
changeset 1260 777153645ab8
parent 1232 80c5723e06fc
child 1395 da3d13b0880a
permissions -rw-r--r--
Sanitise using glibc cvs exports:
- recently, tarballs for glibc 2.8 and 2.9 have appeared on the GNU ftp site
- always use a dot in version strings (eg. 2.9, not 2_9)

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