AUTHOR: Randy McMurchy DATE: 2007-07-01 LICENSE: Creative Commons Attribution-NonCommercial-ShareAlike License http://creativecommons.org/licenses/by-nc-sa/1.0/ SYNOPSIS: Installing all the GCC compilers while building LFS DESCRIPTION: This hint will guide you through the installation of any or all the GCC compilers while building an LFS system. These instructions target the 4.x.x series of GCC as there have been significant changes since the 3.x.x series. Prior to the 4.x.x series, only the Ada compiler could not be installed during Chapter 6 of an LFS build. See my http://www.linuxfromscratch.org/hints/downloads/files/ada_install_during_lfs.txt hint for instructions to install the Ada compiler during an LFS build if you are using a version of GCC prior to 4.x.x. ATTACHMENTS: None REQUIRED DOWNLOADS: 1. The GCC tarball for whatever version of GCC called for in LFS. This will be a file named something similar to gcc-4.1.2.tar.bz2 2. The 2005 version of the GNAT compiler found on the AdaCore site. The download location (https://libre.adacore.com/dynamic/download_page) requires that you create an account on the AdaCore site before you can download the package. Nothing is required other than a valid email address. Ensure you download the 2005 version of the GNAT compiler. The 2006 version will not work. The file name you need is: gnat-gpl-2005-i686-gnu-linux-gnu-libc2.3-bin.tar.gz. (not required if your host system has an existing Ada compiler, or you don't plan on installing the GCC Ada compiler) 3. A GMP tarball if you plan on installing the Fortran compiler. See http://www.linuxfromscratch.org/blfs/view/svn/general/gmp.html for download locations. 4. An MPFR tarball if you plan on installing the Fortran compiler. See http://www.mpfr.org/mpfr-current/ for download locations. PREREQUISITES: None HINT: ========= CONTENTS: ========= 1. Introduction 2. The Treelang compiler 3. The Fortran compiler GMP installation MPFR installation GCC installation 4. The Ada compiler 5. Package dependencies 6. Installing the GNAT Ada compiler 7. Configuring the PATH variable 8. Chapter 5 GCC-Pass1 Modifications 9. Reconfiguring the PATH variable 10. Chapter 5 GCC-Pass2 Modifications 11. Chapter 5 Ncurses modifications 12. Chapter 6 GCC Modifications 13. Chapter 6 Ncurses modifications 14. Closing ================ 1. INTRODUCTION: ================ The default installation during LFS only installs a C and C++ compiler. If you know that you'll need additional compilers after LFS is built, it is easier to just build the additional compilers during LFS. So, you say to yourself, when I get to the GCC installation in Chapter 6 of LFS, I'll just add additional compilers to the configure script command and I'll build them then. This won't work for the Ada, Fortran or Treelang compilers. For these three compilers, you cannot wait until the GCC installation in Chapter 6 to decide you want/need to install them (Fortran is a slight exception to this). At this point of Chapter 6, you are in a chroot environment working with whatever is installed in the /tools directory you created in Chapter 5 and there are not adequate tools, nor any real way to add them, to compile Ada and Treelang. In summary, if you need to install the Ada, Fortran or Treelang compilers during Chapter 6 of an LFS build, you'll need to do some extra work. The Java and Objective C compilers can be installed by simply adding them to the list of compilers in the configure script parameter, --enable-languages=... In order to install the GCC Ada compiler, you must have an existing Ada compiler available so GCC can boostrap its version of Ada. If your host has an existing Ada compiler, you can omit some of this hint and simply use the updated Chapter 5 and Chapter 6 GCC installation instructions. More on this in the appropriate sections later in the hint. ========================= 2. THE TREELANG COMPILER: ========================= You probably don't need the Treelang compiler. It is only good for developers who are developing a new compiler for GCC. However, if you wish to build it during a build of LFS, you'll need to install the Bison and Flex packages before starting the Chapter 6 build of GCC. ======================== 3. THE FORTRAN COMPILER: ======================== Starting with version 4.x.x of GCC, there is no longer support for the Fortran 77 series of compilers. Fortran 95 is now included with GCC. In order to build the Fortran 95 compiler, the system must have the GMP and MPFR packages installed. See the "REQUIRED DOWNLOADS" section above for links to information about these packages. Installing these packages in Chapter 5 may end up producing undesireable results as GCC may look for bits of these packages later in a /tools directory which won't exist any longer. So, it is safer to install these packages in Chapter 6. Installation of packages is somewhat wierd before GCC is installed in Chapter 6, but using the extra parameters shown below seemed to get GMP, MPFR and Fortran 95 installed correctly. Both of these packages should be built after Binutils and before GCC in Chapter 6. GMP should be installed first. ---------------- GMP Installation ---------------- In order to build the GMP C++ extension library (by passing --enable-cxx parameter to configure), you'll need to fake an installation of the libstdc++ library in /usr/lib of the new LFS partition. Issue the two commands below before building the GMP package to provide temporary symlinks to the library in the /tools/lib directory: ln -v -s /tools/lib/libstdc++.so.6 /usr/lib ln -v -s /tools/lib/libstdc++.so /usr/lib Additionally, you'll need to install the M4 package at the end of Chapter 5 or before the GMP installation in Chapter 6. You can use the existing LFS Chapter 6 instructions for installing the M4 package. ----------------- MPFR Installation ----------------- The installation of MPFR must also be slightly modified at this point for a good installation. I found that I had to add --with-gmp-include=/usr/include to the configure script so MPFR could find GMP's library interface header. Here are the commands I used to install MPFR: ./configure --prefix=/usr \ --enable-thread-safe \ --enable-shared \ --with-gmp-include=/usr/include make make html make check make install ---------------- GCC Installation ---------------- At this point (GMP and MPFR installations complete), you can add the fortran language to the --enable-languages switch on GCC's configure and expect it to successfully build Fortran 95. However, you also need to add a couple more parameters to the configure script so that configure can find the two packages you just installed. I'm not certain, but apparently it must look in /tools for these packages, so parameters are added to configure to tell it to look in /usr. Add these two parameters to GCC's configure script: --with-mpfr=/usr --with-gmp=/usr The complete command I used to install all the compilers was: ../gcc-4.0.3/configure \ --prefix=/usr \ --libexecdir=/usr/lib \ --enable-shared \ --enable-threads=posix \ --enable-__cxa_atexit \ --enable-clocale=gnu \ --with-mpfr=/usr \ --with-gmp=/usr \ --enable-languages=c,c++,objc,fortran,ada,java,treelang ==================== 4. THE ADA COMPILER: ==================== Starting with version 4.x.x of GCC, the Ada installation is simpler, but it still requires an initial boostrap using an existing Ada compiler. If you have an Ada compiler on the host system you're building LFS on, there isn't much required before you can just build GCC. ======================== 5. PACKAGE DEPENDENCIES: ======================== As previously mentioned, if you already have an existing Ada compiler on the host system, you won't need to install the GNAT binary Ada compiler. You can skip to step 7 and configure your path. If you don't have an existing Ada compiler, you'll need to install the GNAT binary version available from the URL shown in the "REQUIRED DOWNLOADS" section at the beginning of the hint. ==================================== 6. INSTALLING THE GNAT ADA COMPILER: ==================================== You'll need to install the GNAT Ada compiler before starting the Chapter 5 GCC-Pass1 instructions in the LFS book. This is right after the Binutils-Pass1 installation. Here's the simple installation procedure for the GNAT Ada compiler: 1. Download the tarball from the Adacore site. 2. Unpack the tarball and change directories into the root of the source tree. 3. Issue the following command to install the GNAT compiler: make ins-all prefix=/tools/gnat You should check and ensure that the /tools/gnat directory was created and populated with files. The GNAT source tree can then be removed. ================================= 7. CONFIGURING THE PATH VARIABLE: ================================= You'll need to modify the PATH variable so that the newly installed GNAT compiler is used to bootstrap GCC. Issue the following commands: PATH_HOLD=$PATH export PATH=/tools/gnat/bin:$PATH_HOLD Ensure your PATH variable was changed properly: echo $PATH And if you have the 'which' command installed on your host: which gcc NOTE: if you're using an existing Ada compiler from your host, make the appropriate substitutions above so this compiler is invoked by the 'gcc' command. ===================================== 8. CHAPTER 5 GCC-PASS1 MODIFICATIONS: ===================================== There's some changes required to the Chapter 5 installation of GCC-Pass1. 1. You'll need to unpack the gcc-ada tarball along with the gcc-core tarball so the GCC Ada sources are available. Alternatively, just unpack the combined GCC tarball which contains all the compilers. 2. Modify the ./configure command to pass --enable-languages=c,ada (Note the addition of ",ada") Except for the changes shown above, follow the commands as outlined in the Chapter 5 GCC-Pass1 instructions in LFS. If desired, remove the /tools/gnat directory at the conclusion of the Chapter 5 GCC-Pass1 instructions, as the GNAT compiler won't be required any longer. All remaining GCC installations are done using the now existing GCC version of Ada. =================================== 9. RECONFIGURING THE PATH VARIABLE: =================================== Now that you are done with the GNAT compiler, put your PATH variable back like it was using the following commands: export PATH=$PATH_HOLD unset PATH_HOLD Ensure your PATH variable was changed properly: echo $PATH And if you have the 'which' command installed on your host: which gcc which gnat ===================================== 10. CHAPTER 5 GCC-PASS2 MODIFICATIONS: ===================================== There's some changes required to the Chapter 5 installation of GCC-Pass2. 1. You'll need to unpack the gcc-ada tarball along with the gcc-core and gcc-g++ tarballs so the GCC Ada sources are available. Alternatively, just unpack the combined GCC tarball which contains all the compilers. 2. Modify the ./configure command to pass --enable-languages=c,c++,ada (Note the addition of ",ada") Except for the changes shown above, follow the commands as outlined in the Chapter 5 GCC-Pass2 instructions in LFS. =================================== 11. CHAPTER 5 NCURSES MODIFICATIONS: =================================== Remove the --without-ada switch in the Chapter 5 installation of the Ncurses package if you desire for Ncurses to be Ada-aware and build the Ada hooks. I'm not real sure this is required in Chapter 5, but I've never bothered to test and see. I just remove the switch and let it build the Ada components. =============================== 12. CHAPTER 6 GCC MODIFICATIONS: =============================== There's some changes required to the Chapter 6 installation of GCC. 1. You'll need to unpack the gcc-ada tarball along with the gcc-core and gcc-g++ tarballs so the GCC Ada sources are available. Alternatively, just unpack the combined GCC tarball which contains all the compilers. At this point also decide if you'd like to install additional (or all) compilers. There's nothing keeping you from installing all of the compilers included in the GCC source tarball (providing you followed the other instructions in this hint for Fortran 95 and Treelang). Do remember to also unpack the testsuite tarball if you used the individual compiler tarballs. 2. Modify the ./configure command to pass --enable-languages=c,c++,ada (Note the addition of ",ada") ***** Alternatively, use --enable-languages=all, or add any other additional ***** compilers on the --enable-languages= parameter. 3. After the "make install" step, issue the following command: chown -v -R root:root /usr/lib/gcc/i686-pc-linux-gnu/4.1.2/adainclude (modify the GCC version number in the path shown above) Except for the changes shown above, follow the commands as outlined in the Chapter 6 GCC instructions in LFS. =================================== 13. CHAPTER 6 NCURSES MODIFICATIONS: =================================== If you installed an Ada compiler and you didn't use a parameter to the Ncurses configure script to prevent it from building the Ncurses Ada components, issue the following command to change the ownership of some installed files to the root user. chown -v -R root:root /usr/lib/ada/adainclude =========== 14. CLOSING: =========== Following these easy instructions allows you to install the full suite of GCC compilers during your LFS build, eliminating the time-consuming and perhaps risky process of reinstalling C and C++ later on during your BLFS adventure. ACKNOWLEDGEMENTS: * Jim Gifford for the tip about using the existing Makefile to install GNAT. * The LFS community for creating and maintaining such a cool project. CHANGELOG: [2007-07-01] * Updated the Gnat download instructions * Updated the requirements to install the 'treelang' language * Updated the GMP installation instructions [2006-05-18] * Changed the GNAT installation to use the existing Makefile, which eliminates the need to install Tcsh. [2006-05-03] * Updated for the LFS-6.2 version, including installing the 4.0.3 compiler. Added instructions to install all the compilers, not just the Ada compiler. [2005-03-14] * Fixed typo * Modified the Chapter 5 instructions to not use forced static build [2005-03-13] * Added instructions to change the ownership of the Ada interface header include files to root [2005-03-12] * Original draft