scripts/build/libc/glibc-eglibc.sh-common
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed Dec 28 17:05:46 2011 +0100 (2011-12-28)
changeset 2828 e47d17391ae3
parent 2827 f8f2f75ff3fd
child 2883 cea814c9932a
permissions -rw-r--r--
libc/glibc: cleanup CFLAGS handling

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@2827
   168
                # Remove the multi_dir now it is no longer useful
yann@2827
   169
                CT_DoExecLog DEBUG rm -rf "${CT_SYSROOT_DIR}/${multi_dir}"
yann@2825
   170
            fi # libc_mode == final
yann@2827
   171
yann@2825
   172
            CT_EndStep
yann@2825
   173
        fi
yann@2825
   174
    done
yann@2825
   175
yann@2825
   176
    CT_EndStep
yann@2825
   177
}
yann@2825
   178
yann@2825
   179
# This backend builds the C library once
yann@2825
   180
# Usage: do_libc_backend_once param=value [...]
yann@2825
   181
#   Parameter           : Definition                            : Type      : Default
yann@2826
   182
#   libc_headers        : Build libc headers                    : bool      : n
yann@2826
   183
#   libc_startfiles     : Build libc start-files                : bool      : n
yann@2826
   184
#   libc_full           : Build full libc                       : bool      : n
yann@2820
   185
#   extra_flags         : Extra CFLAGS to use (for multilib)    : string    : (empty)
yann@2823
   186
#   extra_dir           : Extra subdir for multilib             : string    : (empty)
yann@2825
   187
do_libc_backend_once() {
yann@2826
   188
    local libc_headers
yann@2826
   189
    local libc_startfiles
yann@2826
   190
    local libc_full
yann@2820
   191
    local extra_flags
yann@2823
   192
    local extra_dir
yann@2271
   193
    local src_dir="${CT_SRC_DIR}/${CT_LIBC}-${CT_LIBC_VERSION}"
yann@2276
   194
    local extra_cc_args
yann@1478
   195
    local -a extra_config
yann@2271
   196
    local -a extra_make_args
yann@2312
   197
    local glibc_cflags
yann@2821
   198
    local float_extra
yann@2822
   199
    local endian_extra
yann@1478
   200
bryanhundven@2515
   201
    while [ $# -ne 0 ]; do
yann@2542
   202
        eval "${1// /\\ }"
bryanhundven@2515
   203
        shift
bryanhundven@2515
   204
    done
yann@850
   205
yann@850
   206
    CT_DoLog EXTRA "Configuring C library"
yann@850
   207
yann@2271
   208
    case "${CT_LIBC}" in
yann@2271
   209
        eglibc)
yann@2271
   210
            if [ "${CT_EGLIBC_CUSTOM_CONFIG}" = "y" ]; then
yann@2271
   211
                CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/eglibc.config" option-groups.config
yann@2271
   212
            fi
yann@2271
   213
            if [ "${CT_EGLIBC_OPT_SIZE}" = "y" ]; then
yann@2271
   214
                OPTIMIZE=-Os
yann@2271
   215
            else
yann@2271
   216
                OPTIMIZE=-O2
yann@2271
   217
            fi
yann@2271
   218
            ;;
yann@2276
   219
        glibc)
yann@2276
   220
            # glibc can't be built without -O2 (reference needed!)
yann@2276
   221
            OPTIMIZE=-O2
yann@2276
   222
            # Also, if those two are missing, iconv build breaks
yann@2276
   223
            extra_config+=( --disable-debug --disable-sanity-checks )
yann@2276
   224
            ;;
yann@2271
   225
    esac
richard@1796
   226
yann@850
   227
    # Add some default glibc config options if not given by user.
yann@850
   228
    # We don't need to be conditional on wether the user did set different
yann@2467
   229
    # values, as they CT_LIBC_GLIBC_EXTRA_CONFIG_ARRAY is passed after
yann@2467
   230
    # extra_config
yann@850
   231
yann@2273
   232
    extra_config+=("$(do_libc_min_kernel_config)")
yann@850
   233
yann@850
   234
    case "${CT_THREADS}" in
yann@1478
   235
        nptl)           extra_config+=("--with-__thread" "--with-tls");;
yann@1478
   236
        linuxthreads)   extra_config+=("--with-__thread" "--without-tls" "--without-nptl");;
