scripts/build/libc/glibc-eglibc.sh-common
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon Jan 17 23:04:37 2011 +0100 (2011-01-17)
changeset 2270 287e1e00dea4
parent 2229 scripts/build/libc/eglibc.sh@6884dcb80121
child 2271 42ebee266fe5
permissions -rw-r--r--
libc/eglibc: move generic code to a common file

The build procedure for eglibc is generic enough to
be shared between glibc and eglibc. This includes:
- headers install (empty!)
- start files build
- complete libc build
- libc finish (empty!)
- add-ons list

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