scripts/build/libc/glibc-eglibc.sh-common
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon Jan 17 23:04:57 2011 +0100 (2011-01-17)
changeset 2271 42ebee266fe5
parent 2270 287e1e00dea4
child 2272 0ff5b3570cd6
permissions -rw-r--r--
libc/eglibc: cleanup common code for sharing with glibc

Some stuff is eglibc-specific, so needs to be conditonal.

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@2270
     3
# Build and install headers file
yann@2270
     4
# This is a no-op
yann@850
     5
do_libc_headers() {
yann@850
     6
    :
yann@850
     7
}
yann@850
     8
yann@2270
     9
# Build and install headers and start files
yann@850
    10
do_libc_start_files() {
yann@2271
    11
    local src_dir="${CT_SRC_DIR}/${CT_LIBC}-${CT_LIBC_VERSION}"
yann@2271
    12
yann@850
    13
    CT_DoStep INFO "Installing C library headers / start files"
yann@850
    14
yann@850
    15
    mkdir -p "${CT_BUILD_DIR}/build-libc-startfiles"
yann@850
    16
    cd "${CT_BUILD_DIR}/build-libc-startfiles"
yann@850
    17
yann@850
    18
    CT_DoLog EXTRA "Configuring C library"
yann@850
    19
yann@2271
    20
    case "${CT_LIBC}" in
yann@2271
    21
        eglibc)
yann@2271
    22
            if [ "${CT_EGLIBC_CUSTOM_CONFIG}" = "y" ]; then
yann@2271
    23
                CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/eglibc.config" option-groups.config
yann@2271
    24
            fi
yann@2271
    25
            ;;
yann@2271
    26
    esac
avrac@1569
    27
yann@850
    28
    cross_cc=$(CT_Which "${CT_TARGET}-gcc")
yann@850
    29
    cross_cxx=$(CT_Which "${CT_TARGET}-g++")
yann@850
    30
    cross_ar=$(CT_Which "${CT_TARGET}-ar")
yann@850
    31
    cross_ranlib=$(CT_Which "${CT_TARGET}-ranlib")
yann@2271
    32
yann@850
    33
    CT_DoLog DEBUG "Using gcc for target: '${cross_cc}'"
yann@850
    34
    CT_DoLog DEBUG "Using g++ for target: '${cross_cxx}'"
yann@850
    35
    CT_DoLog DEBUG "Using ar for target: '${cross_ar}'"
yann@850
    36
    CT_DoLog DEBUG "Using ranlib for target: '${cross_ranlib}'"
yann@850
    37
yann@1123
    38
    BUILD_CC="${CT_BUILD}-gcc"                          \
yann@1123
    39
    CC=${cross_cc}                                      \
yann@1123
    40
    CXX=${cross_cxx}                                    \
yann@1123
    41
    AR=${cross_ar}                                      \
yann@1123
    42
    RANLIB=${cross_ranlib}                              \
anthony@2154
    43
    CT_DoExecLog CFG                                    \
yann@2271
    44
    "${src_dir}/configure"                              \
yann@1123
    45
        --prefix=/usr                                   \
yann@1123
    46
        --with-headers="${CT_HEADERS_DIR}"              \
yann@1123
    47
        --build="${CT_BUILD}"                           \
yann@1123
    48
        --host="${CT_TARGET}"                           \
yann@1123
    49
        --disable-profile                               \
yann@1123
    50
        --without-gd                                    \
yann@1123
    51
        --without-cvs                                   \
yann@850
    52
        --enable-add-ons
yann@850
    53
yann@850
    54
    CT_DoLog EXTRA "Installing C library headers"
yann@850
    55
yann@850
    56
    # use the 'install-headers' makefile target to install the
yann@850
    57
    # headers
yann@850
    58
    CT_DoExecLog ALL                    \
yann@850
    59
    make install-headers                \
yann@850
    60
         install_root=${CT_SYSROOT_DIR} \
yann@850
    61
         install-bootstrap-headers=yes
yann@850
    62
yann@850
    63
    CT_DoLog EXTRA "Installing C library start files"
yann@850
    64
yann@850
    65
    # there are a few object files needed to link shared libraries,
yann@850
    66
    # which we build and install by hand
yann@2271
    67
    CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/usr/lib"
yann@850
    68
    CT_DoExecLog ALL make csu/subdir_lib
yann@850
    69
    CT_DoExecLog ALL cp csu/crt1.o csu/crti.o csu/crtn.o \
yann@2271
    70
                        "${CT_SYSROOT_DIR}/usr/lib"
yann@850
    71
yann@2271
    72
    # Finally, 'libgcc_s.so' requires a 'libc.so' to link against.
yann@2271
    73
    # However, since we will never actually execute its code,
yann@2271
    74
    # it doesn't matter what it contains.  So, treating '/dev/null'
yann@850
    75
    # as a C source file, we produce a dummy 'libc.so' in one step
yann@2271
    76
    CT_DoExecLog ALL "${cross_cc}" -nostdlib        \
