A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.adacore.com/gprbuild-docs/html/gprbuild_ug/building_with_gprbuild.html below:

Website Navigation


3. Building with GPRbuild — GPR Tools User's Guide 26.0w documentation

3. Building with GPRbuild 3.1. Introduction

GPRbuild is a generic build tool designed for the construction of large multi-language systems organized into subsystems and libraries. It is well-suited for compiled languages supporting separate compilation, such as Ada, C, C++ and Fortran.

GPRbuild manages a three step build process.

The tool is generic in that it provides, when possible, equivalent build capabilities for all supported languages. For this, it uses a configuration file <file>.cgpr that has a syntax and structure very similar to a project file, but which defines the characteristics of the supported languages and toolchains. The configuration file contains information such as:

On the other hand, GPRbuild is not a replacement for general-purpose build tools such as make or ant which give the user a high level of control over the build process itself. When building a system requires complex actions that do not fit well in the three-phase process described above, GPRbuild might not be sufficient. In such situations, GPRbuild can still be used to manage the appropriate part of the build. For instance it can be called from within a Makefile.

3.2. Command Line

Three elements can optionally be specified on GPRbuild’s command line:

The general syntax is thus:

gprbuild [<proj>.gpr] [switches] [names]
 {[-cargs opts] [-cargs:lang opts] [-largs opts] [-kargs opts]
  [-gargs opts]}

GPRbuild requires a project file, which may be specified on the command line either directly or through the -P switch. If not specified, GPRbuild uses the project file default.gpr if there is one in the current working directory. Otherwise, if there is only one project file in the current working directory, GPRbuild uses this project file.

Main source files represent the sources to be used as the main programs. If they are not specified on the command line, GPRbuild uses the source files specified with the Main attribute in the project file. If none exists, then no executable will be built. It is also possible to specify absolute file names, or file names relative to the current directory.

When source files are specified along with the option -c, then recompilation will be considered only for those source files. In all other cases, GPRbuild compiles or recompiles all sources in the project tree that are not up to date, and builds or rebuilds libraries that are not up to date.

If invoked without the --config= or --autoconf= options, then GPRbuild will look for a configuration project file. The file name or path name of this configuration project file depends on the target, the runtime and environment variable GPR_CONFIG See Configuring with GPRconfig. If there is no such file in the default locations expected by GPRbuild (<install>/share/gpr and the current directory) then GPRbuild will invoke GPRconfig with the languages from the project files, and create a configuration project file auto.cgpr in the object directory of the main project. The project auto.cgpr will be rebuilt at each GPRbuild invocation unless you use the switch --autoconf=path/auto.cgpr, which will use the configuration project file if it exists and create it otherwise.

Options given on the GPRbuild command line may be passed along to individual tools by preceding them with one of the “command line separators” shown below. Options following the separator, up to the next separator (or end of the command line), are passed along. The different command line separators are:

3.3. Switches

GPRbuild takes into account switches that may be specified on the command line or in attributes Switches(<main or language>) or Default_Switches (<language>) in package Builder of the main project.

When there are a single main (specified on the command line or in attribute Main in the main project), the switches that are taken into account in package Builder of the main project are Switches (<main>), if declared, or Switches (<language of main>), if declared.

When there are several mains, if there are sources of the same language, then Switches (<language of main>) is taken into account, if specified.

When there are no main specified, if there is only one compiled language (that is a language with a non empty Compiler Driver), then Switches (<single language>) is taken into account, if specified.

The switches that are interpreted directly by GPRbuild are listed below.

First, the switches that may be specified only on the command line, but not in package Builder of the main project:

p.gpr:

with "q.gpr";

project P is
  for Source_Dirs use ("srcP");
  for Object_Dir use "objP";
  for Main use ("main.adb");
end P;

q.gpr:

project Q is
  for Source_Dirs use ("src");
  for Object_Dir use "obj";
end Q;

gprbuild -Pp.gpr -p would fail with the following error:

Setup
  [mkdir]        object directory for project Q
  [mkdir]        object directory for project P
q.gpr:2:24: "src" is not a valid directory
gprbuild: "p.gpr" processing failed

as there is no src directory in the symbolic link directory. gprbuild -Pp.gpr -p -eL would compile correctly and produce the following tree:

.
├── objP
│   └── [compilation artifacts]
├── p.gpr
├── Q
│   ├── obj
|   |   └── [compilation artifacts]
│   ├── q.gpr
│   └── src
│       ├── foo.adb
│       └── foo.ads
├── q.gpr -> Q/q.gpr
└── srcP
    ├── main.adb
    ├── pkg.adb
    └── pkg.ads

Then, the switches that may be specified on the command line as well as in package Builder of the main project (attribute Switches):

Switches that are accepted for compatibility with gnatmake, either on the command line or in the Builder Ada switches in the main project file:

These switches are passed to the Ada compiler.

3.4. Initialization

Before performing one or several of its three phases, GPRbuild has to read the command line, obtain its configuration, and process the project files.

If GPRbuild is invoked with an invalid switch or without any project file on the command line, it will fail immediately.