yann@1478
   237
        none)           extra_config+=("--without-__thread" "--without-nptl")
yann@2467
   238
                        case "${CT_LIBC_GLIBC_EXTRA_CONFIG_ARRAY[*]}" in
yann@850
   239
                            *-tls*) ;;
yann@1478
   240
                            *) extra_config+=("--without-tls");;
yann@850
   241
                        esac
yann@850
   242
                        ;;
yann@850
   243
    esac
yann@850
   244
yann@850
   245
    case "${CT_SHARED_LIBS}" in
yann@1478
   246
        y) extra_config+=("--enable-shared");;
yann@1478
   247
        *) extra_config+=("--disable-shared");;
yann@850
   248
    esac
yann@850
   249
yann@2821
   250
    float_extra="$( echo "${extra_flags}"       \
yann@2821
   251
                    |${sed} -r -e '/^(.*[[:space:]])?-m(hard|soft)-float([[:space:]].*)?$/!d;'  \
yann@2821
   252
                               -e 's//\2/;'     \
yann@2821
   253
                  )"
yann@2821
   254
    case "${float_extra}" in
michael@2737
   255
        hard)   extra_config+=("--with-fp");;
michael@2737
   256
        soft)   extra_config+=("--without-fp");;
yann@2821
   257
        "")
yann@2821
   258
            case "${CT_ARCH_FLOAT}" in
yann@2821
   259
                hard|softfp)    extra_config+=("--with-fp");;
yann@2821
   260
                soft)           extra_config+=("--without-fp");;
yann@2821
   261
            esac
yann@2821
   262
            ;;
yann@850
   263
    esac
yann@850
   264
bryanhundven@2180
   265
    if [ "${CT_LIBC_DISABLE_VERSIONING}" = "y" ]; then
bryanhundven@2180
   266
        extra_config+=("--disable-versioning")
bryanhundven@2180
   267
    fi
bryanhundven@2180
   268
bryanhundven@2181
   269
    if [ "${CT_LIBC_OLDEST_ABI}" != "" ]; then
bryanhundven@2181
   270
        extra_config+=("--enable-oldest-abi=${CT_LIBC_OLDEST_ABI}")
bryanhundven@2181
   271
    fi
bryanhundven@2181
   272
yann@850
   273
    case "$(do_libc_add_ons_list ,)" in
benoit@2573
   274
        "") extra_config+=("--enable-add-ons=no");;
yann@1478
   275
        *)  extra_config+=("--enable-add-ons=$(do_libc_add_ons_list ,)");;
yann@850
   276
    esac
yann@850
   277
benoit@2489
   278
    if [ "${CT_LIBC_EGLIBC_HAS_PKGVERSION_BUGURL}" = "y" ]; then
benoit@2503
   279
        extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
benoit@2503
   280
        [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
benoit@2489
   281
    fi
benoit@2489
   282
yann@2822
   283
    # Extract the endianness options if any
yann@2822
   284
    # This should cover all possible endianness options
yann@2822
   285
    # in gcc, but it is prone to bit-rot... :-(
yann@2822
   286
    endian_extra="$( echo "${extra_flags}"      \
yann@2822
   287
                     |${sed} -r -e '/^(.*[[:space:]])?-(E[BL]|m((big|little)(-endian)?|e?[bl]))([[:space:]].*)?$/!d;' \
yann@2822
   288
                                -e 's//\2/;'    \
yann@2822
   289
                   )"
yann@2822
   290
    case "${endian_extra}" in
yann@2822
   291
        EB|mbig-endian|mbig|meb|mb)
yann@2822
   292
            extra_cc_args="${extra_cc_args} ${endian_extra}"
yann@2822
   293
            ;;
yann@2822
   294
        EL|mlittle-endian|mlittle|mel|ml)
yann@2822
   295
            extra_cc_args="${extra_cc_args} ${endian_extra}"
yann@2822
   296
            ;;
yann@2822
   297
        "") extra_cc_args="${extra_cc_args} ${CT_ARCH_ENDIAN_OPT}"
yann@2822
   298
            ;;
yann@2822
   299
    esac
yann@850
   300
yann@2289
   301
    touch config.cache
yann@2289
   302
    if [ "${CT_LIBC_GLIBC_FORCE_UNWIND}" = "y" ]; then
