scripts/build/libc/eglibc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon Jan 05 20:37:03 2009 +0000 (2009-01-05)
changeset 1124 eec7a46a4c19
parent 1123 8c5881324a79
child 1126 1ab3d2e08c8b
permissions -rw-r--r--
Fix C library addons extraction:
- renaming the dircetory in CT_ExtratAndPatch is wrong:
- patches against the C library addons may be build against the short *or* long name... :-(
- symlink is more robust, even if less nice
- renaming the directory _after_ CT_ExtractAndPatch is too late:
- if patches are against the short name, and we renamed too the long name, patches don't apply
- so we'll never reach the point where we rename

/trunk/scripts/build/libc/glibc.sh | 1 0 1 0 -
/trunk/scripts/build/libc/eglibc.sh | 1 0 1 0 -
/trunk/scripts/functions | 2 1 1 0 +-
3 files changed, 1 insertion(+), 3 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_ExtractAndPatch "eglibc-${CT_LIBC_VERSION}"
    96 
    97     # C library addons
    98     for addon in $(do_libc_add_ons_list " "); do
    99         # NPTL addon is not to be extracted, in any case
   100         [ "${addon}" = "nptl" ] && continue || true
   101         CT_Pushd "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}"
   102         CT_ExtractAndPatch "${CT_LIBC}-${addon}-${CT_LIBC_VERSION}" nochdir
   103         CT_Popd
   104     done
   105 
   106     # The configure files may be older than the configure.in files
   107     # if using a snapshot (or even some tarballs). Fake them being
   108     # up to date.
   109     find "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}" -type f -name configure -exec touch {} \; 2>&1 |CT_DoLog ALL
   110 
   111     return 0
   112 }
   113 
   114 # There is nothing to do for eglibc check config
   115 do_libc_check_config() {
   116     :
   117 }
   118 
   119 # This function installs the eglibc headers needed to build the core compiler
   120 do_libc_headers() {
   121     # Instead of doing two time the same actions, headers will
   122     # be installed with start files
   123     :
   124 }
   125 
   126 # Build and install start files
   127 do_libc_start_files() {
   128     CT_DoStep INFO "Installing C library headers / start files"
   129 
   130     mkdir -p "${CT_BUILD_DIR}/build-libc-startfiles"
   131     cd "${CT_BUILD_DIR}/build-libc-startfiles"
   132 
   133     CT_DoLog EXTRA "Configuring C library"
   134 
   135     cross_cc=$(CT_Which "${CT_TARGET}-gcc")
   136     cross_cxx=$(CT_Which "${CT_TARGET}-g++")
   137     cross_ar=$(CT_Which "${CT_TARGET}-ar")
   138     cross_ranlib=$(CT_Which "${CT_TARGET}-ranlib")
   139     
   140     CT_DoLog DEBUG "Using gcc for target: '${cross_cc}'"
   141     CT_DoLog DEBUG "Using g++ for target: '${cross_cxx}'"
   142     CT_DoLog DEBUG "Using ar for target: '${cross_ar}'"
   143     CT_DoLog DEBUG "Using ranlib for target: '${cross_ranlib}'"
   144 
   145     BUILD_CC="${CT_BUILD}-gcc"                          \
   146     CC=${cross_cc}                                      \
   147     CXX=${cross_cxx}                                    \
   148     AR=${cross_ar}                                      \
   149     RANLIB=${cross_ranlib}                              \
   150     CT_DoExecLog ALL                                    \
   151     "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}/configure" \
   152         --prefix=/usr                                   \
   153         --with-headers="${CT_HEADERS_DIR}"              \
   154         --build="${CT_BUILD}"                           \
   155         --host="${CT_TARGET}"                           \
   156         --disable-profile                               \
   157         --without-gd                                    \
   158         --without-cvs                                   \
   159         --enable-add-ons
   160 
   161     CT_DoLog EXTRA "Installing C library headers"
   162 
   163     # use the 'install-headers' makefile target to install the
   164     # headers
   165 
   166     CT_DoExecLog ALL                    \
   167     make install-headers                \
   168          install_root=${CT_SYSROOT_DIR} \
   169          install-bootstrap-headers=yes
   170 
   171     CT_DoLog EXTRA "Installing C library start files"
   172 
   173     # there are a few object files needed to link shared libraries,
   174     # which we build and install by hand
   175 
   176     CT_DoExecLog ALL mkdir -p ${CT_SYSROOT_DIR}/usr/lib
   177     CT_DoExecLog ALL make csu/subdir_lib
   178     CT_DoExecLog ALL cp csu/crt1.o csu/crti.o csu/crtn.o \
   179         ${CT_SYSROOT_DIR}/usr/lib
   180 
   181     # Finally, 'libgcc_s.so' requires a 'libc.so' to link against.  
   182     # However, since we will never actually execute its code, 
   183     # it doesn't matter what it contains.  So, treating '/dev/null' 
   184     # as a C source file, we produce a dummy 'libc.so' in one step
   185 
   186     CT_DoExecLog ALL ${cross_cc} -nostdlib -nostartfiles -shared -x c /dev/null -o ${CT_SYSROOT_DIR}/usr/lib/libc.so
   187 
   188     CT_EndStep
   189 }
   190 
   191 # This function builds and install the full glibc
   192 do_libc() {
   193     CT_DoStep INFO "Installing C library"
   194 
   195     mkdir -p "${CT_BUILD_DIR}/build-libc"
   196     cd "${CT_BUILD_DIR}/build-libc"
   197 
   198     CT_DoLog EXTRA "Configuring C library"
   199 
   200     # Add some default glibc config options if not given by user.
   201     # We don't need to be conditional on wether the user did set different
   202     # values, as they CT_LIBC_GLIBC_EXTRA_CONFIG is passed after extra_config
   203 
   204     extra_config="--enable-kernel=$(echo ${CT_LIBC_GLIBC_MIN_KERNEL} |sed -r -e 's/^([^.]+\.[^.]+\.[^.]+)(|\.[^.]+)$/\1/;')"
   205 
   206     case "${CT_THREADS}" in
   207         nptl)           extra_config="${extra_config} --with-__thread --with-tls";;
   208         linuxthreads)   extra_config="${extra_config} --with-__thread --without-tls --without-nptl";;
   209         none)           extra_config="${extra_config} --without-__thread --without-nptl"
   210                         case "${CT_LIBC_GLIBC_EXTRA_CONFIG}" in
   211                             *-tls*) ;;
   212                             *) extra_config="${extra_config} --without-tls";;
   213                         esac
   214                         ;;
   215     esac
   216 
   217     case "${CT_SHARED_LIBS}" in
   218         y) extra_config="${extra_config} --enable-shared";;
   219         *) extra_config="${extra_config} --disable-shared";;
   220     esac
   221 
   222     case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
   223         y,) extra_config="${extra_config} --with-fp";;
   224         ,y) extra_config="${extra_config} --without-fp";;
   225     esac
   226 
   227     case "$(do_libc_add_ons_list ,)" in
   228         "") ;;
   229         *)  extra_config="${extra_config} --enable-add-ons=$(do_libc_add_ons_list ,)";;
   230     esac
   231 
   232     extra_cc_args="${extra_cc_args} ${CT_ARCH_ENDIAN_OPT}"
   233 
   234     cross_cc=$(CT_Which "${CT_TARGET}-gcc")    
   235 
   236     CT_DoLog DEBUG "Using gcc for target:     '${cross_cc}'"
   237     CT_DoLog DEBUG "Configuring with addons : '$(do_libc_add_ons_list ,)'"
   238     CT_DoLog DEBUG "Extra config args passed: '${extra_config}'"
   239     CT_DoLog DEBUG "Extra CC args passed    : '${extra_cc_args}'"
   240 
   241     BUILD_CC="${CT_BUILD}-gcc"                                      \
   242     CFLAGS="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} -O"   \
   243     CC="${CT_TARGET}-gcc ${CT_LIBC_EXTRA_CC_ARGS} ${extra_cc_args}" \
   244     AR=${CT_TARGET}-ar                                              \
   245     RANLIB=${CT_TARGET}-ranlib                                      \
   246     CT_DoExecLog ALL                                                \
   247     "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}/configure"             \
   248         --prefix=/usr                                               \
   249         --with-headers="${CT_HEADERS_DIR}"                          \
   250         --build=${CT_BUILD}                                         \
   251         --host=${CT_TARGET}                                         \
   252         --disable-profile                                           \
   253         --without-gd                                                \
   254         --without-cvs                                               \
   255         ${extra_config}                                             \
   256         ${CT_LIBC_GLIBC_EXTRA_CONFIG}
   257     
   258     CT_DoLog EXTRA "Building C library"
   259 
   260     CT_DoExecLog ALL make
   261 
   262     CT_DoLog EXTRA "Installing C library"
   263 
   264     CT_DoExecLog ALL make install install_root="${CT_SYSROOT_DIR}"
   265 
   266     CT_EndStep
   267 }
   268 
   269 # This function finishes the glibc install
   270 do_libc_finish() {
   271     # Nothing to be done for eglibc
   272     :
   273 }
   274 
   275 # Build up the addons list, separated with $1
   276 do_libc_add_ons_list() {
   277     local sep="$1"
   278     local addons_list=$(echo "${CT_LIBC_ADDONS_LIST//,/${sep}}" |tr -s ,)
   279     case "${CT_THREADS}" in
   280         none)   ;;
   281         *)      addons_list="${addons_list}${sep}${CT_THREADS}";;
   282     esac
   283     [ "${CT_LIBC_GLIBC_USE_PORTS}" = "y" ] && addons_list="${addons_list}${sep}ports"
   284     addons_list="${addons_list%%${sep}}"
   285     echo "${addons_list##${sep}}"
   286 }