gnatmake
Build Ada executables from source code
TLDR
Compile an executable
Set a custom executable name
[f]orce recompilation
SYNOPSIS
gnatmake [options] main_source_file [project_file]
or
gnatmake [options] -Pproject_file [main_source_file]
PARAMETERS
-Pproject_file
Specifies the GNAT project file (e.g., my_project.gpr) to be used for the build.
-gnatL
Lists the linker options that would be used without actually performing the link.
-gnatO output_file
Specifies the name of the executable output file produced by the link stage.
-c
Compiles only, without performing the final linking step to create an executable.
-l
Links only, assuming all necessary compilation units are already compiled and up-to-date.
-f
Forces unconditional recompilation of all source files, ignoring timestamps.
-q
Operates in quiet mode, suppressing most informational messages during the build.
-v
Operates in verbose mode, showing detailed progress and commands executed.
-k
Continues as much as possible after encountering compilation or linking errors.
-jN
Compiles and links in parallel, utilizing up to N jobs/threads.
-D
Adds debugging information to the compiled executables, enabling source-level debugging.
-Olevel
Specifies the optimization level for the compiler (e.g., 0 for no optimization, 1, 2, 3 for increasing optimization, s for size optimization).
-Xname=value
Defines or overrides an external variable within the project file context.
-adir
Adds a source directory to the list of paths searched for source files.
-u
Updates object files even if only the source file's date is newer, overriding other checks.
--RTS=runtime
Specifies the Ada runtime library to use for linking (e.g., light-tasking, ravenscar-sfp).
DESCRIPTION
gnatmake is the primary build utility for Ada projects within the GNAT (GNU Ada Toolset) environment. Similar to the traditional make command, it automates the compilation and linking process by analyzing dependencies between source files. It intelligently recompiles only those files that have changed or whose dependencies have been updated, ensuring efficient builds and reducing compilation times.
It integrates seamlessly with GNAT's compiler and linker, supporting various compilation modes, optimization levels, and debugging options. gnatmake can operate on individual source files or, more commonly, utilize GNAT Project Files (.gpr files) to manage complex multi-directory, multi-language projects. This streamlines the entire build workflow for Ada applications, making it an essential tool for developers working with the Ada programming language.
CAVEATS
gnatmake is specifically designed for Ada projects and requires the GNAT toolchain to be installed and correctly configured. While powerful, particularly with GNAT Project Files (.gpr), complex project setups might require a deep understanding of .gpr file syntax and inter-project dependencies. It primarily focuses on Ada, though project files can integrate other languages (like C/C++), their compilation might still rely on external tools. Debugging build issues often involves examining verbose output or thoroughly checking .gpr file definitions.
PROJECT FILE INTEGRATION
gnatmake heavily leverages GNAT Project Files (.gpr) for managing complex, multi-language, and multi-directory projects. These files serve as a central definition for sources, object directories, executable names, external tool chains, and dependencies, significantly simplifying the build process compared to manual makefiles.
AUTOMATIC DEPENDENCY MANAGEMENT
One of gnatmake's core strengths is its automatic dependency analysis. It intelligently parses Ada's with clauses and separate compilation units to determine the precise order of compilation and to only recompile units that are truly out of date. This saves considerable build time and reduces the chance of erroneous builds due to overlooked dependencies.
HISTORY
gnatmake emerged as part of the GNAT (GNU Ada Toolset) project, which began in the early 1990s at New York University. Its development aimed to provide a robust, open-source Ada compiler and a complete development environment, including a sophisticated build system. gnatmake was designed to leverage Ada's strong typing and module system to automatically manage dependencies, making builds more reliable and efficient than traditional make setups for Ada.
While gprbuild later introduced more generalized and advanced project management capabilities, gnatmake remains a core utility for building Ada applications, especially for simpler projects or when explicit control over compilation and linking is desired.