yann@2289
   303
        echo "libc_cv_forced_unwind=yes" >>config.cache
yann@2289
   304
        echo "libc_cv_c_cleanup=yes" >>config.cache
yann@2289
   305
    fi
yann@2289
   306
yann@2276
   307
    # Pre-seed the configparms file with values from the config option
yann@2276
   308
    printf "${CT_LIBC_GLIBC_CONFIGPARMS}\n" > configparms
yann@2276
   309
benoit@2489
   310
    cross_cc=$(CT_Which "${CT_TARGET}-gcc")
yann@2820
   311
    extra_cc_args+=" ${extra_flags}"
yann@850
   312
yann@2312
   313
    case "${CT_LIBC_ENABLE_FORTIFIED_BUILD}" in
yann@2312
   314
        y)  ;;
yann@2312
   315
        *)  glibc_cflags+=" -U_FORTIFY_SOURCE";;
yann@2312
   316
    esac
yann@2828
   317
    glibc_cflags+=" ${CT_TARGET_CFLAGS} ${OPTIMIZE} ${CT_LIBC_GLIBC_EXTRA_CFLAGS}"
yann@2312
   318
bryanhundven@2229
   319
    # ./configure is mislead by our tools override wrapper for bash
bryanhundven@2229
   320
    # so just tell it where the real bash is _on_the_target_!
bryanhundven@2229
   321
    # Notes:
bryanhundven@2229
   322
    # - ${ac_cv_path_BASH_SHELL} is only used to set BASH_SHELL
bryanhundven@2229
   323
    # - ${BASH_SHELL}            is only used to set BASH
bryanhundven@2229
   324
    # - ${BASH}                  is only used to set the shebang
bryanhundven@2229
   325
    #                            in two scripts to run on the target
bryanhundven@2229
   326
    # So we can safely bypass bash detection at compile time.
bryanhundven@2229
   327
    # Should this change in a future eglibc release, we'd better
bryanhundven@2229
   328
    # directly mangle the generated scripts _after_ they get built,
bryanhundven@2229
   329
    # or even after they get installed... eglibc is such a sucker...
yann@2289
   330
    echo "ac_cv_path_BASH_SHELL=/bin/bash" >>config.cache
bryanhundven@2229
   331
yann@2276
   332
    # Configure with --prefix the way we want it on the target...
yann@2276
   333
    # There are a whole lot of settings here.  You'll probably want
yann@2467
   334
    # to read up on what they all mean, and customize a bit, possibly by setting GLIBC_EXTRA_CONFIG_ARRAY
yann@2276
   335
    # Compare these options with the ones used when installing the glibc headers above - they're different.
yann@2276
   336
    # Adding "--without-gd" option to avoid error "memusagestat.c:36:16: gd.h: No such file or directory"
yann@2276
   337
    # See also http://sources.redhat.com/ml/libc-alpha/2000-07/msg00024.html.
yann@2276
   338
    # Set BUILD_CC, or we won't be able to build datafiles
yann@2706
   339
    # Run explicitly through CONFIG_SHELL, or the build breaks badly (loop-of-death)
yann@2706
   340
    # when the shell is not bash... Sigh... :-(
yann@2276
   341
yann@2828
   342
    CT_DoLog DEBUG "Using gcc for target    : '${cross_cc}'"
yann@2828
   343
    CT_DoLog DEBUG "Configuring with addons : '$(do_libc_add_ons_list ,)'"
yann@2828
   344
    CT_DoLog DEBUG "Extra config args passed: '${extra_config[*]}'"
yann@2828
   345
    CT_DoLog DEBUG "Extra CC args passed    : '${glibc_cflags}'"
yann@2828
   346
    CT_DoLog DEBUG "Extra flags (multilib)  : '${extra_flags}'"
yann@2828
   347
yann@2353
   348
    CT_DoExecLog CFG                                                \
yann@1041
   349
    BUILD_CC="${CT_BUILD}-gcc"                                      \
yann@2312
   350
    CFLAGS="${glibc_cflags}"                                        \
yann@850
   351
    CC="${CT_TARGET}-gcc ${CT_LIBC_EXTRA_CC_ARGS} ${extra_cc_args}" \
yann@850
   352
    AR=${CT_TARGET}-ar                                              \
