scripts/build/libc/eglibc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon Jan 05 23:02:43 2009 +0000 (2009-01-05)
changeset 1126 1ab3d2e08c8b
parent 1124 eec7a46a4c19
child 1292 546d2ed3410b
permissions -rw-r--r--
Split CT_ExtractAndPatch in two: CT_Extract and CT_Patch:
- it is unworkable to have CT_ExtactAndPAtch cope with all those silly glibc addons:
- they can have 'short' (as 'ports') or 'long' (as glibc-ports-2.7) names
- patches are against eithe the short or long name, but non-uniformly use one or the other
- it is the reposibility of the component (glibc in this case) to handle corner cases such as those
- update all components to use the new functions

/trunk/scripts/build/tools/000-template.sh | 3 2 1 0 +-
/trunk/scripts/build/tools/100-libelf.sh | 3 2 1 0 +-
/trunk/scripts/build/tools/200-sstrip.sh | 3 2 1 0 +-
/trunk/scripts/build/kernel/linux.sh | 3 2 1 0 +-
/trunk/scripts/build/binutils.sh | 3 2 1 0 +-
/trunk/scripts/build/cc/gcc.sh | 3 2 1 0 +-
/trunk/scripts/build/debug/000-template.sh | 3 2 1 0 +-
/trunk/scripts/build/debug/100-dmalloc.sh | 3 2 1 0 +-
/trunk/scripts/build/debug/400-ltrace.sh | 3 2 1 0 +-
/trunk/scripts/build/debug/300-gdb.sh | 9 6 3 0 +++--
/trunk/scripts/build/debug/500-strace.sh | 7 3 4 0 ++--
/trunk/scripts/build/debug/200-duma.sh | 19 8 11 0 ++++------
/trunk/scripts/build/libc/glibc.sh | 14 12 2 0 ++++++-
/trunk/scripts/build/libc/uClibc.sh | 13 9 4 0 +++++--
/trunk/scripts/build/libc/eglibc.sh | 14 12 2 0 ++++++-
/trunk/scripts/build/gmp.sh | 3 2 1 0 +-
/trunk/scripts/build/mpfr.sh | 3 2 1 0 +-
/trunk/scripts/functions | 68 36 32 0 +++++++++++++++++++-----------------
18 files changed, 108 insertions(+), 69 deletions(-)
yann@850
     1
# eglibc build functions (initially by Thomas JOURDAN).
yann@850
     2
yann@850
     3
# Download eglibc repository
yann@850
     4
do_eglibc_get() {
yann@850
     5
    CT_HasOrAbort svn
yann@850
     6
yann@850
     7
    case "${CT_LIBC_VERSION}" in
yann@850
     8
        trunk)  svn_url="svn://svn.eglibc.org/trunk";;
yann@850
     9
        *)      svn_url="svn://svn.eglibc.org/branches/eglibc-${CT_LIBC_VERSION}";;
yann@850
    10
    esac
yann@850
    11
yann@850
    12
    case "${CT_EGLIBC_CHECKOUT}" in
yann@850
    13
        y)  svn_action="checkout";;
yann@850
    14
        *)  svn_action="export --force";;
yann@850
    15
    esac
yann@850
    16
yann@850
    17
    CT_DoSetProxy ${CT_PROXY_TYPE}
yann@850
    18
    CT_DoExecLog ALL svn ${svn_action} -r "${CT_EGLIBC_REVISION:-HEAD}" "${svn_url}" . 2>&1
yann@850
    19
yann@850
    20
    # Compress eglibc
yann@1123
    21
    CT_DoExecLog ALL mv libc "eglibc-${CT_LIBC_VERSION}"
yann@1123
    22
    CT_DoExecLog ALL tar cjf "eglibc-${CT_LIBC_VERSION}.tar.bz2" "eglibc-${CT_LIBC_VERSION}"
yann@850
    23
yann@850
    24
    # Compress linuxthreads, localedef and ports
yann@850
    25
    # Assign them the name the way ct-ng like it
yann@850
    26
    for addon in linuxthreads localedef ports; do
yann@1123
    27
        CT_DoExecLog ALL mv "${addon}" "eglibc-${addon}-${CT_LIBC_VERSION}"
yann@1123
    28
        CT_DoExecLog ALL tar cjf "eglibc-${addon}-${CT_LIBC_VERSION}.tar.bz2" "eglibc-${addon}-${CT_LIBC_VERSION}"