yann@2271
    77
                                   -nostartfiles    \
yann@2271
    78
                                   -shared          \
yann@2271
    79
                                   -x c /dev/null   \
yann@2271
    80
                                   -o "${CT_SYSROOT_DIR}/usr/lib/libc.so"
yann@850
    81
yann@850
    82
    CT_EndStep
yann@850
    83
}
yann@850
    84
yann@2270
    85
# This function builds and install the full C library
yann@850
    86
do_libc() {
yann@2271
    87
    local src_dir="${CT_SRC_DIR}/${CT_LIBC}-${CT_LIBC_VERSION}"
yann@1478
    88
    local -a extra_config
yann@2271
    89
    local -a extra_make_args
yann@1478
    90
yann@850
    91
    CT_DoStep INFO "Installing C library"
yann@850
    92
yann@850
    93
    mkdir -p "${CT_BUILD_DIR}/build-libc"
yann@850
    94
    cd "${CT_BUILD_DIR}/build-libc"
yann@850
    95
yann@850
    96
    CT_DoLog EXTRA "Configuring C library"
yann@850
    97
yann@2271
    98
    case "${CT_LIBC}" in
yann@2271
    99
        eglibc)
yann@2271
   100
            if [ "${CT_EGLIBC_CUSTOM_CONFIG}" = "y" ]; then
yann@2271
   101
                CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/eglibc.config" option-groups.config
yann@2271
   102
            fi
yann@2271
   103
            if [ "${CT_EGLIBC_OPT_SIZE}" = "y" ]; then
yann@2271
   104
                OPTIMIZE=-Os
yann@2271
   105
            else
yann@2271
   106
                OPTIMIZE=-O2
yann@2271
   107
            fi
yann@2271
   108
            ;;
yann@2271
   109
    esac
richard@1796
   110
yann@850
   111
    # Add some default glibc config options if not given by user.
yann@850
   112
    # We don't need to be conditional on wether the user did set different
yann@850
   113
    # values, as they CT_LIBC_GLIBC_EXTRA_CONFIG is passed after extra_config
yann@850
   114
yann@1478
   115
    extra_config+=("--enable-kernel=$(echo ${CT_LIBC_GLIBC_MIN_KERNEL} |sed -r -e 's/^([^.]+\.[^.]+\.[^.]+)(|\.[^.]+)$/\1/;')")
yann@850
   116
yann@850
   117
    case "${CT_THREADS}" in
yann@1478
   118
        nptl)           extra_config+=("--with-__thread" "--with-tls");;
yann@1478
   119
        linuxthreads)   extra_config+=("--with-__thread" "--without-tls" "--without-nptl");;
yann@1478
   120
        none)           extra_config+=("--without-__thread" "--without-nptl")
yann@850
   121
                        case "${CT_LIBC_GLIBC_EXTRA_CONFIG}" in
yann@850
   122
                            *-tls*) ;;
yann@1478
   123
                            *) extra_config+=("--without-tls");;
yann@850
   124
                        esac
yann@850
   125
                        ;;
yann@850
   126
    esac
yann@850
   127
yann@850
   128
    case "${CT_SHARED_LIBS}" in
yann@1478
   129
        y) extra_config+=("--enable-shared");;
yann@1478
   130
        *) extra_config+=("--disable-shared");;
yann@850
   131
    esac
yann@850
   132
yann@850
   133
    case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
yann@1478
   134
        y,) extra_config+=("--with-fp");;
yann@1478
   135
        ,y) extra_config+=("--without-fp");;
yann@850
   136
    esac
yann@850
   137
bryanhundven@2180
   138
    if [ "${CT_LIBC_DISABLE_VERSIONING}" = "y" ]; then
bryanhundven@2180
   139
        extra_config+=("--disable-versioning")
bryanhundven@2180
   140
    fi
bryanhundven@2180
   141
bryanhundven@2181
   142
    if [ "${CT_LIBC_OLDEST_ABI}" != "" ]; then
bryanhundven@2181
   143
        extra_config+=("--enable-oldest-abi=${CT_LIBC_OLDEST_ABI}")
bryanhundven@2181
   144
    fi
bryanhundven@2181
   145
yann@850
   146
    case "$(do_libc_add_ons_list ,)" in
yann@850
   147
        "") ;;
yann@1478
   148
        *)  extra_config+=("--enable-add-ons=$(do_libc_add_ons_list ,)");;
yann@850
   149
    esac
yann@850
   150
yann@850
   151
    extra_cc_args="${extra_cc_args} ${CT_ARCH_ENDIAN_OPT}"
yann@850
   152
yann@850
   153
    cross_cc=$(CT_Which "${CT_TARGET}-gcc")    
yann@850
   154
yann@850
   155
    CT_DoLog DEBUG "Using gcc for target:     '${cross_cc}'"
yann@850
   156
    CT_DoLog DEBUG "Configuring with addons : '$(do_libc_add_ons_list ,)'"
yann@1478
   157
    CT_DoLog DEBUG "Extra config args passed: '${extra_config[*]}'"