yann@850
   353
    RANLIB=${CT_TARGET}-ranlib                                      \
yann@2706
   354
    "${CONFIG_SHELL}"                                               \
yann@2271
   355
    "${src_dir}/configure"                                          \
yann@850
   356
        --prefix=/usr                                               \
yann@1041
   357
        --build=${CT_BUILD}                                         \
yann@850
   358
        --host=${CT_TARGET}                                         \
yann@2289
   359
        --cache-file="$(pwd)/config.cache"                          \
yann@2276
   360
        --without-cvs                                               \
yann@850
   361
        --disable-profile                                           \
yann@850
   362
        --without-gd                                                \
yann@2276
   363
        --with-headers="${CT_HEADERS_DIR}"                          \
yann@1478
   364
        "${extra_config[@]}"                                        \
yann@2467
   365
        "${CT_LIBC_GLIBC_EXTRA_CONFIG_ARRAY[@]}"
benoit@2489
   366
yann@2276
   367
    # build hacks
yann@2276
   368
    case "${CT_ARCH},${CT_ARCH_CPU}" in
yann@2276
   369
        powerpc,8??)
yann@2276
   370
            # http://sourceware.org/ml/crossgcc/2008-10/msg00068.html
yann@2276
   371
            CT_DoLog DEBUG "Activating support for memset on broken ppc-8xx (CPU15 erratum)"
yann@2276
   372
            extra_make_args+=( ASFLAGS="-DBROKEN_PPC_8xx_CPU15" )
yann@2271
   373
            ;;
yann@1328
   374
    esac
yann@1328
   375
yann@2826
   376
    if [ "${libc_headers}" = "y" ]; then
bryanhundven@2515
   377
        CT_DoLog EXTRA "Installing C library headers"
yann@850
   378
bryanhundven@2515
   379
        # use the 'install-headers' makefile target to install the
bryanhundven@2515
   380
        # headers
yann@2824
   381
        CT_DoExecLog ALL make ${JOBSFLAGS}                          \
yann@2823
   382
                         install_root=${CT_SYSROOT_DIR}${extra_dir} \
yann@2824
   383
                         install-bootstrap-headers=yes              \
yann@2824
   384
                         "${extra_make_args[@]}"                    \
bryanhundven@2515
   385
                         install-headers
bryanhundven@2515
   386
bryanhundven@2515
   387
        # For glibc, a few headers need to be manually installed
bryanhundven@2515
   388
        if [ "${CT_LIBC}" = "glibc" ]; then
bryanhundven@2515
   389
            # Two headers -- stubs.h and features.h -- aren't installed by install-headers,
bryanhundven@2515
   390
            # so do them by hand.  We can tolerate an empty stubs.h for the moment.
bryanhundven@2515
   391
            # See e.g. http://gcc.gnu.org/ml/gcc/2002-01/msg00900.html
bryanhundven@2515
   392
            mkdir -p "${CT_HEADERS_DIR}/gnu"
bryanhundven@2515
   393
            CT_DoExecLog ALL touch "${CT_HEADERS_DIR}/gnu/stubs.h"
bryanhundven@2515
   394
            CT_DoExecLog ALL cp -v "${CT_SRC_DIR}/glibc-${CT_LIBC_VERSION}/include/features.h"  \
bryanhundven@2515
   395
                                   "${CT_HEADERS_DIR}/features.h"
bryanhundven@2515
   396
bryanhundven@2515
   397
            # Building the bootstrap gcc requires either setting inhibit_libc, or
bryanhundven@2515
   398
            # having a copy of stdio_lim.h... see
bryanhundven@2515
   399
            # http://sources.redhat.com/ml/libc-alpha/2003-11/msg00045.html
bryanhundven@2515
   400
            CT_DoExecLog ALL cp -v bits/stdio_lim.h "${CT_HEADERS_DIR}/bits/stdio_lim.h"
bryanhundven@2515
   401
bryanhundven@2515
   402
            # Following error building gcc-4.0.0's gcj:
bryanhundven@2515
   403
            #  error: bits/syscall.h: No such file or directory
bryanhundven@2515
   404
            # solved by following copy; see http://sourceware.org/ml/crossgcc/2005-05/msg00168.html
