scripts/build/libc/glibc-eglibc.sh-common
author Johannes Stezenbach <js@sig21.net>
Fri Nov 02 04:04:04 2012 +0000 (2012-11-02)
changeset 3102 75c2df0f7a12
parent 3087 17cdb10b1675
child 3118 51160d293e1f
permissions -rw-r--r--
libc/eglibc: enable rpc in eglibc-2.16+

While eglibc-2.16 recommends to use TI-RPC instead of the old sunrpc, the
old one can be included using a configure option. Since the user can still
use TI-RPC to override the libc implementation, we enable rpc unconditionally.

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