scripts/build/libc/glibc-eglibc.sh-common
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Dec 27 14:45:03 2011 +0100 (2011-12-27)
changeset 2826 4a21f0eb8b57
parent 2825 1c5ca9b0a5a0
child 2827 f8f2f75ff3fd
permissions -rw-r--r--
libc/glibc: allow to selectively install headers and/or start-files

When doing multilib, we only need the headers from the default variant,
but we need the startfiles for each variants.

Allow the frontend to specify either one, or both.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
yann@2270
     1
# This file contains the functions common to glibc and eglibc
yann@850
     2
yann@2483
     3
# Extract the C library tarball(s)
yann@2483
     4
do_libc_extract() {
yann@2483
     5
    local addon
yann@2483
     6
yann@2483
     7
    # Extract the main tarball
yann@2483
     8
    CT_Extract "${CT_LIBC}-${CT_LIBC_VERSION}"
yann@2483
     9
    CT_Pushd "${CT_SRC_DIR}/${CT_LIBC}-${CT_LIBC_VERSION}"
yann@2483
    10
    CT_Patch nochdir "${CT_LIBC}" "${CT_LIBC_VERSION}"
yann@2483
    11
yann@2483
    12
    # Extract the add-opns
yann@2483
    13
    for addon in $(do_libc_add_ons_list " "); do
yann@2496
    14
        # If the addon was bundled with the main archive, we do not
yann@2496
    15
        # need to extract it. Worse, if we were to try to extract
yann@2496
    16
        # it, we'd get an error.
yann@2496
    17
        if [ -d "${addon}" ]; then
yann@2496
    18
            CT_DoLog DEBUG "Add-on already present, spkipping extraction"
yann@2496
    19
            continue
yann@2496
    20
        fi
yann@2483
    21
yann@2483
    22
        CT_Extract nochdir "${CT_LIBC}-${addon}-${CT_LIBC_VERSION}"
yann@2483
    23
yann@2483
    24
        CT_TestAndAbort "Error in add-on '${addon}': both short and long names in tarball" \
yann@2483
    25
            -d "${addon}" -a -d "${CT_LIBC}-${addon}-${CT_LIBC_VERSION}"
yann@2483
    26
yann@2483
    27
        # Some addons have the 'long' name, while others have the
yann@2483
    28
        # 'short' name, but patches are non-uniformly built with
yann@2483
    29
        # either the 'long' or 'short' name, whatever the addons name
yann@2483
    30
        # but we prefer the 'short' name and avoid duplicates.
yann@2483
    31
        if [ -d "${CT_LIBC}-${addon}-${CT_LIBC_VERSION}" ]; then
esben@2699
    32
            CT_DoExecLog FILE mv "${CT_LIBC}-${addon}-${CT_LIBC_VERSION}" "${addon}"
yann@2483
    33
        fi
yann@2483
    34
esben@2699
    35
        CT_DoExecLog FILE ln -s "${addon}" "${CT_LIBC}-${addon}-${CT_LIBC_VERSION}"
yann@2483
    36
yann@2483
    37
        CT_Patch nochdir "${CT_LIBC}" "${addon}-${CT_LIBC_VERSION}"
yann@2483
    38
yann@2483
    39
        # Remove the long name since it can confuse configure scripts to run
yann@2483
    40
        # the same source twice.
yann@2483
    41
        rm "${CT_LIBC}-${addon}-${CT_LIBC_VERSION}"
yann@2483
    42
    done
yann@2483
    43
yann@2483
    44
    # The configure files may be older than the configure.in files
yann@2483
    45
    # if using a snapshot (or even some tarballs). Fake them being
yann@2483
    46
    # up to date.
yann@2483
    47
    find . -type f -name configure -exec touch {} \; 2>&1 |CT_DoLog ALL
yann@2483
    48
yann@2483
    49
    CT_Popd
benoit@2585
    50
benoit@2585
    51
    if [ "${CT_LIBC_LOCALES}" = "y" ]; then
benoit@2585
    52
        do_libc_locales_extract
benoit@2585
    53
    fi
yann@2483
    54
}
yann@2483
    55
yann@2270
    56
# Build and install headers and start files
yann@850
    57
do_libc_start_files() {
bryanhundven@2515
    58
    # Start files and Headers should be configured the same way as the
bryanhundven@2515
    59
    # final libc, but built and installed differently.
bryanhundven@2515
    60
    do_libc_backend libc_mode=startfiles
yann@850
    61
}
yann@850
    62