bryanhundven@2515
   405
            # but it breaks arm, see http://sourceware.org/ml/crossgcc/2006-01/msg00091.html
bryanhundven@2515
   406
            case "${CT_ARCH}" in
bryanhundven@2515
   407
                arm)    ;;
bryanhundven@2515
   408
                *)  CT_DoExecLog ALL cp -v "misc/syscall-list.h"            \
bryanhundven@2515
   409
                                           "${CT_HEADERS_DIR}/bits/syscall.h"
bryanhundven@2515
   410
                    ;;
bryanhundven@2515
   411
            esac
bryanhundven@2515
   412
        fi
yann@2826
   413
    fi # libc_headers == y
bryanhundven@2515
   414
yann@2826
   415
    if [ "${libc_startfiles}" = "y" ]; then
bryanhundven@2515
   416
        if [ "${CT_THREADS}" = "nptl" ]; then
bryanhundven@2515
   417
            CT_DoLog EXTRA "Installing C library start files"
bryanhundven@2515
   418
bryanhundven@2515
   419
            # there are a few object files needed to link shared libraries,
bryanhundven@2515
   420
            # which we build and install by hand
yann@2823
   421
            CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}${extra_dir}/usr/lib"
bryanhundven@2515
   422
            CT_DoExecLog ALL make ${JOBSFLAGS}  \
bryanhundven@2515
   423
                        "${extra_make_args[@]}" \
bryanhundven@2515
   424
                        csu/subdir_lib
yann@2824
   425
            CT_DoExecLog ALL cp csu/crt1.o csu/crti.o csu/crtn.o    \
yann@2823
   426
                                "${CT_SYSROOT_DIR}${extra_dir}/usr/lib"
bryanhundven@2515
   427
bryanhundven@2515
   428
            # Finally, 'libgcc_s.so' requires a 'libc.so' to link against.
bryanhundven@2515
   429
            # However, since we will never actually execute its code,
bryanhundven@2515
   430
            # it doesn't matter what it contains.  So, treating '/dev/null'
bryanhundven@2515
   431
            # as a C source file, we produce a dummy 'libc.so' in one step
bryanhundven@2515
   432
            CT_DoExecLog ALL "${cross_cc}" -nostdlib        \
bryanhundven@2515
   433
                                           -nostartfiles    \
bryanhundven@2515
   434
                                           -shared          \
bryanhundven@2515
   435
                                           -x c /dev/null   \
yann@2823
   436
                                           -o "${CT_SYSROOT_DIR}${extra_dir}/usr/lib/libc.so"
bryanhundven@2515
   437
        fi # threads == nptl
yann@2826
   438
    fi # libc_headers == y
yann@2826
   439
yann@2826
   440
    if [ "${libc_full}" = "y" ]; then
bryanhundven@2515
   441
        CT_DoLog EXTRA "Building C library"
yann@2824
   442
        CT_DoExecLog ALL make ${JOBSFLAGS}              \
yann@2824
   443
                              "${extra_make_args[@]}"   \
bryanhundven@2515
   444
                              all
bryanhundven@2515
   445
bryanhundven@2515
   446
        CT_DoLog EXTRA "Installing C library"
yann@2824
   447
        CT_DoExecLog ALL make ${JOBSFLAGS}                                  \
yann@2824
   448
                              "${extra_make_args[@]}"                       \
yann@2823
   449
                              install_root="${CT_SYSROOT_DIR}${extra_dir}"  \
bryanhundven@2515
   450
                              install
benoit@2585
   451
michael@2765
   452
        if [ "${CT_BUILD_MANUALS}" = "y" ]; then
michael@2765
   453
            CT_DoLog EXTRA "Building and installing the C library manual"
michael@2765
   454
            # Omit JOBSFLAGS as GLIBC has problems building the
michael@2765
   455
            # manuals in parallel
michael@2765
   456
            CT_DoExecLog ALL make pdf html
michael@2765
   457
            # EGLIBC doesn't have a install-{pdf.html} and leaves the manuals
michael@2765
   458
            # in the source directory
michael@2765
   459
            CT_DoExecLog ALL mkdir -p ${CT_PREFIX_DIR}/share/doc
