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}
24 CT_Extract "uClibc-${CT_LIBC_VERSION}"
25 CT_Patch "uClibc-${CT_LIBC_VERSION}"
28 if [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ]; then
29 CT_Pushd "${CT_SRC_DIR}/uClibc-${CT_LIBC_VERSION}/extra/locale"
30 CT_Extract "uClibc-locale-030818" nochdir
31 CT_Patch "uClibc-locale-030818" nochdir
38 # Check that uClibc has been previously configured
39 do_libc_check_config() {
40 CT_DoStep INFO "Checking C library configuration"
42 CT_TestOrAbort "You did not provide a uClibc config file!" -n "${CT_LIBC_UCLIBC_CONFIG_FILE}" -a -f "${CT_LIBC_UCLIBC_CONFIG_FILE}"
44 if grep -E '^KERNEL_SOURCE=' "${CT_LIBC_UCLIBC_CONFIG_FILE}" >/dev/null 2>&1; then
45 CT_DoLog WARN "Your uClibc version refers to the kernel _sources_, which is bad."
46 CT_DoLog WARN "I can't guarantee that our little hack will work. Please try to upgrade."
49 CT_DoLog EXTRA "Munging uClibc configuration"
50 mungeuClibcConfig "${CT_LIBC_UCLIBC_CONFIG_FILE}" "${CT_CONFIG_DIR}/uClibc.config"
55 # This functions installs uClibc's headers
59 CT_DoStep INFO "Installing C library headers"
61 # Simply copy files until uClibc has the ability to build out-of-tree
62 CT_DoLog EXTRA "Copying sources to build dir"
63 CT_DoExecLog ALL cp -av "${CT_SRC_DIR}/uClibc-${CT_LIBC_VERSION}" \
64 "${CT_BUILD_DIR}/build-libc-headers"
65 cd "${CT_BUILD_DIR}/build-libc-headers"
67 # Retrieve the config file
68 CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/uClibc.config" .config
70 # uClibc uses the CROSS environment variable as a prefix to the
71 # compiler tools to use. Setting it to the empty string forces
72 # use of the native build host tools, which we need at this
73 # stage, as we don't have target tools yet.
74 CT_DoLog EXTRA "Applying configuration"
75 CT_DoYes "" |CT_DoExecLog ALL make CROSS= PREFIX="${CT_SYSROOT_DIR}/" oldconfig
77 CT_DoLog EXTRA "Building headers"
78 CT_DoExecLog ALL make ${CT_LIBC_UCLIBC_VERBOSITY} CROSS= PREFIX="${CT_SYSROOT_DIR}/" headers
80 if [ "${CT_LIBC_UCLIBC_0_9_30_or_later}" = "y" ]; then
81 install_rule=install_headers
83 install_rule=install_dev
86 CT_DoLog EXTRA "Installing headers"
87 CT_DoExecLog ALL make ${CT_LIBC_UCLIBC_VERBOSITY} CROSS= PREFIX="${CT_SYSROOT_DIR}/" "${install_rule}"
92 # Build and install start files
93 do_libc_start_files() {
97 # This function build and install the full uClibc
99 CT_DoStep INFO "Installing C library"
101 # Simply copy files until uClibc has the ability to build out-of-tree
102 CT_DoLog EXTRA "Copying sources to build dir"
103 CT_DoExecLog ALL cp -av "${CT_SRC_DIR}/uClibc-${CT_LIBC_VERSION}" \
104 "${CT_BUILD_DIR}/build-libc"
105 cd "${CT_BUILD_DIR}/build-libc"
107 # Retrieve the config file
108 CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/uClibc.config" .config
110 # uClibc uses the CROSS environment variable as a prefix to the compiler
111 # tools to use. The newly built tools should be in our path, so we need
112 # only give the correct name for them.
113 # Note about CFLAGS: In uClibc, CFLAGS are generated by Rules.mak,
114 # depending on the configuration of the library. That is, they are tailored
115 # to best fit the target. So it is useless and seems to be a bad thing to
116 # use LIBC_EXTRA_CFLAGS here.
117 CT_DoLog EXTRA "Applying configuration"
118 CT_DoYes "" |CT_DoExecLog ALL \
119 make CROSS=${CT_TARGET}- \
120 PREFIX="${CT_SYSROOT_DIR}/" \
123 # We do _not_ want to strip anything for now, in case we specifically
124 # asked for a debug toolchain, thus the STRIPTOOL= assignment
125 # /Old/ versions can not build in //
126 CT_DoLog EXTRA "Building C library"
128 make ${CT_LIBC_UCLIBC_PARALLEL:+${PARALLELMFLAGS}} \
129 CROSS=${CT_TARGET}- \
130 PREFIX="${CT_SYSROOT_DIR}/" \
132 ${CT_LIBC_UCLIBC_VERBOSITY} \
136 # - we want to install 'runtime' files, eg. lib*.{a,so*}, crti.o and
137 # such files, except the headers as they already are installed
138 # - "make install_dev" installs the headers, the crti.o... and the
139 # static libs, but not the dynamic libs
140 # - "make install_runtime" installs the dynamic libs only
141 # - "make install" calls install_runtime and install_dev
142 # - so we're left with re-installing the headers... Sigh...
144 # We do _not_ want to strip anything for now, in case we specifically
145 # asked for a debug toolchain, hence the STRIPTOOL= assignment
147 # Note: PARALLELMFLAGS is not usefull for installation.
149 CT_DoLog EXTRA "Installing C library"
151 make CROSS=${CT_TARGET}- \
152 PREFIX="${CT_SYSROOT_DIR}/" \
154 ${CT_LIBC_UCLIBC_VERBOSITY} \
157 if [ "${CT_LIBC_UCLIBC_BUILD_CROSS_LDD}" = "y" ]; then
158 CT_DoLog EXTRA "Building C library cross-ldd"
160 make PREFIX="${CT_SYSROOT_DIR}/" \
161 ${CT_LIBC_UCLIBC_VERBOSITY} \
164 CT_DoLog EXTRA "Installing C library cross-ldd"
165 CT_DoExecLog ALL install -m 0755 utils/ldd.host "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ldd"
171 # This function is used to install those components needing the final C compiler
176 # Initialises the .config file to sensible values
179 mungeuClibcConfig() {
182 munge_file="${CT_BUILD_DIR}/munge-uClibc-config.sed"
184 # Start with a fresh file
185 rm -f "${munge_file}"
186 touch "${munge_file}"
188 # Do it all in a sub-shell, it's easier to redirect output
191 # Hack our target in the config file.
192 # Also remove stripping: its the responsibility of the
193 # firmware builder to strip or not.
195 s/^(TARGET_.*)=y$/# \\1 is not set/
196 s/^# TARGET_${CT_KERNEL_ARCH} is not set/TARGET_${CT_KERNEL_ARCH}=y/
197 s/^TARGET_ARCH=".*"/TARGET_ARCH="${CT_KERNEL_ARCH}"/
198 s/.*(DOSTRIP).*/# \\1 is not set/
201 # Ah. We may one day need architecture-specific handler here...
202 if [ "${CT_ARCH}" = "arm" ]; then
203 # Hack the ARM {E,O}ABI into the config file
204 if [ "${CT_ARCH_ARM_EABI}" = "y" ]; then
206 s/.*(CONFIG_ARM_OABI).*/# \\1 is not set/
207 s/.*(CONFIG_ARM_EABI).*/\\1=y/
211 s/.*(CONFIG_ARM_OABI).*/\\1=y/
212 s/.*(CONFIG_ARM_EABI).*/# \\1 is not set/
217 # Accomodate for old and new uClibc versions, where the
218 # way to select between big/little endian has changed
219 case "${CT_ARCH_BE},${CT_ARCH_LE}" in
221 s/.*(ARCH_LITTLE_ENDIAN).*/# \\1 is not set/
222 s/.*(ARCH_BIG_ENDIAN).*/\\1=y/
223 s/.*(ARCH_WANTS_LITTLE_ENDIAN).*/# \\1 is not set/
224 s/.*(ARCH_WANTS_BIG_ENDIAN).*/\\1=y/
228 s/.*(ARCH_LITTLE_ENDIAN).*/\\1=y/
229 s/.*(ARCH_BIG_ENDIAN).*/# \\1 is not set/
230 s/.*(ARCH_WANTS_LITTLE_ENDIAN).*/\\1=y/
231 s/.*(ARCH_WANTS_BIG_ENDIAN).*/# \\1 is not set/
236 # Accomodate for old and new uClibc version, where the
237 # way to select between hard/soft float has changed
238 case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
240 s/^[^_]*(HAS_FPU).*/\\1=y/
241 s/.*(UCLIBC_HAS_FPU).*/\\1=y/
245 s/^[^_]*(HAS_FPU).*/\\# \\1 is not set/
246 s/.*(UCLIBC_HAS_FPU).*/# \\1 is not set/
251 # Change paths to work with crosstool-NG
252 # From http://www.uclibc.org/cgi-bin/viewcvs.cgi?rev=16846&view=rev
253 # " we just want the kernel headers, not the whole kernel source ...
254 # " so people may need to update their paths slightly
255 quoted_kernel_source=$(echo "${CT_HEADERS_DIR}" | sed -r -e 's,/include/?$,,; s,/,\\/,g;')
256 quoted_headers_dir=$(echo "${CT_HEADERS_DIR}" | sed -r -e 's,/,\\/,g;')
257 # CROSS_COMPILER_PREFIX is left as is, as the CROSS parameter is forced on the command line
258 # DEVEL_PREFIX is left as '/usr/' because it is post-pended to $PREFIX, wich is the correct value of ${PREFIX}/${TARGET}
259 # Some (old) versions of uClibc use KERNEL_SOURCE (which is _wrong_), and
260 # newer versions use KERNEL_HEADERS (which is right).
262 s/^DEVEL_PREFIX=".*"/DEVEL_PREFIX="\\/usr\\/"/
263 s/^RUNTIME_PREFIX=".*"/RUNTIME_PREFIX="\\/"/
264 s/^SHARED_LIB_LOADER_PREFIX=.*/SHARED_LIB_LOADER_PREFIX="\\/lib\\/"/
265 s/^KERNEL_SOURCE=".*"/KERNEL_SOURCE="${quoted_kernel_source}"/
266 s/^KERNEL_HEADERS=".*"/KERNEL_HEADERS="${quoted_headers_dir}"/
267 s/^UCLIBC_DOWNLOAD_PREGENERATED_LOCALE=y/\\# UCLIBC_DOWNLOAD_PREGENERATED_LOCALE is not set/
270 if [ "${CT_USE_PIPES}" = "y" ]; then
271 if grep UCLIBC_EXTRA_CFLAGS extra/Configs/Config.in >/dev/null 2>&1; then
272 # Good, there is special provision for such things as -pipe!
274 s/^(UCLIBC_EXTRA_CFLAGS=".*)"$/\\1 -pipe"/
277 # Hack our -pipe into WARNINGS, which will be internally incorporated to
278 # CFLAGS. This a dirty hack, but yet needed
280 s/^(WARNINGS=".*)"$/\\1 -pipe"/
286 # Note that the two PREGEN_LOCALE and the XLOCALE lines may be missing
287 # entirely if LOCALE is not set. If LOCALE was already set, we'll
288 # assume the user has already made all the appropriate generation
289 # arrangements. Note that having the uClibc Makefile download the
290 # pregenerated locales is not compatible with crosstool; besides,
291 # crosstool downloads them as part of getandpatch.sh.
292 if [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ] ; then
294 s/^# UCLIBC_HAS_LOCALE is not set/UCLIBC_HAS_LOCALE=y\\
295 UCLIBC_PREGENERATED_LOCALE_DATA=y\\
296 # UCLIBC_DOWNLOAD_PREGENERATED_LOCALE_DATA is not set\\
297 # UCLIBC_HAS_XLOCALE is not set/
302 if [ "${CT_LIBC_UCLIBC_WCHAR}" = "y" ] ; then
304 s/^.*UCLIBC_HAS_WCHAR.*/UCLIBC_HAS_WCHAR=y/
308 s/^.*UCLIBC_HAS_WCHAR.*/UCLIBC_HAS_WCHAR=n/
312 # Force on options needed for C++ if we'll be making a C++ compiler.
313 # I'm not sure locales are a requirement for doing C++... Are they?
314 if [ "${CT_CC_LANG_CXX}" = "y" ]; then
316 s/^# DO_C99_MATH is not set/DO_C99_MATH=y/
317 s/^# UCLIBC_CTOR_DTOR is not set/UCLIBC_CTOR_DTOR=y/
318 s/^# UCLIBC_HAS_GNU_GETOPT is not set/UCLIBC_HAS_GNU_GETOPT=y/
322 # Always build the libpthread_db
324 s/^# PTHREADS_DEBUG_SUPPORT is not set.*/PTHREADS_DEBUG_SUPPORT=y/
327 # Force on debug options if asked for
328 case "${CT_LIBC_UCLIBC_DEBUG_LEVEL}" in
331 s/^DODEBUG=y/# DODEBUG is not set/
332 s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
333 s/^DOASSERTS=y/# DOASSERTS is not set/
334 s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
335 s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
336 s/^UCLIBC_MALLOC_DEBUGGING=y/# UCLIBC_MALLOC_DEBUGGING is not set/
341 s/^# DODEBUG is not set.*/DODEBUG=y/
342 s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
343 s/^DOASSERTS=y/# DOASSERTS is not set/
344 s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
345 s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
346 s/^UCLIBC_MALLOC_DEBUGGING=y/# UCLIBC_MALLOC_DEBUGGING is not set/
351 s/^# DODEBUG is not set.*/DODEBUG=y/
352 s/^# DODEBUG_PT is not set.*/DODEBUG_PT=y/
353 s/^# DOASSERTS is not set.*/DOASSERTS=y/
354 s/^# SUPPORT_LD_DEBUG is not set.*/SUPPORT_LD_DEBUG=y/
355 s/^# SUPPORT_LD_DEBUG_EARLY is not set.*/SUPPORT_LD_DEBUG_EARLY=y/
356 s/^# UCLIBC_MALLOC_DEBUGGING is not set/UCLIBC_MALLOC_DEBUGGING=y/
361 # And now, this is the end
364 sed -r -f "${munge_file}" "${src_config_file}" >"${dst_config_file}"