yann@2270
    63
# This function builds and install the full C library
yann@850
    64
do_libc() {
bryanhundven@2515
    65
    do_libc_backend libc_mode=final
bryanhundven@2515
    66
}
bryanhundven@2515
    67
yann@2825
    68
# This backend builds the C library once for each multilib
yann@2825
    69
# variant the compiler gives us
yann@2806
    70
# Usage: do_libc_backend param=value [...]
yann@2806
    71
#   Parameter           : Definition                            : Type      : Default
yann@2819
    72
#   libc_mode           : 'startfiles' or 'final'               : string    : (none)
yann@2825
    73
do_libc_backend() {
yann@2825
    74
    local libc_mode
yann@2825
    75
    local -a multilibs
yann@2825
    76
    local multilib
yann@2825
    77
    local multi_dir
yann@2825
    78
    local multi_flags
yann@2825
    79
    local extra_dir
yann@2826
    80
    local libc_headers libc_startfiles libc_full
yann@2826
    81
    local hdr
yann@2826
    82
    local arg
yann@2825
    83
yann@2825
    84
    for arg in "$@"; do
yann@2825
    85
        eval "${arg// /\\ }"
yann@2825
    86
    done
yann@2825
    87
yann@2825
    88
    case "${libc_mode}" in
yann@2826
    89
        startfiles)
yann@2826
    90
            CT_DoStep INFO "Installing C library headers & start files"
yann@2826
    91
            hdr=y
yann@2826
    92
            libc_startfiles=y
yann@2826
    93
            libc_full=
yann@2826
    94
            ;;
yann@2826
    95
        final)
yann@2826
    96
            CT_DoStep INFO "Installing C library"
yann@2826
    97
            hdr=
yann@2826
    98
            libc_startfiles=
yann@2826
    99
            libc_full=y
yann@2826
   100
            ;;
yann@2826
   101
        *)  CT_Abort "Unsupported (or unset) libc_mode='${libc_mode}'";;
yann@2825
   102
    esac
yann@2825
   103
yann@2825
   104
    # If gcc is not configured for multilib, it still prints
yann@2825
   105
    # a single line for the default settings
yann@2825
   106
    multilibs=( $("${CT_TARGET}-gcc" -print-multi-lib 2>/dev/null) )
yann@2825
   107
    for multilib in "${multilibs[@]}"; do
yann@2825
   108
        multi_dir="${multilib%%;*}"
yann@2825
   109
        if [ "${multi_dir}" != "." ]; then
yann@2825
   110
            CT_DoStep INFO "Building for multilib subdir='${multi_dir}'"
yann@2825
   111
yann@2825
   112
            extra_flags="$( echo "${multilib#*;}"       \
yann@2825
   113
                            |${sed} -r -e 's/@/ -/g;'   \
yann@2825
   114
                          )"
yann@2825
   115
            extra_dir="/${multi_dir}"
yann@2825
   116
yann@2825
   117
            # glibc install its files in ${extra_dir}/{usr/,}lib
yann@2825
   118
            # while gcc expects them in {,usr/}lib/${extra_dir}.
yann@2825
   119
            # Prepare some symlinks so glibc installs in fact in
yann@2825
   120
            # the proper place
yann@2825
   121
            # We do it in the start-files step, so it is not needed
yann@2825
   122
            # to do it in the final step, as the symlinks will
yann@2825
   123
            # already exist
yann@2825
   124
            if [ "${libc_mode}" = "startfiles" ]; then
yann@2825
   125
                CT_Pushd "${CT_SYSROOT_DIR}"
yann@2825
   126
                CT_DoExecLog ALL mkdir -p "lib/${multi_dir}"        \
yann@2825
   127
                                          "usr/lib/${multi_dir}"    \
yann@2825
   128
                                          "${multi_dir}"            \
yann@2825
   129
                                          "${multi_dir}/usr"
yann@2825
   130
                CT_DoExecLog ALL ln -sf "../lib/${multi_dir}" "${multi_dir}/lib"
yann@2825
   131
                CT_DoExecLog ALL ln -sf "../../usr/lib/${multi_dir}" "${multi_dir}/usr/lib"
yann@2825
   132
                CT_Popd
yann@2825
   133
            fi
yann@2826
   134
            libc_headers=
yann@2825
   135
        else
yann@2825
   136
            extra_dir=
yann@2825
   137
            extra_flags=
yann@2826
   138
            libc_headers="${hdr}"
yann@2825
   139
        fi
yann@2825
   140