yann@850
    29
    done
yann@850
    30
}
yann@850
    31
yann@850
    32
# Download glibc
yann@850
    33
do_libc_get() {
yann@850
    34
    # eglibc is only available through subversion, there are no
yann@850
    35
    # snapshots available. Moreover, addons will be downloaded
yann@850
    36
    # simultaneously.
yann@850
    37
yann@850
    38
    # build filename
yann@1123
    39
    eglibc="eglibc-${CT_LIBC_VERSION}.tar.bz2"
yann@850
    40
    eglibc_linuxthreads="${CT_LIBC}-linuxthreads-${CT_LIBC_VERSION}.tar.bz2"
yann@850
    41
    eglibc_localedef="${CT_LIBC}-localedef-${CT_LIBC_VERSION}.tar.bz2"
yann@850
    42
    eglibc_ports="${CT_LIBC}-ports-${CT_LIBC_VERSION}.tar.bz2"
yann@850
    43
yann@850
    44
    # Check if every tarballs are already present
yann@850
    45
    if [ -a "${CT_TARBALLS_DIR}/${eglibc}" ]              && \
yann@850
    46
       [ -a "${CT_TARBALLS_DIR}/${eglibc_linuxthreads}" ] && \
yann@850
    47
       [ -a "${CT_TARBALLS_DIR}/${eglibc_localedef}" ]    && \
yann@850
    48
       [ -a "${CT_TARBALLS_DIR}/${eglibc_ports}" ]; then
yann@850
    49
        CT_DoLog DEBUG "Already have 'eglibc-${CT_LIBC_VERSION}'"
yann@850
    50
        return 0
yann@850
    51
    fi
yann@850
    52
yann@850
    53
    if [ -a "${CT_LOCAL_TARBALLS_DIR}/${eglibc}" ]              && \
yann@850
    54
       [ -a "${CT_LOCAL_TARBALLS_DIR}/${eglibc_linuxthreads}" ] && \
yann@850
    55
       [ -a "${CT_LOCAL_TARBALLS_DIR}/${eglibc_localedef}" ]    && \
yann@850
    56
       [ -a "${CT_LOCAL_TARBALLS_DIR}/${eglibc_ports}" ]        && \
yann@850
    57
       [ "${CT_FORCE_DOWNLOAD}" != "y" ]; then
yann@850
    58
        CT_DoLog DEBUG "Got 'eglibc-${CT_LIBC_VERSION}' from local storage"
yann@850
    59
        for file in ${eglibc} ${eglibc_linuxthreads} ${eglibc_localedef} ${eglibc_ports}; do
yann@850
    60
            CT_DoExecLog ALL ln -s "${CT_LOCAL_TARBALLS_DIR}/${file}" "${CT_TARBALLS_DIR}/${file}"
yann@850
    61
        done
yann@850
    62
        return 0
yann@850
    63
    fi
yann@850
    64
yann@850
    65
    # Not found locally, try from the network
yann@850
    66
    CT_DoLog EXTRA "Retrieving 'eglibc-${CT_LIBC_VERSION}'"
yann@867
    67
yann@867
    68
    CT_MktempDir tmp_dir
yann@867
    69
    CT_Pushd "${tmp_dir}"
yann@867
    70
yann@850
    71
    do_eglibc_get
yann@867
    72
    CT_DoLog DEBUG "Moving 'eglibc-${CT_LIBC_VERSION}' to tarball directory"
yann@867
    73
    for file in ${eglibc} ${eglibc_linuxthreads} ${eglibc_localedef} ${eglibc_ports}; do
yann@867
    74
        CT_DoExecLog ALL mv -f "${file}" "${CT_TARBALLS_DIR}"
yann@867
    75
    done
yann@867
    76
yann@867
    77
    CT_Popd
yann@867
    78
yann@867
    79
    # Remove source files
yann@867
    80
    CT_DoExecLog ALL rm -rf "${tmp_dir}"
yann@850
    81
yann@850
    82
    if [ "${CT_SAVE_TARBALLS}" = "y" ]; then
yann@850
    83
        CT_DoLog EXTRA "Saving 'eglibc-${CT_LIBC_VERSION}' to local storage"
yann@850
    84
        for file in ${eglibc} ${eglibc_linuxthreads} ${eglibc_localedef} ${eglibc_ports}; do
yann@850
    85
            CT_DoExecLog ALL mv -f "${CT_TARBALLS_DIR}/${file}" "${CT_LOCAL_TARBALLS_DIR}"
yann@850
    86
            CT_DoExecLog ALL ln -s "${CT_LOCAL_TARBALLS_DIR}/${file}" "${CT_TARBALLS_DIR}/${file}"
yann@850
    87
        done
yann@850
    88
    fi
yann@850
    89
yann@850
    90
    return 0
yann@850
    91
}
yann@850
    92
