1 # This file contains the functions common to glibc and eglibc
3 # Build and install headers file
9 # Build and install headers and start files
10 do_libc_start_files() {
11 local src_dir="${CT_SRC_DIR}/${CT_LIBC}-${CT_LIBC_VERSION}"
13 CT_DoStep INFO "Installing C library headers / start files"
15 mkdir -p "${CT_BUILD_DIR}/build-libc-startfiles"
16 cd "${CT_BUILD_DIR}/build-libc-startfiles"
18 CT_DoLog EXTRA "Configuring C library"
22 if [ "${CT_EGLIBC_CUSTOM_CONFIG}" = "y" ]; then
23 CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/eglibc.config" option-groups.config
28 cross_cc=$(CT_Which "${CT_TARGET}-gcc")
29 cross_cxx=$(CT_Which "${CT_TARGET}-g++")
30 cross_ar=$(CT_Which "${CT_TARGET}-ar")
31 cross_ranlib=$(CT_Which "${CT_TARGET}-ranlib")
33 CT_DoLog DEBUG "Using gcc for target: '${cross_cc}'"
34 CT_DoLog DEBUG "Using g++ for target: '${cross_cxx}'"
35 CT_DoLog DEBUG "Using ar for target: '${cross_ar}'"
36 CT_DoLog DEBUG "Using ranlib for target: '${cross_ranlib}'"
38 BUILD_CC="${CT_BUILD}-gcc" \
42 RANLIB=${cross_ranlib} \
44 "${src_dir}/configure" \
46 --with-headers="${CT_HEADERS_DIR}" \
47 --build="${CT_BUILD}" \
48 --host="${CT_TARGET}" \
54 CT_DoLog EXTRA "Installing C library headers"
56 # use the 'install-headers' makefile target to install the
59 make install-headers \
60 install_root=${CT_SYSROOT_DIR} \
61 install-bootstrap-headers=yes
63 CT_DoLog EXTRA "Installing C library start files"
65 # there are a few object files needed to link shared libraries,
66 # which we build and install by hand
67 CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/usr/lib"
68 CT_DoExecLog ALL make csu/subdir_lib
69 CT_DoExecLog ALL cp csu/crt1.o csu/crti.o csu/crtn.o \
70 "${CT_SYSROOT_DIR}/usr/lib"
72 # Finally, 'libgcc_s.so' requires a 'libc.so' to link against.
73 # However, since we will never actually execute its code,
74 # it doesn't matter what it contains. So, treating '/dev/null'
75 # as a C source file, we produce a dummy 'libc.so' in one step
76 CT_DoExecLog ALL "${cross_cc}" -nostdlib \
80 -o "${CT_SYSROOT_DIR}/usr/lib/libc.so"
85 # This function builds and install the full C library
87 local src_dir="${CT_SRC_DIR}/${CT_LIBC}-${CT_LIBC_VERSION}"
89 local -a extra_make_args
91 CT_DoStep INFO "Installing C library"
93 mkdir -p "${CT_BUILD_DIR}/build-libc"
94 cd "${CT_BUILD_DIR}/build-libc"
96 CT_DoLog EXTRA "Configuring C library"
100 if [ "${CT_EGLIBC_CUSTOM_CONFIG}" = "y" ]; then
101 CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/eglibc.config" option-groups.config
103 if [ "${CT_EGLIBC_OPT_SIZE}" = "y" ]; then
111 # Add some default glibc config options if not given by user.
112 # We don't need to be conditional on wether the user did set different
113 # values, as they CT_LIBC_GLIBC_EXTRA_CONFIG is passed after extra_config
115 extra_config+=("--enable-kernel=$(echo ${CT_LIBC_GLIBC_MIN_KERNEL} |sed -r -e 's/^([^.]+\.[^.]+\.[^.]+)(|\.[^.]+)$/\1/;')")
117 case "${CT_THREADS}" in
118 nptl) extra_config+=("--with-__thread" "--with-tls");;
119 linuxthreads) extra_config+=("--with-__thread" "--without-tls" "--without-nptl");;
120 none) extra_config+=("--without-__thread" "--without-nptl")
121 case "${CT_LIBC_GLIBC_EXTRA_CONFIG}" in
123 *) extra_config+=("--without-tls");;
128 case "${CT_SHARED_LIBS}" in
129 y) extra_config+=("--enable-shared");;
130 *) extra_config+=("--disable-shared");;
133 case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
134 y,) extra_config+=("--with-fp");;
135 ,y) extra_config+=("--without-fp");;
138 if [ "${CT_LIBC_DISABLE_VERSIONING}" = "y" ]; then
139 extra_config+=("--disable-versioning")
142 if [ "${CT_LIBC_OLDEST_ABI}" != "" ]; then
143 extra_config+=("--enable-oldest-abi=${CT_LIBC_OLDEST_ABI}")
146 case "$(do_libc_add_ons_list ,)" in
148 *) extra_config+=("--enable-add-ons=$(do_libc_add_ons_list ,)");;
151 extra_cc_args="${extra_cc_args} ${CT_ARCH_ENDIAN_OPT}"
153 cross_cc=$(CT_Which "${CT_TARGET}-gcc")
155 CT_DoLog DEBUG "Using gcc for target: '${cross_cc}'"
156 CT_DoLog DEBUG "Configuring with addons : '$(do_libc_add_ons_list ,)'"
157 CT_DoLog DEBUG "Extra config args passed: '${extra_config[*]}'"
158 CT_DoLog DEBUG "Extra CC args passed : '${extra_cc_args}'"
160 # ./configure is mislead by our tools override wrapper for bash
161 # so just tell it where the real bash is _on_the_target_!
163 # - ${ac_cv_path_BASH_SHELL} is only used to set BASH_SHELL
164 # - ${BASH_SHELL} is only used to set BASH
165 # - ${BASH} is only used to set the shebang
166 # in two scripts to run on the target
167 # So we can safely bypass bash detection at compile time.
168 # Should this change in a future eglibc release, we'd better
169 # directly mangle the generated scripts _after_ they get built,
170 # or even after they get installed... eglibc is such a sucker...
171 echo "ac_cv_path_BASH_SHELL=/bin/bash" >config.cache
173 BUILD_CC="${CT_BUILD}-gcc" \
174 CFLAGS="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} ${OPTIMIZE}" \
175 CC="${CT_TARGET}-gcc ${CT_LIBC_EXTRA_CC_ARGS} ${extra_cc_args}" \
177 RANLIB=${CT_TARGET}-ranlib \
179 "${src_dir}/configure" \
181 --with-headers="${CT_HEADERS_DIR}" \
182 --build=${CT_BUILD} \
183 --host=${CT_TARGET} \
187 --cache-file=config.cache \
188 "${extra_config[@]}" \
189 ${CT_LIBC_GLIBC_EXTRA_CONFIG}
191 CT_DoLog EXTRA "Building C library"
196 case "${CT_ARCH},${CT_ARCH_CPU}" in
198 # http://sourceware.org/ml/crossgcc/2008-10/msg00068.html
199 CT_DoLog DEBUG "Activating support for memset on broken ppc-8xx (CPU15 erratum)"
200 extra_make_args+=( ASFLAGS="-DBROKEN_PPC_8xx_CPU15" )
206 CT_DoExecLog ALL make -j${CT_PARALLEL_JOBS} "${extra_make_args[@]}"
208 CT_DoLog EXTRA "Installing C library"
210 CT_DoExecLog ALL make install "${extra_make_args[@]}" install_root="${CT_SYSROOT_DIR}"
215 # This function finishes the C library install
221 # Build up the addons list, separated with $1
222 do_libc_add_ons_list() {
224 local addons_list=$(echo "${CT_LIBC_ADDONS_LIST//,/${sep}}" |tr -s ,)
225 case "${CT_THREADS}" in
227 *) addons_list="${addons_list}${sep}${CT_THREADS}";;
229 [ "${CT_LIBC_GLIBC_USE_PORTS}" = "y" ] && addons_list="${addons_list}${sep}ports"
230 addons_list="${addons_list%%${sep}}"
231 echo "${addons_list##${sep}}"