aboutsummaryrefslogtreecommitdiffstats
path: root/chapter05/gcc-pass1.xml
blob: 6cb01b4fa1f252d759c1fcaa5a607da1bbb166d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<sect1 id="ch-tools-gcc-pass1">
<title>Installing GCC-&gcc-version; - Pass 1</title>
<?dbhtml filename="gcc-pass1.html" dir="chapter05"?>

<screen>&buildtime; &gcc-time-tools-pass1;
&diskspace; &gcc-compsize-tools-pass1;</screen>

<literallayout>Official download location for GCC (&gcc-version;): 
<ulink url="ftp://ftp.gnu.org/pub/gnu/gcc/"/></literallayout>

&aa-gcc-dep;

<sect2><title>&nbsp;</title><para>&nbsp;</para></sect2>

<sect2>
<title>Installation of GCC</title>

<para>Unpack only the GCC-core tarball, as we won't be needing the C++ compiler
nor the test suite at the moment.</para>

<para>This package is known to behave badly when you change its default
optimization flags (including the <emphasis>-march</emphasis> and
<emphasis>-mcpu</emphasis> options). Therefore, if you have defined any
environment variables that override default optimizations, such as CFLAGS and
CXXFLAGS, we recommend unsetting them when building GCC.</para>

<para>The GCC documentation recommends building GCC outside of the source
directory in a dedicated build directory:</para>

<screen><userinput>mkdir ../gcc-build
cd ../gcc-build</userinput></screen>

<para>Prepare GCC for compilation:</para>

<screen><userinput>../&gcc-dir;/configure --prefix=/tools \
&nbsp;&nbsp;&nbsp;&nbsp;--with-local-prefix=/tools \
&nbsp;&nbsp;&nbsp;&nbsp;--disable-nls --enable-shared \
&nbsp;&nbsp;&nbsp;&nbsp;--enable-languages=c</userinput></screen>

<para>The meaning of the configure options:</para>

<itemizedlist>
<listitem><para><userinput>--with-local-prefix=/tools</userinput>: The
purpose of this switch is to remove <filename>/usr/local/include</filename>
from <command>gcc</command>'s include search path. This is not absolutely
essential; however, we want to try to minimize the influence of the host
system, thus making this a sensible thing to do.</para></listitem>

<listitem><para><userinput>--enable-shared</userinput>: This switch may
seem counter-intuitive at first. But using it allows the building of
<filename>libgcc_s.so.1</filename> and <filename>libgcc_eh.a</filename>, and
having <filename>libgcc_eh.a</filename> available ensures that the configure
script for Glibc (the next package we compile) produces the proper results.
Note that the <command>gcc</command> binaries will still be linked
statically, as this is controlled by the <emphasis>-static</emphasis>
value of BOOT_LDFLAGS in the next step.</para></listitem>

<listitem><para><userinput>--enable-languages=c</userinput>: This option
ensures that only the C compiler is built. The option is only needed when you
have downloaded and unpacked the full GCC tarball.</para></listitem>
</itemizedlist>

<para>Continue with compiling the package:</para>

<screen><userinput>make BOOT_LDFLAGS="-static" bootstrap</userinput></screen>

<para>The meaning of the make parameters:</para>

<itemizedlist>
<listitem><para><userinput>BOOT_LDFLAGS="-static"</userinput>: This tells
GCC to link its programs statically.</para></listitem>

<listitem><para><userinput>bootstrap</userinput>: This target doesn't just
compile GCC, but compiles it several times. It uses the programs compiled in
a first round to compile itself a second time, and then again a third time.
It then compares these second and third compiles to make sure it can
reproduce itself flawlessly, which most probably means that it was
compiled correctly.</para></listitem>
</itemizedlist>

<para>Compilation is now complete, and at this point we would normally run the
test suite. But, as mentioned before, the test suite framework is not in place
yet. And there would be little point in running the tests anyhow, since the
programs from this first pass will soon be replaced.</para>

<para>And install the package:</para>

<screen><userinput>make install</userinput></screen>

<para>As a finishing touch we'll create a symlink. Many programs and scripts
run <command>cc</command> instead of <command>gcc</command>,
a thing meant to keep programs generic and therefore usable on all kinds of
Unix systems. Not everybody has the GNU C compiler installed. Simply running
<command>cc</command> leaves the system administrator free to decide what
C compiler to install, as long as there's a symlink pointing to it:</para>

<screen><userinput>ln -s gcc /tools/bin/cc</userinput></screen>

</sect2>

<sect2><title>&nbsp;</title><para>&nbsp;</para>
<para>The details on this package are found in <xref linkend="contents-gcc"/>.</para>
<para>&nbsp;</para></sect2>

</sect1>