Examples:

$ gprbuild -P
gprbuild: project file name missing after -P

$ gprbuild -P c_main.gpr -WW
gprbuild: illegal option "-WW"

GPRbuild looks for the configuration project file first in the current working directory, then in the default configuration project directory. If the GPRbuild executable is located in a subdirectory <prefix>/bin, then the default configuration project directory is <prefix>/share/gpr, otherwise there is no default configuration project directory.

When it has found its configuration project path, GPRbuild needs to obtain its configuration. By default, the file name of the main configuration project is default.cgpr. This default may be modified using the switch --config=...

Example:

$ gprbuild --config=my_standard.cgpr -P my_project.gpr

If GPRbuild cannot find the main configuration project on the configuration project path, then it will look for all the languages specified in the user project tree and invoke GPRconfig to create a temporary configuration project file. This file is located in the directory computed by the following sequence:

The invocation of GPRconfig will take into account the target, if specified either by switch --target= on the command line or by attribute Target in the main project. Also, if Ada is one of the languages, it will take into account the Ada runtime directory, specified either by switches --RTS= or --RTS:ada= on the command line or by attribute Runtime ("Ada") in the main project file. If the Ada runtime is specified as a relative path, gprbuild will try to locate the Ada runtime directory as a subdirectory of the main project directory, or in the path specified by environment variable GPR_RUNTIME_PATH if it is defined.

Once it has found the configuration project, GPRbuild will process its configuration: if a single string attribute is specified in the configuration project and is not specified in a user project, then the attribute is added to the user project. If a string list attribute is specified in the configuration project then its value is prepended to the corresponding attribute in the user project.

After GPRbuild has processed its configuration, it will process the user project file or files. If these user project files are incorrect then GPRbuild will fail with the appropriate error messages:

$ gprbuild -P my_project.gpr
ada_main.gpr:3:26: "src" is not a valid directory
gprbuild: "my_project.gpr" processing failed

Once the user project files have been dealt with successfully, GPRbuild will start its processing.

3.5. Compilation of one or several sources

If GPRbuild is invoked with -u or -U and there are one or several source file names specified on the command line, GPRbuild will compile or recompile these sources, if they are not up to date or if -f is also specified. Then GPRbuild will stop its execution.

The options/switches used to compile these sources are described in section Compilation Phase.

If GPRbuild is invoked with -u and no source file name is specified on the command line, GPRbuild will compile or recompile all the sources of the main project and then stop.

In contrast, if GPRbuild is invoked with -U, and again no source file name is specified on the command line, GPRbuild will compile or recompile all the sources of all the projects in the project tree and then stop.

3.6. 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 which is associated with 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.

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.

3.7. Simultaneous compilation

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.

Furthermore, GPRbuild is GNU make jobserver compatible when using the switch --autodetect-jobserver. This means if GPRbuild is embedded in a GNU make recursive invocation and --autodetect-jobserver is set, then GPRbuild will only spawn an additionnal compilation process if GNU make’s jobserver allows it. This is particularly useful to ensure that GPRbuild comply to the ressource management of GNU make.

Example:

build1:
  +gprbuild -P prjA/prj.gpr --autodetect-jobserver

build2:
  +gprbuild -P prjB/prj.gpr --autodetect-jobserver

build_all:
  +make build1 build2

calling make build_all -j4 will spawn two GPRbuild processes, resulting in two remaining and available slots for both GPRbuild compilation phase.

Note: if --autodetect-jobserver is set and GNU make jobserver is detected, then any -jnum will simply be ignored by GPRbuild and a warning will be issued.

3.8. Post-Compilation Phase

The post-compilation phase has two parts: library building and program binding.

If there are libraries that need to be built or rebuilt, gprbuild will call the library builder, specified by attribute Library_Builder. This is generally the tool gprlib, provided with GPRbuild. If gprbuild can determine that a library is already up to date, then the library builder will not be called.

If there are mains specified, and for these mains there are sources of languages with a binder driver (specified by attribute Binder'Driver(<language>), then the binder driver is called for each such main, but only if it needs to.

For Ada, the binder driver is normally gprbind, which will call the appropriate version of gnatbind, that either the one in the same directory as the Ada compiler or the fist one found on the path. When neither of those is appropriate, it is possible to specify to gprbind the full path of gnatbind, using the Binder switch --gnatbind_path=.

Example:

package Binder is
   for Switches ("Ada") use ("--gnatbind_path=/toto/gnatbind");
end Binder;

If GPRbuild can determine that the artifacts from a previous post-compilation phase are already up to date, the binder driver is not called.

If there are no libraries and no binder drivers, then the post-compilation phase is empty.

3.9. Linking Phase

When there are mains specified, either in attribute Main or on the command line, and these mains are not up to date, the linker is invoked for each main, with all the specified or implied options, including the object files generated during the post-compilation phase by the binder drivers.

If switch -jnnn is used, with nnn other than 1, gprbuild will attempt to link simultaneously up to nnn executables.

3.10. Exit code

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4