yann@2825
   141
        mkdir -p "${CT_BUILD_DIR}/build-libc-${libc_mode}${extra_dir//\//_}"
yann@2825
   142
        CT_Pushd "${CT_BUILD_DIR}/build-libc-${libc_mode}${extra_dir//\//_}"
yann@2825
   143
yann@2826
   144
        do_libc_backend_once extra_dir="${extra_dir}"               \
yann@2826
   145
                             extra_flags="${extra_flags}"           \
yann@2826
   146
                             libc_headers="${libc_headers}"         \
yann@2826
   147
                             libc_startfiles="${libc_startfiles}"   \
yann@2826
   148
                             libc_full="${libc_full}"
yann@2825
   149
yann@2825
   150
        CT_Popd
yann@2825
   151
yann@2825
   152
        if [ "${multi_dir}" != "." ]; then
yann@2825
   153
            if [ "${libc_mode}" = "final" ]; then
yann@2825
   154
                CT_DoLog EXTRA "Fixing up multilib location"
yann@2825
   155
yann@2825
   156
                # rewrite the library multiplexers
yann@2825
   157
                for d in "lib/${multi_dir}" "usr/lib/${multi_dir}"; do
yann@2825
   158
                    for l in libc libpthread libgcc_s; do
yann@2825
   159
                        if [    -f "${CT_SYSROOT_DIR}/${d}/${l}.so"    \
yann@2825
   160
                             -a ! -L ${CT_SYSROOT_DIR}/${d}/${l}.so    ]
yann@2825
   161
                        then
yann@2825
   162
                            CT_DoExecLog DEBUG ${sed} -r -i                                 \
yann@2825
   163
                                                      -e "s:/lib/:/lib/${multi_dir}/:g;"    \
yann@2825
   164
                                                      "${CT_SYSROOT_DIR}/${d}/${l}.so"
yann@2825
   165
                        fi
yann@2825
   166
                    done
yann@2825
   167
                done
yann@2825
   168
            fi # libc_mode == final
yann@2825
   169
            CT_EndStep
yann@2825
   170
        fi
yann@2825
   171
    done
yann@2825
   172
yann@2825
   173
    CT_EndStep
yann@2825
   174
}
yann@2825
   175
yann@2825
   176
# This backend builds the C library once
yann@2825
   177
# Usage: do_libc_backend_once param=value [...]
yann@2825
   178
#   Parameter           : Definition                            : Type      : Default
yann@2826
   179
#   libc_headers        : Build libc headers                    : bool      : n
yann@2826
   180
#   libc_startfiles     : Build libc start-files                : bool      : n
yann@2826
   181
#   libc_full           : Build full libc                       : bool      : n
yann@2820
   182
#   extra_flags         : Extra CFLAGS to use (for multilib)    : string    : (empty)
yann@2823
   183
#   extra_dir           : Extra subdir for multilib             : string    : (empty)
yann@2825
   184
do_libc_backend_once() {
yann@2826
   185
    local libc_headers
yann@2826
   186
    local libc_startfiles
yann@2826
   187
    local libc_full
yann@2820
   188
    local extra_flags
yann@2823
   189
    local extra_dir
yann@2271
   190
    local src_dir="${CT_SRC_DIR}/${CT_LIBC}-${CT_LIBC_VERSION}"
yann@2276
   191
    local extra_cc_args
yann@1478
   192
    local -a extra_config
yann@2271
   193
    local -a extra_make_args
yann@2312
   194
    local glibc_cflags
yann@2821
   195
    local float_extra
yann@2822
   196
    local endian_extra
yann@1478
   197
bryanhundven@2515
   198
    while [ $# -ne 0 ]; do
yann@2542
   199
        eval "${1// /\\ }"
bryanhundven@2515
   200
        shift
bryanhundven@2515
   201
    done
yann@850
   202
yann@850
   203
    CT_DoLog EXTRA "Configuring C library"
yann@850
   204
yann@2271
   205
    case "${CT_LIBC}" in
yann@2271
   206
        eglibc)
yann@2271
   207
            if [ "${CT_EGLIBC_CUSTOM_CONFIG}" = "y" ]; then
yann@2271
   208
                CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/eglibc.config" option-groups.config
yann@2271
   209
            fi
yann@2271
   210
            if [ "${CT_EGLIBC_OPT_SIZE}" = "y" ]; then
yann@2271
   211
                OPTIMIZE=-Os
yann@2271
   212
            else
yann@2271
   213
                OPTIMIZE=-O2
yann@2271
   214
            fi
yann@2271
   215
            ;;
yann@2276
   216
        glibc)
