libc/glibc: add glibc specifics to the shared code, and use it
author"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sat Jan 22 22:35:58 2011 +0100 (2011-01-22)
changeset 2276ac021d186cd6
parent 2275 9ab4392430ad
child 2277 71803c9f6de0
libc/glibc: add glibc specifics to the shared code, and use it

Final step at sharing code between glibc and eglibc.
Fall, wall of shame, fall!... :-)

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
scripts/build/libc/glibc-eglibc.sh-common
scripts/build/libc/glibc.sh
     1.1 --- a/scripts/build/libc/glibc-eglibc.sh-common	Sat Jan 22 22:35:43 2011 +0100
     1.2 +++ b/scripts/build/libc/glibc-eglibc.sh-common	Sat Jan 22 22:35:58 2011 +0100
     1.3 @@ -107,6 +107,7 @@
     1.4  # This function builds and install the full C library
     1.5  do_libc() {
     1.6      local src_dir="${CT_SRC_DIR}/${CT_LIBC}-${CT_LIBC_VERSION}"
     1.7 +    local extra_cc_args
     1.8      local -a extra_config
     1.9      local -a extra_make_args
    1.10  
    1.11 @@ -128,6 +129,12 @@
    1.12                  OPTIMIZE=-O2
    1.13              fi
    1.14              ;;
    1.15 +        glibc)
    1.16 +            # glibc can't be built without -O2 (reference needed!)
    1.17 +            OPTIMIZE=-O2
    1.18 +            # Also, if those two are missing, iconv build breaks
    1.19 +            extra_config+=( --disable-debug --disable-sanity-checks )
    1.20 +            ;;
    1.21      esac
    1.22  
    1.23      # Add some default glibc config options if not given by user.
    1.24 @@ -172,6 +179,9 @@
    1.25  
    1.26      extra_cc_args="${extra_cc_args} ${CT_ARCH_ENDIAN_OPT}"
    1.27  
    1.28 +    # Pre-seed the configparms file with values from the config option
    1.29 +    printf "${CT_LIBC_GLIBC_CONFIGPARMS}\n" > configparms
    1.30 +
    1.31      cross_cc=$(CT_Which "${CT_TARGET}-gcc")    
    1.32  
    1.33      CT_DoLog DEBUG "Using gcc for target:     '${cross_cc}'"
    1.34 @@ -192,6 +202,14 @@
    1.35      # or even after they get installed... eglibc is such a sucker...
    1.36      echo "ac_cv_path_BASH_SHELL=/bin/bash" >config.cache
    1.37  
    1.38 +    # Configure with --prefix the way we want it on the target...
    1.39 +    # There are a whole lot of settings here.  You'll probably want
    1.40 +    # to read up on what they all mean, and customize a bit, possibly by setting GLIBC_EXTRA_CONFIG
    1.41 +    # Compare these options with the ones used when installing the glibc headers above - they're different.
    1.42 +    # Adding "--without-gd" option to avoid error "memusagestat.c:36:16: gd.h: No such file or directory"
    1.43 +    # See also http://sources.redhat.com/ml/libc-alpha/2000-07/msg00024.html.
    1.44 +    # Set BUILD_CC, or we won't be able to build datafiles
    1.45 +
    1.46      BUILD_CC="${CT_BUILD}-gcc"                                      \
    1.47      CFLAGS="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} ${OPTIMIZE}"  \
    1.48      CC="${CT_TARGET}-gcc ${CT_LIBC_EXTRA_CC_ARGS} ${extra_cc_args}" \
    1.49 @@ -200,36 +218,35 @@
    1.50      CT_DoExecLog CFG                                                \
    1.51      "${src_dir}/configure"                                          \
    1.52          --prefix=/usr                                               \
    1.53 -        --with-headers="${CT_HEADERS_DIR}"                          \
    1.54          --build=${CT_BUILD}                                         \
    1.55          --host=${CT_TARGET}                                         \
    1.56 +        --without-cvs                                               \
    1.57          --disable-profile                                           \
    1.58          --without-gd                                                \
    1.59 -        --without-cvs                                               \
    1.60          --cache-file=config.cache                                   \
    1.61 +        --with-headers="${CT_HEADERS_DIR}"                          \
    1.62          "${extra_config[@]}"                                        \
    1.63          ${CT_LIBC_GLIBC_EXTRA_CONFIG}
    1.64      
    1.65 -    CT_DoLog EXTRA "Building C library"
    1.66 -
    1.67 -    # eglibc build hacks
    1.68 -    case "${CT_LIBC}" in
    1.69 -        eglibc)
    1.70 -            case "${CT_ARCH},${CT_ARCH_CPU}" in
    1.71 -                powerpc,8??)
    1.72 -                    # http://sourceware.org/ml/crossgcc/2008-10/msg00068.html
    1.73 -                    CT_DoLog DEBUG "Activating support for memset on broken ppc-8xx (CPU15 erratum)"
    1.74 -                    extra_make_args+=( ASFLAGS="-DBROKEN_PPC_8xx_CPU15" )
    1.75 -                    ;;
    1.76 -            esac
    1.77 +    # build hacks
    1.78 +    case "${CT_ARCH},${CT_ARCH_CPU}" in
    1.79 +        powerpc,8??)
    1.80 +            # http://sourceware.org/ml/crossgcc/2008-10/msg00068.html
    1.81 +            CT_DoLog DEBUG "Activating support for memset on broken ppc-8xx (CPU15 erratum)"
    1.82 +            extra_make_args+=( ASFLAGS="-DBROKEN_PPC_8xx_CPU15" )
    1.83              ;;
    1.84      esac
    1.85  
    1.86 -    CT_DoExecLog ALL make -j${CT_PARALLEL_JOBS} "${extra_make_args[@]}"
    1.87 +    CT_DoLog EXTRA "Building C library"
    1.88 +    CT_DoExecLog ALL make -j${CT_PARALLEL_JOBS}             \
    1.89 +                          "${extra_make_args[@]}"           \
    1.90 +                          all
    1.91  
    1.92      CT_DoLog EXTRA "Installing C library"
    1.93 -
    1.94 -    CT_DoExecLog ALL make install "${extra_make_args[@]}" install_root="${CT_SYSROOT_DIR}"
    1.95 +    CT_DoExecLog ALL make -j${CT_PARALLEL_JOBS}             \
    1.96 +                          "${extra_make_args[@]}"           \
    1.97 +                          install_root="${CT_SYSROOT_DIR}"  \
    1.98 +                          install
    1.99  
   1.100      CT_EndStep
   1.101  }
   1.102 @@ -280,8 +297,8 @@
   1.103                  min_kernel_config="${version}.${patchlevel}.${sublevel}"
   1.104              elif [ "${CT_LIBC_GLIBC_KERNEL_VERSION_CHOSEN}" = "y" ]; then
   1.105                  # Trim the fourth part of the linux version, keeping only the first three numbers
   1.106 -                min_kernel_config="$( echo "${CT_LIBC_GLIBC_MIN_KERNEL_VERSION}"                \
   1.107 -                                      |sed -r -e 's/^([^.]+\.[^.]+\.[^.]+)(|\.[^.]+)$/\1/;')"   \
   1.108 +                min_kernel_config="$( echo "${CT_LIBC_GLIBC_MIN_KERNEL_VERSION}"            \
   1.109 +                                      |sed -r -e 's/^([^.]+\.[^.]+\.[^.]+)(|\.[^.]+)$/\1/;' \
   1.110                                      )"
   1.111              fi
   1.112              echo "--enable-kernel=${min_kernel_config}"
     2.1 --- a/scripts/build/libc/glibc.sh	Sat Jan 22 22:35:43 2011 +0100
     2.2 +++ b/scripts/build/libc/glibc.sh	Sat Jan 22 22:35:58 2011 +0100
     2.3 @@ -77,187 +77,3 @@
     2.4  do_libc_check_config() {
     2.5      :
     2.6  }
     2.7 -
     2.8 -# This function builds and install the full glibc
     2.9 -do_libc() {
    2.10 -    local -a extra_config
    2.11 -
    2.12 -    CT_DoStep INFO "Installing C library"
    2.13 -
    2.14 -    mkdir -p "${CT_BUILD_DIR}/build-libc"
    2.15 -    cd "${CT_BUILD_DIR}/build-libc"
    2.16 -
    2.17 -    CT_DoLog EXTRA "Configuring C library"
    2.18 -
    2.19 -    # Add some default glibc config options if not given by user.
    2.20 -    # We don't need to be conditional on wether the user did set different
    2.21 -    # values, as they CT_LIBC_GLIBC_EXTRA_CONFIG is passed after extra_config
    2.22 -
    2.23 -    case "${CT_THREADS}" in
    2.24 -        nptl)           extra_config+=("--with-__thread" "--with-tls");;
    2.25 -        linuxthreads)   extra_config+=("--with-__thread" "--without-tls" "--without-nptl");;
    2.26 -        none)           extra_config+=("--without-__thread" "--without-nptl")
    2.27 -                        case "${CT_LIBC_GLIBC_EXTRA_CONFIG}" in
    2.28 -                            *-tls*) ;;
    2.29 -                            *) extra_config+=("--without-tls");;
    2.30 -                        esac
    2.31 -                        ;;
    2.32 -    esac
    2.33 -
    2.34 -    case "${CT_SHARED_LIBS}" in
    2.35 -        y) extra_config+=("--enable-shared");;
    2.36 -        *) extra_config+=("--disable-shared");;
    2.37 -    esac
    2.38 -
    2.39 -    case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
    2.40 -        y,) extra_config+=("--with-fp");;
    2.41 -        ,y) extra_config+=("--without-fp");;
    2.42 -    esac
    2.43 -
    2.44 -    if [ "${CT_LIBC_DISABLE_VERSIONING}" = "y" ]; then
    2.45 -        extra_config+=("--disable-versioning")
    2.46 -    fi
    2.47 -
    2.48 -    if [ "${CT_LIBC_OLDEST_ABI}" != "" ]; then
    2.49 -        extra_config+=("--enable-oldest-abi=${CT_LIBC_OLDEST_ABI}")
    2.50 -    fi
    2.51 -
    2.52 -    case "$(do_libc_add_ons_list ,)" in
    2.53 -        "") ;;
    2.54 -        *)  extra_config+=("--enable-add-ons=$(do_libc_add_ons_list ,)");;
    2.55 -    esac
    2.56 -
    2.57 -    extra_config+=("$(do_libc_min_kernel_config)")
    2.58 -
    2.59 -    # Add some default CC args
    2.60 -    glibc_version="$( grep -E '\<VERSION\>' "${CT_SRC_DIR}/glibc-${CT_LIBC_VERSION}/version.h"  \
    2.61 -                      |cut -d '"' -f 2
    2.62 -                    )"
    2.63 -    glibc_version_major=$(echo ${glibc_version} |sed -r -e 's/^([[:digit:]]+).*/\1/')
    2.64 -    glibc_version_minor=$(echo ${glibc_version} |sed -r -e 's/^[[:digit:]]+[\.-_]([[:digit:]]+).*/\1/')
    2.65 -    if [    ${glibc_version_major} -eq 2 -a ${glibc_version_minor} -ge 6    \
    2.66 -         -o ${glibc_version_major} -gt 2                                    ]; then
    2.67 -        # Don't use -pipe: configure chokes on it for glibc >= 2.6.
    2.68 -        CT_Test 'Removing "-pipe" for use with glibc>=2.6' "${CT_USE_PIPES}" = "y"
    2.69 -        extra_cc_args="${CT_CFLAGS_FOR_HOST/-pipe}"
    2.70 -    else
    2.71 -        extra_cc_args="${CT_CFLAGS_FOR_HOST}"
    2.72 -    fi
    2.73 -    extra_cc_args="${extra_cc_args} ${CT_ARCH_ENDIAN_OPT}"
    2.74 -
    2.75 -    cross_cc=$(CT_Which "${CT_TARGET}-gcc")
    2.76 -    CT_DoLog DEBUG "Using gcc for target    : '${cross_cc}'"
    2.77 -    CT_DoLog DEBUG "Configuring with addons : '$(do_libc_add_ons_list ,)'"
    2.78 -    CT_DoLog DEBUG "Extra config args passed: '${extra_config}'"
    2.79 -    CT_DoLog DEBUG "Extra CC args passed    : '${extra_cc_args}'"
    2.80 -
    2.81 -    # Pre-seed the configparms file with values from the config option
    2.82 -    printf "${CT_LIBC_GLIBC_CONFIGPARMS}\n" > configparms
    2.83 -
    2.84 -    # For glibc 2.3.4 and later we need to set some autoconf cache
    2.85 -    # variables, because nptl/sysdeps/pthread/configure.in does not
    2.86 -    # work when cross-compiling.
    2.87 -    if [ "${CT_THREADS}" = "nptl" ]; then
    2.88 -        echo libc_cv_forced_unwind=yes
    2.89 -        echo libc_cv_c_cleanup=yes
    2.90 -    fi >config.cache
    2.91 -
    2.92 -    # ./configure is mislead by our tools override wrapper for bash
    2.93 -    # so just tell it where the real bash is _on_the_target_!
    2.94 -    # Notes:
    2.95 -    # - ${ac_cv_path_BASH_SHELL} is only used to set BASH_SHELL
    2.96 -    # - ${BASH_SHELL}            is only used to set BASH
    2.97 -    # - ${BASH}                  is only used to set the shebang
    2.98 -    #                            in two scripts to run on the target
    2.99 -    # So we can safely bypass bash detection at compile time.
   2.100 -    # Should this change in a future glibc release, we'd better
   2.101 -    # directly mangle the generated scripts _after_ they get built,
   2.102 -    # or even after they get installed... glibc is such a sucker...
   2.103 -    echo "ac_cv_path_BASH_SHELL=/bin/bash" >>config.cache
   2.104 -
   2.105 -    # Configure with --prefix the way we want it on the target...
   2.106 -    # There are a whole lot of settings here.  You'll probably want
   2.107 -    # to read up on what they all mean, and customize a bit, possibly by setting GLIBC_EXTRA_CONFIG
   2.108 -    # Compare these options with the ones used when installing the glibc headers above - they're different.
   2.109 -    # Adding "--without-gd" option to avoid error "memusagestat.c:36:16: gd.h: No such file or directory" 
   2.110 -    # See also http://sources.redhat.com/ml/libc-alpha/2000-07/msg00024.html. 
   2.111 -    # Set BUILD_CC, or you won't be able to build datafiles
   2.112 -    # Set --build, else glibc-2.3.2 will think you're not cross-compiling, and try to run the test programs
   2.113 -
   2.114 -    # OK. I'm fed up with those folks telling me what I should do.
   2.115 -    # I don't configure nptl? Well, maybe that's purposedly because
   2.116 -    # I don't want nptl! --disable-sanity-checks will shut up those
   2.117 -    # silly messages. GNU folks again, he?
   2.118 -
   2.119 -    BUILD_CC="${CT_BUILD}-gcc"                                      \
   2.120 -    CFLAGS="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} -O2"  \
   2.121 -    CC="${CT_TARGET}-gcc ${CT_LIBC_EXTRA_CC_ARGS} ${extra_cc_args}" \
   2.122 -    AR=${CT_TARGET}-ar                                              \
   2.123 -    RANLIB=${CT_TARGET}-ranlib                                      \
   2.124 -    CT_DoExecLog CFG                                                \
   2.125 -    "${CT_SRC_DIR}/glibc-${CT_LIBC_VERSION}/configure"              \
   2.126 -        --prefix=/usr                                               \
   2.127 -        --build=${CT_BUILD}                                         \
   2.128 -        --host=${CT_TARGET}                                         \
   2.129 -        --without-cvs                                               \
   2.130 -        --disable-profile                                           \
   2.131 -        --disable-debug                                             \
   2.132 -        --without-gd                                                \
   2.133 -        --disable-sanity-checks                                     \
   2.134 -        --cache-file=config.cache                                   \
   2.135 -        --with-headers="${CT_HEADERS_DIR}"                          \
   2.136 -        "${extra_config[@]}"                                        \
   2.137 -        ${CT_LIBC_GLIBC_EXTRA_CONFIG}
   2.138 -
   2.139 -    # glibc initial build hacks
   2.140 -    # http://sourceware.org/ml/crossgcc/2008-10/msg00068.html
   2.141 -    case "${CT_ARCH},${CT_ARCH_CPU}" in
   2.142 -	powerpc,8??)
   2.143 -	    CT_DoLog DEBUG "Activating support for memset on broken ppc-8xx (CPU15 erratum)"
   2.144 -	    GLIBC_INITIAL_BUILD_ASFLAGS="-DBROKEN_PPC_8xx_CPU15";;
   2.145 -    esac
   2.146 -
   2.147 -    # If this fails with an error like this:
   2.148 -    # ...  linux/autoconf.h: No such file or directory 
   2.149 -    # then you need to set the KERNELCONFIG variable to point to a .config file for this arch.
   2.150 -    # The following architectures are known to need kernel .config: alpha, arm, ia64, s390, sh, sparc
   2.151 -    # Note: LD and RANLIB needed by glibc-2.1.3's c_stub directory, at least on macosx
   2.152 -    CT_DoLog EXTRA "Building C library"
   2.153 -    CT_DoExecLog ALL make LD=${CT_TARGET}-ld                        \
   2.154 -                          RANLIB=${CT_TARGET}-ranlib                \
   2.155 -                          OBJDUMP_FOR_HOST="${CT_TARGET}-objdump"   \
   2.156 -                          ASFLAGS="${GLIBC_INITIAL_BUILD_ASFLAGS}"  \
   2.157 -                          all
   2.158 -
   2.159 -    CT_DoLog EXTRA "Installing C library"
   2.160 -    CT_DoExecLog ALL make install_root="${CT_SYSROOT_DIR}"          \
   2.161 -                          ${LIBC_SYSROOT_ARG}                       \
   2.162 -                          OBJDUMP_FOR_HOST="${CT_TARGET}-objdump"   \
   2.163 -                          install
   2.164 -
   2.165 -    # This doesn't seem to work when building a crosscompiler,
   2.166 -    # as it tries to execute localedef using the just-built ld.so!?
   2.167 -    #CT_DoLog EXTRA "Installing locales"
   2.168 -    #make localedata/install-locales install_root=${SYSROOT} 2>&1 |CT_DoLog ALL
   2.169 -
   2.170 -    # Fix problems in linker scripts.
   2.171 -    #
   2.172 -    # Remove lines containing BUG per http://sources.redhat.com/ml/bug-glibc/2003-05/msg00055.html,
   2.173 -    # needed to fix gcc-3.2.3/glibc-2.3.2 targeting arm
   2.174 -    # No need to look into the lib64/ dirs here and there, they point to the
   2.175 -    # corresponding lib/ directories.
   2.176 -    #
   2.177 -    # To make "strip *.so.*" not fail (ptxdist does this), rename to .so_orig rather than .so.orig
   2.178 -    CT_DoLog EXTRA "Fixing C library linker scripts"
   2.179 -    for file in libc.so libpthread.so libgcc_s.so; do
   2.180 -        for dir in lib usr/lib; do
   2.181 -            if [ -f "${CT_SYSROOT_DIR}/${dir}/${file}" -a ! -L ${CT_SYSROOT_DIR}/$lib/$file ]; then
   2.182 -                CT_DoExecLog ALL cp -v "${CT_SYSROOT_DIR}/${dir}/${file}" "${CT_SYSROOT_DIR}/${dir}/${file}_orig"
   2.183 -                CT_DoLog DEBUG "Fixing '${CT_SYS_ROOT_DIR}/${dir}/${file}'"
   2.184 -                CT_DoExecLog ALL sed -i -r -e '/BUG in libc.scripts.output-format.sed/d' "${CT_SYSROOT_DIR}/${dir}/${file}"
   2.185 -            fi
   2.186 -        done
   2.187 -    done
   2.188 -
   2.189 -    CT_EndStep
   2.190 -}