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 "uClibc-${CT_LIBC_VERSION}" ${libc_src}
15 if [ "${CT_LIBC_UCLIBC_LOCALES_PREGEN_DATA}" = "y" ]; then
16 CT_GetFile "uClibc-locale-030818" ${libc_src}
22 libc_uclibc_src_dir() {
23 if [ -z "${CT_LIBC_V_snapshot}" \
24 -a -z "${CT_LIBC_V_specific_date}" \
26 echo "${CT_SRC_DIR}/uClibc-${CT_LIBC_VERSION}"
28 echo "${CT_SRC_DIR}/uClibc"
34 CT_Extract "uClibc-${CT_LIBC_VERSION}"
35 # Don't patch snapshots
36 if [ -z "${CT_LIBC_V_snapshot}" \
37 -a -z "${CT_LIBC_V_specific_date}" \
39 CT_Patch "uClibc" "${CT_LIBC_VERSION}"
43 # Extracting pregen locales ourselves is kinda
44 # broken, so just link it in place...
45 if [ "${CT_LIBC_UCLIBC_LOCALES_PREGEN_DATA}" = "y" \
46 -a ! -f "${CT_SRC_DIR}/.uClibc-locales-030818.extracted" ]; then
47 CT_Pushd "$(libc_uclibc_src_dir)/extra/locale"
48 CT_DoExecLog ALL ln -s "${CT_TARBALLS_DIR}/uClibc-locale-030818.tgz" .
50 touch "${CT_SRC_DIR}/.uClibc-locales-030818.extracted"
56 # Check that uClibc has been previously configured
57 do_libc_check_config() {
58 CT_DoStep INFO "Checking C library configuration"
60 CT_TestOrAbort "You did not provide a uClibc config file!" -n "${CT_LIBC_UCLIBC_CONFIG_FILE}" -a -f "${CT_LIBC_UCLIBC_CONFIG_FILE}"
62 if grep -E '^KERNEL_SOURCE=' "${CT_LIBC_UCLIBC_CONFIG_FILE}" >/dev/null 2>&1; then
63 CT_DoLog WARN "Your uClibc version refers to the kernel _sources_, which is bad."
64 CT_DoLog WARN "I can't guarantee that our little hack will work. Please try to upgrade."
67 CT_DoLog EXTRA "Munging uClibc configuration"
68 mungeuClibcConfig "${CT_LIBC_UCLIBC_CONFIG_FILE}" "${CT_CONFIG_DIR}/uClibc.config"
73 # This functions installs uClibc's headers
78 CT_DoStep INFO "Installing C library headers"
80 # Simply copy files until uClibc has the ability to build out-of-tree
81 CT_DoLog EXTRA "Copying sources to build dir"
82 CT_DoExecLog ALL cp -av "$(libc_uclibc_src_dir)" \
83 "${CT_BUILD_DIR}/build-libc-headers"
84 cd "${CT_BUILD_DIR}/build-libc-headers"
86 # Retrieve the config file
87 CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/uClibc.config" .config
89 # uClibc uses the CROSS environment variable as a prefix to the
90 # compiler tools to use. Setting it to the empty string forces
91 # use of the native build host tools, which we need at this
92 # stage, as we don't have target tools yet.
93 # BUT! With NPTL, we need a cross-compiler (and we have it)
94 if [ "${CT_THREADS}" = "nptl" ]; then
98 CT_DoLog EXTRA "Applying configuration"
99 CT_DoYes "" |CT_DoExecLog ALL \
100 make CROSS="${cross}" \
101 PREFIX="${CT_SYSROOT_DIR}/" \
104 CT_DoLog EXTRA "Building headers"
106 make ${CT_LIBC_UCLIBC_VERBOSITY} \
108 PREFIX="${CT_SYSROOT_DIR}/" \
111 if [ "${CT_LIBC_UCLIBC_0_9_30_or_later}" = "y" ]; then
112 install_rule=install_headers
114 install_rule=install_dev
117 CT_DoLog EXTRA "Installing headers"
119 make ${CT_LIBC_UCLIBC_VERBOSITY} \
121 PREFIX="${CT_SYSROOT_DIR}/" \
124 if [ "${CT_THREADS}" = "nptl" ]; then
125 CT_DoLog EXTRA "Building start files"
127 make ${CT_LIBC_UCLIBC_PARALLEL:+${PARALLELMFLAGS}} \
129 PREFIX="${CT_SYSROOT_DIR}/" \
131 ${CT_LIBC_UCLIBC_VERBOSITY} \
132 lib/crt1.o lib/crti.o lib/crtn.o
134 # From: http://git.openembedded.org/cgit.cgi/openembedded/commit/?id=ad5668a7ac7e0436db92e55caaf3fdf782b6ba3b
135 # libm.so is needed for ppc, as libgcc is linked against libm.so
136 # No problem to create it for other archs.
137 CT_DoLog EXTRA "Building dummy shared libs"
138 CT_DoExecLog ALL "${cross}gcc" -nostdlib \
144 CT_DoLog EXTRA "Installing start files"
145 CT_DoExecLog ALL install -m 0644 lib/crt1.o lib/crti.o lib/crtn.o \
146 "${CT_SYSROOT_DIR}/usr/lib"
148 CT_DoLog EXTRA "Installing dummy shared libs"
149 CT_DoExecLog ALL install -m 0755 libdummy.so "${CT_SYSROOT_DIR}/usr/lib/libc.so"
150 CT_DoExecLog ALL install -m 0755 libdummy.so "${CT_SYSROOT_DIR}/usr/lib/libm.so"
151 fi # CT_THREADS == nptl
156 # Build and install start files
157 do_libc_start_files() {
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 "$(libc_uclibc_src_dir)" \
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 ALL \
183 make CROSS=${CT_TARGET}- \
184 PREFIX="${CT_SYSROOT_DIR}/" \
187 # We do _not_ want to strip anything for now, in case we specifically
188 # asked for a debug toolchain, thus the STRIPTOOL= assignment
189 # /Old/ versions can not build in //
190 CT_DoLog EXTRA "Building C library"
193 CROSS=${CT_TARGET}- \
194 PREFIX="${CT_SYSROOT_DIR}/" \
196 ${CT_LIBC_UCLIBC_VERBOSITY} \
199 make ${CT_LIBC_UCLIBC_PARALLEL:+${PARALLELMFLAGS}} \
200 CROSS=${CT_TARGET}- \
201 PREFIX="${CT_SYSROOT_DIR}/" \
203 ${CT_LIBC_UCLIBC_VERBOSITY} \
207 # - we want to install 'runtime' files, eg. lib*.{a,so*}, crti.o and
208 # such files, except the headers as they already are installed
209 # - "make install_dev" installs the headers, the crti.o... and the
210 # static libs, but not the dynamic libs
211 # - "make install_runtime" installs the dynamic libs only
212 # - "make install" calls install_runtime and install_dev
213 # - so we're left with re-installing the headers... Sigh...
215 # We do _not_ want to strip anything for now, in case we specifically
216 # asked for a debug toolchain, hence the STRIPTOOL= assignment
218 # Note: PARALLELMFLAGS is not usefull for installation.
220 CT_DoLog EXTRA "Installing C library"
222 make CROSS=${CT_TARGET}- \
223 PREFIX="${CT_SYSROOT_DIR}/" \
225 ${CT_LIBC_UCLIBC_VERBOSITY} \
231 # This function is used to install those components needing the final C compiler
236 # Initialises the .config file to sensible values
239 mungeuClibcConfig() {
242 munge_file="${CT_BUILD_DIR}/munge-uClibc-config.sed"
244 # Start with a fresh file
245 rm -f "${munge_file}"
246 touch "${munge_file}"
248 # Do it all in a sub-shell, it's easier to redirect output
251 # Hack our target in the config file.
252 case "${CT_ARCH}:${CT_ARCH_BITNESS}" in
254 x86:64) arch=x86_64;;
257 blackfin:32) arch="bfin";;
258 *) arch="${CT_ARCH}";;
260 # Also remove stripping: its the responsibility of the
261 # firmware builder to strip or not.
263 s/^(TARGET_.*)=y$/# \\1 is not set/
264 s/^# TARGET_${arch} is not set/TARGET_${arch}=y/
265 s/^TARGET_ARCH=".*"/TARGET_ARCH="${arch}"/
266 s/.*(DOSTRIP).*/# \\1 is not set/
269 # Ah. We may one day need architecture-specific handler here...
270 if [ "${CT_ARCH}" = "arm" ]; then
271 # Hack the ARM {E,O}ABI into the config file
272 if [ "${CT_ARCH_ARM_EABI}" = "y" ]; then
274 s/.*(CONFIG_ARM_OABI).*/# \\1 is not set/
275 s/.*(CONFIG_ARM_EABI).*/\\1=y/
279 s/.*(CONFIG_ARM_OABI).*/\\1=y/
280 s/.*(CONFIG_ARM_EABI).*/# \\1 is not set/
285 # Accomodate for old and new uClibc versions, where the
286 # way to select between big/little endian has changed
287 case "${CT_ARCH_BE},${CT_ARCH_LE}" in
289 s/.*(ARCH_LITTLE_ENDIAN).*/# \\1 is not set/
290 s/.*(ARCH_BIG_ENDIAN).*/\\1=y/
291 s/.*(ARCH_WANTS_LITTLE_ENDIAN).*/# \\1 is not set/
292 s/.*(ARCH_WANTS_BIG_ENDIAN).*/\\1=y/
296 s/.*(ARCH_LITTLE_ENDIAN).*/\\1=y/
297 s/.*(ARCH_BIG_ENDIAN).*/# \\1 is not set/
298 s/.*(ARCH_WANTS_LITTLE_ENDIAN).*/\\1=y/
299 s/.*(ARCH_WANTS_BIG_ENDIAN).*/# \\1 is not set/
304 # Accomodate for old and new uClibc version, where the
305 # way to select between hard/soft float has changed
306 case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
308 s/^[^_]*(HAS_FPU).*/\\1=y/
309 s/.*(UCLIBC_HAS_FPU).*/\\1=y/
313 s/^[^_]*(HAS_FPU).*/\\# \\1 is not set/
314 s/.*(UCLIBC_HAS_FPU).*/# \\1 is not set/
319 # Change paths to work with crosstool-NG
320 # From http://www.uclibc.org/cgi-bin/viewcvs.cgi?rev=16846&view=rev
321 # " we just want the kernel headers, not the whole kernel source ...
322 # " so people may need to update their paths slightly
323 quoted_kernel_source=$(echo "${CT_HEADERS_DIR}" | sed -r -e 's,/include/?$,,; s,/,\\/,g;')
324 quoted_headers_dir=$(echo "${CT_HEADERS_DIR}" | sed -r -e 's,/,\\/,g;')
325 # CROSS_COMPILER_PREFIX is left as is, as the CROSS parameter is forced on the command line
326 # DEVEL_PREFIX is left as '/usr/' because it is post-pended to $PREFIX, wich is the correct value of ${PREFIX}/${TARGET}
327 # Some (old) versions of uClibc use KERNEL_SOURCE (which is _wrong_), and
328 # newer versions use KERNEL_HEADERS (which is right).
330 s/^DEVEL_PREFIX=".*"/DEVEL_PREFIX="\\/usr\\/"/
331 s/^RUNTIME_PREFIX=".*"/RUNTIME_PREFIX="\\/"/
332 s/^SHARED_LIB_LOADER_PREFIX=.*/SHARED_LIB_LOADER_PREFIX="\\/lib\\/"/
333 s/^KERNEL_SOURCE=".*"/KERNEL_SOURCE="${quoted_kernel_source}"/
334 s/^KERNEL_HEADERS=".*"/KERNEL_HEADERS="${quoted_headers_dir}"/
335 s/^UCLIBC_DOWNLOAD_PREGENERATED_LOCALE=y/\\# UCLIBC_DOWNLOAD_PREGENERATED_LOCALE is not set/
338 if [ "${CT_USE_PIPES}" = "y" ]; then
339 if grep UCLIBC_EXTRA_CFLAGS extra/Configs/Config.in >/dev/null 2>&1; then
340 # Good, there is special provision for such things as -pipe!
342 s/^(UCLIBC_EXTRA_CFLAGS=".*)"$/\\1 -pipe"/
345 # Hack our -pipe into WARNINGS, which will be internally incorporated to
346 # CFLAGS. This a dirty hack, but yet needed
348 s/^(WARNINGS=".*)"$/\\1 -pipe"/
354 # Note that the two PREGEN_LOCALE and the XLOCALE lines may be missing
355 # entirely if LOCALE is not set. If LOCALE was already set, we'll
356 # assume the user has already made all the appropriate generation
357 # arrangements. Note that having the uClibc Makefile download the
358 # pregenerated locales is not compatible with crosstool; besides,
359 # crosstool downloads them as part of getandpatch.sh.
360 case "${CT_LIBC_UCLIBC_LOCALES}:${CT_LIBC_UCLIBC_LOCALES_PREGEN_DATA}" in
365 s/^# UCLIBC_HAS_LOCALE is not set/UCLIBC_HAS_LOCALE=y\\
366 # UCLIBC_PREGENERATED_LOCALE_DATA is not set\\
367 # UCLIBC_DOWNLOAD_PREGENERATED_LOCALE_DATA is not set\\
368 # UCLIBC_HAS_XLOCALE is not set/
373 s/^# UCLIBC_HAS_LOCALE is not set/UCLIBC_HAS_LOCALE=y\\
374 UCLIBC_PREGENERATED_LOCALE_DATA=y\\
375 # UCLIBC_DOWNLOAD_PREGENERATED_LOCALE_DATA is not set\\
376 # UCLIBC_HAS_XLOCALE is not set/
382 if [ "${CT_LIBC_UCLIBC_WCHAR}" = "y" ] ; then
384 s/^.*UCLIBC_HAS_WCHAR.*/UCLIBC_HAS_WCHAR=y/
388 s/^.*UCLIBC_HAS_WCHAR.*/UCLIBC_HAS_WCHAR=n/
392 # Force on options needed for C++ if we'll be making a C++ compiler.
393 # I'm not sure locales are a requirement for doing C++... Are they?
394 if [ "${CT_CC_LANG_CXX}" = "y" ]; then
396 s/^# DO_C99_MATH is not set/DO_C99_MATH=y/
397 s/^# UCLIBC_CTOR_DTOR is not set/UCLIBC_CTOR_DTOR=y/
398 s/^# UCLIBC_HAS_GNU_GETOPT is not set/UCLIBC_HAS_GNU_GETOPT=y/
402 # Push the threading model
403 # Note: we take into account all of the .28, .29, .30 and .31
404 # versions, here. Even snapshots with NPTL.
405 case "${CT_THREADS}:${CT_LIBC_UCLIBC_LNXTHRD}" in
408 s/^UCLIBC_HAS_THREADS=y/# UCLIBC_HAS_THREADS is not set/
409 s/^LINUXTHREADS_OLD=y/# LINUXTHREADS_OLD is not set/
410 s/^LINUXTHREADS_NEW=y/# LINUXTHREADS_NEW is not set/
411 s/^UCLIBC_HAS_THREADS_NATIVE=y/# UCLIBC_HAS_THREADS_NATIVE is not set/
416 s/^# UCLIBC_HAS_THREADS is not set/UCLIBC_HAS_THREADS=y/
417 s/^# LINUXTHREADS_OLD is not set/LINUXTHREADS_OLD=y/
418 s/^LINUXTHREADS_NEW=y/# LINUXTHREADS_NEW is not set/
419 s/^UCLIBC_HAS_THREADS_NATIVE=y/# UCLIBC_HAS_THREADS_NATIVE is not set/
424 s/^# UCLIBC_HAS_THREADS is not set/UCLIBC_HAS_THREADS=y/
425 s/^LINUXTHREADS_OLD=y/# LINUXTHREADS_OLD is not set/
426 s/^# LINUXTHREADS_NEW is not set/LINUXTHREADS_NEW=y/
427 s/^UCLIBC_HAS_THREADS_NATIVE=y/# UCLIBC_HAS_THREADS_NATIVE is not set/
432 s/^HAS_NO_THREADS=y/# HAS_NO_THREADS is not set/
433 s/^UCLIBC_HAS_THREADS=y/# UCLIBC_HAS_THREADS is not set/
434 s/^LINUXTHREADS_OLD=y/# LINUXTHREADS_OLD is not set/
435 s/^LINUXTHREADS_NEW=y/# LINUXTHREADS_NEW is not set/
436 s/^# UCLIBC_HAS_THREADS_NATIVE is not set/UCLIBC_HAS_THREADS_NATIVE=y/
440 CT_Abort "Incorrect thread settings: CT_THREADS='${CT_THREAD}' CT_LIBC_UCLIBC_LNXTHRD='${CT_LIBC_UCLIBC_LNXTHRD}'"
444 # Always build the libpthread_db
446 s/^# PTHREADS_DEBUG_SUPPORT is not set.*/PTHREADS_DEBUG_SUPPORT=y/
449 # Force on debug options if asked for
450 case "${CT_LIBC_UCLIBC_DEBUG_LEVEL}" in
453 s/^DODEBUG=y/# DODEBUG is not set/
454 s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
455 s/^DOASSERTS=y/# DOASSERTS is not set/
456 s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
457 s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
458 s/^UCLIBC_MALLOC_DEBUGGING=y/# UCLIBC_MALLOC_DEBUGGING is not set/
463 s/^# DODEBUG is not set.*/DODEBUG=y/
464 s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
465 s/^DOASSERTS=y/# DOASSERTS is not set/
466 s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
467 s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
468 s/^UCLIBC_MALLOC_DEBUGGING=y/# UCLIBC_MALLOC_DEBUGGING is not set/
473 s/^# DODEBUG is not set.*/DODEBUG=y/
474 s/^# DODEBUG_PT is not set.*/DODEBUG_PT=y/
475 s/^# DOASSERTS is not set.*/DOASSERTS=y/
476 s/^# SUPPORT_LD_DEBUG is not set.*/SUPPORT_LD_DEBUG=y/
477 s/^# SUPPORT_LD_DEBUG_EARLY is not set.*/SUPPORT_LD_DEBUG_EARLY=y/
478 s/^# UCLIBC_MALLOC_DEBUGGING is not set/UCLIBC_MALLOC_DEBUGGING=y/
483 # And now, this is the end
486 sed -r -f "${munge_file}" "${src_config_file}" >"${dst_config_file}"