scripts/build/libc/eglibc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Thu May 07 19:30:32 2009 +0000 (2009-05-07)
changeset 1328 f9e0931908f4
parent 1292 546d2ed3410b
child 1475 1626414b1662
permissions -rw-r--r--
Workaround for "PowerPC-8xx CPU15 errata" (whatever that might be).
Patch by Nye LIU: http://sourceware.org/ml/crossgcc/2009-05/msg00014.html

-------- diffstat follows --------
/trunk/patches/eglibc/2_9/100-powerpc-8xx-CPU15-errata.patch | 49 49 0 0 ++++++++++++++++++
/trunk/scripts/build/libc/eglibc.sh | 10 9 1 0 +++-
2 files changed, 58 insertions(+), 1 deletion(-)
     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_DoExecLog ALL svn ${svn_action} -r "${CT_EGLIBC_REVISION:-HEAD}" "${svn_url}" . 2>&1
    18 
    19     # Compress eglibc
    20     CT_DoExecLog ALL mv libc "eglibc-${CT_LIBC_VERSION}"
    21     CT_DoExecLog ALL tar cjf "eglibc-${CT_LIBC_VERSION}.tar.bz2" "eglibc-${CT_LIBC_VERSION}"
    22 
    23     # Compress linuxthreads, localedef and ports
    24     # Assign them the name the way ct-ng like it
    25     for addon in linuxthreads localedef ports; do
    26         CT_DoExecLog ALL mv "${addon}" "eglibc-${addon}-${CT_LIBC_VERSION}"
    27         CT_DoExecLog ALL tar cjf "eglibc-${addon}-${CT_LIBC_VERSION}.tar.bz2" "eglibc-${addon}-${CT_LIBC_VERSION}"
    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="eglibc-${CT_LIBC_VERSION}.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_Extract "eglibc-${CT_LIBC_VERSION}"
    95     CT_Patch "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_Extract "eglibc-${addon}-${CT_LIBC_VERSION}" nochdir
   103         # Some addons have the 'long' name, while others have the
   104         # 'short' name, but patches are non-uniformly built with
   105         # either the 'long' or 'short' name, whatever the addons name
   106         # so we have to make symlinks from the existing to the missing
   107         # Fortunately for us, [ -d foo ], when foo is a symlink to a
   108         # directory, returns true!
   109         [ -d "${addon}" ] || ln -s "eglibc-${addon}-${CT_LIBC_VERSION}" "${addon}"
   110         [ -d "eglibc-${addon}-${CT_LIBC_VERSION}" ] || ln -s "${addon}" "eglibc-${addon}-${CT_LIBC_VERSION}"
   111         CT_Patch "eglibc-${addon}-${CT_LIBC_VERSION}" nochdir
   112         CT_Popd
   113     done
   114 
   115     # The configure files may be older than the configure.in files
   116     # if using a snapshot (or even some tarballs). Fake them being
   117     # up to date.
   118     find "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}" -type f -name configure -exec touch {} \; 2>&1 |CT_DoLog ALL
   119 
   120     return 0
   121 }
   122 
   123 # There is nothing to do for eglibc check config
   124 do_libc_check_config() {
   125     :
   126 }
   127 
   128 # This function installs the eglibc headers needed to build the core compiler
   129 do_libc_headers() {
   130     # Instead of doing two time the same actions, headers will
   131     # be installed with start files
   132     :
   133 }
   134 
   135 # Build and install start files
   136 do_libc_start_files() {
   137     CT_DoStep INFO "Installing C library headers / start files"
   138 
   139     mkdir -p "${CT_BUILD_DIR}/build-libc-startfiles"
   140     cd "${CT_BUILD_DIR}/build-libc-startfiles"
   141 
   142     CT_DoLog EXTRA "Configuring C library"
   143 
   144     cross_cc=$(CT_Which "${CT_TARGET}-gcc")
   145     cross_cxx=$(CT_Which "${CT_TARGET}-g++")
   146     cross_ar=$(CT_Which "${CT_TARGET}-ar")
   147     cross_ranlib=$(CT_Which "${CT_TARGET}-ranlib")
   148     
   149     CT_DoLog DEBUG "Using gcc for target: '${cross_cc}'"
   150     CT_DoLog DEBUG "Using g++ for target: '${cross_cxx}'"
   151     CT_DoLog DEBUG "Using ar for target: '${cross_ar}'"
   152     CT_DoLog DEBUG "Using ranlib for target: '${cross_ranlib}'"
   153 
   154     BUILD_CC="${CT_BUILD}-gcc"                          \
   155     CC=${cross_cc}                                      \
   156     CXX=${cross_cxx}                                    \
   157     AR=${cross_ar}                                      \
   158     RANLIB=${cross_ranlib}                              \
   159     CT_DoExecLog ALL                                    \
   160     "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}/configure" \
   161         --prefix=/usr                                   \
   162         --with-headers="${CT_HEADERS_DIR}"              \
   163         --build="${CT_BUILD}"                           \
   164         --host="${CT_TARGET}"                           \
   165         --disable-profile                               \
   166         --without-gd                                    \
   167         --without-cvs                                   \
   168         --enable-add-ons
   169 
   170     CT_DoLog EXTRA "Installing C library headers"
   171 
   172     # use the 'install-headers' makefile target to install the
   173     # headers
   174 
   175     CT_DoExecLog ALL                    \
   176     make install-headers                \
   177          install_root=${CT_SYSROOT_DIR} \
   178          install-bootstrap-headers=yes
   179 
   180     CT_DoLog EXTRA "Installing C library start files"
   181 
   182     # there are a few object files needed to link shared libraries,
   183     # which we build and install by hand
   184 
   185     CT_DoExecLog ALL mkdir -p ${CT_SYSROOT_DIR}/usr/lib
   186     CT_DoExecLog ALL make csu/subdir_lib
   187     CT_DoExecLog ALL cp csu/crt1.o csu/crti.o csu/crtn.o \
   188         ${CT_SYSROOT_DIR}/usr/lib
   189 
   190     # Finally, 'libgcc_s.so' requires a 'libc.so' to link against.  
   191     # However, since we will never actually execute its code, 
   192     # it doesn't matter what it contains.  So, treating '/dev/null' 
   193     # as a C source file, we produce a dummy 'libc.so' in one step
   194 
   195     CT_DoExecLog ALL ${cross_cc} -nostdlib -nostartfiles -shared -x c /dev/null -o ${CT_SYSROOT_DIR}/usr/lib/libc.so
   196 
   197     CT_EndStep
   198 }
   199 
   200 # This function builds and install the full glibc
   201 do_libc() {
   202     CT_DoStep INFO "Installing C library"
   203 
   204     mkdir -p "${CT_BUILD_DIR}/build-libc"
   205     cd "${CT_BUILD_DIR}/build-libc"
   206 
   207     CT_DoLog EXTRA "Configuring C library"
   208 
   209     # Add some default glibc config options if not given by user.
   210     # We don't need to be conditional on wether the user did set different
   211     # values, as they CT_LIBC_GLIBC_EXTRA_CONFIG is passed after extra_config
   212 
   213     extra_config="--enable-kernel=$(echo ${CT_LIBC_GLIBC_MIN_KERNEL} |sed -r -e 's/^([^.]+\.[^.]+\.[^.]+)(|\.[^.]+)$/\1/;')"
   214 
   215     case "${CT_THREADS}" in
   216         nptl)           extra_config="${extra_config} --with-__thread --with-tls";;
   217         linuxthreads)   extra_config="${extra_config} --with-__thread --without-tls --without-nptl";;
   218         none)           extra_config="${extra_config} --without-__thread --without-nptl"
   219                         case "${CT_LIBC_GLIBC_EXTRA_CONFIG}" in
   220                             *-tls*) ;;
   221                             *) extra_config="${extra_config} --without-tls";;
   222                         esac
   223                         ;;
   224     esac
   225 
   226     case "${CT_SHARED_LIBS}" in
   227         y) extra_config="${extra_config} --enable-shared";;
   228         *) extra_config="${extra_config} --disable-shared";;
   229     esac
   230 
   231     case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
   232         y,) extra_config="${extra_config} --with-fp";;
   233         ,y) extra_config="${extra_config} --without-fp";;
   234     esac
   235 
   236     case "$(do_libc_add_ons_list ,)" in
   237         "") ;;
   238         *)  extra_config="${extra_config} --enable-add-ons=$(do_libc_add_ons_list ,)";;
   239     esac
   240 
   241     extra_cc_args="${extra_cc_args} ${CT_ARCH_ENDIAN_OPT}"
   242 
   243     cross_cc=$(CT_Which "${CT_TARGET}-gcc")    
   244 
   245     CT_DoLog DEBUG "Using gcc for target:     '${cross_cc}'"
   246     CT_DoLog DEBUG "Configuring with addons : '$(do_libc_add_ons_list ,)'"
   247     CT_DoLog DEBUG "Extra config args passed: '${extra_config}'"
   248     CT_DoLog DEBUG "Extra CC args passed    : '${extra_cc_args}'"
   249 
   250     BUILD_CC="${CT_BUILD}-gcc"                                      \
   251     CFLAGS="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} -O"   \
   252     CC="${CT_TARGET}-gcc ${CT_LIBC_EXTRA_CC_ARGS} ${extra_cc_args}" \
   253     AR=${CT_TARGET}-ar                                              \
   254     RANLIB=${CT_TARGET}-ranlib                                      \
   255     CT_DoExecLog ALL                                                \
   256     "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}/configure"             \
   257         --prefix=/usr                                               \
   258         --with-headers="${CT_HEADERS_DIR}"                          \
   259         --build=${CT_BUILD}                                         \
   260         --host=${CT_TARGET}                                         \
   261         --disable-profile                                           \
   262         --without-gd                                                \
   263         --without-cvs                                               \
   264         ${extra_config}                                             \
   265         ${CT_LIBC_GLIBC_EXTRA_CONFIG}
   266     
   267     CT_DoLog EXTRA "Building C library"
   268 
   269     # eglibc build hacks
   270     # http://sourceware.org/ml/crossgcc/2008-10/msg00068.html
   271     case "${CT_ARCH},${CT_ARCH_CPU}" in
   272         powerpc,8??)
   273             CT_DoLog DEBUG "Activating support for memset on broken ppc-8xx (CPU15 erratum)"
   274             EGLIBC_BUILD_ASFLAGS="-DBROKEN_PPC_8xx_CPU15";;
   275     esac
   276 
   277     CT_DoExecLog ALL make ASFLAGS="${EGLIBC_BUILD_ASFLAGS}"
   278 
   279     CT_DoLog EXTRA "Installing C library"
   280 
   281     CT_DoExecLog ALL make install install_root="${CT_SYSROOT_DIR}"
   282 
   283     CT_EndStep
   284 }
   285 
   286 # This function finishes the glibc install
   287 do_libc_finish() {
   288     # Nothing to be done for eglibc
   289     :
   290 }
   291 
   292 # Build up the addons list, separated with $1
   293 do_libc_add_ons_list() {
   294     local sep="$1"
   295     local addons_list=$(echo "${CT_LIBC_ADDONS_LIST//,/${sep}}" |tr -s ,)
   296     case "${CT_THREADS}" in
   297         none)   ;;
   298         *)      addons_list="${addons_list}${sep}${CT_THREADS}";;
   299     esac
   300     [ "${CT_LIBC_GLIBC_USE_PORTS}" = "y" ] && addons_list="${addons_list}${sep}ports"
   301     addons_list="${addons_list%%${sep}}"
   302     echo "${addons_list##${sep}}"
   303 }