A number of GNAT tools, other than gnatmake are project-aware: gnatbind, gnatfind, gnatlink, gnatls, gnatelim, gnatpp, gnatmetric, gnatstub, and gnatxref. However, none of these tools can be invoked directly with a project file switch (-P). They must be invoked through the gnat driver.
The gnat driver is a front-end that accepts a number of commands and call the corresponding tool. It has been designed initially for VMS to convert VMS style qualifiers to Unix style switches, but it is now available to all the GNAT supported platforms.
On non VMS platforms, the gnat driver accepts the following commands (case insensitive):
(note that the compiler is invoked using the command gnatmake -f -u -c).
On non VMS platforms, between gnat and the command, two special switches may be used:
The command may be followed by switches and arguments for the invoked tool.
gnat bind -C main.ali gnat ls -a main gnat chop foo.txt
Switches may also be put in text files, one switch per line, and the text files may be specified with their path name preceded by '@'.
gnat bind @args.txt main.ali
In addition, for commands BIND, COMP or COMPILE, FIND, ELIM, LS or LIST, LINK, METRIC, PP or PRETTY, STUB and XREF, the project file related switches (-P, -X and -vPx) may be used in addition to the switches of the invoking tool.
When GNAT PP or GNAT PRETTY is used with a project file, but with no source specified on the command line, it invokes gnatpp with all the immediate sources of the specified project file.
When GNAT METRIC is used with a project file, but with no source specified on the command line, it invokes gnatmetric with all the immediate sources of the specified project file and with -d with the parameter pointing to the object directory of the project.
In addition, when GNAT PP, GNAT PRETTY or GNAT METRIC is used with a project file, no source is specified on the command line and switch -U is specified on the command line, then the underlying tool (gnatpp or gnatmetric) is invoked for all sources of all projects, not only for the immediate sources of the main project. (-U stands for Universal or Union of the project files of the project tree)
For each of the following commands, there is optionally a corresponding package in the main project.
Binderfor command BIND (invoking
Compilerfor command COMP or COMPILE (invoking the compiler)
Finderfor command FIND (invoking
Eliminatefor command ELIM (invoking
Gnatlsfor command LS or LIST (invoking
Linkerfor command LINK (invoking
Metricsfor command METRIC (invoking
Pretty_Printerfor command PP or PRETTY (invoking
Gnatstubfor command STUB (invoking
Cross_Referencefor command XREF (invoking
Gnatls has a unique attribute
a simple variable with a string list value. It contains switches
for the invocation of
project Proj1 is package gnatls is for Switches use ("-a", "-v"); end gnatls; end Proj1;
All other packages have two attribute
Switches is an associated array attribute, indexed by the
source file name, that has a string list value: the switches to be
used when the tool corresponding to the package is invoked for the specific
Default_Switches is an associative array attribute,
indexed by the programming language that has a string list value.
Default_Switches ("Ada") contains the
switches for the invocation of the tool corresponding
to the package, except if a specific
is specified for the source file.
project Proj is for Source_Dirs use ("./**"); package gnatls is for Switches use ("-a", "-v"); end gnatls; package Compiler is for Default_Switches ("Ada") use ("-gnatv", "-gnatwa"); end Binder; package Binder is for Default_Switches ("Ada") use ("-C", "-e"); end Binder; package Linker is for Default_Switches ("Ada") use ("-C"); for Switches ("main.adb") use ("-C", "-v", "-v"); end Linker; package Finder is for Default_Switches ("Ada") use ("-a", "-f"); end Finder; package Cross_Reference is for Default_Switches ("Ada") use ("-a", "-f", "-d", "-u"); end Cross_Reference; end Proj;
With the above project file, commands such as
gnat comp -Pproj main gnat ls -Pproj main gnat xref -Pproj main gnat bind -Pproj main.ali gnat link -Pproj main.ali
will set up the environment properly and invoke the tool with the switches
found in the package corresponding to the tool:
Default_Switches ("Ada") for all tools,