Added a few comments here and there
[linux_from_scratch.git] / newxml / chapter06 / glibc.xml
blob122330067c912bf8f76c83ff1939c39bac1ab00e
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.3CR2//EN" "http://www.docbook.org/xml/4.3CR2/docbookx.dtd" [
3   <!ENTITY % glibc-entities SYSTEM "../ent/glibc.ent">
4   %glibc-entities;
5 ]>
6 <sect1 id="ch06-glibc">
7 <title>Installing Glibc-&glibc-version;</title>
8 <?dbhtml filename="glibc.html"?>
10 <screen>Estimated build time:           12.3 SBU
11 Estimated required disk space:  784 MB</screen>
13 <xi:include xmlns:xi="http://www.w3.org/2003/XInclude" href="../appendixa/glibc-contents.xml"/>
17 <xi:include xmlns:xi="http://www.w3.org/2003/XInclude" href="../appendixa/glibc-deps.xml"/>
21 <sect2>
22 <title>Glibc installation</title>
24 <para>The Glibc build system is very well self-contained and will install
25 perfectly, even though our compiler specs file and linker are still pointing
26 at <filename>/tools</filename>. We cannot adjust the specs and linker before
27 the Glibc install, because the Glibc autoconf tests would then give bogus
28 results and thus defeat our goal of achieving a clean build.</para>
30 <note><para>The test suite for Glibc in this section is considered
31 <emphasis>critical</emphasis>. Our advice is to not skip it under any
32 circumstance.</para></note>
34 <para>Before starting to build Glibc, remember to unpack the Glibc-linuxthreads
35 again inside the <filename>glibc-&glibc-version;</filename> directory, and to
36 unset any environment variables that override the default optimization
37 flags.</para>
39 <para>Apply the same patch we used previously:</para>
40                                                                                 
41 <screen><userinput>patch -Np1 -i ../glibc-&glibc-version;-sscanf-1.patch</userinput></screen>
43 <para>The Glibc documentation recommends building Glibc outside of the source
44 directory in a dedicated build directory:</para>
46 <screen><userinput>mkdir ../glibc-build
47 cd ../glibc-build</userinput></screen>
49 <para>Now prepare Glibc for compilation:</para>
51 <screen><userinput>../glibc-&glibc-version;/configure --prefix=/usr \
52     --disable-profile --enable-add-ons \
53     --libexecdir=/usr/lib --with-headers=/usr/include</userinput></screen>
55 <para>The meaning of the new configure options:</para>
57 <itemizedlist>
58 <listitem><para><userinput>--libexecdir=/usr/lib</userinput>: This changes the
59 location of the <filename>pt_chown</filename> program from its default of 
60 <filename class="directory">/usr/libexec</filename> to
61 <filename class="directory">/usr/lib</filename>. The use of
62 <emphasis>libexec</emphasis> is considered not FHS compliant because the FHS
63 doesn't even mention it.</para></listitem>
65 <listitem><para><userinput>--with-headers=/usr/include</userinput>: This
66 ensures that the kernel headers in <filename>/usr/include</filename> are used
67 for this build. If you don't pass this switch then the headers from
68 <filename>/tools/include</filename> are used which of course is not ideal
69 (although they should be identical). Using this switch has the advantage
70 that you will be informed immediately should you have forgotten to install the
71 kernel headers into <filename>/usr/include</filename>.</para></listitem>
72 </itemizedlist>
74 <para>Compile the package:</para>
76 <screen><userinput>make</userinput></screen>
78 <para>Test the results:</para>
80 <screen><userinput>make check</userinput></screen>
82 <para>The test suite notes from <xref linkend="ch05-glibc"/> are still very much
83 appropriate here. Be sure to refer back there should you have any doubts.</para>
85 <para>Though it is a harmless message, the install stage of Glibc will
86 complain about the absence of <filename>/etc/ld.so.conf</filename>. Fix this
87 annoying little warning with:</para>
89 <screen><userinput>touch /etc/ld.so.conf</userinput></screen>
91 <para>And install the package:</para>
93 <screen><userinput>make install</userinput></screen>
95 <para>The locales that can make your system respond in a different language
96 weren't installed by the above command. Do it with this:</para>
98 <screen><userinput>make localedata/install-locales</userinput></screen>
100 <para>An alternative to running the previous command is to install only those
101 locales which you need or want. This can be achieved using the
102 <userinput>localedef</userinput> command. Information on this can be found in
103 the <filename>INSTALL</filename> file in the
104 <filename>glibc-&glibc-version;</filename> tree. However,  there are a number
105 of locales that are essential for the tests of future packages to pass
106 correctly. The following instructions, in place of the install-locales
107 command above, will install the minimum set of locales necessary for the
108 tests to run successfully:</para>
110 <screen><userinput>mkdir -p /usr/lib/locale
111 localedef -i de_DE -f ISO-8859-1 de_DE
112 localedef -i de_DE@euro -f ISO-8859-15 de_DE@euro
113 localedef -i en_HK -f ISO-8859-1 en_HK
114 localedef -i en_PH -f ISO-8859-1 en_PH
115 localedef -i en_US -f ISO-8859-1 en_US
116 localedef -i es_MX -f ISO-8859-1 es_MX
117 localedef -i fr_FR -f ISO-8859-1 fr_FR
118 localedef -i fr_FR@euro -f ISO-8859-15 fr_FR@euro
119 localedef -i it_IT -f ISO-8859-1 it_IT
120 localedef -i ja_JP -f EUC-JP ja_JP</userinput></screen>
122 <para>Finally, build the linuxthreads man pages:</para>
124 <screen><userinput>make -C ../glibc-&glibc-version;/linuxthreads/man</userinput></screen>
126 <para>And install these pages:</para>
128 <screen><userinput>make -C ../glibc-&glibc-version;/linuxthreads/man install</userinput></screen>
130 </sect2>
132 <sect2><title>Configuring Glibc</title>
134 <para>We need to create the <filename>/etc/nsswitch.conf</filename> file,
135 because, although Glibc provides defaults when this file is missing or corrupt,
136 the Glibc defaults don't work well with networking. Also, our time zone needs
137 to be set up.</para>
139 <para>Create a new file <filename>/etc/nsswitch.conf</filename> by running the
140 following:</para>
142 <screen><userinput>cat &gt; /etc/nsswitch.conf &lt;&lt; "EOF"</userinput>
143 # Begin /etc/nsswitch.conf
145 passwd: files
146 group: files
147 shadow: files
149 publickey: files
151 hosts: files dns
152 networks: files
154 protocols: db files
155 services: db files
156 ethers: db files
157 rpc: db files
159 netgroup: db files
161 # End /etc/nsswitch.conf
162 <userinput>EOF</userinput></screen>
164 <para>To find out what time zone you're in, run the following script:</para>
166 <screen><userinput>tzselect</userinput></screen>
168 <para>When you've answered a few questions about your location, the script will
169 output the name of your time zone, something like <emphasis>EST5EDT</emphasis>
170 or <emphasis>Canada/Eastern</emphasis>. Then create the
171 <filename>/etc/localtime</filename> file by running:</para>
173 <screen><userinput>cp --remove-destination /usr/share/zoneinfo/Canada/Eastern /etc/localtime</userinput></screen>
175 <para>The meaning of the option:</para>
177 <itemizedlist>
178 <listitem><para><userinput>--remove-destination</userinput>: This is needed to
179 force removal of the already existing symbolic link. The reason why we copy
180 instead of symlink is to cover the situation where <filename>/usr</filename> is
181 on a separate partition. This could matter, for example, when booted into single
182 user mode.</para></listitem>
183 </itemizedlist>
185 <para>Of course, instead of <emphasis>Canada/Eastern</emphasis>, fill in
186 the name of the time zone that the <userinput>tzselect</userinput> script
187 gave you.</para>
189 </sect2>
192 <sect2>
193 <title>Configuring Dynamic Loader</title>
195 <para>By default, the dynamic loader
196 (<filename>/lib/ld-linux.so.2</filename>) searches through <filename class="directory">/lib</filename> and <filename class="directory">/usr/lib</filename> for dynamic libraries that are needed
197 by programs when you run them. However, if there are libraries in
198 directories other than <filename class="directory">/lib</filename> and
199 <filename class="directory">/usr/lib</filename>, you need to add them to
200 the <filename>/etc/ld.so.conf</filename> file for the dynamic
201 loader to find them. Two directories that are commonly known to contain
202 additional libraries are <filename class="directory">/usr/local/lib</filename> and <filename class="directory">/opt/lib</filename>, so we add those directories to the
203 dynamic loader's search path.</para>
205 <para>Create a new file <filename>/etc/ld.so.conf</filename> by running the
206 following:</para>
208 <screen><userinput>cat &gt; /etc/ld.so.conf &lt;&lt; "EOF"</userinput>
209 # Begin /etc/ld.so.conf
211 /usr/local/lib
212 /opt/lib
214 # End /etc/ld.so.conf
215 <userinput>EOF</userinput></screen>
217 </sect2>
220 </sect1>