1 # This file declares functions to install the uClibc C library
2 # Copyright 2007 Yann E. MORIN
3 # Licensed under the GPL v2. See COPYING in the root of this package
7 libc_src="http://www.uclibc.org/downloads
8 http://www.uclibc.org/downloads/snapshots
9 http://www.uclibc.org/downloads/old-releases"
10 # For uClibc, we have almost every thing: releases, and snapshots
11 # for the last month or so. We'll have to deal with svn revisions
13 CT_GetFile "${CT_LIBC_FILE}" ${libc_src}
15 [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ] && CT_GetFile "uClibc-locale-030818" ${libc_src}
20 CT_ExtractAndPatch "${CT_LIBC_FILE}"
22 [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ] && CT_ExtractAndPatch "uClibc-locale-030818"
25 # Check that uClibc has been previously configured
26 do_libc_check_config() {
27 CT_DoStep INFO "Checking C library configuration"
29 CT_TestOrAbort "You did not provide a uClibc config file!" -n "${CT_LIBC_UCLIBC_CONFIG_FILE}" -a -f "${CT_LIBC_UCLIBC_CONFIG_FILE}"
31 cp "${CT_LIBC_UCLIBC_CONFIG_FILE}" "${CT_BUILD_DIR}/uClibc.config"
33 if egrep '^KERNEL_SOURCE=' "${CT_LIBC_UCLIBC_CONFIG_FILE}" >/dev/null 2>&1; then
34 CT_DoLog WARN "Your uClibc version refers to the kernel _sources_, which is bad."
35 CT_DoLog WARN "I can't guarantee that our little hack will work. Please try to upgrade."
38 CT_DoLog EXTRA "Munging uClibc configuration"
39 mungeuClibcConfig "${CT_BUILD_DIR}/uClibc.config"
44 # This functions installs uClibc's headers
46 # Only need to install bootstrap uClibc headers for gcc-3.0 and above? Or maybe just gcc-3.3 and above?
47 # See also http://gcc.gnu.org/PR8180, which complains about the need for this step.
48 grep -q 'gcc-[34]' "${CT_SRC_DIR}/${CT_CC_CORE_FILE}/ChangeLog" || return 0
50 CT_DoStep INFO "Installing C library headers"
52 mkdir -p "${CT_BUILD_DIR}/build-libc-headers"
53 cd "${CT_BUILD_DIR}/build-libc-headers"
55 # Simply copy files until uClibc has the ablity to build out-of-tree
56 CT_DoLog EXTRA "Copying sources to build dir"
57 { cd "${CT_SRC_DIR}/${CT_LIBC_FILE}"; tar cf - .; } |tar xf -
59 # Retrieve the config file
60 cp "${CT_BUILD_DIR}/uClibc.config" .config
62 # uClibc uses the CROSS environment variable as a prefix to the
63 # compiler tools to use. Setting it to the empty string forces
64 # use of the native build host tools, which we need at this
65 # stage, as we don't have target tools yet.
66 CT_DoLog EXTRA "Applying configuration"
67 CT_DoYes "" |make CROSS= PREFIX="${CT_SYSROOT_DIR}/" oldconfig 2>&1 |CT_DoLog DEBUG
69 CT_DoLog EXTRA "Building headers"
70 make ${PARALLELMFLAGS} CROSS= PREFIX="${CT_SYSROOT_DIR}/" headers 2>&1 |CT_DoLog DEBUG
72 CT_DoLog EXTRA "Installing headers"
73 make CROSS= PREFIX="${CT_SYSROOT_DIR}/" install_dev 2>&1 |CT_DoLog DEBUG
78 # This function build and install the full uClibc
80 CT_DoStep INFO "Installing C library"
82 mkdir -p "${CT_BUILD_DIR}/build-libc"
83 cd "${CT_BUILD_DIR}/build-libc"
85 # Simply copy files until uClibc has the ablity to build out-of-tree
86 CT_DoLog EXTRA "Copying sources to build dir"
87 { cd "${CT_SRC_DIR}/${CT_LIBC_FILE}"; tar cf - .; } |tar xf -
89 # Retrieve the config file
90 cp "${CT_BUILD_DIR}/uClibc.config" .config
92 # uClibc uses the CROSS environment variable as a prefix to the compiler
93 # tools to use. The newly built tools should be in our path, so we need
94 # only give the correct name for them.
95 # Note about CFLAGS: In uClibc, CFLAGS are generated by Rules.mak,
96 # depending on the configuration of the library. That is, they are tailored
97 # to best fit the target. So it is useless and seems to be a bad thing to
98 # use LIBC_EXTRA_CFLAGS here.
99 CT_DoLog EXTRA "Applying configuration"
100 CT_DoYes "" |make ${PARALLELMFLAGS} \
101 CROSS=${CT_TARGET}- \
102 PREFIX="${CT_SYSROOT_DIR}/" \
103 oldconfig 2>&1 |CT_DoLog DEBUG
105 # We do _not_ want to strip anything for now, in case we specifically
106 # asked for a debug toolchain, thus the STRIPTOOL= assignment
107 CT_DoLog EXTRA "Building C library"
108 make ${PARALLELMFLAGS} \
109 CROSS=${CT_TARGET}- \
110 PREFIX="${CT_SYSROOT_DIR}/" \
112 all 2>&1 |CT_DoLog DEBUG
114 # YEM-FIXME: we want to install libraries in $SYSROOT/lib, but we don't want
115 # to install headers in $SYSROOT/include, thus making only install_runtime.
116 # Plus, the headers were previously installed earlier with install_dev, so
117 # all should be well. Unfortunately, the install_dev target does not install
118 # crti.o and consorts... :-( So reverting to target 'install'.
119 # Note: PARALLELMFLAGS is not usefull for installation.
120 # We do _not_ want to strip anything for now, in case we specifically
121 # asked for a debug toolchain, thus the STRIPTOOL= assignment
122 CT_DoLog EXTRA "Installing C library"
123 make CROSS=${CT_TARGET}- \
124 PREFIX="${CT_SYSROOT_DIR}/" \
126 install 2>&1 |CT_DoLog DEBUG
131 # This function is used to install those components needing the final C compiler
133 CT_DoStep INFO "Finishing C library"
134 # uClibc has nothing to finish
135 CT_DoLog EXTRA "uClibc has nothing to finish"
139 # Initialises the .config file to sensible values
140 mungeuClibcConfig() {
142 munge_file="${CT_BUILD_DIR}/munge-uClibc-config.sed"
144 cat > "${munge_file}" <<-ENDSED
145 s/^(TARGET_.*)=y$/# \\1 is not set/
146 s/^# TARGET_${CT_KERNEL_ARCH} is not set/TARGET_${CT_KERNEL_ARCH}=y/
147 s/^TARGET_ARCH=".*"/TARGET_ARCH="${CT_KERNEL_ARCH}"/
150 case "${CT_ARCH_BE},${CT_ARCH_LE}" in
151 y,) cat >> "${munge_file}" <<-ENDSED
152 s/.*(ARCH_BIG_ENDIAN).*/\\1=y/
153 s/.*(ARCH_LITTLE_ENDIAN).*/# \\1 is not set/
156 ,y) cat >> "${munge_file}" <<-ENDSED
157 s/.*(ARCH_BIG_ENDIAN).*/# \\1 is not set/
158 s/.*(ARCH_LITTLE_ENDIAN).*/\\1=y/
163 case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
164 y,) cat >> "${munge_file}" <<-ENDSED
165 s/.*(HAS_FPU).*/\\1=y/
168 ,y) cat >> "${munge_file}" <<-ENDSED
169 s/.*(HAS_FPU).*/\\# \\1 is not set/
174 # Change paths to work with crosstool
175 # From http://www.uclibc.org/cgi-bin/viewcvs.cgi?rev=16846&view=rev
176 # " we just want the kernel headers, not the whole kernel source ...
177 # " so people may need to update their paths slightly
178 quoted_kernel_source=`echo "${CT_HEADERS_DIR}" | sed -r -e 's,/include/?$,,; s,/,\\\\/,g;'`
179 quoted_headers_dir=`echo ${CT_HEADERS_DIR} | sed -r -e 's,/,\\\\/,g;'`
180 # CROSS_COMPILER_PREFIX is left as is, as the CROSS parameter is forced on the command line
181 # DEVEL_PREFIX is left as '/usr/' because it is post-pended to $PREFIX, wich is the correct value of ${PREFIX}/${TARGET}
182 # Some (old) versions of uClibc use KERNEL_SOURCE (which is _wrong_), and
183 # newer versions use KERNEL_HEADERS (which is right). See:
184 cat >> "${munge_file}" <<-ENDSED
185 s/^DEVEL_PREFIX=".*"/DEVEL_PREFIX="\\/usr\\/"/
186 s/^RUNTIME_PREFIX=".*"/RUNTIME_PREFIX="\\/"/
187 s/^SHARED_LIB_LOADER_PREFIX=.*/SHARED_LIB_LOADER_PREFIX="\\/lib\\/"/
188 s/^KERNEL_SOURCE=".*"/KERNEL_SOURCE="${quoted_kernel_source}"/
189 s/^KERNEL_HEADERS=".*"/KERNEL_HEADERS="${quoted_headers_dir}"/
190 s/^UCLIBC_DOWNLOAD_PREGENERATED_LOCALE=y/\\# UCLIBC_DOWNLOAD_PREGENERATED_LOCALE is not set/
193 # Hack our -pipe into WARNINGS, which will be internally incorporated to
194 # CFLAGS. This a dirty hack, but yet needed
195 if [ "${CT_USE_PIPES}" = "y" ]; then
196 cat >> "${munge_file}" <<-ENDSED
197 s/^(WARNINGS=".*)"$/\\1 -pipe"/
201 # Force on options needed for C++ if we'll be making a C++ compiler.
202 # Note that the two PREGEN_LOCALE and the XLOCALE lines may be missing
203 # entirely if LOCALE is not set. If LOCALE was already set, we'll
204 # assume the user has already made all the appropriate generation
205 # arrangements. Note that having the uClibc Makefile download the
206 # pregenerated locales is not compatible with crosstool; besides,
207 # crosstool downloads them as part of getandpatch.sh.
208 if [ "${CT_CC_LANG_CXX}" = "y" ]; then
209 cat >> "${munge_file}" <<-ENDSED
210 s/^# DO_C99_MATH is not set/DO_C99_MATH=y/
211 s/^# UCLIBC_CTOR_DTOR is not set/UCLIBC_CTOR_DTOR=y/
212 # Add these three lines when doing C++?
213 #s/^# UCLIBC_HAS_WCHAR is not set/UCLIBC_HAS_WCHAR=y/
214 #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/
215 #s/^# UCLIBC_HAS_GNU_GETOPT is not set/UCLIBC_HAS_GNU_GETOPT=y/
219 # Force on debug options if asked for
220 case "${CT_LIBC_UCLIBC_DEBUG_LEVEL}" in
222 cat >>"${munge_file}" <<-ENDSED
223 s/^PTHREADS_DEBUG_SUPPORT=y/# PTHREADS_DEBUG_SUPPORT is not set/
224 s/^DODEBUG=y/# DODEBUG is not set/
225 s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
226 s/^DOASSERTS=y/# DOASSERTS is not set/
227 s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
228 s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
232 cat >>"${munge_file}" <<-ENDSED
233 s/^# PTHREADS_DEBUG_SUPPORT is not set.*/PTHREADS_DEBUG_SUPPORT=y/
234 s/^# DODEBUG is not set.*/DODEBUG=y/
235 s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
236 s/^DOASSERTS=y/# DOASSERTS is not set/
237 s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
238 s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
242 cat >>"${munge_file}" <<-ENDSED
243 s/^# PTHREADS_DEBUG_SUPPORT is not set.*/PTHREADS_DEBUG_SUPPORT=y/
244 s/^# DODEBUG is not set.*/DODEBUG=y/
245 s/^# DODEBUG_PT is not set.*/DODEBUG_PT=y/
246 s/^# DOASSERTS is not set.*/DOASSERTS=y/
247 s/^# SUPPORT_LD_DEBUG is not set.*/SUPPORT_LD_DEBUG=y/
248 s/^# SUPPORT_LD_DEBUG_EARLY is not set.*/SUPPORT_LD_DEBUG_EARLY=y/
252 sed -r -i -f "${munge_file}" "${config_file}"
253 rm -f "${munge_file}"