yann@850
    93
# Extract eglibc
yann@850
    94
do_libc_extract() {
yann@1126
    95
    CT_Extract "eglibc-${CT_LIBC_VERSION}"
yann@1126
    96
    CT_Patch "eglibc-${CT_LIBC_VERSION}"
yann@850
    97
yann@850
    98
    # C library addons
yann@850
    99
    for addon in $(do_libc_add_ons_list " "); do
yann@850
   100
        # NPTL addon is not to be extracted, in any case
yann@850
   101
        [ "${addon}" = "nptl" ] && continue || true
yann@1123
   102
        CT_Pushd "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}"
yann@1126
   103
        CT_Extract "eglibc-${addon}-${CT_LIBC_VERSION}" nochdir
yann@1126
   104
        # Some addons have the 'long' name, while others have the
yann@1126
   105
        # 'short' name, but patches are non-uniformly built with
yann@1126
   106
        # either the 'long' or 'short' name, whatever the addons name
yann@1126
   107
        # so we have to make symlinks from the existing to the missing
yann@1126
   108
        # Fortunately for us, [ -d foo ], when foo is a symlink to a
yann@1126
   109
        # directory, returns true!
yann@1126
   110
        [ -d "${addon}" ] || ln -s "eglibc-${addon}-${CT_LIBC_VERSION}" "${addon}"
yann@1126
   111
        [ -d "eglibc-${addon}-${CT_LIBC_VERSION}" ] || ln -s "${addon}" "eglibc-${addon}-${CT_LIBC_VERSION}"
yann@1126
   112
        CT_Patch "eglibc-${addon}-${CT_LIBC_VERSION}" nochdir
yann@1123
   113
        CT_Popd
yann@850
   114
    done
yann@850
   115
yann@884
   116
    # The configure files may be older than the configure.in files
yann@884
   117
    # if using a snapshot (or even some tarballs). Fake them being
yann@884
   118
    # up to date.
yann@1123
   119
    find "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}" -type f -name configure -exec touch {} \; 2>&1 |CT_DoLog ALL
yann@884
   120
yann@850
   121
    return 0
yann@850
   122
}
yann@850
   123
yann@850
   124
# There is nothing to do for eglibc check config
yann@850
   125
do_libc_check_config() {
yann@850
   126
    :
yann@850
   127
}
yann@850
   128
yann@884
   129
# This function installs the eglibc headers needed to build the core compiler
yann@850
   130
do_libc_headers() {
yann@850
   131
    # Instead of doing two time the same actions, headers will
yann@850
   132
    # be installed with start files
yann@850
   133
    :
yann@850
   134
}
yann@850
   135
yann@850
   136
# Build and install start files
yann@850
   137
