scripts/build/libc/eglibc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sat Jan 03 21:11:41 2009 +0000 (2009-01-03)
changeset 1112 c72aecd1a9ef
parent 1041 2573519c00d6
child 1123 8c5881324a79
permissions -rw-r--r--
Get rid of all stuff related to building a /delivery' traball:
- building a delivery tarball has long been broken (since crostool-Ng is installable)
- get rid of implied do_print_filename, that can be mis-leading now tarballs can not be built

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