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