The Glibc package contains the main C library. This library provides the basic routines for allocating memory, searching directories, opening and closing files, reading and writing files, string handling, pattern matching, arithmetic, and so on.
Some packages outside of CLFS suggest installing GNU libiconv in order to translate data from one encoding to another. The project's home page (http://www.gnu.org/software/libiconv/) says “This library provides an iconv() implementation, for use on systems which don't have one, or whose implementation cannot convert from/to Unicode.” Glibc provides an iconv() implementation and can convert from/to Unicode, therefore libiconv is not required on an CLFS system.
The Glibc build will expect to find libgcc_eh, but this library is not installed when GCC is built without "--enable-shared". As a result, the Glibc build will fail. The following patch will force Glibc to check for the existance of libgcc_eh and try to link to it only if it exists:
patch -Np1 -i ../glibc-2.5-libgcc_eh-2.patch
The following patch fixes an issue that can cause localdef to segfault:
patch -Np1 -i ../glibc-2.5-localedef_segfault-1.patch
The following patch builds zic-native, localedef-native, and rpcgen-native. zic-native is used to generate the zoneinfo, localedef-native is used to generate the locale archive, and rpcgen-native is used to generate part of librpcsvc.a. All of these programs would normally not be available when cross-compiling:
patch -Np1 -i ../glibc-2.5-cross_hacks-2.patch
The following patch corrects the Minor version, changing the value from 4 to 5:
patch -Np1 -i ../glibc-2.5-MINOR-1.patch
The Glibc documentation recommends building Glibc outside of the source directory in a dedicated build directory:
mkdir -v ../glibc-build cd ../glibc-build
The following lines need to be added to config.cache for Glibc to support NPTL:
echo "libc_cv_forced_unwind=yes" > config.cache echo "libc_cv_c_cleanup=yes" >> config.cache
The following line needs to be added to configparms to adjust installation paths:
echo "install_root=${CLFS}" > configparms
Prepare Glibc for compilation:
BUILD_CC="gcc" CC="${CLFS_TARGET}-gcc" \
AR="${CLFS_TARGET}-ar" RANLIB="${CLFS_TARGET}-ranlib" \
../glibc-2.5/configure --prefix=/usr --libexecdir=/usr/lib/glibc \
--host=${CLFS_TARGET} --build=${CLFS_HOST} \
--disable-profile --enable-add-ons \
--with-tls --enable-kernel=2.6.0 --with-__thread \
--with-binutils=${CLFS}/cross-tools/bin --with-headers=${CLFS}/usr/include \
--cache-file=config.cache
The meaning of the new configure options:
This sets Glibc to use the current compiler on our system. This is used to create the tools Glibc uses during its build.
This forces Glibc to use the GCC compiler that we made for our target architecture.
This forces Glibc to use the ar utility we made for our target architecture.
This forces Glibc to use the ranlib utility we made for our target architecture.
This builds the libraries without profiling information. Omit this option if profiling on the temporary tools is necessary.
This tells Glibc to utilize all add-ons that are available.
This tells Glibc to use Thread Local Storage.
This tells Glibc to use use the __thread for libc and libpthread builds.
This tells Glibc to use the Binutils that are specific to our target architecture.
This tells Glibc to utilize a premade cache file.
During this stage the following warning might appear:
configure: WARNING: *** These auxiliary programs are missing or *** incompatible versions: msgfmt *** some features will be disabled. *** Check the INSTALL file for required versions.
The missing or incompatible msgfmt program is generally harmless. This msgfmt program is part of the Gettext package which the host distribution should provide.
Compile the package:
make
Install the package:
make install
The locales that can make the system respond in a different language were not installed by the above command. Install them with:
make localedata/install-locales
To save time, an alternative to running the previous command (which generates and installs every locale listed in the glibc-2.5/localedata/SUPPORTED file) is to install only those locales that are wanted and needed. This can be achieved by using the localedef command. Information on this command is located in the INSTALL file in the Glibc source. However, there are a number of locales that are essential in order for the tests of future packages to pass, in particular, the libstdc++ tests from GCC. The following instructions, instead of the install-locales target used above, will install the minimum set of locales necessary for the tests to run successfully:
mkdir -pv ${CLFS}/usr/lib/locale
export I18NPATH=${PWD}/localedata
export GCONV_PATH=${PWD}/iconvdata
export LOCALEDEF="${PWD}/locale/localedef-native --alias-file=../intl/locale.alias"
cd ../glibc-2.5/localedata
${LOCALEDEF} -i locales/de_DE -f charmaps/ISO-8859-1 --prefix=${CLFS} de_DE
${LOCALEDEF} -i locales/de_DE@euro -f charmaps/ISO-8859-15 --prefix=${CLFS} de_DE@euro
${LOCALEDEF} -i locales/en_HK -f charmaps/ISO-8859-1 --prefix=${CLFS} en_HK
${LOCALEDEF} -i locales/en_PH -f charmaps/ISO-8859-1 --prefix=${CLFS} en_PH
${LOCALEDEF} -i locales/en_US -f charmaps/ISO-8859-1 --prefix=${CLFS} en_US
${LOCALEDEF} -i locales/es_MX -f charmaps/ISO-8859-1 --prefix=${CLFS} es_MX
${LOCALEDEF} -i locales/fa_IR -f charmaps/UTF-8 --prefix=${CLFS} fa_IR
${LOCALEDEF} -i locales/fr_FR -f charmaps/ISO-8859-1 --prefix=${CLFS} fr_FR
${LOCALEDEF} -i locales/fr_FR@euro -f charmaps/ISO-8859-15 --prefix=${CLFS} fr_FR@euro
${LOCALEDEF} -i locales/it_IT -f charmaps/ISO-8859-1 --prefix=${CLFS} it_IT
${LOCALEDEF} -i locales/ja_JP -f charmaps/EUC-JP --prefix=${CLFS} ja_JP
unset I18NPATH GCONV_PATH LOCALEDEF
Some locales installed by the make localedata/install-locales command above are not properly supported by some applications that are in the CLFS and BLFS books. Because of the various problems that arise due to application programmers making assumptions that break in such locales, CLFS should not be used in locales that utilize multibyte character sets (including UTF-8) or right-to-left writing order. Numerous unofficial and unstable patches are required to fix these problems, and it has been decided by the CLFS developers not to support such complex locales at this time. This applies to the ja_JP and fa_IR locales as well—they have been installed only for GCC and Gettext tests to pass, and the watch program (part of the Procps package) does not work properly in them. Various attempts to circumvent these restrictions are documented in internationalization-related hints.
The /etc/nsswitch.conf file needs to be created because, although Glibc provides defaults when this file is missing or corrupt, the Glibc defaults do not work well in a networked environment. The time zone also needs to be configured.
Create a new file /etc/nsswitch.conf by running the following:
cat > ${CLFS}/etc/nsswitch.conf << "EOF"
# Begin /etc/nsswitch.conf
passwd: files
group: files
shadow: files
hosts: files dns
networks: files
protocols: files
services: files
ethers: files
rpc: files
# End /etc/nsswitch.conf
EOF
To determine the local time zone, run the following script:
TZDIR="${CLFS}/usr/share/zoneinfo" ${CLFS}/usr/bin/tzselect
After answering a few questions about the location, the script will output the name of the time zone (e.g., EST5EDT or Canada/Eastern). Then create the /etc/localtime file by running:
cp -v --remove-destination ${CLFS}/usr/share/zoneinfo/[xxx] \
${CLFS}/etc/localtime
Replace [xxx] with the name of the time zone that tzselect provided (e.g., Canada/Eastern).
The meaning of the cp option:
This is needed to force removal of the already existing symbolic link. The reason for copying the file instead of using a symlink is to cover the situation where /usr is on a separate partition. This could be important when booted into single user mode.
By default, the dynamic loader (/lib/ld-linux.so.2) searches through /lib and /usr/lib for dynamic libraries that are needed by programs as they are run. However, if there are libraries in directories other than /lib and /usr/lib, these need to be added to the /etc/ld.so.conf file in order for the dynamic loader to find them. Two directories that are commonly known to contain additional libraries are /usr/local/lib and /opt/lib, so add those directories to the dynamic loader's search path.
Create a new file /etc/ld.so.conf by running the following:
cat > ${CLFS}/etc/ld.so.conf << "EOF"
# Begin /etc/ld.so.conf
/usr/local/lib
/opt/lib
# End /etc/ld.so.conf
EOF