gcc-pass1-inst.xml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <sect2><title>&nbsp;</title><para>&nbsp;</para></sect2>
  2. <sect2>
  3. <title>Installation of GCC</title>
  4. <para>We won't be needing a C++ compiler until Chapter 6. So, only
  5. the gcc-core tarball needs to be unpacked at this time.</para>
  6. <para>This package is known to behave badly when you have changed its
  7. default optimization flags (including the -march and -mcpu options).
  8. Therefore, if you have defined any environment variables that override
  9. default optimizations, such as CFLAGS and CXXFLAGS, we recommend unsetting
  10. or modifying them when building GCC.</para>
  11. <para><screen><userinput>patch -Np1 -i ../gcc-&gcc-version;-mmap_test.patch
  12. patch -Np1 -i ../gcc-&gcc-version;-no_fixincludes.patch
  13. patch -Np1 -i ../gcc-&gcc-version;-libstdc++_no_debug.patch
  14. patch -Np1 -i ../gcc-&gcc-version;-libgcc_no_debug.patch</userinput></screen></para>
  15. <para>It is recommended by the GCC installation documentation to build
  16. GCC outside of the source directory in a dedicated directory:</para>
  17. <para><screen><userinput>mkdir ../gcc-build
  18. cd ../gcc-build</userinput></screen></para>
  19. <para>Prepare GCC to be compiled:</para>
  20. <para><screen><userinput>CFLAGS="-O2 -pipe" \
  21. &nbsp;&nbsp;&nbsp;&nbsp;../gcc-&gcc-version;/configure --prefix=/stage1 \
  22. &nbsp;&nbsp;&nbsp;&nbsp;--with-local-prefix=/stage1 \
  23. &nbsp;&nbsp;&nbsp;&nbsp;--disable-nls --enable-shared </userinput></screen></para>
  24. <para>The meaning of the configure options are:</para>
  25. <itemizedlist>
  26. <listitem><para><userinput>--prefix=/static</userinput>: This is NOT a
  27. typo. GCC hard codes some paths while compiling and so we need to pass
  28. <filename class="directory">/static</filename> as the prefix during the
  29. configure stage. We will pass the real installation prefix (<filename
  30. class="directory">$LFS/static</filename>) during the installation
  31. stage later on.</para></listitem>
  32. <listitem><para><userinput>--disable-shared</userinput>: This prevents the
  33. build of dynamic libraries. They are useless to us at the moment. We'll
  34. create them when we reinstall GCC in chapter 6.</para></listitem>
  35. <listitem><para><userinput>--with-as=$LFS/static/bin/as and
  36. --with-ld=$LFS/static/bin/ld</userinput>: GCC can be miscompiled if your
  37. host distribution's Binutils package is quite old. We need a good working
  38. static GCC until we reinstall GCC later in chapter 6. So by using
  39. <filename>as</filename> and <filename>ld</filename> from the Binutils
  40. package we compiled earlier in this chapter we ensure that GCC will work
  41. correctly.</para></listitem>
  42. </itemizedlist>
  43. <para>Continue with compiling the package:</para>
  44. <para><screen><userinput>make BOOT_LDFLAGS="-static -s" \
  45. &nbsp;&nbsp;&nbsp;&nbsp;BOOT_CFLAGS="-O2 -pipe" \
  46. &nbsp;&nbsp;&nbsp;&nbsp;STAGE1_CFLAGS="-pipe" bootstrap</userinput></screen></para>
  47. <para>The meaning of the make options are:</para>
  48. <itemizedlist>
  49. <listitem><para><userinput>BOOT_LDFLAGS="-static"</userinput>: This is
  50. GCC's equivalent to make LDFLAGS="-static" as we use with other packages to
  51. compile them statically.</para></listitem>
  52. <listitem><para><userinput>bootstrap</userinput>: The
  53. <emphasis>bootstrap</emphasis> target doesn't just compile GCC, but it
  54. compiles GCC a second time. It uses the first compiled programs to compile
  55. itself a second and third time to make sure the compiler was compiled properly
  56. and can compile itself properly.</para></listitem>
  57. </itemizedlist>
  58. <para>And finish off installing the package:</para>
  59. <para><screen><userinput>make install</userinput></screen></para>
  60. <para>The meaning of the make option is:</para>
  61. <itemizedlist>
  62. <listitem><para><userinput>install-no-fixedincludes</userinput>: This prevents
  63. the fixincludes script from running. Preventing this is necessary because
  64. under normal circumstances the GCC installation will run the fixincludes
  65. script which scans your system for header files that need to be fixed. It
  66. might find that the Glibc header files of your host system need to be fixed.
  67. If so, it will fix them and put them in
  68. <filename>$LFS/static/lib/gcc-lib/i686-pc-linux-gnu/3.2</filename>. Later on
  69. in chapter 6 you will install Glibc which will put its header files in
  70. <filename>/usr/include</filename>. Next you will install other programs that
  71. use the Glibc headers and GCC will look in
  72. <filename>/static/lib/gcc-lib</filename> before looking in
  73. <filename>/usr/include</filename>, with the result of finding and using the
  74. fixed Glibc header files from your host distribution, which are probably
  75. incompatible with the Glibc version actually used on the LFS
  76. system.</para></listitem>
  77. </itemizedlist>
  78. <para>As the finishing touch we'll create the <filename
  79. class="symlink">$LFS/static/bin/cc</filename> symlink. A lot of programs
  80. and scripts try to run <userinput>cc</userinput> instead of
  81. <userinput>gcc</userinput> This is to keep programs generic and usable on
  82. all kinds of Unix systems. Not everybody has GNU CC installed. Just running
  83. <userinput>cc</userinput> (C Compiler) leaves the user free to decide which
  84. C compiler to install. The symlink will point to the system's default
  85. compiler.</para>
  86. <para><screen><userinput>ln -sf gcc /stage1/bin/cc</userinput></screen></para>
  87. </sect2>