gcc-pass1.xml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
  3. <!ENTITY % general-entities SYSTEM "../general.ent">
  4. %general-entities;
  5. ]>
  6. <sect1 id="ch-tools-gcc-pass1" role="wrap">
  7. <title>GCC-&gcc-version; - Pass 1</title>
  8. <?dbhtml filename="gcc-pass1.html"?>
  9. <indexterm zone="ch-tools-gcc-pass1">
  10. <primary sortas="a-GCC">GCC</primary>
  11. <secondary>tools, pass 1</secondary></indexterm>
  12. <sect2 role="package"><title/>
  13. <xi:include xmlns:xi="http://www.w3.org/2003/XInclude" href="../chapter06/gcc.xml" xpointer="xpointer(/sect1/sect2[1]/para[1])"/>
  14. <segmentedlist>
  15. <segtitle>&buildtime;</segtitle>
  16. <segtitle>&diskspace;</segtitle>
  17. <seglistitem><seg>4.4 SBU</seg><seg>300 MB</seg></seglistitem>
  18. </segmentedlist>
  19. <xi:include xmlns:xi="http://www.w3.org/2003/XInclude" href="../chapter06/gcc.xml" xpointer="xpointer(/sect1/sect2[1]/segmentedlist[2])"/>
  20. </sect2>
  21. <sect2 role="installation">
  22. <title>Installation of GCC</title>
  23. <para>Unpack only the GCC-core tarball, as we won't be needing the C++ compiler
  24. nor the test suite here.</para>
  25. <para>This package is known to behave badly when you change its default
  26. optimization flags (including the <parameter>-march</parameter> and
  27. <parameter>-mcpu</parameter> options). Therefore, if you have defined any
  28. environment variables that override default optimizations, such as CFLAGS and
  29. CXXFLAGS, we recommend un-setting them when building GCC.</para>
  30. <para>The GCC documentation recommends building GCC outside of the source
  31. directory in a dedicated build directory:</para>
  32. <screen><userinput>mkdir ../gcc-build
  33. cd ../gcc-build</userinput></screen>
  34. <para>Prepare GCC for compilation:</para>
  35. <screen><userinput>CC="gcc -B/usr/bin" ../gcc-&gcc-version;/configure \
  36. --prefix=/tools --libexecdir=/tools/lib \
  37. --with-local-prefix=/tools --disable-nls \
  38. --enable-shared --enable-languages=c</userinput></screen>
  39. <para>The meaning of the configure options:</para>
  40. <variablelist>
  41. <varlistentry>
  42. <term><parameter>CC="gcc -B/usr/bin"</parameter></term>
  43. <listitem><para>This parameter fixes a possible problem with building GCC
  44. at this stage, first noticed in LFS 5.1.1. If our host uses a new version
  45. of Binutils than we compiled, the host compiler may try use features not
  46. supported by our new linker, causing compilation errors. By passing the -B
  47. flag to gcc, we cause the compiler to temporarily use the host's linker,
  48. which solves the problem.</para></listitem>
  49. </varlistentry>
  50. <varlistentry>
  51. <term><parameter>--with-local-prefix=/tools</parameter></term>
  52. <listitem><para>The purpose of this switch is to remove <filename class="directory">/usr/local/include</filename>
  53. from <command>gcc</command>'s include search path. This is not absolutely
  54. essential; however, we want to try to minimize the influence of the host
  55. system, so this a sensible thing to do.</para></listitem>
  56. </varlistentry>
  57. <varlistentry>
  58. <term><parameter>--enable-shared</parameter></term>
  59. <listitem><para>This switch may
  60. seem counter-intuitive at first. But using it allows the building of
  61. <filename>libgcc_s.so.1</filename> and <filename>libgcc_eh.a</filename>, and
  62. having <filename>libgcc_eh.a</filename> available ensures that the configure
  63. script for Glibc (the next package we compile) produces the proper results.
  64. Note that the GCC binaries will still be linked
  65. statically, as this is controlled by the <parameter>-static</parameter>
  66. value of BOOT_LDFLAGS in the next step.</para></listitem>
  67. </varlistentry>
  68. <varlistentry>
  69. <term><parameter>--enable-languages=c</parameter></term>
  70. <listitem><para>This option
  71. ensures that only the C compiler is built. The option is only needed when you
  72. have downloaded and unpacked the full GCC tarball.</para></listitem>
  73. </varlistentry>
  74. </variablelist>
  75. <para>Continue with compiling the package:</para>
  76. <screen><userinput>make BOOT_LDFLAGS="-static" bootstrap</userinput></screen>
  77. <para>The meaning of the make parameters:</para>
  78. <variablelist>
  79. <varlistentry>
  80. <term><parameter>BOOT_LDFLAGS="-static"</parameter></term>
  81. <listitem><para>This tells GCC to link its programs statically.</para></listitem>
  82. </varlistentry>
  83. <varlistentry>
  84. <term><parameter>bootstrap</parameter></term>
  85. <listitem><para>This target doesn't just
  86. compile GCC, but compiles it several times. It uses the programs compiled in
  87. a first round to compile itself a second time, and then again a third time.
  88. It then compares these second and third compiles to make sure it can
  89. reproduce itself flawlessly, which most probably means that it was
  90. compiled correctly.</para></listitem>
  91. </varlistentry>
  92. </variablelist>
  93. <para>Compilation is now complete, and at this point we would normally run the
  94. test suite. But, as mentioned before, the test suite framework is not in place
  95. yet. And there would be little point in running the tests anyhow, since the
  96. programs from this first pass will soon be replaced.</para>
  97. <para>Now install the package:</para>
  98. <screen><userinput>make install</userinput></screen>
  99. <para>As a finishing touch we'll create a symlink. Many programs and scripts
  100. run <command>cc</command> instead of <command>gcc</command>,
  101. a thing meant to keep programs generic and therefore usable on all kinds of
  102. Unix systems. Not everybody has the GNU C compiler installed. Simply running
  103. <command>cc</command> leaves the system administrator free to decide what
  104. C compiler to install, as long as there's a symlink pointing to it:</para>
  105. <screen><userinput>ln -s gcc /tools/bin/cc</userinput></screen>
  106. </sect2>
  107. <sect2 role="content"><title/>
  108. <para>The details on this package are found in <xref linkend="contents-gcc"/>.</para>
  109. </sect2>
  110. </sect1>