michael@2765
   460
            CT_DoExecLog ALL cp -av ${src_dir}/manual/*.pdf ${src_dir}/manual/libc \
michael@2765
   461
                ${CT_PREFIX_DIR}/share/doc
michael@2765
   462
        fi
michael@2765
   463
benoit@2585
   464
        if [ "${CT_LIBC_LOCALES}" = "y" ]; then
benoit@2585
   465
            do_libc_locales
benoit@2585
   466
        fi
yann@2826
   467
    fi # libc_full == y
yann@850
   468
}
yann@850
   469
yann@2270
   470
# This function finishes the C library install
yann@2270
   471
# This is a no-op
yann@850
   472
do_libc_finish() {
yann@850
   473
    :
yann@850
   474
}
yann@850
   475
yann@850
   476
# Build up the addons list, separated with $1
yann@850
   477
do_libc_add_ons_list() {
yann@850
   478
    local sep="$1"
yann@2274
   479
    local addons_list="$( echo "${CT_LIBC_ADDONS_LIST}"         \
yann@2274
   480
                          |sed -r -e "s/[[:space:],]/${sep}/g;" \
yann@2274
   481
                        )"
yann@850
   482
    case "${CT_THREADS}" in
yann@850
   483
        none)   ;;
yann@850
   484
        *)      addons_list="${addons_list}${sep}${CT_THREADS}";;
yann@850
   485
    esac
yann@850
   486
    [ "${CT_LIBC_GLIBC_USE_PORTS}" = "y" ] && addons_list="${addons_list}${sep}ports"
yann@2274
   487
    # Remove duplicate, leading and trailing separators
yann@2274
   488
    echo "${addons_list}" |sed -r -e "s/${sep}+/${sep}/g; s/^${sep}//; s/${sep}\$//;"
yann@850
   489
}
yann@2273
   490
yann@2273
   491
# Compute up the minimum supported Linux kernel version
yann@2273
   492
do_libc_min_kernel_config() {
yann@2273
   493
    local min_kernel_config
yann@2273
   494
yann@2467
   495
    case "${CT_LIBC_GLIBC_EXTRA_CONFIG_ARRAY[*]}" in
yann@2273
   496
        *--enable-kernel*) ;;
yann@2273
   497
        *)  if [ "${CT_LIBC_GLIBC_KERNEL_VERSION_AS_HEADERS}" = "y" ]; then
yann@2273
   498
                # We can't rely on the kernel version from the configuration,
yann@2273
   499
                # because it might not be available if the user uses pre-installed
yann@2273
   500
                # headers. On the other hand, both method will have the kernel
yann@2279
   501
                # version installed in "usr/include/linux/version.h" in the sysroot.
yann@2273
   502
                # Parse that instead of having two code-paths.
yann@2273
   503
                version_code_file="${CT_SYSROOT_DIR}/usr/include/linux/version.h"
yann@2273
   504
                if [ ! -f "${version_code_file}" -o ! -r "${version_code_file}" ]; then
yann@2273
   505
                    CT_Abort "Linux version is unavailable in installed headers files"
yann@2273
   506
                fi
yann@2273
   507
                version_code="$( grep -E LINUX_VERSION_CODE "${version_code_file}"  \
yann@2273
   508
                                 |cut -d ' ' -f 3                                   \
yann@2273
   509
                               )"
yann@2273
   510
                version=$(((version_code>>16)&0xFF))
yann@2273
   511
                patchlevel=$(((version_code>>8)&0xFF))
yann@2273
   512
                sublevel=$((version_code&0xFF))
yann@2273
   513
                min_kernel_config="${version}.${patchlevel}.${sublevel}"
yann@2273
   514
            elif [ "${CT_LIBC_GLIBC_KERNEL_VERSION_CHOSEN}" = "y" ]; then
yann@2273
   515
                # Trim the fourth part of the linux version, keeping only the first three numbers
yann@2276
   516
                min_kernel_config="$( echo "${CT_LIBC_GLIBC_MIN_KERNEL_VERSION}"            \
yann@2276
   517
                                      |sed -r -e 's/^([^.]+\.[^.]+\.[^.]+)(|\.[^.]+)$/\1/;' \
yann@2273
   518
                                    )"
yann@2273
   519
            fi
yann@2273
   520
            echo "--enable-kernel=${min_kernel_config}"
yann@2273
   521
            ;;
yann@2273
   522
    esac
yann@2273
   523
}