yann@2276
   217
            # glibc can't be built without -O2 (reference needed!)
yann@2276
   218
            OPTIMIZE=-O2
yann@2276
   219
            # Also, if those two are missing, iconv build breaks
yann@2276
   220
            extra_config+=( --disable-debug --disable-sanity-checks )
yann@2276
   221
            ;;
yann@2271
   222
    esac
richard@1796
   223
yann@850
   224
    # Add some default glibc config options if not given by user.
yann@850
   225
    # We don't need to be conditional on wether the user did set different
yann@2467
   226
    # values, as they CT_LIBC_GLIBC_EXTRA_CONFIG_ARRAY is passed after
yann@2467
   227
    # extra_config
yann@850
   228
yann@2273
   229
    extra_config+=("$(do_libc_min_kernel_config)")
yann@850
   230
yann@850
   231
    case "${CT_THREADS}" in
yann@1478
   232
        nptl)           extra_config+=("--with-__thread" "--with-tls");;
yann@1478
   233
        linuxthreads)   extra_config+=("--with-__thread" "--without-tls" "--without-nptl");;
yann@1478
   234
        none)           extra_config+=("--without-__thread" "--without-nptl")
yann@2467
   235
                        case "${CT_LIBC_GLIBC_EXTRA_CONFIG_ARRAY[*]}" in
yann@850
   236
                            *-tls*) ;;
yann@1478
   237
                            *) extra_config+=("--without-tls");;
yann@850
   238
                        esac
yann@850
   239
                        ;;
yann@850
   240
    esac
yann@850
   241
yann@850
   242
    case "${CT_SHARED_LIBS}" in
yann@1478
   243
        y) extra_config+=("--enable-shared");;
yann@1478
   244
        *) extra_config+=("--disable-shared");;
yann@850
   245
    esac
yann@850
   246
yann@2821
   247
    float_extra="$( echo "${extra_flags}"       \
yann@2821
   248
                    |${sed} -r -e '/^(.*[[:space:]])?-m(hard|soft)-float([[:space:]].*)?$/!d;'  \
yann@2821
   249
                               -e 's//\2/;'     \
yann@2821
   250
                  )"
yann@2821
   251
    case "${float_extra}" in
michael@2737
   252
        hard)   extra_config+=("--with-fp");;
michael@2737
   253
        soft)   extra_config+=("--without-fp");;
yann@2821
   254
        "")
yann@2821
   255
            case "${CT_ARCH_FLOAT}" in
yann@2821
   256
                hard|softfp)    extra_config+=("--with-fp");;
yann@2821
   257
                soft)           extra_config+=("--without-fp");;
yann@2821
   258
            esac
yann@2821
   259
            ;;
yann@850
   260
    esac
yann@850
   261
bryanhundven@2180
   262
    if [ "${CT_LIBC_DISABLE_VERSIONING}" = "y" ]; then
bryanhundven@2180
   263
        extra_config+=("--disable-versioning")
bryanhundven@2180
   264
    fi
bryanhundven@2180
   265
bryanhundven@2181
   266
    if [ "${CT_LIBC_OLDEST_ABI}" != "" ]; then
bryanhundven@2181
   267
        extra_config+=("--enable-oldest-abi=${CT_LIBC_OLDEST_ABI}")
bryanhundven@2181
   268
    fi
bryanhundven@2181
   269
yann@850
   270
    case "$(do_libc_add_ons_list ,)" in
benoit@2573
   271
        "") extra_config+=("--enable-add-ons=no");;
yann@1478
   272
        *)  extra_config+=("--enable-add-ons=$(do_libc_add_ons_list ,)");;
yann@850
   273
    esac
yann@850
   274
benoit@2489
   275
    if [ "${CT_LIBC_EGLIBC_HAS_PKGVERSION_BUGURL}" = "y" ]; then
benoit@2503
   276
        extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
benoit@2503
   277
        [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
benoit@2489
   278
    fi
benoit@2489
   279
yann@2822
   280
    # Extract the endianness options if any
yann@2822
   281
    # This should cover all possible endianness options
yann@2822
   282
    # in gcc, but it is prone to bit-rot... :-(
yann@2822
   283
    endian_extra="$( echo "${extra_flags}"      \
yann@2822
   284
                     |${sed} -r -e '/^(.*[[:space:]])?-(E[BL]|m((big|little)(-endian)?|e?[bl]))([[:space:]].*)?$/!d;' \
yann@2822
   285
                                -e 's//\2/;'    \
yann@2822
   286
                   )"
