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}" = "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 if [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ]; then
44 CT_Pushd "$(libc_uclibc_src_dir)/extra/locale"
45 CT_Extract nochdir "uClibc-locale-030818"
46 CT_Patch nochdir "uClibc" "locale-030818"
53 # Check that uClibc has been previously configured
54 do_libc_check_config() {
55 CT_DoStep INFO "Checking C library configuration"
57 CT_TestOrAbort "You did not provide a uClibc config file!" -n "${CT_LIBC_UCLIBC_CONFIG_FILE}" -a -f "${CT_LIBC_UCLIBC_CONFIG_FILE}"
59 if grep -E '^KERNEL_SOURCE=' "${CT_LIBC_UCLIBC_CONFIG_FILE}" >/dev/null 2>&1; then
60 CT_DoLog WARN "Your uClibc version refers to the kernel _sources_, which is bad."
61 CT_DoLog WARN "I can't guarantee that our little hack will work. Please try to upgrade."
64 CT_DoLog EXTRA "Munging uClibc configuration"
65 mungeuClibcConfig "${CT_LIBC_UCLIBC_CONFIG_FILE}" "${CT_CONFIG_DIR}/uClibc.config"
70 # This functions installs uClibc's headers
74 CT_DoStep INFO "Installing C library headers"
76 # Simply copy files until uClibc has the ability to build out-of-tree
77 CT_DoLog EXTRA "Copying sources to build dir"
78 CT_DoExecLog ALL cp -av "$(libc_uclibc_src_dir)" \
79 "${CT_BUILD_DIR}/build-libc-headers"
80 cd "${CT_BUILD_DIR}/build-libc-headers"
82 # Retrieve the config file
83 CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/uClibc.config" .config
85 # uClibc uses the CROSS environment variable as a prefix to the
86 # compiler tools to use. Setting it to the empty string forces
87 # use of the native build host tools, which we need at this
88 # stage, as we don't have target tools yet.
89 CT_DoLog EXTRA "Applying configuration"
90 CT_DoYes "" |CT_DoExecLog ALL make CROSS= PREFIX="${CT_SYSROOT_DIR}/" oldconfig
92 CT_DoLog EXTRA "Building headers"
93 CT_DoExecLog ALL make ${CT_LIBC_UCLIBC_VERBOSITY} CROSS= PREFIX="${CT_SYSROOT_DIR}/" headers
95 if [ "${CT_LIBC_UCLIBC_0_9_30_or_later}" = "y" ]; then
96 install_rule=install_headers
98 install_rule=install_dev
101 CT_DoLog EXTRA "Installing headers"
102 CT_DoExecLog ALL make ${CT_LIBC_UCLIBC_VERBOSITY} CROSS= PREFIX="${CT_SYSROOT_DIR}/" "${install_rule}"
107 # Build and install start files
108 do_libc_start_files() {
112 # This function build and install the full uClibc
114 CT_DoStep INFO "Installing C library"
116 # Simply copy files until uClibc has the ability to build out-of-tree
117 CT_DoLog EXTRA "Copying sources to build dir"
118 CT_DoExecLog ALL cp -av "$(libc_uclibc_src_dir)" \
119 "${CT_BUILD_DIR}/build-libc"
120 cd "${CT_BUILD_DIR}/build-libc"
122 # Retrieve the config file
123 CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/uClibc.config" .config
125 # uClibc uses the CROSS environment variable as a prefix to the compiler
126 # tools to use. The newly built tools should be in our path, so we need
127 # only give the correct name for them.
128 # Note about CFLAGS: In uClibc, CFLAGS are generated by Rules.mak,
129 # depending on the configuration of the library. That is, they are tailored
130 # to best fit the target. So it is useless and seems to be a bad thing to
131 # use LIBC_EXTRA_CFLAGS here.
132 CT_DoLog EXTRA "Applying configuration"
133 CT_DoYes "" |CT_DoExecLog ALL \
134 make CROSS=${CT_TARGET}- \
135 PREFIX="${CT_SYSROOT_DIR}/" \
138 # We do _not_ want to strip anything for now, in case we specifically
139 # asked for a debug toolchain, thus the STRIPTOOL= assignment
140 # /Old/ versions can not build in //
141 CT_DoLog EXTRA "Building C library"
143 make ${CT_LIBC_UCLIBC_PARALLEL:+${PARALLELMFLAGS}} \
144 CROSS=${CT_TARGET}- \
145 PREFIX="${CT_SYSROOT_DIR}/" \
147 ${CT_LIBC_UCLIBC_VERBOSITY} \
151 # - we want to install 'runtime' files, eg. lib*.{a,so*}, crti.o and
152 # such files, except the headers as they already are installed
153 # - "make install_dev" installs the headers, the crti.o... and the
154 # static libs, but not the dynamic libs
155 # - "make install_runtime" installs the dynamic libs only
156 # - "make install" calls install_runtime and install_dev
157 # - so we're left with re-installing the headers... Sigh...
159 # We do _not_ want to strip anything for now, in case we specifically
160 # asked for a debug toolchain, hence the STRIPTOOL= assignment
162 # Note: PARALLELMFLAGS is not usefull for installation.
164 CT_DoLog EXTRA "Installing C library"
166 make CROSS=${CT_TARGET}- \
167 PREFIX="${CT_SYSROOT_DIR}/" \
169 ${CT_LIBC_UCLIBC_VERBOSITY} \
172 if [ "${CT_LIBC_UCLIBC_BUILD_CROSS_LDD}" = "y" ]; then
173 CT_DoLog EXTRA "Building C library cross-ldd"
175 make PREFIX="${CT_SYSROOT_DIR}/" \
176 ${CT_LIBC_UCLIBC_VERBOSITY} \
179 CT_DoLog EXTRA "Installing C library cross-ldd"
180 CT_DoExecLog ALL install -m 0755 utils/ldd.host "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ldd"
186 # This function is used to install those components needing the final C compiler
191 # Initialises the .config file to sensible values
194 mungeuClibcConfig() {
197 munge_file="${CT_BUILD_DIR}/munge-uClibc-config.sed"
199 # Start with a fresh file
200 rm -f "${munge_file}"
201 touch "${munge_file}"
203 # Do it all in a sub-shell, it's easier to redirect output
206 # Hack our target in the config file.
207 case "${CT_ARCH}:${CT_ARCH_BITNESS}" in
209 x86:64) arch=x86_64;;
212 blackfin:32) arch="bfin";;
213 *) arch="${CT_ARCH}";;
215 # Also remove stripping: its the responsibility of the
216 # firmware builder to strip or not.
218 s/^(TARGET_.*)=y$/# \\1 is not set/
219 s/^# TARGET_${arch} is not set/TARGET_${arch}=y/
220 s/^TARGET_ARCH=".*"/TARGET_ARCH="${arch}"/
221 s/.*(DOSTRIP).*/# \\1 is not set/
224 # Ah. We may one day need architecture-specific handler here...
225 if [ "${CT_ARCH}" = "arm" ]; then
226 # Hack the ARM {E,O}ABI into the config file
227 if [ "${CT_ARCH_ARM_EABI}" = "y" ]; then
229 s/.*(CONFIG_ARM_OABI).*/# \\1 is not set/
230 s/.*(CONFIG_ARM_EABI).*/\\1=y/
234 s/.*(CONFIG_ARM_OABI).*/\\1=y/
235 s/.*(CONFIG_ARM_EABI).*/# \\1 is not set/
240 # Accomodate for old and new uClibc versions, where the
241 # way to select between big/little endian has changed
242 case "${CT_ARCH_BE},${CT_ARCH_LE}" in
244 s/.*(ARCH_LITTLE_ENDIAN).*/# \\1 is not set/
245 s/.*(ARCH_BIG_ENDIAN).*/\\1=y/
246 s/.*(ARCH_WANTS_LITTLE_ENDIAN).*/# \\1 is not set/
247 s/.*(ARCH_WANTS_BIG_ENDIAN).*/\\1=y/
251 s/.*(ARCH_LITTLE_ENDIAN).*/\\1=y/
252 s/.*(ARCH_BIG_ENDIAN).*/# \\1 is not set/
253 s/.*(ARCH_WANTS_LITTLE_ENDIAN).*/\\1=y/
254 s/.*(ARCH_WANTS_BIG_ENDIAN).*/# \\1 is not set/
259 # Accomodate for old and new uClibc version, where the
260 # way to select between hard/soft float has changed
261 case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
263 s/^[^_]*(HAS_FPU).*/\\1=y/
264 s/.*(UCLIBC_HAS_FPU).*/\\1=y/
268 s/^[^_]*(HAS_FPU).*/\\# \\1 is not set/
269 s/.*(UCLIBC_HAS_FPU).*/# \\1 is not set/
274 # Change paths to work with crosstool-NG
275 # From http://www.uclibc.org/cgi-bin/viewcvs.cgi?rev=16846&view=rev
276 # " we just want the kernel headers, not the whole kernel source ...
277 # " so people may need to update their paths slightly
278 quoted_kernel_source=$(echo "${CT_HEADERS_DIR}" | sed -r -e 's,/include/?$,,; s,/,\\/,g;')
279 quoted_headers_dir=$(echo "${CT_HEADERS_DIR}" | sed -r -e 's,/,\\/,g;')
280 # CROSS_COMPILER_PREFIX is left as is, as the CROSS parameter is forced on the command line
281 # DEVEL_PREFIX is left as '/usr/' because it is post-pended to $PREFIX, wich is the correct value of ${PREFIX}/${TARGET}
282 # Some (old) versions of uClibc use KERNEL_SOURCE (which is _wrong_), and
283 # newer versions use KERNEL_HEADERS (which is right).
285 s/^DEVEL_PREFIX=".*"/DEVEL_PREFIX="\\/usr\\/"/
286 s/^RUNTIME_PREFIX=".*"/RUNTIME_PREFIX="\\/"/
287 s/^SHARED_LIB_LOADER_PREFIX=.*/SHARED_LIB_LOADER_PREFIX="\\/lib\\/"/
288 s/^KERNEL_SOURCE=".*"/KERNEL_SOURCE="${quoted_kernel_source}"/
289 s/^KERNEL_HEADERS=".*"/KERNEL_HEADERS="${quoted_headers_dir}"/
290 s/^UCLIBC_DOWNLOAD_PREGENERATED_LOCALE=y/\\# UCLIBC_DOWNLOAD_PREGENERATED_LOCALE is not set/
293 if [ "${CT_USE_PIPES}" = "y" ]; then
294 if grep UCLIBC_EXTRA_CFLAGS extra/Configs/Config.in >/dev/null 2>&1; then
295 # Good, there is special provision for such things as -pipe!
297 s/^(UCLIBC_EXTRA_CFLAGS=".*)"$/\\1 -pipe"/
300 # Hack our -pipe into WARNINGS, which will be internally incorporated to
301 # CFLAGS. This a dirty hack, but yet needed
303 s/^(WARNINGS=".*)"$/\\1 -pipe"/
309 # Note that the two PREGEN_LOCALE and the XLOCALE lines may be missing
310 # entirely if LOCALE is not set. If LOCALE was already set, we'll
311 # assume the user has already made all the appropriate generation
312 # arrangements. Note that having the uClibc Makefile download the
313 # pregenerated locales is not compatible with crosstool; besides,
314 # crosstool downloads them as part of getandpatch.sh.
315 if [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ] ; then
317 s/^# UCLIBC_HAS_LOCALE is not set/UCLIBC_HAS_LOCALE=y\\
318 UCLIBC_PREGENERATED_LOCALE_DATA=y\\
319 # UCLIBC_DOWNLOAD_PREGENERATED_LOCALE_DATA is not set\\
320 # UCLIBC_HAS_XLOCALE is not set/
325 if [ "${CT_LIBC_UCLIBC_WCHAR}" = "y" ] ; then
327 s/^.*UCLIBC_HAS_WCHAR.*/UCLIBC_HAS_WCHAR=y/
331 s/^.*UCLIBC_HAS_WCHAR.*/UCLIBC_HAS_WCHAR=n/
335 # Force on options needed for C++ if we'll be making a C++ compiler.
336 # I'm not sure locales are a requirement for doing C++... Are they?
337 if [ "${CT_CC_LANG_CXX}" = "y" ]; then
339 s/^# DO_C99_MATH is not set/DO_C99_MATH=y/
340 s/^# UCLIBC_CTOR_DTOR is not set/UCLIBC_CTOR_DTOR=y/
341 s/^# UCLIBC_HAS_GNU_GETOPT is not set/UCLIBC_HAS_GNU_GETOPT=y/
345 # Push the threading model
346 # Note: we take into account all of the .28, .29, .30 and .31
348 case "${CT_THREADS}:${CT_LIBC_UCLIBC_LNXTHRD}" in
351 s/^UCLIBC_HAS_THREADS=y/# UCLIBC_HAS_THREADS is not set/
352 s/^LINUXTHREADS_OLD=y/# LINUXTHREADS_OLD is not set/
353 s/^LINUXTHREADS_NEW=y/# LINUXTHREADS_NEW is not set/
358 s/^# UCLIBC_HAS_THREADS is not set/UCLIBC_HAS_THREADS=y/
359 s/^# LINUXTHREADS_OLD is not set/LINUXTHREADS_OLD=y/
360 s/^LINUXTHREADS_NEW=y/# LINUXTHREADS_NEW is not set/
365 s/^# UCLIBC_HAS_THREADS is not set/UCLIBC_HAS_THREADS=y/
366 s/^LINUXTHREADS_OLD=y/# LINUXTHREADS_OLD is not set/
367 s/^# LINUXTHREADS_NEW is not set/LINUXTHREADS_NEW=y/
372 # Always build the libpthread_db
374 s/^# PTHREADS_DEBUG_SUPPORT is not set.*/PTHREADS_DEBUG_SUPPORT=y/
377 # Force on debug options if asked for
378 case "${CT_LIBC_UCLIBC_DEBUG_LEVEL}" in
381 s/^DODEBUG=y/# DODEBUG is not set/
382 s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
383 s/^DOASSERTS=y/# DOASSERTS is not set/
384 s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
385 s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
386 s/^UCLIBC_MALLOC_DEBUGGING=y/# UCLIBC_MALLOC_DEBUGGING is not set/
391 s/^# DODEBUG is not set.*/DODEBUG=y/
392 s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
393 s/^DOASSERTS=y/# DOASSERTS is not set/
394 s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
395 s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
396 s/^UCLIBC_MALLOC_DEBUGGING=y/# UCLIBC_MALLOC_DEBUGGING is not set/
401 s/^# DODEBUG is not set.*/DODEBUG=y/
402 s/^# DODEBUG_PT is not set.*/DODEBUG_PT=y/
403 s/^# DOASSERTS is not set.*/DOASSERTS=y/
404 s/^# SUPPORT_LD_DEBUG is not set.*/SUPPORT_LD_DEBUG=y/
405 s/^# SUPPORT_LD_DEBUG_EARLY is not set.*/SUPPORT_LD_DEBUG_EARLY=y/
406 s/^# UCLIBC_MALLOC_DEBUGGING is not set/UCLIBC_MALLOC_DEBUGGING=y/
411 # And now, this is the end
414 sed -r -f "${munge_file}" "${src_config_file}" >"${dst_config_file}"