scripts/build/libc/glibc-eglibc.sh-common
changeset 2270 287e1e00dea4
parent 2229 6884dcb80121
child 2271 42ebee266fe5
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/scripts/build/libc/glibc-eglibc.sh-common	Mon Jan 17 23:04:37 2011 +0100
     1.3 @@ -0,0 +1,215 @@
     1.4 +# This file contains the functions common to glibc and eglibc
     1.5 +
     1.6 +# Build and install headers file
     1.7 +# This is a no-op
     1.8 +do_libc_headers() {
     1.9 +    :
    1.10 +}
    1.11 +
    1.12 +# Build and install headers and start files
    1.13 +do_libc_start_files() {
    1.14 +    CT_DoStep INFO "Installing C library headers / start files"
    1.15 +
    1.16 +    mkdir -p "${CT_BUILD_DIR}/build-libc-startfiles"
    1.17 +    cd "${CT_BUILD_DIR}/build-libc-startfiles"
    1.18 +
    1.19 +    CT_DoLog EXTRA "Configuring C library"
    1.20 +
    1.21 +    if [ "${CT_EGLIBC_CUSTOM_CONFIG}" = "y" ]; then
    1.22 +        CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/eglibc.config" option-groups.config
    1.23 +    fi
    1.24 +
    1.25 +    cross_cc=$(CT_Which "${CT_TARGET}-gcc")
    1.26 +    cross_cxx=$(CT_Which "${CT_TARGET}-g++")
    1.27 +    cross_ar=$(CT_Which "${CT_TARGET}-ar")
    1.28 +    cross_ranlib=$(CT_Which "${CT_TARGET}-ranlib")
    1.29 +    
    1.30 +    CT_DoLog DEBUG "Using gcc for target: '${cross_cc}'"
    1.31 +    CT_DoLog DEBUG "Using g++ for target: '${cross_cxx}'"
    1.32 +    CT_DoLog DEBUG "Using ar for target: '${cross_ar}'"
    1.33 +    CT_DoLog DEBUG "Using ranlib for target: '${cross_ranlib}'"
    1.34 +
    1.35 +    BUILD_CC="${CT_BUILD}-gcc"                          \
    1.36 +    CC=${cross_cc}                                      \
    1.37 +    CXX=${cross_cxx}                                    \
    1.38 +    AR=${cross_ar}                                      \
    1.39 +    RANLIB=${cross_ranlib}                              \
    1.40 +    CT_DoExecLog CFG                                    \
    1.41 +    "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}/configure" \
    1.42 +        --prefix=/usr                                   \
    1.43 +        --with-headers="${CT_HEADERS_DIR}"              \
    1.44 +        --build="${CT_BUILD}"                           \
    1.45 +        --host="${CT_TARGET}"                           \
    1.46 +        --disable-profile                               \
    1.47 +        --without-gd                                    \
    1.48 +        --without-cvs                                   \
    1.49 +        --enable-add-ons
    1.50 +
    1.51 +    CT_DoLog EXTRA "Installing C library headers"
    1.52 +
    1.53 +    # use the 'install-headers' makefile target to install the
    1.54 +    # headers
    1.55 +
    1.56 +    CT_DoExecLog ALL                    \
    1.57 +    make install-headers                \
    1.58 +         install_root=${CT_SYSROOT_DIR} \
    1.59 +         install-bootstrap-headers=yes
    1.60 +
    1.61 +    CT_DoLog EXTRA "Installing C library start files"
    1.62 +
    1.63 +    # there are a few object files needed to link shared libraries,
    1.64 +    # which we build and install by hand
    1.65 +
    1.66 +    CT_DoExecLog ALL mkdir -p ${CT_SYSROOT_DIR}/usr/lib
    1.67 +    CT_DoExecLog ALL make csu/subdir_lib
    1.68 +    CT_DoExecLog ALL cp csu/crt1.o csu/crti.o csu/crtn.o \
    1.69 +        ${CT_SYSROOT_DIR}/usr/lib
    1.70 +
    1.71 +    # Finally, 'libgcc_s.so' requires a 'libc.so' to link against.  
    1.72 +    # However, since we will never actually execute its code, 
    1.73 +    # it doesn't matter what it contains.  So, treating '/dev/null' 
    1.74 +    # as a C source file, we produce a dummy 'libc.so' in one step
    1.75 +
    1.76 +    CT_DoExecLog ALL ${cross_cc} -nostdlib -nostartfiles -shared -x c /dev/null -o ${CT_SYSROOT_DIR}/usr/lib/libc.so
    1.77 +
    1.78 +    CT_EndStep
    1.79 +}
    1.80 +
    1.81 +# This function builds and install the full C library
    1.82 +do_libc() {
    1.83 +    local -a extra_config
    1.84 +
    1.85 +    CT_DoStep INFO "Installing C library"
    1.86 +
    1.87 +    mkdir -p "${CT_BUILD_DIR}/build-libc"
    1.88 +    cd "${CT_BUILD_DIR}/build-libc"
    1.89 +
    1.90 +    CT_DoLog EXTRA "Configuring C library"
    1.91 +
    1.92 +    if [ "${CT_EGLIBC_CUSTOM_CONFIG}" = "y" ]; then
    1.93 +        CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/eglibc.config" option-groups.config
    1.94 +    fi
    1.95 +
    1.96 +    if [ "${CT_EGLIBC_OPT_SIZE}" = "y" ]; then
    1.97 +        OPTIMIZE=-Os
    1.98 +    else
    1.99 +        OPTIMIZE=-O2
   1.100 +    fi
   1.101 +
   1.102 +    # Add some default glibc config options if not given by user.
   1.103 +    # We don't need to be conditional on wether the user did set different
   1.104 +    # values, as they CT_LIBC_GLIBC_EXTRA_CONFIG is passed after extra_config
   1.105 +
   1.106 +    extra_config+=("--enable-kernel=$(echo ${CT_LIBC_GLIBC_MIN_KERNEL} |sed -r -e 's/^([^.]+\.[^.]+\.[^.]+)(|\.[^.]+)$/\1/;')")
   1.107 +
   1.108 +    case "${CT_THREADS}" in
   1.109 +        nptl)           extra_config+=("--with-__thread" "--with-tls");;
   1.110 +        linuxthreads)   extra_config+=("--with-__thread" "--without-tls" "--without-nptl");;
   1.111 +        none)           extra_config+=("--without-__thread" "--without-nptl")
   1.112 +                        case "${CT_LIBC_GLIBC_EXTRA_CONFIG}" in
   1.113 +                            *-tls*) ;;
   1.114 +                            *) extra_config+=("--without-tls");;
   1.115 +                        esac
   1.116 +                        ;;
   1.117 +    esac
   1.118 +
   1.119 +    case "${CT_SHARED_LIBS}" in
   1.120 +        y) extra_config+=("--enable-shared");;
   1.121 +        *) extra_config+=("--disable-shared");;
   1.122 +    esac
   1.123 +
   1.124 +    case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
   1.125 +        y,) extra_config+=("--with-fp");;
   1.126 +        ,y) extra_config+=("--without-fp");;
   1.127 +    esac
   1.128 +
   1.129 +    if [ "${CT_LIBC_DISABLE_VERSIONING}" = "y" ]; then
   1.130 +        extra_config+=("--disable-versioning")
   1.131 +    fi
   1.132 +
   1.133 +    if [ "${CT_LIBC_OLDEST_ABI}" != "" ]; then
   1.134 +        extra_config+=("--enable-oldest-abi=${CT_LIBC_OLDEST_ABI}")
   1.135 +    fi
   1.136 +
   1.137 +    case "$(do_libc_add_ons_list ,)" in
   1.138 +        "") ;;
   1.139 +        *)  extra_config+=("--enable-add-ons=$(do_libc_add_ons_list ,)");;
   1.140 +    esac
   1.141 +
   1.142 +    extra_cc_args="${extra_cc_args} ${CT_ARCH_ENDIAN_OPT}"
   1.143 +
   1.144 +    cross_cc=$(CT_Which "${CT_TARGET}-gcc")    
   1.145 +
   1.146 +    CT_DoLog DEBUG "Using gcc for target:     '${cross_cc}'"
   1.147 +    CT_DoLog DEBUG "Configuring with addons : '$(do_libc_add_ons_list ,)'"
   1.148 +    CT_DoLog DEBUG "Extra config args passed: '${extra_config[*]}'"
   1.149 +    CT_DoLog DEBUG "Extra CC args passed    : '${extra_cc_args}'"
   1.150 +
   1.151 +    # ./configure is mislead by our tools override wrapper for bash
   1.152 +    # so just tell it where the real bash is _on_the_target_!
   1.153 +    # Notes:
   1.154 +    # - ${ac_cv_path_BASH_SHELL} is only used to set BASH_SHELL
   1.155 +    # - ${BASH_SHELL}            is only used to set BASH
   1.156 +    # - ${BASH}                  is only used to set the shebang
   1.157 +    #                            in two scripts to run on the target
   1.158 +    # So we can safely bypass bash detection at compile time.
   1.159 +    # Should this change in a future eglibc release, we'd better
   1.160 +    # directly mangle the generated scripts _after_ they get built,
   1.161 +    # or even after they get installed... eglibc is such a sucker...
   1.162 +    echo "ac_cv_path_BASH_SHELL=/bin/bash" >config.cache
   1.163 +
   1.164 +    BUILD_CC="${CT_BUILD}-gcc"                                      \
   1.165 +    CFLAGS="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} ${OPTIMIZE}"  \
   1.166 +    CC="${CT_TARGET}-gcc ${CT_LIBC_EXTRA_CC_ARGS} ${extra_cc_args}" \
   1.167 +    AR=${CT_TARGET}-ar                                              \
   1.168 +    RANLIB=${CT_TARGET}-ranlib                                      \
   1.169 +    CT_DoExecLog CFG                                                \
   1.170 +    "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}/configure"             \
   1.171 +        --prefix=/usr                                               \
   1.172 +        --with-headers="${CT_HEADERS_DIR}"                          \
   1.173 +        --build=${CT_BUILD}                                         \
   1.174 +        --host=${CT_TARGET}                                         \
   1.175 +        --disable-profile                                           \
   1.176 +        --without-gd                                                \
   1.177 +        --without-cvs                                               \
   1.178 +        --cache-file=config.cache                                   \
   1.179 +        "${extra_config[@]}"                                        \
   1.180 +        ${CT_LIBC_GLIBC_EXTRA_CONFIG}
   1.181 +    
   1.182 +    CT_DoLog EXTRA "Building C library"
   1.183 +
   1.184 +    # eglibc build hacks
   1.185 +    # http://sourceware.org/ml/crossgcc/2008-10/msg00068.html
   1.186 +    case "${CT_ARCH},${CT_ARCH_CPU}" in
   1.187 +        powerpc,8??)
   1.188 +            CT_DoLog DEBUG "Activating support for memset on broken ppc-8xx (CPU15 erratum)"
   1.189 +            EGLIBC_BUILD_ASFLAGS="-DBROKEN_PPC_8xx_CPU15";;
   1.190 +    esac
   1.191 +
   1.192 +    CT_DoExecLog ALL make ASFLAGS="${EGLIBC_BUILD_ASFLAGS}"
   1.193 +
   1.194 +    CT_DoLog EXTRA "Installing C library"
   1.195 +
   1.196 +    CT_DoExecLog ALL make install install_root="${CT_SYSROOT_DIR}"
   1.197 +
   1.198 +    CT_EndStep
   1.199 +}
   1.200 +
   1.201 +# This function finishes the C library install
   1.202 +# This is a no-op
   1.203 +do_libc_finish() {
   1.204 +    :
   1.205 +}
   1.206 +
   1.207 +# Build up the addons list, separated with $1
   1.208 +do_libc_add_ons_list() {
   1.209 +    local sep="$1"
   1.210 +    local addons_list=$(echo "${CT_LIBC_ADDONS_LIST//,/${sep}}" |tr -s ,)
   1.211 +    case "${CT_THREADS}" in
   1.212 +        none)   ;;
   1.213 +        *)      addons_list="${addons_list}${sep}${CT_THREADS}";;
   1.214 +    esac
   1.215 +    [ "${CT_LIBC_GLIBC_USE_PORTS}" = "y" ] && addons_list="${addons_list}${sep}ports"
   1.216 +    addons_list="${addons_list%%${sep}}"
   1.217 +    echo "${addons_list##${sep}}"
   1.218 +}