do_libc_start_files() {
yann@850
   138
    CT_DoStep INFO "Installing C library headers / start files"
yann@850
   139
yann@850
   140
    mkdir -p "${CT_BUILD_DIR}/build-libc-startfiles"
yann@850
   141
    cd "${CT_BUILD_DIR}/build-libc-startfiles"
yann@850
   142
yann@850
   143
    CT_DoLog EXTRA "Configuring C library"
yann@850
   144
yann@850
   145
    cross_cc=$(CT_Which "${CT_TARGET}-gcc")
yann@850
   146
    cross_cxx=$(CT_Which "${CT_TARGET}-g++")
yann@850
   147
    cross_ar=$(CT_Which "${CT_TARGET}-ar")
yann@850
   148
    cross_ranlib=$(CT_Which "${CT_TARGET}-ranlib")
yann@850
   149
    
yann@850
   150
    CT_DoLog DEBUG "Using gcc for target: '${cross_cc}'"
yann@850
   151
    CT_DoLog DEBUG "Using g++ for target: '${cross_cxx}'"
yann@850
   152
    CT_DoLog DEBUG "Using ar for target: '${cross_ar}'"
yann@850
   153
    CT_DoLog DEBUG "Using ranlib for target: '${cross_ranlib}'"
yann@850
   154
yann@1123
   155
    BUILD_CC="${CT_BUILD}-gcc"                          \
yann@1123
   156
    CC=${cross_cc}                                      \
yann@1123
   157
    CXX=${cross_cxx}                                    \
yann@1123
   158
    AR=${cross_ar}                                      \
yann@1123
   159
    RANLIB=${cross_ranlib}                              \
yann@1123
   160
    CT_DoExecLog ALL                                    \
yann@1123
   161
    "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}/configure" \
yann@1123
   162
        --prefix=/usr                                   \
yann@1123
   163
        --with-headers="${CT_HEADERS_DIR}"              \
yann@1123
   164
        --build="${CT_BUILD}"                           \
yann@1123
   165
        --host="${CT_TARGET}"                           \
yann@1123
   166
        --disable-profile                               \
yann@1123
   167
        --without-gd                                    \
yann@1123
   168
        --without-cvs                                   \
yann@850
   169
        --enable-add-ons
yann@850
   170
yann@850
   171
    CT_DoLog EXTRA "Installing C library headers"
yann@850
   172
yann@850
   173
    # use the 'install-headers' makefile target to install the
yann@850
   174
    # headers
yann@850
   175
yann@850
   176
    CT_DoExecLog ALL                    \
yann@850
   177
    make install-headers                \
yann@850
   178
         install_root=${CT_SYSROOT_DIR} \
yann@850
   179
         install-bootstrap-headers=yes
yann@850
   180
yann@850
   181
    CT_DoLog EXTRA "Installing C library start files"
yann@850
   182
yann@850
   183
    # there are a few object files needed to link shared libraries,
yann@850
   184
    # which we build and install by hand
yann@850
   185
yann@850
   186
    CT_DoExecLog ALL mkdir -p ${CT_SYSROOT_DIR}/usr/lib
yann@850
   187
    CT_DoExecLog ALL make csu/subdir_lib
yann@850
   188
    CT_DoExecLog ALL cp csu/crt1.o csu/crti.o csu/crtn.o \
yann@850
   189
        ${CT_SYSROOT_DIR}/usr/lib
yann@850
   190
yann@850
   191
    # Finally, 'libgcc_s.so' requires a 'libc.so' to link against.  
yann@850
   192
    # However, since we will never actually execute its code, 
yann@850
   193
    # it doesn't matter what it contains.  So, treating '/dev/null' 
yann@850
   194
    # as a C source file, we produce a dummy 'libc.so' in one step
yann@850
   195
yann@850
   196
    CT_DoExecLog ALL ${cross_cc} -nostdlib -nostartfiles -shared -x c /dev/null -o ${CT_SYSROOT_DIR}/usr/lib/libc.so
yann@850
   197
yann@850
   198
    CT_EndStep
yann@850
   199
}
yann@850
   200
yann@850
   201
# This function builds and install the full glibc
yann@850
   202
do_libc() {
yann@850
   203
    CT_DoStep INFO "Installing C library"
yann@850
   204
yann@850
   205
    mkdir -p "${CT_BUILD_DIR}/build-libc"
yann@850
   206
    cd "${CT_BUILD_DIR}/build-libc"
yann@850
   207
yann@850
   208
    CT_DoLog EXTRA "Configuring C library"
yann@850
   209
yann@850
   210
    # Add some default glibc config options if not given by user.
yann@850
   211
    # We don't need to be conditional on wether the user did set different
yann@850
   212
    # values, as they CT_LIBC_GLIBC_EXTRA_CONFIG is passed after extra_config
yann@850
   213
yann@850
   214
    extra_config="--enable-kernel=$(echo ${CT_LIBC_GLIBC_MIN_KERNEL} |sed -r -e 's/^([^.]+\.[^.]+\.[^.]+)(|\.[^.]+)$/\1/;')"
yann@850
   215
yann@850
   216
    case "${CT_THREADS}" in
yann@850
   217
        nptl)           extra_config="${extra_config} --with-__thread --with-tls";;
yann@850
   218
        linuxthreads)   extra_config="${extra_config} --with-__thread --without-tls --without-nptl";;
yann@850
   219
        none)           extra_config="${extra_config} --without-__thread --without-nptl"
yann@850
   220
                        case "${CT_LIBC_GLIBC_EXTRA_CONFIG}" in
yann@850
   221
                            *-tls*) ;;
yann@850
   222
                            *) extra_config="${extra_config} --without-tls";;
