aboutsummaryrefslogtreecommitdiffstats
path: root/chapter05/gcc-pass1-inst.xml
blob: e9a6497762e5f30ac7bcceb780669fdf02f18d24 (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
<sect2><title>&nbsp;</title><para>&nbsp;</para></sect2>

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

<para>We won't be needing a C++ compiler until the next chapter. So, only
the gcc-core tarball needs to be unpacked at this time.</para>

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

<para><screen><userinput>patch -Np1 -i ../gcc-&gcc-version;-mmap_test.patch
patch -Np1 -i ../gcc-&gcc-version;-no_fixincludes.patch</userinput></screen></para>

<para>It is recommended by the GCC installation documentation to build
GCC outside of the source directory in a dedicated directory:</para>

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

<para>Prepare GCC to be compiled:</para>

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

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

<itemizedlist>
<listitem><para><userinput>--with-local-prefix=/stage1</userinput>:  The
purpose of this switch is to remove <filename>/usr/local/include</filename>
from <userinput>gcc</userinput>'s include search path. This is not absolutely
essential, but we want to try and minimize the influence from the host system,
so this seems a logical 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.
Please note that the <userinput>gcc</userinput> binaries will still be linked
statically, as this is controlled by the <userinput>-static</userinput>
value of BOOT_LDFLAGS further on.</para></listitem>

<listitem><para><userinput>--enable-languages=c</userinput>: This will build
only the C compiler from the GCC package. We won't be needing anything else
during this chapter.</para></listitem>
</itemizedlist>

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

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

<para>The meaning of the make parameters is:</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>And install the package:</para>

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

<para>As a finishing touch we'll create the <filename
class="symlink">/stage1/bin/cc</filename> symlink. Many programs and
scripts run <userinput>cc</userinput> instead of <userinput>gcc</userinput>,
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
<userinput>cc</userinput> leaves the system administrator free to decide what
C compiler to install, as long as there's a symlink pointing to it:</para>

<para><screen><userinput>ln -sf gcc /stage1/bin/cc</userinput></screen></para>

</sect2>