1 # eglibc build functions (initially by Thomas JOURDAN).
3 # Download eglibc repository
7 case "${CT_LIBC_VERSION}" in
8 trunk) svn_url="svn://svn.eglibc.org/trunk";;
9 *) svn_url="svn://svn.eglibc.org/branches/eglibc-${CT_LIBC_VERSION}";;
12 case "${CT_EGLIBC_CHECKOUT}" in
13 y) svn_action="checkout";;
14 *) svn_action="export --force";;
17 CT_DoExecLog ALL svn ${svn_action} -r "${CT_EGLIBC_REVISION:-HEAD}" "${svn_url}" . 2>&1
20 CT_DoExecLog ALL mv libc "eglibc-${CT_LIBC_VERSION}"
21 CT_DoExecLog ALL tar cjf "eglibc-${CT_LIBC_VERSION}.tar.bz2" "eglibc-${CT_LIBC_VERSION}"
23 # Compress linuxthreads, localedef and ports
24 # Assign them the name the way ct-ng like it
25 for addon in linuxthreads localedef ports; do
26 CT_DoExecLog ALL mv "${addon}" "eglibc-${addon}-${CT_LIBC_VERSION}"
27 CT_DoExecLog ALL tar cjf "eglibc-${addon}-${CT_LIBC_VERSION}.tar.bz2" "eglibc-${addon}-${CT_LIBC_VERSION}"
33 # eglibc is only available through subversion, there are no
34 # snapshots available. Moreover, addons will be downloaded
38 eglibc="eglibc-${CT_LIBC_VERSION}.tar.bz2"
39 eglibc_linuxthreads="${CT_LIBC}-linuxthreads-${CT_LIBC_VERSION}.tar.bz2"
40 eglibc_localedef="${CT_LIBC}-localedef-${CT_LIBC_VERSION}.tar.bz2"
41 eglibc_ports="${CT_LIBC}-ports-${CT_LIBC_VERSION}.tar.bz2"
43 # Check if every tarballs are already present
44 if [ -f "${CT_TARBALLS_DIR}/${eglibc}" \
45 -a -f "${CT_TARBALLS_DIR}/${eglibc_linuxthreads}" \
46 -a -f "${CT_TARBALLS_DIR}/${eglibc_localedef}" \
47 -a -f "${CT_TARBALLS_DIR}/${eglibc_ports}" \
49 CT_DoLog DEBUG "Already have 'eglibc-${CT_LIBC_VERSION}'"
53 if [ -f "${CT_LOCAL_TARBALLS_DIR}/${eglibc}" \
54 -a -f "${CT_LOCAL_TARBALLS_DIR}/${eglibc_linuxthreads}" \
55 -a -f "${CT_LOCAL_TARBALLS_DIR}/${eglibc_localedef}" \
56 -a -f "${CT_LOCAL_TARBALLS_DIR}/${eglibc_ports}" \
57 -a "${CT_FORCE_DOWNLOAD}" != "y" \
59 CT_DoLog DEBUG "Got 'eglibc-${CT_LIBC_VERSION}' from local storage"
60 for file in ${eglibc} ${eglibc_linuxthreads} ${eglibc_localedef} ${eglibc_ports}; do
61 CT_DoExecLog ALL ln -s "${CT_LOCAL_TARBALLS_DIR}/${file}" "${CT_TARBALLS_DIR}/${file}"
66 # Not found locally, try from the network
67 CT_DoLog EXTRA "Retrieving 'eglibc-${CT_LIBC_VERSION}'"
73 CT_DoLog DEBUG "Moving 'eglibc-${CT_LIBC_VERSION}' to tarball directory"
74 for file in ${eglibc} ${eglibc_linuxthreads} ${eglibc_localedef} ${eglibc_ports}; do
75 CT_DoExecLog ALL mv -f "${file}" "${CT_TARBALLS_DIR}"
81 CT_DoExecLog ALL rm -rf "${tmp_dir}"
83 if [ "${CT_SAVE_TARBALLS}" = "y" ]; then
84 CT_DoLog EXTRA "Saving 'eglibc-${CT_LIBC_VERSION}' to local storage"
85 for file in ${eglibc} ${eglibc_linuxthreads} ${eglibc_localedef} ${eglibc_ports}; do
86 CT_DoExecLog ALL mv -f "${CT_TARBALLS_DIR}/${file}" "${CT_LOCAL_TARBALLS_DIR}"
87 CT_DoExecLog ALL ln -s "${CT_LOCAL_TARBALLS_DIR}/${file}" "${CT_TARBALLS_DIR}/${file}"
96 CT_Extract "eglibc-${CT_LIBC_VERSION}"
97 CT_Patch "eglibc-${CT_LIBC_VERSION}"
100 for addon in $(do_libc_add_ons_list " "); do
101 # NPTL addon is not to be extracted, in any case
102 [ "${addon}" = "nptl" ] && continue || true
103 CT_Pushd "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}"
104 CT_Extract "eglibc-${addon}-${CT_LIBC_VERSION}" nochdir
105 # Some addons have the 'long' name, while others have the
106 # 'short' name, but patches are non-uniformly built with
107 # either the 'long' or 'short' name, whatever the addons name
108 # so we have to make symlinks from the existing to the missing
109 # Fortunately for us, [ -d foo ], when foo is a symlink to a
110 # directory, returns true!
111 [ -d "${addon}" ] || ln -s "eglibc-${addon}-${CT_LIBC_VERSION}" "${addon}"
112 [ -d "eglibc-${addon}-${CT_LIBC_VERSION}" ] || ln -s "${addon}" "eglibc-${addon}-${CT_LIBC_VERSION}"
113 CT_Patch "eglibc-${addon}-${CT_LIBC_VERSION}" nochdir
117 # The configure files may be older than the configure.in files
118 # if using a snapshot (or even some tarballs). Fake them being
120 find "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}" -type f -name configure -exec touch {} \; 2>&1 |CT_DoLog ALL
125 # Copy user provided eglibc configuration file if provided
126 do_libc_check_config() {
127 if [ "${CT_EGLIBC_CUSTOM_CONFIG}" != "y" ]; then
131 CT_DoStep INFO "Checking C library configuration"
133 CT_TestOrAbort "You did not provide an eglibc config file!" \
134 -n "${CT_EGLIBC_OPTION_GROUPS_FILE}" -a \
135 -f "${CT_EGLIBC_OPTION_GROUPS_FILE}"
137 CT_DoExecLog ALL cp "${CT_EGLIBC_OPTION_GROUPS_FILE}" "${CT_CONFIG_DIR}/eglibc.config"
140 if grep -E '^OPTION_EGLIBC_NSSWITCH[[:space:]]*=[[:space:]]*n' "${CT_EGLIBC_OPTION_GROUPS_FILE}" >/dev/null 2>&1; then
141 CT_DoLog DEBUG "Using fixed-configuration nsswitch facility"
143 if [ "${CT_EGLIBC_BUNDLED_NSS_CONFIG}" = "y" ]; then
144 nss_config="${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}/nss/fixed-nsswitch.conf"
146 nss_config="${CT_EGLIBC_NSS_CONFIG_FILE}"
148 CT_TestOrAbort "NSS config file not found!" -n "${nss_config}" -a -f "${nss_config}"
150 CT_DoExecLog ALL cp "${nss_config}" "${CT_CONFIG_DIR}/nsswitch.config"
151 echo "OPTION_EGLIBC_NSSWITCH_FIXED_CONFIG = ${CT_CONFIG_DIR}/nsswitch.config" \
152 >> "${CT_CONFIG_DIR}/eglibc.config"
154 if [ "${CT_EGLIBC_BUNDLED_NSS_FUNCTIONS}" = "y" ]; then
155 nss_functions="${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}/nss/fixed-nsswitch.functions"
157 nss_functions="${CT_EGLIBC_NSS_FUNCTIONS_FILE}"
159 CT_TestOrAbort "NSS functions file not found!" -n "${nss_functions}" -a -f "${nss_functions}"
161 CT_DoExecLog ALL cp "${nss_functions}" "${CT_CONFIG_DIR}/nsswitch.functions"
162 echo "OPTION_EGLIBC_NSSWITCH_FIXED_FUNCTIONS = ${CT_CONFIG_DIR}/nsswitch.functions" \
163 >> "${CT_CONFIG_DIR}/eglibc.config"
165 CT_DoLog DEBUG "Using full-blown nsswitch facility"
171 # This function installs the eglibc headers needed to build the core compiler
173 # Instead of doing two time the same actions, headers will
174 # be installed with start files
178 # Build and install start files
179 do_libc_start_files() {
180 CT_DoStep INFO "Installing C library headers / start files"
182 mkdir -p "${CT_BUILD_DIR}/build-libc-startfiles"
183 cd "${CT_BUILD_DIR}/build-libc-startfiles"
185 CT_DoLog EXTRA "Configuring C library"
187 if [ "${CT_EGLIBC_CUSTOM_CONFIG}" = "y" ]; then
188 CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/eglibc.config" option-groups.config
191 cross_cc=$(CT_Which "${CT_TARGET}-gcc")
192 cross_cxx=$(CT_Which "${CT_TARGET}-g++")
193 cross_ar=$(CT_Which "${CT_TARGET}-ar")
194 cross_ranlib=$(CT_Which "${CT_TARGET}-ranlib")
196 CT_DoLog DEBUG "Using gcc for target: '${cross_cc}'"
197 CT_DoLog DEBUG "Using g++ for target: '${cross_cxx}'"
198 CT_DoLog DEBUG "Using ar for target: '${cross_ar}'"
199 CT_DoLog DEBUG "Using ranlib for target: '${cross_ranlib}'"
201 BUILD_CC="${CT_BUILD}-gcc" \
205 RANLIB=${cross_ranlib} \
207 "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}/configure" \
209 --with-headers="${CT_HEADERS_DIR}" \
210 --build="${CT_BUILD}" \
211 --host="${CT_TARGET}" \
217 CT_DoLog EXTRA "Installing C library headers"
219 # use the 'install-headers' makefile target to install the
223 make install-headers \
224 install_root=${CT_SYSROOT_DIR} \
225 install-bootstrap-headers=yes
227 CT_DoLog EXTRA "Installing C library start files"
229 # there are a few object files needed to link shared libraries,
230 # which we build and install by hand
232 CT_DoExecLog ALL mkdir -p ${CT_SYSROOT_DIR}/usr/lib
233 CT_DoExecLog ALL make csu/subdir_lib
234 CT_DoExecLog ALL cp csu/crt1.o csu/crti.o csu/crtn.o \
235 ${CT_SYSROOT_DIR}/usr/lib
237 # Finally, 'libgcc_s.so' requires a 'libc.so' to link against.
238 # However, since we will never actually execute its code,
239 # it doesn't matter what it contains. So, treating '/dev/null'
240 # as a C source file, we produce a dummy 'libc.so' in one step
242 CT_DoExecLog ALL ${cross_cc} -nostdlib -nostartfiles -shared -x c /dev/null -o ${CT_SYSROOT_DIR}/usr/lib/libc.so
247 # This function builds and install the full glibc
249 local -a extra_config
251 CT_DoStep INFO "Installing C library"
253 mkdir -p "${CT_BUILD_DIR}/build-libc"
254 cd "${CT_BUILD_DIR}/build-libc"
256 CT_DoLog EXTRA "Configuring C library"
258 if [ "${CT_EGLIBC_CUSTOM_CONFIG}" = "y" ]; then
259 CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/eglibc.config" option-groups.config
262 # Add some default glibc config options if not given by user.
263 # We don't need to be conditional on wether the user did set different
264 # values, as they CT_LIBC_GLIBC_EXTRA_CONFIG is passed after extra_config
266 extra_config+=("--enable-kernel=$(echo ${CT_LIBC_GLIBC_MIN_KERNEL} |sed -r -e 's/^([^.]+\.[^.]+\.[^.]+)(|\.[^.]+)$/\1/;')")
268 case "${CT_THREADS}" in
269 nptl) extra_config+=("--with-__thread" "--with-tls");;
270 linuxthreads) extra_config+=("--with-__thread" "--without-tls" "--without-nptl");;
271 none) extra_config+=("--without-__thread" "--without-nptl")
272 case "${CT_LIBC_GLIBC_EXTRA_CONFIG}" in
274 *) extra_config+=("--without-tls");;
279 case "${CT_SHARED_LIBS}" in
280 y) extra_config+=("--enable-shared");;
281 *) extra_config+=("--disable-shared");;
284 case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
285 y,) extra_config+=("--with-fp");;
286 ,y) extra_config+=("--without-fp");;
289 case "$(do_libc_add_ons_list ,)" in
291 *) extra_config+=("--enable-add-ons=$(do_libc_add_ons_list ,)");;
294 extra_cc_args="${extra_cc_args} ${CT_ARCH_ENDIAN_OPT}"
296 cross_cc=$(CT_Which "${CT_TARGET}-gcc")
298 CT_DoLog DEBUG "Using gcc for target: '${cross_cc}'"
299 CT_DoLog DEBUG "Configuring with addons : '$(do_libc_add_ons_list ,)'"
300 CT_DoLog DEBUG "Extra config args passed: '${extra_config[*]}'"
301 CT_DoLog DEBUG "Extra CC args passed : '${extra_cc_args}'"
303 BUILD_CC="${CT_BUILD}-gcc" \
304 CFLAGS="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} -O2" \
305 CC="${CT_TARGET}-gcc ${CT_LIBC_EXTRA_CC_ARGS} ${extra_cc_args}" \
307 RANLIB=${CT_TARGET}-ranlib \
309 "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}/configure" \
311 --with-headers="${CT_HEADERS_DIR}" \
312 --build=${CT_BUILD} \
313 --host=${CT_TARGET} \
317 "${extra_config[@]}" \
318 ${CT_LIBC_GLIBC_EXTRA_CONFIG}
320 CT_DoLog EXTRA "Building C library"
323 # http://sourceware.org/ml/crossgcc/2008-10/msg00068.html
324 case "${CT_ARCH},${CT_ARCH_CPU}" in
326 CT_DoLog DEBUG "Activating support for memset on broken ppc-8xx (CPU15 erratum)"
327 EGLIBC_BUILD_ASFLAGS="-DBROKEN_PPC_8xx_CPU15";;
330 CT_DoExecLog ALL make ASFLAGS="${EGLIBC_BUILD_ASFLAGS}"
332 CT_DoLog EXTRA "Installing C library"
334 CT_DoExecLog ALL make install install_root="${CT_SYSROOT_DIR}"
339 # This function finishes the glibc install
341 # Nothing to be done for eglibc
345 # Build up the addons list, separated with $1
346 do_libc_add_ons_list() {
348 local addons_list=$(echo "${CT_LIBC_ADDONS_LIST//,/${sep}}" |tr -s ,)
349 case "${CT_THREADS}" in
351 *) addons_list="${addons_list}${sep}${CT_THREADS}";;
353 [ "${CT_LIBC_GLIBC_USE_PORTS}" = "y" ] && addons_list="${addons_list}${sep}ports"
354 addons_list="${addons_list%%${sep}}"
355 echo "${addons_list##${sep}}"