yann@2822
   287
    case "${endian_extra}" in
yann@2822
   288
        EB|mbig-endian|mbig|meb|mb)
yann@2822
   289
            extra_cc_args="${extra_cc_args} ${endian_extra}"
yann@2822
   290
            ;;
yann@2822
   291
        EL|mlittle-endian|mlittle|mel|ml)
yann@2822
   292
            extra_cc_args="${extra_cc_args} ${endian_extra}"
yann@2822
   293
            ;;
yann@2822
   294
        "") extra_cc_args="${extra_cc_args} ${CT_ARCH_ENDIAN_OPT}"
yann@2822
   295
            ;;
yann@2822
   296
    esac
yann@850
   297
yann@2289
   298
    touch config.cache
yann@2289
   299
    if [ "${CT_LIBC_GLIBC_FORCE_UNWIND}" = "y" ]; then
yann@2289
   300
        echo "libc_cv_forced_unwind=yes" >>config.cache
yann@2289
   301
        echo "libc_cv_c_cleanup=yes" >>config.cache
yann@2289
   302
    fi
yann@2289
   303
yann@2276
   304
    # Pre-seed the configparms file with values from the config option
yann@2276
   305
    printf "${CT_LIBC_GLIBC_CONFIGPARMS}\n" > configparms
yann@2276
   306
benoit@2489
   307
    cross_cc=$(CT_Which "${CT_TARGET}-gcc")
yann@2820
   308
    extra_cc_args+=" ${extra_flags}"
yann@850
   309
yann@2824
   310
    CT_DoLog DEBUG "Using gcc for target    : '${cross_cc}'"
yann@850
   311
    CT_DoLog DEBUG "Configuring with addons : '$(do_libc_add_ons_list ,)'"
yann@1478
   312
    CT_DoLog DEBUG "Extra config args passed: '${extra_config[*]}'"
yann@850
   313
    CT_DoLog DEBUG "Extra CC args passed    : '${extra_cc_args}'"
yann@2820
   314
    CT_DoLog DEBUG "Extra flags (multilib)  : '${extra_flags}'"
yann@850
   315
yann@2312
   316
    glibc_cflags="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} ${OPTIMIZE}"
yann@2312
   317
    case "${CT_LIBC_ENABLE_FORTIFIED_BUILD}" in
yann@2312
   318
        y)  ;;
yann@2312
   319
        *)  glibc_cflags+=" -U_FORTIFY_SOURCE";;
yann@2312
   320
    esac
yann@2312
   321
bryanhundven@2229
   322
    # ./configure is mislead by our tools override wrapper for bash
bryanhundven@2229
   323
    # so just tell it where the real bash is _on_the_target_!
bryanhundven@2229
   324
    # Notes:
bryanhundven@2229
   325
    # - ${ac_cv_path_BASH_SHELL} is only used to set BASH_SHELL
bryanhundven@2229
   326
    # - ${BASH_SHELL}            is only used to set BASH
bryanhundven@2229
   327
    # - ${BASH}                  is only used to set the shebang
bryanhundven@2229
   328
    #                            in two scripts to run on the target
bryanhundven@2229
   329
    # So we can safely bypass bash detection at compile time.
bryanhundven@2229
   330
    # Should this change in a future eglibc release, we'd better
bryanhundven@2229
   331
    # directly mangle the generated scripts _after_ they get built,
bryanhundven@2229
   332
    # or even after they get installed... eglibc is such a sucker...
yann@2289
   333
    echo "ac_cv_path_BASH_SHELL=/bin/bash" >>config.cache
bryanhundven@2229
   334
yann@2276
   335
    # Configure with --prefix the way we want it on the target...
yann@2276
   336
    # There are a whole lot of settings here.  You'll probably want
yann@2467
   337
    # to read up on what they all mean, and customize a bit, possibly by setting GLIBC_EXTRA_CONFIG_ARRAY
yann@2276
   338
    # Compare these options with the ones used when installing the glibc headers above - they're different.
yann@2276
   339
    # Adding "--without-gd" option to avoid error "memusagestat.c:36:16: gd.h: No such file or directory"
yann@2276
   340
    # See also http://sources.redhat.com/ml/libc-alpha/2000-07/msg00024.html.
yann@2276
   341
    # Set BUILD_CC, or we won't be able to build datafiles
