scripts/build/libc/eglibc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon Sep 22 19:51:29 2008 +0000 (2008-09-22)
changeset 867 c91b266f4dfa
parent 850 ef8549b58b6f
child 884 35302e8a3483
permissions -rw-r--r--
Rework the eglibc download so as to be a little bit saner.

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