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
5 # This is a constant because it does not change very often.
6 # We're in 2010, and are still using data from 7 years ago.
7 uclibc_locales_version=030818
8 uclibc_local_tarball="uClibc-locale-${uclibc_locales_version}"
12 libc_src="http://www.uclibc.org/downloads
13 http://www.uclibc.org/downloads/old-releases"
14 if [ "${CT_LIBC_UCLIBC_CUSTOM}" = "y" ]; then
15 CT_GetCustom "uClibc" "${CT_LIBC_VERSION}" \
16 "${CT_LIBC_UCLIBC_CUSTOM_LOCATION}"
18 CT_GetFile "uClibc-${CT_LIBC_VERSION}" ${libc_src}
21 if [ "${CT_LIBC_UCLIBC_LOCALES_PREGEN_DATA}" = "y" ]; then
22 CT_GetFile "${uclibc_local_tarball}" ${libc_src}
30 # If not using custom directory location, extract and patch
31 # Note: we do the inverse test we do in other components,
32 # because here we still need to extract the locales, even for
33 # custom location directory. Just use negate the whole test,
34 # to keep it the same as for other components.
35 if ! [ "${CT_LIBC_UCLIBC_CUSTOM}" = "y" \
36 -a -d "${CT_SRC_DIR}/uClibc-${CT_LIBC_VERSION}" ]; then
37 CT_Extract "uClibc-${CT_LIBC_VERSION}"
38 CT_Patch "uClibc" "${CT_LIBC_VERSION}"
42 # Extracting pregen locales ourselves is kinda
43 # broken, so just link it in place...
44 if [ "${CT_LIBC_UCLIBC_LOCALES_PREGEN_DATA}" = "y" \
45 -a ! -f "${CT_SRC_DIR}/.${uclibc_local_tarball}.extracted" ]; then
46 CT_Pushd "${CT_SRC_DIR}/uClibc-${CT_LIBC_VERSION}/extra/locale"
47 CT_DoExecLog ALL ln -s "${CT_TARBALLS_DIR}/${uclibc_local_tarball}.tgz" .
49 touch "${CT_SRC_DIR}/.${uclibc_local_tarball}.extracted"
55 # Check that uClibc has been previously configured
56 do_libc_check_config() {
57 CT_DoStep INFO "Checking C library configuration"
59 CT_TestOrAbort "You did not provide a uClibc config file!" -n "${CT_LIBC_UCLIBC_CONFIG_FILE}" -a -f "${CT_LIBC_UCLIBC_CONFIG_FILE}"
61 if grep -E '^KERNEL_SOURCE=' "${CT_LIBC_UCLIBC_CONFIG_FILE}" >/dev/null 2>&1; then
62 CT_DoLog WARN "Your uClibc version refers to the kernel _sources_, which is bad."
63 CT_DoLog WARN "I can't guarantee that our little hack will work. Please try to upgrade."
66 CT_DoLog EXTRA "Munging uClibc configuration"
67 mungeuClibcConfig "${CT_LIBC_UCLIBC_CONFIG_FILE}" "${CT_CONFIG_DIR}/uClibc.config"
72 # Build and install headers and start files
73 do_libc_start_files() {
77 CT_DoStep INFO "Installing C library headers"
79 # Simply copy files until uClibc has the ability to build out-of-tree
80 CT_DoLog EXTRA "Copying sources to build dir"
81 CT_DoExecLog ALL cp -av "${CT_SRC_DIR}/uClibc-${CT_LIBC_VERSION}" \
82 "${CT_BUILD_DIR}/build-libc-headers"
83 cd "${CT_BUILD_DIR}/build-libc-headers"
85 # Retrieve the config file
86 CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/uClibc.config" .config
88 # uClibc uses the CROSS environment variable as a prefix to the
89 # compiler tools to use. Setting it to the empty string forces
90 # use of the native build host tools, which we need at this
91 # stage, as we don't have target tools yet.
92 # BUT! With NPTL, we need a cross-compiler (and we have it)
93 if [ "${CT_THREADS}" = "nptl" ]; then
97 # Force the date of the pregen locale data, as the
98 # newer ones that are referenced are not available
99 CT_DoLog EXTRA "Applying configuration"
100 CT_DoYes "" |CT_DoExecLog ALL \
101 make CROSS="${cross}" \
102 PREFIX="${CT_SYSROOT_DIR}/" \
103 LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \
106 CT_DoLog EXTRA "Building headers"
108 make ${CT_LIBC_UCLIBC_VERBOSITY} \
110 PREFIX="${CT_SYSROOT_DIR}/" \
111 LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \
114 if [ "${CT_LIBC_UCLIBC_0_9_30_or_later}" = "y" ]; then
115 install_rule=install_headers
117 install_rule=install_dev
120 CT_DoLog EXTRA "Installing headers"
122 make ${CT_LIBC_UCLIBC_VERBOSITY} \
124 PREFIX="${CT_SYSROOT_DIR}/" \
125 LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \
128 if [ "${CT_THREADS}" = "nptl" ]; then
129 CT_DoLog EXTRA "Building start files"
131 make ${CT_LIBC_UCLIBC_PARALLEL:+${JOBSFLAGS}} \
133 PREFIX="${CT_SYSROOT_DIR}/" \
135 ${CT_LIBC_UCLIBC_VERBOSITY} \
136 LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \
137 lib/crt1.o lib/crti.o lib/crtn.o
139 # From: http://git.openembedded.org/cgit.cgi/openembedded/commit/?id=ad5668a7ac7e0436db92e55caaf3fdf782b6ba3b
140 # libm.so is needed for ppc, as libgcc is linked against libm.so
141 # No problem to create it for other archs.
142 CT_DoLog EXTRA "Building dummy shared libs"
143 CT_DoExecLog ALL "${cross}gcc" -nostdlib \
149 CT_DoLog EXTRA "Installing start files"
150 CT_DoExecLog ALL install -m 0644 lib/crt1.o lib/crti.o lib/crtn.o \
151 "${CT_SYSROOT_DIR}/usr/lib"
153 CT_DoLog EXTRA "Installing dummy shared libs"
154 CT_DoExecLog ALL install -m 0755 libdummy.so "${CT_SYSROOT_DIR}/usr/lib/libc.so"
155 CT_DoExecLog ALL install -m 0755 libdummy.so "${CT_SYSROOT_DIR}/usr/lib/libm.so"
156 fi # CT_THREADS == nptl
161 # This function build and install the full uClibc
163 CT_DoStep INFO "Installing C library"
165 # Simply copy files until uClibc has the ability to build out-of-tree
166 CT_DoLog EXTRA "Copying sources to build dir"
167 CT_DoExecLog ALL cp -av "${CT_SRC_DIR}/uClibc-${CT_LIBC_VERSION}" \
168 "${CT_BUILD_DIR}/build-libc"
169 cd "${CT_BUILD_DIR}/build-libc"
171 # Retrieve the config file
172 CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/uClibc.config" .config
174 # uClibc uses the CROSS environment variable as a prefix to the compiler
175 # tools to use. The newly built tools should be in our path, so we need
176 # only give the correct name for them.
177 # Note about CFLAGS: In uClibc, CFLAGS are generated by Rules.mak,
178 # depending on the configuration of the library. That is, they are tailored
179 # to best fit the target. So it is useless and seems to be a bad thing to
180 # use LIBC_EXTRA_CFLAGS here.
181 CT_DoLog EXTRA "Applying configuration"
182 CT_DoYes "" |CT_DoExecLog CFG \
183 make CROSS=${CT_TARGET}- \
184 PREFIX="${CT_SYSROOT_DIR}/" \
185 LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \
188 # We do _not_ want to strip anything for now, in case we specifically
189 # asked for a debug toolchain, thus the STRIPTOOL= assignment
190 # /Old/ versions can not build in //
191 CT_DoLog EXTRA "Building C library"
194 CROSS=${CT_TARGET}- \
195 PREFIX="${CT_SYSROOT_DIR}/" \
197 ${CT_LIBC_UCLIBC_VERBOSITY} \
198 LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \
201 make ${CT_LIBC_UCLIBC_PARALLEL:+${JOBSFLAGS}} \
202 CROSS=${CT_TARGET}- \
203 PREFIX="${CT_SYSROOT_DIR}/" \
205 ${CT_LIBC_UCLIBC_VERBOSITY} \
206 LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \
210 # - we want to install 'runtime' files, eg. lib*.{a,so*}, crti.o and
211 # such files, except the headers as they already are installed
212 # - "make install_dev" installs the headers, the crti.o... and the
213 # static libs, but not the dynamic libs
214 # - "make install_runtime" installs the dynamic libs only
215 # - "make install" calls install_runtime and install_dev
216 # - so we're left with re-installing the headers... Sigh...
218 # We do _not_ want to strip anything for now, in case we specifically
219 # asked for a debug toolchain, hence the STRIPTOOL= assignment
221 # Note: JOBSFLAGS is not usefull for installation.
223 CT_DoLog EXTRA "Installing C library"
225 make CROSS=${CT_TARGET}- \
226 PREFIX="${CT_SYSROOT_DIR}/" \
228 ${CT_LIBC_UCLIBC_VERBOSITY} \
229 LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \
235 # This function is used to install those components needing the final C compiler
240 # Initialises the .config file to sensible values
243 mungeuClibcConfig() {
246 munge_file="${CT_BUILD_DIR}/munge-uClibc-config.sed"
248 # Start with a fresh file
249 rm -f "${munge_file}"
250 touch "${munge_file}"
252 # Do it all in a sub-shell, it's easier to redirect output
255 # Hack our target in the config file.
256 case "${CT_ARCH}:${CT_ARCH_BITNESS}" in
258 x86:64) arch=x86_64;;
261 blackfin:32) arch="bfin";;
262 *) arch="${CT_ARCH}";;
264 # Also remove stripping: its the responsibility of the
265 # firmware builder to strip or not.
267 s/^(TARGET_.*)=y$/# \\1 is not set/
268 s/^# TARGET_${arch} is not set/TARGET_${arch}=y/
269 s/^TARGET_ARCH=".*"/TARGET_ARCH="${arch}"/
270 s/.*(DOSTRIP).*/# \\1 is not set/
273 # Ah. We may one day need architecture-specific handler here...
276 # Hack the ARM {E,O}ABI into the config file
277 if [ "${CT_ARCH_ARM_EABI}" = "y" ]; then
279 s/.*(CONFIG_ARM_OABI).*/# \\1 is not set/
280 s/.*(CONFIG_ARM_EABI).*/\\1=y/
284 s/.*(CONFIG_ARM_OABI).*/\\1=y/
285 s/.*(CONFIG_ARM_EABI).*/# \\1 is not set/
290 case "${CT_ARCH_mips_ABI}" in
293 s/.*(CONFIG_MIPS_O32_ABI).*/\\1=y/
294 s/.*(CONFIG_MIPS_N32_ABI).*/# \\1 is not set/
295 s/.*(CONFIG_MIPS_N64_ABI).*/# \\1 is not set/
298 # For n32 and n64, also force the ISA
299 # Not so sure this is pertinent, so it's
300 # commented out for now. It would take a
301 # (MIPS+uClibc) expert to either remove
302 # or re-enable the overrides.
305 s/.*(CONFIG_MIPS_O32_ABI).*/# \\1 is not set/
306 s/.*(CONFIG_MIPS_N32_ABI).*/\\1=y/
307 s/.*(CONFIG_MIPS_N64_ABI).*/# \\1 is not set/
308 s/.*(CONFIG_MIPS_ISA_.*).*/# \\1 is not set/
309 s/.*(CONFIG_MIPS_ISA_3).*/\\1=y/
314 s/.*(CONFIG_MIPS_O32_ABI).*/# \\1 is not set/
315 s/.*(CONFIG_MIPS_N32_ABI).*/# \\1 is not set/
316 s/.*(CONFIG_MIPS_N64_ABI).*/\\1=y/
317 s/.*(CONFIG_MIPS_ISA_.*).*/# \\1 is not set/
318 s/.*(CONFIG_MIPS_ISA_MIPS64).*/\\1=y/
325 # Accomodate for old and new uClibc versions, where the
326 # way to select between big/little endian has changed
327 case "${CT_ARCH_ENDIAN}" in
330 s/.*(ARCH_LITTLE_ENDIAN).*/# \\1 is not set/
331 s/.*(ARCH_BIG_ENDIAN).*/\\1=y/
332 s/.*(ARCH_WANTS_LITTLE_ENDIAN).*/# \\1 is not set/
333 s/.*(ARCH_WANTS_BIG_ENDIAN).*/\\1=y/
338 s/.*(ARCH_LITTLE_ENDIAN).*/\\1=y/
339 s/.*(ARCH_BIG_ENDIAN).*/# \\1 is not set/
340 s/.*(ARCH_WANTS_LITTLE_ENDIAN).*/\\1=y/
341 s/.*(ARCH_WANTS_BIG_ENDIAN).*/# \\1 is not set/
346 # Accomodate for old and new uClibc versions, where the
347 # MMU settings has different config knobs
348 if [ "${CT_ARCH_USE_MMU}" = "y" ]; then
350 s/.*(ARCH_HAS_MMU).*/\\1=y\nARCH_USE_MMU=y/
354 s/.*(ARCH_HAS_MMU).*/# \\1 is not set/
355 /.*(ARCH_USE_MMU).*/d
359 # Accomodate for old and new uClibc version, where the
360 # way to select between hard/soft float has changed
361 case "${CT_ARCH_FLOAT}" in
364 s/^[^_]*(HAS_FPU).*/\\1=y/
365 s/.*(UCLIBC_HAS_FPU).*/\\1=y/
370 s/^[^_]*(HAS_FPU).*/\\# \\1 is not set/
371 s/.*(UCLIBC_HAS_FPU).*/# \\1 is not set/
376 # We always want ctor/dtor
378 s/^# (UCLIBC_CTOR_DTOR) is not set/\\1=y/
381 # Change paths to work with crosstool-NG
382 # From http://www.uclibc.org/cgi-bin/viewcvs.cgi?rev=16846&view=rev
383 # " we just want the kernel headers, not the whole kernel source ...
384 # " so people may need to update their paths slightly
385 quoted_kernel_source=$(echo "${CT_HEADERS_DIR}" | sed -r -e 's,/include/?$,,; s,/,\\/,g;')
386 quoted_headers_dir=$(echo "${CT_HEADERS_DIR}" | sed -r -e 's,/,\\/,g;')
387 # CROSS_COMPILER_PREFIX is left as is, as the CROSS parameter is forced on the command line
388 # DEVEL_PREFIX is left as '/usr/' because it is post-pended to $PREFIX, wich is the correct value of ${PREFIX}/${TARGET}
389 # Some (old) versions of uClibc use KERNEL_SOURCE (which is _wrong_), and
390 # newer versions use KERNEL_HEADERS (which is right).
392 s/^DEVEL_PREFIX=".*"/DEVEL_PREFIX="\\/usr\\/"/
393 s/^RUNTIME_PREFIX=".*"/RUNTIME_PREFIX="\\/"/
394 s/^SHARED_LIB_LOADER_PREFIX=.*/SHARED_LIB_LOADER_PREFIX="\\/lib\\/"/
395 s/^KERNEL_SOURCE=".*"/KERNEL_SOURCE="${quoted_kernel_source}"/
396 s/^KERNEL_HEADERS=".*"/KERNEL_HEADERS="${quoted_headers_dir}"/
397 s/^UCLIBC_DOWNLOAD_PREGENERATED_LOCALE=y/\\# UCLIBC_DOWNLOAD_PREGENERATED_LOCALE is not set/
400 if [ "${CT_USE_PIPES}" = "y" ]; then
401 if grep UCLIBC_EXTRA_CFLAGS extra/Configs/Config.in >/dev/null 2>&1; then
402 # Good, there is special provision for such things as -pipe!
404 s/^(UCLIBC_EXTRA_CFLAGS=".*)"$/\\1 -pipe"/
407 # Hack our -pipe into WARNINGS, which will be internally incorporated to
408 # CFLAGS. This a dirty hack, but yet needed
410 s/^(WARNINGS=".*)"$/\\1 -pipe"/
416 # Note that the two PREGEN_LOCALE and the XLOCALE lines may be missing
417 # entirely if LOCALE is not set. If LOCALE was already set, we'll
418 # assume the user has already made all the appropriate generation
419 # arrangements. Note that having the uClibc Makefile download the
420 # pregenerated locales is not compatible with crosstool; besides,
421 # crosstool downloads them as part of getandpatch.sh.
422 case "${CT_LIBC_UCLIBC_LOCALES}:${CT_LIBC_UCLIBC_LOCALES_PREGEN_DATA}" in
427 s/^# UCLIBC_HAS_LOCALE is not set/UCLIBC_HAS_LOCALE=y\\
428 # UCLIBC_PREGENERATED_LOCALE_DATA is not set\\
429 # UCLIBC_DOWNLOAD_PREGENERATED_LOCALE_DATA is not set\\
430 # UCLIBC_HAS_XLOCALE is not set/
435 s/^# UCLIBC_HAS_LOCALE is not set/UCLIBC_HAS_LOCALE=y\\
436 UCLIBC_PREGENERATED_LOCALE_DATA=y\\
437 # UCLIBC_DOWNLOAD_PREGENERATED_LOCALE_DATA is not set\\
438 # UCLIBC_HAS_XLOCALE is not set/
444 if [ "${CT_LIBC_UCLIBC_WCHAR}" = "y" ] ; then
446 s/^.*UCLIBC_HAS_WCHAR.*/UCLIBC_HAS_WCHAR=y/
450 s/^.*UCLIBC_HAS_WCHAR.*/UCLIBC_HAS_WCHAR=n/
454 # Force on options needed for C++ if we'll be making a C++ compiler.
455 # I'm not sure locales are a requirement for doing C++... Are they?
456 if [ "${CT_CC_LANG_CXX}" = "y" ]; then
458 s/^# DO_C99_MATH is not set/DO_C99_MATH=y/
459 s/^# UCLIBC_HAS_GNU_GETOPT is not set/UCLIBC_HAS_GNU_GETOPT=y/
463 # Push the threading model
464 case "${CT_THREADS}:${CT_LIBC_UCLIBC_LNXTHRD}" in
467 s/^UCLIBC_HAS_THREADS=y/# UCLIBC_HAS_THREADS is not set/
468 s/^LINUXTHREADS_OLD=y/# LINUXTHREADS_OLD is not set/
469 s/^LINUXTHREADS_NEW=y/# LINUXTHREADS_NEW is not set/
470 s/^UCLIBC_HAS_THREADS_NATIVE=y/# UCLIBC_HAS_THREADS_NATIVE is not set/
475 s/^# UCLIBC_HAS_THREADS is not set/UCLIBC_HAS_THREADS=y/
476 s/^# LINUXTHREADS_OLD is not set/LINUXTHREADS_OLD=y/
477 s/^LINUXTHREADS_NEW=y/# LINUXTHREADS_NEW is not set/
478 s/^UCLIBC_HAS_THREADS_NATIVE=y/# UCLIBC_HAS_THREADS_NATIVE is not set/
483 s/^# UCLIBC_HAS_THREADS is not set/UCLIBC_HAS_THREADS=y/
484 s/^LINUXTHREADS_OLD=y/# LINUXTHREADS_OLD is not set/
485 s/^# LINUXTHREADS_NEW is not set/LINUXTHREADS_NEW=y/
486 s/^UCLIBC_HAS_THREADS_NATIVE=y/# UCLIBC_HAS_THREADS_NATIVE is not set/
491 s/^HAS_NO_THREADS=y/# HAS_NO_THREADS is not set/
492 s/^UCLIBC_HAS_THREADS=y/# UCLIBC_HAS_THREADS is not set/
493 s/^LINUXTHREADS_OLD=y/# LINUXTHREADS_OLD is not set/
494 s/^LINUXTHREADS_NEW=y/# LINUXTHREADS_NEW is not set/
495 s/^# UCLIBC_HAS_THREADS_NATIVE is not set/UCLIBC_HAS_THREADS_NATIVE=y/
499 CT_Abort "Incorrect thread settings: CT_THREADS='${CT_THREAD}' CT_LIBC_UCLIBC_LNXTHRD='${CT_LIBC_UCLIBC_LNXTHRD}'"
503 # Always build the libpthread_db
505 s/^# PTHREADS_DEBUG_SUPPORT is not set.*/PTHREADS_DEBUG_SUPPORT=y/
508 # Force on debug options if asked for
509 case "${CT_LIBC_UCLIBC_DEBUG_LEVEL}" in
512 s/^DODEBUG=y/# DODEBUG is not set/
513 s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
514 s/^DOASSERTS=y/# DOASSERTS is not set/
515 s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
516 s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
517 s/^UCLIBC_MALLOC_DEBUGGING=y/# UCLIBC_MALLOC_DEBUGGING is not set/
522 s/^# DODEBUG is not set.*/DODEBUG=y/
523 s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
524 s/^DOASSERTS=y/# DOASSERTS is not set/
525 s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
526 s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
527 s/^UCLIBC_MALLOC_DEBUGGING=y/# UCLIBC_MALLOC_DEBUGGING is not set/
532 s/^# DODEBUG is not set.*/DODEBUG=y/
533 s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
534 s/^# DOASSERTS is not set.*/DOASSERTS=y/
535 s/^# SUPPORT_LD_DEBUG is not set.*/SUPPORT_LD_DEBUG=y/
536 s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
537 s/^# UCLIBC_MALLOC_DEBUGGING is not set/UCLIBC_MALLOC_DEBUGGING=y/
542 s/^# DODEBUG is not set.*/DODEBUG=y/
543 s/^# DODEBUG_PT is not set.*/DODEBUG_PT=y/
544 s/^# DOASSERTS is not set.*/DOASSERTS=y/
545 s/^# SUPPORT_LD_DEBUG is not set.*/SUPPORT_LD_DEBUG=y/
546 s/^# SUPPORT_LD_DEBUG_EARLY is not set.*/SUPPORT_LD_DEBUG_EARLY=y/
547 s/^# UCLIBC_MALLOC_DEBUGGING is not set/UCLIBC_MALLOC_DEBUGGING=y/
552 # And now, this is the end
555 sed -r -f "${munge_file}" "${src_config_file}" >"${dst_config_file}"