# This file adds functions to build glibc # Copyright 2007 Yann E. MORIN # Licensed under the GPL v2. See COPYING in the root of this package # Add the definitions common to glibc and eglibc # do_libc_headers # do_libc_start_files . "${CT_LIB_DIR}/scripts/build/libc/glibc-eglibc.sh-common" # Download glibc do_libc_get() { local date local version local -a addons_list addons_list=($(do_libc_add_ons_list " ")) # Main source CT_GetFile "glibc-${CT_LIBC_VERSION}" \ {ftp,http}://ftp.gnu.org/gnu/glibc \ ftp://gcc.gnu.org/pub/glibc/releases \ ftp://gcc.gnu.org/pub/glibc/snapshots # C library addons for addon in "${addons_list[@]}"; do # NPTL addon is not to be downloaded, in any case [ "${addon}" = "nptl" ] && continue || true CT_GetFile "glibc-${addon}-${CT_LIBC_VERSION}" \ {ftp,http}://ftp.gnu.org/gnu/glibc \ ftp://gcc.gnu.org/pub/glibc/releases \ ftp://gcc.gnu.org/pub/glibc/snapshots done return 0 } # Extract glibc do_libc_extract() { local -a addons_list addons_list=($(do_libc_add_ons_list " ")) CT_Extract "glibc-${CT_LIBC_VERSION}" CT_Pushd "${CT_SRC_DIR}/glibc-${CT_LIBC_VERSION}" CT_Patch nochdir "glibc" "${CT_LIBC_VERSION}" # C library addons for addon in "${addons_list[@]}"; do # NPTL addon is not to be extracted, in any case [ "${addon}" = "nptl" ] && continue || true CT_Extract nochdir "glibc-${addon}-${CT_LIBC_VERSION}" # Some addons have the 'long' name, while others have the # 'short' name, but patches are non-uniformly built with # either the 'long' or 'short' name, whatever the addons name # so we have to make symlinks from the existing to the missing # Fortunately for us, [ -d foo ], when foo is a symlink to a # directory, returns true! [ -d "${addon}" ] || CT_DoExecLog ALL ln -s "glibc-${addon}-${CT_LIBC_VERSION}" "${addon}" [ -d "glibc-${addon}-${CT_LIBC_VERSION}" ] || CT_DoExecLog ALL ln -s "${addon}" "glibc-${addon}-${CT_LIBC_VERSION}" CT_Patch nochdir "glibc" "${addon}-${CT_LIBC_VERSION}" done # The configure files may be older than the configure.in files # if using a snapshot (or even some tarballs). Fake them being # up to date. sleep 2 find . -type f -name configure -exec touch {} \; 2>&1 |CT_DoLog ALL CT_Popd return 0 } # There is nothing to do for glibc check config do_libc_check_config() { : } # This function builds and install the full glibc do_libc() { local -a extra_config CT_DoStep INFO "Installing C library" mkdir -p "${CT_BUILD_DIR}/build-libc" cd "${CT_BUILD_DIR}/build-libc" CT_DoLog EXTRA "Configuring C library" # Add some default glibc config options if not given by user. # We don't need to be conditional on wether the user did set different # values, as they CT_LIBC_GLIBC_EXTRA_CONFIG is passed after extra_config case "${CT_THREADS}" in nptl) extra_config+=("--with-__thread" "--with-tls");; linuxthreads) extra_config+=("--with-__thread" "--without-tls" "--without-nptl");; none) extra_config+=("--without-__thread" "--without-nptl") case "${CT_LIBC_GLIBC_EXTRA_CONFIG}" in *-tls*) ;; *) extra_config+=("--without-tls");; esac ;; esac case "${CT_SHARED_LIBS}" in y) extra_config+=("--enable-shared");; *) extra_config+=("--disable-shared");; esac case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in y,) extra_config+=("--with-fp");; ,y) extra_config+=("--without-fp");; esac if [ "${CT_LIBC_DISABLE_VERSIONING}" = "y" ]; then extra_config+=("--disable-versioning") fi if [ "${CT_LIBC_OLDEST_ABI}" != "" ]; then extra_config+=("--enable-oldest-abi=${CT_LIBC_OLDEST_ABI}") fi case "$(do_libc_add_ons_list ,)" in "") ;; *) extra_config+=("--enable-add-ons=$(do_libc_add_ons_list ,)");; esac extra_config+=("$(do_libc_min_kernel_config)") # Add some default CC args glibc_version="$( grep -E '\' "${CT_SRC_DIR}/glibc-${CT_LIBC_VERSION}/version.h" \ |cut -d '"' -f 2 )" glibc_version_major=$(echo ${glibc_version} |sed -r -e 's/^([[:digit:]]+).*/\1/') glibc_version_minor=$(echo ${glibc_version} |sed -r -e 's/^[[:digit:]]+[\.-_]([[:digit:]]+).*/\1/') if [ ${glibc_version_major} -eq 2 -a ${glibc_version_minor} -ge 6 \ -o ${glibc_version_major} -gt 2 ]; then # Don't use -pipe: configure chokes on it for glibc >= 2.6. CT_Test 'Removing "-pipe" for use with glibc>=2.6' "${CT_USE_PIPES}" = "y" extra_cc_args="${CT_CFLAGS_FOR_HOST/-pipe}" else extra_cc_args="${CT_CFLAGS_FOR_HOST}" fi extra_cc_args="${extra_cc_args} ${CT_ARCH_ENDIAN_OPT}" cross_cc=$(CT_Which "${CT_TARGET}-gcc") CT_DoLog DEBUG "Using gcc for target : '${cross_cc}'" CT_DoLog DEBUG "Configuring with addons : '$(do_libc_add_ons_list ,)'" CT_DoLog DEBUG "Extra config args passed: '${extra_config}'" CT_DoLog DEBUG "Extra CC args passed : '${extra_cc_args}'" # Pre-seed the configparms file with values from the config option printf "${CT_LIBC_GLIBC_CONFIGPARMS}\n" > configparms # For glibc 2.3.4 and later we need to set some autoconf cache # variables, because nptl/sysdeps/pthread/configure.in does not # work when cross-compiling. if [ "${CT_THREADS}" = "nptl" ]; then echo libc_cv_forced_unwind=yes echo libc_cv_c_cleanup=yes fi >config.cache # ./configure is mislead by our tools override wrapper for bash # so just tell it where the real bash is _on_the_target_! # Notes: # - ${ac_cv_path_BASH_SHELL} is only used to set BASH_SHELL # - ${BASH_SHELL} is only used to set BASH # - ${BASH} is only used to set the shebang # in two scripts to run on the target # So we can safely bypass bash detection at compile time. # Should this change in a future glibc release, we'd better # directly mangle the generated scripts _after_ they get built, # or even after they get installed... glibc is such a sucker... echo "ac_cv_path_BASH_SHELL=/bin/bash" >>config.cache # Configure with --prefix the way we want it on the target... # There are a whole lot of settings here. You'll probably want # to read up on what they all mean, and customize a bit, possibly by setting GLIBC_EXTRA_CONFIG # Compare these options with the ones used when installing the glibc headers above - they're different. # Adding "--without-gd" option to avoid error "memusagestat.c:36:16: gd.h: No such file or directory" # See also http://sources.redhat.com/ml/libc-alpha/2000-07/msg00024.html. # Set BUILD_CC, or you won't be able to build datafiles # Set --build, else glibc-2.3.2 will think you're not cross-compiling, and try to run the test programs # OK. I'm fed up with those folks telling me what I should do. # I don't configure nptl? Well, maybe that's purposedly because # I don't want nptl! --disable-sanity-checks will shut up those # silly messages. GNU folks again, he? BUILD_CC="${CT_BUILD}-gcc" \ CFLAGS="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} -O2" \ CC="${CT_TARGET}-gcc ${CT_LIBC_EXTRA_CC_ARGS} ${extra_cc_args}" \ AR=${CT_TARGET}-ar \ RANLIB=${CT_TARGET}-ranlib \ CT_DoExecLog CFG \ "${CT_SRC_DIR}/glibc-${CT_LIBC_VERSION}/configure" \ --prefix=/usr \ --build=${CT_BUILD} \ --host=${CT_TARGET} \ --without-cvs \ --disable-profile \ --disable-debug \ --without-gd \ --disable-sanity-checks \ --cache-file=config.cache \ --with-headers="${CT_HEADERS_DIR}" \ "${extra_config[@]}" \ ${CT_LIBC_GLIBC_EXTRA_CONFIG} # glibc initial build hacks # http://sourceware.org/ml/crossgcc/2008-10/msg00068.html case "${CT_ARCH},${CT_ARCH_CPU}" in powerpc,8??) CT_DoLog DEBUG "Activating support for memset on broken ppc-8xx (CPU15 erratum)" GLIBC_INITIAL_BUILD_ASFLAGS="-DBROKEN_PPC_8xx_CPU15";; esac # If this fails with an error like this: # ... linux/autoconf.h: No such file or directory # then you need to set the KERNELCONFIG variable to point to a .config file for this arch. # The following architectures are known to need kernel .config: alpha, arm, ia64, s390, sh, sparc # Note: LD and RANLIB needed by glibc-2.1.3's c_stub directory, at least on macosx CT_DoLog EXTRA "Building C library" CT_DoExecLog ALL make LD=${CT_TARGET}-ld \ RANLIB=${CT_TARGET}-ranlib \ OBJDUMP_FOR_HOST="${CT_TARGET}-objdump" \ ASFLAGS="${GLIBC_INITIAL_BUILD_ASFLAGS}" \ PARALLELMFLAGS="${PARALLELMFLAGS}" \ all CT_DoLog EXTRA "Installing C library" CT_DoExecLog ALL make install_root="${CT_SYSROOT_DIR}" \ ${LIBC_SYSROOT_ARG} \ OBJDUMP_FOR_HOST="${CT_TARGET}-objdump" \ PARALLELMFLAGS="${PARALLELMFLAGS}" \ install # This doesn't seem to work when building a crosscompiler, # as it tries to execute localedef using the just-built ld.so!? #CT_DoLog EXTRA "Installing locales" #make localedata/install-locales install_root=${SYSROOT} 2>&1 |CT_DoLog ALL # Fix problems in linker scripts. # # Remove lines containing BUG per http://sources.redhat.com/ml/bug-glibc/2003-05/msg00055.html, # needed to fix gcc-3.2.3/glibc-2.3.2 targeting arm # No need to look into the lib64/ dirs here and there, they point to the # corresponding lib/ directories. # # To make "strip *.so.*" not fail (ptxdist does this), rename to .so_orig rather than .so.orig CT_DoLog EXTRA "Fixing C library linker scripts" for file in libc.so libpthread.so libgcc_s.so; do for dir in lib usr/lib; do if [ -f "${CT_SYSROOT_DIR}/${dir}/${file}" -a ! -L ${CT_SYSROOT_DIR}/$lib/$file ]; then CT_DoExecLog ALL cp -v "${CT_SYSROOT_DIR}/${dir}/${file}" "${CT_SYSROOT_DIR}/${dir}/${file}_orig" CT_DoLog DEBUG "Fixing '${CT_SYS_ROOT_DIR}/${dir}/${file}'" CT_DoExecLog ALL sed -i -r -e '/BUG in libc.scripts.output-format.sed/d' "${CT_SYSROOT_DIR}/${dir}/${file}" fi done done CT_EndStep } # Build up the addons list, separated with $1 do_libc_add_ons_list() { local sep="$1" local addons_list=$(echo "${CT_LIBC_ADDONS_LIST}" |sed -r -e "s/[ ,]/${sep}/g;") case "${CT_THREADS}" in none) ;; *) addons_list="${addons_list}${sep}${CT_THREADS}";; esac [ "${CT_LIBC_GLIBC_USE_PORTS}" = "y" ] && addons_list="${addons_list}${sep}ports" # Remove duplicate, leading and trailing separators echo "${addons_list}" |sed -r -e "s/${sep}+/${sep}/g; s/^${sep}//; s/${sep}\$//;" }