1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/scripts/build/libc_uClibc.sh Sun May 06 11:55:09 2007 +0000
1.3 @@ -0,0 +1,235 @@
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 +
1.9 +# Check that uClibc has been previously configured
1.10 +do_libc_check_config() {
1.11 + CT_DoStep INFO "Checking C library configuration"
1.12 +
1.13 + CT_TestOrAbort "You did not provide a uClibc config file!" -n "${CT_LIBC_UCLIBC_CONFIG_FILE}" -a -f "${CT_LIBC_UCLIBC_CONFIG_FILE}"
1.14 +
1.15 + cp "${CT_LIBC_UCLIBC_CONFIG_FILE}" "${CT_BUILD_DIR}/uClibc.config"
1.16 +
1.17 + if egrep '^KERNEL_SOURCE=' "${CT_LIBC_UCLIBC_CONFIG_FILE}" >/dev/null 2>&1; then
1.18 + CT_DoLog WARN "Your uClibc version refers to the kernel _sources_, which is bad."
1.19 + CT_DoLog WARN "I can't guarantee that our little hack will work. Please try to upgrade."
1.20 + fi
1.21 +
1.22 + CT_DoLog EXTRA "Munging uClibc configuration"
1.23 + mungeuClibcConfig "${CT_BUILD_DIR}/uClibc.config"
1.24 +
1.25 + CT_EndStep
1.26 +}
1.27 +
1.28 +# This functions installs uClibc's headers
1.29 +do_libc_headers() {
1.30 + # Only need to install bootstrap uClibc headers for gcc-3.0 and above? Or maybe just gcc-3.3 and above?
1.31 + # See also http://gcc.gnu.org/PR8180, which complains about the need for this step.
1.32 + grep -q 'gcc-[34]' "${CT_SRC_DIR}/${CT_CC_CORE_FILE}/ChangeLog" || return 0
1.33 +
1.34 + CT_DoStep INFO "Installing C library headers"
1.35 +
1.36 + mkdir -p "${CT_BUILD_DIR}/build-libc-headers"
1.37 + cd "${CT_BUILD_DIR}/build-libc-headers"
1.38 +
1.39 + # Simply copy files until uClibc has the ablity to build out-of-tree
1.40 + CT_DoLog EXTRA "Copying sources to build dir"
1.41 + { cd "${CT_SRC_DIR}/${CT_LIBC_FILE}"; tar cf - .; } |tar xf -
1.42 +
1.43 + # Retrieve the config file
1.44 + cp "${CT_BUILD_DIR}/uClibc.config" .config
1.45 +
1.46 + # uClibc uses the CROSS environment variable as a prefix to the
1.47 + # compiler tools to use. Setting it to the empty string forces
1.48 + # use of the native build host tools, which we need at this
1.49 + # stage, as we don't have target tools yet.
1.50 + CT_DoLog EXTRA "Applying configuration"
1.51 + CT_DoYes "" |make CROSS= PREFIX="${CT_SYSROOT_DIR}/" oldconfig 2>&1 |CT_DoLog DEBUG
1.52 +
1.53 + CT_DoLog EXTRA "Building headers"
1.54 + make ${PARALLELMFLAGS} CROSS= PREFIX="${CT_SYSROOT_DIR}/" headers 2>&1 |CT_DoLog DEBUG
1.55 +
1.56 + CT_DoLog EXTRA "Installing headers"
1.57 + make CROSS= PREFIX="${CT_SYSROOT_DIR}/" install_dev 2>&1 |CT_DoLog DEBUG
1.58 +
1.59 + CT_EndStep
1.60 +}
1.61 +
1.62 +# This function build and install the full uClibc
1.63 +do_libc() {
1.64 + CT_DoStep INFO "Installing C library"
1.65 +
1.66 + mkdir -p "${CT_BUILD_DIR}/build-libc"
1.67 + cd "${CT_BUILD_DIR}/build-libc"
1.68 +
1.69 + # Simply copy files until uClibc has the ablity to build out-of-tree
1.70 + CT_DoLog EXTRA "Copying sources to build dir"
1.71 + { cd "${CT_SRC_DIR}/${CT_LIBC_FILE}"; tar cf - .; } |tar xf -
1.72 +
1.73 + # Retrieve the config file
1.74 + cp "${CT_BUILD_DIR}/uClibc.config" .config
1.75 +
1.76 + # uClibc uses the CROSS environment variable as a prefix to the compiler
1.77 + # tools to use. The newly built tools should be in our path, so we need
1.78 + # only give the correct name for them.
1.79 + # Note about CFLAGS: In uClibc, CFLAGS are generated by Rules.mak,
1.80 + # depending on the configuration of the library. That is, they are tailored
1.81 + # to best fit the target. So it is useless and seems to be a bad thing to
1.82 + # use LIBC_EXTRA_CFLAGS here.
1.83 + CT_DoLog EXTRA "Applying configuration"
1.84 + CT_DoYes "" |make ${PARALLELMFLAGS} \
1.85 + CROSS=${CT_TARGET}- \
1.86 + PREFIX="${CT_SYSROOT_DIR}/" \
1.87 + oldconfig 2>&1 |CT_DoLog DEBUG
1.88 +
1.89 + # We do _not_ want to strip anything for now, in case we specifically
1.90 + # asked for a debug toolchain, thus the STRIPTOOL= assignment
1.91 + CT_DoLog EXTRA "Building C library"
1.92 + make ${PARALLELMFLAGS} \
1.93 + CROSS=${CT_TARGET}- \
1.94 + PREFIX="${CT_SYSROOT_DIR}/" \
1.95 + STRIPTOOL=true \
1.96 + all 2>&1 |CT_DoLog DEBUG
1.97 +
1.98 + # YEM-FIXME: we want to install libraries in $SYSROOT/lib, but we don't want
1.99 + # to install headers in $SYSROOT/include, thus making only install_runtime.
1.100 + # Plus, the headers were previously installed earlier with install_dev, so
1.101 + # all should be well. Unfortunately, the install_dev target does not install
1.102 + # crti.o and consorts... :-( So reverting to target 'install'.
1.103 + # Note: PARALLELMFLAGS is not usefull for installation.
1.104 + # We do _not_ want to strip anything for now, in case we specifically
1.105 + # asked for a debug toolchain, thus the STRIPTOOL= assignment
1.106 + CT_DoLog EXTRA "Installing C library"
1.107 + make CROSS=${CT_TARGET}- \
1.108 + PREFIX="${CT_SYSROOT_DIR}/" \
1.109 + STRIPTOOL=true \
1.110 + install 2>&1 |CT_DoLog DEBUG
1.111 +
1.112 + CT_EndStep
1.113 +}
1.114 +
1.115 +# This function is used to install those components needing the final C compiler
1.116 +do_libc_finish() {
1.117 + CT_DoStep INFO "Finishing C library"
1.118 + # uClibc has nothing to finish
1.119 + CT_DoLog EXTRA "uClibc has nothing to finish"
1.120 + CT_EndStep
1.121 +}
1.122 +
1.123 +# Initialises the .config file to sensible values
1.124 +mungeuClibcConfig() {
1.125 + config_file="$1"
1.126 + munge_file="${CT_BUILD_DIR}/munge-uClibc-config.sed"
1.127 +
1.128 + cat > "${munge_file}" <<-ENDSED
1.129 +s/^(TARGET_.*)=y$/# \\1 is not set/
1.130 +s/^# TARGET_${CT_KERNEL_ARCH} is not set/TARGET_${CT_KERNEL_ARCH}=y/
1.131 +s/^TARGET_ARCH=".*"/TARGET_ARCH="${CT_KERNEL_ARCH}"/
1.132 +ENDSED
1.133 +
1.134 + case "${CT_ARCH_BE},${CT_ARCH_LE}" in
1.135 + y,) cat >> "${munge_file}" <<-ENDSED
1.136 +s/.*(ARCH_BIG_ENDIAN).*/\\1=y/
1.137 +s/.*(ARCH_LITTLE_ENDIAN).*/# \\1 is not set/
1.138 +ENDSED
1.139 + ;;
1.140 + ,y) cat >> "${munge_file}" <<-ENDSED
1.141 +s/.*(ARCH_BIG_ENDIAN).*/# \\1 is not set/
1.142 +s/.*(ARCH_LITTLE_ENDIAN).*/\\1=y/
1.143 +ENDSED
1.144 + ;;
1.145 + esac
1.146 +
1.147 + case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
1.148 + y,) cat >> "${munge_file}" <<-ENDSED
1.149 +s/.*(HAS_FPU).*/\\1=y/
1.150 +ENDSED
1.151 + ;;
1.152 + ,y) cat >> "${munge_file}" <<-ENDSED
1.153 +s/.*(HAS_FPU).*/\\# \\1 is not set/
1.154 +ENDSED
1.155 + ;;
1.156 + esac
1.157 +
1.158 + # Change paths to work with crosstool
1.159 + # From http://www.uclibc.org/cgi-bin/viewcvs.cgi?rev=16846&view=rev
1.160 + # " we just want the kernel headers, not the whole kernel source ...
1.161 + # " so people may need to update their paths slightly
1.162 + quoted_kernel_source=`echo "${CT_HEADERS_DIR}" | sed -r -e 's,/include/?$,,; s,/,\\\\/,g;'`
1.163 + quoted_headers_dir=`echo ${CT_HEADERS_DIR} | sed -r -e 's,/,\\\\/,g;'`
1.164 + # CROSS_COMPILER_PREFIX is left as is, as the CROSS parameter is forced on the command line
1.165 + # DEVEL_PREFIX is left as '/usr/' because it is post-pended to $PREFIX, wich is the correct value of ${PREFIX}/${TARGET}
1.166 + # Some (old) versions of uClibc use KERNEL_SOURCE (which is _wrong_), and
1.167 + # newer versions use KERNEL_HEADERS (which is right). See:
1.168 + cat >> "${munge_file}" <<-ENDSED
1.169 +s/^DEVEL_PREFIX=".*"/DEVEL_PREFIX="\\/usr\\/"/
1.170 +s/^RUNTIME_PREFIX=".*"/RUNTIME_PREFIX="\\/"/
1.171 +s/^SHARED_LIB_LOADER_PREFIX=.*/SHARED_LIB_LOADER_PREFIX="\\/lib\\/"/
1.172 +s/^KERNEL_SOURCE=".*"/KERNEL_SOURCE="${quoted_kernel_source}"/
1.173 +s/^KERNEL_HEADERS=".*"/KERNEL_HEADERS="${quoted_headers_dir}"/
1.174 +s/^UCLIBC_DOWNLOAD_PREGENERATED_LOCALE=y/\\# UCLIBC_DOWNLOAD_PREGENERATED_LOCALE is not set/
1.175 +ENDSED
1.176 +
1.177 + # Hack our -pipe into WARNINGS, which will be internally incorporated to
1.178 + # CFLAGS. This a dirty hack, but yet needed
1.179 + if [ "${CT_USE_PIPES}" = "y" ]; then
1.180 + cat >> "${munge_file}" <<-ENDSED
1.181 +s/^(WARNINGS=".*)"$/\\1 -pipe"/
1.182 +ENDSED
1.183 + fi
1.184 +
1.185 + # Force on options needed for C++ if we'll be making a C++ compiler.
1.186 + # Note that the two PREGEN_LOCALE and the XLOCALE lines may be missing
1.187 + # entirely if LOCALE is not set. If LOCALE was already set, we'll
1.188 + # assume the user has already made all the appropriate generation
1.189 + # arrangements. Note that having the uClibc Makefile download the
1.190 + # pregenerated locales is not compatible with crosstool; besides,
1.191 + # crosstool downloads them as part of getandpatch.sh.
1.192 + if [ "${CT_CC_LANG_CXX}" = "y" ]; then
1.193 + cat >> "${munge_file}" <<-ENDSED
1.194 +s/^# DO_C99_MATH is not set/DO_C99_MATH=y/
1.195 +s/^# UCLIBC_CTOR_DTOR is not set/UCLIBC_CTOR_DTOR=y/
1.196 +# Add these three lines when doing C++?
1.197 +#s/^# UCLIBC_HAS_WCHAR is not set/UCLIBC_HAS_WCHAR=y/
1.198 +#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.199 +#s/^# UCLIBC_HAS_GNU_GETOPT is not set/UCLIBC_HAS_GNU_GETOPT=y/
1.200 +ENDSED
1.201 + fi
1.202 +
1.203 + # Force on debug options if asked for
1.204 + case "${CT_LIBC_UCLIBC_DEBUG_LEVEL}" in
1.205 + 0)
1.206 + cat >>"${munge_file}" <<-ENDSED
1.207 +s/^PTHREADS_DEBUG_SUPPORT=y/# PTHREADS_DEBUG_SUPPORT is not set/
1.208 +s/^DODEBUG=y/# DODEBUG is not set/
1.209 +s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
1.210 +s/^DOASSERTS=y/# DOASSERTS is not set/
1.211 +s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
1.212 +s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
1.213 +ENDSED
1.214 + ;;
1.215 + 1)
1.216 + cat >>"${munge_file}" <<-ENDSED
1.217 +s/^# PTHREADS_DEBUG_SUPPORT is not set.*/PTHREADS_DEBUG_SUPPORT=y/
1.218 +s/^# DODEBUG is not set.*/DODEBUG=y/
1.219 +s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
1.220 +s/^DOASSERTS=y/# DOASSERTS is not set/
1.221 +s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
1.222 +s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
1.223 +ENDSED
1.224 + ;;
1.225 + 2)
1.226 + cat >>"${munge_file}" <<-ENDSED
1.227 +s/^# PTHREADS_DEBUG_SUPPORT is not set.*/PTHREADS_DEBUG_SUPPORT=y/
1.228 +s/^# DODEBUG is not set.*/DODEBUG=y/
1.229 +s/^# DODEBUG_PT is not set.*/DODEBUG_PT=y/
1.230 +s/^# DOASSERTS is not set.*/DOASSERTS=y/
1.231 +s/^# SUPPORT_LD_DEBUG is not set.*/SUPPORT_LD_DEBUG=y/
1.232 +s/^# SUPPORT_LD_DEBUG_EARLY is not set.*/SUPPORT_LD_DEBUG_EARLY=y/
1.233 +ENDSED
1.234 + ;;
1.235 + esac
1.236 + sed -r -i -f "${munge_file}" "${config_file}"
1.237 + rm -f "${munge_file}"
1.238 +}