yann@2706
   342
    # Run explicitly through CONFIG_SHELL, or the build breaks badly (loop-of-death)
yann@2706
   343
    # when the shell is not bash... Sigh... :-(
yann@2276
   344
yann@2353
   345
    CT_DoExecLog CFG                                                \
yann@1041
   346
    BUILD_CC="${CT_BUILD}-gcc"                                      \
yann@2312
   347
    CFLAGS="${glibc_cflags}"                                        \
yann@850
   348
    CC="${CT_TARGET}-gcc ${CT_LIBC_EXTRA_CC_ARGS} ${extra_cc_args}" \
yann@850
   349
    AR=${CT_TARGET}-ar                                              \
yann@850
   350
    RANLIB=${CT_TARGET}-ranlib                                      \
yann@2706
   351
    "${CONFIG_SHELL}"                                               \
yann@2271
   352
    "${src_dir}/configure"                                          \
yann@850
   353
        --prefix=/usr                                               \
yann@1041
   354
        --build=${CT_BUILD}                                         \
yann@850
   355
        --host=${CT_TARGET}                                         \
yann@2289
   356
        --cache-file="$(pwd)/config.cache"                          \
yann@2276
   357
        --without-cvs                                               \
yann@850
   358
        --disable-profile                                           \
yann@850
   359
        --without-gd                                                \
yann@2276
   360
        --with-headers="${CT_HEADERS_DIR}"                          \
yann@1478
   361
        "${extra_config[@]}"                                        \
yann@2467
   362
        "${CT_LIBC_GLIBC_EXTRA_CONFIG_ARRAY[@]}"
benoit@2489
   363
yann@2276
   364
    # build hacks
yann@2276
   365
    case "${CT_ARCH},${CT_ARCH_CPU}" in
yann@2276
   366
        powerpc,8??)
yann@2276
   367
            # http://sourceware.org/ml/crossgcc/2008-10/msg00068.html
yann@2276
   368
            CT_DoLog DEBUG "Activating support for memset on broken ppc-8xx (CPU15 erratum)"
yann@2276
   369
            extra_make_args+=( ASFLAGS="-DBROKEN_PPC_8xx_CPU15" )
yann@2271
   370
            ;;
yann@1328
   371
    esac
yann@1328
   372
yann@2826
   373
    if [ "${libc_headers}" = "y" ]; then
bryanhundven@2515
   374
        CT_DoLog EXTRA "Installing C library headers"
yann@850
   375
bryanhundven@2515
   376
        # use the 'install-headers' makefile target to install the
bryanhundven@2515
   377
        # headers
yann@2824
   378
        CT_DoExecLog ALL make ${JOBSFLAGS}                          \
yann@2823
   379
                         install_root=${CT_SYSROOT_DIR}${extra_dir} \
yann@2824
   380
                         install-bootstrap-headers=yes              \
yann@2824
   381
                         "${extra_make_args[@]}"                    \
bryanhundven@2515
   382
                         install-headers
bryanhundven@2515
   383
bryanhundven@2515
   384
        # For glibc, a few headers need to be manually installed
bryanhundven@2515
   385
        if [ "${CT_LIBC}" = "glibc" ]; then
bryanhundven@2515
   386
            # Two headers -- stubs.h and features.h -- aren't installed by install-headers,
bryanhundven@2515
   387
            # so do them by hand.  We can tolerate an empty stubs.h for the moment.
bryanhundven@2515
   388
            # See e.g. http://gcc.gnu.org/ml/gcc/2002-01/msg00900.html
bryanhundven@2515
   389
            mkdir -p "${CT_HEADERS_DIR}/gnu"
bryanhundven@2515
   390
            CT_DoExecLog ALL touch "${CT_HEADERS_DIR}/gnu/stubs.h"
bryanhundven@2515
   391
            CT_DoExecLog ALL cp -v "${CT_SRC_DIR}/glibc-${CT_LIBC_VERSION}/include/features.h"  \
bryanhundven@2515
   392
                                   "${CT_HEADERS_DIR}/features.h"
bryanhundven@2515
   393
bryanhundven@2515
   394
            # Building the bootstrap gcc requires either setting inhibit_libc, or
bryanhundven@2515
   395
            # having a copy of stdio_lim.h... see
bryanhundven@2515
   396
            # http://sources.redhat.com/ml/libc-alpha/2003-11/msg00045.html
bryanhundven@2515
   397
            CT_DoExecLog ALL cp -v bits/stdio_lim.h "${CT_HEADERS_DIR}/bits/stdio_lim.h"
