Guide to Building gcc/gfortran

DRAFT in process

Building gfortran is usually fairly straight-forward. However, it is known that users not familiar with the process or when building on a system they have not used before, may have some issues. This guide is an attempt to describe the steps to go through to get you a working version.

The Build Process

The following steps provide an overview of the build process:

  1. Prerequisites and getting the source.
  2. Setting up a build directory and an installation directory.
  3. Configuring the build directory.
  4. Invoking make.
  5. Checking and testing.
  6. Installing.

Prerequisites and Getting the Source

Prerequisites

There are several prerequisite utility programs and libraries that you must have for things to build correctly. In fact, if you do not have these in place in the right way you probably will not get past the configuration step.

Gcc/gfortran follows the Gnu Build System. As such, the maintainers use Autotools to create the build system. You do not need to know anything about Autotools. What you do need to know is that when you do get the source code for gcc you will see a file in the top source directory called 'configure'. This configure file is a shell script that was generated using Autotools. This script is chock full of code and macro that will check your system for you and establish all the parameters you need to build gcc/gfortran. We will have more to say about configuration later.

The prerequisites needed are listed on the GCC main website here

There are several ways you can get these prerequisites. Some will be installed on your system already, such as the standard C compiler and binutils. Others you may have to install yourself. If your system supports a package manager such as apt-get or dnf, or brew, you can use these tools to install the needed packages. The package managers will likely install these in places where your system will find them as needed and a lot of times this is a painless way to go. It will also ensure that you don't install something that may get crossed up with your systems.

Another method preferred by some people is to build the prerequisite libraries and utilities by yourself from source. If you choose to do this, do make sure you install them where the executables are in your search PATH and the libraries and include files can be found. This is often where people get into difficulty. If you are not comfortable doing these things, do not use this approach.

If you do not know whether or not you have what you need installed, then read on. In the configuration section we will discuss how to discover things when the configure script is run.

Gcc/Fortran Source

On the main gcc web page there are links provided that tell you how to get to the source code. You can either grab a snapshot tarball or use either git or svn to get the source files. It is important to keep these in a clean, unmodified directory. If you are a software developer then you will understand this. If not, just follow along.

It is usually a good idea to establish a place in your home directory where you will work.

cd ~

mkdir dev
mkdir dev/trunk

The names of the directories can be what you choose. We use 'dev' and 'trunk' to designate a place for development and the latest experimental branch of gcc/gfortran commonly referred to as trunk. You can just as easily call it gcc7 if you were for example wanting to build the latest gcc7 snapshot.

--- to be continued ---

Build and Installation Directories

Do not try to build gcc/gfortran from within the source directory. It is best to create a separate build directory outside of all source directories. This ensures that your source tree stays clean and untouched and that the build process does not overwrite anything. Following the example starting from your home directory, create a new build directory.

mkdir ~/dev/objdir

You will also need a place to install everything. This can be wherever you chose. I will do this.

mkdir ~/dev/usr

During installation, executables, libraries, info files, etc, will be installed in there with appropriate sub-directories created for you.

Configuring the Build Directory

Move into the build directory.

cd ~/dev/objdir

Now, assuming the gcc/gfortran source is where we put it, execute the configurations command.

../trunk/configure --prefix=~/dev/usr --enable-languages=c,c++,fortran --disable-bootstrap 

Watch as the messages fly by. If something needed is missing, configure will usually stop and let you know what it is with an error message. There is also a file generated called config.log. You can examine this file for additional information. If you want to do a full bootstrap do the following instead.

../trunk/configure --prefix=~/dev/usr --enable-languages=c,c++,fortran --enable-bootstrap 

Bootstrap or Not

Since gfortran is a part of gcc (Gnu Compiler Collection), when building from source it is necessary to also build the gcc C and C++ compilers. When building, you may choose whether or not to use a bootstrapping process or not. Bootstrapping is a 3 stage process. The first stage builds the C and C++ compilers using the available system compilers. After the first stage is completed, the just built compilers are used to rebuild themselves to make sure latest features and fixed bugs are incorporated correctly. Finally, in the third stage the second stage compilers are used to build the final products including C, C++, Fortran, and other front-ends if you selected them during configuration.

Boot-strapping takes longer to do and some prefer this as a level of assurance that all is well. If you plan to use the C and C++ compilers as well as Fortran, you probably should use the bootstrapped process. If you want to finish sooner and only want to use Fortran, you probably don't need to bootstrap.

Configuration Options

If you do this:

../trunk/configure --help

The configure script will display a long list of available options to you along with some helpful information. You can choose to have things installed wherever you want. Usually its best to just give a --prefix= and keep things together under the installation directory you specify. If you encounter a situation where configure can not find something that you know is installed on your system you can use the options that start with '--with-*'. These allow you to tell configure exactly where it is.

Invoking Make

Checking and Testing

Installing

None: Guide to Building gcc/gfortran (last edited 2017-07-23 14:52:02 by JerryDeLisle)