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 "${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 # There is nothing to do for eglibc check config
126 do_libc_check_config() {
130 # This function installs the eglibc headers needed to build the core compiler
132 # Instead of doing two time the same actions, headers will
133 # be installed with start files
137 # Build and install start files
138 do_libc_start_files() {
139 CT_DoStep INFO "Installing C library headers / start files"
141 mkdir -p "${CT_BUILD_DIR}/build-libc-startfiles"
142 cd "${CT_BUILD_DIR}/build-libc-startfiles"
144 CT_DoLog EXTRA "Configuring C library"
146 cross_cc=$(CT_Which "${CT_TARGET}-gcc")
147 cross_cxx=$(CT_Which "${CT_TARGET}-g++")
148 cross_ar=$(CT_Which "${CT_TARGET}-ar")
149 cross_ranlib=$(CT_Which "${CT_TARGET}-ranlib")
151 CT_DoLog DEBUG "Using gcc for target: '${cross_cc}'"
152 CT_DoLog DEBUG "Using g++ for target: '${cross_cxx}'"
153 CT_DoLog DEBUG "Using ar for target: '${cross_ar}'"
154 CT_DoLog DEBUG "Using ranlib for target: '${cross_ranlib}'"
156 BUILD_CC="${CT_BUILD}-gcc" \
160 RANLIB=${cross_ranlib} \
162 "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}/configure" \
164 --with-headers="${CT_HEADERS_DIR}" \
165 --build="${CT_BUILD}" \
166 --host="${CT_TARGET}" \
172 CT_DoLog EXTRA "Installing C library headers"
174 # use the 'install-headers' makefile target to install the
178 make install-headers \
179 install_root=${CT_SYSROOT_DIR} \
180 install-bootstrap-headers=yes
182 CT_DoLog EXTRA "Installing C library start files"
184 # there are a few object files needed to link shared libraries,
185 # which we build and install by hand
187 CT_DoExecLog ALL mkdir -p ${CT_SYSROOT_DIR}/usr/lib
188 CT_DoExecLog ALL make csu/subdir_lib
189 CT_DoExecLog ALL cp csu/crt1.o csu/crti.o csu/crtn.o \
190 ${CT_SYSROOT_DIR}/usr/lib
192 # Finally, 'libgcc_s.so' requires a 'libc.so' to link against.
193 # However, since we will never actually execute its code,
194 # it doesn't matter what it contains. So, treating '/dev/null'
195 # as a C source file, we produce a dummy 'libc.so' in one step
197 CT_DoExecLog ALL ${cross_cc} -nostdlib -nostartfiles -shared -x c /dev/null -o ${CT_SYSROOT_DIR}/usr/lib/libc.so
202 # This function builds and install the full glibc
204 local -a extra_config
206 CT_DoStep INFO "Installing C library"
208 mkdir -p "${CT_BUILD_DIR}/build-libc"
209 cd "${CT_BUILD_DIR}/build-libc"
211 CT_DoLog EXTRA "Configuring C library"
213 # Add some default glibc config options if not given by user.
214 # We don't need to be conditional on wether the user did set different
215 # values, as they CT_LIBC_GLIBC_EXTRA_CONFIG is passed after extra_config
217 extra_config+=("--enable-kernel=$(echo ${CT_LIBC_GLIBC_MIN_KERNEL} |sed -r -e 's/^([^.]+\.[^.]+\.[^.]+)(|\.[^.]+)$/\1/;')")
219 case "${CT_THREADS}" in
220 nptl) extra_config+=("--with-__thread" "--with-tls");;
221 linuxthreads) extra_config+=("--with-__thread" "--without-tls" "--without-nptl");;
222 none) extra_config+=("--without-__thread" "--without-nptl")
223 case "${CT_LIBC_GLIBC_EXTRA_CONFIG}" in
225 *) extra_config+=("--without-tls");;
230 case "${CT_SHARED_LIBS}" in
231 y) extra_config+=("--enable-shared");;
232 *) extra_config+=("--disable-shared");;
235 case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
236 y,) extra_config+=("--with-fp");;
237 ,y) extra_config+=("--without-fp");;
240 case "$(do_libc_add_ons_list ,)" in
242 *) extra_config+=("--enable-add-ons=$(do_libc_add_ons_list ,)");;
245 extra_cc_args="${extra_cc_args} ${CT_ARCH_ENDIAN_OPT}"
247 cross_cc=$(CT_Which "${CT_TARGET}-gcc")
249 CT_DoLog DEBUG "Using gcc for target: '${cross_cc}'"
250 CT_DoLog DEBUG "Configuring with addons : '$(do_libc_add_ons_list ,)'"
251 CT_DoLog DEBUG "Extra config args passed: '${extra_config[*]}'"
252 CT_DoLog DEBUG "Extra CC args passed : '${extra_cc_args}'"
254 BUILD_CC="${CT_BUILD}-gcc" \
255 CFLAGS="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} -O" \
256 CC="${CT_TARGET}-gcc ${CT_LIBC_EXTRA_CC_ARGS} ${extra_cc_args}" \
258 RANLIB=${CT_TARGET}-ranlib \
260 "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}/configure" \
262 --with-headers="${CT_HEADERS_DIR}" \
263 --build=${CT_BUILD} \
264 --host=${CT_TARGET} \
268 "${extra_config[@]}" \
269 ${CT_LIBC_GLIBC_EXTRA_CONFIG}
271 CT_DoLog EXTRA "Building C library"
274 # http://sourceware.org/ml/crossgcc/2008-10/msg00068.html
275 case "${CT_ARCH},${CT_ARCH_CPU}" in
277 CT_DoLog DEBUG "Activating support for memset on broken ppc-8xx (CPU15 erratum)"
278 EGLIBC_BUILD_ASFLAGS="-DBROKEN_PPC_8xx_CPU15";;
281 CT_DoExecLog ALL make ASFLAGS="${EGLIBC_BUILD_ASFLAGS}"
283 CT_DoLog EXTRA "Installing C library"
285 CT_DoExecLog ALL make install install_root="${CT_SYSROOT_DIR}"
290 # This function finishes the glibc install
292 # Nothing to be done for eglibc
296 # Build up the addons list, separated with $1
297 do_libc_add_ons_list() {
299 local addons_list=$(echo "${CT_LIBC_ADDONS_LIST//,/${sep}}" |tr -s ,)
300 case "${CT_THREADS}" in
302 *) addons_list="${addons_list}${sep}${CT_THREADS}";;
304 [ "${CT_LIBC_GLIBC_USE_PORTS}" = "y" ] && addons_list="${addons_list}${sep}ports"
305 addons_list="${addons_list%%${sep}}"
306 echo "${addons_list##${sep}}"