scripts/build/libc/eglibc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Aug 30 00:57:40 2009 +0200 (2009-08-30)
changeset 1495 2542421e3321
parent 1476 eded63022651
child 1528 f87b08efe892
permissions -rw-r--r--
tools wrapper: introduce the silent WRAPPER_NEEDED config option

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