yann@850
   158
    CT_DoLog DEBUG "Extra CC args passed    : '${extra_cc_args}'"
yann@850
   159
bryanhundven@2229
   160
    # ./configure is mislead by our tools override wrapper for bash
bryanhundven@2229
   161
    # so just tell it where the real bash is _on_the_target_!
bryanhundven@2229
   162
    # Notes:
bryanhundven@2229
   163
    # - ${ac_cv_path_BASH_SHELL} is only used to set BASH_SHELL
bryanhundven@2229
   164
    # - ${BASH_SHELL}            is only used to set BASH
bryanhundven@2229
   165
    # - ${BASH}                  is only used to set the shebang
bryanhundven@2229
   166
    #                            in two scripts to run on the target
bryanhundven@2229
   167
    # So we can safely bypass bash detection at compile time.
bryanhundven@2229
   168
    # Should this change in a future eglibc release, we'd better
bryanhundven@2229
   169
    # directly mangle the generated scripts _after_ they get built,
bryanhundven@2229
   170
    # or even after they get installed... eglibc is such a sucker...
bryanhundven@2229
   171
    echo "ac_cv_path_BASH_SHELL=/bin/bash" >config.cache
bryanhundven@2229
   172
yann@1041
   173
    BUILD_CC="${CT_BUILD}-gcc"                                      \
richard@1796
   174
    CFLAGS="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} ${OPTIMIZE}"  \
yann@850
   175
    CC="${CT_TARGET}-gcc ${CT_LIBC_EXTRA_CC_ARGS} ${extra_cc_args}" \
yann@850
   176
    AR=${CT_TARGET}-ar                                              \
yann@850
   177
    RANLIB=${CT_TARGET}-ranlib                                      \
anthony@2154
   178
    CT_DoExecLog CFG                                                \
yann@2271
   179
    "${src_dir}/configure"                                          \
yann@850
   180
        --prefix=/usr                                               \
yann@850
   181
        --with-headers="${CT_HEADERS_DIR}"                          \
yann@1041
   182
        --build=${CT_BUILD}                                         \
yann@850
   183
        --host=${CT_TARGET}                                         \
yann@850
   184
        --disable-profile                                           \
yann@850
   185
        --without-gd                                                \
yann@850
   186
        --without-cvs                                               \
bryanhundven@2229
   187
        --cache-file=config.cache                                   \
yann@1478
   188
        "${extra_config[@]}"                                        \
yann@850
   189
        ${CT_LIBC_GLIBC_EXTRA_CONFIG}
yann@850
   190
    
yann@850
   191
    CT_DoLog EXTRA "Building C library"
yann@850
   192
yann@1328
   193
    # eglibc build hacks
yann@2271
   194
    case "${CT_LIBC}" in
yann@2271
   195
        eglibc)
yann@2271
   196
            case "${CT_ARCH},${CT_ARCH_CPU}" in
yann@2271
   197
                powerpc,8??)
yann@2271
   198
                    # http://sourceware.org/ml/crossgcc/2008-10/msg00068.html
yann@2271
   199
                    CT_DoLog DEBUG "Activating support for memset on broken ppc-8xx (CPU15 erratum)"
yann@2271
   200
                    extra_make_args+=( ASFLAGS="-DBROKEN_PPC_8xx_CPU15" )
yann@2271
   201
                    ;;
yann@2271
   202
            esac
yann@2271
   203
            ;;
yann@1328
   204
    esac
yann@1328
   205
yann@2271
   206
    CT_DoExecLog ALL make -j${CT_PARALLEL_JOBS} "${extra_make_args[@]}"
yann@850
   207
yann@850
   208
    CT_DoLog EXTRA "Installing C library"
yann@850
   209
yann@2271
   210
    CT_DoExecLog ALL make install "${extra_make_args[@]}" install_root="${CT_SYSROOT_DIR}"
yann@850
   211
yann@850
   212
    CT_EndStep
yann@850
   213
}
yann@850
   214
yann@2270
   215
# This function finishes the C library install
yann@2270
   216
# This is a no-op
yann@850
   217
do_libc_finish() {
yann@850
   218
    :
yann@850
   219
}
yann@850
   220
yann@850
   221
# Build up the addons list, separated with $1
yann@850
   222
do_libc_add_ons_list() {
yann@850
   223
    local sep="$1"
yann@850
   224
    local addons_list=$(echo "${CT_LIBC_ADDONS_LIST//,/${sep}}" |tr -s ,)
yann@850
   225
    case "${CT_THREADS}" in
yann@850
   226
        none)   ;;
yann@850
   227
        *)      addons_list="${addons_list}${sep}${CT_THREADS}";;
yann@850
   228
    esac
yann@850
   229
    [ "${CT_LIBC_GLIBC_USE_PORTS}" = "y" ] && addons_list="${addons_list}${sep}ports"
yann@850
   230
    addons_list="${addons_list%%${sep}}"
yann@850
   231
    echo "${addons_list##${sep}}"
yann@850
   232
}