[Emacs-ada-mode] Thanks and my first enquiry
Stephen Leake
stephen_leake at stephe-leake.org
Sun Aug 20 18:58:06 PDT 2006
"The masked-coder known as Randux" <randux at Safe-mail.net> writes:
>> >> The menu also provides "ada-compile-current", not bound to a key,
>> >> which generates object code for the current file.
>> >
>> > Apparently it doesn't do the full gnatmake, so I think while it's
>> > aptly named, it's not enough. There should be something such as
>> > ada-make-current if that makes any sense.
>>
>> I don't understand what you mean by it.
>
> If I understand properly (which would be quite the miracle at this
> hour) gnatmake does one of the following:
>
> 1. if issued against a main program A (A has with B; with C;) compiles
> all the dependencies (B and C) that have changed, compiles the main
> program A, and links the main program A.
Correct.
> 2. if issued against against programs B or C which provides services(A
> has with B; with C;), compiles that program B or C, then compiles and
> links all of the consumers such as A.
Incorrect. It will just compile B or C.
> If this is true, it's why I say that there should be a function
> (probably the most important one) to do gnatmake on whatever the
> buffer is I'm working with. If I'm working with a main program,
> gnatmake is necessary because of #1 above. And if I'm working with a
> package withed by anyone, it's necessary for reason #2 above.
Which is why you should always execute 'gnatmake A' rather than
'gnatmake B'. It does what you are asking for.
Note that you are _not_ asking for "compile this file", but for
"compile the program this file is part of".
Hmm, you actually seem to be asking for "compile _all_ programs this
file is part of". gnatmake will not do that. But you can specify
several main programs in one invocation of gnatmake.
>> There is an important difference between files that are Ada main
>> programs, and files that are Ada, but not main programs.
>
> It's not exactly clear to me how those are defined. I suppose a
> program that is not withed by anything else would qualify as a main
> program, and programs that are withed by something else are "files
> that are Ada, but not main programs?"
Not quite. A main program must be a library procedure, with no
parameters. A non-main program is pretty much any other legal Ada file.
>> It only makes sense to invoke compile and link (gnatmake) on Ada
>> main programs.
>
> Ah, but gnatmake is supposed to be intelligent enough to do what's
> necessary. So if I understand what the people have been saying on
> comp.lang.ada about gnatmake checking dependencies and compiling
> and/or linking as necessary, then I think the above statement is not
> true. Because gnatmake against a subprogram will compile the
> subprogram and rebuild all the programs that with it. Is that not
> correct?
You misunderstand.
Section 6.1 in the GNAT User's Guide, 'Running gnatmake', says:
The usual form of the `gnatmake' command is
$ gnatmake [SWITCHES] FILE_NAME
[FILE_NAMES] [MODE_SWITCHES]
The only required argument is one FILE_NAME, which specifies a
compilation unit that is a main program.
The manual goes on to give examples and define the switches. It never
actually says what happens when gnatmake is invoked on a file that is
not a main program.
The GNAT reference manual does not describe gnatmake.
>> But the recommended process is to always invoke 'gnatmake -gnatc' on
>> the main program, even when you've just edited some other file. That
>> will identify all of the compilation errors for all the files that
>> make up the program. When that completes with no errors, then you
>> invoke 'gnatmake' on the main program, to generate the executable.
>
> That seems to suggest that there isn't any purpose in rebuilding other
> subprograms that have changed until the main program you're working on
> is correct. What if we have this scenario:
>
> program A is main program that withs program X
> program B is main program that withs program X
>
Hmm. It is not proper to call "X" a "program"; that should be reserved
for "main program". But I'll take it to mean "an Ada compilation unit".
> You are working on program A and program X. If I understand what's
>being said here, we don't want to relink program B automagically when
>program X's changes are complete? If we continuously do gnatmake
>incrementally, I think program B is always current. Otherwise, it
>seems to me that we have to do a separate gnatmake on program B even
>though gnatmake on X would have rebuilt B...
If you do 'gnatmake A' continuously, then it won't know about B, so
only A and X will be compiled, and A will be linked.
To get both A and B linked, you can do 'gnatmake A B'; that will
compile A, B and X, and link A and B.
Doing 'gnatmake X' will only compile X; it won't know about A and B.
> I think it would be nice to be able to work on any number of Ada
> source modules (main programs and subprograms) in one Emacs session
> and not have Emacs be required to know anything about the
> relationships. Just invoke gnatmake on the current buffer name and be
> done with it. Will this not work?
It will not. Which is partly why I use Makefiles.
Think about how gnatmake must work. How will it know what the main
programs that use X are? Should it just scan the current directory,
looking for 'with X'? Or scan the whole disk? Or scan all directories
in the project file?
But, it does appear that you can specify a list of main programs for
gnatmake, and it will do what you want. Ada mode should support that.
It would be interesting to know where you acquired your
misunderstanding. Certainly it would help if the GNAT User's guide
explicitly said "this is what happens when you invoke gnatmake on a
non-main program; so don't bother".
I can add that to the Emacs Ada mode manual. And suggest it to
AdaCore.
--
-- Stephe
More information about the Emacs-ada-mode
mailing list