LinuxCommandLibrary

gnatmake

Build Ada executables from source code

TLDR

Compile an executable

$ gnatmake [source_file1.adb source_file2.adb ...]
copy

Set a custom executable name
$ gnatmake -o [executable_name] [source_file.adb]
copy

[f]orce recompilation
$ gnatmake -f [source_file.adb]
copy

SYNOPSIS

gnatmake [options] main_program.adb

PARAMETERS

-a
    Analyze the project files only, without building.

-c
    Compile Ada sources, default is compiling and linking.

-f
    Force recompilation of all sources, even if they are up to date.

-m
    Display the command lines that would be executed without actually executing them.

-n
    No execute mode.

-p
    Compile the project file.

-P project_file.gpr
    Specify the project file to use.

-q
    Quiet mode; suppress informational messages.

-u
    Consider all source files out of date.

-v
    Verbose mode; display more detailed information about the build process.

-x
    Create cross-reference data during compilation.

-jN
    Specifies the number of parallel compilation jobs. N is an integer.

DESCRIPTION

gnatmake is a command-line tool used for building and managing Ada projects. It analyzes Ada source code, including project files (.gpr), to determine dependencies and compilation order. It automatically compiles and links the necessary files to create an executable. gnatmake simplifies the build process, especially for complex projects with multiple files and dependencies. It uses the project file to understand the structure of the project, including source directories, object directories, and library dependencies. It can also handle mixed-language projects, where Ada code interacts with code written in other languages like C or C++. It provides options for controlling optimization levels, debugging information, and other compiler settings. Overall, gnatmake automates the process of compiling and linking Ada projects, ensuring that all dependencies are satisfied and that the resulting executable is built correctly.
It aims for incremental compilation where recompilation only happens if a file is modified and will also use as many parallel compilation jobs as available.

CAVEATS

gnatmake relies heavily on correctly configured project files (.gpr). Errors in the project file can lead to unexpected build failures. It also expects that compiler environment (PATH, etc.) is configured properly.

PROJECT FILES (.GPR)

Project files (.gpr) are essential for gnatmake. They describe the structure of the Ada project, including source directories, object directories, library dependencies, and compiler settings. The project file uses a specific syntax to define these elements, which gnatmake interprets to build the project.

ERROR HANDLING

gnatmake provides detailed error messages when compilation or linking fails. These messages typically include the file name, line number, and a description of the error. Understanding these error messages is crucial for debugging build problems. Using verbose mode (-v) can provide more context.

HISTORY

gnatmake was developed as part of the GNU Ada Toolchain (GNAT) project. It was designed to simplify the build process for Ada programs and has been a standard tool for Ada development for many years. It evolved from simple compilation scripts to a sophisticated build system that handles dependencies and optimizes the build process.
Originally started as a way to automate Ada build processes by integrating Ada compilers to make the process automatic.

SEE ALSO

gcc(1), gprbuild(1), gprls(1)

Copied to clipboard