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