bryanhundven@2515
   398
bryanhundven@2515
   399
            # Following error building gcc-4.0.0's gcj:
bryanhundven@2515
   400
            #  error: bits/syscall.h: No such file or directory
bryanhundven@2515
   401
            # solved by following copy; see http://sourceware.org/ml/crossgcc/2005-05/msg00168.html
bryanhundven@2515
   402
            # but it breaks arm, see http://sourceware.org/ml/crossgcc/2006-01/msg00091.html
bryanhundven@2515
   403
            case "${CT_ARCH}" in
bryanhundven@2515
   404
                arm)    ;;
bryanhundven@2515
   405
                *)  CT_DoExecLog ALL cp -v "misc/syscall-list.h"            \
bryanhundven@2515
   406
                                           "${CT_HEADERS_DIR}/bits/syscall.h"
bryanhundven@2515
   407
                    ;;
bryanhundven@2515
   408
            esac
bryanhundven@2515
   409
        fi
yann@2826
   410
    fi # libc_headers == y
bryanhundven@2515
   411
yann@2826
   412
    if [ "${libc_startfiles}" = "y" ]; then
bryanhundven@2515
   413
        if [ "${CT_THREADS}" = "nptl" ]; then
bryanhundven@2515
   414
            CT_DoLog EXTRA "Installing C library start files"
bryanhundven@2515
   415
bryanhundven@2515
   416
            # there are a few object files needed to link shared libraries,
bryanhundven@2515
   417
            # which we build and install by hand
yann@2823
   418
            CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}${extra_dir}/usr/lib"
bryanhundven@2515
   419
            CT_DoExecLog ALL make ${JOBSFLAGS}  \
bryanhundven@2515
   420
                        "${extra_make_args[@]}" \
bryanhundven@2515
   421
                        csu/subdir_lib
yann@2824
   422
            CT_DoExecLog ALL cp csu/crt1.o csu/crti.o csu/crtn.o    \
yann@2823
   423
                                "${CT_SYSROOT_DIR}${extra_dir}/usr/lib"
bryanhundven@2515
   424
bryanhundven@2515
   425
            # Finally, 'libgcc_s.so' requires a 'libc.so' to link against.
bryanhundven@2515
   426
            # However, since we will never actually execute its code,
bryanhundven@2515
   427
            # it doesn't matter what it contains.  So, treating '/dev/null'
bryanhundven@2515
   428
            # as a C source file, we produce a dummy 'libc.so' in one step
bryanhundven@2515
   429
            CT_DoExecLog ALL "${cross_cc}" -nostdlib        \
bryanhundven@2515
   430
                                           -nostartfiles    \
bryanhundven@2515
   431
                                           -shared          \
bryanhundven@2515
   432
                                           -x c /dev/null   \
yann@2823
   433
                                           -o "${CT_SYSROOT_DIR}${extra_dir}/usr/lib/libc.so"
bryanhundven@2515
   434
        fi # threads == nptl
yann@2826
   435
    fi # libc_headers == y
yann@2826
   436
yann@2826
   437
    if [ "${libc_full}" = "y" ]; then
bryanhundven@2515
   438
        CT_DoLog EXTRA "Building C library"
yann@2824
   439
        CT_DoExecLog ALL make ${JOBSFLAGS}              \
yann@2824
   440
                              "${extra_make_args[@]}"   \
bryanhundven@2515
   441
                              all
bryanhundven@2515
   442
bryanhundven@2515
   443
        CT_DoLog EXTRA "Installing C library"
yann@2824
   444
        CT_DoExecLog ALL make ${JOBSFLAGS}                                  \
yann@2824
   445
                              "${extra_make_args[@]}"                       \
yann@2823
   446
                              install_root="${CT_SYSROOT_DIR}${extra_dir}"  \
bryanhundven@2515
   447
                              install
benoit@2585
   448
michael@2765
   449
        if [ "${CT_BUILD_MANUALS}" = "y" ]; then
michael@2765
   450
            CT_DoLog EXTRA "Building and installing the C library manual"
michael@2765
   451
            # Omit JOBSFLAGS as GLIBC has problems building the
michael@2765
   452
            # manuals in parallel
michael@2765
   453
            CT_DoExecLog ALL make pdf html
michael@2765
   454
            # EGLIBC doesn't have a install-{pdf.html} and leaves the manuals
michael@2765
   455
            # in the source directory
michael@2765
   456
            CT_DoExecLog ALL mkdir -p ${CT_PREFIX_DIR}/share/doc