yann@850
   223
                        esac
yann@850
   224
                        ;;
yann@850
   225
    esac
yann@850
   226
yann@850
   227
    case "${CT_SHARED_LIBS}" in
yann@850
   228
        y) extra_config="${extra_config} --enable-shared";;
yann@850
   229
        *) extra_config="${extra_config} --disable-shared";;
yann@850
   230
    esac
yann@850
   231
yann@850
   232
    case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
yann@850
   233
        y,) extra_config="${extra_config} --with-fp";;
yann@850
   234
        ,y) extra_config="${extra_config} --without-fp";;
yann@850
   235
    esac
yann@850
   236
yann@850
   237
    case "$(do_libc_add_ons_list ,)" in
yann@850
   238
        "") ;;
yann@850
   239
        *)  extra_config="${extra_config} --enable-add-ons=$(do_libc_add_ons_list ,)";;
yann@850
   240
    esac
yann@850
   241
yann@850
   242
    extra_cc_args="${extra_cc_args} ${CT_ARCH_ENDIAN_OPT}"
yann@850
   243
yann@850
   244
    cross_cc=$(CT_Which "${CT_TARGET}-gcc")    
yann@850
   245
yann@850
   246
    CT_DoLog DEBUG "Using gcc for target:     '${cross_cc}'"
yann@850
   247
    CT_DoLog DEBUG "Configuring with addons : '$(do_libc_add_ons_list ,)'"
yann@850
   248
    CT_DoLog DEBUG "Extra config args passed: '${extra_config}'"
yann@850
   249
    CT_DoLog DEBUG "Extra CC args passed    : '${extra_cc_args}'"
yann@850
   250
yann@1041
   251
    BUILD_CC="${CT_BUILD}-gcc"                                      \
yann@850
   252
    CFLAGS="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} -O"   \
yann@850
   253
    CC="${CT_TARGET}-gcc ${CT_LIBC_EXTRA_CC_ARGS} ${extra_cc_args}" \
yann@850
   254
    AR=${CT_TARGET}-ar                                              \
yann@850
   255
    RANLIB=${CT_TARGET}-ranlib                                      \
yann@850
   256
    CT_DoExecLog ALL                                                \
yann@1123
   257
    "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}/configure"             \
yann@850
   258
        --prefix=/usr                                               \
yann@850
   259
        --with-headers="${CT_HEADERS_DIR}"                          \
yann@1041
   260
        --build=${CT_BUILD}                                         \
yann@850
   261
        --host=${CT_TARGET}                                         \
yann@850
   262
        --disable-profile                                           \
yann@850
   263
        --without-gd                                                \
yann@850
   264
        --without-cvs                                               \
yann@850
   265
        ${extra_config}                                             \
yann@850
   266
        ${CT_LIBC_GLIBC_EXTRA_CONFIG}
yann@850
   267
    
yann@850
   268
    CT_DoLog EXTRA "Building C library"
yann@850
   269
yann@850
   270
    CT_DoExecLog ALL make
yann@850
   271
yann@850
   272
    CT_DoLog EXTRA "Installing C library"
yann@850
   273
yann@850
   274
    CT_DoExecLog ALL make install install_root="${CT_SYSROOT_DIR}"
yann@850
   275
yann@850
   276
    CT_EndStep
yann@850
   277
}
yann@850
   278
yann@850
   279
# This function finishes the glibc install
yann@850
   280
do_libc_finish() {
yann@850
   281
    # Nothing to be done for eglibc
yann@850
   282
    :
yann@850
   283
}
yann@850
   284
yann@850
   285
# Build up the addons list, separated with $1
yann@850
   286
do_libc_add_ons_list() {
yann@850
   287
    local sep="$1"
yann@850
   288
    local addons_list=$(echo "${CT_LIBC_ADDONS_LIST//,/${sep}}" |tr -s ,)
yann@850
   289
    case "${CT_THREADS}" in
yann@850
   290
        none)   ;;
yann@850
   291
        *)      addons_list="${addons_list}${sep}${CT_THREADS}";;
yann@850
   292
    esac
yann@850
   293
    [ "${CT_LIBC_GLIBC_USE_PORTS}" = "y" ] && addons_list="${addons_list}${sep}ports"
yann@850
   294
    addons_list="${addons_list%%${sep}}"
yann@850
   295
    echo "${addons_list##${sep}}"
yann@850
   296
}