Emacs provides a full Integrated Development Environment for GNAT and Ada programmers. That is to say, editing, compiling, executing and debugging can be performed within Emacs in a convenient and natural way.
To take full advantage of this features, it is possible to create a file in the main directory of your application, with a '.adp' extension. This file contain all needed information dealing with the way your application is organized between directories, the commands to compile, run and debug it etc. Creating this file is not mandatory and convenient defaults are automatically provided for simple setups. It only becomes necessary when those above mentioned defaults need customizing.
A simple way to edit this file is provided for Emacs 20.2 or newer, with the following functions, that you can access also through the Ada menu. It is also possible to edit the project file as a regular text file.
Once in the buffer for editing the project file, you can save your modification using the '[OK]' button at the bottom of the buffer, or simply use the usual C-x C-s binding. To cancel your modifications, simply kill the buffer or click on the '[CANCEL]' button at the button.
Each buffer using Ada mode will be associated with one project file when there is one available, so that Emacs can easily navigate through related source files for instance.
The exact algorithm to determine which project file should be used is described in the next section, but you can force the project file you want to use by setting one or two variables in your .emacs file.
ada-prj-default-project-file
to
the name of that file.
(set 'ada-prj-default-project-file "/dir1/dir2/file")
ada-xref-default-prj-file
.
(set 'ada-xref-default-prj-file '(("/dir1/dir2" . "/dir3/file1") ("/dir4/dir5" . "/dir6/file2")))
Note: This has a higher priority than the first variable, so the first
choice is to use this variable settings, and otherwise
ada-prj-default-project-file
.
The following variables can be defined in a project file. They all have a default value, so that small projects do not need to create a project file.
Some variables below can be referenced in other variables, using a
shell-like notation. For instance, if the variable comp_cmd
contains a sequence like ${comp_opt}
, the value of that variable
will be substituted.
Here is the list of variables:
src_dir [default: "./"]
obj_dir [default: "./"]
comp_opt [default: ""]
${comp_opt}
notation. This is intended to store the default
switches given to `gnatmake' and `gcc'.
bind_opt=SWITCHES [default: ""]
${bind_opt}
notation. This is intended to store the default
switches given to `gnatbind'.
link_opt=SWITCHES [default: ""]
${link_opt}
notation. This is intended to store the default
switches given to `gnatlink'.
main=EXECUTABLE [default: ""]
${main}
notation.
cross_prefix=PREFIX [default: ""]
remote_machine=MACHINE [default: ""]
comp_cmd=COMMAND [default: "${cross_prefix}gcc -c -I${src_dir} -g -gnatq"]
make_cmd=COMMAND [default: "${cross_prefix}gnatmake ${main} -aI${src_dir} -aO${obj_dir} -g -gnatq -cargs ${comp_opt} -bargs ${bind_opt} -largs ${link_opt}"]'
run_cmd=COMMAND [default: "${main}"]
debug_cmd=COMMAND [default: "${cross_prefix}gdb ${main}"]
This section gives more details on the project file setup and is only of interest for advanced users.
Usually, an Ada file is part of a larger application, whose sources and objects can be spread over multiple directories. The first time emacs is asked to compile, run or debug an application, or when a cross reference function is used (goto declaration for instance), the following steps are taken:
ada-xref-default-prj-file
described above.
ada-prj-default-project-file
is set,
use the project file specified in this variable.
The first project file that is selected in a given directory becomes the default project file for this directory and is used implicitly for other sources unless specified otherwise by the user.
obj_dir
defined
in the project file. If this file can not be found, emacs proposes to
compile the source using the comp_cmd
defined in the project file
in order to create the ali file.
ada-xref-create-ali
is
set, otherwise the reference is searched in the obsolete ali file with
possible inaccurate results.
src_dir
defined in the project file. Put the cursor at the
correct position and display this new cursor.