michael@2765
   457
            CT_DoExecLog ALL cp -av ${src_dir}/manual/*.pdf ${src_dir}/manual/libc \
michael@2765
   458
                ${CT_PREFIX_DIR}/share/doc
michael@2765
   459
        fi
michael@2765
   460
benoit@2585
   461
        if [ "${CT_LIBC_LOCALES}" = "y" ]; then
benoit@2585
   462
            do_libc_locales
benoit@2585
   463
        fi
yann@2826
   464
    fi # libc_full == y
yann@850
   465
}
yann@850
   466
yann@2270
   467
# This function finishes the C library install
yann@2270
   468
# This is a no-op
yann@850
   469
do_libc_finish() {
yann@850
   470
    :
yann@850
   471
}
yann@850
   472
yann@850
   473
# Build up the addons list, separated with $1
yann@850
   474
do_libc_add_ons_list() {
yann@850
   475
    local sep="$1"
yann@2274
   476
    local addons_list="$( echo "${CT_LIBC_ADDONS_LIST}"         \
yann@2274
   477
                          |sed -r -e "s/[[:space:],]/${sep}/g;" \
yann@2274
   478
                        )"
yann@850
   479
    case "${CT_THREADS}" in
yann@850
   480
        none)   ;;
yann@850
   481
        *)      addons_list="${addons_list}${sep}${CT_THREADS}";;
yann@850
   482
    esac
yann@850
   483
    [ "${CT_LIBC_GLIBC_USE_PORTS}" = "y" ] && addons_list="${addons_list}${sep}ports"
yann@2274
   484
    # Remove duplicate, leading and trailing separators
yann@2274
   485
    echo "${addons_list}" |sed -r -e "s/${sep}+/${sep}/g; s/^${sep}//; s/${sep}\$//;"
yann@850
   486
}
yann@2273
   487
yann@2273
   488
# Compute up the minimum supported Linux kernel version
yann@2273
   489
do_libc_min_kernel_config() {
yann@2273
   490
    local min_kernel_config
yann@2273
   491
yann@2467
   492
    case "${CT_LIBC_GLIBC_EXTRA_CONFIG_ARRAY[*]}" in
yann@2273
   493
        *--enable-kernel*) ;;
yann@2273
   494
        *)  if [ "${CT_LIBC_GLIBC_KERNEL_VERSION_AS_HEADERS}" = "y" ]; then
yann@2273
   495
                # We can't rely on the kernel version from the configuration,
yann@2273
   496
                # because it might not be available if the user uses pre-installed
yann@2273
   497
                # headers. On the other hand, both method will have the kernel
yann@2279
   498
                # version installed in "usr/include/linux/version.h" in the sysroot.
yann@2273
   499
                # Parse that instead of having two code-paths.
yann@2273
   500
                version_code_file="${CT_SYSROOT_DIR}/usr/include/linux/version.h"
yann@2273
   501
                if [ ! -f "${version_code_file}" -o ! -r "${version_code_file}" ]; then
yann@2273
   502
                    CT_Abort "Linux version is unavailable in installed headers files"
yann@2273
   503
                fi
yann@2273
   504
                version_code="$( grep -E LINUX_VERSION_CODE "${version_code_file}"  \
yann@2273
   505
                                 |cut -d ' ' -f 3                                   \
yann@2273
   506
                               )"
yann@2273
   507
                version=$(((version_code>>16)&0xFF))
yann@2273
   508
                patchlevel=$(((version_code>>8)&0xFF))
yann@2273
   509
                sublevel=$((version_code&0xFF))
yann@2273
   510
                min_kernel_config="${version}.${patchlevel}.${sublevel}"
yann@2273
   511
            elif [ "${CT_LIBC_GLIBC_KERNEL_VERSION_CHOSEN}" = "y" ]; then
yann@2273
   512
                # Trim the fourth part of the linux version, keeping only the first three numbers
yann@2276
   513
                min_kernel_config="$( echo "${CT_LIBC_GLIBC_MIN_KERNEL_VERSION}"            \
yann@2276
   514
                                      |sed -r -e 's/^([^.]+\.[^.]+\.[^.]+)(|\.[^.]+)$/\1/;' \
yann@2273
   515
                                    )"
yann@2273
   516
            fi
yann@2273
   517
            echo "--enable-kernel=${min_kernel_config}"
yann@2273
   518
            ;;
yann@2273
   519
    esac
yann@2273
   520
}