Offer an option to build the gdbserver statically. This helps in case of debugging shared library loading.
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 [ "${CT_LIBC}" = "uClibc" ] || return 0
7 echo "uClibc-${CT_LIBC_VERSION}"
8 [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ] && echo "uClibc-locale-030818" || true
13 libc_src="http://www.uclibc.org/downloads
14 http://www.uclibc.org/downloads/snapshots
15 http://www.uclibc.org/downloads/old-releases"
16 # For uClibc, we have almost every thing: releases, and snapshots
17 # for the last month or so. We'll have to deal with svn revisions
19 CT_GetFile "${CT_LIBC_FILE}" ${libc_src}
21 [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ] && CT_GetFile "uClibc-locale-030818" ${libc_src} || true
28 CT_ExtractAndPatch "${CT_LIBC_FILE}"
30 [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ] && CT_ExtractAndPatch "uClibc-locale-030818" || true
35 # Check that uClibc has been previously configured
36 do_libc_check_config() {
37 CT_DoStep INFO "Checking C library configuration"
39 CT_TestOrAbort "You did not provide a uClibc config file!" -n "${CT_LIBC_UCLIBC_CONFIG_FILE}" -a -f "${CT_LIBC_UCLIBC_CONFIG_FILE}"
41 cp "${CT_LIBC_UCLIBC_CONFIG_FILE}" "${CT_SRC_DIR}/uClibc.config"
43 if egrep '^KERNEL_SOURCE=' "${CT_LIBC_UCLIBC_CONFIG_FILE}" >/dev/null 2>&1; then
44 CT_DoLog WARN "Your uClibc version refers to the kernel _sources_, which is bad."
45 CT_DoLog WARN "I can't guarantee that our little hack will work. Please try to upgrade."
48 CT_DoLog EXTRA "Munging uClibc configuration"
49 mungeuClibcConfig "${CT_SRC_DIR}/uClibc.config"
54 # This functions installs uClibc's headers
56 # Only need to install bootstrap uClibc headers for gcc-3.0 and above? Or maybe just gcc-3.3 and above?
57 # See also http://gcc.gnu.org/PR8180, which complains about the need for this step.
58 grep -q 'gcc-[34]' "${CT_SRC_DIR}/${CT_CC_CORE_FILE}/ChangeLog" || return 0
60 CT_DoStep INFO "Installing C library headers"
62 mkdir -p "${CT_BUILD_DIR}/build-libc-headers"
63 cd "${CT_BUILD_DIR}/build-libc-headers"
65 # Simply copy files until uClibc has the ablity to build out-of-tree
66 CT_DoLog EXTRA "Copying sources to build dir"
67 { cd "${CT_SRC_DIR}/${CT_LIBC_FILE}"; tar cf - .; } |tar xf -
69 # Retrieve the config file
70 cp "${CT_SRC_DIR}/uClibc.config" .config
72 # uClibc uses the CROSS environment variable as a prefix to the
73 # compiler tools to use. Setting it to the empty string forces
74 # use of the native build host tools, which we need at this
75 # stage, as we don't have target tools yet.
76 CT_DoLog EXTRA "Applying configuration"
77 CT_DoYes "" |make CROSS= PREFIX="${CT_SYSROOT_DIR}/" oldconfig 2>&1 |CT_DoLog ALL
79 CT_DoLog EXTRA "Building headers"
80 make ${PARALLELMFLAGS} CROSS= PREFIX="${CT_SYSROOT_DIR}/" headers 2>&1 |CT_DoLog ALL
82 CT_DoLog EXTRA "Installing headers"
83 make CROSS= PREFIX="${CT_SYSROOT_DIR}/" install_dev 2>&1 |CT_DoLog ALL
88 # Build and install start files
89 do_libc_start_files() {
93 # This function build and install the full uClibc
95 CT_DoStep INFO "Installing C library"
97 mkdir -p "${CT_BUILD_DIR}/build-libc"
98 cd "${CT_BUILD_DIR}/build-libc"
100 # Simply copy files until uClibc has the ablity to build out-of-tree
101 CT_DoLog EXTRA "Copying sources to build dir"
102 { cd "${CT_SRC_DIR}/${CT_LIBC_FILE}"; tar cf - .; } |tar xf -
104 # Retrieve the config file
105 cp "${CT_SRC_DIR}/uClibc.config" .config
107 # uClibc uses the CROSS environment variable as a prefix to the compiler
108 # tools to use. The newly built tools should be in our path, so we need
109 # only give the correct name for them.
110 # Note about CFLAGS: In uClibc, CFLAGS are generated by Rules.mak,
111 # depending on the configuration of the library. That is, they are tailored
112 # to best fit the target. So it is useless and seems to be a bad thing to
113 # use LIBC_EXTRA_CFLAGS here.
114 CT_DoLog EXTRA "Applying configuration"
115 CT_DoYes "" |make ${PARALLELMFLAGS} \
116 CROSS=${CT_TARGET}- \
117 PREFIX="${CT_SYSROOT_DIR}/" \
118 oldconfig 2>&1 |CT_DoLog ALL
120 # We do _not_ want to strip anything for now, in case we specifically
121 # asked for a debug toolchain, thus the STRIPTOOL= assignment
122 CT_DoLog EXTRA "Building C library"
123 make ${PARALLELMFLAGS} \
124 CROSS=${CT_TARGET}- \
125 PREFIX="${CT_SYSROOT_DIR}/" \
127 all 2>&1 |CT_DoLog ALL
129 # YEM-FIXME: we want to install libraries in $SYSROOT/lib, but we don't want
130 # to install headers in $SYSROOT/include, thus making only install_runtime.
131 # Plus, the headers were previously installed earlier with install_dev, so
132 # all should be well. Unfortunately, the install_dev target does not install
133 # crti.o and consorts... :-( So reverting to target 'install'.
134 # Note: PARALLELMFLAGS is not usefull for installation.
135 # We do _not_ want to strip anything for now, in case we specifically
136 # asked for a debug toolchain, thus the STRIPTOOL= assignment
137 CT_DoLog EXTRA "Installing C library"
138 make CROSS=${CT_TARGET}- \
139 PREFIX="${CT_SYSROOT_DIR}/" \
141 install 2>&1 |CT_DoLog ALL
146 # This function is used to install those components needing the final C compiler
151 # Initialises the .config file to sensible values
152 mungeuClibcConfig() {
154 munge_file="${CT_BUILD_DIR}/munge-uClibc-config.sed"
156 # Hack our target in the config file.
157 # Also remove stripping: its the responsibility of the
158 # firmware builder to strip or not.
159 cat > "${munge_file}" <<-ENDSED
160 s/^(TARGET_.*)=y$/# \\1 is not set/
161 s/^# TARGET_${CT_KERNEL_ARCH} is not set/TARGET_${CT_KERNEL_ARCH}=y/
162 s/^TARGET_ARCH=".*"/TARGET_ARCH="${CT_KERNEL_ARCH}"/
163 s/.*(DOSTRIP).*/# \\1 is not set/
166 # Accomodate for old and new uClibc versions, where the
167 # way to select between big/little endian has changed
168 case "${CT_ARCH_BE},${CT_ARCH_LE}" in
169 y,) cat >> "${munge_file}" <<-ENDSED
170 s/.*(ARCH_LITTLE_ENDIAN).*/# \\1 is not set/
171 s/.*(ARCH_BIG_ENDIAN).*/\\1=y/
172 s/.*(ARCH_WANTS_LITTLE_ENDIAN).*/# \\1 is not set/
173 s/.*(ARCH_WANTS_BIG_ENDIAN).*/\\1=y/
176 ,y) cat >> "${munge_file}" <<-ENDSED
177 s/.*(ARCH_LITTLE_ENDIAN).*/\\1=y/
178 s/.*(ARCH_BIG_ENDIAN).*/# \\1 is not set/
179 s/.*(ARCH_WANTS_LITTLE_ENDIAN).*/\\1=y/
180 s/.*(ARCH_WANTS_BIG_ENDIAN).*/# \\1 is not set/
185 # Accomodate for old and new uClibc version, where the
186 # way to select between hard/soft float has changed
187 case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
188 y,) cat >> "${munge_file}" <<-ENDSED
189 s/.*(HAS_FPU).*/\\1=y/
190 s/.*(UCLIBC_HAS_FPU).*/\\1=y/
193 ,y) cat >> "${munge_file}" <<-ENDSED
194 s/.*(HAS_FPU).*/\\# \\1 is not set/
195 s/.*(UCLIBC_HAS_FPU).*/# \\1 is not set/
200 # Change paths to work with crosstool
201 # From http://www.uclibc.org/cgi-bin/viewcvs.cgi?rev=16846&view=rev
202 # " we just want the kernel headers, not the whole kernel source ...
203 # " so people may need to update their paths slightly
204 quoted_kernel_source=`echo "${CT_HEADERS_DIR}" | sed -r -e 's,/include/?$,,; s,/,\\\\/,g;'`
205 quoted_headers_dir=`echo ${CT_HEADERS_DIR} | sed -r -e 's,/,\\\\/,g;'`
206 # CROSS_COMPILER_PREFIX is left as is, as the CROSS parameter is forced on the command line
207 # DEVEL_PREFIX is left as '/usr/' because it is post-pended to $PREFIX, wich is the correct value of ${PREFIX}/${TARGET}
208 # Some (old) versions of uClibc use KERNEL_SOURCE (which is _wrong_), and
209 # newer versions use KERNEL_HEADERS (which is right). See:
210 cat >> "${munge_file}" <<-ENDSED
211 s/^DEVEL_PREFIX=".*"/DEVEL_PREFIX="\\/usr\\/"/
212 s/^RUNTIME_PREFIX=".*"/RUNTIME_PREFIX="\\/"/
213 s/^SHARED_LIB_LOADER_PREFIX=.*/SHARED_LIB_LOADER_PREFIX="\\/lib\\/"/
214 s/^KERNEL_SOURCE=".*"/KERNEL_SOURCE="${quoted_kernel_source}"/
215 s/^KERNEL_HEADERS=".*"/KERNEL_HEADERS="${quoted_headers_dir}"/
216 s/^UCLIBC_DOWNLOAD_PREGENERATED_LOCALE=y/\\# UCLIBC_DOWNLOAD_PREGENERATED_LOCALE is not set/
219 if [ "${CT_USE_PIPES}" = "y" ]; then
220 if grep UCLIBC_EXTRA_CFLAGS extra/Configs/Config.in >/dev/null 2>&1; then
221 # Good, there is special provision for such things as -pipe!
222 cat >> "${munge_file}" <<-ENDSED
223 s/^(UCLIBC_EXTRA_CFLAGS=".*)"$/\\1 -pipe"/
226 # Hack our -pipe into WARNINGS, which will be internally incorporated to
227 # CFLAGS. This a dirty hack, but yet needed
228 cat >> "${munge_file}" <<-ENDSED
229 s/^(WARNINGS=".*)"$/\\1 -pipe"/
234 # Force on options needed for C++ if we'll be making a C++ compiler.
235 # Note that the two PREGEN_LOCALE and the XLOCALE lines may be missing
236 # entirely if LOCALE is not set. If LOCALE was already set, we'll
237 # assume the user has already made all the appropriate generation
238 # arrangements. Note that having the uClibc Makefile download the
239 # pregenerated locales is not compatible with crosstool; besides,
240 # crosstool downloads them as part of getandpatch.sh.
241 if [ "${CT_CC_LANG_CXX}" = "y" ]; then
242 cat >> "${munge_file}" <<-ENDSED
243 s/^# DO_C99_MATH is not set/DO_C99_MATH=y/
244 s/^# UCLIBC_CTOR_DTOR is not set/UCLIBC_CTOR_DTOR=y/
245 # Add these three lines when doing C++?
246 #s/^# UCLIBC_HAS_WCHAR is not set/UCLIBC_HAS_WCHAR=y/
247 #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/
248 #s/^# UCLIBC_HAS_GNU_GETOPT is not set/UCLIBC_HAS_GNU_GETOPT=y/
252 # Force on debug options if asked for
253 case "${CT_LIBC_UCLIBC_DEBUG_LEVEL}" in
255 cat >>"${munge_file}" <<-ENDSED
256 s/^PTHREADS_DEBUG_SUPPORT=y/# PTHREADS_DEBUG_SUPPORT is not set/
257 s/^DODEBUG=y/# DODEBUG is not set/
258 s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
259 s/^DOASSERTS=y/# DOASSERTS is not set/
260 s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
261 s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
262 s/^UCLIBC_MALLOC_DEBUGGING=y/# UCLIBC_MALLOC_DEBUGGING is not set/
266 cat >>"${munge_file}" <<-ENDSED
267 s/^# PTHREADS_DEBUG_SUPPORT is not set.*/PTHREADS_DEBUG_SUPPORT=y/
268 s/^# DODEBUG is not set.*/DODEBUG=y/
269 s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
270 s/^DOASSERTS=y/# DOASSERTS is not set/
271 s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
272 s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
273 s/^UCLIBC_MALLOC_DEBUGGING=y/# UCLIBC_MALLOC_DEBUGGING is not set/
277 cat >>"${munge_file}" <<-ENDSED
278 s/^# PTHREADS_DEBUG_SUPPORT is not set.*/PTHREADS_DEBUG_SUPPORT=y/
279 s/^# DODEBUG is not set.*/DODEBUG=y/
280 s/^# DODEBUG_PT is not set.*/DODEBUG_PT=y/
281 s/^# DOASSERTS is not set.*/DOASSERTS=y/
282 s/^# SUPPORT_LD_DEBUG is not set.*/SUPPORT_LD_DEBUG=y/
283 s/^# SUPPORT_LD_DEBUG_EARLY is not set.*/SUPPORT_LD_DEBUG_EARLY=y/
284 s/^# UCLIBC_MALLOC_DEBUGGING is not set/UCLIBC_MALLOC_DEBUGGING=y/
288 sed -r -i -f "${munge_file}" "${config_file}"
289 rm -f "${munge_file}"