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