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