gcc-pass1.xml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
  4. <!ENTITY % general-entities SYSTEM "../general.ent">
  5. %general-entities;
  6. ]>
  7. <sect1 id="ch-tools-gcc-pass1" role="wrap">
  8. <?dbhtml filename="gcc-pass1.html"?>
  9. <sect1info condition="script">
  10. <productname>gcc</productname>
  11. <productnumber>&gcc-version;</productnumber>
  12. <address>&gcc-url;</address>
  13. </sect1info>
  14. <title>GCC-&gcc-version; - Pass 1</title>
  15. <indexterm zone="ch-tools-gcc-pass1">
  16. <primary sortas="a-GCC">GCC</primary>
  17. <secondary>tools, pass 1</secondary>
  18. </indexterm>
  19. <sect2 role="package">
  20. <title/>
  21. <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"
  22. href="../chapter06/gcc.xml"
  23. xpointer="xpointer(/sect1/sect2[1]/para[1])"/>
  24. <segmentedlist>
  25. <segtitle>&buildtime;</segtitle>
  26. <segtitle>&diskspace;</segtitle>
  27. <seglistitem>
  28. <seg>&gcc-ch5p1-sbu;</seg>
  29. <seg>&gcc-ch5p1-du;</seg>
  30. </seglistitem>
  31. </segmentedlist>
  32. </sect2>
  33. <sect2 role="installation">
  34. <title>Installation of GCC</title>
  35. <para>The GCC documentation recommends building GCC outside of the
  36. source directory in a dedicated build directory:</para>
  37. <screen><userinput>mkdir -v ../gcc-build
  38. cd ../gcc-build</userinput></screen>
  39. <para>Set the --with-arch flag if the machine is x86:</para>
  40. <screen><userinput>test $(uname -m | grep i?86) &amp;&amp; WITHARCH="--with-arch=i486"</userinput></screen>
  41. <para>Prepare GCC for compilation:</para>
  42. <screen><userinput>CC="gcc -B/usr/bin/" ../gcc-&gcc-version;/configure --prefix=/tools \
  43. --with-local-prefix=/tools --disable-nls --disable-shared \
  44. --enable-languages=c --disable-multilib \
  45. $WITHARCH
  46. unset WITHARCH</userinput></screen>
  47. <variablelist>
  48. <title>The meaning of the configure options:</title>
  49. <varlistentry>
  50. <term><envar>CC="gcc -B/usr/bin/"</envar></term>
  51. <listitem>
  52. <para>This forces <command>gcc</command> to prefer the linker from
  53. the host in <filename class="directory">/usr/bin</filename>. This
  54. is necessary on some hosts where the new <command>ld</command>
  55. built in the previous section is not compatible with the host's
  56. <command>gcc</command>.</para>
  57. </listitem>
  58. </varlistentry>
  59. <varlistentry>
  60. <term><parameter>--with-local-prefix=/tools</parameter></term>
  61. <listitem>
  62. <para>The purpose of this switch is to remove <filename
  63. class="directory">/usr/local/include</filename> from
  64. <command>gcc</command>'s include search path. This is not
  65. absolutely essential, however, it helps to minimize the
  66. influence of the host system.</para>
  67. </listitem>
  68. </varlistentry>
  69. <varlistentry>
  70. <term><parameter>--disable-shared</parameter></term>
  71. <listitem>
  72. <para>This forces gcc to link its internal libraries statically. We do this
  73. to avoid possible issues with the host system.</para>
  74. </listitem>
  75. </varlistentry>
  76. <varlistentry>
  77. <term><parameter>--enable-languages=c</parameter></term>
  78. <listitem>
  79. <para>This option ensures that only the C compiler is built.</para>
  80. </listitem>
  81. </varlistentry>
  82. <varlistentry>
  83. <term><parameter>--disable-multilib</parameter></term>
  84. <listitem>
  85. <para>We currently only want to build support for 64-bit libraries.</para>
  86. </listitem>
  87. </varlistentry>
  88. <varlistentry>
  89. <term><parameter>--with-arch=i486</parameter></term>
  90. <listitem>
  91. <para>On x86 machines Glibc-&glibc-version; needs to be built for a
  92. minimum architecture of <quote>i486</quote>. In fact, Glibc developers suggest
  93. setting the compiler flag <parameter>-march=i486</parameter> when compiling it.
  94. However, by using the above parameter for the GCC build, we can set a default
  95. value for <parameter>-march</parameter> at the compiler level, ensuring that
  96. the entire system is built consistently, i.e., for the same cpu-type.
  97. Of course, values greater or more specific than <quote>i486</quote> could be
  98. used. See <command>man gcc</command> for other acceptable cpu-types.
  99. Keep in mind that using an incompatible cpu-type for the machine will result
  100. in breakage. The advantage of <quote>i486</quote> is that it is a generic
  101. option and will work for all modern x86 machines.</para>
  102. </listitem>
  103. </varlistentry>
  104. </variablelist>
  105. <para>The following command will compile GCC not once, but several times. It
  106. uses the programs compiled in a first round to compile itself a second time,
  107. and then again a third time. It then compares these second and third compiles
  108. to make sure it can reproduce itself flawlessly. This is called
  109. <quote>bootstrapping</quote>. Building GCC in this way ensures that it was
  110. compiled correctly and is now the default configuration for the released
  111. package. Continue with compiling by running:</para>
  112. <screen><userinput>make</userinput></screen>
  113. <para>Compilation is now complete. At this point, the test suite would
  114. normally be run, but, as mentioned before, the test suite framework is
  115. not in place yet. The benefits of running the tests at this point
  116. are minimal since the programs from this first pass will soon be
  117. replaced.</para>
  118. <para>Install the package:</para>
  119. <screen><userinput>make install</userinput></screen>
  120. <para>Using <command>--disable-shared</command> means that the file
  121. <filename class="libraryfile">libgcc_eh.a</filename>
  122. isn't created and installed. The next package, Glibc, depends on this
  123. library as it uses <command>-lgcc_eh</command> within its build system.
  124. We can satisfy that dependency by creating a symlink to
  125. <filename class="libraryfile">libgcc.a</filename>, since that file will
  126. end up containing the objects normally contained in
  127. <filename class="libraryfile">libgcc_eh.a</filename>.</para>
  128. <screen><userinput>ln -vs libgcc.a `gcc -print-libgcc-file-name | \
  129. sed 's/libgcc/&amp;_eh/'`</userinput></screen>
  130. <para>As a finishing touch, create a symlink. Many programs and scripts
  131. run <command>cc</command> instead of <command>gcc</command>, which is
  132. used to keep programs generic and therefore usable on all kinds of UNIX
  133. systems where the GNU C compiler is not always installed. Running
  134. <command>cc</command> leaves the system administrator free to decide
  135. which C compiler to install:</para>
  136. <screen><userinput>ln -vs gcc /tools/bin/cc</userinput></screen>
  137. </sect2>
  138. <sect2 role="content">
  139. <title/>
  140. <para>Details on this package are located in
  141. <xref linkend="contents-gcc" role="."/></para>
  142. </sect2>
  143. </sect1>