Next: , Previous: Compilation of one or several sources, Up: Building with GPRbuild   [Contents][Index]

3.1.5 Compilation Phase

When switch -c is used or when switches -b or -l are not used, GPRbuild will first compile or recompile the sources that are not up to date in all the projects in the project tree. The sources considered are:

Attribute Roots takes as an index a main and a string list value. Each string in the list is the name of an Ada library unit.

Example:

   for Roots ("main.c") use ("pkga", "pkgb");

Package PkgA and PkgB will be considered, and all the Ada units in their closure will also be considered.

GPRbuild will first consider each source and decide if it needs to be (re)compiled.

A source needs to be compiled in the following cases:

When a source is successfully compiled, the following files are normally created in the object directory of the project of the source:

The compiler for the language corresponding to the source file name is invoked with the following switches/options:

If compilation is needed, then all the options/switches, except those described as “Various other options” are written to the switch file. The switch file is a text file. Its file name is obtained by replacing the suffix of the source with .cswi. For example, the switch file for source main.adb is main.cswi and for toto.c it is toto.cswi.

If the compilation is successful, then if the creation of the dependency file is not done during compilation but after (see configuration attribute Compute_Dependency), then the process to create the dependency file is invoked.

If GPRbuild is invoked with a switch -j specifying more than one compilation process, then several compilation processes for several sources of possibly different languages are spawned concurrently.

For each project file, attribute Interfaces may be declared. Its value is a list of sources or header files of the project file. For a project file extending another one, directly or indirectly, inherited sources may be in the list. When Interfaces is not declared, all sources or header files are part of the interface of the project. When Interfaces is declared, only those sources or header files are part of the interface of the project file. After a successful compilation, gprbuild checks that all imported or included sources or header files that are from an imported project are part of the interface of the imported project. If this check fails, the compilation is invalidated and the compilation artifacts (dependency, object and switches files) are deleted.

Example:

   project Prj is
      for Languages use ("Ada", "C");
      for Interfaces use ("pkg.ads", "toto.h");
   end Prj;

If a source from a project importing project Prj imports sources from Prj other than package Pkg or includes header files from Prj other than "toto.h", then its compilation will be invalidated.