[Emacs-ada-mode] Project files and multiple main programs
Ludovic Brenta
ludovic at ludovic-brenta.org
Tue Aug 22 03:40:36 PDT 2006
The way I usually work in the context of multiple small programs is that
I create one GNAT project file and specify the main program on the
command line, like this:
project Foo is
for Source_Dirs use (".");
for Object_Dir use ("obj");
package Compiler is
for Default_Switches ("Ada")
use ("-g", "-O2", "-gnatafno", "-gnatVa");
end Compiler;
package Binder is
for Default_Switches ("Ada") use ("-E");
end Binder;
end Foo;
(yes, the above are my default compiler options). I have a directory
where I keep such a project file and many small programs that I have
written or gathered over the years, such as test cases or small
experiments. There are a bunch of subdirectories with "larger"
experiments consisting of two or more units.
Then, I first load the project file using my modified, gpr-aware
ada-mode. This sets up the compile-command to automatically change to
the directory containing the project file, then to invoke "gnatmake
-Pfoo.gpr". (I can switch to a different project file using C-c C-d or
the menu).
Then, I use C-c C-f to load my source files. This searches through all
the Source_Dirs of the project file. Thus, there may be many source
directories scattered around.
To compile, I usually do M-x compile and add the source file name at the
end of the command, like: "gnatmake -Pfoo.gpr bar" if I'm editing
bar.adb. This is the only manual step; I have not automated it yet
because I don't use that very often. I almost never use C-c C-c, but
I've lost the reason why (habits die hard). Alternatively, I can also
add a "for Main use ("foo", "bar")" line to the project file and just
recompile everything. Gnatmake will usually only recompile the one
program that I just modified.
I think it should be fairly easy to just add the current buffer name
after the compile-command in a function named compile-buffer, and bind
that function to C-c C-c. There is no need for project file variables
or for -X.
I understand that this may not be what Jean-Pierre wants, which is to
avoid the need for project files entirely. In my situation, I prefer to
use project files for two reasons: (1) I don't like the default
behaviour of gnat, especially the lack of range checks, and (2) I like
to separate my object files from my source files.
--
Ludovic Brenta.
More information about the Emacs-ada-mode
mailing list