scripts/build/libc/uClibc.sh
changeset 850 ef8549b58b6f
child 1027 ae53f827dce6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/scripts/build/libc/uClibc.sh	Sun Sep 14 16:21:07 2008 +0000
     1.3 @@ -0,0 +1,313 @@
     1.4 +# This file declares functions to install the uClibc C library
     1.5 +# Copyright 2007 Yann E. MORIN
     1.6 +# Licensed under the GPL v2. See COPYING in the root of this package
     1.7 +
     1.8 +do_print_filename() {
     1.9 +    [ "${CT_LIBC}" = "uClibc" ] || return 0
    1.10 +    echo "uClibc-${CT_LIBC_VERSION}"
    1.11 +    [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ] && echo "uClibc-locale-030818" || true
    1.12 +}
    1.13 +
    1.14 +# Download uClibc
    1.15 +do_libc_get() {
    1.16 +    libc_src="http://www.uclibc.org/downloads
    1.17 +              http://www.uclibc.org/downloads/snapshots
    1.18 +              http://www.uclibc.org/downloads/old-releases"
    1.19 +    # For uClibc, we have almost every thing: releases, and snapshots
    1.20 +    # for the last month or so. We'll have to deal with svn revisions
    1.21 +    # later...
    1.22 +    CT_GetFile "${CT_LIBC_FILE}" ${libc_src}
    1.23 +    # uClibc locales
    1.24 +    [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ] && CT_GetFile "uClibc-locale-030818" ${libc_src} || true
    1.25 +
    1.26 +    return 0
    1.27 +}
    1.28 +
    1.29 +# Extract uClibc
    1.30 +do_libc_extract() {
    1.31 +    CT_ExtractAndPatch "${CT_LIBC_FILE}"
    1.32 +    # uClibc locales
    1.33 +    [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ] && CT_ExtractAndPatch "uClibc-locale-030818" || true
    1.34 +
    1.35 +    return 0
    1.36 +}
    1.37 +
    1.38 +# Check that uClibc has been previously configured
    1.39 +do_libc_check_config() {
    1.40 +    CT_DoStep INFO "Checking C library configuration"
    1.41 +
    1.42 +    CT_TestOrAbort "You did not provide a uClibc config file!" -n "${CT_LIBC_UCLIBC_CONFIG_FILE}" -a -f "${CT_LIBC_UCLIBC_CONFIG_FILE}"
    1.43 +
    1.44 +    if egrep '^KERNEL_SOURCE=' "${CT_LIBC_UCLIBC_CONFIG_FILE}" >/dev/null 2>&1; then
    1.45 +        CT_DoLog WARN "Your uClibc version refers to the kernel _sources_, which is bad."
    1.46 +        CT_DoLog WARN "I can't guarantee that our little hack will work. Please try to upgrade."
    1.47 +    fi
    1.48 +
    1.49 +    CT_DoLog EXTRA "Munging uClibc configuration"
    1.50 +    mungeuClibcConfig "${CT_LIBC_UCLIBC_CONFIG_FILE}" "${CT_BUILD_DIR}/uClibc.config"
    1.51 +
    1.52 +    CT_EndStep
    1.53 +}
    1.54 +
    1.55 +# This functions installs uClibc's headers
    1.56 +do_libc_headers() {
    1.57 +    # Only need to install bootstrap uClibc headers for gcc-3.0 and above?  Or maybe just gcc-3.3 and above?
    1.58 +    # See also http://gcc.gnu.org/PR8180, which complains about the need for this step.
    1.59 +    grep -q 'gcc-[34]' "${CT_SRC_DIR}/${CT_CC_FILE}/ChangeLog" 2>/dev/null || return 0
    1.60 +
    1.61 +    CT_DoStep INFO "Installing C library headers"
    1.62 +
    1.63 +    mkdir -p "${CT_BUILD_DIR}/build-libc-headers"
    1.64 +    cd "${CT_BUILD_DIR}/build-libc-headers"
    1.65 +
    1.66 +    # Simply copy files until uClibc has the ablity to build out-of-tree
    1.67 +    CT_DoLog EXTRA "Copying sources to build dir"
    1.68 +    { cd "${CT_SRC_DIR}/${CT_LIBC_FILE}"; tar cf - .; } |tar xf -
    1.69 +
    1.70 +    # Retrieve the config file
    1.71 +    cp "${CT_BUILD_DIR}/uClibc.config" .config
    1.72 +
    1.73 +    # uClibc uses the CROSS environment variable as a prefix to the
    1.74 +    # compiler tools to use.  Setting it to the empty string forces
    1.75 +    # use of the native build host tools, which we need at this
    1.76 +    # stage, as we don't have target tools yet.
    1.77 +    CT_DoLog EXTRA "Applying configuration"
    1.78 +    CT_DoYes "" |CT_DoExecLog ALL make CROSS= PREFIX="${CT_SYSROOT_DIR}/" oldconfig
    1.79 +
    1.80 +    CT_DoLog EXTRA "Building headers"
    1.81 +    CT_DoExecLog ALL make ${CT_LIBC_UCLIBC_VERBOSITY} CROSS= PREFIX="${CT_SYSROOT_DIR}/" headers
    1.82 +
    1.83 +    CT_DoLog EXTRA "Installing headers"
    1.84 +    CT_DoExecLog ALL make ${CT_LIBC_UCLIBC_VERBOSITY} CROSS= PREFIX="${CT_SYSROOT_DIR}/" install_dev
    1.85 +
    1.86 +    CT_EndStep
    1.87 +}
    1.88 +
    1.89 +# Build and install start files
    1.90 +do_libc_start_files() {
    1.91 +    :
    1.92 +}
    1.93 +
    1.94 +# This function build and install the full uClibc
    1.95 +do_libc() {
    1.96 +    CT_DoStep INFO "Installing C library"
    1.97 +
    1.98 +    mkdir -p "${CT_BUILD_DIR}/build-libc"
    1.99 +    cd "${CT_BUILD_DIR}/build-libc"
   1.100 +
   1.101 +    # Simply copy files until uClibc has the ablity to build out-of-tree
   1.102 +    CT_DoLog EXTRA "Copying sources to build dir"
   1.103 +    { cd "${CT_SRC_DIR}/${CT_LIBC_FILE}"; tar cf - .; } |tar xf -
   1.104 +
   1.105 +    # Retrieve the config file
   1.106 +    cp "${CT_BUILD_DIR}/uClibc.config" .config
   1.107 +
   1.108 +    # uClibc uses the CROSS environment variable as a prefix to the compiler
   1.109 +    # tools to use.  The newly built tools should be in our path, so we need
   1.110 +    # only give the correct name for them.
   1.111 +    # Note about CFLAGS: In uClibc, CFLAGS are generated by Rules.mak,
   1.112 +    # depending  on the configuration of the library. That is, they are tailored
   1.113 +    # to best fit the target. So it is useless and seems to be a bad thing to
   1.114 +    # use LIBC_EXTRA_CFLAGS here.
   1.115 +    CT_DoLog EXTRA "Applying configuration"
   1.116 +    CT_DoYes "" |CT_DoExecLog ALL               \
   1.117 +                 make CROSS=${CT_TARGET}-       \
   1.118 +                 PREFIX="${CT_SYSROOT_DIR}/"    \
   1.119 +                 oldconfig
   1.120 +
   1.121 +    # We do _not_ want to strip anything for now, in case we specifically
   1.122 +    # asked for a debug toolchain, thus the STRIPTOOL= assignment
   1.123 +    CT_DoLog EXTRA "Building C library"
   1.124 +    CT_DoExecLog ALL                    \
   1.125 +    make CROSS=${CT_TARGET}-            \
   1.126 +         PREFIX="${CT_SYSROOT_DIR}/"    \
   1.127 +         STRIPTOOL=true                 \
   1.128 +         ${CT_LIBC_UCLIBC_VERBOSITY}    \
   1.129 +         all
   1.130 +
   1.131 +    # YEM-FIXME: we want to install libraries in $SYSROOT/lib, but we don't want
   1.132 +    # to install headers in $SYSROOT/include, thus making only install_runtime.
   1.133 +    # Plus, the headers were previously installed earlier with install_dev, so
   1.134 +    # all should be well. Unfortunately, the install_dev target does not install
   1.135 +    # crti.o and consorts... :-( So reverting to target 'install'.
   1.136 +    # Note: PARALLELMFLAGS is not usefull for installation.
   1.137 +    # We do _not_ want to strip anything for now, in case we specifically
   1.138 +    # asked for a debug toolchain, thus the STRIPTOOL= assignment
   1.139 +    CT_DoLog EXTRA "Installing C library"
   1.140 +    CT_DoExecLog ALL                    \
   1.141 +    make CROSS=${CT_TARGET}-            \
   1.142 +         PREFIX="${CT_SYSROOT_DIR}/"    \
   1.143 +         STRIPTOOL=true                 \
   1.144 +         ${CT_LIBC_UCLIBC_VERBOSITY}    \
   1.145 +         install
   1.146 +
   1.147 +    CT_EndStep
   1.148 +}
   1.149 +
   1.150 +# This function is used to install those components needing the final C compiler
   1.151 +do_libc_finish() {
   1.152 +    :
   1.153 +}
   1.154 +
   1.155 +# Initialises the .config file to sensible values
   1.156 +# $1: original file
   1.157 +# $2: munged file
   1.158 +mungeuClibcConfig() {
   1.159 +    src_config_file="$1"
   1.160 +    dst_config_file="$2"
   1.161 +    munge_file="${CT_BUILD_DIR}/munge-uClibc-config.sed"
   1.162 +
   1.163 +    # Start with a fresh file
   1.164 +    rm -f "${munge_file}"
   1.165 +    touch "${munge_file}"
   1.166 +
   1.167 +    # Hack our target in the config file.
   1.168 +    # Also remove stripping: its the responsibility of the
   1.169 +    # firmware builder to strip or not.
   1.170 +    cat >>"${munge_file}" <<-ENDSED
   1.171 +s/^(TARGET_.*)=y$/# \\1 is not set/
   1.172 +s/^# TARGET_${CT_KERNEL_ARCH} is not set/TARGET_${CT_KERNEL_ARCH}=y/
   1.173 +s/^TARGET_ARCH=".*"/TARGET_ARCH="${CT_KERNEL_ARCH}"/
   1.174 +s/.*(DOSTRIP).*/# \\1 is not set/
   1.175 +ENDSED
   1.176 +
   1.177 +    # Ah. We may one day need architecture-specific handler here...
   1.178 +    # Hack the ARM {E,O}ABI into the config file
   1.179 +    if [ "${CT_ARCH_ARM_EABI}" = "y" ]; then
   1.180 +        cat >>"${munge_file}" <<-ENDSED
   1.181 +s/.*(CONFIG_ARM_OABI).*/# \\1 is not set/
   1.182 +s/.*(CONFIG_ARM_EABI).*/\\1=y/
   1.183 +ENDSED
   1.184 +    else
   1.185 +        cat >>"${munge_file}" <<-ENDSED
   1.186 +s/.*(CONFIG_ARM_OABI).*/\\1=y/
   1.187 +s/.*(CONFIG_ARM_EABI).*/# \\1 is not set/
   1.188 +ENDSED
   1.189 +    fi
   1.190 +
   1.191 +    # Accomodate for old and new uClibc versions, where the
   1.192 +    # way to select between big/little endian has changed
   1.193 +    case "${CT_ARCH_BE},${CT_ARCH_LE}" in
   1.194 +        y,) cat >>"${munge_file}" <<-ENDSED
   1.195 +s/.*(ARCH_LITTLE_ENDIAN).*/# \\1 is not set/
   1.196 +s/.*(ARCH_BIG_ENDIAN).*/\\1=y/
   1.197 +s/.*(ARCH_WANTS_LITTLE_ENDIAN).*/# \\1 is not set/
   1.198 +s/.*(ARCH_WANTS_BIG_ENDIAN).*/\\1=y/
   1.199 +ENDSED
   1.200 +        ;;
   1.201 +        ,y) cat >>"${munge_file}" <<-ENDSED
   1.202 +s/.*(ARCH_LITTLE_ENDIAN).*/\\1=y/
   1.203 +s/.*(ARCH_BIG_ENDIAN).*/# \\1 is not set/
   1.204 +s/.*(ARCH_WANTS_LITTLE_ENDIAN).*/\\1=y/
   1.205 +s/.*(ARCH_WANTS_BIG_ENDIAN).*/# \\1 is not set/
   1.206 +ENDSED
   1.207 +        ;;
   1.208 +    esac
   1.209 +
   1.210 +    # Accomodate for old and new uClibc version, where the
   1.211 +    # way to select between hard/soft float has changed
   1.212 +    case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
   1.213 +        y,) cat >>"${munge_file}" <<-ENDSED
   1.214 +s/^[^_]*(HAS_FPU).*/\\1=y/
   1.215 +s/.*(UCLIBC_HAS_FPU).*/\\1=y/
   1.216 +ENDSED
   1.217 +            ;;
   1.218 +        ,y) cat >>"${munge_file}" <<-ENDSED
   1.219 +s/^[^_]*(HAS_FPU).*/\\# \\1 is not set/
   1.220 +s/.*(UCLIBC_HAS_FPU).*/# \\1 is not set/
   1.221 +ENDSED
   1.222 +            ;;
   1.223 +    esac
   1.224 +
   1.225 +    # Change paths to work with crosstool-NG
   1.226 +    # From http://www.uclibc.org/cgi-bin/viewcvs.cgi?rev=16846&view=rev
   1.227 +    #  " we just want the kernel headers, not the whole kernel source ...
   1.228 +    #  " so people may need to update their paths slightly
   1.229 +    quoted_kernel_source=$(echo "${CT_HEADERS_DIR}" | sed -r -e 's,/include/?$,,; s,/,\\/,g;')
   1.230 +    quoted_headers_dir=$(echo "${CT_HEADERS_DIR}" | sed -r -e 's,/,\\/,g;')
   1.231 +    # CROSS_COMPILER_PREFIX is left as is, as the CROSS parameter is forced on the command line
   1.232 +    # DEVEL_PREFIX is left as '/usr/' because it is post-pended to $PREFIX, wich is the correct value of ${PREFIX}/${TARGET}
   1.233 +    # Some (old) versions of uClibc use KERNEL_SOURCE (which is _wrong_), and
   1.234 +    # newer versions use KERNEL_HEADERS (which is right). See:
   1.235 +    cat >>"${munge_file}" <<-ENDSED
   1.236 +s/^DEVEL_PREFIX=".*"/DEVEL_PREFIX="\\/usr\\/"/
   1.237 +s/^RUNTIME_PREFIX=".*"/RUNTIME_PREFIX="\\/"/
   1.238 +s/^SHARED_LIB_LOADER_PREFIX=.*/SHARED_LIB_LOADER_PREFIX="\\/lib\\/"/
   1.239 +s/^KERNEL_SOURCE=".*"/KERNEL_SOURCE="${quoted_kernel_source}"/
   1.240 +s/^KERNEL_HEADERS=".*"/KERNEL_HEADERS="${quoted_headers_dir}"/
   1.241 +s/^UCLIBC_DOWNLOAD_PREGENERATED_LOCALE=y/\\# UCLIBC_DOWNLOAD_PREGENERATED_LOCALE is not set/
   1.242 +ENDSED
   1.243 +
   1.244 +    if [ "${CT_USE_PIPES}" = "y" ]; then
   1.245 +        if grep UCLIBC_EXTRA_CFLAGS extra/Configs/Config.in >/dev/null 2>&1; then
   1.246 +            # Good, there is special provision for such things as -pipe!
   1.247 +            cat >>"${munge_file}" <<-ENDSED
   1.248 +s/^(UCLIBC_EXTRA_CFLAGS=".*)"$/\\1 -pipe"/
   1.249 +ENDSED
   1.250 +        else
   1.251 +            # Hack our -pipe into WARNINGS, which will be internally incorporated to
   1.252 +            # CFLAGS. This a dirty hack, but yet needed
   1.253 +            cat >> "${munge_file}" <<-ENDSED
   1.254 +s/^(WARNINGS=".*)"$/\\1 -pipe"/
   1.255 +ENDSED
   1.256 +        fi
   1.257 +    fi
   1.258 +
   1.259 +    # Force on options needed for C++ if we'll be making a C++ compiler.
   1.260 +    # Note that the two PREGEN_LOCALE and the XLOCALE lines may be missing
   1.261 +    # entirely if LOCALE is not set.  If LOCALE was already set, we'll
   1.262 +    # assume the user has already made all the appropriate generation
   1.263 +    # arrangements.  Note that having the uClibc Makefile download the
   1.264 +    # pregenerated locales is not compatible with crosstool; besides,
   1.265 +    # crosstool downloads them as part of getandpatch.sh.
   1.266 +    if [ "${CT_CC_LANG_CXX}" = "y" ]; then
   1.267 +        cat >>"${munge_file}" <<-ENDSED
   1.268 +s/^# DO_C99_MATH is not set/DO_C99_MATH=y/
   1.269 +s/^# UCLIBC_CTOR_DTOR is not set/UCLIBC_CTOR_DTOR=y/
   1.270 +# Add these three lines when doing C++?
   1.271 +s/^# UCLIBC_HAS_WCHAR is not set/UCLIBC_HAS_WCHAR=y/
   1.272 +#s/^# UCLIBC_HAS_LOCALE is not set/UCLIBC_HAS_LOCALE=y\\nUCLIBC_PREGENERATED_LOCALE_DATA=y\\n\\# UCLIBC_DOWNLOAD_PREGENERATED_LOCALE_DATA is not set\\n\\# UCLIBC_HAS_XLOCALE is not set/
   1.273 +s/^# UCLIBC_HAS_GNU_GETOPT is not set/UCLIBC_HAS_GNU_GETOPT=y/
   1.274 +ENDSED
   1.275 +    fi
   1.276 +
   1.277 +    # Always build the libpthread_db
   1.278 +    cat >>"${munge_file}" <<-ENDSED
   1.279 +s/^# PTHREADS_DEBUG_SUPPORT is not set.*/PTHREADS_DEBUG_SUPPORT=y/
   1.280 +ENDSED
   1.281 +
   1.282 +    # Force on debug options if asked for
   1.283 +    case "${CT_LIBC_UCLIBC_DEBUG_LEVEL}" in
   1.284 +      0)
   1.285 +        cat >>"${munge_file}" <<-ENDSED
   1.286 +s/^DODEBUG=y/# DODEBUG is not set/
   1.287 +s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
   1.288 +s/^DOASSERTS=y/# DOASSERTS is not set/
   1.289 +s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
   1.290 +s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
   1.291 +s/^UCLIBC_MALLOC_DEBUGGING=y/# UCLIBC_MALLOC_DEBUGGING is not set/
   1.292 +ENDSED
   1.293 +        ;;
   1.294 +      1)
   1.295 +        cat >>"${munge_file}" <<-ENDSED
   1.296 +s/^# DODEBUG is not set.*/DODEBUG=y/
   1.297 +s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
   1.298 +s/^DOASSERTS=y/# DOASSERTS is not set/
   1.299 +s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
   1.300 +s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
   1.301 +s/^UCLIBC_MALLOC_DEBUGGING=y/# UCLIBC_MALLOC_DEBUGGING is not set/
   1.302 +ENDSED
   1.303 +        ;;
   1.304 +      2)
   1.305 +        cat >>"${munge_file}" <<-ENDSED
   1.306 +s/^# DODEBUG is not set.*/DODEBUG=y/
   1.307 +s/^# DODEBUG_PT is not set.*/DODEBUG_PT=y/
   1.308 +s/^# DOASSERTS is not set.*/DOASSERTS=y/
   1.309 +s/^# SUPPORT_LD_DEBUG is not set.*/SUPPORT_LD_DEBUG=y/
   1.310 +s/^# SUPPORT_LD_DEBUG_EARLY is not set.*/SUPPORT_LD_DEBUG_EARLY=y/
   1.311 +s/^# UCLIBC_MALLOC_DEBUGGING is not set/UCLIBC_MALLOC_DEBUGGING=y/
   1.312 +ENDSED
   1.313 +        ;;
   1.314 +    esac
   1.315 +    sed -r -f "${munge_file}" "${src_config_file}" >"${dst_config_file}"
   1.316 +}