Once in a while I write some documentation... Not often enough...
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
6 # Check that uClibc has been previously configured
7 do_libc_check_config() {
8 CT_DoStep INFO "Checking C library configuration"
10 CT_TestOrAbort "You did not provide a uClibc config file!" -n "${CT_LIBC_UCLIBC_CONFIG_FILE}" -a -f "${CT_LIBC_UCLIBC_CONFIG_FILE}"
12 cp "${CT_LIBC_UCLIBC_CONFIG_FILE}" "${CT_BUILD_DIR}/uClibc.config"
14 if egrep '^KERNEL_SOURCE=' "${CT_LIBC_UCLIBC_CONFIG_FILE}" >/dev/null 2>&1; then
15 CT_DoLog WARN "Your uClibc version refers to the kernel _sources_, which is bad."
16 CT_DoLog WARN "I can't guarantee that our little hack will work. Please try to upgrade."
19 CT_DoLog EXTRA "Munging uClibc configuration"
20 mungeuClibcConfig "${CT_BUILD_DIR}/uClibc.config"
25 # This functions installs uClibc's headers
27 # Only need to install bootstrap uClibc headers for gcc-3.0 and above? Or maybe just gcc-3.3 and above?
28 # See also http://gcc.gnu.org/PR8180, which complains about the need for this step.
29 grep -q 'gcc-[34]' "${CT_SRC_DIR}/${CT_CC_CORE_FILE}/ChangeLog" || return 0
31 CT_DoStep INFO "Installing C library headers"
33 mkdir -p "${CT_BUILD_DIR}/build-libc-headers"
34 cd "${CT_BUILD_DIR}/build-libc-headers"
36 # Simply copy files until uClibc has the ablity to build out-of-tree
37 CT_DoLog EXTRA "Copying sources to build dir"
38 { cd "${CT_SRC_DIR}/${CT_LIBC_FILE}"; tar cf - .; } |tar xf -
40 # Retrieve the config file
41 cp "${CT_BUILD_DIR}/uClibc.config" .config
43 # uClibc uses the CROSS environment variable as a prefix to the
44 # compiler tools to use. Setting it to the empty string forces
45 # use of the native build host tools, which we need at this
46 # stage, as we don't have target tools yet.
47 CT_DoLog EXTRA "Applying configuration"
48 CT_DoYes "" |make CROSS= PREFIX="${CT_SYSROOT_DIR}/" oldconfig 2>&1 |CT_DoLog DEBUG
50 CT_DoLog EXTRA "Building headers"
51 make ${PARALLELMFLAGS} CROSS= PREFIX="${CT_SYSROOT_DIR}/" headers 2>&1 |CT_DoLog DEBUG
53 CT_DoLog EXTRA "Installing headers"
54 make CROSS= PREFIX="${CT_SYSROOT_DIR}/" install_dev 2>&1 |CT_DoLog DEBUG
59 # This function build and install the full uClibc
61 CT_DoStep INFO "Installing C library"
63 mkdir -p "${CT_BUILD_DIR}/build-libc"
64 cd "${CT_BUILD_DIR}/build-libc"
66 # Simply copy files until uClibc has the ablity to build out-of-tree
67 CT_DoLog EXTRA "Copying sources to build dir"
68 { cd "${CT_SRC_DIR}/${CT_LIBC_FILE}"; tar cf - .; } |tar xf -
70 # Retrieve the config file
71 cp "${CT_BUILD_DIR}/uClibc.config" .config
73 # uClibc uses the CROSS environment variable as a prefix to the compiler
74 # tools to use. The newly built tools should be in our path, so we need
75 # only give the correct name for them.
76 # Note about CFLAGS: In uClibc, CFLAGS are generated by Rules.mak,
77 # depending on the configuration of the library. That is, they are tailored
78 # to best fit the target. So it is useless and seems to be a bad thing to
79 # use LIBC_EXTRA_CFLAGS here.
80 CT_DoLog EXTRA "Applying configuration"
81 CT_DoYes "" |make ${PARALLELMFLAGS} \
83 PREFIX="${CT_SYSROOT_DIR}/" \
84 oldconfig 2>&1 |CT_DoLog DEBUG
86 # We do _not_ want to strip anything for now, in case we specifically
87 # asked for a debug toolchain, thus the STRIPTOOL= assignment
88 CT_DoLog EXTRA "Building C library"
89 make ${PARALLELMFLAGS} \
91 PREFIX="${CT_SYSROOT_DIR}/" \
93 all 2>&1 |CT_DoLog DEBUG
95 # YEM-FIXME: we want to install libraries in $SYSROOT/lib, but we don't want
96 # to install headers in $SYSROOT/include, thus making only install_runtime.
97 # Plus, the headers were previously installed earlier with install_dev, so
98 # all should be well. Unfortunately, the install_dev target does not install
99 # crti.o and consorts... :-( So reverting to target 'install'.
100 # Note: PARALLELMFLAGS is not usefull for installation.
101 # We do _not_ want to strip anything for now, in case we specifically
102 # asked for a debug toolchain, thus the STRIPTOOL= assignment
103 CT_DoLog EXTRA "Installing C library"
104 make CROSS=${CT_TARGET}- \
105 PREFIX="${CT_SYSROOT_DIR}/" \
107 install 2>&1 |CT_DoLog DEBUG
112 # This function is used to install those components needing the final C compiler
114 CT_DoStep INFO "Finishing C library"
115 # uClibc has nothing to finish
116 CT_DoLog EXTRA "uClibc has nothing to finish"
120 # Initialises the .config file to sensible values
121 mungeuClibcConfig() {
123 munge_file="${CT_BUILD_DIR}/munge-uClibc-config.sed"
125 cat > "${munge_file}" <<-ENDSED
126 s/^(TARGET_.*)=y$/# \\1 is not set/
127 s/^# TARGET_${CT_KERNEL_ARCH} is not set/TARGET_${CT_KERNEL_ARCH}=y/
128 s/^TARGET_ARCH=".*"/TARGET_ARCH="${CT_KERNEL_ARCH}"/
131 case "${CT_ARCH_BE},${CT_ARCH_LE}" in
132 y,) cat >> "${munge_file}" <<-ENDSED
133 s/.*(ARCH_BIG_ENDIAN).*/\\1=y/
134 s/.*(ARCH_LITTLE_ENDIAN).*/# \\1 is not set/
137 ,y) cat >> "${munge_file}" <<-ENDSED
138 s/.*(ARCH_BIG_ENDIAN).*/# \\1 is not set/
139 s/.*(ARCH_LITTLE_ENDIAN).*/\\1=y/
144 case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
145 y,) cat >> "${munge_file}" <<-ENDSED
146 s/.*(HAS_FPU).*/\\1=y/
149 ,y) cat >> "${munge_file}" <<-ENDSED
150 s/.*(HAS_FPU).*/\\# \\1 is not set/
155 # Change paths to work with crosstool
156 # From http://www.uclibc.org/cgi-bin/viewcvs.cgi?rev=16846&view=rev
157 # " we just want the kernel headers, not the whole kernel source ...
158 # " so people may need to update their paths slightly
159 quoted_kernel_source=`echo "${CT_HEADERS_DIR}" | sed -r -e 's,/include/?$,,; s,/,\\\\/,g;'`
160 quoted_headers_dir=`echo ${CT_HEADERS_DIR} | sed -r -e 's,/,\\\\/,g;'`
161 # CROSS_COMPILER_PREFIX is left as is, as the CROSS parameter is forced on the command line
162 # DEVEL_PREFIX is left as '/usr/' because it is post-pended to $PREFIX, wich is the correct value of ${PREFIX}/${TARGET}
163 # Some (old) versions of uClibc use KERNEL_SOURCE (which is _wrong_), and
164 # newer versions use KERNEL_HEADERS (which is right). See:
165 cat >> "${munge_file}" <<-ENDSED
166 s/^DEVEL_PREFIX=".*"/DEVEL_PREFIX="\\/usr\\/"/
167 s/^RUNTIME_PREFIX=".*"/RUNTIME_PREFIX="\\/"/
168 s/^SHARED_LIB_LOADER_PREFIX=.*/SHARED_LIB_LOADER_PREFIX="\\/lib\\/"/
169 s/^KERNEL_SOURCE=".*"/KERNEL_SOURCE="${quoted_kernel_source}"/
170 s/^KERNEL_HEADERS=".*"/KERNEL_HEADERS="${quoted_headers_dir}"/
171 s/^UCLIBC_DOWNLOAD_PREGENERATED_LOCALE=y/\\# UCLIBC_DOWNLOAD_PREGENERATED_LOCALE is not set/
174 # Hack our -pipe into WARNINGS, which will be internally incorporated to
175 # CFLAGS. This a dirty hack, but yet needed
176 if [ "${CT_USE_PIPES}" = "y" ]; then
177 cat >> "${munge_file}" <<-ENDSED
178 s/^(WARNINGS=".*)"$/\\1 -pipe"/
182 # Force on options needed for C++ if we'll be making a C++ compiler.
183 # Note that the two PREGEN_LOCALE and the XLOCALE lines may be missing
184 # entirely if LOCALE is not set. If LOCALE was already set, we'll
185 # assume the user has already made all the appropriate generation
186 # arrangements. Note that having the uClibc Makefile download the
187 # pregenerated locales is not compatible with crosstool; besides,
188 # crosstool downloads them as part of getandpatch.sh.
189 if [ "${CT_CC_LANG_CXX}" = "y" ]; then
190 cat >> "${munge_file}" <<-ENDSED
191 s/^# DO_C99_MATH is not set/DO_C99_MATH=y/
192 s/^# UCLIBC_CTOR_DTOR is not set/UCLIBC_CTOR_DTOR=y/
193 # Add these three lines when doing C++?
194 #s/^# UCLIBC_HAS_WCHAR is not set/UCLIBC_HAS_WCHAR=y/
195 #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/
196 #s/^# UCLIBC_HAS_GNU_GETOPT is not set/UCLIBC_HAS_GNU_GETOPT=y/
200 # Force on debug options if asked for
201 case "${CT_LIBC_UCLIBC_DEBUG_LEVEL}" in
203 cat >>"${munge_file}" <<-ENDSED
204 s/^PTHREADS_DEBUG_SUPPORT=y/# PTHREADS_DEBUG_SUPPORT is not set/
205 s/^DODEBUG=y/# DODEBUG is not set/
206 s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
207 s/^DOASSERTS=y/# DOASSERTS is not set/
208 s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
209 s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
213 cat >>"${munge_file}" <<-ENDSED
214 s/^# PTHREADS_DEBUG_SUPPORT is not set.*/PTHREADS_DEBUG_SUPPORT=y/
215 s/^# DODEBUG is not set.*/DODEBUG=y/
216 s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
217 s/^DOASSERTS=y/# DOASSERTS is not set/
218 s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
219 s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
223 cat >>"${munge_file}" <<-ENDSED
224 s/^# PTHREADS_DEBUG_SUPPORT is not set.*/PTHREADS_DEBUG_SUPPORT=y/
225 s/^# DODEBUG is not set.*/DODEBUG=y/
226 s/^# DODEBUG_PT is not set.*/DODEBUG_PT=y/
227 s/^# DOASSERTS is not set.*/DOASSERTS=y/
228 s/^# SUPPORT_LD_DEBUG is not set.*/SUPPORT_LD_DEBUG=y/
229 s/^# SUPPORT_LD_DEBUG_EARLY is not set.*/SUPPORT_LD_DEBUG_EARLY=y/
233 sed -r -i -f "${munge_file}" "${config_file}"
234 rm -f "${munge_file}"